--- /srv/reproducible-results/rbuild-debian/r-b-build.NdPtmx6M/b1/openlayers_2.13.1+ds2-11_i386.changes +++ /srv/reproducible-results/rbuild-debian/r-b-build.NdPtmx6M/b2/openlayers_2.13.1+ds2-11_i386.changes ├── Files │ @@ -1,2 +1,2 @@ │ │ - f3a6badd141c6fb44590d90735067dc6 714000 javascript optional libjs-openlayers_2.13.1+ds2-11_all.deb │ + a8b691201f10cf133bb27cf95f95c2dc 715616 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 710124 2025-03-06 18:35:30.000000 data.tar.xz │ │ +-rw-r--r-- 0 0 0 711740 2025-03-06 18:35:30.000000 data.tar.xz │ ├── control.tar.xz │ │ ├── control.tar │ │ │ ├── ./md5sums │ │ │ │ ├── ./md5sums │ │ │ │ │┄ Files differ │ ├── data.tar.xz │ │ ├── data.tar │ │ │ ├── ./usr/share/javascript/openlayers/OpenLayers.js │ │ │ │ ├── js-beautify {} │ │ │ │ │ @@ -52,37 +52,14 @@ │ │ │ │ │ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS │ │ │ │ │ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN │ │ │ │ │ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) │ │ │ │ │ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE │ │ │ │ │ * POSSIBILITY OF SUCH DAMAGE. │ │ │ │ │ */ │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - Rico/license.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @license Apache 2 │ │ │ │ │ - * │ │ │ │ │ - * Contains portions of Rico │ │ │ │ │ - * │ │ │ │ │ - * Copyright 2005 Sabre Airline Solutions │ │ │ │ │ - * │ │ │ │ │ - * Licensed under the Apache License, Version 2.0 (the "License"); you │ │ │ │ │ - * may not use this file except in compliance with the License. You │ │ │ │ │ - * may obtain a copy of the License at │ │ │ │ │ - * │ │ │ │ │ - * http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ │ - * │ │ │ │ │ - * Unless required by applicable law or agreed to in writing, software │ │ │ │ │ - * distributed under the License is distributed on an "AS IS" BASIS, │ │ │ │ │ - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or │ │ │ │ │ - * implied. See the License for the specific language governing │ │ │ │ │ - * permissions and limitations under the License. │ │ │ │ │ - */ │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ OpenLayers/SingleFile.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ @@ -286,268 +263,14 @@ │ │ │ │ │ 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. */ │ │ │ │ │ @@ -1866,14 +1589,207 @@ │ │ │ │ │ │ │ │ │ │ opp += (quadrant.charAt(0) == 't') ? 'b' : 't'; │ │ │ │ │ opp += (quadrant.charAt(1) == 'l') ? 'r' : 'l'; │ │ │ │ │ │ │ │ │ │ return opp; │ │ │ │ │ }; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ + OpenLayers/BaseTypes/Element.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Element │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Element = { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: visible │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Is the element visible? │ │ │ │ │ + */ │ │ │ │ │ + visible: function(element) { │ │ │ │ │ + return OpenLayers.Util.getElement(element).style.display != 'none'; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: toggle │ │ │ │ │ + * Toggle the visibility of element(s) passed in │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} Actually user can pass any number of elements │ │ │ │ │ + */ │ │ │ │ │ + toggle: function() { │ │ │ │ │ + for (var i = 0, len = arguments.length; i < len; i++) { │ │ │ │ │ + var element = OpenLayers.Util.getElement(arguments[i]); │ │ │ │ │ + var display = OpenLayers.Element.visible(element) ? 'none' : │ │ │ │ │ + ''; │ │ │ │ │ + element.style.display = display; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: remove │ │ │ │ │ + * Remove the specified element from the DOM. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + remove: function(element) { │ │ │ │ │ + element = OpenLayers.Util.getElement(element); │ │ │ │ │ + element.parentNode.removeChild(element); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: getHeight │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} The offset height of the element passed in │ │ │ │ │ + */ │ │ │ │ │ + getHeight: function(element) { │ │ │ │ │ + element = OpenLayers.Util.getElement(element); │ │ │ │ │ + return element.offsetHeight; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: hasClass │ │ │ │ │ + * Tests if an element has the given CSS class name. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to search for. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The element has the given class name. │ │ │ │ │ + */ │ │ │ │ │ + hasClass: function(element, name) { │ │ │ │ │ + var names = element.className; │ │ │ │ │ + return (!!names && new RegExp("(^|\\s)" + name + "(\\s|$)").test(names)); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: addClass │ │ │ │ │ + * Add a CSS class name to an element. Safe where element already has │ │ │ │ │ + * the class name. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to add. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The element. │ │ │ │ │ + */ │ │ │ │ │ + addClass: function(element, name) { │ │ │ │ │ + if (!OpenLayers.Element.hasClass(element, name)) { │ │ │ │ │ + element.className += (element.className ? " " : "") + name; │ │ │ │ │ + } │ │ │ │ │ + return element; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: removeClass │ │ │ │ │ + * Remove a CSS class name from an element. Safe where element does not │ │ │ │ │ + * have the class name. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to remove. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The element. │ │ │ │ │ + */ │ │ │ │ │ + removeClass: function(element, name) { │ │ │ │ │ + var names = element.className; │ │ │ │ │ + if (names) { │ │ │ │ │ + element.className = OpenLayers.String.trim( │ │ │ │ │ + names.replace( │ │ │ │ │ + new RegExp("(^|\\s+)" + name + "(\\s+|$)"), " " │ │ │ │ │ + ) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return element; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: toggleClass │ │ │ │ │ + * Remove a CSS class name from an element if it exists. Add the class name │ │ │ │ │ + * if it doesn't exist. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} A DOM element node. │ │ │ │ │ + * name - {String} The CSS class name to toggle. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The element. │ │ │ │ │ + */ │ │ │ │ │ + toggleClass: function(element, name) { │ │ │ │ │ + if (OpenLayers.Element.hasClass(element, name)) { │ │ │ │ │ + OpenLayers.Element.removeClass(element, name); │ │ │ │ │ + } else { │ │ │ │ │ + OpenLayers.Element.addClass(element, name); │ │ │ │ │ + } │ │ │ │ │ + return element; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: getStyle │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + * style - {?} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {?} │ │ │ │ │ + */ │ │ │ │ │ + getStyle: function(element, style) { │ │ │ │ │ + element = OpenLayers.Util.getElement(element); │ │ │ │ │ + │ │ │ │ │ + var value = null; │ │ │ │ │ + if (element && element.style) { │ │ │ │ │ + value = element.style[OpenLayers.String.camelize(style)]; │ │ │ │ │ + if (!value) { │ │ │ │ │ + if (document.defaultView && │ │ │ │ │ + document.defaultView.getComputedStyle) { │ │ │ │ │ + │ │ │ │ │ + var css = document.defaultView.getComputedStyle(element, null); │ │ │ │ │ + value = css ? css.getPropertyValue(style) : null; │ │ │ │ │ + } else if (element.currentStyle) { │ │ │ │ │ + value = element.currentStyle[OpenLayers.String.camelize(style)]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var positions = ['left', 'top', 'right', 'bottom']; │ │ │ │ │ + if (window.opera && │ │ │ │ │ + (OpenLayers.Util.indexOf(positions, style) != -1) && │ │ │ │ │ + (OpenLayers.Element.getStyle(element, 'position') == 'static')) { │ │ │ │ │ + value = 'auto'; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return value == 'auto' ? null : value; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ +}; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ OpenLayers/BaseTypes/LonLat.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ @@ -2327,14 +2243,268 @@ │ │ │ │ │ } │ │ │ │ │ return equals; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Size" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ + OpenLayers/Console.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Console │ │ │ │ │ + * The OpenLayers.Console namespace is used for debugging and error logging. │ │ │ │ │ + * If the Firebug Lite (../Firebug/firebug.js) is included before this script, │ │ │ │ │ + * calls to OpenLayers.Console methods will get redirected to window.console. │ │ │ │ │ + * This makes use of the Firebug extension where available and allows for │ │ │ │ │ + * cross-browser debugging Firebug style. │ │ │ │ │ + * │ │ │ │ │ + * Note: │ │ │ │ │ + * Note that behavior will differ with the Firebug extention and Firebug Lite. │ │ │ │ │ + * Most notably, the Firebug Lite console does not currently allow for │ │ │ │ │ + * hyperlinks to code or for clicking on object to explore their properties. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Console = { │ │ │ │ │ + /** │ │ │ │ │ + * Create empty functions for all console methods. The real value of these │ │ │ │ │ + * properties will be set if Firebug Lite (../Firebug/firebug.js script) is │ │ │ │ │ + * included. We explicitly require the Firebug Lite script to trigger │ │ │ │ │ + * functionality of the OpenLayers.Console methods. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: log │ │ │ │ │ + * Log an object in the console. The Firebug Lite console logs string │ │ │ │ │ + * representation of objects. Given multiple arguments, they will │ │ │ │ │ + * be cast to strings and logged with a space delimiter. If the first │ │ │ │ │ + * argument is a string with printf-like formatting, subsequent arguments │ │ │ │ │ + * will be used in string substitution. Any additional arguments (beyond │ │ │ │ │ + * the number substituted in a format string) will be appended in a space- │ │ │ │ │ + * delimited line. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + log: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: debug │ │ │ │ │ + * Writes a message to the console, including a hyperlink to the line │ │ │ │ │ + * where it was called. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + debug: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: info │ │ │ │ │ + * Writes a message to the console with the visual "info" icon and color │ │ │ │ │ + * coding and a hyperlink to the line where it was called. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + info: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: warn │ │ │ │ │ + * Writes a message to the console with the visual "warning" icon and │ │ │ │ │ + * color coding and a hyperlink to the line where it was called. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + warn: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: error │ │ │ │ │ + * Writes a message to the console with the visual "error" icon and color │ │ │ │ │ + * coding and a hyperlink to the line where it was called. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + error: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: userError │ │ │ │ │ + * A single interface for showing error messages to the user. The default │ │ │ │ │ + * behavior is a Javascript alert, though this can be overridden by │ │ │ │ │ + * reassigning OpenLayers.Console.userError to a different function. │ │ │ │ │ + * │ │ │ │ │ + * Expects a single error message │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * error - {Object} │ │ │ │ │ + */ │ │ │ │ │ + userError: function(error) { │ │ │ │ │ + alert(error); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: assert │ │ │ │ │ + * Tests that an expression is true. If not, it will write a message to │ │ │ │ │ + * the console and throw an exception. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + assert: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: dir │ │ │ │ │ + * Prints an interactive listing of all properties of the object. This │ │ │ │ │ + * looks identical to the view that you would see in the DOM tab. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + dir: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: dirxml │ │ │ │ │ + * Prints the XML source tree of an HTML or XML element. This looks │ │ │ │ │ + * identical to the view that you would see in the HTML tab. You can click │ │ │ │ │ + * on any node to inspect it in the HTML tab. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + dirxml: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: trace │ │ │ │ │ + * Prints an interactive stack trace of JavaScript execution at the point │ │ │ │ │ + * where it is called. The stack trace details the functions on the stack, │ │ │ │ │ + * as well as the values that were passed as arguments to each function. │ │ │ │ │ + * You can click each function to take you to its source in the Script tab, │ │ │ │ │ + * and click each argument value to inspect it in the DOM or HTML tabs. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + trace: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: group │ │ │ │ │ + * Writes a message to the console and opens a nested block to indent all │ │ │ │ │ + * future messages sent to the console. Call OpenLayers.Console.groupEnd() │ │ │ │ │ + * to close the block. │ │ │ │ │ + * │ │ │ │ │ + * May be called with multiple arguments as with OpenLayers.Console.log(). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * object - {Object} │ │ │ │ │ + */ │ │ │ │ │ + group: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: groupEnd │ │ │ │ │ + * Closes the most recently opened block created by a call to │ │ │ │ │ + * OpenLayers.Console.group │ │ │ │ │ + */ │ │ │ │ │ + groupEnd: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: time │ │ │ │ │ + * Creates a new timer under the given name. Call │ │ │ │ │ + * OpenLayers.Console.timeEnd(name) │ │ │ │ │ + * with the same name to stop the timer and print the time elapsed. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * name - {String} │ │ │ │ │ + */ │ │ │ │ │ + time: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: timeEnd │ │ │ │ │ + * Stops a timer created by a call to OpenLayers.Console.time(name) and │ │ │ │ │ + * writes the time elapsed. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * name - {String} │ │ │ │ │ + */ │ │ │ │ │ + timeEnd: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: profile │ │ │ │ │ + * Turns on the JavaScript profiler. The optional argument title would │ │ │ │ │ + * contain the text to be printed in the header of the profile report. │ │ │ │ │ + * │ │ │ │ │ + * This function is not currently implemented in Firebug Lite. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * title - {String} Optional title for the profiler │ │ │ │ │ + */ │ │ │ │ │ + profile: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: profileEnd │ │ │ │ │ + * Turns off the JavaScript profiler and prints its report. │ │ │ │ │ + * │ │ │ │ │ + * This function is not currently implemented in Firebug Lite. │ │ │ │ │ + */ │ │ │ │ │ + profileEnd: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIFunction: count │ │ │ │ │ + * Writes the number of times that the line of code where count was called │ │ │ │ │ + * was executed. The optional argument title will print a message in │ │ │ │ │ + * addition to the number of the count. │ │ │ │ │ + * │ │ │ │ │ + * This function is not currently implemented in Firebug Lite. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * title - {String} Optional title to be printed with count │ │ │ │ │ + */ │ │ │ │ │ + count: function() {}, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Console" │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Execute an anonymous function to extend the OpenLayers.Console namespace │ │ │ │ │ + * if the firebug.js script is included. This closure is used so that the │ │ │ │ │ + * "scripts" and "i" variables don't pollute the global namespace. │ │ │ │ │ + */ │ │ │ │ │ +(function() { │ │ │ │ │ + /** │ │ │ │ │ + * If Firebug Lite is included (before this script), re-route all │ │ │ │ │ + * OpenLayers.Console calls to the console object. │ │ │ │ │ + */ │ │ │ │ │ + var scripts = document.getElementsByTagName("script"); │ │ │ │ │ + for (var i = 0, len = scripts.length; i < len; ++i) { │ │ │ │ │ + if (scripts[i].src.indexOf("firebug.js") != -1) { │ │ │ │ │ + if (console) { │ │ │ │ │ + OpenLayers.Util.extend(OpenLayers.Console, console); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ +})(); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ OpenLayers/Lang.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ @@ -4256,3198 +4426,1940 @@ │ │ │ │ │ } else { │ │ │ │ │ str += coordinate < 0 ? OpenLayers.i18n("S") : OpenLayers.i18n("N"); │ │ │ │ │ } │ │ │ │ │ return str; │ │ │ │ │ }; │ │ │ │ │ │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/BaseTypes/Element.js │ │ │ │ │ + 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/Util.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes.js │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ +OpenLayers.Util = OpenLayers.Util || {}; │ │ │ │ │ /** │ │ │ │ │ - * Namespace: OpenLayers.Element │ │ │ │ │ + * Namespace: OpenLayers.Util.vendorPrefix │ │ │ │ │ + * A collection of utility functions to detect vendor prefixed features │ │ │ │ │ */ │ │ │ │ │ -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; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +OpenLayers.Util.vendorPrefix = (function() { │ │ │ │ │ + "use strict"; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIFunction: remove │ │ │ │ │ - * Remove the specified element from the DOM. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * element - {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - remove: function(element) { │ │ │ │ │ - element = OpenLayers.Util.getElement(element); │ │ │ │ │ - element.parentNode.removeChild(element); │ │ │ │ │ - }, │ │ │ │ │ + var VENDOR_PREFIXES = ["", "O", "ms", "Moz", "Webkit"], │ │ │ │ │ + divStyle = document.createElement("div").style, │ │ │ │ │ + cssCache = {}, │ │ │ │ │ + jsCache = {}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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: │ │ │ │ │ - * element - {DOMElement} A DOM element node. │ │ │ │ │ - * name - {String} The CSS class name to search for. │ │ │ │ │ + * prefixedDom - {String} The property to convert │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The element has the given class name. │ │ │ │ │ + * {String} The CSS property │ │ │ │ │ */ │ │ │ │ │ - hasClass: function(element, name) { │ │ │ │ │ - var names = element.className; │ │ │ │ │ - return (!!names && new RegExp("(^|\\s)" + name + "(\\s|$)").test(names)); │ │ │ │ │ - }, │ │ │ │ │ + function domToCss(prefixedDom) { │ │ │ │ │ + if (!prefixedDom) { │ │ │ │ │ + return null; │ │ │ │ │ + } │ │ │ │ │ + return prefixedDom. │ │ │ │ │ + replace(/([A-Z])/g, function(c) { │ │ │ │ │ + return "-" + c.toLowerCase(); │ │ │ │ │ + }). │ │ │ │ │ + replace(/^ms-/, "-ms-"); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: addClass │ │ │ │ │ - * Add a CSS class name to an element. Safe where element already has │ │ │ │ │ - * the class name. │ │ │ │ │ + * APIMethod: css │ │ │ │ │ + * Detect which property is used for a CSS property │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * element - {DOMElement} A DOM element node. │ │ │ │ │ - * name - {String} The CSS class name to add. │ │ │ │ │ + * property - {String} The standard (unprefixed) CSS property name │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} The element. │ │ │ │ │ + * {String} The standard CSS property, prefixed property or null if not │ │ │ │ │ + * supported │ │ │ │ │ */ │ │ │ │ │ - addClass: function(element, name) { │ │ │ │ │ - if (!OpenLayers.Element.hasClass(element, name)) { │ │ │ │ │ - element.className += (element.className ? " " : "") + name; │ │ │ │ │ + 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 element; │ │ │ │ │ - }, │ │ │ │ │ + return cssCache[property]; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: removeClass │ │ │ │ │ - * Remove a CSS class name from an element. Safe where element does not │ │ │ │ │ - * have the class name. │ │ │ │ │ + * APIMethod: js │ │ │ │ │ + * Detect which property is used for a JS property/method │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * element - {DOMElement} A DOM element node. │ │ │ │ │ - * name - {String} The CSS class name to remove. │ │ │ │ │ + * obj - {Object} The object to test on │ │ │ │ │ + * property - {String} The standard (unprefixed) JS property name │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} The element. │ │ │ │ │ + * {String} The standard JS property, prefixed property or null if not │ │ │ │ │ + * supported │ │ │ │ │ */ │ │ │ │ │ - removeClass: function(element, name) { │ │ │ │ │ - var names = element.className; │ │ │ │ │ - if (names) { │ │ │ │ │ - element.className = OpenLayers.String.trim( │ │ │ │ │ - names.replace( │ │ │ │ │ - new RegExp("(^|\\s+)" + name + "(\\s+|$)"), " " │ │ │ │ │ - ) │ │ │ │ │ - ); │ │ │ │ │ + function js(obj, property) { │ │ │ │ │ + if (jsCache[property] === undefined) { │ │ │ │ │ + var tmpProp, │ │ │ │ │ + i = 0, │ │ │ │ │ + l = VENDOR_PREFIXES.length, │ │ │ │ │ + prefix, │ │ │ │ │ + isStyleObj = (typeof obj.cssText !== "undefined"); │ │ │ │ │ + │ │ │ │ │ + jsCache[property] = null; │ │ │ │ │ + for (; i < l; i++) { │ │ │ │ │ + prefix = VENDOR_PREFIXES[i]; │ │ │ │ │ + if (prefix) { │ │ │ │ │ + if (!isStyleObj) { │ │ │ │ │ + // js prefix should be lower-case, while style │ │ │ │ │ + // properties have upper case on first character │ │ │ │ │ + prefix = prefix.toLowerCase(); │ │ │ │ │ + } │ │ │ │ │ + tmpProp = prefix + property.charAt(0).toUpperCase() + property.slice(1); │ │ │ │ │ + } else { │ │ │ │ │ + tmpProp = property; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (obj[tmpProp] !== undefined) { │ │ │ │ │ + jsCache[property] = tmpProp; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return element; │ │ │ │ │ - }, │ │ │ │ │ + return jsCache[property]; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: toggleClass │ │ │ │ │ - * Remove a CSS class name from an element if it exists. Add the class name │ │ │ │ │ - * if it doesn't exist. │ │ │ │ │ + * APIMethod: style │ │ │ │ │ + * Detect which property is used for a DOM style property │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * element - {DOMElement} A DOM element node. │ │ │ │ │ - * name - {String} The CSS class name to toggle. │ │ │ │ │ + * property - {String} The standard (unprefixed) style property name │ │ │ │ │ * │ │ │ │ │ * 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: │ │ │ │ │ - * {?} │ │ │ │ │ + * {String} The standard style property, prefixed property or null if not │ │ │ │ │ + * supported │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + function style(property) { │ │ │ │ │ + return js(divStyle, property); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ -}; │ │ │ │ │ + return { │ │ │ │ │ + css: css, │ │ │ │ │ + js: js, │ │ │ │ │ + style: style, │ │ │ │ │ + │ │ │ │ │ + // used for testing │ │ │ │ │ + cssCache: cssCache, │ │ │ │ │ + jsCache: jsCache │ │ │ │ │ + }; │ │ │ │ │ +}()); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - Rico/Color.js │ │ │ │ │ + OpenLayers/Events.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires Rico/license.js │ │ │ │ │ - * @requires OpenLayers/Console.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Element.js │ │ │ │ │ - */ │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ -/* │ │ │ │ │ - * This file has been edited substantially from the Rico-released version by │ │ │ │ │ - * the OpenLayers development team. │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ -OpenLayers.Console.warn("OpenLayers.Rico is deprecated"); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Rico = OpenLayers.Rico || {}; │ │ │ │ │ -OpenLayers.Rico.Color = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - initialize: function(red, green, blue) { │ │ │ │ │ - this.rgb = { │ │ │ │ │ - r: red, │ │ │ │ │ - g: green, │ │ │ │ │ - b: blue │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - setRed: function(r) { │ │ │ │ │ - this.rgb.r = r; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Event │ │ │ │ │ + * Utility functions for event handling. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Event = { │ │ │ │ │ │ │ │ │ │ - setGreen: function(g) { │ │ │ │ │ - this.rgb.g = g; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: observers │ │ │ │ │ + * {Object} A hashtable cache of the event observers. Keyed by │ │ │ │ │ + * element._eventCacheID │ │ │ │ │ + */ │ │ │ │ │ + observers: false, │ │ │ │ │ │ │ │ │ │ - setBlue: function(b) { │ │ │ │ │ - this.rgb.b = b; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_SPACE │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_SPACE: 32, │ │ │ │ │ │ │ │ │ │ - setHue: function(h) { │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_BACKSPACE │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_BACKSPACE: 8, │ │ │ │ │ │ │ │ │ │ - // get an HSB model, and set the new hue... │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - hsb.h = h; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_TAB │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_TAB: 9, │ │ │ │ │ │ │ │ │ │ - // convert back to RGB... │ │ │ │ │ - this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_RETURN │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_RETURN: 13, │ │ │ │ │ │ │ │ │ │ - setSaturation: function(s) { │ │ │ │ │ - // get an HSB model, and set the new hue... │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - hsb.s = s; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_ESC │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_ESC: 27, │ │ │ │ │ │ │ │ │ │ - // convert back to RGB and set values... │ │ │ │ │ - this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_LEFT │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_LEFT: 37, │ │ │ │ │ │ │ │ │ │ - setBrightness: function(b) { │ │ │ │ │ - // get an HSB model, and set the new hue... │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - hsb.b = b; │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_UP │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_UP: 38, │ │ │ │ │ │ │ │ │ │ - // convert back to RGB and set values... │ │ │ │ │ - this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, hsb.b); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_RIGHT │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_RIGHT: 39, │ │ │ │ │ │ │ │ │ │ - darken: function(percent) { │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.max(hsb.b - percent, 0)); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_DOWN │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_DOWN: 40, │ │ │ │ │ │ │ │ │ │ - brighten: function(percent) { │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - this.rgb = OpenLayers.Rico.Color.HSBtoRGB(hsb.h, hsb.s, Math.min(hsb.b + percent, 1)); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_DELETE │ │ │ │ │ + * {int} │ │ │ │ │ + */ │ │ │ │ │ + KEY_DELETE: 46, │ │ │ │ │ │ │ │ │ │ - blend: function(other) { │ │ │ │ │ - this.rgb.r = Math.floor((this.rgb.r + other.rgb.r) / 2); │ │ │ │ │ - this.rgb.g = Math.floor((this.rgb.g + other.rgb.g) / 2); │ │ │ │ │ - this.rgb.b = Math.floor((this.rgb.b + other.rgb.b) / 2); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - isBright: function() { │ │ │ │ │ - var hsb = this.asHSB(); │ │ │ │ │ - return this.asHSB().b > 0.5; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - isDark: function() { │ │ │ │ │ - return !this.isBright(); │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - asRGB: function() { │ │ │ │ │ - return "rgb(" + this.rgb.r + "," + this.rgb.g + "," + this.rgb.b + ")"; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - asHex: function() { │ │ │ │ │ - return "#" + this.rgb.r.toColorPart() + this.rgb.g.toColorPart() + this.rgb.b.toColorPart(); │ │ │ │ │ + /** │ │ │ │ │ + * 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))); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - asHSB: function() { │ │ │ │ │ - return OpenLayers.Rico.Color.RGBtoHSB(this.rgb.r, this.rgb.g, this.rgb.b); │ │ │ │ │ + /** │ │ │ │ │ + * 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))); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - toString: function() { │ │ │ │ │ - return this.asHex(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Rico.Color.createFromHex = function(hexCode) { │ │ │ │ │ - if (hexCode.length == 4) { │ │ │ │ │ - var shortHexCode = hexCode; │ │ │ │ │ - var hexCode = '#'; │ │ │ │ │ - for (var i = 1; i < 4; i++) { │ │ │ │ │ - hexCode += (shortHexCode.charAt(i) + │ │ │ │ │ - shortHexCode.charAt(i)); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (hexCode.indexOf('#') == 0) { │ │ │ │ │ - hexCode = hexCode.substring(1); │ │ │ │ │ - } │ │ │ │ │ - var red = hexCode.substring(0, 2); │ │ │ │ │ - var green = hexCode.substring(2, 4); │ │ │ │ │ - var blue = hexCode.substring(4, 6); │ │ │ │ │ - return new OpenLayers.Rico.Color(parseInt(red, 16), parseInt(green, 16), parseInt(blue, 16)); │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Factory method for creating a color from the background of │ │ │ │ │ - * an HTML element. │ │ │ │ │ - */ │ │ │ │ │ -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))); │ │ │ │ │ + /** │ │ │ │ │ + * 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) { │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ + if (!allowDefault) { │ │ │ │ │ + OpenLayers.Event.preventDefault(event); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - 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; │ │ │ │ │ + if (event.stopPropagation) { │ │ │ │ │ + event.stopPropagation(); │ │ │ │ │ } else { │ │ │ │ │ - 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); │ │ │ │ │ + event.cancelBubble = true; │ │ │ │ │ } │ │ │ │ │ - this._roundCornersImpl(e, color, bgColor); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** This is a helper function to change the background │ │ │ │ │ - * color of
that has had Rico rounded corners added. │ │ │ │ │ - * │ │ │ │ │ - * It seems we cannot just set the background color for the │ │ │ │ │ - * outer
so each element used to create the │ │ │ │ │ - * corners must have its background color set individually. │ │ │ │ │ - * │ │ │ │ │ - * @param {DOM} theDiv - A child of the outer
that was │ │ │ │ │ - * supplied to the `round` method. │ │ │ │ │ + /** │ │ │ │ │ + * Method: preventDefault │ │ │ │ │ + * Cancels the event if it is cancelable, without stopping further │ │ │ │ │ + * propagation of the event. │ │ │ │ │ * │ │ │ │ │ - * @param {String} newColor - The new background color to use. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Event} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + preventDefault: function(event) { │ │ │ │ │ + if (event.preventDefault) { │ │ │ │ │ + event.preventDefault(); │ │ │ │ │ + } else { │ │ │ │ │ + event.returnValue = false; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ - /** 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). │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** 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 │ │ │ │ │ + /** │ │ │ │ │ + * Method: observe │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * elementParam - {DOMElement || String} │ │ │ │ │ + * name - {String} │ │ │ │ │ + * observer - {function} │ │ │ │ │ + * useCapture - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - reRound: function(theDiv, options) { │ │ │ │ │ - │ │ │ │ │ - var topRico = theDiv.parentNode.childNodes[0]; │ │ │ │ │ - //theDiv would be theDiv.parentNode.childNodes[1] │ │ │ │ │ - var bottomRico = theDiv.parentNode.childNodes[2]; │ │ │ │ │ - │ │ │ │ │ - theDiv.parentNode.removeChild(topRico); │ │ │ │ │ - theDiv.parentNode.removeChild(bottomRico); │ │ │ │ │ - │ │ │ │ │ - this.round(theDiv.parentNode, options); │ │ │ │ │ - }, │ │ │ │ │ + observe: function(elementParam, name, observer, useCapture) { │ │ │ │ │ + var element = OpenLayers.Util.getElement(elementParam); │ │ │ │ │ + useCapture = useCapture || false; │ │ │ │ │ │ │ │ │ │ - _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 (name == 'keypress' && │ │ │ │ │ + (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || │ │ │ │ │ + element.attachEvent)) { │ │ │ │ │ + name = 'keydown'; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - _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")); │ │ │ │ │ + //if observers cache has not yet been created, create it │ │ │ │ │ + if (!this.observers) { │ │ │ │ │ + this.observers = {}; │ │ │ │ │ } │ │ │ │ │ - el.style.paddingTop = 0; │ │ │ │ │ - el.insertBefore(corner, el.firstChild); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - _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")); │ │ │ │ │ + //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); │ │ │ │ │ } │ │ │ │ │ - el.style.paddingBottom = 0; │ │ │ │ │ - el.appendChild(corner); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - _createCorner: function(bgColor) { │ │ │ │ │ - var corner = document.createElement("div"); │ │ │ │ │ - corner.style.backgroundColor = (this._isTransparent() ? "transparent" : bgColor); │ │ │ │ │ - return corner; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - _createCornerSlice: function(color, bgColor, n, position) { │ │ │ │ │ - var slice = document.createElement("span"); │ │ │ │ │ - │ │ │ │ │ - var inStyle = slice.style; │ │ │ │ │ - inStyle.backgroundColor = color; │ │ │ │ │ - inStyle.display = "block"; │ │ │ │ │ - inStyle.height = "1px"; │ │ │ │ │ - inStyle.overflow = "hidden"; │ │ │ │ │ - inStyle.fontSize = "1px"; │ │ │ │ │ + var cacheID = element._eventCacheID; │ │ │ │ │ │ │ │ │ │ - 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 there is not yet a hash entry for this element, add one │ │ │ │ │ + if (!this.observers[cacheID]) { │ │ │ │ │ + this.observers[cacheID] = []; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (!this.options.compact && (n == (this.options.numSlices - 1))) { │ │ │ │ │ - inStyle.height = "2px"; │ │ │ │ │ + //add a new observer to this element's list │ │ │ │ │ + this.observers[cacheID].push({ │ │ │ │ │ + 'element': element, │ │ │ │ │ + 'name': name, │ │ │ │ │ + 'observer': observer, │ │ │ │ │ + 'useCapture': useCapture │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + //add the actual browser event listener │ │ │ │ │ + if (element.addEventListener) { │ │ │ │ │ + element.addEventListener(name, observer, useCapture); │ │ │ │ │ + } else if (element.attachEvent) { │ │ │ │ │ + element.attachEvent('on' + name, observer); │ │ │ │ │ } │ │ │ │ │ - this._setMargin(slice, n, position); │ │ │ │ │ - this._setBorder(slice, n, position); │ │ │ │ │ - return slice; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - _setOptions: function(options) { │ │ │ │ │ - this.options = { │ │ │ │ │ - corners: "all", │ │ │ │ │ - color: "fromElement", │ │ │ │ │ - bgColor: "fromParent", │ │ │ │ │ - blend: true, │ │ │ │ │ - border: false, │ │ │ │ │ - compact: false │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Util.extend(this.options, options || {}); │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ │ │ │ │ │ - this.options.numSlices = this.options.compact ? 2 : 4; │ │ │ │ │ - if (this._isTransparent()) { │ │ │ │ │ - this.options.blend = false; │ │ │ │ │ - } │ │ │ │ │ + this._removeElementObservers(OpenLayers.Event.observers[cacheID]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - _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"; │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ + ]); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return ""; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - _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 ""; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ │ │ │ │ │ - if (this.options.corners.indexOf("bl") >= 0) { │ │ │ │ │ - return "left"; │ │ │ │ │ - } else if (this.options.corners.indexOf("br") >= 0) { │ │ │ │ │ - return "right"; │ │ │ │ │ - } │ │ │ │ │ - return ""; │ │ │ │ │ - }, │ │ │ │ │ + var element = OpenLayers.Util.getElement(elementParam); │ │ │ │ │ + var cacheID = element._eventCacheID; │ │ │ │ │ │ │ │ │ │ - _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 ""; │ │ │ │ │ + if (name == 'keypress') { │ │ │ │ │ + if (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || │ │ │ │ │ + element.detachEvent) { │ │ │ │ │ + name = 'keydown'; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ + // find element's entry in this.observers cache and remove it │ │ │ │ │ + var foundEntry = false; │ │ │ │ │ + var elementObservers = OpenLayers.Event.observers[cacheID]; │ │ │ │ │ + if (elementObservers) { │ │ │ │ │ │ │ │ │ │ - _setMargin: function(el, n, corners) { │ │ │ │ │ - var marginSize = this._marginSize(n); │ │ │ │ │ - var whichSide = corners == "top" ? this._whichSideTop() : this._whichSideBottom(); │ │ │ │ │ - │ │ │ │ │ - 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"; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + // find the specific event type in the element's list │ │ │ │ │ + var i = 0; │ │ │ │ │ + while (!foundEntry && i < elementObservers.length) { │ │ │ │ │ + var cacheEntry = elementObservers[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"; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + if ((cacheEntry.name == name) && │ │ │ │ │ + (cacheEntry.observer == observer) && │ │ │ │ │ + (cacheEntry.useCapture == useCapture)) { │ │ │ │ │ │ │ │ │ │ - _marginSize: function(n) { │ │ │ │ │ - if (this._isTransparent()) { │ │ │ │ │ - return 0; │ │ │ │ │ + elementObservers.splice(i, 1); │ │ │ │ │ + if (elementObservers.length == 0) { │ │ │ │ │ + delete OpenLayers.Event.observers[cacheID]; │ │ │ │ │ + } │ │ │ │ │ + foundEntry = true; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + i++; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - 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]; │ │ │ │ │ + //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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - _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]; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ } │ │ │ │ │ - return 0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - _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; │ │ │ │ │ - } │ │ │ │ │ + CLASS_NAME: "OpenLayers.Event" │ │ │ │ │ }; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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 │ │ │ │ │ - */ │ │ │ │ │ +/* prevent memory leaks in IE */ │ │ │ │ │ +OpenLayers.Event.observe(window, 'unload', OpenLayers.Event.unloadCache, false); │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Symbolizer │ │ │ │ │ - * Base class representing a symbolizer used for feature rendering. │ │ │ │ │ + * Class: OpenLayers.Events │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Symbolizer = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ +OpenLayers.Events = 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. │ │ │ │ │ + /** │ │ │ │ │ + * Constant: BROWSER_EVENTS │ │ │ │ │ + * {Array(String)} supported events │ │ │ │ │ */ │ │ │ │ │ - zIndex: 0, │ │ │ │ │ + BROWSER_EVENTS: [ │ │ │ │ │ + "mouseover", "mouseout", │ │ │ │ │ + "mousedown", "mouseup", "mousemove", │ │ │ │ │ + "click", "dblclick", "rightclick", "dblrightclick", │ │ │ │ │ + "resize", "focus", "blur", │ │ │ │ │ + "touchstart", "touchmove", "touchend", │ │ │ │ │ + "keydown" │ │ │ │ │ + ], │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: listeners │ │ │ │ │ + * {Object} Hashtable of Array(Function): events listener functions │ │ │ │ │ */ │ │ │ │ │ - initialize: function(config) { │ │ │ │ │ - OpenLayers.Util.extend(this, config); │ │ │ │ │ - }, │ │ │ │ │ + listeners: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a copy of this symbolizer. │ │ │ │ │ - * │ │ │ │ │ - * Returns a symbolizer of the same type with the same properties. │ │ │ │ │ + * Property: object │ │ │ │ │ + * {Object} the code object issuing application events │ │ │ │ │ */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var Type = eval(this.CLASS_NAME); │ │ │ │ │ - return new Type(OpenLayers.Util.extend({}, this)); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Symbolizer" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - 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({ │ │ │ │ │ + object: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ + * Property: element │ │ │ │ │ + * {DOMElement} the DOM element receiving browser events │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + element: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} │ │ │ │ │ + * Property: eventHandler │ │ │ │ │ + * {Function} bound event handler attached to elements │ │ │ │ │ */ │ │ │ │ │ - id: null, │ │ │ │ │ + eventHandler: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lonlat │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: fallThrough │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - lonlat: null, │ │ │ │ │ + fallThrough: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: data │ │ │ │ │ - * {Object} │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - data: null, │ │ │ │ │ + includeXY: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: marker │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * 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) │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - marker: null, │ │ │ │ │ + extensions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: popupClass │ │ │ │ │ - * {} The class which will be used to instantiate │ │ │ │ │ - * a new Popup. Default is . │ │ │ │ │ + * Property: extensionCount │ │ │ │ │ + * {Object} Keys are event types (like in ), values are the │ │ │ │ │ + * number of extension listeners for each event type. │ │ │ │ │ */ │ │ │ │ │ - popupClass: null, │ │ │ │ │ + extensionCount: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: popup │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * Method: clearMouseListener │ │ │ │ │ + * A version of that is bound to this instance so that │ │ │ │ │ + * it can be used with and │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - popup: null, │ │ │ │ │ + clearMouseListener: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Feature │ │ │ │ │ - * Constructor for features. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Events │ │ │ │ │ + * Construct an OpenLayers.Events object. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * data - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * 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(layer, lonlat, data) { │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.lonlat = lonlat; │ │ │ │ │ - this.data = (data != null) ? data : {}; │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ 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); │ │ │ │ │ + for (var e in this.extensions) { │ │ │ │ │ + if (typeof this.extensions[e] !== "boolean") { │ │ │ │ │ + this.extensions[e].destroy(); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - // remove the marker from the layer │ │ │ │ │ - if (this.layer != null && this.marker != null) { │ │ │ │ │ - this.layer.removeMarker(this.marker); │ │ │ │ │ + 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.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; │ │ │ │ │ - } │ │ │ │ │ + this.listeners = null; │ │ │ │ │ + this.object = null; │ │ │ │ │ + this.fallThrough = null; │ │ │ │ │ + this.eventHandler = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ + * APIMethod: addEventType │ │ │ │ │ + * Deprecated. Any event can be triggered without adding it first. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the feature is currently visible on screen │ │ │ │ │ - * (based on its 'lonlat' property) │ │ │ │ │ + * Parameters: │ │ │ │ │ + * eventName - {String} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ + addEventType: function(eventName) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createMarker │ │ │ │ │ - * Based on the data associated with the Feature, create and return a marker object. │ │ │ │ │ + * Method: attachToElement │ │ │ │ │ * │ │ │ │ │ - * 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 │ │ │ │ │ - * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {HTMLDOMElement} a DOM element to attach browser events to │ │ │ │ │ */ │ │ │ │ │ - createMarker: function() { │ │ │ │ │ + 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 │ │ │ │ │ + ); │ │ │ │ │ │ │ │ │ │ - if (this.lonlat != null) { │ │ │ │ │ - this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon); │ │ │ │ │ + // to be used with observe and stopObserving │ │ │ │ │ + this.clearMouseListener = OpenLayers.Function.bind( │ │ │ │ │ + this.clearMouseCache, this │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - return this.marker; │ │ │ │ │ + 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyMarker │ │ │ │ │ - * Destroys marker. │ │ │ │ │ - * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ - * to also specify an alternative function for destroying it │ │ │ │ │ + * 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} │ │ │ │ │ */ │ │ │ │ │ - destroyMarker: function() { │ │ │ │ │ - this.marker.destroy(); │ │ │ │ │ + on: function(object) { │ │ │ │ │ + for (var type in object) { │ │ │ │ │ + if (type != "scope" && object.hasOwnProperty(type)) { │ │ │ │ │ + this.register(type, object.scope, object[type]); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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 │ │ │ │ │ * │ │ │ │ │ - * If no 'lonlat' is set, returns null. │ │ │ │ │ - * If no this.marker has been created, no anchor is sent. │ │ │ │ │ + * : centerStr = "Center: " + this.getCenterLonLat(); │ │ │ │ │ * │ │ │ │ │ - * 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 . │ │ │ │ │ - * │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - if (this.data.overflow != null) { │ │ │ │ │ - this.popup.contentDiv.style.overflow = this.data.overflow; │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - this.popup.feature = this; │ │ │ │ │ } │ │ │ │ │ - return this.popup; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyPopup │ │ │ │ │ - * Destroys the popup created via createPopup. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * As with the marker, if user overrides the createPopup() function, s/he │ │ │ │ │ - * should also be able to override the destruction │ │ │ │ │ + * │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - destroyPopup: function() { │ │ │ │ │ - if (this.popup) { │ │ │ │ │ - this.popup.feature = null; │ │ │ │ │ - this.popup.destroy(); │ │ │ │ │ - this.popup = null; │ │ │ │ │ - } │ │ │ │ │ + registerPriority: function(type, obj, func) { │ │ │ │ │ + this.register(type, obj, func, true); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - 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 │ │ │ │ │ + * APIMethod: un │ │ │ │ │ + * Convenience method for unregistering listeners with a common scope. │ │ │ │ │ + * Internally, this method calls as shown in the examples │ │ │ │ │ + * below. │ │ │ │ │ * │ │ │ │ │ + * Example use: │ │ │ │ │ * (code) │ │ │ │ │ - * { │ │ │ │ │ - * geometry: >Object │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * // unregister a single listener for the "loadstart" event │ │ │ │ │ + * events.un({"loadstart": loadStartListener}); │ │ │ │ │ * │ │ │ │ │ - * When an application has made changes to feature attributes, it could │ │ │ │ │ - * have set the attributes to something like this: │ │ │ │ │ + * // this is equivalent to the following │ │ │ │ │ + * events.unregister("loadstart", undefined, loadStartListener); │ │ │ │ │ * │ │ │ │ │ - * (code) │ │ │ │ │ - * { │ │ │ │ │ - * attributes: { │ │ │ │ │ - * myAttribute: "original" │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * // unregister multiple listeners with the same `this` object │ │ │ │ │ + * events.un({ │ │ │ │ │ + * "loadstart": loadStartListener, │ │ │ │ │ + * "loadend": loadEndListener, │ │ │ │ │ + * scope: object │ │ │ │ │ + * }); │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * // this is equivalent to the following │ │ │ │ │ + * events.unregister("loadstart", object, loadStartListener); │ │ │ │ │ + * events.unregister("loadend", object, loadEndListener); │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ - modified: null, │ │ │ │ │ + un: function(object) { │ │ │ │ │ + for (var type in object) { │ │ │ │ │ + if (type != "scope" && object.hasOwnProperty(type)) { │ │ │ │ │ + this.unregister(type, object.scope, object[type]); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Feature.Vector │ │ │ │ │ - * Create a vector feature. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: unregister │ │ │ │ │ + * │ │ │ │ │ * 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. │ │ │ │ │ + * type - {String} │ │ │ │ │ + * obj - {Object} If none specified, defaults to this.object │ │ │ │ │ + * func - {Function} │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.style = style ? style : null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + * Method: remove │ │ │ │ │ + * Remove all listeners for a given event type. If type is not registered, │ │ │ │ │ + * does nothing. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * type - {String} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.layer) { │ │ │ │ │ - this.layer.removeFeatures(this); │ │ │ │ │ - this.layer = null; │ │ │ │ │ + remove: function(type) { │ │ │ │ │ + if (this.listeners[type] != null) { │ │ │ │ │ + this.listeners[type] = []; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - 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. │ │ │ │ │ + * APIMethod: triggerEvent │ │ │ │ │ + * Trigger a specified registered event. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * type - {String} │ │ │ │ │ + * evt - {Event || Object} will be passed to the listeners. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An exact clone of this vector feature. │ │ │ │ │ + * {Boolean} The last listener return. If a listener returns false, the │ │ │ │ │ + * chain of listeners will stop getting called. │ │ │ │ │ */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return new OpenLayers.Feature.Vector( │ │ │ │ │ - this.geometry ? this.geometry.clone() : null, │ │ │ │ │ - this.attributes, │ │ │ │ │ - this.style); │ │ │ │ │ + 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: 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. │ │ │ │ │ + * 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: │ │ │ │ │ - * 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). │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - return onScreen; │ │ │ │ │ + if (this.includeXY) { │ │ │ │ │ + evt.xy = this.getMousePosition(evt); │ │ │ │ │ + } │ │ │ │ │ + this.triggerEvent(type, evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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: │ │ │ │ │ - * {Boolean} The feature is currently displayed. │ │ │ │ │ + * {Object} An object with only clientX and clientY properties with the │ │ │ │ │ + * calculated values. │ │ │ │ │ */ │ │ │ │ │ - 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()); │ │ │ │ │ - }, │ │ │ │ │ + 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; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - }, │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ + evt.olClientX = x; │ │ │ │ │ + evt.olClientY = y; │ │ │ │ │ + │ │ │ │ │ + return { │ │ │ │ │ + clientX: x, │ │ │ │ │ + clientY: y │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createPopup │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * create popups │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} For now just returns null │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - createPopup: function() { │ │ │ │ │ - return null; │ │ │ │ │ + clearMouseCache: function() { │ │ │ │ │ + this.element.scrolls = null; │ │ │ │ │ + this.element.lefttop = null; │ │ │ │ │ + this.element.offsets = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: atPoint │ │ │ │ │ - * Determins whether the feature intersects with the specified location. │ │ │ │ │ + * Method: getMousePosition │ │ │ │ │ * │ │ │ │ │ - * 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: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the feature is at the specified location │ │ │ │ │ + * {} The current xy coordinate of the mouse, adjusted │ │ │ │ │ + * for offsets │ │ │ │ │ */ │ │ │ │ │ - atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ - var atPoint = false; │ │ │ │ │ - if (this.geometry) { │ │ │ │ │ - atPoint = this.geometry.atPoint(lonlat, toleranceLon, │ │ │ │ │ - toleranceLat); │ │ │ │ │ + getMousePosition: function(evt) { │ │ │ │ │ + if (!this.includeXY) { │ │ │ │ │ + this.clearMouseCache(); │ │ │ │ │ + } else if (!this.element.hasScrollEvent) { │ │ │ │ │ + OpenLayers.Event.observe(window, "scroll", this.clearMouseListener); │ │ │ │ │ + this.element.hasScrollEvent = true; │ │ │ │ │ } │ │ │ │ │ - return atPoint; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyPopup │ │ │ │ │ - * HACK - we need to decide if all vector features should be able to │ │ │ │ │ - * delete popups │ │ │ │ │ - */ │ │ │ │ │ - destroyPopup: function() { │ │ │ │ │ - // pass │ │ │ │ │ + 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: move │ │ │ │ │ - * Moves the feature and redraws it at its new location │ │ │ │ │ + * Method: addMsTouchListener │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * location - { or } the │ │ │ │ │ - * location to which to move the feature. │ │ │ │ │ + * element - {DOMElement} The DOM element to register the listener on │ │ │ │ │ + * type - {String} The event type │ │ │ │ │ + * handler - {Function} the handler │ │ │ │ │ */ │ │ │ │ │ - move: function(location) { │ │ │ │ │ + addMsTouchListener: function(element, type, handler) { │ │ │ │ │ + var eventHandler = this.eventHandler; │ │ │ │ │ + var touches = this._msTouches; │ │ │ │ │ │ │ │ │ │ - if (!this.layer || !this.geometry.move) { │ │ │ │ │ - //do nothing if no layer or immoveable geometry │ │ │ │ │ - return undefined; │ │ │ │ │ + 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)); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - var pixel; │ │ │ │ │ - if (location.CLASS_NAME == "OpenLayers.LonLat") { │ │ │ │ │ - pixel = this.layer.getViewPortPxFromLonLat(location); │ │ │ │ │ - } else { │ │ │ │ │ - pixel = location; │ │ │ │ │ + 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'; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - 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 │ │ │ │ │ + * Method: addMsTouchListenerStart │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * state - {String} │ │ │ │ │ + * element - {DOMElement} The DOM element to register the listener on │ │ │ │ │ + * type - {String} The event type │ │ │ │ │ + * handler - {Function} the handler │ │ │ │ │ */ │ │ │ │ │ - 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: │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - } else if (state == OpenLayers.State.INSERT) { │ │ │ │ │ - switch (this.state) { │ │ │ │ │ - case OpenLayers.State.UNKNOWN: │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - this.state = state; │ │ │ │ │ - break; │ │ │ │ │ + if (!alreadyInArray) { │ │ │ │ │ + touches.push(e); │ │ │ │ │ } │ │ │ │ │ - } else if (state == OpenLayers.State.DELETE) { │ │ │ │ │ - switch (this.state) { │ │ │ │ │ - case OpenLayers.State.INSERT: │ │ │ │ │ - // the feature should be destroyed │ │ │ │ │ + │ │ │ │ │ + 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; │ │ │ │ │ - case OpenLayers.State.DELETE: │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + 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; │ │ │ │ │ - case OpenLayers.State.UNKNOWN: │ │ │ │ │ - case OpenLayers.State.UPDATE: │ │ │ │ │ - this.state = state; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - } else if (state == OpenLayers.State.UNKNOWN) { │ │ │ │ │ - this.state = state; │ │ │ │ │ - } │ │ │ │ │ + │ │ │ │ │ + e.touches = touches.slice(); │ │ │ │ │ + handler(e); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Event.observe(element, 'MSPointerUp', cb); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Feature.Vector" │ │ │ │ │ + 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. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * @requires OpenLayers/SingleFile.js │ │ │ │ │ + * @requires OpenLayers/Util/vendorPrefix.js │ │ │ │ │ */ │ │ │ │ │ -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 │ │ │ │ │ +/** │ │ │ │ │ + * 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) { │ │ │ │ │ │ │ │ │ │ - }, │ │ │ │ │ - 'delete': { │ │ │ │ │ - display: "none" │ │ │ │ │ + /** │ │ │ │ │ + * Property: isNative │ │ │ │ │ + * {Boolean} true if a native requestAnimationFrame function is available │ │ │ │ │ + */ │ │ │ │ │ + var requestAnimationFrame = OpenLayers.Util.vendorPrefix.js(window, "requestAnimationFrame"); │ │ │ │ │ + var isNative = !!(requestAnimationFrame); │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: requestFrame │ │ │ │ │ + * Schedule a function to be called at the next available animation frame. │ │ │ │ │ + * Uses the native method where available. Where requestAnimationFrame is │ │ │ │ │ + * not available, setTimeout will be called with a 16ms delay. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * callback - {Function} The function to be called at the next animation frame. │ │ │ │ │ + * element - {DOMElement} Optional element that visually bounds the animation. │ │ │ │ │ + */ │ │ │ │ │ + var requestFrame = (function() { │ │ │ │ │ + var request = window[requestAnimationFrame] || │ │ │ │ │ + function(callback, element) { │ │ │ │ │ + window.setTimeout(callback, 16); │ │ │ │ │ + }; │ │ │ │ │ + // bind to window to avoid illegal invocation of native function │ │ │ │ │ + return function(callback, element) { │ │ │ │ │ + request.apply(window, [callback, element]); │ │ │ │ │ + }; │ │ │ │ │ + })(); │ │ │ │ │ + │ │ │ │ │ + // private variables for animation loops │ │ │ │ │ + var counter = 0; │ │ │ │ │ + var loops = {}; │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: start │ │ │ │ │ + * Executes a method with in series for some │ │ │ │ │ + * duration. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * callback - {Function} The function to be called at the next animation frame. │ │ │ │ │ + * duration - {Number} Optional duration for the loop. If not provided, the │ │ │ │ │ + * animation loop will execute indefinitely. │ │ │ │ │ + * element - {DOMElement} Optional element that visually bounds the animation. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} Identifier for the animation loop. Used to stop animations with │ │ │ │ │ + * . │ │ │ │ │ + */ │ │ │ │ │ + function start(callback, duration, element) { │ │ │ │ │ + duration = duration > 0 ? duration : Number.POSITIVE_INFINITY; │ │ │ │ │ + var id = ++counter; │ │ │ │ │ + var start = +new Date; │ │ │ │ │ + loops[id] = function() { │ │ │ │ │ + if (loops[id] && +new Date - start <= duration) { │ │ │ │ │ + callback(); │ │ │ │ │ + if (loops[id]) { │ │ │ │ │ + requestFrame(loops[id], element); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + delete loops[id]; │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + requestFrame(loops[id], element); │ │ │ │ │ + return id; │ │ │ │ │ } │ │ │ │ │ -}; │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Function: stop │ │ │ │ │ + * Terminates an animation loop started with . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * id - {Number} Identifier returned from . │ │ │ │ │ + */ │ │ │ │ │ + function stop(id) { │ │ │ │ │ + delete loops[id]; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return { │ │ │ │ │ + isNative: isNative, │ │ │ │ │ + requestFrame: requestFrame, │ │ │ │ │ + start: start, │ │ │ │ │ + stop: stop │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ +})(window); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Style.js │ │ │ │ │ + OpenLayers/Tween.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + * @requires OpenLayers/Animation.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Style │ │ │ │ │ - * This class represents a UserStyle obtained │ │ │ │ │ - * from a SLD, containing styling rules. │ │ │ │ │ + * Namespace: OpenLayers.Tween │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Style = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Tween = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} A unique id for this session. │ │ │ │ │ + * APIProperty: easing │ │ │ │ │ + * {(Function)} Easing equation used for the animation │ │ │ │ │ + * Defaultly set to OpenLayers.Easing.Expo.easeOut │ │ │ │ │ */ │ │ │ │ │ - id: null, │ │ │ │ │ + easing: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} │ │ │ │ │ + * APIProperty: begin │ │ │ │ │ + * {Object} Values to start the animation with │ │ │ │ │ */ │ │ │ │ │ - name: null, │ │ │ │ │ + begin: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: title │ │ │ │ │ - * {String} Title of this style (set if included in SLD) │ │ │ │ │ + * APIProperty: finish │ │ │ │ │ + * {Object} Values to finish the animation with │ │ │ │ │ */ │ │ │ │ │ - title: null, │ │ │ │ │ + finish: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: description │ │ │ │ │ - * {String} Description of this style (set if abstract is included in SLD) │ │ │ │ │ + * APIProperty: duration │ │ │ │ │ + * {int} duration of the tween (number of steps) │ │ │ │ │ */ │ │ │ │ │ - description: null, │ │ │ │ │ + duration: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layerName │ │ │ │ │ - * {} name of the layer that this style belongs to, usually │ │ │ │ │ - * according to the NamedLayer attribute of an SLD document. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - layerName: null, │ │ │ │ │ + callbacks: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isDefault │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - isDefault: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: rules │ │ │ │ │ - * {Array()} │ │ │ │ │ + * Property: time │ │ │ │ │ + * {int} Step counter │ │ │ │ │ */ │ │ │ │ │ - rules: null, │ │ │ │ │ + time: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: context │ │ │ │ │ - * {Object} An optional object with properties that symbolizers' property │ │ │ │ │ - * values should be evaluated against. If no context is specified, │ │ │ │ │ - * feature.attributes will be used │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - context: null, │ │ │ │ │ + minFrameRate: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: defaultStyle │ │ │ │ │ - * {Object} hash of style properties to use as default for merging │ │ │ │ │ - * rule-based style symbolizers onto. If no rules are defined, │ │ │ │ │ - * createSymbolizer will return this style. If is set to │ │ │ │ │ - * true, the defaultStyle will only be taken into account if there are │ │ │ │ │ - * rules defined. │ │ │ │ │ + * Property: startTime │ │ │ │ │ + * {Number} The timestamp of the first execution step. Used for skipping │ │ │ │ │ + * frames │ │ │ │ │ */ │ │ │ │ │ - defaultStyle: null, │ │ │ │ │ + startTime: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: defaultsPerSymbolizer │ │ │ │ │ - * {Boolean} If set to true, the will extend the symbolizer │ │ │ │ │ - * of every rule. Properties of the will also be used to set │ │ │ │ │ - * missing symbolizer properties if the symbolizer has stroke, fill or │ │ │ │ │ - * graphic set to true. Default is false. │ │ │ │ │ + * Property: animationId │ │ │ │ │ + * {int} Loop id returned by OpenLayers.Animation.start │ │ │ │ │ */ │ │ │ │ │ - defaultsPerSymbolizer: false, │ │ │ │ │ + animationId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: propertyStyles │ │ │ │ │ - * {Hash of Boolean} cache of style properties that need to be parsed for │ │ │ │ │ - * propertyNames. Property names are keys, values won't be used. │ │ │ │ │ + * Property: playing │ │ │ │ │ + * {Boolean} Tells if the easing is currently playing │ │ │ │ │ */ │ │ │ │ │ - propertyStyles: null, │ │ │ │ │ - │ │ │ │ │ + playing: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Style │ │ │ │ │ - * Creates a UserStyle. │ │ │ │ │ + * Constructor: OpenLayers.Tween │ │ │ │ │ + * Creates a Tween. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * style - {Object} Optional hash of style properties that will be │ │ │ │ │ - * used as default style for this style object. This style │ │ │ │ │ - * applies if no rules are specified. Symbolizers defined in │ │ │ │ │ - * rules will extend this default style. │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * style. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * rules - {Array()} List of rules to be added to the │ │ │ │ │ - * style. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(style, options) { │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.rules = []; │ │ │ │ │ - if (options && options.rules) { │ │ │ │ │ - this.addRules(options.rules); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // use the default style from OpenLayers.Feature.Vector if no style │ │ │ │ │ - // was given in the constructor │ │ │ │ │ - this.setDefaultStyle(style || │ │ │ │ │ - OpenLayers.Feature.Vector.style["default"]); │ │ │ │ │ - │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + * easing - {(Function)} easing function method to use │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var i = 0, len = this.rules.length; i < len; i++) { │ │ │ │ │ - this.rules[i].destroy(); │ │ │ │ │ - this.rules[i] = null; │ │ │ │ │ - } │ │ │ │ │ - this.rules = null; │ │ │ │ │ - this.defaultStyle = null; │ │ │ │ │ + initialize: function(easing) { │ │ │ │ │ + this.easing = (easing) ? easing : OpenLayers.Easing.Expo.easeOut; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createSymbolizer │ │ │ │ │ - * creates a style by applying all feature-dependent rules to the base │ │ │ │ │ - * style. │ │ │ │ │ + * APIMethod: start │ │ │ │ │ + * Plays the Tween, and calls the callback method on each step │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} feature to evaluate rules for │ │ │ │ │ - * │ │ │ │ │ - * 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) { │ │ │ │ │ - var style = this.defaultsPerSymbolizer ? {} : this.createLiterals( │ │ │ │ │ - OpenLayers.Util.extend({}, this.defaultStyle), feature); │ │ │ │ │ - │ │ │ │ │ - var rules = this.rules; │ │ │ │ │ - │ │ │ │ │ - var rule, context; │ │ │ │ │ - var elseRules = []; │ │ │ │ │ - var appliedRules = false; │ │ │ │ │ - for (var i = 0, len = rules.length; i < len; i++) { │ │ │ │ │ - rule = rules[i]; │ │ │ │ │ - // does the rule apply? │ │ │ │ │ - var applies = rule.evaluate(feature); │ │ │ │ │ - │ │ │ │ │ - if (applies) { │ │ │ │ │ - if (rule instanceof OpenLayers.Rule && rule.elseFilter) { │ │ │ │ │ - elseRules.push(rule); │ │ │ │ │ - } else { │ │ │ │ │ - appliedRules = true; │ │ │ │ │ - this.applySymbolizer(rule, style, feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // if no other rules apply, apply the rules with else filters │ │ │ │ │ - if (appliedRules == false && elseRules.length > 0) { │ │ │ │ │ - appliedRules = true; │ │ │ │ │ - for (var i = 0, len = elseRules.length; i < len; i++) { │ │ │ │ │ - this.applySymbolizer(elseRules[i], style, feature); │ │ │ │ │ - } │ │ │ │ │ + start: function(begin, finish, duration, options) { │ │ │ │ │ + this.playing = true; │ │ │ │ │ + this.begin = begin; │ │ │ │ │ + this.finish = finish; │ │ │ │ │ + this.duration = duration; │ │ │ │ │ + this.callbacks = options.callbacks; │ │ │ │ │ + this.minFrameRate = options.minFrameRate || 30; │ │ │ │ │ + this.time = 0; │ │ │ │ │ + this.startTime = new Date().getTime(); │ │ │ │ │ + OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ + this.animationId = null; │ │ │ │ │ + if (this.callbacks && this.callbacks.start) { │ │ │ │ │ + this.callbacks.start.call(this, this.begin); │ │ │ │ │ } │ │ │ │ │ + this.animationId = OpenLayers.Animation.start( │ │ │ │ │ + OpenLayers.Function.bind(this.play, this) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // don't display if there were rules but none applied │ │ │ │ │ - if (rules.length > 0 && appliedRules == false) { │ │ │ │ │ - style.display = "none"; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: stop │ │ │ │ │ + * Stops the Tween, and calls the done callback │ │ │ │ │ + * Doesn't do anything if animation is already finished │ │ │ │ │ + */ │ │ │ │ │ + stop: function() { │ │ │ │ │ + if (!this.playing) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (style.label != null && typeof style.label !== "string") { │ │ │ │ │ - style.label = String(style.label); │ │ │ │ │ + if (this.callbacks && this.callbacks.done) { │ │ │ │ │ + this.callbacks.done.call(this, this.finish); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return style; │ │ │ │ │ + OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ + this.animationId = null; │ │ │ │ │ + this.playing = false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: applySymbolizer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * rule - {} │ │ │ │ │ - * style - {Object} │ │ │ │ │ - * feature - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} A style with new symbolizer applied. │ │ │ │ │ + * Method: play │ │ │ │ │ + * Calls the appropriate easing method │ │ │ │ │ */ │ │ │ │ │ - applySymbolizer: function(rule, style, feature) { │ │ │ │ │ - var symbolizerPrefix = feature.geometry ? │ │ │ │ │ - this.getSymbolizerPrefix(feature.geometry) : │ │ │ │ │ - OpenLayers.Style.SYMBOLIZER_PREFIXES[0]; │ │ │ │ │ + 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 symbolizer = rule.symbolizer[symbolizerPrefix] || rule.symbolizer; │ │ │ │ │ + var c = f - b; │ │ │ │ │ + value[i] = this.easing.apply(this, [this.time, b, c, this.duration]); │ │ │ │ │ + } │ │ │ │ │ + this.time++; │ │ │ │ │ │ │ │ │ │ - if (this.defaultsPerSymbolizer === true) { │ │ │ │ │ - var defaults = this.defaultStyle; │ │ │ │ │ - OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ - pointRadius: defaults.pointRadius │ │ │ │ │ - }); │ │ │ │ │ - if (symbolizer.stroke === true || symbolizer.graphic === true) { │ │ │ │ │ - OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ - strokeWidth: defaults.strokeWidth, │ │ │ │ │ - strokeColor: defaults.strokeColor, │ │ │ │ │ - strokeOpacity: defaults.strokeOpacity, │ │ │ │ │ - strokeDashstyle: defaults.strokeDashstyle, │ │ │ │ │ - strokeLinecap: defaults.strokeLinecap │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.fill === true || symbolizer.graphic === true) { │ │ │ │ │ - OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ - fillColor: defaults.fillColor, │ │ │ │ │ - fillOpacity: defaults.fillOpacity │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.graphic === true) { │ │ │ │ │ - OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ - pointRadius: this.defaultStyle.pointRadius, │ │ │ │ │ - externalGraphic: this.defaultStyle.externalGraphic, │ │ │ │ │ - graphicName: this.defaultStyle.graphicName, │ │ │ │ │ - graphicOpacity: this.defaultStyle.graphicOpacity, │ │ │ │ │ - graphicWidth: this.defaultStyle.graphicWidth, │ │ │ │ │ - graphicHeight: this.defaultStyle.graphicHeight, │ │ │ │ │ - graphicXOffset: this.defaultStyle.graphicXOffset, │ │ │ │ │ - graphicYOffset: this.defaultStyle.graphicYOffset │ │ │ │ │ - }); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // merge the style with the current style │ │ │ │ │ - return this.createLiterals( │ │ │ │ │ - OpenLayers.Util.extend(style, symbolizer), feature); │ │ │ │ │ + if (this.time > this.duration) { │ │ │ │ │ + this.stop(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createLiterals │ │ │ │ │ - * creates literals for all style properties that have an entry in │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * style - {Object} style to create literals for. Will be modified │ │ │ │ │ - * inline. │ │ │ │ │ - * feature - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} the modified style │ │ │ │ │ + * Create empty functions for all easing methods. │ │ │ │ │ */ │ │ │ │ │ - createLiterals: function(style, feature) { │ │ │ │ │ - var context = OpenLayers.Util.extend({}, feature.attributes || feature.data); │ │ │ │ │ - OpenLayers.Util.extend(context, this.context); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Tween" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - for (var i in this.propertyStyles) { │ │ │ │ │ - style[i] = OpenLayers.Style.createLiteral(style[i], context, feature, i); │ │ │ │ │ - } │ │ │ │ │ - return style; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * 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 = { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: findPropertyStyles │ │ │ │ │ - * Looks into all rules for this style and the defaultStyle to collect │ │ │ │ │ - * all the style hash property names containing ${...} strings that have │ │ │ │ │ - * to be replaced using the createLiteral method before returning them. │ │ │ │ │ + * Function: easeIn │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} hash of property names that need createLiteral parsing. The │ │ │ │ │ - * name of the property is the key, and the value is true; │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - findPropertyStyles: function() { │ │ │ │ │ - var propertyStyles = {}; │ │ │ │ │ - │ │ │ │ │ - // check the default style │ │ │ │ │ - var style = this.defaultStyle; │ │ │ │ │ - this.addPropertyStyles(propertyStyles, style); │ │ │ │ │ - │ │ │ │ │ - // walk through all rules to check for properties in their symbolizer │ │ │ │ │ - var rules = this.rules; │ │ │ │ │ - var symbolizer, value; │ │ │ │ │ - for (var i = 0, len = rules.length; i < len; i++) { │ │ │ │ │ - symbolizer = rules[i].symbolizer; │ │ │ │ │ - for (var key in symbolizer) { │ │ │ │ │ - value = symbolizer[key]; │ │ │ │ │ - if (typeof value == "object") { │ │ │ │ │ - // symbolizer key is "Point", "Line" or "Polygon" │ │ │ │ │ - this.addPropertyStyles(propertyStyles, value); │ │ │ │ │ - } else { │ │ │ │ │ - // symbolizer is a hash of style properties │ │ │ │ │ - this.addPropertyStyles(propertyStyles, symbolizer); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return propertyStyles; │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return c * t / d + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addPropertyStyles │ │ │ │ │ + * Function: easeOut │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * propertyStyles - {Object} hash to add new property styles to. Will be │ │ │ │ │ - * modified inline │ │ │ │ │ - * symbolizer - {Object} search this symbolizer for property styles │ │ │ │ │ - * │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} propertyStyles hash │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - addPropertyStyles: function(propertyStyles, symbolizer) { │ │ │ │ │ - var property; │ │ │ │ │ - for (var key in symbolizer) { │ │ │ │ │ - property = symbolizer[key]; │ │ │ │ │ - if (typeof property == "string" && │ │ │ │ │ - property.match(/\$\{\w+\}/)) { │ │ │ │ │ - propertyStyles[key] = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return propertyStyles; │ │ │ │ │ + easeOut: function(t, b, c, d) { │ │ │ │ │ + return c * t / d + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addRules │ │ │ │ │ - * Adds rules to this style. │ │ │ │ │ + * Function: easeInOut │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * rules - {Array()} │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - addRules: function(rules) { │ │ │ │ │ - Array.prototype.push.apply(this.rules, rules); │ │ │ │ │ - this.propertyStyles = this.findPropertyStyles(); │ │ │ │ │ + easeInOut: function(t, b, c, d) { │ │ │ │ │ + return c * t / d + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Easing.Linear" │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Namespace: OpenLayers.Easing.Expo │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Easing.Expo = { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setDefaultStyle │ │ │ │ │ - * Sets the default style for this style object. │ │ │ │ │ + * Function: easeIn │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * style - {Object} Hash of style properties │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - setDefaultStyle: function(style) { │ │ │ │ │ - this.defaultStyle = style; │ │ │ │ │ - this.propertyStyles = this.findPropertyStyles(); │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getSymbolizerPrefix │ │ │ │ │ - * Returns the correct symbolizer prefix according to the │ │ │ │ │ - * geometry type of the passed geometry │ │ │ │ │ + * Function: easeOut │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} key of the according symbolizer │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - getSymbolizerPrefix: function(geometry) { │ │ │ │ │ - var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES; │ │ │ │ │ - for (var i = 0, len = prefixes.length; i < len; i++) { │ │ │ │ │ - if (geometry.CLASS_NAME.indexOf(prefixes[i]) != -1) { │ │ │ │ │ - return prefixes[i]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + easeOut: function(t, b, c, d) { │ │ │ │ │ + return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this style. │ │ │ │ │ + * Function: easeInOut │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} Clone of this style. │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - var options = OpenLayers.Util.extend({}, this); │ │ │ │ │ - // clone rules │ │ │ │ │ - if (this.rules) { │ │ │ │ │ - options.rules = []; │ │ │ │ │ - for (var i = 0, len = this.rules.length; i < len; ++i) { │ │ │ │ │ - options.rules.push(this.rules[i].clone()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // clone context │ │ │ │ │ - options.context = this.context && OpenLayers.Util.extend({}, this.context); │ │ │ │ │ - //clone default style │ │ │ │ │ - var defaultStyle = OpenLayers.Util.extend({}, this.defaultStyle); │ │ │ │ │ - return new OpenLayers.Style(defaultStyle, options); │ │ │ │ │ + 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.Style" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Function: createLiteral │ │ │ │ │ - * converts a style value holding a combination of PropertyName and Literal │ │ │ │ │ - * into a Literal, taking the property values from the passed features. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * value - {String} value to parse. If this string contains a construct like │ │ │ │ │ - * "foo ${bar}", then "foo " will be taken as literal, and "${bar}" │ │ │ │ │ - * will be replaced by the value of the "bar" attribute of the passed │ │ │ │ │ - * feature. │ │ │ │ │ - * context - {Object} context to take attribute values from │ │ │ │ │ - * feature - {} optional feature to pass to │ │ │ │ │ - * for evaluating functions in the │ │ │ │ │ - * context. │ │ │ │ │ - * property - {String} optional, name of the property for which the literal is │ │ │ │ │ - * being created for evaluating functions in the context. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} the parsed value. In the example of the value parameter above, the │ │ │ │ │ - * result would be "foo valueOfBar", assuming that the passed feature has an │ │ │ │ │ - * attribute named "bar" with the value "valueOfBar". │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Style.createLiteral = function(value, context, feature, property) { │ │ │ │ │ - if (typeof value == "string" && value.indexOf("${") != -1) { │ │ │ │ │ - value = OpenLayers.String.format(value, context, [feature, property]); │ │ │ │ │ - value = (isNaN(value) || !value) ? value : parseFloat(value); │ │ │ │ │ - } │ │ │ │ │ - return value; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Easing.Expo" │ │ │ │ │ }; │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: OpenLayers.Style.SYMBOLIZER_PREFIXES │ │ │ │ │ - * {Array} prefixes of the sld symbolizers. These are the │ │ │ │ │ - * same as the main geometry types │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon', 'Text', │ │ │ │ │ - 'Raster' │ │ │ │ │ -]; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/StyleMap.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Style.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.StyleMap │ │ │ │ │ + * Namespace: OpenLayers.Easing.Quad │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.StyleMap = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: styles │ │ │ │ │ - * {Object} Hash of {}, keyed by names of well known │ │ │ │ │ - * rendering intents (e.g. "default", "temporary", "select", "delete"). │ │ │ │ │ - */ │ │ │ │ │ - styles: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: extendDefault │ │ │ │ │ - * {Boolean} if true, every render intent will extend the symbolizers │ │ │ │ │ - * specified for the "default" intent at rendering time. Otherwise, every │ │ │ │ │ - * rendering intent will be treated as a completely independent style. │ │ │ │ │ - */ │ │ │ │ │ - extendDefault: true, │ │ │ │ │ +OpenLayers.Easing.Quad = { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.StyleMap │ │ │ │ │ + * Function: easeIn │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * style - {Object} Optional. Either a style hash, or a style object, or │ │ │ │ │ - * a hash of style objects (style hashes) keyed by rendering │ │ │ │ │ - * intent. If just one style hash or style object is passed, │ │ │ │ │ - * this will be used for all known render intents (default, │ │ │ │ │ - * select, temporary) │ │ │ │ │ - * options - {Object} optional hash of additional options for this │ │ │ │ │ - * instance │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(style, options) { │ │ │ │ │ - this.styles = { │ │ │ │ │ - "default": new OpenLayers.Style( │ │ │ │ │ - OpenLayers.Feature.Vector.style["default"]), │ │ │ │ │ - "select": new OpenLayers.Style( │ │ │ │ │ - OpenLayers.Feature.Vector.style["select"]), │ │ │ │ │ - "temporary": new OpenLayers.Style( │ │ │ │ │ - OpenLayers.Feature.Vector.style["temporary"]), │ │ │ │ │ - "delete": new OpenLayers.Style( │ │ │ │ │ - OpenLayers.Feature.Vector.style["delete"]) │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // take whatever the user passed as style parameter and convert it │ │ │ │ │ - // into parts of stylemap. │ │ │ │ │ - if (style instanceof OpenLayers.Style) { │ │ │ │ │ - // user passed a style object │ │ │ │ │ - this.styles["default"] = style; │ │ │ │ │ - this.styles["select"] = style; │ │ │ │ │ - this.styles["temporary"] = style; │ │ │ │ │ - this.styles["delete"] = style; │ │ │ │ │ - } else if (typeof style == "object") { │ │ │ │ │ - for (var key in style) { │ │ │ │ │ - if (style[key] instanceof OpenLayers.Style) { │ │ │ │ │ - // user passed a hash of style objects │ │ │ │ │ - this.styles[key] = style[key]; │ │ │ │ │ - } else if (typeof style[key] == "object") { │ │ │ │ │ - // user passsed a hash of style hashes │ │ │ │ │ - this.styles[key] = new OpenLayers.Style(style[key]); │ │ │ │ │ - } else { │ │ │ │ │ - // user passed a style hash (i.e. symbolizer) │ │ │ │ │ - this.styles["default"] = new OpenLayers.Style(style); │ │ │ │ │ - this.styles["select"] = new OpenLayers.Style(style); │ │ │ │ │ - this.styles["temporary"] = new OpenLayers.Style(style); │ │ │ │ │ - this.styles["delete"] = new OpenLayers.Style(style); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var key in this.styles) { │ │ │ │ │ - this.styles[key].destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.styles = null; │ │ │ │ │ + easeIn: function(t, b, c, d) { │ │ │ │ │ + return c * (t /= d) * t + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createSymbolizer │ │ │ │ │ - * Creates the symbolizer for a feature for a render intent. │ │ │ │ │ + * Function: easeOut │ │ │ │ │ * │ │ │ │ │ * 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). │ │ │ │ │ - * │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} symbolizer hash │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - createSymbolizer: function(feature, intent) { │ │ │ │ │ - if (!feature) { │ │ │ │ │ - feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ - } │ │ │ │ │ - if (!this.styles[intent]) { │ │ │ │ │ - intent = "default"; │ │ │ │ │ - } │ │ │ │ │ - feature.renderIntent = intent; │ │ │ │ │ - var defaultSymbolizer = {}; │ │ │ │ │ - if (this.extendDefault && intent != "default") { │ │ │ │ │ - defaultSymbolizer = this.styles["default"].createSymbolizer(feature); │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Util.extend(defaultSymbolizer, │ │ │ │ │ - this.styles[intent].createSymbolizer(feature)); │ │ │ │ │ + easeOut: function(t, b, c, d) { │ │ │ │ │ + return -c * (t /= d) * (t - 2) + b; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 │ │ │ │ │ + * Function: easeInOut │ │ │ │ │ * │ │ │ │ │ * 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 │ │ │ │ │ + * t - {Float} time │ │ │ │ │ + * b - {Float} beginning position │ │ │ │ │ + * c - {Float} total change │ │ │ │ │ + * d - {Float} duration of the transition │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + 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.StyleMap" │ │ │ │ │ -}); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Easing.Quad" │ │ │ │ │ +}; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Rule.js │ │ │ │ │ + OpenLayers/Projection.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Style.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Rule │ │ │ │ │ - * This class represents an SLD Rule, as being used for rule-based SLD styling. │ │ │ │ │ + * 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.Rule = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} A unique id for this session. │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} name of this rule │ │ │ │ │ - */ │ │ │ │ │ - name: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: title │ │ │ │ │ - * {String} Title of this rule (set if included in SLD) │ │ │ │ │ - */ │ │ │ │ │ - title: null, │ │ │ │ │ +OpenLayers.Projection = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: description │ │ │ │ │ - * {String} Description of this rule (set if abstract is included in SLD) │ │ │ │ │ + * Property: proj │ │ │ │ │ + * {Object} Proj4js.Proj instance. │ │ │ │ │ */ │ │ │ │ │ - description: null, │ │ │ │ │ + proj: 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. │ │ │ │ │ + * Property: projCode │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - context: null, │ │ │ │ │ + projCode: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: filter │ │ │ │ │ - * {} Optional filter for the rule. │ │ │ │ │ + * Property: titleRegEx │ │ │ │ │ + * {RegExp} regular expression to strip the title from a proj4js definition │ │ │ │ │ */ │ │ │ │ │ - filter: null, │ │ │ │ │ + titleRegEx: /\+title=[^\+]*/, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Constructor: OpenLayers.Projection │ │ │ │ │ + * This class offers several methods for interacting with a wrapped │ │ │ │ │ + * pro4js projection object. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * projCode - {String} A string identifying the Well Known Identifier for │ │ │ │ │ + * the projection. │ │ │ │ │ + * options - {Object} An optional object to set additional properties │ │ │ │ │ + * on the projection. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A projection object. │ │ │ │ │ */ │ │ │ │ │ - elseFilter: false, │ │ │ │ │ + initialize: function(projCode, options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.projCode = projCode; │ │ │ │ │ + if (typeof Proj4js == "object") { │ │ │ │ │ + this.proj = new Proj4js.Proj(projCode); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: getCode │ │ │ │ │ + * Get the string SRS code. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The SRS code. │ │ │ │ │ */ │ │ │ │ │ - symbolizer: null, │ │ │ │ │ + getCode: function() { │ │ │ │ │ + return this.proj ? this.proj.srsCode : this.projCode; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: getUnits │ │ │ │ │ + * Get the units string for the projection -- returns null if │ │ │ │ │ + * proj4js is not available. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The units abbreviation. │ │ │ │ │ */ │ │ │ │ │ - symbolizers: null, │ │ │ │ │ + getUnits: function() { │ │ │ │ │ + return this.proj ? this.proj.units : 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}" │ │ │ │ │ + * Method: toString │ │ │ │ │ + * Convert projection to string (getCode wrapper). │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The projection code. │ │ │ │ │ */ │ │ │ │ │ - minScaleDenominator: null, │ │ │ │ │ + toString: function() { │ │ │ │ │ + return this.getCode(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: equals │ │ │ │ │ + * Test equality of two projection instances. Determines equality based │ │ │ │ │ + * soley on the projection code. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object with properties to set on the │ │ │ │ │ - * rule │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * {Boolean} The two projections are equivalent. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.symbolizer = {}; │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - if (this.symbolizers) { │ │ │ │ │ - delete this.symbolizer; │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + return equals; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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/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/Projection.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Projection │ │ │ │ │ - * Methods for coordinate transforms between coordinate systems. By default, │ │ │ │ │ - * OpenLayers ships with the ability to transform coordinates between │ │ │ │ │ - * geographic (EPSG:4326) and web or spherical mercator (EPSG:900913 et al.) │ │ │ │ │ - * coordinate reference systems. See the method for details │ │ │ │ │ - * on usage. │ │ │ │ │ - * │ │ │ │ │ - * Additional transforms may be added by using the │ │ │ │ │ - * library. If the proj4js library is included, the method │ │ │ │ │ - * will work between any two coordinate reference systems with proj4js │ │ │ │ │ - * definitions. │ │ │ │ │ - * │ │ │ │ │ - * If the proj4js library is not included, or if you wish to allow transforms │ │ │ │ │ - * between arbitrary coordinate reference systems, use the │ │ │ │ │ - * method to register a custom transform method. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Projection = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: proj │ │ │ │ │ - * {Object} Proj4js.Proj instance. │ │ │ │ │ - */ │ │ │ │ │ - proj: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: projCode │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - projCode: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: titleRegEx │ │ │ │ │ - * {RegExp} regular expression to strip the title from a proj4js definition │ │ │ │ │ - */ │ │ │ │ │ - titleRegEx: /\+title=[^\+]*/, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Projection │ │ │ │ │ - * This class offers several methods for interacting with a wrapped │ │ │ │ │ - * pro4js projection object. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * projCode - {String} A string identifying the Well Known Identifier for │ │ │ │ │ - * the projection. │ │ │ │ │ - * options - {Object} An optional object to set additional properties │ │ │ │ │ - * on the projection. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A projection object. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(projCode, options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.projCode = projCode; │ │ │ │ │ - if (typeof Proj4js == "object") { │ │ │ │ │ - this.proj = new Proj4js.Proj(projCode); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCode │ │ │ │ │ - * Get the string SRS code. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The SRS code. │ │ │ │ │ - */ │ │ │ │ │ - getCode: function() { │ │ │ │ │ - return this.proj ? this.proj.srsCode : this.projCode; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getUnits │ │ │ │ │ - * Get the units string for the projection -- returns null if │ │ │ │ │ - * proj4js is not available. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The units abbreviation. │ │ │ │ │ - */ │ │ │ │ │ - getUnits: function() { │ │ │ │ │ - return this.proj ? this.proj.units : null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: toString │ │ │ │ │ - * Convert projection to string (getCode wrapper). │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The projection code. │ │ │ │ │ - */ │ │ │ │ │ - toString: function() { │ │ │ │ │ - return this.getCode(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: equals │ │ │ │ │ - * Test equality of two projection instances. Determines equality based │ │ │ │ │ - * soley on the projection code. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The two projections are equivalent. │ │ │ │ │ - */ │ │ │ │ │ - equals: function(projection) { │ │ │ │ │ - var p = projection, │ │ │ │ │ - equals = false; │ │ │ │ │ - if (p) { │ │ │ │ │ - if (!(p instanceof OpenLayers.Projection)) { │ │ │ │ │ - p = new OpenLayers.Projection(p); │ │ │ │ │ - } │ │ │ │ │ - if ((typeof Proj4js == "object") && this.proj.defData && p.proj.defData) { │ │ │ │ │ - equals = this.proj.defData.replace(this.titleRegEx, "") == │ │ │ │ │ - p.proj.defData.replace(this.titleRegEx, ""); │ │ │ │ │ - } else if (p.getCode) { │ │ │ │ │ - var source = this.getCode(), │ │ │ │ │ - target = p.getCode(); │ │ │ │ │ - equals = source == target || │ │ │ │ │ - !!OpenLayers.Projection.transforms[source] && │ │ │ │ │ - OpenLayers.Projection.transforms[source][target] === │ │ │ │ │ - OpenLayers.Projection.nullTransform; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return equals; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /* Method: destroy │ │ │ │ │ - * Destroy projection object. │ │ │ │ │ + /* Method: destroy │ │ │ │ │ + * Destroy projection object. │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ delete this.proj; │ │ │ │ │ delete this.projCode; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Projection" │ │ │ │ │ @@ -7630,2244 +6542,14 @@ │ │ │ │ │ } │ │ │ │ │ for (i = geographic.length - 1; i >= 0; --i) { │ │ │ │ │ map(geographic[i], mercator); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ })(); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - 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/Util/vendorPrefix.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/SingleFile.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Util = OpenLayers.Util || {}; │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Util.vendorPrefix │ │ │ │ │ - * A collection of utility functions to detect vendor prefixed features │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Util.vendorPrefix = (function() { │ │ │ │ │ - "use strict"; │ │ │ │ │ - │ │ │ │ │ - var VENDOR_PREFIXES = ["", "O", "ms", "Moz", "Webkit"], │ │ │ │ │ - divStyle = document.createElement("div").style, │ │ │ │ │ - cssCache = {}, │ │ │ │ │ - jsCache = {}; │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: domToCss │ │ │ │ │ - * Converts a upper camel case DOM style property name to a CSS property │ │ │ │ │ - * i.e. transformOrigin -> transform-origin │ │ │ │ │ - * or WebkitTransformOrigin -> -webkit-transform-origin │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * prefixedDom - {String} The property to convert │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The CSS property │ │ │ │ │ - */ │ │ │ │ │ - function domToCss(prefixedDom) { │ │ │ │ │ - if (!prefixedDom) { │ │ │ │ │ - return null; │ │ │ │ │ - } │ │ │ │ │ - return prefixedDom. │ │ │ │ │ - replace(/([A-Z])/g, function(c) { │ │ │ │ │ - return "-" + c.toLowerCase(); │ │ │ │ │ - }). │ │ │ │ │ - replace(/^ms-/, "-ms-"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: css │ │ │ │ │ - * Detect which property is used for a CSS property │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * property - {String} The standard (unprefixed) CSS property name │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The standard CSS property, prefixed property or null if not │ │ │ │ │ - * supported │ │ │ │ │ - */ │ │ │ │ │ - function css(property) { │ │ │ │ │ - if (cssCache[property] === undefined) { │ │ │ │ │ - var domProperty = property. │ │ │ │ │ - replace(/(-[\s\S])/g, function(c) { │ │ │ │ │ - return c.charAt(1).toUpperCase(); │ │ │ │ │ - }); │ │ │ │ │ - var prefixedDom = style(domProperty); │ │ │ │ │ - cssCache[property] = domToCss(prefixedDom); │ │ │ │ │ - } │ │ │ │ │ - return cssCache[property]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: js │ │ │ │ │ - * Detect which property is used for a JS property/method │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} The object to test on │ │ │ │ │ - * property - {String} The standard (unprefixed) JS property name │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The standard JS property, prefixed property or null if not │ │ │ │ │ - * supported │ │ │ │ │ - */ │ │ │ │ │ - function js(obj, property) { │ │ │ │ │ - if (jsCache[property] === undefined) { │ │ │ │ │ - var tmpProp, │ │ │ │ │ - i = 0, │ │ │ │ │ - l = VENDOR_PREFIXES.length, │ │ │ │ │ - prefix, │ │ │ │ │ - isStyleObj = (typeof obj.cssText !== "undefined"); │ │ │ │ │ - │ │ │ │ │ - jsCache[property] = null; │ │ │ │ │ - for (; i < l; i++) { │ │ │ │ │ - prefix = VENDOR_PREFIXES[i]; │ │ │ │ │ - if (prefix) { │ │ │ │ │ - if (!isStyleObj) { │ │ │ │ │ - // js prefix should be lower-case, while style │ │ │ │ │ - // properties have upper case on first character │ │ │ │ │ - prefix = prefix.toLowerCase(); │ │ │ │ │ - } │ │ │ │ │ - tmpProp = prefix + property.charAt(0).toUpperCase() + property.slice(1); │ │ │ │ │ - } else { │ │ │ │ │ - tmpProp = property; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (obj[tmpProp] !== undefined) { │ │ │ │ │ - jsCache[property] = tmpProp; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return jsCache[property]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: style │ │ │ │ │ - * Detect which property is used for a DOM style property │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * property - {String} The standard (unprefixed) style property name │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The standard style property, prefixed property or null if not │ │ │ │ │ - * supported │ │ │ │ │ - */ │ │ │ │ │ - function style(property) { │ │ │ │ │ - return js(divStyle, property); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - css: css, │ │ │ │ │ - js: js, │ │ │ │ │ - style: style, │ │ │ │ │ - │ │ │ │ │ - // used for testing │ │ │ │ │ - cssCache: cssCache, │ │ │ │ │ - jsCache: jsCache │ │ │ │ │ - }; │ │ │ │ │ -}()); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Events.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Event │ │ │ │ │ - * Utility functions for event handling. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Event = { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: observers │ │ │ │ │ - * {Object} A hashtable cache of the event observers. Keyed by │ │ │ │ │ - * element._eventCacheID │ │ │ │ │ - */ │ │ │ │ │ - observers: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_SPACE │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_SPACE: 32, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_BACKSPACE │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_BACKSPACE: 8, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_TAB │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_TAB: 9, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_RETURN │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_RETURN: 13, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_ESC │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_ESC: 27, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_LEFT │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_LEFT: 37, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_UP │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_UP: 38, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_RIGHT │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_RIGHT: 39, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_DOWN │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_DOWN: 40, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_DELETE │ │ │ │ │ - * {int} │ │ │ │ │ - */ │ │ │ │ │ - KEY_DELETE: 46, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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))); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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))); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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) { │ │ │ │ │ - │ │ │ │ │ - if (!allowDefault) { │ │ │ │ │ - OpenLayers.Event.preventDefault(event); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (event.stopPropagation) { │ │ │ │ │ - event.stopPropagation(); │ │ │ │ │ - } else { │ │ │ │ │ - event.cancelBubble = true; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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 (name == 'keypress' && │ │ │ │ │ - (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || │ │ │ │ │ - element.attachEvent)) { │ │ │ │ │ - name = 'keydown'; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //if observers cache has not yet been created, create it │ │ │ │ │ - if (!this.observers) { │ │ │ │ │ - this.observers = {}; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //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); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var cacheID = element._eventCacheID; │ │ │ │ │ - │ │ │ │ │ - //if there is not yet a hash entry for this element, add one │ │ │ │ │ - if (!this.observers[cacheID]) { │ │ │ │ │ - this.observers[cacheID] = []; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //add a new observer to this element's list │ │ │ │ │ - this.observers[cacheID].push({ │ │ │ │ │ - 'element': element, │ │ │ │ │ - 'name': name, │ │ │ │ │ - 'observer': observer, │ │ │ │ │ - 'useCapture': useCapture │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - //add the actual browser event listener │ │ │ │ │ - if (element.addEventListener) { │ │ │ │ │ - element.addEventListener(name, observer, useCapture); │ │ │ │ │ - } else if (element.attachEvent) { │ │ │ │ │ - element.attachEvent('on' + name, observer); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - │ │ │ │ │ - this._removeElementObservers(OpenLayers.Event.observers[cacheID]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ - ]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - │ │ │ │ │ - var element = OpenLayers.Util.getElement(elementParam); │ │ │ │ │ - var cacheID = element._eventCacheID; │ │ │ │ │ - │ │ │ │ │ - if (name == 'keypress') { │ │ │ │ │ - if (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || │ │ │ │ │ - element.detachEvent) { │ │ │ │ │ - name = 'keydown'; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // 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]; │ │ │ │ │ - │ │ │ │ │ - if ((cacheEntry.name == name) && │ │ │ │ │ - (cacheEntry.observer == observer) && │ │ │ │ │ - (cacheEntry.useCapture == useCapture)) { │ │ │ │ │ - │ │ │ │ │ - elementObservers.splice(i, 1); │ │ │ │ │ - if (elementObservers.length == 0) { │ │ │ │ │ - delete OpenLayers.Event.observers[cacheID]; │ │ │ │ │ - } │ │ │ │ │ - foundEntry = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - i++; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //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; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Event" │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/* prevent memory leaks in IE */ │ │ │ │ │ -OpenLayers.Event.observe(window, 'unload', OpenLayers.Event.unloadCache, false); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Events │ │ │ │ │ - */ │ │ │ │ │ -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, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: extensionCount │ │ │ │ │ - * {Object} Keys are event types (like in ), values are the │ │ │ │ │ - * number of extension listeners for each event type. │ │ │ │ │ - */ │ │ │ │ │ - extensionCount: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clearMouseListener │ │ │ │ │ - * A version of that is bound to this instance so that │ │ │ │ │ - * it can be used with and │ │ │ │ │ - * . │ │ │ │ │ - */ │ │ │ │ │ - clearMouseListener: 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. │ │ │ │ │ - */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * 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/Animation.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/SingleFile.js │ │ │ │ │ - * @requires OpenLayers/Util/vendorPrefix.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Animation │ │ │ │ │ - * A collection of utility functions for executing methods that repaint a │ │ │ │ │ - * portion of the browser window. These methods take advantage of the │ │ │ │ │ - * browser's scheduled repaints where requestAnimationFrame is available. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Animation = (function(window) { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: isNative │ │ │ │ │ - * {Boolean} true if a native requestAnimationFrame function is available │ │ │ │ │ - */ │ │ │ │ │ - var requestAnimationFrame = OpenLayers.Util.vendorPrefix.js(window, "requestAnimationFrame"); │ │ │ │ │ - var isNative = !!(requestAnimationFrame); │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: requestFrame │ │ │ │ │ - * Schedule a function to be called at the next available animation frame. │ │ │ │ │ - * Uses the native method where available. Where requestAnimationFrame is │ │ │ │ │ - * not available, setTimeout will be called with a 16ms delay. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * callback - {Function} The function to be called at the next animation frame. │ │ │ │ │ - * element - {DOMElement} Optional element that visually bounds the animation. │ │ │ │ │ - */ │ │ │ │ │ - var requestFrame = (function() { │ │ │ │ │ - var request = window[requestAnimationFrame] || │ │ │ │ │ - function(callback, element) { │ │ │ │ │ - window.setTimeout(callback, 16); │ │ │ │ │ - }; │ │ │ │ │ - // bind to window to avoid illegal invocation of native function │ │ │ │ │ - return function(callback, element) { │ │ │ │ │ - request.apply(window, [callback, element]); │ │ │ │ │ - }; │ │ │ │ │ - })(); │ │ │ │ │ - │ │ │ │ │ - // private variables for animation loops │ │ │ │ │ - var counter = 0; │ │ │ │ │ - var loops = {}; │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: start │ │ │ │ │ - * Executes a method with in series for some │ │ │ │ │ - * duration. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * callback - {Function} The function to be called at the next animation frame. │ │ │ │ │ - * duration - {Number} Optional duration for the loop. If not provided, the │ │ │ │ │ - * animation loop will execute indefinitely. │ │ │ │ │ - * element - {DOMElement} Optional element that visually bounds the animation. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} Identifier for the animation loop. Used to stop animations with │ │ │ │ │ - * . │ │ │ │ │ - */ │ │ │ │ │ - function start(callback, duration, element) { │ │ │ │ │ - duration = duration > 0 ? duration : Number.POSITIVE_INFINITY; │ │ │ │ │ - var id = ++counter; │ │ │ │ │ - var start = +new Date; │ │ │ │ │ - loops[id] = function() { │ │ │ │ │ - if (loops[id] && +new Date - start <= duration) { │ │ │ │ │ - callback(); │ │ │ │ │ - if (loops[id]) { │ │ │ │ │ - requestFrame(loops[id], element); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - delete loops[id]; │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - requestFrame(loops[id], element); │ │ │ │ │ - return id; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: stop │ │ │ │ │ - * Terminates an animation loop started with . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {Number} Identifier returned from . │ │ │ │ │ - */ │ │ │ │ │ - function stop(id) { │ │ │ │ │ - delete loops[id]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - isNative: isNative, │ │ │ │ │ - requestFrame: requestFrame, │ │ │ │ │ - start: start, │ │ │ │ │ - stop: stop │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ -})(window); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Tween.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Animation.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Tween │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Tween = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: easing │ │ │ │ │ - * {(Function)} Easing equation used for the animation │ │ │ │ │ - * Defaultly set to OpenLayers.Easing.Expo.easeOut │ │ │ │ │ - */ │ │ │ │ │ - easing: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: begin │ │ │ │ │ - * {Object} Values to start the animation with │ │ │ │ │ - */ │ │ │ │ │ - begin: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: finish │ │ │ │ │ - * {Object} Values to finish the animation with │ │ │ │ │ - */ │ │ │ │ │ - finish: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: duration │ │ │ │ │ - * {int} duration of the tween (number of steps) │ │ │ │ │ - */ │ │ │ │ │ - duration: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: callbacks │ │ │ │ │ - * {Object} An object with start, eachStep and done properties whose values │ │ │ │ │ - * are functions to be call during the animation. They are passed the │ │ │ │ │ - * current computed value as argument. │ │ │ │ │ - */ │ │ │ │ │ - callbacks: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: time │ │ │ │ │ - * {int} Step counter │ │ │ │ │ - */ │ │ │ │ │ - time: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minFrameRate │ │ │ │ │ - * {Number} The minimum framerate for animations in frames per second. After │ │ │ │ │ - * each step, the time spent in the animation is compared to the calculated │ │ │ │ │ - * time at this frame rate. If the animation runs longer than the calculated │ │ │ │ │ - * time, the next step is skipped. Default is 30. │ │ │ │ │ - */ │ │ │ │ │ - minFrameRate: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: startTime │ │ │ │ │ - * {Number} The timestamp of the first execution step. Used for skipping │ │ │ │ │ - * frames │ │ │ │ │ - */ │ │ │ │ │ - startTime: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: animationId │ │ │ │ │ - * {int} Loop id returned by OpenLayers.Animation.start │ │ │ │ │ - */ │ │ │ │ │ - animationId: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: playing │ │ │ │ │ - * {Boolean} Tells if the easing is currently playing │ │ │ │ │ - */ │ │ │ │ │ - playing: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Tween │ │ │ │ │ - * Creates a Tween. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * easing - {(Function)} easing function method to use │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(easing) { │ │ │ │ │ - this.easing = (easing) ? easing : OpenLayers.Easing.Expo.easeOut; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: start │ │ │ │ │ - * Plays the Tween, and calls the callback method on each step │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * begin - {Object} values to start the animation with │ │ │ │ │ - * finish - {Object} values to finish the animation with │ │ │ │ │ - * duration - {int} duration of the tween (number of steps) │ │ │ │ │ - * options - {Object} hash of options (callbacks (start, eachStep, done), │ │ │ │ │ - * minFrameRate) │ │ │ │ │ - */ │ │ │ │ │ - start: function(begin, finish, duration, options) { │ │ │ │ │ - this.playing = true; │ │ │ │ │ - this.begin = begin; │ │ │ │ │ - this.finish = finish; │ │ │ │ │ - this.duration = duration; │ │ │ │ │ - this.callbacks = options.callbacks; │ │ │ │ │ - this.minFrameRate = options.minFrameRate || 30; │ │ │ │ │ - this.time = 0; │ │ │ │ │ - this.startTime = new Date().getTime(); │ │ │ │ │ - OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ - this.animationId = null; │ │ │ │ │ - if (this.callbacks && this.callbacks.start) { │ │ │ │ │ - this.callbacks.start.call(this, this.begin); │ │ │ │ │ - } │ │ │ │ │ - this.animationId = OpenLayers.Animation.start( │ │ │ │ │ - OpenLayers.Function.bind(this.play, this) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: stop │ │ │ │ │ - * Stops the Tween, and calls the done callback │ │ │ │ │ - * Doesn't do anything if animation is already finished │ │ │ │ │ - */ │ │ │ │ │ - stop: function() { │ │ │ │ │ - if (!this.playing) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.callbacks && this.callbacks.done) { │ │ │ │ │ - this.callbacks.done.call(this, this.finish); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Animation.stop(this.animationId); │ │ │ │ │ - this.animationId = null; │ │ │ │ │ - this.playing = false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: play │ │ │ │ │ - * Calls the appropriate easing method │ │ │ │ │ - */ │ │ │ │ │ - play: function() { │ │ │ │ │ - var value = {}; │ │ │ │ │ - for (var i in this.begin) { │ │ │ │ │ - var b = this.begin[i]; │ │ │ │ │ - var f = this.finish[i]; │ │ │ │ │ - if (b == null || f == null || isNaN(b) || isNaN(f)) { │ │ │ │ │ - throw new TypeError('invalid value for Tween'); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var c = f - b; │ │ │ │ │ - value[i] = this.easing.apply(this, [this.time, b, c, this.duration]); │ │ │ │ │ - } │ │ │ │ │ - this.time++; │ │ │ │ │ - │ │ │ │ │ - if (this.callbacks && this.callbacks.eachStep) { │ │ │ │ │ - // skip frames if frame rate drops below threshold │ │ │ │ │ - if ((new Date().getTime() - this.startTime) / this.time <= 1000 / this.minFrameRate) { │ │ │ │ │ - this.callbacks.eachStep.call(this, value); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.time > this.duration) { │ │ │ │ │ - this.stop(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Create empty functions for all easing methods. │ │ │ │ │ - */ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Tween" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Easing │ │ │ │ │ - * │ │ │ │ │ - * Credits: │ │ │ │ │ - * Easing Equations by Robert Penner, │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Easing = { │ │ │ │ │ - /** │ │ │ │ │ - * Create empty functions for all easing methods. │ │ │ │ │ - */ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Easing" │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Easing.Linear │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Easing.Linear = { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeIn │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeIn: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeInOut: function(t, b, c, d) { │ │ │ │ │ - return c * t / d + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Easing.Linear" │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Easing.Expo │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Easing.Expo = { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeIn │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeIn: function(t, b, c, d) { │ │ │ │ │ - return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeInOut: function(t, b, c, d) { │ │ │ │ │ - if (t == 0) return b; │ │ │ │ │ - if (t == d) return b + c; │ │ │ │ │ - if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b; │ │ │ │ │ - return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Easing.Expo" │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Namespace: OpenLayers.Easing.Quad │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Easing.Quad = { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeIn │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeIn: function(t, b, c, d) { │ │ │ │ │ - return c * (t /= d) * t + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeOut: function(t, b, c, d) { │ │ │ │ │ - return -c * (t /= d) * (t - 2) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Function: easeInOut │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * t - {Float} time │ │ │ │ │ - * b - {Float} beginning position │ │ │ │ │ - * c - {Float} total change │ │ │ │ │ - * d - {Float} duration of the transition │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - easeInOut: function(t, b, c, d) { │ │ │ │ │ - if ((t /= d / 2) < 1) return c / 2 * t * t + b; │ │ │ │ │ - return -c / 2 * ((--t) * (t - 2) - 1) + b; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Easing.Quad" │ │ │ │ │ -}; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ OpenLayers/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. */ │ │ │ │ │ @@ -12775,6895 +9457,2715 @@ │ │ │ │ │ OpenLayers.Map.TILE_WIDTH = 256; │ │ │ │ │ /** │ │ │ │ │ * Constant: TILE_HEIGHT │ │ │ │ │ * {Integer} 256 Default tile height (unless otherwise specified) │ │ │ │ │ */ │ │ │ │ │ OpenLayers.Map.TILE_HEIGHT = 256; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer.js │ │ │ │ │ + OpenLayers/Icon.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Map.js │ │ │ │ │ - * @requires OpenLayers/Projection.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer │ │ │ │ │ + * 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.Layer = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Icon = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: id │ │ │ │ │ - * {String} │ │ │ │ │ + /** │ │ │ │ │ + * Property: url │ │ │ │ │ + * {String} image url │ │ │ │ │ */ │ │ │ │ │ - id: null, │ │ │ │ │ + url: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} │ │ │ │ │ + * Property: size │ │ │ │ │ + * {|Object} An OpenLayers.Size or │ │ │ │ │ + * an object with a 'w' and 'h' properties. │ │ │ │ │ */ │ │ │ │ │ - name: null, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: div │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - div: null, │ │ │ │ │ + offset: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: opacity │ │ │ │ │ - * {Float} The layer's opacity. Float number between 0.0 and 1.0. Default │ │ │ │ │ - * is 1. │ │ │ │ │ + /** │ │ │ │ │ + * Property: calculateOffset │ │ │ │ │ + * {Function} Function to calculate the offset (based on the size) │ │ │ │ │ */ │ │ │ │ │ - opacity: 1, │ │ │ │ │ + calculateOffset: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: imageDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - alwaysInRange: null, │ │ │ │ │ + imageDiv: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: RESOLUTION_PROPERTIES │ │ │ │ │ - * {Array} The properties that are used for calculating resolutions │ │ │ │ │ - * information. │ │ │ │ │ + /** │ │ │ │ │ + * Property: px │ │ │ │ │ + * {|Object} An OpenLayers.Pixel or an object │ │ │ │ │ + * with a 'x' and 'y' properties. │ │ │ │ │ */ │ │ │ │ │ - RESOLUTION_PROPERTIES: [ │ │ │ │ │ - 'scales', 'resolutions', │ │ │ │ │ - 'maxScale', 'minScale', │ │ │ │ │ - 'maxResolution', 'minResolution', │ │ │ │ │ - 'numZoomLevels', 'maxZoomLevel' │ │ │ │ │ - ], │ │ │ │ │ + px: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * layer.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Listeners will be called with a reference to an event object. The │ │ │ │ │ - * properties of this event depends on exactly what happened. │ │ │ │ │ - * │ │ │ │ │ - * All event objects have at least the following properties: │ │ │ │ │ - * object - {Object} A reference to layer.events.object. │ │ │ │ │ - * element - {DOMElement} A reference to layer.events.element. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Icon │ │ │ │ │ + * Creates an icon, which is an image tag in a div. │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * 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} │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + initialize: function(url, size, offset, calculateOffset) { │ │ │ │ │ + this.url = url; │ │ │ │ │ + this.size = size || { │ │ │ │ │ + w: 20, │ │ │ │ │ + h: 20 │ │ │ │ │ + }; │ │ │ │ │ + this.offset = offset || { │ │ │ │ │ + x: -(this.size.w / 2), │ │ │ │ │ + y: -(this.size.h / 2) │ │ │ │ │ + }; │ │ │ │ │ + this.calculateOffset = calculateOffset; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: map │ │ │ │ │ - * {} This variable is set when the layer is added to │ │ │ │ │ - * the map, via the accessor function setMap(). │ │ │ │ │ - */ │ │ │ │ │ - map: null, │ │ │ │ │ + var id = OpenLayers.Util.createUniqueID("OL_Icon_"); │ │ │ │ │ + this.imageDiv = OpenLayers.Util.createAlphaImageDiv(id); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} Whether or not the layer is a base layer. This should be set │ │ │ │ │ - * individually by all subclasses. Default is false │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Nullify references and remove event listeners to prevent circular │ │ │ │ │ + * references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: false, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + // erase any drawn elements │ │ │ │ │ + this.erase(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: alpha │ │ │ │ │ - * {Boolean} The layer's images have an alpha channel. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - alpha: false, │ │ │ │ │ + OpenLayers.Event.stopObservingElement(this.imageDiv.firstChild); │ │ │ │ │ + this.imageDiv.innerHTML = ""; │ │ │ │ │ + this.imageDiv = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displayInLayerSwitcher │ │ │ │ │ - * {Boolean} Display the layer's name in the layer switcher. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * Method: clone │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A fresh copy of the icon. │ │ │ │ │ */ │ │ │ │ │ - displayInLayerSwitcher: true, │ │ │ │ │ + clone: function() { │ │ │ │ │ + return new OpenLayers.Icon(this.url, │ │ │ │ │ + this.size, │ │ │ │ │ + this.offset, │ │ │ │ │ + this.calculateOffset); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: visibility │ │ │ │ │ - * {Boolean} The layer should be displayed in the map. Default is true. │ │ │ │ │ + * Method: setSize │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * size - {|Object} An OpenLayers.Size or │ │ │ │ │ + * an object with a 'w' and 'h' properties. │ │ │ │ │ */ │ │ │ │ │ - visibility: true, │ │ │ │ │ + setSize: function(size) { │ │ │ │ │ + if (size != null) { │ │ │ │ │ + this.size = size; │ │ │ │ │ + } │ │ │ │ │ + this.draw(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: attribution │ │ │ │ │ - * {String} Attribution string, displayed when an │ │ │ │ │ - * has been added to the map. │ │ │ │ │ + * Method: setUrl │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * url - {String} │ │ │ │ │ */ │ │ │ │ │ - attribution: null, │ │ │ │ │ + setUrl: function(url) { │ │ │ │ │ + if (url != null) { │ │ │ │ │ + this.url = url; │ │ │ │ │ + } │ │ │ │ │ + this.draw(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - imageSize: null, │ │ │ │ │ - │ │ │ │ │ - // OPTIONS │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + this.size, │ │ │ │ │ + this.url, │ │ │ │ │ + "absolute"); │ │ │ │ │ + this.moveTo(px); │ │ │ │ │ + return this.imageDiv; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: erase │ │ │ │ │ + * Erase the underlying image element. │ │ │ │ │ */ │ │ │ │ │ - options: null, │ │ │ │ │ + erase: function() { │ │ │ │ │ + if (this.imageDiv != null && this.imageDiv.parentNode != null) { │ │ │ │ │ + OpenLayers.Element.remove(this.imageDiv); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Method: setOpacity │ │ │ │ │ + * Change the icon's opacity │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * opacity - {float} │ │ │ │ │ */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, null, null, │ │ │ │ │ + null, null, null, null, opacity); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - projection: null, │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + //if no px passed in, use stored location │ │ │ │ │ + if (px != null) { │ │ │ │ │ + this.px = px; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + if (this.imageDiv != null) { │ │ │ │ │ + if (this.px == null) { │ │ │ │ │ + this.display(false); │ │ │ │ │ + } else { │ │ │ │ │ + if (this.calculateOffset) { │ │ │ │ │ + this.offset = this.calculateOffset(this.size); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, { │ │ │ │ │ + x: this.px.x + this.offset.x, │ │ │ │ │ + y: this.px.y + this.offset.y │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: 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. │ │ │ │ │ + /** │ │ │ │ │ + * Method: display │ │ │ │ │ + * Hide or show the icon │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - scales: null, │ │ │ │ │ + display: function(display) { │ │ │ │ │ + this.imageDiv.style.display = (display) ? "" : "none"; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: isDrawn │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the icon is drawn. │ │ │ │ │ */ │ │ │ │ │ - minExtent: null, │ │ │ │ │ + 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)); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + return isDrawn; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: minResolution │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - minResolution: null, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Icon" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: numZoomLevels │ │ │ │ │ - * {Integer} │ │ │ │ │ - */ │ │ │ │ │ - numZoomLevels: 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: minScale │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - minScale: null, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxScale │ │ │ │ │ - * {Float} │ │ │ │ │ - */ │ │ │ │ │ - maxScale: null, │ │ │ │ │ +/** │ │ │ │ │ + * 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: displayOutsideMaxExtent │ │ │ │ │ - * {Boolean} Request map tiles that are completely outside of the max │ │ │ │ │ - * extent for this layer. Defaults to false. │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique identifier for this geometry. │ │ │ │ │ */ │ │ │ │ │ - displayOutsideMaxExtent: false, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: parent │ │ │ │ │ + * {}This is set when a Geometry is added as component │ │ │ │ │ + * of another geometry │ │ │ │ │ */ │ │ │ │ │ - wrapDateLine: false, │ │ │ │ │ + parent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: metadata │ │ │ │ │ - * {Object} This object can be used to store additional information on a │ │ │ │ │ - * layer object. │ │ │ │ │ + * Property: bounds │ │ │ │ │ + * {} The bounds of this geometry │ │ │ │ │ */ │ │ │ │ │ - metadata: null, │ │ │ │ │ + bounds: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} The layer name │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * Constructor: OpenLayers.Geometry │ │ │ │ │ + * Creates a geometry object. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, options) { │ │ │ │ │ - │ │ │ │ │ - this.metadata = {}; │ │ │ │ │ - │ │ │ │ │ - options = OpenLayers.Util.extend({}, options); │ │ │ │ │ - // make sure we respect alwaysInRange if set on the prototype │ │ │ │ │ - if (this.alwaysInRange != null) { │ │ │ │ │ - options.alwaysInRange = this.alwaysInRange; │ │ │ │ │ - } │ │ │ │ │ - this.addOptions(options); │ │ │ │ │ - │ │ │ │ │ - this.name = name; │ │ │ │ │ - │ │ │ │ │ - if (this.id == null) { │ │ │ │ │ - │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - │ │ │ │ │ - this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ - this.div.style.width = "100%"; │ │ │ │ │ - this.div.style.height = "100%"; │ │ │ │ │ - this.div.dir = "ltr"; │ │ │ │ │ - │ │ │ │ │ - this.events = new OpenLayers.Events(this, this.div); │ │ │ │ │ - if (this.eventListeners instanceof Object) { │ │ │ │ │ - this.events.on(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - } │ │ │ │ │ + initialize: function() { │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * 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 this geometry. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.id = null; │ │ │ │ │ + this.bounds = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {} The layer to be cloned │ │ │ │ │ - * │ │ │ │ │ + * 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 │ │ │ │ │ + * {} An exact clone of this geometry. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + clone: function() { │ │ │ │ │ + return new OpenLayers.Geometry(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: setBounds │ │ │ │ │ + * Set the bounds for this Geometry. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} the of the layer, representing the current state. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ */ │ │ │ │ │ - getOptions: function() { │ │ │ │ │ - var options = {}; │ │ │ │ │ - for (var o in this.options) { │ │ │ │ │ - options[o] = this[o]; │ │ │ │ │ + setBounds: function(bounds) { │ │ │ │ │ + if (bounds) { │ │ │ │ │ + this.bounds = bounds.clone(); │ │ │ │ │ } │ │ │ │ │ - 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. │ │ │ │ │ + /** │ │ │ │ │ + * Method: clearBounds │ │ │ │ │ + * Nullify this components bounds and that of its parent as well. │ │ │ │ │ */ │ │ │ │ │ - setName: function(newName) { │ │ │ │ │ - if (newName != this.name) { │ │ │ │ │ - this.name = newName; │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: this, │ │ │ │ │ - property: "name" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + clearBounds: function() { │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + if (this.parent) { │ │ │ │ │ + this.parent.clearBounds(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addOptions │ │ │ │ │ + * 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: │ │ │ │ │ - * 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. │ │ │ │ │ + * newBounds - {} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + extendBounds: function(newBounds) { │ │ │ │ │ + var bounds = this.getBounds(); │ │ │ │ │ + if (!bounds) { │ │ │ │ │ + this.setBounds(newBounds); │ │ │ │ │ + } else { │ │ │ │ │ + this.bounds.extend(newBounds); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: onMapResize │ │ │ │ │ - * This function can be implemented by subclasses │ │ │ │ │ + * APIMethod: getBounds │ │ │ │ │ + * Get the bounds for this Geometry. If bounds is not set, it │ │ │ │ │ + * is calculated again, this makes queries faster. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - onMapResize: function() { │ │ │ │ │ - //this function can be implemented by subclasses │ │ │ │ │ + getBounds: function() { │ │ │ │ │ + if (this.bounds == null) { │ │ │ │ │ + this.calculateBounds(); │ │ │ │ │ + } │ │ │ │ │ + return this.bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: redraw │ │ │ │ │ - * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The layer was redrawn. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: calculateBounds │ │ │ │ │ + * Recalculate the bounds for the geometry. │ │ │ │ │ */ │ │ │ │ │ - redraw: function() { │ │ │ │ │ - var redrawn = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - │ │ │ │ │ - // min/max Range may have changed │ │ │ │ │ - this.inRange = this.calculateInRange(); │ │ │ │ │ - │ │ │ │ │ - // map's center might not yet be set │ │ │ │ │ - var extent = this.getExtent(); │ │ │ │ │ - │ │ │ │ │ - if (extent && this.inRange && this.visibility) { │ │ │ │ │ - var zoomChanged = true; │ │ │ │ │ - this.moveTo(extent, zoomChanged, false); │ │ │ │ │ - this.events.triggerEvent("moveend", { │ │ │ │ │ - "zoomChanged": zoomChanged │ │ │ │ │ - }); │ │ │ │ │ - redrawn = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return redrawn; │ │ │ │ │ + calculateBounds: function() { │ │ │ │ │ + // │ │ │ │ │ + // This should be overridden by subclasses. │ │ │ │ │ + // │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: distanceTo │ │ │ │ │ + * Calculate the closest distance between two geometries (on the x-y plane). │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} Tells when zoom has changed, as layers have to │ │ │ │ │ - * do some init work in that case. │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - var display = this.visibility; │ │ │ │ │ - if (!this.isBaseLayer) { │ │ │ │ │ - display = display && this.inRange; │ │ │ │ │ - } │ │ │ │ │ - this.display(display); │ │ │ │ │ - }, │ │ │ │ │ + distanceTo: function(geometry, options) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveByPx │ │ │ │ │ - * Move the layer based on pixel vector. To be implemented by subclasses. │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * dx - {Number} The x coord of the displacement vector. │ │ │ │ │ - * dy - {Number} The y coord of the displacement vector. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - moveByPx: function(dx, dy) {}, │ │ │ │ │ + getVertices: function(nodes) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: atPoint │ │ │ │ │ + * Note - This is only an approximation based on the bounds of the │ │ │ │ │ + * geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ + var atPoint = false; │ │ │ │ │ + var bounds = this.getBounds(); │ │ │ │ │ + if ((bounds != null) && (lonlat != null)) { │ │ │ │ │ │ │ │ │ │ - this.initResolutions(); │ │ │ │ │ + var dX = (toleranceLon != null) ? toleranceLon : 0; │ │ │ │ │ + var dY = (toleranceLat != null) ? toleranceLat : 0; │ │ │ │ │ │ │ │ │ │ - if (!this.isBaseLayer) { │ │ │ │ │ - this.inRange = this.calculateInRange(); │ │ │ │ │ - var show = ((this.visibility) && (this.inRange)); │ │ │ │ │ - this.div.style.display = show ? "" : "none"; │ │ │ │ │ - } │ │ │ │ │ + var toleranceBounds = │ │ │ │ │ + new OpenLayers.Bounds(this.bounds.left - dX, │ │ │ │ │ + this.bounds.bottom - dY, │ │ │ │ │ + this.bounds.right + dX, │ │ │ │ │ + this.bounds.top + dY); │ │ │ │ │ │ │ │ │ │ - // deal with gutters │ │ │ │ │ - this.setTileSize(); │ │ │ │ │ + atPoint = toleranceBounds.containsLonLat(lonlat); │ │ │ │ │ } │ │ │ │ │ + return atPoint; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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) │ │ │ │ │ + * Method: getLength │ │ │ │ │ + * Calculate the length of this geometry. This method is defined in │ │ │ │ │ + * subclasses. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The size that the image should be, taking into │ │ │ │ │ - * account gutters. │ │ │ │ │ + * {Float} The length of the collection by summing its parts │ │ │ │ │ */ │ │ │ │ │ - getImageSize: function(bounds) { │ │ │ │ │ - return (this.imageSize || this.tileSize); │ │ │ │ │ + getLength: function() { │ │ │ │ │ + //to be overridden by geometries that actually have a length │ │ │ │ │ + // │ │ │ │ │ + return 0.0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setTileSize │ │ │ │ │ - * Set the tile size based on the map size. This also sets layer.imageSize │ │ │ │ │ - * or use by Tile.Image. │ │ │ │ │ + * Method: getArea │ │ │ │ │ + * Calculate the area of this geometry. This method is defined in subclasses. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * size - {} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The area of the collection by summing its parts │ │ │ │ │ */ │ │ │ │ │ - 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)); │ │ │ │ │ - } │ │ │ │ │ + getArea: function() { │ │ │ │ │ + //to be overridden by geometries that actually have an area │ │ │ │ │ + // │ │ │ │ │ + return 0.0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getVisibility │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ + * Calculate the centroid of this geometry. This method is defined in subclasses. │ │ │ │ │ + * │ │ │ │ │ * 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} │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - if (display != (this.div.style.display != "none")) { │ │ │ │ │ - this.div.style.display = (display && this.calculateInRange()) ? "block" : "none"; │ │ │ │ │ - } │ │ │ │ │ + getCentroid: function() { │ │ │ │ │ + return null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: calculateInRange │ │ │ │ │ - * │ │ │ │ │ + * Method: toString │ │ │ │ │ + * Returns a text representation of the geometry. If the WKT format is │ │ │ │ │ + * included in a build, this will be the Well-Known Text │ │ │ │ │ + * representation. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The 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. │ │ │ │ │ + * {String} String representation of this geometry. │ │ │ │ │ */ │ │ │ │ │ - calculateInRange: function() { │ │ │ │ │ - var inRange = false; │ │ │ │ │ - │ │ │ │ │ - if (this.alwaysInRange) { │ │ │ │ │ - inRange = true; │ │ │ │ │ + toString: function() { │ │ │ │ │ + var string; │ │ │ │ │ + if (OpenLayers.Format && OpenLayers.Format.WKT) { │ │ │ │ │ + string = OpenLayers.Format.WKT.prototype.write( │ │ │ │ │ + new OpenLayers.Feature.Vector(this) │ │ │ │ │ + ); │ │ │ │ │ } else { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - var resolution = this.map.getResolution(); │ │ │ │ │ - inRange = ((resolution >= this.minResolution) && │ │ │ │ │ - (resolution <= this.maxResolution)); │ │ │ │ │ - } │ │ │ │ │ + string = Object.prototype.toString.call(this); │ │ │ │ │ } │ │ │ │ │ - return inRange; │ │ │ │ │ + return string; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 │ │ │ │ │ - }); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Baselayer Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ + } │ │ │ │ │ + return geom; │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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); │ │ │ │ │ +/** │ │ │ │ │ + * 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; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // if we still don't have resolutions then attempt to calculate them │ │ │ │ │ - if (props.resolutions == null) { │ │ │ │ │ - props.resolutions = this.calculateResolutions(props); │ │ │ │ │ + } 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // 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); │ │ │ │ │ + } 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; │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - // 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); │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * 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; │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - if (props.resolutions) { │ │ │ │ │ +/** │ │ │ │ │ + * 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 │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - //sort resolutions array descendingly │ │ │ │ │ - props.resolutions.sort(function(a, b) { │ │ │ │ │ - return (b - a); │ │ │ │ │ - }); │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - // if we still don't have a 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]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.resolutions = props.resolutions; │ │ │ │ │ - if (this.resolutions) { │ │ │ │ │ - len = this.resolutions.length; │ │ │ │ │ - this.scales = new Array(len); │ │ │ │ │ - for (i = 0; i < len; i++) { │ │ │ │ │ - this.scales[i] = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ - this.resolutions[i], this.units); │ │ │ │ │ - } │ │ │ │ │ - this.numZoomLevels = len; │ │ │ │ │ - } │ │ │ │ │ - this.minResolution = minResolution; │ │ │ │ │ - if (minResolution) { │ │ │ │ │ - this.maxScale = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ - minResolution, this.units); │ │ │ │ │ - } │ │ │ │ │ - this.maxResolution = maxResolution; │ │ │ │ │ - if (maxResolution) { │ │ │ │ │ - this.minScale = OpenLayers.Util.getScaleFromResolution( │ │ │ │ │ - maxResolution, this.units); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Feature │ │ │ │ │ + * Features are combinations of geography and attributes. The OpenLayers.Feature │ │ │ │ │ + * class specifically combines a marker and a lonlat. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Feature = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: resolutionsFromScales │ │ │ │ │ - * Derive resolutions from scales. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * scales - {Array(Number)} Scales │ │ │ │ │ - * │ │ │ │ │ - * Returns │ │ │ │ │ - * {Array(Number)} Resolutions │ │ │ │ │ + /** │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateResolutions │ │ │ │ │ - * Calculate resolutions based on the provided properties. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * props - {Object} Properties │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array({Number})} Array of resolutions. │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - return resolutions; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: lonlat │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + lonlat: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getResolution │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The currently selected resolution of the map, taken from the │ │ │ │ │ - * resolutions array, indexed by current zoom level. │ │ │ │ │ + /** │ │ │ │ │ + * Property: data │ │ │ │ │ + * {Object} │ │ │ │ │ */ │ │ │ │ │ - getResolution: function() { │ │ │ │ │ - var zoom = this.map.getZoom(); │ │ │ │ │ - return this.getResolutionForZoom(zoom); │ │ │ │ │ - }, │ │ │ │ │ + data: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getExtent │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A Bounds object which represents the lon/lat │ │ │ │ │ - * bounds of the current viewPort. │ │ │ │ │ + * Property: marker │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - getExtent: function() { │ │ │ │ │ - // just use stock map calculateBounds function -- passing no arguments │ │ │ │ │ - // means it will user map's current center & resolution │ │ │ │ │ - // │ │ │ │ │ - return this.map.calculateBounds(); │ │ │ │ │ - }, │ │ │ │ │ + marker: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getZoomForExtent │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * extent - {} │ │ │ │ │ - * closest - {Boolean} Find the zoom level that most closely fits the │ │ │ │ │ - * specified bounds. Note that this may result in a zoom that does │ │ │ │ │ - * not exactly contain the entire extent. │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} The index of the zoomLevel (entry in the resolutions array) │ │ │ │ │ - * for the passed-in extent. We do this by calculating the ideal │ │ │ │ │ - * resolution for the given extent (based on the map size) and then │ │ │ │ │ - * calling getZoomForResolution(), passing along the 'closest' │ │ │ │ │ - * parameter. │ │ │ │ │ + * APIProperty: popupClass │ │ │ │ │ + * {} The class which will be used to instantiate │ │ │ │ │ + * a new Popup. Default is . │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + popupClass: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getDataExtent │ │ │ │ │ - * Calculates the max extent which includes all of the data for the layer. │ │ │ │ │ - * This function is to be implemented by subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Property: popup │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - getDataExtent: function() { │ │ │ │ │ - //to be implemented by subclasses │ │ │ │ │ - }, │ │ │ │ │ + popup: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getResolutionForZoom │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Feature │ │ │ │ │ + * Constructor for features. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * zoom - {Float} │ │ │ │ │ + * layer - {} │ │ │ │ │ + * lonlat - {} │ │ │ │ │ + * data - {Object} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} A suitable resolution for the specified zoom. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - getResolutionForZoom: function(zoom) { │ │ │ │ │ - zoom = Math.max(0, Math.min(zoom, this.resolutions.length - 1)); │ │ │ │ │ - var resolution; │ │ │ │ │ - if (this.map.fractionalZoom) { │ │ │ │ │ - var low = Math.floor(zoom); │ │ │ │ │ - var high = Math.ceil(zoom); │ │ │ │ │ - resolution = this.resolutions[low] - │ │ │ │ │ - ((zoom - low) * (this.resolutions[low] - this.resolutions[high])); │ │ │ │ │ - } else { │ │ │ │ │ - resolution = this.resolutions[Math.round(zoom)]; │ │ │ │ │ - } │ │ │ │ │ - return resolution; │ │ │ │ │ + initialize: function(layer, lonlat, data) { │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.lonlat = lonlat; │ │ │ │ │ + this.data = (data != null) ? data : {}; │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getZoomForResolution │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * resolution - {Float} │ │ │ │ │ - * closest - {Boolean} Find the zoom level that corresponds to the absolute │ │ │ │ │ - * closest resolution, which may result in a zoom whose corresponding │ │ │ │ │ - * resolution is actually smaller than we would have desired (if this │ │ │ │ │ - * is being called from a getZoomForExtent() call, then this means that │ │ │ │ │ - * the returned zoom index might not actually contain the entire │ │ │ │ │ - * extent specified... but it'll be close). │ │ │ │ │ - * Default is false. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} The index of the zoomLevel (entry in the resolutions array) │ │ │ │ │ - * that corresponds to the best fit resolution given the passed in │ │ │ │ │ - * value and the 'closest' specification. │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - getZoomForResolution: function(resolution, closest) { │ │ │ │ │ - var zoom, i, len; │ │ │ │ │ - if (this.map.fractionalZoom) { │ │ │ │ │ - var lowZoom = 0; │ │ │ │ │ - var highZoom = this.resolutions.length - 1; │ │ │ │ │ - var highRes = this.resolutions[lowZoom]; │ │ │ │ │ - var lowRes = this.resolutions[highZoom]; │ │ │ │ │ - var res; │ │ │ │ │ - for (i = 0, len = this.resolutions.length; i < len; ++i) { │ │ │ │ │ - res = this.resolutions[i]; │ │ │ │ │ - if (res >= resolution) { │ │ │ │ │ - highRes = res; │ │ │ │ │ - lowZoom = i; │ │ │ │ │ - } │ │ │ │ │ - if (res <= resolution) { │ │ │ │ │ - lowRes = res; │ │ │ │ │ - highZoom = i; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var dRes = highRes - lowRes; │ │ │ │ │ - if (dRes > 0) { │ │ │ │ │ - zoom = lowZoom + ((highRes - resolution) / dRes); │ │ │ │ │ - } else { │ │ │ │ │ - zoom = lowZoom; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - var diff; │ │ │ │ │ - var minDiff = Number.POSITIVE_INFINITY; │ │ │ │ │ - for (i = 0, len = this.resolutions.length; i < len; i++) { │ │ │ │ │ - if (closest) { │ │ │ │ │ - diff = Math.abs(this.resolutions[i] - resolution); │ │ │ │ │ - if (diff > minDiff) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - minDiff = diff; │ │ │ │ │ - } else { │ │ │ │ │ - if (this.resolutions[i] < resolution) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - zoom = Math.max(0, i - 1); │ │ │ │ │ } │ │ │ │ │ - return zoom; │ │ │ │ │ + // 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; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getLonLatFromViewPortPx │ │ │ │ │ + * Method: onScreen │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * viewPortPx - {|Object} An OpenLayers.Pixel or │ │ │ │ │ - * an object with a 'x' │ │ │ │ │ - * and 'y' properties. │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An OpenLayers.LonLat which is the passed-in │ │ │ │ │ - * view port , translated into lon/lat by the layer. │ │ │ │ │ + * {Boolean} Whether or not the feature is currently visible on screen │ │ │ │ │ + * (based on its 'lonlat' property) │ │ │ │ │ */ │ │ │ │ │ - getLonLatFromViewPortPx: function(viewPortPx) { │ │ │ │ │ - var lonlat = null; │ │ │ │ │ - var map = this.map; │ │ │ │ │ - if (viewPortPx != null && map.minPx) { │ │ │ │ │ - var res = map.getResolution(); │ │ │ │ │ - var maxExtent = map.getMaxExtent({ │ │ │ │ │ - restricted: true │ │ │ │ │ - }); │ │ │ │ │ - var lon = (viewPortPx.x - map.minPx.x) * res + maxExtent.left; │ │ │ │ │ - var lat = (map.minPx.y - viewPortPx.y) * res + maxExtent.top; │ │ │ │ │ - lonlat = new OpenLayers.LonLat(lon, lat); │ │ │ │ │ + onScreen: function() { │ │ │ │ │ │ │ │ │ │ - if (this.wrapDateLine) { │ │ │ │ │ - lonlat = lonlat.wrapDateLine(this.maxExtent); │ │ │ │ │ - } │ │ │ │ │ + var onScreen = false; │ │ │ │ │ + if ((this.layer != null) && (this.layer.map != null)) { │ │ │ │ │ + var screenBounds = this.layer.map.getExtent(); │ │ │ │ │ + onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ } │ │ │ │ │ - return lonlat; │ │ │ │ │ + return onScreen; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getViewPortPxFromLonLat │ │ │ │ │ - * Returns a pixel location given a map location. This method will return │ │ │ │ │ - * fractional pixel values. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {|Object} An OpenLayers.LonLat or │ │ │ │ │ - * an object with a 'lon' │ │ │ │ │ - * and 'lat' properties. │ │ │ │ │ + * Method: createMarker │ │ │ │ │ + * Based on the data associated with the Feature, create and return a marker object. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An which is the passed-in │ │ │ │ │ - * lonlat translated into view port pixels. │ │ │ │ │ - */ │ │ │ │ │ - getViewPortPxFromLonLat: function(lonlat, resolution) { │ │ │ │ │ - var px = null; │ │ │ │ │ - if (lonlat != null) { │ │ │ │ │ - resolution = resolution || this.map.getResolution(); │ │ │ │ │ - var extent = this.map.calculateBounds(null, resolution); │ │ │ │ │ - px = new OpenLayers.Pixel( │ │ │ │ │ - (1 / resolution * (lonlat.lon - extent.left)), │ │ │ │ │ - (1 / resolution * (extent.top - lonlat.lat)) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return px; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setOpacity │ │ │ │ │ - * Sets the opacity for the entire layer (all images) │ │ │ │ │ + * {} 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 │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * opacity - {Float} │ │ │ │ │ */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - if (opacity != this.opacity) { │ │ │ │ │ - this.opacity = opacity; │ │ │ │ │ - var childNodes = this.div.childNodes; │ │ │ │ │ - for (var i = 0, len = childNodes.length; i < len; ++i) { │ │ │ │ │ - var element = childNodes[i].firstChild || childNodes[i]; │ │ │ │ │ - var lastChild = childNodes[i].lastChild; │ │ │ │ │ - //TODO de-uglify this │ │ │ │ │ - if (lastChild && lastChild.nodeName.toLowerCase() === "iframe") { │ │ │ │ │ - element = lastChild.parentNode; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Util.modifyDOMElement(element, null, null, null, │ │ │ │ │ - null, null, null, opacity); │ │ │ │ │ - } │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: this, │ │ │ │ │ - property: "opacity" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + createMarker: function() { │ │ │ │ │ + │ │ │ │ │ + if (this.lonlat != null) { │ │ │ │ │ + this.marker = new OpenLayers.Marker(this.lonlat, this.data.icon); │ │ │ │ │ } │ │ │ │ │ + return this.marker; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getZIndex │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} the z-index of this layer │ │ │ │ │ + * Method: destroyMarker │ │ │ │ │ + * Destroys marker. │ │ │ │ │ + * If user overrides the createMarker() function, s/he should be able │ │ │ │ │ + * to also specify an alternative function for destroying it │ │ │ │ │ */ │ │ │ │ │ - getZIndex: function() { │ │ │ │ │ - return this.div.style.zIndex; │ │ │ │ │ + destroyMarker: function() { │ │ │ │ │ + this.marker.destroy(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setZIndex │ │ │ │ │ + * 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: │ │ │ │ │ - * zIndex - {Integer} │ │ │ │ │ - */ │ │ │ │ │ - setZIndex: function(zIndex) { │ │ │ │ │ - this.div.style.zIndex = zIndex; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: adjustBounds │ │ │ │ │ - * This function will take a bounds, and if wrapDateLine option is set │ │ │ │ │ - * on the layer, it will return a bounds which is wrapped around the │ │ │ │ │ - * world. We do not wrap for bounds which *cross* the │ │ │ │ │ - * maxExtent.left/right, only bounds which are entirely to the left │ │ │ │ │ - * or entirely to the right. │ │ │ │ │ + * 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 . │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ */ │ │ │ │ │ - adjustBounds: function(bounds) { │ │ │ │ │ + createPopup: function(closeBox) { │ │ │ │ │ │ │ │ │ │ - if (this.gutter) { │ │ │ │ │ - // Adjust the extent of a bounds in map units by the │ │ │ │ │ - // layer's gutter in pixels. │ │ │ │ │ - var mapGutter = this.gutter * this.map.getResolution(); │ │ │ │ │ - bounds = new OpenLayers.Bounds(bounds.left - mapGutter, │ │ │ │ │ - bounds.bottom - mapGutter, │ │ │ │ │ - bounds.right + mapGutter, │ │ │ │ │ - bounds.top + mapGutter); │ │ │ │ │ + if (this.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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.wrapDateLine) { │ │ │ │ │ - // wrap around the date line, within the limits of rounding error │ │ │ │ │ - var wrappingOptions = { │ │ │ │ │ - 'rightTolerance': this.getResolution(), │ │ │ │ │ - 'leftTolerance': this.getResolution() │ │ │ │ │ - }; │ │ │ │ │ - bounds = bounds.wrapDateLine(this.maxExtent, wrappingOptions); │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ } │ │ │ │ │ - return bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Feature" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/HTTPRequest.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/Layer.js │ │ │ │ │ + * @requires OpenLayers/Feature.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.HTTPRequest │ │ │ │ │ + * 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: │ │ │ │ │ - * - │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ +OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: URL_HASH_FACTOR │ │ │ │ │ - * {Float} Used to hash URL param strings for multi-WMS server selection. │ │ │ │ │ - * Set to the Golden Ratio per Knuth's recommendation. │ │ │ │ │ + * Property: fid │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - URL_HASH_FACTOR: (Math.sqrt(5) - 1) / 2, │ │ │ │ │ + fid: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: url │ │ │ │ │ - * {Array(String) or String} This is either an array of url strings or │ │ │ │ │ - * a single url string. │ │ │ │ │ + * APIProperty: geometry │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - url: null, │ │ │ │ │ + geometry: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: params │ │ │ │ │ - * {Object} Hashtable of key/value parameters │ │ │ │ │ + * APIProperty: attributes │ │ │ │ │ + * {Object} This object holds arbitrary, serializable properties that │ │ │ │ │ + * describe the feature. │ │ │ │ │ */ │ │ │ │ │ - params: null, │ │ │ │ │ + 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: reproject │ │ │ │ │ - * *Deprecated*. See http://docs.openlayers.org/library/spherical_mercator.html │ │ │ │ │ - * for information on the replacement for this functionality. │ │ │ │ │ - * {Boolean} Whether layer should reproject itself based on base layer │ │ │ │ │ - * locations. This allows reprojection onto commercial layers. │ │ │ │ │ - * Default is false: Most layers can't reproject, but layers │ │ │ │ │ - * which can create non-square geographic pixels can, like WMS. │ │ │ │ │ - * │ │ │ │ │ + * Property: state │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - reproject: false, │ │ │ │ │ + state: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: style │ │ │ │ │ + * {Object} │ │ │ │ │ + */ │ │ │ │ │ + style: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.HTTPRequest │ │ │ │ │ + * 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: │ │ │ │ │ - * name - {String} │ │ │ │ │ - * url - {Array(String) or String} │ │ │ │ │ - * params - {Object} │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * 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(name, url, params, options) { │ │ │ │ │ - OpenLayers.Layer.prototype.initialize.apply(this, [name, options]); │ │ │ │ │ - this.url = url; │ │ │ │ │ - if (!this.params) { │ │ │ │ │ - this.params = OpenLayers.Util.extend({}, params); │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - this.url = null; │ │ │ │ │ - this.params = null; │ │ │ │ │ - OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ + if (this.layer) { │ │ │ │ │ + this.layer.removeFeatures(this); │ │ │ │ │ + this.layer = null; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.geometry = null; │ │ │ │ │ + this.modified = null; │ │ │ │ │ + OpenLayers.Feature.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * obj - {Object} │ │ │ │ │ + * 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: │ │ │ │ │ - * {} An exact clone of this │ │ │ │ │ - * │ │ │ │ │ + * {Boolean} The feature is currently visible on screen (optionally │ │ │ │ │ + * based on its bounds if boundsOnly is true). │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.HTTPRequest(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.params, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ + return onScreen; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setUrl │ │ │ │ │ + /** │ │ │ │ │ + * 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: │ │ │ │ │ - * newUrl - {String} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The feature is currently displayed. │ │ │ │ │ */ │ │ │ │ │ - setUrl: function(newUrl) { │ │ │ │ │ - this.url = newUrl; │ │ │ │ │ + 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()); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: mergeNewParams │ │ │ │ │ + * Method: createMarker │ │ │ │ │ + * HACK - we need to decide if all vector features should be able to │ │ │ │ │ + * create markers │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newParams - {Object} │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ + * {} For now just returns null │ │ │ │ │ */ │ │ │ │ │ - mergeNewParams: function(newParams) { │ │ │ │ │ - this.params = OpenLayers.Util.extend(this.params, newParams); │ │ │ │ │ - var ret = this.redraw(); │ │ │ │ │ - if (this.map != null) { │ │ │ │ │ - this.map.events.triggerEvent("changelayer", { │ │ │ │ │ - layer: this, │ │ │ │ │ - property: "params" │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - return ret; │ │ │ │ │ + createMarker: function() { │ │ │ │ │ + return null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: redraw │ │ │ │ │ - * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * force - {Boolean} Force redraw by adding random parameter. │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * {Boolean} The layer was redrawn. │ │ │ │ │ + * {} For now just returns null │ │ │ │ │ */ │ │ │ │ │ - redraw: function(force) { │ │ │ │ │ - if (force) { │ │ │ │ │ - return this.mergeNewParams({ │ │ │ │ │ - "_olSalt": Math.random() │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - return OpenLayers.Layer.prototype.redraw.apply(this, []); │ │ │ │ │ - } │ │ │ │ │ + createPopup: function() { │ │ │ │ │ + return null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: selectUrl │ │ │ │ │ - * selectUrl() implements the standard floating-point multiplicative │ │ │ │ │ - * hash function described by Knuth, and hashes the contents of the │ │ │ │ │ - * given param string into a float between 0 and 1. This float is then │ │ │ │ │ - * scaled to the size of the provided urls array, and used to select │ │ │ │ │ - * a URL. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * paramString - {String} │ │ │ │ │ - * urls - {Array(String)} │ │ │ │ │ + * 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: │ │ │ │ │ - * {String} An entry from the urls array, deterministically selected based │ │ │ │ │ - * on the paramString. │ │ │ │ │ + * {Boolean} Whether or not the feature is at the specified location │ │ │ │ │ */ │ │ │ │ │ - selectUrl: function(paramString, urls) { │ │ │ │ │ - var product = 1; │ │ │ │ │ - for (var i = 0, len = paramString.length; i < len; i++) { │ │ │ │ │ - product *= paramString.charCodeAt(i) * this.URL_HASH_FACTOR; │ │ │ │ │ - product -= Math.floor(product); │ │ │ │ │ + atPoint: function(lonlat, toleranceLon, toleranceLat) { │ │ │ │ │ + var atPoint = false; │ │ │ │ │ + if (this.geometry) { │ │ │ │ │ + atPoint = this.geometry.atPoint(lonlat, toleranceLon, │ │ │ │ │ + toleranceLat); │ │ │ │ │ } │ │ │ │ │ - return urls[Math.floor(product * urls.length)]; │ │ │ │ │ + return atPoint; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getFullRequestString │ │ │ │ │ - * Combine url with layer's params and these newParams. │ │ │ │ │ - * │ │ │ │ │ - * does checking on the serverPath variable, allowing for cases when it │ │ │ │ │ - * is supplied with trailing ? or &, as well as cases where not. │ │ │ │ │ - * │ │ │ │ │ - * return in formatted string like this: │ │ │ │ │ - * "server?key1=value1&key2=value2&key3=value3" │ │ │ │ │ - * │ │ │ │ │ - * WARNING: The altUrl parameter is deprecated and will be removed in 3.0. │ │ │ │ │ + /** │ │ │ │ │ + * Method: 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: │ │ │ │ │ - * newParams - {Object} │ │ │ │ │ - * altUrl - {String} Use this as the url instead of the layer's url │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} │ │ │ │ │ + * location - { or } the │ │ │ │ │ + * location to which to move the feature. │ │ │ │ │ */ │ │ │ │ │ - getFullRequestString: function(newParams, altUrl) { │ │ │ │ │ - │ │ │ │ │ - // if not altUrl passed in, use layer's url │ │ │ │ │ - var url = altUrl || this.url; │ │ │ │ │ + move: function(location) { │ │ │ │ │ │ │ │ │ │ - // create a new params hashtable with all the layer params and the │ │ │ │ │ - // new params together. then convert to string │ │ │ │ │ - var allParams = OpenLayers.Util.extend({}, this.params); │ │ │ │ │ - allParams = OpenLayers.Util.extend(allParams, newParams); │ │ │ │ │ - var paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ + if (!this.layer || !this.geometry.move) { │ │ │ │ │ + //do nothing if no layer or immoveable geometry │ │ │ │ │ + return undefined; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // if url is not a string, it should be an array of strings, │ │ │ │ │ - // in which case we will deterministically select one of them in │ │ │ │ │ - // order to evenly distribute requests to different urls. │ │ │ │ │ - // │ │ │ │ │ - if (OpenLayers.Util.isArray(url)) { │ │ │ │ │ - url = this.selectUrl(paramsString, url); │ │ │ │ │ + var pixel; │ │ │ │ │ + if (location.CLASS_NAME == "OpenLayers.LonLat") { │ │ │ │ │ + pixel = this.layer.getViewPortPxFromLonLat(location); │ │ │ │ │ + } else { │ │ │ │ │ + pixel = location; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // ignore parameters that are already in the url search string │ │ │ │ │ - var urlParams = │ │ │ │ │ - OpenLayers.Util.upperCaseObject(OpenLayers.Util.getParameters(url)); │ │ │ │ │ - for (var key in allParams) { │ │ │ │ │ - if (key.toUpperCase() in urlParams) { │ │ │ │ │ - delete allParams[key]; │ │ │ │ │ + var 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; │ │ │ │ │ } │ │ │ │ │ - paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ - │ │ │ │ │ - return OpenLayers.Util.urlAppend(url, paramsString); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.HTTPRequest" │ │ │ │ │ + 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/Tile.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 │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Tile │ │ │ │ │ - * This is a class designed to designate a single tile, however │ │ │ │ │ - * it is explicitly designed to do relatively little. Tiles store │ │ │ │ │ - * information about themselves -- such as the URL that they are related │ │ │ │ │ - * to, and their size - but do not add themselves to the layer div │ │ │ │ │ - * automatically, for example. Create a new tile with the │ │ │ │ │ - * constructor, or a subclass. │ │ │ │ │ - * │ │ │ │ │ - * TBD 3.0 - remove reference to url in above paragraph │ │ │ │ │ - * │ │ │ │ │ + * 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.Tile = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Format = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} An events object that handles all │ │ │ │ │ - * events on the tile. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * tile.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types: │ │ │ │ │ - * beforedraw - Triggered before the tile is drawn. Used to defer │ │ │ │ │ - * drawing to an animation queue. To defer drawing, listeners need │ │ │ │ │ - * to return false, which will abort drawing. The queue handler needs │ │ │ │ │ - * to call (true) to actually draw the tile. │ │ │ │ │ - * loadstart - Triggered when tile loading starts. │ │ │ │ │ - * loadend - Triggered when tile loading ends. │ │ │ │ │ - * loaderror - Triggered before the loadend event (i.e. when the tile is │ │ │ │ │ - * still hidden) if the tile could not be loaded. │ │ │ │ │ - * reload - Triggered when an already loading tile is reloaded. │ │ │ │ │ - * unload - Triggered before a tile is unloaded. │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} A reference to options passed to the constructor. │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + 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. │ │ │ │ │ - * │ │ │ │ │ - * This options can be set in the ``tileOptions`` option from │ │ │ │ │ - * . For example, to be notified of the │ │ │ │ │ - * ``loadend`` event of each tiles: │ │ │ │ │ - * (code) │ │ │ │ │ - * new OpenLayers.Layer.OSM('osm', 'http://tile.openstreetmap.org/${z}/${x}/${y}.png', { │ │ │ │ │ - * tileOptions: { │ │ │ │ │ - * eventListeners: { │ │ │ │ │ - * 'loadend': function(evt) { │ │ │ │ │ - * // do something on loadend │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ + externalProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} null │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} layer the tile is attached to │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + internalProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: url │ │ │ │ │ - * {String} url of the request. │ │ │ │ │ - * │ │ │ │ │ - * TBD 3.0 │ │ │ │ │ - * Deprecated. The base tile class does not need an url. This should be │ │ │ │ │ - * handled in subclasses. Does not belong here. │ │ │ │ │ - */ │ │ │ │ │ - url: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: bounds │ │ │ │ │ - * {} null │ │ │ │ │ - */ │ │ │ │ │ - bounds: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {} null │ │ │ │ │ - */ │ │ │ │ │ - size: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: position │ │ │ │ │ - * {} Top Left pixel of the tile │ │ │ │ │ + * APIProperty: data │ │ │ │ │ + * {Object} When is true, this is the parsed string sent to │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - position: null, │ │ │ │ │ + data: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: isLoading │ │ │ │ │ - * {Boolean} Is the tile loading? │ │ │ │ │ - */ │ │ │ │ │ - isLoading: false, │ │ │ │ │ - │ │ │ │ │ - /** TBD 3.0 -- remove 'url' from the list of parameters to the constructor. │ │ │ │ │ - * there is no need for the base tile class to have a url. │ │ │ │ │ + * APIProperty: keepData │ │ │ │ │ + * {Object} Maintain a reference () to the most recently read data. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ + keepData: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Tile │ │ │ │ │ - * Constructor for a new instance. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format │ │ │ │ │ + * Instances of this class are not useful. See one of the subclasses. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} layer that the tile will go in. │ │ │ │ │ - * position - {} │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * url - {} │ │ │ │ │ - * size - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * 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(layer, position, bounds, url, size, options) { │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.position = position.clone(); │ │ │ │ │ - this.setBounds(bounds); │ │ │ │ │ - this.url = url; │ │ │ │ │ - if (size) { │ │ │ │ │ - this.size = size.clone(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //give the tile a unique id based on its BBOX. │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID("Tile_"); │ │ │ │ │ - │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ OpenLayers.Util.extend(this, options); │ │ │ │ │ - │ │ │ │ │ - this.events = new OpenLayers.Events(this); │ │ │ │ │ - if (this.eventListeners instanceof Object) { │ │ │ │ │ - this.events.on(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ + this.options = options; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: unload │ │ │ │ │ - * Call immediately before destroying if you are listening to tile │ │ │ │ │ - * events, so that counters are properly handled if tile is still │ │ │ │ │ - * loading at destroy-time. Will only fire an event if the tile is │ │ │ │ │ - * still loading. │ │ │ │ │ - */ │ │ │ │ │ - unload: function() { │ │ │ │ │ - if (this.isLoading) { │ │ │ │ │ - this.isLoading = false; │ │ │ │ │ - this.events.triggerEvent("unload"); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ * APIMethod: destroy │ │ │ │ │ - * Nullify references to prevent circular references and memory leaks. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.layer = null; │ │ │ │ │ - this.bounds = null; │ │ │ │ │ - this.size = null; │ │ │ │ │ - this.position = null; │ │ │ │ │ - │ │ │ │ │ - if (this.eventListeners) { │ │ │ │ │ - this.events.un(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.eventListeners = null; │ │ │ │ │ - this.events = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Clear whatever is currently in the tile, then return whether or not │ │ │ │ │ - * it should actually be re-drawn. This is an example implementation │ │ │ │ │ - * that can be overridden by subclasses. The minimum thing to do here │ │ │ │ │ - * is to call and return the result from . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * force - {Boolean} If true, the tile will not be cleared and no beforedraw │ │ │ │ │ - * event will be fired. This is used for drawing tiles asynchronously │ │ │ │ │ - * after drawing has been cancelled by returning false from a beforedraw │ │ │ │ │ - * listener. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Whether or not the tile should actually be drawn. Returns null │ │ │ │ │ - * if a beforedraw listener returned false. │ │ │ │ │ + * Clean up. │ │ │ │ │ */ │ │ │ │ │ - draw: function(force) { │ │ │ │ │ - if (!force) { │ │ │ │ │ - //clear tile's contents and mark as not drawn │ │ │ │ │ - this.clear(); │ │ │ │ │ - } │ │ │ │ │ - var draw = this.shouldDraw(); │ │ │ │ │ - if (draw && !force && this.events.triggerEvent("beforedraw") === false) { │ │ │ │ │ - draw = null; │ │ │ │ │ - } │ │ │ │ │ - return draw; │ │ │ │ │ - }, │ │ │ │ │ + destroy: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: shouldDraw │ │ │ │ │ - * Return whether or not the tile should actually be (re-)drawn. The only │ │ │ │ │ - * case where we *wouldn't* want to draw the tile is if the tile is outside │ │ │ │ │ - * its layer's maxExtent │ │ │ │ │ + * 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: │ │ │ │ │ - * {Boolean} Whether or not the tile should actually be drawn. │ │ │ │ │ + * Depends on the subclass │ │ │ │ │ */ │ │ │ │ │ - shouldDraw: function() { │ │ │ │ │ - var withinMaxExtent = false, │ │ │ │ │ - maxExtent = this.layer.maxExtent; │ │ │ │ │ - if (maxExtent) { │ │ │ │ │ - var map = this.layer.map; │ │ │ │ │ - var worldBounds = map.baseLayer.wrapDateLine && map.getMaxExtent(); │ │ │ │ │ - if (this.bounds.intersectsBounds(maxExtent, { │ │ │ │ │ - inclusive: false, │ │ │ │ │ - worldBounds: worldBounds │ │ │ │ │ - })) { │ │ │ │ │ - withinMaxExtent = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return withinMaxExtent || this.layer.displayOutsideMaxExtent; │ │ │ │ │ + read: function(data) { │ │ │ │ │ + throw new Error('Read not implemented.'); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setBounds │ │ │ │ │ - * Sets the bounds on this instance │ │ │ │ │ + * Method: write │ │ │ │ │ + * Accept an object, and return a string. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds {} │ │ │ │ │ - */ │ │ │ │ │ - setBounds: function(bounds) { │ │ │ │ │ - bounds = bounds.clone(); │ │ │ │ │ - if (this.layer.map.baseLayer.wrapDateLine) { │ │ │ │ │ - var worldExtent = this.layer.map.getMaxExtent(), │ │ │ │ │ - tolerance = this.layer.map.getResolution(); │ │ │ │ │ - bounds = bounds.wrapDateLine(worldExtent, { │ │ │ │ │ - leftTolerance: tolerance, │ │ │ │ │ - rightTolerance: tolerance │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - this.bounds = bounds; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Reposition the tile. │ │ │ │ │ + * object - {Object} Object to be serialized │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * position - {} │ │ │ │ │ - * redraw - {Boolean} Call draw method on tile after moving. │ │ │ │ │ - * Default is true │ │ │ │ │ - */ │ │ │ │ │ - moveTo: function(bounds, position, redraw) { │ │ │ │ │ - if (redraw == null) { │ │ │ │ │ - redraw = true; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.setBounds(bounds); │ │ │ │ │ - this.position = position.clone(); │ │ │ │ │ - if (redraw) { │ │ │ │ │ - this.draw(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clear │ │ │ │ │ - * Clear the tile of any bounds/position-related data so that it can │ │ │ │ │ - * be reused in a new location. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A string representation of the object. │ │ │ │ │ */ │ │ │ │ │ - clear: function(draw) { │ │ │ │ │ - // to be extended by subclasses │ │ │ │ │ + write: function(object) { │ │ │ │ │ + throw new Error('Write not implemented.'); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Tile" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Tile/Image.js │ │ │ │ │ + OpenLayers/Geometry/Point.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Tile.js │ │ │ │ │ - * @requires OpenLayers/Animation.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Geometry.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Tile.Image │ │ │ │ │ - * Instances of OpenLayers.Tile.Image are used to manage the image tiles │ │ │ │ │ - * used by various layers. Create a new image tile with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Geometry.Point │ │ │ │ │ + * Point geometry class. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} An events object that handles all │ │ │ │ │ - * events on the tile. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * tile.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to the events): │ │ │ │ │ - * beforeload - Triggered before an image is prepared for loading, when the │ │ │ │ │ - * url for the image is known already. Listeners may call on │ │ │ │ │ - * the tile instance. If they do so, that image will be used and no new │ │ │ │ │ - * one will be created. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: url │ │ │ │ │ - * {String} The URL of the image being requested. No default. Filled in by │ │ │ │ │ - * layer.getURL() function. May be modified by loadstart listeners. │ │ │ │ │ - */ │ │ │ │ │ - url: null, │ │ │ │ │ +OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: imgDiv │ │ │ │ │ - * {HTMLImageElement} The image for this tile. │ │ │ │ │ - */ │ │ │ │ │ - imgDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: frame │ │ │ │ │ - * {DOMElement} The image element is appended to the frame. Any gutter on │ │ │ │ │ - * the image will be hidden behind the frame. If no gutter is set, │ │ │ │ │ - * this will be null. │ │ │ │ │ + * APIProperty: x │ │ │ │ │ + * {float} │ │ │ │ │ */ │ │ │ │ │ - frame: null, │ │ │ │ │ + x: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: imageReloadAttempts │ │ │ │ │ - * {Integer} Attempts to load the image. │ │ │ │ │ - */ │ │ │ │ │ - imageReloadAttempts: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerAlphaHack │ │ │ │ │ - * {Boolean} True if the png alpha hack needs to be applied on the layer's div. │ │ │ │ │ - */ │ │ │ │ │ - layerAlphaHack: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: asyncRequestId │ │ │ │ │ - * {Integer} ID of an request to see if request is still valid. This is a │ │ │ │ │ - * number which increments by 1 for each asynchronous request. │ │ │ │ │ + * APIProperty: y │ │ │ │ │ + * {float} │ │ │ │ │ */ │ │ │ │ │ - asyncRequestId: null, │ │ │ │ │ + y: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxGetUrlLength │ │ │ │ │ - * {Number} If set, requests that would result in GET urls with more │ │ │ │ │ - * characters than the number provided will be made using form-encoded │ │ │ │ │ - * HTTP POST. It is good practice to avoid urls that are longer than 2048 │ │ │ │ │ - * characters. │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Point │ │ │ │ │ + * Construct a point geometry. │ │ │ │ │ * │ │ │ │ │ - * Caution: │ │ │ │ │ - * Older versions of Gecko based browsers (e.g. Firefox < 3.5) and most │ │ │ │ │ - * Opera versions do not fully support this option. On all browsers, │ │ │ │ │ - * transition effects are not supported if POST requests are used. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {float} │ │ │ │ │ + * y - {float} │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - maxGetUrlLength: null, │ │ │ │ │ + initialize: function(x, y) { │ │ │ │ │ + OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: canvasContext │ │ │ │ │ - * {CanvasRenderingContext2D} A canvas context associated with │ │ │ │ │ - * the tile image. │ │ │ │ │ - */ │ │ │ │ │ - canvasContext: null, │ │ │ │ │ + this.x = parseFloat(x); │ │ │ │ │ + this.y = parseFloat(y); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: crossOriginKeyword │ │ │ │ │ - * The value of the crossorigin keyword to use when loading images. This is │ │ │ │ │ - * only relevant when using for tiles from remote │ │ │ │ │ - * origins and should be set to either 'anonymous' or 'use-credentials' │ │ │ │ │ - * for servers that send Access-Control-Allow-Origin headers with their │ │ │ │ │ - * tiles. │ │ │ │ │ - */ │ │ │ │ │ - crossOriginKeyword: null, │ │ │ │ │ - │ │ │ │ │ - /** TBD 3.0 - reorder the parameters to the init function to remove │ │ │ │ │ - * URL. the getUrl() function on the layer gets called on │ │ │ │ │ - * each draw(), so no need to specify it here. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Tile.Image │ │ │ │ │ - * Constructor for a new instance. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} layer that the tile will go in. │ │ │ │ │ - * position - {} │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * url - {} Deprecated. Remove me in 3.0. │ │ │ │ │ - * size - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this OpenLayers.Geometry.Point │ │ │ │ │ */ │ │ │ │ │ - initialize: function(layer, position, bounds, url, size, options) { │ │ │ │ │ - OpenLayers.Tile.prototype.initialize.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - this.url = url; //deprecated remove me │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - this.layerAlphaHack = this.layer.alpha && OpenLayers.Util.alphaHack(); │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ │ │ │ │ │ - if (this.maxGetUrlLength != null || this.layer.gutter || this.layerAlphaHack) { │ │ │ │ │ - // only create frame if it's needed │ │ │ │ │ - this.frame = document.createElement("div"); │ │ │ │ │ - this.frame.style.position = "absolute"; │ │ │ │ │ - this.frame.style.overflow = "hidden"; │ │ │ │ │ - } │ │ │ │ │ - if (this.maxGetUrlLength != null) { │ │ │ │ │ - OpenLayers.Util.extend(this, OpenLayers.Tile.Image.IFrame); │ │ │ │ │ - } │ │ │ │ │ + return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + * Method: calculateBounds │ │ │ │ │ + * Create a new Bounds based on the lon/lat │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.imgDiv) { │ │ │ │ │ - this.clear(); │ │ │ │ │ - this.imgDiv = null; │ │ │ │ │ - this.frame = null; │ │ │ │ │ - } │ │ │ │ │ - // don't handle async requests any more │ │ │ │ │ - this.asyncRequestId = null; │ │ │ │ │ - OpenLayers.Tile.prototype.destroy.apply(this, arguments); │ │ │ │ │ + calculateBounds: function() { │ │ │ │ │ + this.bounds = new OpenLayers.Bounds(this.x, this.y, │ │ │ │ │ + this.x, this.y); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Check that a tile should be drawn, and draw it. │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * {Boolean} Was a tile drawn? Or null if a beforedraw listener returned │ │ │ │ │ - * false. │ │ │ │ │ - */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var shouldDraw = OpenLayers.Tile.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (shouldDraw) { │ │ │ │ │ - // The layer's reproject option is deprecated. │ │ │ │ │ - if (this.layer != this.layer.map.baseLayer && this.layer.reproject) { │ │ │ │ │ - // getBoundsFromBaseLayer is defined in deprecated.js. │ │ │ │ │ - this.bounds = this.getBoundsFromBaseLayer(this.position); │ │ │ │ │ - } │ │ │ │ │ - if (this.isLoading) { │ │ │ │ │ - //if we're already loading, send 'reload' instead of 'loadstart'. │ │ │ │ │ - this._loadEvent = "reload"; │ │ │ │ │ - } else { │ │ │ │ │ - this.isLoading = true; │ │ │ │ │ - this._loadEvent = "loadstart"; │ │ │ │ │ - } │ │ │ │ │ - this.renderTile(); │ │ │ │ │ - this.positionTile(); │ │ │ │ │ - } else if (shouldDraw === false) { │ │ │ │ │ - this.unload(); │ │ │ │ │ - } │ │ │ │ │ - return shouldDraw; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: renderTile │ │ │ │ │ - * Internal function to actually initialize the image tile, │ │ │ │ │ - * position it correctly, and set its url. │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - renderTile: function() { │ │ │ │ │ - if (this.layer.async) { │ │ │ │ │ - // Asynchronous image requests call the asynchronous getURL method │ │ │ │ │ - // on the layer to fetch an image that covers 'this.bounds'. │ │ │ │ │ - var id = this.asyncRequestId = (this.asyncRequestId || 0) + 1; │ │ │ │ │ - this.layer.getURLasync(this.bounds, function(url) { │ │ │ │ │ - if (id == this.asyncRequestId) { │ │ │ │ │ - this.url = url; │ │ │ │ │ - this.initImage(); │ │ │ │ │ - } │ │ │ │ │ - }, this); │ │ │ │ │ + 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 { │ │ │ │ │ - // synchronous image requests get the url immediately. │ │ │ │ │ - this.url = this.layer.getURL(this.bounds); │ │ │ │ │ - this.initImage(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: positionTile │ │ │ │ │ - * Using the properties currenty set on the layer, position the tile correctly. │ │ │ │ │ - * This method is used both by the async and non-async versions of the Tile.Image │ │ │ │ │ - * code. │ │ │ │ │ - */ │ │ │ │ │ - positionTile: function() { │ │ │ │ │ - var style = this.getTile().style, │ │ │ │ │ - size = this.frame ? this.size : │ │ │ │ │ - this.layer.getImageSize(this.bounds), │ │ │ │ │ - ratio = 1; │ │ │ │ │ - if (this.layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ - ratio = this.layer.getServerResolution() / this.layer.map.getResolution(); │ │ │ │ │ - } │ │ │ │ │ - style.left = this.position.x + "px"; │ │ │ │ │ - style.top = this.position.y + "px"; │ │ │ │ │ - style.width = Math.round(ratio * size.w) + "px"; │ │ │ │ │ - style.height = Math.round(ratio * size.h) + "px"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clear │ │ │ │ │ - * Remove the tile from the DOM, clear it of any image related data so that │ │ │ │ │ - * it can be reused in a new location. │ │ │ │ │ - */ │ │ │ │ │ - clear: function() { │ │ │ │ │ - OpenLayers.Tile.prototype.clear.apply(this, arguments); │ │ │ │ │ - var img = this.imgDiv; │ │ │ │ │ - if (img) { │ │ │ │ │ - var tile = this.getTile(); │ │ │ │ │ - if (tile.parentNode === this.layer.div) { │ │ │ │ │ - this.layer.div.removeChild(tile); │ │ │ │ │ - } │ │ │ │ │ - this.setImgSrc(); │ │ │ │ │ - if (this.layerAlphaHack === true) { │ │ │ │ │ - img.style.filter = ""; │ │ │ │ │ + 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 │ │ │ │ │ + }; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Element.removeClass(img, "olImageLoadError"); │ │ │ │ │ } │ │ │ │ │ - this.canvasContext = null; │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getImage │ │ │ │ │ - * Returns or creates and returns the tile image. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - getImage: function() { │ │ │ │ │ - if (!this.imgDiv) { │ │ │ │ │ - this.imgDiv = OpenLayers.Tile.Image.IMAGE.cloneNode(false); │ │ │ │ │ - │ │ │ │ │ - var style = this.imgDiv.style; │ │ │ │ │ - if (this.frame) { │ │ │ │ │ - var left = 0, │ │ │ │ │ - top = 0; │ │ │ │ │ - if (this.layer.gutter) { │ │ │ │ │ - left = this.layer.gutter / this.layer.tileSize.w * 100; │ │ │ │ │ - top = this.layer.gutter / this.layer.tileSize.h * 100; │ │ │ │ │ - } │ │ │ │ │ - style.left = -left + "%"; │ │ │ │ │ - style.top = -top + "%"; │ │ │ │ │ - style.width = (2 * left + 100) + "%"; │ │ │ │ │ - style.height = (2 * top + 100) + "%"; │ │ │ │ │ - } │ │ │ │ │ - style.visibility = "hidden"; │ │ │ │ │ - style.opacity = 0; │ │ │ │ │ - if (this.layer.opacity < 1) { │ │ │ │ │ - style.filter = 'alpha(opacity=' + │ │ │ │ │ - (this.layer.opacity * 100) + │ │ │ │ │ - ')'; │ │ │ │ │ - } │ │ │ │ │ - style.position = "absolute"; │ │ │ │ │ - if (this.layerAlphaHack) { │ │ │ │ │ - // move the image out of sight │ │ │ │ │ - style.paddingTop = style.height; │ │ │ │ │ - style.height = "0"; │ │ │ │ │ - style.width = "100%"; │ │ │ │ │ - } │ │ │ │ │ - if (this.frame) { │ │ │ │ │ - this.frame.appendChild(this.imgDiv); │ │ │ │ │ - } │ │ │ │ │ + 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 this.imgDiv; │ │ │ │ │ + return equals; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setImage │ │ │ │ │ - * Sets the image element for this tile. This method should only be called │ │ │ │ │ - * from beforeload listeners. │ │ │ │ │ + * Method: toShortString │ │ │ │ │ * │ │ │ │ │ - * Parameters │ │ │ │ │ - * img - {HTMLImageElement} The image to use for this tile. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} Shortened String representation of Point object. │ │ │ │ │ + * (ex. "5, 42") │ │ │ │ │ */ │ │ │ │ │ - setImage: function(img) { │ │ │ │ │ - this.imgDiv = img; │ │ │ │ │ + toShortString: function() { │ │ │ │ │ + return (this.x + ", " + this.y); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: initImage │ │ │ │ │ - * Creates the content for the frame on the tile. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - initImage: function() { │ │ │ │ │ - if (!this.url && !this.imgDiv) { │ │ │ │ │ - // fast path out - if there is no tile url and no previous image │ │ │ │ │ - this.isLoading = false; │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent('beforeload'); │ │ │ │ │ - this.layer.div.appendChild(this.getTile()); │ │ │ │ │ - this.events.triggerEvent(this._loadEvent); │ │ │ │ │ - var img = this.getImage(); │ │ │ │ │ - var src = img.getAttribute('src') || ''; │ │ │ │ │ - if (this.url && OpenLayers.Util.isEquivalentUrl(src, this.url)) { │ │ │ │ │ - this._loadTimeout = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(this.onImageLoad, this), 0 │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - this.stopLoading(); │ │ │ │ │ - if (this.crossOriginKeyword) { │ │ │ │ │ - img.removeAttribute("crossorigin"); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Event.observe(img, "load", │ │ │ │ │ - OpenLayers.Function.bind(this.onImageLoad, this) │ │ │ │ │ - ); │ │ │ │ │ - OpenLayers.Event.observe(img, "error", │ │ │ │ │ - OpenLayers.Function.bind(this.onImageError, this) │ │ │ │ │ - ); │ │ │ │ │ - this.imageReloadAttempts = 0; │ │ │ │ │ - this.setImgSrc(this.url); │ │ │ │ │ - } │ │ │ │ │ + move: function(x, y) { │ │ │ │ │ + this.x = this.x + x; │ │ │ │ │ + this.y = this.y + y; │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setImgSrc │ │ │ │ │ - * Sets the source for the tile image │ │ │ │ │ + * APIMethod: rotate │ │ │ │ │ + * Rotate a point around another. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * url - {String} or undefined to hide the image │ │ │ │ │ + * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ + * from the positive x-axis) │ │ │ │ │ + * origin - {} Center point for the rotation │ │ │ │ │ */ │ │ │ │ │ - setImgSrc: function(url) { │ │ │ │ │ - var img = this.imgDiv; │ │ │ │ │ - if (url) { │ │ │ │ │ - img.style.visibility = 'hidden'; │ │ │ │ │ - img.style.opacity = 0; │ │ │ │ │ - // don't set crossOrigin if the url is a data URL │ │ │ │ │ - if (this.crossOriginKeyword) { │ │ │ │ │ - if (url.substr(0, 5) !== 'data:') { │ │ │ │ │ - img.setAttribute("crossorigin", this.crossOriginKeyword); │ │ │ │ │ - } else { │ │ │ │ │ - img.removeAttribute("crossorigin"); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - img.src = url; │ │ │ │ │ - } else { │ │ │ │ │ - // Remove reference to the image, and leave it to the browser's │ │ │ │ │ - // caching and garbage collection. │ │ │ │ │ - this.stopLoading(); │ │ │ │ │ - this.imgDiv = null; │ │ │ │ │ - if (img.parentNode) { │ │ │ │ │ - img.parentNode.removeChild(img); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTile │ │ │ │ │ - * Get the tile's markup. │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} The tile's markup │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - getTile: function() { │ │ │ │ │ - return this.frame ? this.frame : this.getImage(); │ │ │ │ │ + getCentroid: function() { │ │ │ │ │ + return new OpenLayers.Geometry.Point(this.x, this.y); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createBackBuffer │ │ │ │ │ - * Create a backbuffer for this tile. A backbuffer isn't exactly a clone │ │ │ │ │ - * of the tile's markup, because we want to avoid the reloading of the │ │ │ │ │ - * image. So we clone the frame, and steal the image from the tile. │ │ │ │ │ + * APIMethod: 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: │ │ │ │ │ - * {DOMElement} The markup, or undefined if the tile has no image │ │ │ │ │ - * or if it's currently loading. │ │ │ │ │ + * {} - The current geometry. │ │ │ │ │ */ │ │ │ │ │ - createBackBuffer: function() { │ │ │ │ │ - if (!this.imgDiv || this.isLoading) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var backBuffer; │ │ │ │ │ - if (this.frame) { │ │ │ │ │ - backBuffer = this.frame.cloneNode(false); │ │ │ │ │ - backBuffer.appendChild(this.imgDiv); │ │ │ │ │ - } else { │ │ │ │ │ - backBuffer = this.imgDiv; │ │ │ │ │ - } │ │ │ │ │ - this.imgDiv = null; │ │ │ │ │ - return backBuffer; │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onImageLoad │ │ │ │ │ - * Handler for the image onload event │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Determine if the input geometry intersects this one. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} Any type of geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The input geometry intersects this one. │ │ │ │ │ */ │ │ │ │ │ - onImageLoad: function() { │ │ │ │ │ - var img = this.imgDiv; │ │ │ │ │ - this.stopLoading(); │ │ │ │ │ - img.style.visibility = 'inherit'; │ │ │ │ │ - img.style.opacity = this.layer.opacity; │ │ │ │ │ - this.isLoading = false; │ │ │ │ │ - this.canvasContext = null; │ │ │ │ │ - this.events.triggerEvent("loadend"); │ │ │ │ │ - │ │ │ │ │ - if (this.layerAlphaHack === true) { │ │ │ │ │ - img.style.filter = │ │ │ │ │ - "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + │ │ │ │ │ - img.src + "', sizingMethod='scale')"; │ │ │ │ │ + intersects: function(geometry) { │ │ │ │ │ + var intersect = false; │ │ │ │ │ + if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + intersect = this.equals(geometry); │ │ │ │ │ + } else { │ │ │ │ │ + intersect = geometry.intersects(this); │ │ │ │ │ } │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onImageError │ │ │ │ │ - * Handler for the image onerror event │ │ │ │ │ + * APIMethod: transform │ │ │ │ │ + * Translate the x,y properties of the point from source to dest. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * source - {} │ │ │ │ │ + * dest - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - onImageError: function() { │ │ │ │ │ - var img = this.imgDiv; │ │ │ │ │ - if (img.src != null) { │ │ │ │ │ - this.imageReloadAttempts++; │ │ │ │ │ - if (this.imageReloadAttempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) { │ │ │ │ │ - this.setImgSrc(this.layer.getURL(this.bounds)); │ │ │ │ │ - } else { │ │ │ │ │ - OpenLayers.Element.addClass(img, "olImageLoadError"); │ │ │ │ │ - this.events.triggerEvent("loaderror"); │ │ │ │ │ - this.onImageLoad(); │ │ │ │ │ - } │ │ │ │ │ + transform: function(source, dest) { │ │ │ │ │ + if ((source && dest)) { │ │ │ │ │ + OpenLayers.Projection.transform( │ │ │ │ │ + this, source, dest); │ │ │ │ │ + this.bounds = null; │ │ │ │ │ } │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: stopLoading │ │ │ │ │ - * Stops a loading sequence so won't be executed. │ │ │ │ │ - */ │ │ │ │ │ - stopLoading: function() { │ │ │ │ │ - OpenLayers.Event.stopObservingElement(this.imgDiv); │ │ │ │ │ - window.clearTimeout(this._loadTimeout); │ │ │ │ │ - delete this._loadTimeout; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCanvasContext │ │ │ │ │ - * Returns a canvas context associated with the tile image (with │ │ │ │ │ - * the image drawn on it). │ │ │ │ │ - * Returns undefined if the browser does not support canvas, if │ │ │ │ │ - * the tile has no image or if it's currently loading. │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ - * The function returns a canvas context instance but the │ │ │ │ │ - * underlying canvas is still available in the 'canvas' property: │ │ │ │ │ - * (code) │ │ │ │ │ - * var context = tile.getCanvasContext(); │ │ │ │ │ - * if (context) { │ │ │ │ │ - * var data = context.canvas.toDataURL('image/jpeg'); │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * 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: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - getCanvasContext: function() { │ │ │ │ │ - if (OpenLayers.CANVAS_SUPPORTED && this.imgDiv && !this.isLoading) { │ │ │ │ │ - if (!this.canvasContext) { │ │ │ │ │ - var canvas = document.createElement("canvas"); │ │ │ │ │ - canvas.width = this.size.w; │ │ │ │ │ - canvas.height = this.size.h; │ │ │ │ │ - this.canvasContext = canvas.getContext("2d"); │ │ │ │ │ - this.canvasContext.drawImage(this.imgDiv, 0, 0); │ │ │ │ │ - } │ │ │ │ │ - return this.canvasContext; │ │ │ │ │ - } │ │ │ │ │ + getVertices: function(nodes) { │ │ │ │ │ + return [this]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Tile.Image" │ │ │ │ │ - │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Point" │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Tile.Image.IMAGE │ │ │ │ │ - * {HTMLImageElement} The image for a tile. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Tile.Image.IMAGE = (function() { │ │ │ │ │ - var img = new Image(); │ │ │ │ │ - img.className = "olTileImage"; │ │ │ │ │ - // avoid image gallery menu in IE6 │ │ │ │ │ - img.galleryImg = "no"; │ │ │ │ │ - return img; │ │ │ │ │ -}()); │ │ │ │ │ - │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/Grid.js │ │ │ │ │ + OpenLayers/Geometry/Collection.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Layer/HTTPRequest.js │ │ │ │ │ - * @requires OpenLayers/Tile/Image.js │ │ │ │ │ + * @requires OpenLayers/Geometry.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.Grid │ │ │ │ │ - * Base class for layers that use a lattice of tiles. Create a new grid │ │ │ │ │ - * layer with the constructor. │ │ │ │ │ + * 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.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileSize │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - tileSize: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileOriginCorner │ │ │ │ │ - * {String} If the property is not provided, the tile origin │ │ │ │ │ - * will be derived from the layer's . The corner of the │ │ │ │ │ - * used is determined by this property. Acceptable values │ │ │ │ │ - * are "tl" (top left), "tr" (top right), "bl" (bottom left), and "br" │ │ │ │ │ - * (bottom right). Default is "bl". │ │ │ │ │ - */ │ │ │ │ │ - tileOriginCorner: "bl", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileOrigin │ │ │ │ │ - * {} Optional origin for aligning the grid of tiles. │ │ │ │ │ - * If provided, requests for tiles at all resolutions will be aligned │ │ │ │ │ - * with this location (no tiles shall overlap this location). If │ │ │ │ │ - * not provided, the grid of tiles will be aligned with the layer's │ │ │ │ │ - * . Default is ``null``. │ │ │ │ │ - */ │ │ │ │ │ - tileOrigin: null, │ │ │ │ │ - │ │ │ │ │ - /** APIProperty: tileOptions │ │ │ │ │ - * {Object} optional configuration options for instances │ │ │ │ │ - * created by this Layer, if supported by the tile class. │ │ │ │ │ - */ │ │ │ │ │ - tileOptions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tileClass │ │ │ │ │ - * {} The tile class to use for this layer. │ │ │ │ │ - * Defaults is OpenLayers.Tile.Image. │ │ │ │ │ - */ │ │ │ │ │ - tileClass: OpenLayers.Tile.Image, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: grid │ │ │ │ │ - * {Array(Array())} This is an array of rows, each row is │ │ │ │ │ - * an array of tiles. │ │ │ │ │ - */ │ │ │ │ │ - grid: null, │ │ │ │ │ +OpenLayers.Geometry.Collection = OpenLayers.Class(OpenLayers.Geometry, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: singleTile │ │ │ │ │ - * {Boolean} Moves the layer into single-tile mode, meaning that one tile │ │ │ │ │ - * will be loaded. The tile's size will be determined by the 'ratio' │ │ │ │ │ - * property. When the tile is dragged such that it does not cover the │ │ │ │ │ - * entire viewport, it is reloaded. │ │ │ │ │ - */ │ │ │ │ │ - singleTile: false, │ │ │ │ │ - │ │ │ │ │ - /** APIProperty: ratio │ │ │ │ │ - * {Float} Used only when in single-tile mode, this specifies the │ │ │ │ │ - * ratio of the size of the single tile to the size of the map. │ │ │ │ │ - * Default value is 1.5. │ │ │ │ │ + * APIProperty: components │ │ │ │ │ + * {Array()} The component parts of this geometry │ │ │ │ │ */ │ │ │ │ │ - ratio: 1.5, │ │ │ │ │ + components: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: buffer │ │ │ │ │ - * {Integer} Used only when in gridded mode, this specifies the number of │ │ │ │ │ - * extra rows and colums of tiles on each side which will │ │ │ │ │ - * surround the minimum grid tiles to cover the map. │ │ │ │ │ - * For very slow loading layers, a larger value may increase │ │ │ │ │ - * performance somewhat when dragging, but will increase bandwidth │ │ │ │ │ - * use significantly. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - buffer: 0, │ │ │ │ │ + componentTypes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: transitionEffect │ │ │ │ │ - * {String} The transition effect to use when the map is zoomed. │ │ │ │ │ - * Two posible values: │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Collection │ │ │ │ │ + * Creates a Geometry Collection -- a list of geoms. │ │ │ │ │ * │ │ │ │ │ - * "resize" - Existing tiles are resized on zoom to provide a visual │ │ │ │ │ - * effect of the zoom having taken place immediately. As the │ │ │ │ │ - * new tiles become available, they are drawn on top of the │ │ │ │ │ - * resized tiles (this is the default setting). │ │ │ │ │ - * "map-resize" - Existing tiles are resized on zoom and placed below the │ │ │ │ │ - * base layer. New tiles for the base layer will cover existing tiles. │ │ │ │ │ - * This setting is recommended when having an overlay duplicated during │ │ │ │ │ - * the transition is undesirable (e.g. street labels or big transparent │ │ │ │ │ - * fills). │ │ │ │ │ - * null - No transition effect. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} Optional array of geometries │ │ │ │ │ * │ │ │ │ │ - * Using "resize" on non-opaque layers can cause undesired visual │ │ │ │ │ - * effects. Set transitionEffect to null in this case. │ │ │ │ │ - */ │ │ │ │ │ - transitionEffect: "resize", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: numLoadingTiles │ │ │ │ │ - * {Integer} How many tiles are still loading? │ │ │ │ │ - */ │ │ │ │ │ - numLoadingTiles: 0, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: serverResolutions │ │ │ │ │ - * {Array(Number}} This property is documented in subclasses as │ │ │ │ │ - * an API property. │ │ │ │ │ - */ │ │ │ │ │ - serverResolutions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: loading │ │ │ │ │ - * {Boolean} Indicates if tiles are being loaded. │ │ │ │ │ - */ │ │ │ │ │ - loading: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: backBuffer │ │ │ │ │ - * {DOMElement} The back buffer. │ │ │ │ │ - */ │ │ │ │ │ - backBuffer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: gridResolution │ │ │ │ │ - * {Number} The resolution of the current grid. Used for backbuffer and │ │ │ │ │ - * client zoom. This property is updated every time the grid is │ │ │ │ │ - * initialized. │ │ │ │ │ - */ │ │ │ │ │ - gridResolution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: backBufferResolution │ │ │ │ │ - * {Number} The resolution of the current back buffer. This property is │ │ │ │ │ - * updated each time a back buffer is created. │ │ │ │ │ */ │ │ │ │ │ - backBufferResolution: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: backBufferLonLat │ │ │ │ │ - * {Object} The top-left corner of the current back buffer. Includes lon │ │ │ │ │ - * and lat properties. This object is updated each time a back buffer │ │ │ │ │ - * is created. │ │ │ │ │ - */ │ │ │ │ │ - backBufferLonLat: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: backBufferTimerId │ │ │ │ │ - * {Number} The id of the back buffer timer. This timer is used to │ │ │ │ │ - * delay the removal of the back buffer, thereby preventing │ │ │ │ │ - * flash effects caused by tile animation. │ │ │ │ │ - */ │ │ │ │ │ - backBufferTimerId: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: removeBackBufferDelay │ │ │ │ │ - * {Number} Delay for removing the backbuffer when all tiles have finished │ │ │ │ │ - * loading. Can be set to 0 when no css opacity transitions for the │ │ │ │ │ - * olTileImage class are used. Default is 0 for layers, │ │ │ │ │ - * 2500 for tiled layers. See for more information on │ │ │ │ │ - * tile animation. │ │ │ │ │ - */ │ │ │ │ │ - removeBackBufferDelay: null, │ │ │ │ │ + initialize: function(components) { │ │ │ │ │ + OpenLayers.Geometry.prototype.initialize.apply(this, arguments); │ │ │ │ │ + this.components = []; │ │ │ │ │ + if (components != null) { │ │ │ │ │ + this.addComponents(components); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: className │ │ │ │ │ - * {String} Name of the class added to the layer div. If not set in the │ │ │ │ │ - * options passed to the constructor then className defaults to │ │ │ │ │ - * "olLayerGridSingleTile" for single tile layers (see ), │ │ │ │ │ - * and "olLayerGrid" for non single tile layers. │ │ │ │ │ - * │ │ │ │ │ - * Note: │ │ │ │ │ - * │ │ │ │ │ - * The displaying of tiles is not animated by default for single tile │ │ │ │ │ - * layers - OpenLayers' default theme (style.css) includes this: │ │ │ │ │ - * (code) │ │ │ │ │ - * .olLayerGrid .olTileImage { │ │ │ │ │ - * -webkit-transition: opacity 0.2s linear; │ │ │ │ │ - * -moz-transition: opacity 0.2s linear; │ │ │ │ │ - * -o-transition: opacity 0.2s linear; │ │ │ │ │ - * transition: opacity 0.2s linear; │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - * To animate tile displaying for any grid layer the following │ │ │ │ │ - * CSS rule can be used: │ │ │ │ │ - * (code) │ │ │ │ │ - * .olTileImage { │ │ │ │ │ - * -webkit-transition: opacity 0.2s linear; │ │ │ │ │ - * -moz-transition: opacity 0.2s linear; │ │ │ │ │ - * -o-transition: opacity 0.2s linear; │ │ │ │ │ - * transition: opacity 0.2s linear; │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - * In that case, to avoid flash effects, │ │ │ │ │ - * should not be zero. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Destroy this geometry. │ │ │ │ │ */ │ │ │ │ │ - className: null, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.components.length = 0; │ │ │ │ │ + this.components = null; │ │ │ │ │ + OpenLayers.Geometry.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clone this geometry. │ │ │ │ │ * │ │ │ │ │ - * Supported event types: │ │ │ │ │ - * addtile - Triggered when a tile is added to this layer. Listeners receive │ │ │ │ │ - * an object as first argument, which has a tile property that │ │ │ │ │ - * references the tile that has been added. │ │ │ │ │ - * tileloadstart - Triggered when a tile starts loading. Listeners receive │ │ │ │ │ - * an object as first argument, which has a tile property that │ │ │ │ │ - * references the tile that starts loading. │ │ │ │ │ - * tileloaded - Triggered when each new tile is │ │ │ │ │ - * loaded, as a means of progress update to listeners. │ │ │ │ │ - * listeners can access 'numLoadingTiles' if they wish to keep │ │ │ │ │ - * track of the loading progress. Listeners are called with an object │ │ │ │ │ - * with a 'tile' property as first argument, making the loaded tile │ │ │ │ │ - * available to the listener, and an 'aborted' property, which will be │ │ │ │ │ - * true when loading was aborted and no tile data is available. │ │ │ │ │ - * tileerror - Triggered before the tileloaded event (i.e. when the tile is │ │ │ │ │ - * still hidden) if a tile failed to load. Listeners receive an object │ │ │ │ │ - * as first argument, which has a tile property that references the │ │ │ │ │ - * tile that could not be loaded. │ │ │ │ │ - * retile - Triggered when the layer recreates its tile grid. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: gridLayout │ │ │ │ │ - * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ - * startrow │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this collection │ │ │ │ │ */ │ │ │ │ │ - gridLayout: null, │ │ │ │ │ + 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()); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: rowSign │ │ │ │ │ - * {Number} 1 for grids starting at the top, -1 for grids starting at the │ │ │ │ │ - * bottom. This is used for several grid index and offset calculations. │ │ │ │ │ - */ │ │ │ │ │ - rowSign: null, │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(geometry, this); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: transitionendEvents │ │ │ │ │ - * {Array} Event names for transitionend │ │ │ │ │ - */ │ │ │ │ │ - transitionendEvents: [ │ │ │ │ │ - 'transitionend', 'webkitTransitionEnd', 'otransitionend', │ │ │ │ │ - 'oTransitionEnd' │ │ │ │ │ - ], │ │ │ │ │ + return geometry; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.Grid │ │ │ │ │ - * Create a new grid layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - * url - {String} │ │ │ │ │ - * params - {Object} │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * Method: getComponentsString │ │ │ │ │ + * Get a string representing the components for this collection │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A string representation of the components of this geometry │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, params, options) { │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this, │ │ │ │ │ - arguments); │ │ │ │ │ - this.grid = []; │ │ │ │ │ - this._removeBackBuffer = OpenLayers.Function.bind(this.removeBackBuffer, this); │ │ │ │ │ - │ │ │ │ │ - this.initProperties(); │ │ │ │ │ - │ │ │ │ │ - this.rowSign = this.tileOriginCorner.substr(0, 1) === "t" ? 1 : -1; │ │ │ │ │ + getComponentsString: function() { │ │ │ │ │ + var strings = []; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + strings.push(this.components[i].toShortString()); │ │ │ │ │ + } │ │ │ │ │ + return strings.join(","); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: initProperties │ │ │ │ │ - * Set any properties that depend on the value of singleTile. │ │ │ │ │ - * Currently sets removeBackBufferDelay and className │ │ │ │ │ + * APIMethod: calculateBounds │ │ │ │ │ + * Recalculate the bounds by iterating through the components and │ │ │ │ │ + * calling calling extendBounds() on each item. │ │ │ │ │ */ │ │ │ │ │ - initProperties: function() { │ │ │ │ │ - if (this.options.removeBackBufferDelay === undefined) { │ │ │ │ │ - this.removeBackBufferDelay = this.singleTile ? 0 : 2500; │ │ │ │ │ + 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()); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - if (this.options.className === undefined) { │ │ │ │ │ - this.className = this.singleTile ? 'olLayerGridSingleTile' : │ │ │ │ │ - 'olLayerGrid'; │ │ │ │ │ + // 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); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ + * APIMethod: addComponents │ │ │ │ │ + * Add components to this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} The map. │ │ │ │ │ + * components - {Array()} An array of geometries to add │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.setMap.call(this, map); │ │ │ │ │ - OpenLayers.Element.addClass(this.div, this.className); │ │ │ │ │ + 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: removeMap │ │ │ │ │ - * Called when the layer is removed 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. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} The map. │ │ │ │ │ - */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Deconstruct the layer and clear the grid. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - this.clearGrid(); │ │ │ │ │ - │ │ │ │ │ - this.grid = null; │ │ │ │ │ - this.tileSize = null; │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: mergeNewParams │ │ │ │ │ - * Refetches tiles with new params merged, keeping a backbuffer. Each │ │ │ │ │ - * loading new tile will have a css class of '.olTileReplacing'. If a │ │ │ │ │ - * stylesheet applies a 'display: none' style to that class, any fade-in │ │ │ │ │ - * transition will not apply, and backbuffers for each tile will be removed │ │ │ │ │ - * as soon as the tile is loaded. │ │ │ │ │ + * The bounds cache is reset. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * newParams - {Object} │ │ │ │ │ + * component - {} A geometry to add │ │ │ │ │ + * index - {int} Optional index into the array to insert the component │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ + * {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)) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: clearGrid │ │ │ │ │ - * Go through and remove all tiles from the grid, calling │ │ │ │ │ - * destroy() on each of them to kill circular references │ │ │ │ │ - */ │ │ │ │ │ - clearGrid: function() { │ │ │ │ │ - if (this.grid) { │ │ │ │ │ - for (var iRow = 0, len = this.grid.length; iRow < len; iRow++) { │ │ │ │ │ - var row = this.grid[iRow]; │ │ │ │ │ - for (var iCol = 0, clen = row.length; iCol < clen; iCol++) { │ │ │ │ │ - var tile = row[iCol]; │ │ │ │ │ - this.destroyTile(tile); │ │ │ │ │ + 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.grid = []; │ │ │ │ │ - this.gridResolution = null; │ │ │ │ │ - this.gridLayout = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: addOptions │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newOptions - {Object} │ │ │ │ │ - * reinitialize - {Boolean} If set to true, and if resolution options of the │ │ │ │ │ - * current baseLayer were changed, the map will be recentered to make │ │ │ │ │ - * sure that it is displayed with a valid resolution, and a │ │ │ │ │ - * changebaselayer event will be triggered. │ │ │ │ │ - */ │ │ │ │ │ - addOptions: function(newOptions, reinitialize) { │ │ │ │ │ - var singleTileChanged = newOptions.singleTile !== undefined && │ │ │ │ │ - newOptions.singleTile !== this.singleTile; │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.addOptions.apply(this, arguments); │ │ │ │ │ - if (this.map && singleTileChanged) { │ │ │ │ │ - this.initProperties(); │ │ │ │ │ - this.clearGrid(); │ │ │ │ │ - this.tileSize = this.options.tileSize; │ │ │ │ │ - this.setTileSize(); │ │ │ │ │ - this.moveTo(null, true); │ │ │ │ │ } │ │ │ │ │ + return added; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a clone of this layer │ │ │ │ │ + * APIMethod: removeComponents │ │ │ │ │ + * Remove components from this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {Object} Is this ever used? │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this OpenLayers.Layer.Grid │ │ │ │ │ + * components - {Array()} The components to be removed │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} A component was removed. │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ + removeComponents: function(components) { │ │ │ │ │ + var removed = false; │ │ │ │ │ │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.Grid(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.params, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + if (!(OpenLayers.Util.isArray(components))) { │ │ │ │ │ + components = [components]; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ - if (this.tileSize != null) { │ │ │ │ │ - obj.tileSize = this.tileSize.clone(); │ │ │ │ │ + for (var i = components.length - 1; i >= 0; --i) { │ │ │ │ │ + removed = this.removeComponent(components[i]) || removed; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // we do not want to copy reference to grid, so we make a new array │ │ │ │ │ - obj.grid = []; │ │ │ │ │ - obj.gridResolution = null; │ │ │ │ │ - // same for backbuffer │ │ │ │ │ - obj.backBuffer = null; │ │ │ │ │ - obj.backBufferTimerId = null; │ │ │ │ │ - obj.loading = false; │ │ │ │ │ - obj.numLoadingTiles = 0; │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ + return removed; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * This function is called whenever the map is moved. All the moving │ │ │ │ │ - * of actual 'tiles' is done by the map, but moveTo's role is to accept │ │ │ │ │ - * a bounds and make sure the data that that bounds requires is pre-loaded. │ │ │ │ │ + * Method: removeComponent │ │ │ │ │ + * Remove a component from this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ + * component - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The component was removed. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - bounds = bounds || this.map.getExtent(); │ │ │ │ │ - │ │ │ │ │ - if (bounds != null) { │ │ │ │ │ - │ │ │ │ │ - // if grid is empty or zoom has changed, we *must* re-tile │ │ │ │ │ - var forceReTile = !this.grid.length || zoomChanged; │ │ │ │ │ - │ │ │ │ │ - // total bounds of the tiles │ │ │ │ │ - var tilesBounds = this.getTilesBounds(); │ │ │ │ │ - │ │ │ │ │ - // the new map resolution │ │ │ │ │ - var resolution = this.map.getResolution(); │ │ │ │ │ - │ │ │ │ │ - // the server-supported resolution for the new map resolution │ │ │ │ │ - var serverResolution = this.getServerResolution(resolution); │ │ │ │ │ - │ │ │ │ │ - if (this.singleTile) { │ │ │ │ │ - │ │ │ │ │ - // We want to redraw whenever even the slightest part of the │ │ │ │ │ - // current bounds is not contained by our tile. │ │ │ │ │ - // (thus, we do not specify partial -- its default is false) │ │ │ │ │ - │ │ │ │ │ - if (forceReTile || │ │ │ │ │ - (!dragging && !tilesBounds.containsBounds(bounds))) { │ │ │ │ │ - │ │ │ │ │ - // In single tile mode with no transition effect, we insert │ │ │ │ │ - // a non-scaled backbuffer when the layer is moved. But if │ │ │ │ │ - // a zoom occurs right after a move, i.e. before the new │ │ │ │ │ - // image is received, we need to remove the backbuffer, or │ │ │ │ │ - // an ill-positioned image will be visible during the zoom │ │ │ │ │ - // transition. │ │ │ │ │ - │ │ │ │ │ - if (zoomChanged && this.transitionEffect !== 'resize') { │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (!zoomChanged || this.transitionEffect === 'resize') { │ │ │ │ │ - this.applyBackBuffer(resolution); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.initSingleTile(bounds); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ + removeComponent: function(component) { │ │ │ │ │ │ │ │ │ │ - // if the bounds have changed such that they are not even │ │ │ │ │ - // *partially* contained by our tiles (e.g. when user has │ │ │ │ │ - // programmatically panned to the other side of the earth on │ │ │ │ │ - // zoom level 18), then moveGriddedTiles could potentially have │ │ │ │ │ - // to run through thousands of cycles, so we want to reTile │ │ │ │ │ - // instead (thus, partial true). │ │ │ │ │ - forceReTile = forceReTile || │ │ │ │ │ - !tilesBounds.intersectsBounds(bounds, { │ │ │ │ │ - worldBounds: this.map.baseLayer.wrapDateLine && │ │ │ │ │ - this.map.getMaxExtent() │ │ │ │ │ - }); │ │ │ │ │ + OpenLayers.Util.removeItem(this.components, component); │ │ │ │ │ │ │ │ │ │ - if (forceReTile) { │ │ │ │ │ - if (zoomChanged && (this.transitionEffect === 'resize' || │ │ │ │ │ - this.gridResolution === resolution)) { │ │ │ │ │ - this.applyBackBuffer(resolution); │ │ │ │ │ - } │ │ │ │ │ - this.initGriddedTiles(bounds); │ │ │ │ │ - } else { │ │ │ │ │ - this.moveGriddedTiles(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + // clearBounds() so that it gets recalculated on the next call │ │ │ │ │ + // to this.getBounds(); │ │ │ │ │ + this.clearBounds(); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTileData │ │ │ │ │ - * Given a map location, retrieve a tile and the pixel offset within that │ │ │ │ │ - * tile corresponding to the location. If there is not an existing │ │ │ │ │ - * tile in the grid that covers the given location, null will be │ │ │ │ │ - * returned. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * loc - {} map location │ │ │ │ │ + * APIMethod: getLength │ │ │ │ │ + * Calculate the length of this geometry │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} Object with the following properties: tile ({}), │ │ │ │ │ - * i ({Number} x-pixel offset from top left), and j ({Integer} y-pixel │ │ │ │ │ - * offset from top left). │ │ │ │ │ + * {Float} The length of the geometry │ │ │ │ │ */ │ │ │ │ │ - getTileData: function(loc) { │ │ │ │ │ - var data = null, │ │ │ │ │ - x = loc.lon, │ │ │ │ │ - y = loc.lat, │ │ │ │ │ - numRows = this.grid.length; │ │ │ │ │ - │ │ │ │ │ - if (this.map && numRows) { │ │ │ │ │ - var res = this.map.getResolution(), │ │ │ │ │ - tileWidth = this.tileSize.w, │ │ │ │ │ - tileHeight = this.tileSize.h, │ │ │ │ │ - bounds = this.grid[0][0].bounds, │ │ │ │ │ - left = bounds.left, │ │ │ │ │ - top = bounds.top; │ │ │ │ │ - │ │ │ │ │ - if (x < left) { │ │ │ │ │ - // deal with multiple worlds │ │ │ │ │ - if (this.map.baseLayer.wrapDateLine) { │ │ │ │ │ - var worldWidth = this.map.getMaxExtent().getWidth(); │ │ │ │ │ - var worldsAway = Math.ceil((left - x) / worldWidth); │ │ │ │ │ - x += worldWidth * worldsAway; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // tile distance to location (fractional number of tiles); │ │ │ │ │ - var dtx = (x - left) / (res * tileWidth); │ │ │ │ │ - var dty = (top - y) / (res * tileHeight); │ │ │ │ │ - // index of tile in grid │ │ │ │ │ - var col = Math.floor(dtx); │ │ │ │ │ - var row = Math.floor(dty); │ │ │ │ │ - if (row >= 0 && row < numRows) { │ │ │ │ │ - var tile = this.grid[row][col]; │ │ │ │ │ - if (tile) { │ │ │ │ │ - data = { │ │ │ │ │ - tile: tile, │ │ │ │ │ - // pixel index within tile │ │ │ │ │ - i: Math.floor((dtx - col) * tileWidth), │ │ │ │ │ - j: Math.floor((dty - row) * tileHeight) │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + getLength: function() { │ │ │ │ │ + var length = 0.0; │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + length += this.components[i].getLength(); │ │ │ │ │ } │ │ │ │ │ - return data; │ │ │ │ │ + return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyTile │ │ │ │ │ + * APIMethod: getArea │ │ │ │ │ + * Calculate the area of this geometry. Note how this function is overridden │ │ │ │ │ + * in . │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * tile - {} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The area of the collection by summing its parts │ │ │ │ │ */ │ │ │ │ │ - destroyTile: function(tile) { │ │ │ │ │ - this.removeTileMonitoringHooks(tile); │ │ │ │ │ - tile.destroy(); │ │ │ │ │ + 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: getServerResolution │ │ │ │ │ - * Return the closest server-supported resolution. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getGeodesicArea │ │ │ │ │ + * Calculate the approximate area of the polygon were it projected onto │ │ │ │ │ + * the earth. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * resolution - {Number} The base resolution. If undefined the │ │ │ │ │ - * map resolution is used. │ │ │ │ │ + * 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: │ │ │ │ │ - * {Number} The closest server resolution value. │ │ │ │ │ + * {float} The approximate geodesic area of the geometry in square meters. │ │ │ │ │ */ │ │ │ │ │ - getServerResolution: function(resolution) { │ │ │ │ │ - var distance = Number.POSITIVE_INFINITY; │ │ │ │ │ - resolution = resolution || this.map.getResolution(); │ │ │ │ │ - if (this.serverResolutions && │ │ │ │ │ - OpenLayers.Util.indexOf(this.serverResolutions, resolution) === -1) { │ │ │ │ │ - var i, newDistance, newResolution, serverResolution; │ │ │ │ │ - for (i = this.serverResolutions.length - 1; i >= 0; i--) { │ │ │ │ │ - newResolution = this.serverResolutions[i]; │ │ │ │ │ - newDistance = Math.abs(newResolution - resolution); │ │ │ │ │ - if (newDistance > distance) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - distance = newDistance; │ │ │ │ │ - serverResolution = newResolution; │ │ │ │ │ - } │ │ │ │ │ - resolution = serverResolution; │ │ │ │ │ + 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 resolution; │ │ │ │ │ + return area; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getServerZoom │ │ │ │ │ - * Return the zoom value corresponding to the best matching server │ │ │ │ │ - * resolution, taking into account and . │ │ │ │ │ + * APIMethod: getCentroid │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} The closest server supported zoom. This is not the map zoom │ │ │ │ │ - * level, but an index of the server's resolutions array. │ │ │ │ │ - */ │ │ │ │ │ - getServerZoom: function() { │ │ │ │ │ - var resolution = this.getServerResolution(); │ │ │ │ │ - return this.serverResolutions ? │ │ │ │ │ - OpenLayers.Util.indexOf(this.serverResolutions, resolution) : │ │ │ │ │ - this.map.getZoomForResolution(resolution) + (this.zoomOffset || 0); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: applyBackBuffer │ │ │ │ │ - * Create, insert, scale and position a back buffer for the layer. │ │ │ │ │ + * Compute the centroid for this geometry collection. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * resolution - {Number} The resolution to transition to. │ │ │ │ │ + * weighted - {Boolean} Perform the getCentroid computation recursively, │ │ │ │ │ + * returning an area weighted average of all geometries in this collection. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The centroid of the collection │ │ │ │ │ */ │ │ │ │ │ - applyBackBuffer: function(resolution) { │ │ │ │ │ - if (this.backBufferTimerId !== null) { │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ + getCentroid: function(weighted) { │ │ │ │ │ + if (!weighted) { │ │ │ │ │ + return this.components.length && this.components[0].getCentroid(); │ │ │ │ │ } │ │ │ │ │ - var backBuffer = this.backBuffer; │ │ │ │ │ - if (!backBuffer) { │ │ │ │ │ - backBuffer = this.createBackBuffer(); │ │ │ │ │ - if (!backBuffer) { │ │ │ │ │ - return; │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - if (resolution === this.gridResolution) { │ │ │ │ │ - this.div.insertBefore(backBuffer, this.div.firstChild); │ │ │ │ │ - } else { │ │ │ │ │ - this.map.baseLayer.div.parentNode.insertBefore(backBuffer, this.map.baseLayer.div); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - this.backBuffer = backBuffer; │ │ │ │ │ - │ │ │ │ │ - // set some information in the instance for subsequent │ │ │ │ │ - // calls to applyBackBuffer where the same back buffer │ │ │ │ │ - // is reused │ │ │ │ │ - var topLeftTileBounds = this.grid[0][0].bounds; │ │ │ │ │ - this.backBufferLonLat = { │ │ │ │ │ - lon: topLeftTileBounds.left, │ │ │ │ │ - lat: topLeftTileBounds.top │ │ │ │ │ - }; │ │ │ │ │ - this.backBufferResolution = this.gridResolution; │ │ │ │ │ + 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 ratio = this.backBufferResolution / resolution; │ │ │ │ │ - │ │ │ │ │ - // scale the tiles inside the back buffer │ │ │ │ │ - var tiles = backBuffer.childNodes, │ │ │ │ │ - tile; │ │ │ │ │ - for (var i = tiles.length - 1; i >= 0; --i) { │ │ │ │ │ - tile = tiles[i]; │ │ │ │ │ - tile.style.top = ((ratio * tile._i * tile._h) | 0) + 'px'; │ │ │ │ │ - tile.style.left = ((ratio * tile._j * tile._w) | 0) + 'px'; │ │ │ │ │ - tile.style.width = Math.round(ratio * tile._w) + 'px'; │ │ │ │ │ - tile.style.height = Math.round(ratio * tile._h) + 'px'; │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // and position it (based on the grid's top-left corner) │ │ │ │ │ - var position = this.getViewPortPxFromLonLat( │ │ │ │ │ - this.backBufferLonLat, resolution); │ │ │ │ │ - var leftOffset = this.map.layerContainerOriginPx.x; │ │ │ │ │ - var topOffset = this.map.layerContainerOriginPx.y; │ │ │ │ │ - backBuffer.style.left = Math.round(position.x - leftOffset) + 'px'; │ │ │ │ │ - backBuffer.style.top = Math.round(position.y - topOffset) + 'px'; │ │ │ │ │ + return new OpenLayers.Geometry.Point(xSum / areaSum, ySum / areaSum); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createBackBuffer │ │ │ │ │ - * Create a back buffer. │ │ │ │ │ + * 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: │ │ │ │ │ - * {DOMElement} The DOM element for the back buffer, undefined if the │ │ │ │ │ - * grid isn't initialized yet. │ │ │ │ │ + * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ */ │ │ │ │ │ - createBackBuffer: function() { │ │ │ │ │ - var backBuffer; │ │ │ │ │ - if (this.grid.length > 0) { │ │ │ │ │ - backBuffer = document.createElement('div'); │ │ │ │ │ - backBuffer.id = this.div.id + '_bb'; │ │ │ │ │ - backBuffer.className = 'olBackBuffer'; │ │ │ │ │ - backBuffer.style.position = 'absolute'; │ │ │ │ │ - var map = this.map; │ │ │ │ │ - backBuffer.style.zIndex = this.transitionEffect === 'resize' ? │ │ │ │ │ - this.getZIndex() - 1 : │ │ │ │ │ - // 'map-resize': │ │ │ │ │ - map.Z_INDEX_BASE.BaseLayer - │ │ │ │ │ - (map.getNumLayers() - map.getLayerIndex(this)); │ │ │ │ │ - for (var i = 0, lenI = this.grid.length; i < lenI; i++) { │ │ │ │ │ - for (var j = 0, lenJ = this.grid[i].length; j < lenJ; j++) { │ │ │ │ │ - var tile = this.grid[i][j], │ │ │ │ │ - markup = this.grid[i][j].createBackBuffer(); │ │ │ │ │ - if (markup) { │ │ │ │ │ - markup._i = i; │ │ │ │ │ - markup._j = j; │ │ │ │ │ - markup._w = tile.size.w; │ │ │ │ │ - markup._h = tile.size.h; │ │ │ │ │ - markup.id = tile.id + '_bb'; │ │ │ │ │ - backBuffer.appendChild(markup); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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 backBuffer; │ │ │ │ │ + return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeBackBuffer │ │ │ │ │ - * Remove back buffer from DOM. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - removeBackBuffer: function() { │ │ │ │ │ - if (this._transitionElement) { │ │ │ │ │ - for (var i = this.transitionendEvents.length - 1; i >= 0; --i) { │ │ │ │ │ - OpenLayers.Event.stopObserving(this._transitionElement, │ │ │ │ │ - this.transitionendEvents[i], this._removeBackBuffer); │ │ │ │ │ - } │ │ │ │ │ - delete this._transitionElement; │ │ │ │ │ - } │ │ │ │ │ - if (this.backBuffer) { │ │ │ │ │ - if (this.backBuffer.parentNode) { │ │ │ │ │ - this.backBuffer.parentNode.removeChild(this.backBuffer); │ │ │ │ │ - } │ │ │ │ │ - this.backBuffer = null; │ │ │ │ │ - this.backBufferResolution = null; │ │ │ │ │ - if (this.backBufferTimerId !== null) { │ │ │ │ │ - window.clearTimeout(this.backBufferTimerId); │ │ │ │ │ - this.backBufferTimerId = null; │ │ │ │ │ - } │ │ │ │ │ + move: function(x, y) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; i++) { │ │ │ │ │ + this.components[i].move(x, y); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveByPx │ │ │ │ │ - * Move the layer based on pixel vector. │ │ │ │ │ + * APIMethod: rotate │ │ │ │ │ + * Rotate a geometry around some origin │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * dx - {Number} │ │ │ │ │ - * dy - {Number} │ │ │ │ │ + * angle - {Float} Rotation angle in degrees (measured counterclockwise │ │ │ │ │ + * from the positive x-axis) │ │ │ │ │ + * origin - {} Center point for the rotation │ │ │ │ │ */ │ │ │ │ │ - moveByPx: function(dx, dy) { │ │ │ │ │ - if (!this.singleTile) { │ │ │ │ │ - this.moveGriddedTiles(); │ │ │ │ │ + rotate: function(angle, origin) { │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + this.components[i].rotate(angle, origin); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setTileSize │ │ │ │ │ - * Check if we are in singleTile mode and if so, set the size as a ratio │ │ │ │ │ - * of the map size (as specified by the layer's 'ratio' property). │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: resize │ │ │ │ │ + * Resize a geometry relative to some origin. Use this method to apply │ │ │ │ │ + * a uniform scaling to a geometry. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * size - {} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - setTileSize: function(size) { │ │ │ │ │ - if (this.singleTile) { │ │ │ │ │ - size = this.map.getSize(); │ │ │ │ │ - size.h = parseInt(size.h * this.ratio, 10); │ │ │ │ │ - size.w = parseInt(size.w * this.ratio, 10); │ │ │ │ │ + resize: function(scale, origin, ratio) { │ │ │ │ │ + for (var i = 0; i < this.components.length; ++i) { │ │ │ │ │ + this.components[i].resize(scale, origin, ratio); │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Layer.HTTPRequest.prototype.setTileSize.apply(this, [size]); │ │ │ │ │ + return this; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getTilesBounds │ │ │ │ │ - * Return the bounds of the tile grid. │ │ │ │ │ + * 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: │ │ │ │ │ - * {} A Bounds object representing the bounds of all the │ │ │ │ │ - * currently loaded tiles (including those partially or not at all seen │ │ │ │ │ - * onscreen). │ │ │ │ │ + * {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. │ │ │ │ │ */ │ │ │ │ │ - getTilesBounds: function() { │ │ │ │ │ - var bounds = null; │ │ │ │ │ - │ │ │ │ │ - var length = this.grid.length; │ │ │ │ │ - if (length) { │ │ │ │ │ - var bottomLeftTileBounds = this.grid[length - 1][0].bounds, │ │ │ │ │ - width = this.grid[0].length * bottomLeftTileBounds.getWidth(), │ │ │ │ │ - height = this.grid.length * bottomLeftTileBounds.getHeight(); │ │ │ │ │ - │ │ │ │ │ - bounds = new OpenLayers.Bounds(bottomLeftTileBounds.left, │ │ │ │ │ - bottomLeftTileBounds.bottom, │ │ │ │ │ - bottomLeftTileBounds.left + width, │ │ │ │ │ - bottomLeftTileBounds.bottom + height); │ │ │ │ │ + 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 bounds; │ │ │ │ │ + return best; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: initSingleTile │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: equals │ │ │ │ │ + * Determine whether another geometry is equivalent to this one. Geometries │ │ │ │ │ + * are considered equivalent if all components have the same coordinates. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} The geometry to test. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The supplied geometry is equivalent to this geometry. │ │ │ │ │ */ │ │ │ │ │ - initSingleTile: function(bounds) { │ │ │ │ │ - this.events.triggerEvent("retile"); │ │ │ │ │ - │ │ │ │ │ - //determine new tile bounds │ │ │ │ │ - var center = bounds.getCenterLonLat(); │ │ │ │ │ - var tileWidth = bounds.getWidth() * this.ratio; │ │ │ │ │ - var tileHeight = bounds.getHeight() * this.ratio; │ │ │ │ │ - │ │ │ │ │ - var tileBounds = │ │ │ │ │ - new OpenLayers.Bounds(center.lon - (tileWidth / 2), │ │ │ │ │ - center.lat - (tileHeight / 2), │ │ │ │ │ - center.lon + (tileWidth / 2), │ │ │ │ │ - center.lat + (tileHeight / 2)); │ │ │ │ │ - │ │ │ │ │ - var px = this.map.getLayerPxFromLonLat({ │ │ │ │ │ - lon: tileBounds.left, │ │ │ │ │ - lat: tileBounds.top │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - if (!this.grid.length) { │ │ │ │ │ - this.grid[0] = []; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var tile = this.grid[0][0]; │ │ │ │ │ - if (!tile) { │ │ │ │ │ - tile = this.addTile(tileBounds, px); │ │ │ │ │ - │ │ │ │ │ - this.addTileMonitoringHooks(tile); │ │ │ │ │ - tile.draw(); │ │ │ │ │ - this.grid[0][0] = tile; │ │ │ │ │ + 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 { │ │ │ │ │ - tile.moveTo(tileBounds, px); │ │ │ │ │ + for (var i = 0, len = this.components.length; i < len; ++i) { │ │ │ │ │ + if (!this.components[i].equals(geometry.components[i])) { │ │ │ │ │ + equivalent = false; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //remove all but our single tile │ │ │ │ │ - this.removeExcessTiles(1, 1); │ │ │ │ │ - │ │ │ │ │ - // store the resolution of the grid │ │ │ │ │ - this.gridResolution = this.getServerResolution(); │ │ │ │ │ + return equivalent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: calculateGridLayout │ │ │ │ │ - * Generate parameters for the grid layout. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: transform │ │ │ │ │ + * Reproject the components geometry from source to dest. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {|Object} OpenLayers.Bounds or an │ │ │ │ │ - * object with a 'left' and 'top' properties. │ │ │ │ │ - * origin - {|Object} OpenLayers.LonLat or an │ │ │ │ │ - * object with a 'lon' and 'lat' properties. │ │ │ │ │ - * resolution - {Number} │ │ │ │ │ - * │ │ │ │ │ + * source - {} │ │ │ │ │ + * dest - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ - * startrow │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - calculateGridLayout: function(bounds, origin, resolution) { │ │ │ │ │ - var tilelon = resolution * this.tileSize.w; │ │ │ │ │ - var tilelat = resolution * this.tileSize.h; │ │ │ │ │ - │ │ │ │ │ - var offsetlon = bounds.left - origin.lon; │ │ │ │ │ - var tilecol = Math.floor(offsetlon / tilelon) - this.buffer; │ │ │ │ │ - │ │ │ │ │ - var rowSign = this.rowSign; │ │ │ │ │ - │ │ │ │ │ - var offsetlat = rowSign * (origin.lat - bounds.top + tilelat); │ │ │ │ │ - var tilerow = Math[~rowSign ? 'floor' : 'ceil'](offsetlat / tilelat) - this.buffer * rowSign; │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - tilelon: tilelon, │ │ │ │ │ - tilelat: tilelat, │ │ │ │ │ - startcol: tilecol, │ │ │ │ │ - startrow: tilerow │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTileOrigin │ │ │ │ │ - * Determine the origin for aligning the grid of tiles. If a │ │ │ │ │ - * property is supplied, that will be returned. Otherwise, the origin │ │ │ │ │ - * will be derived from the layer's property. In this case, │ │ │ │ │ - * the tile origin will be the corner of the given by the │ │ │ │ │ - * property. │ │ │ │ │ + * APIMethod: intersects │ │ │ │ │ + * Determine if the input geometry intersects this one. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} Any type of geometry. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} The tile origin. │ │ │ │ │ + * {Boolean} The input geometry intersects this one. │ │ │ │ │ */ │ │ │ │ │ - getTileOrigin: function() { │ │ │ │ │ - var origin = this.tileOrigin; │ │ │ │ │ - if (!origin) { │ │ │ │ │ - var extent = this.getMaxExtent(); │ │ │ │ │ - var edges = ({ │ │ │ │ │ - "tl": ["left", "top"], │ │ │ │ │ - "tr": ["right", "top"], │ │ │ │ │ - "bl": ["left", "bottom"], │ │ │ │ │ - "br": ["right", "bottom"] │ │ │ │ │ - })[this.tileOriginCorner]; │ │ │ │ │ - origin = new OpenLayers.LonLat(extent[edges[0]], extent[edges[1]]); │ │ │ │ │ + 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 origin; │ │ │ │ │ + return intersect; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getTileBoundsForGridIndex │ │ │ │ │ + * APIMethod: getVertices │ │ │ │ │ + * Return a list of all points in this geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * row - {Number} The row of the grid │ │ │ │ │ - * col - {Number} The column of the grid │ │ │ │ │ + * 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 bounds for the tile at (row, col) │ │ │ │ │ + * {Array} A list of all vertices in the geometry. │ │ │ │ │ */ │ │ │ │ │ - getTileBoundsForGridIndex: function(row, col) { │ │ │ │ │ - var origin = this.getTileOrigin(); │ │ │ │ │ - var tileLayout = this.gridLayout; │ │ │ │ │ - var tilelon = tileLayout.tilelon; │ │ │ │ │ - var tilelat = tileLayout.tilelat; │ │ │ │ │ - var startcol = tileLayout.startcol; │ │ │ │ │ - var startrow = tileLayout.startrow; │ │ │ │ │ - var rowSign = this.rowSign; │ │ │ │ │ - return new OpenLayers.Bounds( │ │ │ │ │ - origin.lon + (startcol + col) * tilelon, │ │ │ │ │ - origin.lat - (startrow + row * rowSign) * tilelat * rowSign, │ │ │ │ │ - origin.lon + (startcol + col + 1) * tilelon, │ │ │ │ │ - origin.lat - (startrow + (row - 1) * rowSign) * tilelat * rowSign │ │ │ │ │ - ); │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: initGriddedTiles │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - */ │ │ │ │ │ - initGriddedTiles: function(bounds) { │ │ │ │ │ - this.events.triggerEvent("retile"); │ │ │ │ │ - │ │ │ │ │ - // work out mininum number of rows and columns; this is the number of │ │ │ │ │ - // tiles required to cover the viewport plus at least one for panning │ │ │ │ │ - │ │ │ │ │ - var viewSize = this.map.getSize(); │ │ │ │ │ - │ │ │ │ │ - var origin = this.getTileOrigin(); │ │ │ │ │ - var resolution = this.map.getResolution(), │ │ │ │ │ - serverResolution = this.getServerResolution(), │ │ │ │ │ - ratio = resolution / serverResolution, │ │ │ │ │ - tileSize = { │ │ │ │ │ - w: this.tileSize.w / ratio, │ │ │ │ │ - h: this.tileSize.h / ratio │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - var minRows = Math.ceil(viewSize.h / tileSize.h) + │ │ │ │ │ - 2 * this.buffer + 1; │ │ │ │ │ - var minCols = Math.ceil(viewSize.w / tileSize.w) + │ │ │ │ │ - 2 * this.buffer + 1; │ │ │ │ │ │ │ │ │ │ - var tileLayout = this.calculateGridLayout(bounds, origin, serverResolution); │ │ │ │ │ - this.gridLayout = tileLayout; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Collection" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - var tilelon = tileLayout.tilelon; │ │ │ │ │ - var tilelat = tileLayout.tilelat; │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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 layerContainerDivLeft = this.map.layerContainerOriginPx.x; │ │ │ │ │ - var layerContainerDivTop = this.map.layerContainerOriginPx.y; │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/Collection.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - var tileBounds = this.getTileBoundsForGridIndex(0, 0); │ │ │ │ │ - var startPx = this.map.getViewPortPxFromLonLat( │ │ │ │ │ - new OpenLayers.LonLat(tileBounds.left, tileBounds.top) │ │ │ │ │ - ); │ │ │ │ │ - startPx.x = Math.round(startPx.x) - layerContainerDivLeft; │ │ │ │ │ - startPx.y = Math.round(startPx.y) - layerContainerDivTop; │ │ │ │ │ +/** │ │ │ │ │ + * 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, { │ │ │ │ │ │ │ │ │ │ - var tileData = [], │ │ │ │ │ - center = this.map.getCenter(); │ │ │ │ │ + /** │ │ │ │ │ + * 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 rowidx = 0; │ │ │ │ │ - do { │ │ │ │ │ - var row = this.grid[rowidx]; │ │ │ │ │ - if (!row) { │ │ │ │ │ - row = []; │ │ │ │ │ - this.grid.push(row); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Geometry.MultiPoint │ │ │ │ │ + * Create a new MultiPoint Geometry │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * components - {Array()} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - var colidx = 0; │ │ │ │ │ - do { │ │ │ │ │ - tileBounds = this.getTileBoundsForGridIndex(rowidx, colidx); │ │ │ │ │ - var px = startPx.clone(); │ │ │ │ │ - px.x = px.x + colidx * Math.round(tileSize.w); │ │ │ │ │ - px.y = px.y + rowidx * Math.round(tileSize.h); │ │ │ │ │ - var tile = row[colidx]; │ │ │ │ │ - if (!tile) { │ │ │ │ │ - tile = this.addTile(tileBounds, px); │ │ │ │ │ - this.addTileMonitoringHooks(tile); │ │ │ │ │ - row.push(tile); │ │ │ │ │ - } else { │ │ │ │ │ - tile.moveTo(tileBounds, px, false); │ │ │ │ │ - } │ │ │ │ │ - var tileCenter = tileBounds.getCenterLonLat(); │ │ │ │ │ - tileData.push({ │ │ │ │ │ - tile: tile, │ │ │ │ │ - distance: Math.pow(tileCenter.lon - center.lon, 2) + │ │ │ │ │ - Math.pow(tileCenter.lat - center.lat, 2) │ │ │ │ │ - }); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addPoint │ │ │ │ │ + * Wrapper for │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} Point to be added │ │ │ │ │ + * index - {Integer} Optional index │ │ │ │ │ + */ │ │ │ │ │ + addPoint: function(point, index) { │ │ │ │ │ + this.addComponent(point, index); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - colidx += 1; │ │ │ │ │ - } while ((tileBounds.right <= bounds.right + tilelon * this.buffer) || │ │ │ │ │ - colidx < minCols); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: removePoint │ │ │ │ │ + * Wrapper for │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} Point to be removed │ │ │ │ │ + */ │ │ │ │ │ + removePoint: function(point) { │ │ │ │ │ + this.removeComponent(point); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - rowidx += 1; │ │ │ │ │ - } while ((tileBounds.bottom >= bounds.bottom - tilelat * this.buffer) || │ │ │ │ │ - rowidx < minRows); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.MultiPoint" │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Geometry/Curve.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - //shave off exceess rows and colums │ │ │ │ │ - this.removeExcessTiles(rowidx, colidx); │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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 resolution = this.getServerResolution(); │ │ │ │ │ - // store the resolution of the grid │ │ │ │ │ - this.gridResolution = resolution; │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Geometry/MultiPoint.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - //now actually draw the tiles │ │ │ │ │ - tileData.sort(function(a, b) { │ │ │ │ │ - return a.distance - b.distance; │ │ │ │ │ - }); │ │ │ │ │ - for (var i = 0, ii = tileData.length; i < ii; ++i) { │ │ │ │ │ - tileData[i].tile.draw(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * 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: getMaxExtent │ │ │ │ │ - * Get this layer's maximum extent. (Implemented as a getter for │ │ │ │ │ - * potential specific implementations in sub-classes.) │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - getMaxExtent: function() { │ │ │ │ │ - return this.maxExtent; │ │ │ │ │ - }, │ │ │ │ │ + componentTypes: ["OpenLayers.Geometry.Point"], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addTile │ │ │ │ │ - * Create a tile, initialize it, and add it to the layer div. │ │ │ │ │ - * │ │ │ │ │ - * Parameters │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * position - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The added OpenLayers.Tile │ │ │ │ │ - */ │ │ │ │ │ - addTile: function(bounds, position) { │ │ │ │ │ - var tile = new this.tileClass( │ │ │ │ │ - this, position, bounds, null, this.tileSize, this.tileOptions │ │ │ │ │ - ); │ │ │ │ │ - this.events.triggerEvent("addtile", { │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - return tile; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addTileMonitoringHooks │ │ │ │ │ - * This function takes a tile as input and adds the appropriate hooks to │ │ │ │ │ - * the tile so that the layer can keep track of the loading tiles. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * tile - {} │ │ │ │ │ - */ │ │ │ │ │ - addTileMonitoringHooks: function(tile) { │ │ │ │ │ - │ │ │ │ │ - var replacingCls = 'olTileReplacing'; │ │ │ │ │ - │ │ │ │ │ - tile.onLoadStart = function() { │ │ │ │ │ - //if that was first tile then trigger a 'loadstart' on the layer │ │ │ │ │ - if (this.loading === false) { │ │ │ │ │ - this.loading = true; │ │ │ │ │ - this.events.triggerEvent("loadstart"); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("tileloadstart", { │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - this.numLoadingTiles++; │ │ │ │ │ - if (!this.singleTile && this.backBuffer && this.gridResolution === this.backBufferResolution) { │ │ │ │ │ - OpenLayers.Element.addClass(tile.getTile(), replacingCls); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - tile.onLoadEnd = function(evt) { │ │ │ │ │ - this.numLoadingTiles--; │ │ │ │ │ - var aborted = evt.type === 'unload'; │ │ │ │ │ - this.events.triggerEvent("tileloaded", { │ │ │ │ │ - tile: tile, │ │ │ │ │ - aborted: aborted │ │ │ │ │ - }); │ │ │ │ │ - if (!this.singleTile && !aborted && this.backBuffer && this.gridResolution === this.backBufferResolution) { │ │ │ │ │ - var tileDiv = tile.getTile(); │ │ │ │ │ - if (OpenLayers.Element.getStyle(tileDiv, 'display') === 'none') { │ │ │ │ │ - var bufferTile = document.getElementById(tile.id + '_bb'); │ │ │ │ │ - if (bufferTile) { │ │ │ │ │ - bufferTile.parentNode.removeChild(bufferTile); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Element.removeClass(tileDiv, replacingCls); │ │ │ │ │ - } │ │ │ │ │ - //if that was the last tile, then trigger a 'loadend' on the layer │ │ │ │ │ - if (this.numLoadingTiles === 0) { │ │ │ │ │ - if (this.backBuffer) { │ │ │ │ │ - if (this.backBuffer.childNodes.length === 0) { │ │ │ │ │ - // no tiles transitioning, remove immediately │ │ │ │ │ - this.removeBackBuffer(); │ │ │ │ │ - } else { │ │ │ │ │ - // wait until transition has ended or delay has passed │ │ │ │ │ - this._transitionElement = aborted ? │ │ │ │ │ - this.div.lastChild : tile.imgDiv; │ │ │ │ │ - var transitionendEvents = this.transitionendEvents; │ │ │ │ │ - for (var i = transitionendEvents.length - 1; i >= 0; --i) { │ │ │ │ │ - OpenLayers.Event.observe(this._transitionElement, │ │ │ │ │ - transitionendEvents[i], │ │ │ │ │ - this._removeBackBuffer); │ │ │ │ │ - } │ │ │ │ │ - // the removal of the back buffer is delayed to prevent │ │ │ │ │ - // flash effects due to the animation of tile displaying │ │ │ │ │ - this.backBufferTimerId = window.setTimeout( │ │ │ │ │ - this._removeBackBuffer, this.removeBackBufferDelay │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.loading = false; │ │ │ │ │ - this.events.triggerEvent("loadend"); │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - tile.onLoadError = function() { │ │ │ │ │ - this.events.triggerEvent("tileerror", { │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - tile.events.on({ │ │ │ │ │ - "loadstart": tile.onLoadStart, │ │ │ │ │ - "loadend": tile.onLoadEnd, │ │ │ │ │ - "unload": tile.onLoadEnd, │ │ │ │ │ - "loaderror": tile.onLoadError, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeTileMonitoringHooks │ │ │ │ │ - * This function takes a tile as input and removes the tile hooks │ │ │ │ │ - * that were added in addTileMonitoringHooks() │ │ │ │ │ + * Constructor: OpenLayers.Geometry.Curve │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * tile - {} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {Array()} │ │ │ │ │ */ │ │ │ │ │ - removeTileMonitoringHooks: function(tile) { │ │ │ │ │ - tile.unload(); │ │ │ │ │ - tile.events.un({ │ │ │ │ │ - "loadstart": tile.onLoadStart, │ │ │ │ │ - "loadend": tile.onLoadEnd, │ │ │ │ │ - "unload": tile.onLoadEnd, │ │ │ │ │ - "loaderror": tile.onLoadError, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveGriddedTiles │ │ │ │ │ + * APIMethod: getLength │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The length of the curve │ │ │ │ │ */ │ │ │ │ │ - moveGriddedTiles: function() { │ │ │ │ │ - var buffer = this.buffer + 1; │ │ │ │ │ - while (true) { │ │ │ │ │ - var tlTile = this.grid[0][0]; │ │ │ │ │ - var tlViewPort = { │ │ │ │ │ - x: tlTile.position.x + │ │ │ │ │ - this.map.layerContainerOriginPx.x, │ │ │ │ │ - y: tlTile.position.y + │ │ │ │ │ - this.map.layerContainerOriginPx.y │ │ │ │ │ - }; │ │ │ │ │ - var ratio = this.getServerResolution() / this.map.getResolution(); │ │ │ │ │ - var tileSize = { │ │ │ │ │ - w: Math.round(this.tileSize.w * ratio), │ │ │ │ │ - h: Math.round(this.tileSize.h * ratio) │ │ │ │ │ - }; │ │ │ │ │ - if (tlViewPort.x > -tileSize.w * (buffer - 1)) { │ │ │ │ │ - this.shiftColumn(true, tileSize); │ │ │ │ │ - } else if (tlViewPort.x < -tileSize.w * buffer) { │ │ │ │ │ - this.shiftColumn(false, tileSize); │ │ │ │ │ - } else if (tlViewPort.y > -tileSize.h * (buffer - 1)) { │ │ │ │ │ - this.shiftRow(true, tileSize); │ │ │ │ │ - } else if (tlViewPort.y < -tileSize.h * buffer) { │ │ │ │ │ - this.shiftRow(false, tileSize); │ │ │ │ │ - } else { │ │ │ │ │ - break; │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: shiftRow │ │ │ │ │ - * Shifty grid work │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * prepend - {Boolean} if true, prepend to beginning. │ │ │ │ │ - * if false, then append to end │ │ │ │ │ - * tileSize - {Object} rendered tile size; object with w and h properties │ │ │ │ │ - */ │ │ │ │ │ - shiftRow: function(prepend, tileSize) { │ │ │ │ │ - var grid = this.grid; │ │ │ │ │ - var rowIndex = prepend ? 0 : (grid.length - 1); │ │ │ │ │ - var sign = prepend ? -1 : 1; │ │ │ │ │ - var rowSign = this.rowSign; │ │ │ │ │ - var tileLayout = this.gridLayout; │ │ │ │ │ - tileLayout.startrow += sign * rowSign; │ │ │ │ │ - │ │ │ │ │ - var modelRow = grid[rowIndex]; │ │ │ │ │ - var row = grid[prepend ? 'pop' : 'shift'](); │ │ │ │ │ - for (var i = 0, len = row.length; i < len; i++) { │ │ │ │ │ - var tile = row[i]; │ │ │ │ │ - var position = modelRow[i].position.clone(); │ │ │ │ │ - position.y += tileSize.h * sign; │ │ │ │ │ - tile.moveTo(this.getTileBoundsForGridIndex(rowIndex, i), position); │ │ │ │ │ - } │ │ │ │ │ - grid[prepend ? 'unshift' : 'push'](row); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: shiftColumn │ │ │ │ │ - * Shift grid work in the other dimension │ │ │ │ │ + * APIMethod: getGeodesicLength │ │ │ │ │ + * Calculate the approximate length of the geometry were it projected onto │ │ │ │ │ + * the earth. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * prepend - {Boolean} if true, prepend to beginning. │ │ │ │ │ - * if false, then append to end │ │ │ │ │ - * tileSize - {Object} rendered tile size; object with w and h properties │ │ │ │ │ - */ │ │ │ │ │ - shiftColumn: function(prepend, tileSize) { │ │ │ │ │ - var grid = this.grid; │ │ │ │ │ - var colIndex = prepend ? 0 : (grid[0].length - 1); │ │ │ │ │ - var sign = prepend ? -1 : 1; │ │ │ │ │ - var tileLayout = this.gridLayout; │ │ │ │ │ - tileLayout.startcol += sign; │ │ │ │ │ - │ │ │ │ │ - for (var i = 0, len = grid.length; i < len; i++) { │ │ │ │ │ - var row = grid[i]; │ │ │ │ │ - var position = row[colIndex].position.clone(); │ │ │ │ │ - var tile = row[prepend ? 'pop' : 'shift'](); │ │ │ │ │ - position.x += tileSize.w * sign; │ │ │ │ │ - tile.moveTo(this.getTileBoundsForGridIndex(i, colIndex), position); │ │ │ │ │ - row[prepend ? 'unshift' : 'push'](tile); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeExcessTiles │ │ │ │ │ - * When the size of the map or the buffer changes, we may need to │ │ │ │ │ - * remove some excess rows and columns. │ │ │ │ │ + * projection - {} The spatial reference system │ │ │ │ │ + * for the geometry coordinates. If not provided, Geographic/WGS84 is │ │ │ │ │ + * assumed. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * rows - {Integer} Maximum number of rows we want our grid to have. │ │ │ │ │ - * columns - {Integer} Maximum number of columns we want our grid to have. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The appoximate geodesic length of the geometry in meters. │ │ │ │ │ */ │ │ │ │ │ - removeExcessTiles: function(rows, columns) { │ │ │ │ │ - var i, l; │ │ │ │ │ - │ │ │ │ │ - // remove extra rows │ │ │ │ │ - while (this.grid.length > rows) { │ │ │ │ │ - var row = this.grid.pop(); │ │ │ │ │ - for (i = 0, l = row.length; i < l; i++) { │ │ │ │ │ - var tile = row[i]; │ │ │ │ │ - this.destroyTile(tile); │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // remove extra columns │ │ │ │ │ - for (i = 0, l = this.grid.length; i < l; i++) { │ │ │ │ │ - while (this.grid[i].length > columns) { │ │ │ │ │ - var row = this.grid[i]; │ │ │ │ │ - var tile = row.pop(); │ │ │ │ │ - this.destroyTile(tile); │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onMapResize │ │ │ │ │ - * For singleTile layers, this will set a new tile size according to the │ │ │ │ │ - * dimensions of the map pane. │ │ │ │ │ - */ │ │ │ │ │ - onMapResize: function() { │ │ │ │ │ - if (this.singleTile) { │ │ │ │ │ - this.clearGrid(); │ │ │ │ │ - this.setTileSize(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getTileBounds │ │ │ │ │ - * Returns The tile bounds for a layer given a pixel location. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * viewPortPx - {} The location in the viewport. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Bounds of the tile at the given pixel location. │ │ │ │ │ - */ │ │ │ │ │ - getTileBounds: function(viewPortPx) { │ │ │ │ │ - var maxExtent = this.maxExtent; │ │ │ │ │ - var resolution = this.getResolution(); │ │ │ │ │ - var tileMapWidth = resolution * this.tileSize.w; │ │ │ │ │ - var tileMapHeight = resolution * this.tileSize.h; │ │ │ │ │ - var mapPoint = this.getLonLatFromViewPortPx(viewPortPx); │ │ │ │ │ - var tileLeft = maxExtent.left + (tileMapWidth * │ │ │ │ │ - Math.floor((mapPoint.lon - │ │ │ │ │ - maxExtent.left) / │ │ │ │ │ - tileMapWidth)); │ │ │ │ │ - var tileBottom = maxExtent.bottom + (tileMapHeight * │ │ │ │ │ - Math.floor((mapPoint.lat - │ │ │ │ │ - maxExtent.bottom) / │ │ │ │ │ - tileMapHeight)); │ │ │ │ │ - return new OpenLayers.Bounds(tileLeft, tileBottom, │ │ │ │ │ - tileLeft + tileMapWidth, │ │ │ │ │ - tileBottom + tileMapHeight); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.Grid" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Geometry.Curve" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/TileManager.js │ │ │ │ │ + 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/Util.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Element.js │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ - * @requires OpenLayers/Tile/Image.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Curve.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.TileManager │ │ │ │ │ - * Provides queueing of image requests and caching of image elements. │ │ │ │ │ - * │ │ │ │ │ - * Queueing avoids unnecessary image requests while changing zoom levels │ │ │ │ │ - * quickly, and helps improve dragging performance on mobile devices that show │ │ │ │ │ - * a lag in dragging when loading of new images starts. and │ │ │ │ │ - * are the configuration options to control this behavior. │ │ │ │ │ - * │ │ │ │ │ - * Caching avoids setting the src on image elements for images that have already │ │ │ │ │ - * been used. Several maps can share a TileManager instance, in which case each │ │ │ │ │ - * map gets its own tile queue, but all maps share the same tile cache. │ │ │ │ │ + * 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.TileManager = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Geometry.LineString = OpenLayers.Class(OpenLayers.Geometry.Curve, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: cacheSize │ │ │ │ │ - * {Number} Number of image elements to keep referenced in this instance's │ │ │ │ │ - * cache for fast reuse. Default is 256. │ │ │ │ │ + * Constructor: OpenLayers.Geometry.LineString │ │ │ │ │ + * Create a new LineString geometry │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * points - {Array()} An array of points used to │ │ │ │ │ + * generate the linestring │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - cacheSize: 256, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: tilesPerFrame │ │ │ │ │ - * {Number} Number of queued tiles to load per frame (see ). │ │ │ │ │ - * Default is 2. │ │ │ │ │ - */ │ │ │ │ │ - tilesPerFrame: 2, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: frameDelay │ │ │ │ │ - * {Number} Delay between tile loading frames (see ) in │ │ │ │ │ - * milliseconds. Default is 16. │ │ │ │ │ - */ │ │ │ │ │ - frameDelay: 16, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: moveDelay │ │ │ │ │ - * {Number} Delay in milliseconds after a map's move event before loading │ │ │ │ │ - * tiles. Default is 100. │ │ │ │ │ - */ │ │ │ │ │ - moveDelay: 100, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomDelay │ │ │ │ │ - * {Number} Delay in milliseconds after a map's zoomend event before loading │ │ │ │ │ - * tiles. Default is 200. │ │ │ │ │ - */ │ │ │ │ │ - zoomDelay: 200, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: maps │ │ │ │ │ - * {Array()} The maps to manage tiles on. │ │ │ │ │ - */ │ │ │ │ │ - maps: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileQueueId │ │ │ │ │ - * {Object} The ids of the loop, keyed by map id. │ │ │ │ │ - */ │ │ │ │ │ - tileQueueId: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileQueue │ │ │ │ │ - * {Object(Array())} Tiles queued for drawing, keyed by │ │ │ │ │ - * map id. │ │ │ │ │ - */ │ │ │ │ │ - tileQueue: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileCache │ │ │ │ │ - * {Object} Cached image elements, keyed by URL. │ │ │ │ │ - */ │ │ │ │ │ - tileCache: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: tileCacheIndex │ │ │ │ │ - * {Array(String)} URLs of cached tiles. First entry is the least recently │ │ │ │ │ - * used. │ │ │ │ │ - */ │ │ │ │ │ - tileCacheIndex: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.TileManager │ │ │ │ │ - * Constructor for a new instance. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Configuration for this instance. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.maps = []; │ │ │ │ │ - this.tileQueueId = {}; │ │ │ │ │ - this.tileQueue = {}; │ │ │ │ │ - this.tileCache = {}; │ │ │ │ │ - this.tileCacheIndex = []; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addMap │ │ │ │ │ - * Binds this instance to a map │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - addMap: function(map) { │ │ │ │ │ - if (this._destroyed || !OpenLayers.Layer.Grid) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - this.maps.push(map); │ │ │ │ │ - this.tileQueue[map.id] = []; │ │ │ │ │ - for (var i = 0, ii = map.layers.length; i < ii; ++i) { │ │ │ │ │ - this.addLayer({ │ │ │ │ │ - layer: map.layers[i] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - map.events.on({ │ │ │ │ │ - move: this.move, │ │ │ │ │ - zoomend: this.zoomEnd, │ │ │ │ │ - changelayer: this.changeLayer, │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - preremovelayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeMap │ │ │ │ │ - * Unbinds this instance from a map │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - if (this._destroyed || !OpenLayers.Layer.Grid) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - window.clearTimeout(this.tileQueueId[map.id]); │ │ │ │ │ - if (map.layers) { │ │ │ │ │ - for (var i = 0, ii = map.layers.length; i < ii; ++i) { │ │ │ │ │ - this.removeLayer({ │ │ │ │ │ - layer: map.layers[i] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (map.events) { │ │ │ │ │ - map.events.un({ │ │ │ │ │ - move: this.move, │ │ │ │ │ - zoomend: this.zoomEnd, │ │ │ │ │ - changelayer: this.changeLayer, │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - preremovelayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - delete this.tileQueue[map.id]; │ │ │ │ │ - delete this.tileQueueId[map.id]; │ │ │ │ │ - OpenLayers.Util.removeItem(this.maps, map); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Handles the map's move event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument │ │ │ │ │ - */ │ │ │ │ │ - move: function(evt) { │ │ │ │ │ - this.updateTimeout(evt.object, this.moveDelay, true); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: zoomEnd │ │ │ │ │ - * Handles the map's zoomEnd event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument │ │ │ │ │ - */ │ │ │ │ │ - zoomEnd: function(evt) { │ │ │ │ │ - this.updateTimeout(evt.object, this.zoomDelay); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: changeLayer │ │ │ │ │ - * Handles the map's changeLayer event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument │ │ │ │ │ - */ │ │ │ │ │ - changeLayer: function(evt) { │ │ │ │ │ - if (evt.property === 'visibility' || evt.property === 'params') { │ │ │ │ │ - this.updateTimeout(evt.object, 0); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addLayer │ │ │ │ │ - * Handles the map's addlayer event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ - */ │ │ │ │ │ - addLayer: function(evt) { │ │ │ │ │ - var layer = evt.layer; │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ - layer.events.on({ │ │ │ │ │ - addtile: this.addTile, │ │ │ │ │ - retile: this.clearTileQueue, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - var i, j, tile; │ │ │ │ │ - for (i = layer.grid.length - 1; i >= 0; --i) { │ │ │ │ │ - for (j = layer.grid[i].length - 1; j >= 0; --j) { │ │ │ │ │ - tile = layer.grid[i][j]; │ │ │ │ │ - this.addTile({ │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - if (tile.url && !tile.imgDiv) { │ │ │ │ │ - this.manageTileCache({ │ │ │ │ │ - object: tile │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeLayer │ │ │ │ │ - * Handles the map's preremovelayer event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ - */ │ │ │ │ │ - removeLayer: function(evt) { │ │ │ │ │ - var layer = evt.layer; │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ - this.clearTileQueue({ │ │ │ │ │ - object: layer │ │ │ │ │ - }); │ │ │ │ │ - if (layer.events) { │ │ │ │ │ - layer.events.un({ │ │ │ │ │ - addtile: this.addTile, │ │ │ │ │ - retile: this.clearTileQueue, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (layer.grid) { │ │ │ │ │ - var i, j, tile; │ │ │ │ │ - for (i = layer.grid.length - 1; i >= 0; --i) { │ │ │ │ │ - for (j = layer.grid[i].length - 1; j >= 0; --j) { │ │ │ │ │ - tile = layer.grid[i][j]; │ │ │ │ │ - this.unloadTile({ │ │ │ │ │ - object: tile │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateTimeout │ │ │ │ │ - * Applies the or to the loop, │ │ │ │ │ - * and schedules more queue processing after if there are still │ │ │ │ │ - * tiles in the queue. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} The map to update the timeout for │ │ │ │ │ - * delay - {Number} The delay to apply │ │ │ │ │ - * nice - {Boolean} If true, the timeout function will only be created if │ │ │ │ │ - * the tilequeue is not empty. This is used by the move handler to │ │ │ │ │ - * avoid impacts on dragging performance. For other events, the tile │ │ │ │ │ - * queue may not be populated yet, so we need to set the timer │ │ │ │ │ - * regardless of the queue size. │ │ │ │ │ - */ │ │ │ │ │ - updateTimeout: function(map, delay, nice) { │ │ │ │ │ - window.clearTimeout(this.tileQueueId[map.id]); │ │ │ │ │ - var tileQueue = this.tileQueue[map.id]; │ │ │ │ │ - if (!nice || tileQueue.length) { │ │ │ │ │ - this.tileQueueId[map.id] = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(function() { │ │ │ │ │ - this.drawTilesFromQueue(map); │ │ │ │ │ - if (tileQueue.length) { │ │ │ │ │ - this.updateTimeout(map, this.frameDelay); │ │ │ │ │ - } │ │ │ │ │ - }, this), delay │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addTile │ │ │ │ │ - * Listener for the layer's addtile event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ - */ │ │ │ │ │ - addTile: function(evt) { │ │ │ │ │ - if (evt.tile instanceof OpenLayers.Tile.Image) { │ │ │ │ │ - evt.tile.events.on({ │ │ │ │ │ - beforedraw: this.queueTileDraw, │ │ │ │ │ - beforeload: this.manageTileCache, │ │ │ │ │ - loadend: this.addToCache, │ │ │ │ │ - unload: this.unloadTile, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - // Layer has the wrong tile type, so don't handle it any longer │ │ │ │ │ - this.removeLayer({ │ │ │ │ │ - layer: evt.tile.layer │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: unloadTile │ │ │ │ │ - * Listener for the tile's unload event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ - */ │ │ │ │ │ - unloadTile: function(evt) { │ │ │ │ │ - var tile = evt.object; │ │ │ │ │ - tile.events.un({ │ │ │ │ │ - beforedraw: this.queueTileDraw, │ │ │ │ │ - beforeload: this.manageTileCache, │ │ │ │ │ - loadend: this.addToCache, │ │ │ │ │ - unload: this.unloadTile, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - OpenLayers.Util.removeItem(this.tileQueue[tile.layer.map.id], tile); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: queueTileDraw │ │ │ │ │ - * Adds a tile to the queue that will draw it. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument of the tile's beforedraw event │ │ │ │ │ - */ │ │ │ │ │ - queueTileDraw: function(evt) { │ │ │ │ │ - var tile = evt.object; │ │ │ │ │ - var queued = false; │ │ │ │ │ - var layer = tile.layer; │ │ │ │ │ - var url = layer.getURL(tile.bounds); │ │ │ │ │ - var img = this.tileCache[url]; │ │ │ │ │ - if (img && img.className !== 'olTileImage') { │ │ │ │ │ - // cached image no longer valid, e.g. because we're olTileReplacing │ │ │ │ │ - delete this.tileCache[url]; │ │ │ │ │ - OpenLayers.Util.removeItem(this.tileCacheIndex, url); │ │ │ │ │ - img = null; │ │ │ │ │ - } │ │ │ │ │ - // queue only if image with same url not cached already │ │ │ │ │ - if (layer.url && (layer.async || !img)) { │ │ │ │ │ - // add to queue only if not in queue already │ │ │ │ │ - var tileQueue = this.tileQueue[layer.map.id]; │ │ │ │ │ - if (!~OpenLayers.Util.indexOf(tileQueue, tile)) { │ │ │ │ │ - tileQueue.push(tile); │ │ │ │ │ - } │ │ │ │ │ - queued = true; │ │ │ │ │ - } │ │ │ │ │ - return !queued; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: drawTilesFromQueue │ │ │ │ │ - * Draws tiles from the tileQueue, and unqueues the tiles │ │ │ │ │ - */ │ │ │ │ │ - drawTilesFromQueue: function(map) { │ │ │ │ │ - var tileQueue = this.tileQueue[map.id]; │ │ │ │ │ - var limit = this.tilesPerFrame; │ │ │ │ │ - var animating = map.zoomTween && map.zoomTween.playing; │ │ │ │ │ - while (!animating && tileQueue.length && limit) { │ │ │ │ │ - tileQueue.shift().draw(true); │ │ │ │ │ - --limit; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: manageTileCache │ │ │ │ │ - * Adds, updates, removes and fetches cache entries. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument of the tile's beforeload event │ │ │ │ │ - */ │ │ │ │ │ - manageTileCache: function(evt) { │ │ │ │ │ - var tile = evt.object; │ │ │ │ │ - var img = this.tileCache[tile.url]; │ │ │ │ │ - if (img) { │ │ │ │ │ - // if image is on its layer's backbuffer, remove it from backbuffer │ │ │ │ │ - if (img.parentNode && │ │ │ │ │ - OpenLayers.Element.hasClass(img.parentNode, 'olBackBuffer')) { │ │ │ │ │ - img.parentNode.removeChild(img); │ │ │ │ │ - img.id = null; │ │ │ │ │ - } │ │ │ │ │ - // only use image from cache if it is not on a layer already │ │ │ │ │ - if (!img.parentNode) { │ │ │ │ │ - img.style.visibility = 'hidden'; │ │ │ │ │ - img.style.opacity = 0; │ │ │ │ │ - tile.setImage(img); │ │ │ │ │ - // LRU - move tile to the end of the array to mark it as the most │ │ │ │ │ - // recently used │ │ │ │ │ - OpenLayers.Util.removeItem(this.tileCacheIndex, tile.url); │ │ │ │ │ - this.tileCacheIndex.push(tile.url); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addToCache │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument for the tile's loadend event │ │ │ │ │ - */ │ │ │ │ │ - addToCache: function(evt) { │ │ │ │ │ - var tile = evt.object; │ │ │ │ │ - if (!this.tileCache[tile.url]) { │ │ │ │ │ - if (!OpenLayers.Element.hasClass(tile.imgDiv, 'olImageLoadError')) { │ │ │ │ │ - if (this.tileCacheIndex.length >= this.cacheSize) { │ │ │ │ │ - delete this.tileCache[this.tileCacheIndex[0]]; │ │ │ │ │ - this.tileCacheIndex.shift(); │ │ │ │ │ - } │ │ │ │ │ - this.tileCache[tile.url] = tile.imgDiv; │ │ │ │ │ - this.tileCacheIndex.push(tile.url); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clearTileQueue │ │ │ │ │ - * Clears the tile queue from tiles of a specific layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Listener argument of the layer's retile event │ │ │ │ │ - */ │ │ │ │ │ - clearTileQueue: function(evt) { │ │ │ │ │ - var layer = evt.object; │ │ │ │ │ - var tileQueue = this.tileQueue[layer.map.id]; │ │ │ │ │ - for (var i = tileQueue.length - 1; i >= 0; --i) { │ │ │ │ │ - if (tileQueue[i].layer === layer) { │ │ │ │ │ - tileQueue.splice(i, 1); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var i = this.maps.length - 1; i >= 0; --i) { │ │ │ │ │ - this.removeMap(this.maps[i]); │ │ │ │ │ - } │ │ │ │ │ - this.maps = null; │ │ │ │ │ - this.tileQueue = null; │ │ │ │ │ - this.tileQueueId = null; │ │ │ │ │ - this.tileCache = null; │ │ │ │ │ - this.tileCacheIndex = null; │ │ │ │ │ - this._destroyed = true; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/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/Filter.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Style.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Filter │ │ │ │ │ - * This class represents an OGC Filter. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Filter = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Filter │ │ │ │ │ - * This class represents a generic filter. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Remove reference to anything added. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: evaluate │ │ │ │ │ - * Evaluates this filter in a specific context. Instances or subclasses │ │ │ │ │ - * are supposed to override this method. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * context - {Object} Context to use in evaluating the filter. If a vector │ │ │ │ │ - * feature is provided, the feature.attributes will be used as context. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The filter applies. │ │ │ │ │ - */ │ │ │ │ │ - evaluate: function(context) { │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Clones this filter. Should be implemented by subclasses. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Clone of this filter. │ │ │ │ │ - */ │ │ │ │ │ - clone: function() { │ │ │ │ │ - return null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: toString │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} Include in your build to get a CQL │ │ │ │ │ - * representation of the filter returned. Otherwise "[Object object]" │ │ │ │ │ - * will be returned. │ │ │ │ │ - */ │ │ │ │ │ - toString: function() { │ │ │ │ │ - var string; │ │ │ │ │ - if (OpenLayers.Format && OpenLayers.Format.CQL) { │ │ │ │ │ - string = OpenLayers.Format.CQL.prototype.write(this); │ │ │ │ │ - } else { │ │ │ │ │ - string = Object.prototype.toString.call(this); │ │ │ │ │ - } │ │ │ │ │ - return string; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Filter" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/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/Control.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control │ │ │ │ │ - * Controls affect the display or behavior of the map. They allow everything │ │ │ │ │ - * from panning and zooming to displaying a scale indicator. Controls by │ │ │ │ │ - * default are added to the map they are contained within however it is │ │ │ │ │ - * possible to add a control to an external div by passing the div in the │ │ │ │ │ - * options parameter. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * The following example shows how to add many of the common controls │ │ │ │ │ - * to a map. │ │ │ │ │ - * │ │ │ │ │ - * > var map = new OpenLayers.Map('map', { controls: [] }); │ │ │ │ │ - * > │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.PanZoomBar()); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.Permalink()); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.Permalink('permalink')); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.MousePosition()); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.OverviewMap()); │ │ │ │ │ - * > map.addControl(new OpenLayers.Control.KeyboardDefaults()); │ │ │ │ │ - * │ │ │ │ │ - * The next code fragment is a quick example of how to intercept │ │ │ │ │ - * shift-mouse click to display the extent of the bounding box │ │ │ │ │ - * dragged out by the user. Usually controls are not created │ │ │ │ │ - * in exactly this manner. See the source for a more complete │ │ │ │ │ - * example: │ │ │ │ │ - * │ │ │ │ │ - * > var control = new OpenLayers.Control(); │ │ │ │ │ - * > OpenLayers.Util.extend(control, { │ │ │ │ │ - * > draw: function () { │ │ │ │ │ - * > // this Handler.Box will intercept the shift-mousedown │ │ │ │ │ - * > // before Control.MouseDefault gets to see it │ │ │ │ │ - * > this.box = new OpenLayers.Handler.Box( control, │ │ │ │ │ - * > {"done": this.notice}, │ │ │ │ │ - * > {keyMask: OpenLayers.Handler.MOD_SHIFT}); │ │ │ │ │ - * > this.box.activate(); │ │ │ │ │ - * > }, │ │ │ │ │ - * > │ │ │ │ │ - * > notice: function (bounds) { │ │ │ │ │ - * > OpenLayers.Console.userError(bounds); │ │ │ │ │ - * > } │ │ │ │ │ - * > }); │ │ │ │ │ - * > map.addControl(control); │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: id │ │ │ │ │ - * {String} │ │ │ │ │ - */ │ │ │ │ │ - id: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} this gets set in the addControl() function in │ │ │ │ │ - * OpenLayers.Map │ │ │ │ │ - */ │ │ │ │ │ - map: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: div │ │ │ │ │ - * {DOMElement} The element that contains the control, if not present the │ │ │ │ │ - * control is placed inside the map. │ │ │ │ │ - */ │ │ │ │ │ - div: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: type │ │ │ │ │ - * {Number} Controls can have a 'type'. The type determines the type of │ │ │ │ │ - * interactions which are possible with them when they are placed in an │ │ │ │ │ - * . │ │ │ │ │ - */ │ │ │ │ │ - type: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: allowSelection │ │ │ │ │ - * {Boolean} By default, controls do not allow selection, because │ │ │ │ │ - * it may interfere with map dragging. If this is true, OpenLayers │ │ │ │ │ - * will not prevent selection of the control. │ │ │ │ │ - * Default is false. │ │ │ │ │ - */ │ │ │ │ │ - allowSelection: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: displayClass │ │ │ │ │ - * {string} This property is used for CSS related to the drawing of the │ │ │ │ │ - * Control. │ │ │ │ │ - */ │ │ │ │ │ - displayClass: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: title │ │ │ │ │ - * {string} This property is used for showing a tooltip over the │ │ │ │ │ - * Control. │ │ │ │ │ - */ │ │ │ │ │ - title: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * false. │ │ │ │ │ - */ │ │ │ │ │ - autoActivate: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: active │ │ │ │ │ - * {Boolean} The control is active (read-only). Use and │ │ │ │ │ - * to change control state. │ │ │ │ │ - */ │ │ │ │ │ - active: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ - */ │ │ │ │ │ - handlerOptions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: handler │ │ │ │ │ - * {} null │ │ │ │ │ - */ │ │ │ │ │ - handler: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: eventListeners │ │ │ │ │ - * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ - * object will be registered with . Object │ │ │ │ │ - * structure must be a listeners object as shown in the example for │ │ │ │ │ - * the events.on method. │ │ │ │ │ - */ │ │ │ │ │ - eventListeners: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Listeners will be called with a reference to an event object. The │ │ │ │ │ - * properties of this event depends on exactly what happened. │ │ │ │ │ - * │ │ │ │ │ - * All event objects have at least the following properties: │ │ │ │ │ - * object - {Object} A reference to control.events.object (a reference │ │ │ │ │ - * to the control). │ │ │ │ │ - * element - {DOMElement} A reference to control.events.element (which │ │ │ │ │ - * will be null unless documented otherwise). │ │ │ │ │ - * │ │ │ │ │ - * Supported map event types: │ │ │ │ │ - * activate - Triggered when activated. │ │ │ │ │ - * deactivate - Triggered when deactivated. │ │ │ │ │ - */ │ │ │ │ │ - events: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control │ │ │ │ │ - * Create an OpenLayers Control. The options passed as a parameter │ │ │ │ │ - * directly extend the control. For example passing the following: │ │ │ │ │ - * │ │ │ │ │ - * > var control = new OpenLayers.Control({div: myDiv}); │ │ │ │ │ - * │ │ │ │ │ - * Overrides the default div attribute value of null. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - // We do this before the extend so that instances can override │ │ │ │ │ - // className in options. │ │ │ │ │ - this.displayClass = │ │ │ │ │ - this.CLASS_NAME.replace("OpenLayers.", "ol").replace(/\./g, ""); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - │ │ │ │ │ - this.events = new OpenLayers.Events(this); │ │ │ │ │ - if (this.eventListeners instanceof Object) { │ │ │ │ │ - this.events.on(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - if (this.id == null) { │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * The destroy method is used to perform any clean up before the control │ │ │ │ │ - * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ - * to prevent memory leaks. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.events) { │ │ │ │ │ - if (this.eventListeners) { │ │ │ │ │ - this.events.un(this.eventListeners); │ │ │ │ │ - } │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - } │ │ │ │ │ - this.eventListeners = null; │ │ │ │ │ - │ │ │ │ │ - // eliminate circular references │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.destroy(); │ │ │ │ │ - this.handler = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.handlers) { │ │ │ │ │ - for (var key in this.handlers) { │ │ │ │ │ - if (this.handlers.hasOwnProperty(key) && │ │ │ │ │ - typeof this.handlers[key].destroy == "function") { │ │ │ │ │ - this.handlers[key].destroy(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.handlers = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.removeControl(this); │ │ │ │ │ - this.map = null; │ │ │ │ │ - } │ │ │ │ │ - this.div = null; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control. This is done through an accessor │ │ │ │ │ - * so that subclasses can override this and take special action once │ │ │ │ │ - * they have their map variable set. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.map = map; │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.setMap(map); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * The draw method is called when the control is ready to be displayed │ │ │ │ │ - * on the page. If a div has not been created one is created. Controls │ │ │ │ │ - * with a visual component will almost always want to override this method │ │ │ │ │ - * to customize the look of control. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} The top-left pixel position of the control │ │ │ │ │ - * or null. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ - */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - if (this.div == null) { │ │ │ │ │ - this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ - this.div.className = this.displayClass; │ │ │ │ │ - if (!this.allowSelection) { │ │ │ │ │ - this.div.className += " olControlNoSelect"; │ │ │ │ │ - this.div.setAttribute("unselectable", "on", 0); │ │ │ │ │ - this.div.onselectstart = OpenLayers.Function.False; │ │ │ │ │ - } │ │ │ │ │ - if (this.title != "") { │ │ │ │ │ - this.div.title = this.title; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (px != null) { │ │ │ │ │ - this.position = px.clone(); │ │ │ │ │ - } │ │ │ │ │ - this.moveTo(this.position); │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Sets the left and top style attributes to the passed in pixel │ │ │ │ │ - * coordinates. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - if ((px != null) && (this.div != null)) { │ │ │ │ │ - this.div.style.left = px.x + "px"; │ │ │ │ │ - this.div.style.top = px.y + "px"; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Explicitly activates a control and it's associated │ │ │ │ │ - * handler if one has been set. Controls can be │ │ │ │ │ - * deactivated by calling the deactivate() method. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the control was successfully activated or │ │ │ │ │ - * false if the control was already active. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.activate(); │ │ │ │ │ - } │ │ │ │ │ - this.active = true; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - OpenLayers.Element.addClass( │ │ │ │ │ - this.map.viewPortDiv, │ │ │ │ │ - this.displayClass.replace(/ /g, "") + "Active" │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("activate"); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivates a control and it's associated handler if any. The exact │ │ │ │ │ - * effect of this depends on the control itself. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} True if the control was effectively deactivated or false │ │ │ │ │ - * if the control was already inactive. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.deactivate(); │ │ │ │ │ - } │ │ │ │ │ - this.active = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, │ │ │ │ │ - this.displayClass.replace(/ /g, "") + "Active" │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("deactivate"); │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Control.TYPE_BUTTON │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.TYPE_BUTTON = 1; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Control.TYPE_TOGGLE │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.TYPE_TOGGLE = 2; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Control.TYPE_TOOL │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.TYPE_TOOL = 3; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/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/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/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. │ │ │ │ │ + * 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); │ │ │ │ │ } │ │ │ │ │ @@ -24825,14 +17327,557 @@ │ │ │ │ │ * Constant: OpenLayers.Format.WFST.DEFAULTS │ │ │ │ │ * {Object} Default properties for the WFST format. │ │ │ │ │ */ │ │ │ │ │ OpenLayers.Format.WFST.DEFAULTS = { │ │ │ │ │ "version": "1.0.0" │ │ │ │ │ }; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ + OpenLayers/Style.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Style │ │ │ │ │ + * This class represents a UserStyle obtained │ │ │ │ │ + * from a SLD, containing styling rules. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Style = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique id for this session. │ │ │ │ │ + */ │ │ │ │ │ + id: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} │ │ │ │ │ + */ │ │ │ │ │ + name: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: title │ │ │ │ │ + * {String} Title of this style (set if included in SLD) │ │ │ │ │ + */ │ │ │ │ │ + title: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: description │ │ │ │ │ + * {String} Description of this style (set if abstract is included in SLD) │ │ │ │ │ + */ │ │ │ │ │ + description: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: layerName │ │ │ │ │ + * {} name of the layer that this style belongs to, usually │ │ │ │ │ + * according to the NamedLayer attribute of an SLD document. │ │ │ │ │ + */ │ │ │ │ │ + layerName: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: isDefault │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + isDefault: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: rules │ │ │ │ │ + * {Array()} │ │ │ │ │ + */ │ │ │ │ │ + rules: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: context │ │ │ │ │ + * {Object} An optional object with properties that symbolizers' property │ │ │ │ │ + * values should be evaluated against. If no context is specified, │ │ │ │ │ + * feature.attributes will be used │ │ │ │ │ + */ │ │ │ │ │ + context: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: defaultStyle │ │ │ │ │ + * {Object} hash of style properties to use as default for merging │ │ │ │ │ + * rule-based style symbolizers onto. If no rules are defined, │ │ │ │ │ + * createSymbolizer will return this style. If is set to │ │ │ │ │ + * true, the defaultStyle will only be taken into account if there are │ │ │ │ │ + * rules defined. │ │ │ │ │ + */ │ │ │ │ │ + defaultStyle: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: defaultsPerSymbolizer │ │ │ │ │ + * {Boolean} If set to true, the will extend the symbolizer │ │ │ │ │ + * of every rule. Properties of the will also be used to set │ │ │ │ │ + * missing symbolizer properties if the symbolizer has stroke, fill or │ │ │ │ │ + * graphic set to true. Default is false. │ │ │ │ │ + */ │ │ │ │ │ + defaultsPerSymbolizer: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: propertyStyles │ │ │ │ │ + * {Hash of Boolean} cache of style properties that need to be parsed for │ │ │ │ │ + * propertyNames. Property names are keys, values won't be used. │ │ │ │ │ + */ │ │ │ │ │ + propertyStyles: null, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Style │ │ │ │ │ + * Creates a UserStyle. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * style - {Object} Optional hash of style properties that will be │ │ │ │ │ + * used as default style for this style object. This style │ │ │ │ │ + * applies if no rules are specified. Symbolizers defined in │ │ │ │ │ + * rules will extend this default style. │ │ │ │ │ + * options - {Object} An optional object with properties to set on the │ │ │ │ │ + * style. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * rules - {Array()} List of rules to be added to the │ │ │ │ │ + * style. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(style, options) { │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.rules = []; │ │ │ │ │ + if (options && options.rules) { │ │ │ │ │ + this.addRules(options.rules); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // use the default style from OpenLayers.Feature.Vector if no style │ │ │ │ │ + // was given in the constructor │ │ │ │ │ + this.setDefaultStyle(style || │ │ │ │ │ + OpenLayers.Feature.Vector.style["default"]); │ │ │ │ │ + │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var i = 0, len = this.rules.length; i < len; i++) { │ │ │ │ │ + this.rules[i].destroy(); │ │ │ │ │ + this.rules[i] = null; │ │ │ │ │ + } │ │ │ │ │ + this.rules = null; │ │ │ │ │ + this.defaultStyle = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createSymbolizer │ │ │ │ │ + * creates a style by applying all feature-dependent rules to the base │ │ │ │ │ + * style. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} feature to evaluate rules for │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} symbolizer hash │ │ │ │ │ + */ │ │ │ │ │ + createSymbolizer: function(feature) { │ │ │ │ │ + var style = this.defaultsPerSymbolizer ? {} : this.createLiterals( │ │ │ │ │ + OpenLayers.Util.extend({}, this.defaultStyle), feature); │ │ │ │ │ + │ │ │ │ │ + var rules = this.rules; │ │ │ │ │ + │ │ │ │ │ + var rule, context; │ │ │ │ │ + var elseRules = []; │ │ │ │ │ + var appliedRules = false; │ │ │ │ │ + for (var i = 0, len = rules.length; i < len; i++) { │ │ │ │ │ + rule = rules[i]; │ │ │ │ │ + // does the rule apply? │ │ │ │ │ + var applies = rule.evaluate(feature); │ │ │ │ │ + │ │ │ │ │ + if (applies) { │ │ │ │ │ + if (rule instanceof OpenLayers.Rule && rule.elseFilter) { │ │ │ │ │ + elseRules.push(rule); │ │ │ │ │ + } else { │ │ │ │ │ + appliedRules = true; │ │ │ │ │ + this.applySymbolizer(rule, style, feature); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // if no other rules apply, apply the rules with else filters │ │ │ │ │ + if (appliedRules == false && elseRules.length > 0) { │ │ │ │ │ + appliedRules = true; │ │ │ │ │ + for (var i = 0, len = elseRules.length; i < len; i++) { │ │ │ │ │ + this.applySymbolizer(elseRules[i], style, feature); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // don't display if there were rules but none applied │ │ │ │ │ + if (rules.length > 0 && appliedRules == false) { │ │ │ │ │ + style.display = "none"; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (style.label != null && typeof style.label !== "string") { │ │ │ │ │ + style.label = String(style.label); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return style; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: applySymbolizer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * rule - {} │ │ │ │ │ + * style - {Object} │ │ │ │ │ + * feature - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} A style with new symbolizer applied. │ │ │ │ │ + */ │ │ │ │ │ + applySymbolizer: function(rule, style, feature) { │ │ │ │ │ + var symbolizerPrefix = feature.geometry ? │ │ │ │ │ + this.getSymbolizerPrefix(feature.geometry) : │ │ │ │ │ + OpenLayers.Style.SYMBOLIZER_PREFIXES[0]; │ │ │ │ │ + │ │ │ │ │ + var symbolizer = rule.symbolizer[symbolizerPrefix] || rule.symbolizer; │ │ │ │ │ + │ │ │ │ │ + if (this.defaultsPerSymbolizer === true) { │ │ │ │ │ + var defaults = this.defaultStyle; │ │ │ │ │ + OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ + pointRadius: defaults.pointRadius │ │ │ │ │ + }); │ │ │ │ │ + if (symbolizer.stroke === true || symbolizer.graphic === true) { │ │ │ │ │ + OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ + strokeWidth: defaults.strokeWidth, │ │ │ │ │ + strokeColor: defaults.strokeColor, │ │ │ │ │ + strokeOpacity: defaults.strokeOpacity, │ │ │ │ │ + strokeDashstyle: defaults.strokeDashstyle, │ │ │ │ │ + strokeLinecap: defaults.strokeLinecap │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.fill === true || symbolizer.graphic === true) { │ │ │ │ │ + OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ + fillColor: defaults.fillColor, │ │ │ │ │ + fillOpacity: defaults.fillOpacity │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.graphic === true) { │ │ │ │ │ + OpenLayers.Util.applyDefaults(symbolizer, { │ │ │ │ │ + pointRadius: this.defaultStyle.pointRadius, │ │ │ │ │ + externalGraphic: this.defaultStyle.externalGraphic, │ │ │ │ │ + graphicName: this.defaultStyle.graphicName, │ │ │ │ │ + graphicOpacity: this.defaultStyle.graphicOpacity, │ │ │ │ │ + graphicWidth: this.defaultStyle.graphicWidth, │ │ │ │ │ + graphicHeight: this.defaultStyle.graphicHeight, │ │ │ │ │ + graphicXOffset: this.defaultStyle.graphicXOffset, │ │ │ │ │ + graphicYOffset: this.defaultStyle.graphicYOffset │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // merge the style with the current style │ │ │ │ │ + return this.createLiterals( │ │ │ │ │ + OpenLayers.Util.extend(style, symbolizer), feature); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createLiterals │ │ │ │ │ + * creates literals for all style properties that have an entry in │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * style - {Object} style to create literals for. Will be modified │ │ │ │ │ + * inline. │ │ │ │ │ + * feature - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} the modified style │ │ │ │ │ + */ │ │ │ │ │ + createLiterals: function(style, feature) { │ │ │ │ │ + var context = OpenLayers.Util.extend({}, feature.attributes || feature.data); │ │ │ │ │ + OpenLayers.Util.extend(context, this.context); │ │ │ │ │ + │ │ │ │ │ + for (var i in this.propertyStyles) { │ │ │ │ │ + style[i] = OpenLayers.Style.createLiteral(style[i], context, feature, i); │ │ │ │ │ + } │ │ │ │ │ + return style; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: findPropertyStyles │ │ │ │ │ + * Looks into all rules for this style and the defaultStyle to collect │ │ │ │ │ + * all the style hash property names containing ${...} strings that have │ │ │ │ │ + * to be replaced using the createLiteral method before returning them. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} hash of property names that need createLiteral parsing. The │ │ │ │ │ + * name of the property is the key, and the value is true; │ │ │ │ │ + */ │ │ │ │ │ + findPropertyStyles: function() { │ │ │ │ │ + var propertyStyles = {}; │ │ │ │ │ + │ │ │ │ │ + // check the default style │ │ │ │ │ + var style = this.defaultStyle; │ │ │ │ │ + this.addPropertyStyles(propertyStyles, style); │ │ │ │ │ + │ │ │ │ │ + // walk through all rules to check for properties in their symbolizer │ │ │ │ │ + var rules = this.rules; │ │ │ │ │ + var symbolizer, value; │ │ │ │ │ + for (var i = 0, len = rules.length; i < len; i++) { │ │ │ │ │ + symbolizer = rules[i].symbolizer; │ │ │ │ │ + for (var key in symbolizer) { │ │ │ │ │ + value = symbolizer[key]; │ │ │ │ │ + if (typeof value == "object") { │ │ │ │ │ + // symbolizer key is "Point", "Line" or "Polygon" │ │ │ │ │ + this.addPropertyStyles(propertyStyles, value); │ │ │ │ │ + } else { │ │ │ │ │ + // symbolizer is a hash of style properties │ │ │ │ │ + this.addPropertyStyles(propertyStyles, symbolizer); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return propertyStyles; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addPropertyStyles │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * propertyStyles - {Object} hash to add new property styles to. Will be │ │ │ │ │ + * modified inline │ │ │ │ │ + * symbolizer - {Object} search this symbolizer for property styles │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} propertyStyles hash │ │ │ │ │ + */ │ │ │ │ │ + addPropertyStyles: function(propertyStyles, symbolizer) { │ │ │ │ │ + var property; │ │ │ │ │ + for (var key in symbolizer) { │ │ │ │ │ + property = symbolizer[key]; │ │ │ │ │ + if (typeof property == "string" && │ │ │ │ │ + property.match(/\$\{\w+\}/)) { │ │ │ │ │ + propertyStyles[key] = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return propertyStyles; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addRules │ │ │ │ │ + * Adds rules to this style. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * rules - {Array()} │ │ │ │ │ + */ │ │ │ │ │ + addRules: function(rules) { │ │ │ │ │ + Array.prototype.push.apply(this.rules, rules); │ │ │ │ │ + this.propertyStyles = this.findPropertyStyles(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setDefaultStyle │ │ │ │ │ + * Sets the default style for this style object. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * style - {Object} Hash of style properties │ │ │ │ │ + */ │ │ │ │ │ + setDefaultStyle: function(style) { │ │ │ │ │ + this.defaultStyle = style; │ │ │ │ │ + this.propertyStyles = this.findPropertyStyles(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getSymbolizerPrefix │ │ │ │ │ + * Returns the correct symbolizer prefix according to the │ │ │ │ │ + * geometry type of the passed geometry │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} key of the according symbolizer │ │ │ │ │ + */ │ │ │ │ │ + getSymbolizerPrefix: function(geometry) { │ │ │ │ │ + var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES; │ │ │ │ │ + for (var i = 0, len = prefixes.length; i < len; i++) { │ │ │ │ │ + if (geometry.CLASS_NAME.indexOf(prefixes[i]) != -1) { │ │ │ │ │ + return prefixes[i]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this style. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this style. │ │ │ │ │ + */ │ │ │ │ │ + clone: function() { │ │ │ │ │ + var options = OpenLayers.Util.extend({}, this); │ │ │ │ │ + // clone rules │ │ │ │ │ + if (this.rules) { │ │ │ │ │ + options.rules = []; │ │ │ │ │ + for (var i = 0, len = this.rules.length; i < len; ++i) { │ │ │ │ │ + options.rules.push(this.rules[i].clone()); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // clone context │ │ │ │ │ + options.context = this.context && OpenLayers.Util.extend({}, this.context); │ │ │ │ │ + //clone default style │ │ │ │ │ + var defaultStyle = OpenLayers.Util.extend({}, this.defaultStyle); │ │ │ │ │ + return new OpenLayers.Style(defaultStyle, options); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Style" │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Function: createLiteral │ │ │ │ │ + * converts a style value holding a combination of PropertyName and Literal │ │ │ │ │ + * into a Literal, taking the property values from the passed features. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * value - {String} value to parse. If this string contains a construct like │ │ │ │ │ + * "foo ${bar}", then "foo " will be taken as literal, and "${bar}" │ │ │ │ │ + * will be replaced by the value of the "bar" attribute of the passed │ │ │ │ │ + * feature. │ │ │ │ │ + * context - {Object} context to take attribute values from │ │ │ │ │ + * feature - {} optional feature to pass to │ │ │ │ │ + * for evaluating functions in the │ │ │ │ │ + * context. │ │ │ │ │ + * property - {String} optional, name of the property for which the literal is │ │ │ │ │ + * being created for evaluating functions in the context. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} the parsed value. In the example of the value parameter above, the │ │ │ │ │ + * result would be "foo valueOfBar", assuming that the passed feature has an │ │ │ │ │ + * attribute named "bar" with the value "valueOfBar". │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Style.createLiteral = function(value, context, feature, property) { │ │ │ │ │ + if (typeof value == "string" && value.indexOf("${") != -1) { │ │ │ │ │ + value = OpenLayers.String.format(value, context, [feature, property]); │ │ │ │ │ + value = (isNaN(value) || !value) ? value : parseFloat(value); │ │ │ │ │ + } │ │ │ │ │ + return value; │ │ │ │ │ +}; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Style.SYMBOLIZER_PREFIXES │ │ │ │ │ + * {Array} prefixes of the sld symbolizers. These are the │ │ │ │ │ + * same as the main geometry types │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon', 'Text', │ │ │ │ │ + 'Raster' │ │ │ │ │ +]; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Filter.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Filter │ │ │ │ │ + * This class represents an OGC Filter. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Filter = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Filter │ │ │ │ │ + * This class represents a generic filter. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Remove reference to anything added. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: evaluate │ │ │ │ │ + * Evaluates this filter in a specific context. Instances or subclasses │ │ │ │ │ + * are supposed to override this method. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * context - {Object} Context to use in evaluating the filter. If a vector │ │ │ │ │ + * feature is provided, the feature.attributes will be used as context. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The filter applies. │ │ │ │ │ + */ │ │ │ │ │ + evaluate: function(context) { │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Clones this filter. Should be implemented by subclasses. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Clone of this filter. │ │ │ │ │ + */ │ │ │ │ │ + clone: function() { │ │ │ │ │ + return null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: toString │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} Include in your build to get a CQL │ │ │ │ │ + * representation of the filter returned. Otherwise "[Object object]" │ │ │ │ │ + * will be returned. │ │ │ │ │ + */ │ │ │ │ │ + toString: function() { │ │ │ │ │ + var string; │ │ │ │ │ + if (OpenLayers.Format && OpenLayers.Format.CQL) { │ │ │ │ │ + string = OpenLayers.Format.CQL.prototype.write(this); │ │ │ │ │ + } else { │ │ │ │ │ + string = Object.prototype.toString.call(this); │ │ │ │ │ + } │ │ │ │ │ + return string; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Filter" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ OpenLayers/Filter/Spatial.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ @@ -31477,14054 +24522,13800 @@ │ │ │ │ │ this.servers = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: 'OpenLayers.WPSClient' │ │ │ │ │ │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler.js │ │ │ │ │ + OpenLayers/StyleMap.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.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. │ │ │ │ │ + * Class: OpenLayers.StyleMap │ │ │ │ │ */ │ │ │ │ │ -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, │ │ │ │ │ +OpenLayers.StyleMap = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: styles │ │ │ │ │ + * {Object} Hash of {}, keyed by names of well known │ │ │ │ │ + * rendering intents (e.g. "default", "temporary", "select", "delete"). │ │ │ │ │ */ │ │ │ │ │ - evt: null, │ │ │ │ │ + styles: 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. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - touch: false, │ │ │ │ │ + extendDefault: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler │ │ │ │ │ - * Construct a handler. │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.StyleMap │ │ │ │ │ + * │ │ │ │ │ * 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. │ │ │ │ │ + * 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(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.control = control; │ │ │ │ │ - this.callbacks = callbacks; │ │ │ │ │ + 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"]) │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - var map = this.map || control.map; │ │ │ │ │ - if (map) { │ │ │ │ │ - this.setMap(map); │ │ │ │ │ + // 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.map = map; │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ - checkModifiers: function(evt) { │ │ │ │ │ - if (this.keyMask == null) { │ │ │ │ │ - return true; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var key in this.styles) { │ │ │ │ │ + this.styles[key].destroy(); │ │ │ │ │ } │ │ │ │ │ - /* 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); │ │ │ │ │ + this.styles = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Turn on the handler. Returns false if the handler was already active. │ │ │ │ │ + * Method: createSymbolizer │ │ │ │ │ + * Creates the symbolizer for a feature for a render intent. │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * 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: │ │ │ │ │ - * {Boolean} The handler was deactivated. │ │ │ │ │ + * {Object} symbolizer hash │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (!this.active) { │ │ │ │ │ - return false; │ │ │ │ │ + createSymbolizer: function(feature, intent) { │ │ │ │ │ + if (!feature) { │ │ │ │ │ + feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ } │ │ │ │ │ - // 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]]); │ │ │ │ │ - } │ │ │ │ │ + if (!this.styles[intent]) { │ │ │ │ │ + intent = "default"; │ │ │ │ │ } │ │ │ │ │ - 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]]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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: callback │ │ │ │ │ - * Trigger the control's named callback with the given arguments │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * 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). │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - callback: function(name, args) { │ │ │ │ │ - if (name && this.callbacks[name]) { │ │ │ │ │ - this.callbacks[name].apply(this.control, args); │ │ │ │ │ + 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: 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" │ │ │ │ │ + CLASS_NAME: "OpenLayers.StyleMap" │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Handler.MOD_NONE │ │ │ │ │ - * If set as the , returns false if any key is down. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MOD_NONE = 0; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Handler.MOD_SHIFT │ │ │ │ │ - * If set as the , returns false if Shift is down. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MOD_SHIFT = 1; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Handler.MOD_CTRL │ │ │ │ │ - * If set as the , returns false if Ctrl is down. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MOD_CTRL = 2; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Handler.MOD_ALT │ │ │ │ │ - * If set as the , returns false if Alt is down. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MOD_ALT = 4; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: OpenLayers.Handler.MOD_META │ │ │ │ │ - * If set as the , returns false if Cmd is down. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MOD_META = 8; │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Protocol.js │ │ │ │ │ + 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.Protocol │ │ │ │ │ - * Abstract vector layer protocol class. Not to be instantiated directly. Use │ │ │ │ │ - * one of the protocol subclasses instead. │ │ │ │ │ + * Class: OpenLayers.Layer │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Protocol = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: format │ │ │ │ │ - * {} The format used by this protocol. │ │ │ │ │ - */ │ │ │ │ │ - format: null, │ │ │ │ │ +OpenLayers.Layer = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: options │ │ │ │ │ - * {Object} Any options sent to the constructor. │ │ │ │ │ + * APIProperty: id │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - options: null, │ │ │ │ │ + id: 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. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - autoDestroy: true, │ │ │ │ │ + name: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultFilter │ │ │ │ │ - * {} Optional default filter to read requests │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: div │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - defaultFilter: null, │ │ │ │ │ + div: 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. │ │ │ │ │ + * APIProperty: opacity │ │ │ │ │ + * {Float} The layer's opacity. Float number between 0.0 and 1.0. Default │ │ │ │ │ + * is 1. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - this.options = options; │ │ │ │ │ - }, │ │ │ │ │ + opacity: 1, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mergeWithDefaultFilter │ │ │ │ │ - * Merge filter passed to the read method with the default one │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * filter - {} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + alwaysInRange: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Clean up the protocol. │ │ │ │ │ + * Constant: RESOLUTION_PROPERTIES │ │ │ │ │ + * {Array} The properties that are used for calculating resolutions │ │ │ │ │ + * information. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.options = null; │ │ │ │ │ - this.format = null; │ │ │ │ │ - }, │ │ │ │ │ + RESOLUTION_PROPERTIES: [ │ │ │ │ │ + 'scales', 'resolutions', │ │ │ │ │ + 'maxScale', 'minScale', │ │ │ │ │ + 'maxResolution', 'minResolution', │ │ │ │ │ + 'numZoomLevels', 'maxZoomLevel' │ │ │ │ │ + ], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Construct a request for reading new features. │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object for configuring the request. │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * layer.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ * │ │ │ │ │ - * 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. │ │ │ │ │ + * Listeners will be called with a reference to an event object. The │ │ │ │ │ + * properties of this event depends on exactly what happened. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * features - {Array({})} or │ │ │ │ │ - * {} │ │ │ │ │ - * options - {Object} Optional object for configuring the request. │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An │ │ │ │ │ - * object, the same object will be passed to the callback function passed │ │ │ │ │ - * if one exists in the options object. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - create: function() {}, │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: map │ │ │ │ │ + * {} This variable is set when the layer is added to │ │ │ │ │ + * the map, via the accessor function setMap(). │ │ │ │ │ */ │ │ │ │ │ - update: function() {}, │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: isBaseLayer │ │ │ │ │ + * {Boolean} Whether or not the layer is a base layer. This should be set │ │ │ │ │ + * individually by all subclasses. Default is false │ │ │ │ │ */ │ │ │ │ │ - "delete": function() {}, │ │ │ │ │ + isBaseLayer: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: alpha │ │ │ │ │ + * {Boolean} The layer's images have an alpha channel. Default is false. │ │ │ │ │ */ │ │ │ │ │ - commit: function() {}, │ │ │ │ │ + alpha: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: abort │ │ │ │ │ - * Abort an ongoing request. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * response - {} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: displayInLayerSwitcher │ │ │ │ │ + * {Boolean} Display the layer's name in the layer switcher. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - abort: function(response) {}, │ │ │ │ │ + displayInLayerSwitcher: 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 │ │ │ │ │ + * APIProperty: visibility │ │ │ │ │ + * {Boolean} The layer should be displayed in the map. Default is true. │ │ │ │ │ */ │ │ │ │ │ - createCallback: function(method, response, options) { │ │ │ │ │ - return OpenLayers.Function.bind(function() { │ │ │ │ │ - method.apply(this, [response, options]); │ │ │ │ │ - }, this); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Protocol" │ │ │ │ │ -}); │ │ │ │ │ + visibility: true, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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 │ │ │ │ │ + * APIProperty: attribution │ │ │ │ │ + * {String} Attribution string, displayed when an │ │ │ │ │ + * has been added to the map. │ │ │ │ │ */ │ │ │ │ │ - code: null, │ │ │ │ │ + attribution: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: requestType │ │ │ │ │ - * {String} The type of request this response corresponds to. Either │ │ │ │ │ - * "create", "read", "update" or "delete". │ │ │ │ │ + /** │ │ │ │ │ + * Property: inRange │ │ │ │ │ + * {Boolean} The current map resolution is within the layer's min/max │ │ │ │ │ + * range. This is set in whenever the zoom │ │ │ │ │ + * changes. │ │ │ │ │ */ │ │ │ │ │ - requestType: null, │ │ │ │ │ + inRange: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: last │ │ │ │ │ - * {Boolean} - true if this is the last response expected in a commit, │ │ │ │ │ - * false otherwise, defaults to true. │ │ │ │ │ + * Propery: imageSize │ │ │ │ │ + * {} For layers with a gutter, the image is larger than │ │ │ │ │ + * the tile by twice the gutter in each dimension. │ │ │ │ │ */ │ │ │ │ │ - last: true, │ │ │ │ │ + imageSize: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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, │ │ │ │ │ + // OPTIONS │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - data: null, │ │ │ │ │ + options: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: reqFeatures │ │ │ │ │ - * {Array({})} or {} │ │ │ │ │ - * The features provided by the user and placed in the request by the │ │ │ │ │ - * protocol. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - reqFeatures: null, │ │ │ │ │ + eventListeners: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: priv │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - priv: null, │ │ │ │ │ + gutter: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: error │ │ │ │ │ - * {Object} The error object in case a service exception was encountered. │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - error: null, │ │ │ │ │ + projection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Protocol.Response │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Util.extend(this, options); │ │ │ │ │ - }, │ │ │ │ │ + units: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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/Popup.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Popup │ │ │ │ │ - * A popup is a small div that can opened and closed on the map. │ │ │ │ │ - * Typically opened in response to clicking on a marker. │ │ │ │ │ - * See . Popup's don't require their own │ │ │ │ │ - * layer and are added the the map using the │ │ │ │ │ - * method. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * popup = new OpenLayers.Popup("chicken", │ │ │ │ │ - * new OpenLayers.LonLat(5,40), │ │ │ │ │ - * new OpenLayers.Size(200,200), │ │ │ │ │ - * "example popup", │ │ │ │ │ - * true); │ │ │ │ │ - * │ │ │ │ │ - * map.addPopup(popup); │ │ │ │ │ - * (end) │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Popup = OpenLayers.Class({ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: events │ │ │ │ │ - * {} custom event manager │ │ │ │ │ - */ │ │ │ │ │ - events: null, │ │ │ │ │ - │ │ │ │ │ - /** Property: id │ │ │ │ │ - * {String} the unique identifier assigned to this popup. │ │ │ │ │ - */ │ │ │ │ │ - id: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: lonlat │ │ │ │ │ - * {} the position of this popup on the map │ │ │ │ │ - */ │ │ │ │ │ - lonlat: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: div │ │ │ │ │ - * {DOMElement} the div that contains this popup. │ │ │ │ │ - */ │ │ │ │ │ - div: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: contentSize │ │ │ │ │ - * {} the width and height of the content. │ │ │ │ │ - */ │ │ │ │ │ - contentSize: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: size │ │ │ │ │ - * {} the width and height of the popup. │ │ │ │ │ - */ │ │ │ │ │ - size: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: contentHTML │ │ │ │ │ - * {String} An HTML string for this popup to display. │ │ │ │ │ - */ │ │ │ │ │ - contentHTML: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: backgroundColor │ │ │ │ │ - * {String} the background color used by the popup. │ │ │ │ │ - */ │ │ │ │ │ - backgroundColor: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: opacity │ │ │ │ │ - * {float} the opacity of this popup (between 0.0 and 1.0) │ │ │ │ │ - */ │ │ │ │ │ - opacity: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: border │ │ │ │ │ - * {String} the border size of the popup. (eg 2px) │ │ │ │ │ - */ │ │ │ │ │ - border: "", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: contentDiv │ │ │ │ │ - * {DOMElement} a reference to the element that holds the content of │ │ │ │ │ - * the div. │ │ │ │ │ - */ │ │ │ │ │ - contentDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: groupDiv │ │ │ │ │ - * {DOMElement} First and only child of 'div'. The group Div contains the │ │ │ │ │ - * 'contentDiv' and the 'closeDiv'. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - groupDiv: null, │ │ │ │ │ + scales: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: closeDiv │ │ │ │ │ - * {DOMElement} the optional closer image │ │ │ │ │ + /** │ │ │ │ │ + * 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.). │ │ │ │ │ */ │ │ │ │ │ - closeDiv: null, │ │ │ │ │ + resolutions: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoSize │ │ │ │ │ - * {Boolean} Resize the popup to auto-fit the contents. │ │ │ │ │ - * Default is false. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - autoSize: false, │ │ │ │ │ + maxExtent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: minSize │ │ │ │ │ - * {} Minimum size allowed for the popup's contents. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - minSize: null, │ │ │ │ │ + minExtent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxSize │ │ │ │ │ - * {} Maximum size allowed for the popup's contents. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - maxSize: null, │ │ │ │ │ + maxResolution: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: displayClass │ │ │ │ │ - * {String} The CSS class of the popup. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minResolution │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - displayClass: "olPopup", │ │ │ │ │ + minResolution: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: contentDisplayClass │ │ │ │ │ - * {String} The CSS class of the popup content div. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: numZoomLevels │ │ │ │ │ + * {Integer} │ │ │ │ │ */ │ │ │ │ │ - contentDisplayClass: "olPopupContent", │ │ │ │ │ + numZoomLevels: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: padding │ │ │ │ │ - * {int or } An extra opportunity to specify internal │ │ │ │ │ - * padding of the content div inside the popup. This was originally │ │ │ │ │ - * confused with the css padding as specified in style.css's │ │ │ │ │ - * 'olPopupContent' class. We would like to get rid of this altogether, │ │ │ │ │ - * except that it does come in handy for the framed and anchoredbubble │ │ │ │ │ - * popups, who need to maintain yet another barrier between their │ │ │ │ │ - * content and the outer border of the popup itself. │ │ │ │ │ - * │ │ │ │ │ - * Note that in order to not break API, we must continue to support │ │ │ │ │ - * this property being set as an integer. Really, though, we'd like to │ │ │ │ │ - * have this specified as a Bounds object so that user can specify │ │ │ │ │ - * distinct left, top, right, bottom paddings. With the 3.0 release │ │ │ │ │ - * we can make this only a bounds. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minScale │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - padding: 0, │ │ │ │ │ + minScale: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: disableFirefoxOverflowHack │ │ │ │ │ - * {Boolean} The hack for overflow in Firefox causes all elements │ │ │ │ │ - * to be re-drawn, which causes Flash elements to be │ │ │ │ │ - * re-initialized, which is troublesome. │ │ │ │ │ - * With this property the hack can be disabled. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxScale │ │ │ │ │ + * {Float} │ │ │ │ │ */ │ │ │ │ │ - disableFirefoxOverflowHack: false, │ │ │ │ │ + maxScale: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: fixPadding │ │ │ │ │ - * To be removed in 3.0, this function merely helps us to deal with the │ │ │ │ │ - * case where the user may have set an integer value for padding, │ │ │ │ │ - * instead of an object. │ │ │ │ │ + * APIProperty: displayOutsideMaxExtent │ │ │ │ │ + * {Boolean} Request map tiles that are completely outside of the max │ │ │ │ │ + * extent for this layer. Defaults to false. │ │ │ │ │ */ │ │ │ │ │ - fixPadding: function() { │ │ │ │ │ - if (typeof this.padding == "number") { │ │ │ │ │ - this.padding = new OpenLayers.Bounds( │ │ │ │ │ - this.padding, this.padding, this.padding, this.padding │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + displayOutsideMaxExtent: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: panMapIfOutOfView │ │ │ │ │ - * {Boolean} When drawn, pan map such that the entire popup is visible in │ │ │ │ │ - * the current viewport (if necessary). │ │ │ │ │ - * Default is 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. │ │ │ │ │ */ │ │ │ │ │ - panMapIfOutOfView: false, │ │ │ │ │ + wrapDateLine: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: keepInMap │ │ │ │ │ - * {Boolean} If panMapIfOutOfView is false, and this property is true, │ │ │ │ │ - * contrain the popup such that it always fits in the available map │ │ │ │ │ - * space. By default, this is not set on the base class. If you are │ │ │ │ │ - * creating popups that are near map edges and not allowing pannning, │ │ │ │ │ - * and especially if you have a popup which has a │ │ │ │ │ - * fixedRelativePosition, setting this to false may be a smart thing to │ │ │ │ │ - * do. Subclasses may want to override this setting. │ │ │ │ │ - * │ │ │ │ │ - * Default is false. │ │ │ │ │ + * Property: metadata │ │ │ │ │ + * {Object} This object can be used to store additional information on a │ │ │ │ │ + * layer object. │ │ │ │ │ */ │ │ │ │ │ - keepInMap: false, │ │ │ │ │ + metadata: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: closeOnMove │ │ │ │ │ - * {Boolean} When map pans, close the popup. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * Constructor: OpenLayers.Layer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * name - {String} The layer name │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ */ │ │ │ │ │ - closeOnMove: false, │ │ │ │ │ + initialize: function(name, options) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} this gets set in Map.js when the popup is added to the map │ │ │ │ │ - */ │ │ │ │ │ - map: null, │ │ │ │ │ + this.metadata = {}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Popup │ │ │ │ │ - * Create a popup. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {String} a unqiue identifier for this popup. If null is passed │ │ │ │ │ - * an identifier will be automatically generated. │ │ │ │ │ - * lonlat - {} The position on the map the popup will │ │ │ │ │ - * be shown. │ │ │ │ │ - * contentSize - {} The size of the content. │ │ │ │ │ - * contentHTML - {String} An HTML string to display inside the │ │ │ │ │ - * popup. │ │ │ │ │ - * closeBox - {Boolean} Whether to display a close box inside │ │ │ │ │ - * the popup. │ │ │ │ │ - * closeBoxCallback - {Function} Function to be called on closeBox click. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(id, lonlat, contentSize, contentHTML, closeBox, closeBoxCallback) { │ │ │ │ │ - if (id == null) { │ │ │ │ │ - id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + 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.id = id; │ │ │ │ │ - this.lonlat = lonlat; │ │ │ │ │ + this.name = name; │ │ │ │ │ │ │ │ │ │ - this.contentSize = (contentSize != null) ? contentSize : │ │ │ │ │ - new OpenLayers.Size( │ │ │ │ │ - OpenLayers.Popup.WIDTH, │ │ │ │ │ - OpenLayers.Popup.HEIGHT); │ │ │ │ │ - if (contentHTML != null) { │ │ │ │ │ - this.contentHTML = contentHTML; │ │ │ │ │ - } │ │ │ │ │ - this.backgroundColor = OpenLayers.Popup.COLOR; │ │ │ │ │ - this.opacity = OpenLayers.Popup.OPACITY; │ │ │ │ │ - this.border = OpenLayers.Popup.BORDER; │ │ │ │ │ + if (this.id == null) { │ │ │ │ │ │ │ │ │ │ - this.div = OpenLayers.Util.createDiv(this.id, null, null, │ │ │ │ │ - null, null, null, "hidden"); │ │ │ │ │ - this.div.className = this.displayClass; │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ │ │ │ │ │ - var groupDivId = this.id + "_GroupDiv"; │ │ │ │ │ - this.groupDiv = OpenLayers.Util.createDiv(groupDivId, null, null, │ │ │ │ │ - null, "relative", null, │ │ │ │ │ - "hidden"); │ │ │ │ │ + this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ + this.div.style.width = "100%"; │ │ │ │ │ + this.div.style.height = "100%"; │ │ │ │ │ + this.div.dir = "ltr"; │ │ │ │ │ │ │ │ │ │ - var id = this.div.id + "_contentDiv"; │ │ │ │ │ - this.contentDiv = OpenLayers.Util.createDiv(id, null, this.contentSize.clone(), │ │ │ │ │ - null, "relative"); │ │ │ │ │ - this.contentDiv.className = this.contentDisplayClass; │ │ │ │ │ - this.groupDiv.appendChild(this.contentDiv); │ │ │ │ │ - this.div.appendChild(this.groupDiv); │ │ │ │ │ + this.events = new OpenLayers.Events(this, this.div); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (closeBox) { │ │ │ │ │ - this.addCloseBox(closeBoxCallback); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - this.registerEvents(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ + /** │ │ │ │ │ * Method: destroy │ │ │ │ │ - * nullify references to prevent circular references and memory leaks │ │ │ │ │ + * 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() { │ │ │ │ │ - │ │ │ │ │ - this.id = null; │ │ │ │ │ - this.lonlat = null; │ │ │ │ │ - this.size = null; │ │ │ │ │ - this.contentHTML = null; │ │ │ │ │ - │ │ │ │ │ - this.backgroundColor = null; │ │ │ │ │ - this.opacity = null; │ │ │ │ │ - this.border = null; │ │ │ │ │ - │ │ │ │ │ - if (this.closeOnMove && this.map) { │ │ │ │ │ - this.map.events.unregister("movestart", this, this.hide); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.events.destroy(); │ │ │ │ │ - this.events = null; │ │ │ │ │ - │ │ │ │ │ - if (this.closeDiv) { │ │ │ │ │ - OpenLayers.Event.stopObservingElement(this.closeDiv); │ │ │ │ │ - this.groupDiv.removeChild(this.closeDiv); │ │ │ │ │ + destroy: function(setNewBaseLayer) { │ │ │ │ │ + if (setNewBaseLayer == null) { │ │ │ │ │ + setNewBaseLayer = true; │ │ │ │ │ } │ │ │ │ │ - this.closeDiv = null; │ │ │ │ │ - │ │ │ │ │ - this.div.removeChild(this.groupDiv); │ │ │ │ │ - this.groupDiv = null; │ │ │ │ │ - │ │ │ │ │ if (this.map != null) { │ │ │ │ │ - this.map.removePopup(this); │ │ │ │ │ + this.map.removeLayer(this, setNewBaseLayer); │ │ │ │ │ } │ │ │ │ │ + this.projection = null; │ │ │ │ │ this.map = null; │ │ │ │ │ + this.name = null; │ │ │ │ │ this.div = null; │ │ │ │ │ + this.options = null; │ │ │ │ │ │ │ │ │ │ - this.autoSize = null; │ │ │ │ │ - this.minSize = null; │ │ │ │ │ - this.maxSize = null; │ │ │ │ │ - this.padding = null; │ │ │ │ │ - this.panMapIfOutOfView = null; │ │ │ │ │ + if (this.events) { │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ + this.events = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Constructs the elements that make up the popup. │ │ │ │ │ + /** │ │ │ │ │ + * Method: clone │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} the position the popup in pixels. │ │ │ │ │ - * │ │ │ │ │ + * obj - {} The layer to be cloned │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} Reference to a div that contains the drawn popup │ │ │ │ │ + * {} An exact clone of this │ │ │ │ │ */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - if (px == null) { │ │ │ │ │ - if ((this.lonlat != null) && (this.map != null)) { │ │ │ │ │ - px = this.map.getLayerPxFromLonLat(this.lonlat); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ │ │ │ │ │ - // this assumes that this.map already exists, which is okay because │ │ │ │ │ - // this.draw is only called once the popup has been added to the map. │ │ │ │ │ - if (this.closeOnMove) { │ │ │ │ │ - this.map.events.register("movestart", this, this.hide); │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer(this.name, this.getOptions()); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - //listen to movestart, moveend to disable overflow (FF bug) │ │ │ │ │ - if (!this.disableFirefoxOverflowHack && OpenLayers.BROWSER_NAME == 'firefox') { │ │ │ │ │ - this.map.events.register("movestart", this, function() { │ │ │ │ │ - var style = document.defaultView.getComputedStyle( │ │ │ │ │ - this.contentDiv, null │ │ │ │ │ - ); │ │ │ │ │ - var currentOverflow = style.getPropertyValue("overflow"); │ │ │ │ │ - if (currentOverflow != "hidden") { │ │ │ │ │ - this.contentDiv._oldOverflow = currentOverflow; │ │ │ │ │ - this.contentDiv.style.overflow = "hidden"; │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - this.map.events.register("moveend", this, function() { │ │ │ │ │ - var oldOverflow = this.contentDiv._oldOverflow; │ │ │ │ │ - if (oldOverflow) { │ │ │ │ │ - this.contentDiv.style.overflow = oldOverflow; │ │ │ │ │ - this.contentDiv._oldOverflow = null; │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + // catch any randomly tagged-on properties │ │ │ │ │ + OpenLayers.Util.applyDefaults(obj, this); │ │ │ │ │ │ │ │ │ │ - this.moveTo(px); │ │ │ │ │ - if (!this.autoSize && !this.size) { │ │ │ │ │ - this.setSize(this.contentSize); │ │ │ │ │ - } │ │ │ │ │ - this.setBackgroundColor(); │ │ │ │ │ - this.setOpacity(); │ │ │ │ │ - this.setBorder(); │ │ │ │ │ - this.setContentHTML(); │ │ │ │ │ + // a cloned layer should never have its map property set │ │ │ │ │ + // because it has not been added to a map yet. │ │ │ │ │ + obj.map = null; │ │ │ │ │ │ │ │ │ │ - if (this.panMapIfOutOfView) { │ │ │ │ │ - this.panIntoView(); │ │ │ │ │ - } │ │ │ │ │ + return obj; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - return this.div; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updatePosition │ │ │ │ │ - * if the popup has a lonlat and its map members set, │ │ │ │ │ - * then have it move itself to its proper position │ │ │ │ │ + * APIMethod: setName │ │ │ │ │ + * Sets the new layer name for this layer. Can trigger a changelayer event │ │ │ │ │ + * on the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newName - {String} The new name. │ │ │ │ │ */ │ │ │ │ │ - updatePosition: function() { │ │ │ │ │ - if ((this.lonlat) && (this.map)) { │ │ │ │ │ - var px = this.map.getLayerPxFromLonLat(this.lonlat); │ │ │ │ │ - if (px) { │ │ │ │ │ - this.moveTo(px); │ │ │ │ │ + setName: function(newName) { │ │ │ │ │ + if (newName != this.name) { │ │ │ │ │ + this.name = newName; │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: this, │ │ │ │ │ + property: "name" │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ + * APIMethod: addOptions │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} the top and left position of the popup div. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - if ((px != null) && (this.div != null)) { │ │ │ │ │ - this.div.style.left = px.x + "px"; │ │ │ │ │ - this.div.style.top = px.y + "px"; │ │ │ │ │ + addOptions: function(newOptions, reinitialize) { │ │ │ │ │ + │ │ │ │ │ + if (this.options == null) { │ │ │ │ │ + this.options = {}; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: visible │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Boolean indicating whether or not the popup is visible │ │ │ │ │ - */ │ │ │ │ │ - visible: function() { │ │ │ │ │ - return OpenLayers.Element.visible(this.div); │ │ │ │ │ - }, │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: toggle │ │ │ │ │ - * Toggles visibility of the popup. │ │ │ │ │ - */ │ │ │ │ │ - toggle: function() { │ │ │ │ │ - if (this.visible()) { │ │ │ │ │ - this.hide(); │ │ │ │ │ - } else { │ │ │ │ │ - this.show(); │ │ │ │ │ + // 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(); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: show │ │ │ │ │ - * Makes the popup visible. │ │ │ │ │ - */ │ │ │ │ │ - show: function() { │ │ │ │ │ - this.div.style.display = ''; │ │ │ │ │ + // 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.panMapIfOutOfView) { │ │ │ │ │ - this.panIntoView(); │ │ │ │ │ + this.initResolutions(); │ │ │ │ │ + if (reinitialize && this.map.baseLayer === this) { │ │ │ │ │ + // update map position, and restore previous resolution │ │ │ │ │ + this.map.setCenter(this.map.getCenter(), │ │ │ │ │ + this.map.getZoomForResolution(resolution), │ │ │ │ │ + false, true │ │ │ │ │ + ); │ │ │ │ │ + // trigger a changebaselayer event to make sure that │ │ │ │ │ + // all controls (especially │ │ │ │ │ + // OpenLayers.Control.PanZoomBar) get notified of the │ │ │ │ │ + // new options │ │ │ │ │ + this.map.events.triggerEvent("changebaselayer", { │ │ │ │ │ + layer: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: hide │ │ │ │ │ - * Makes the popup invisible. │ │ │ │ │ + * APIMethod: onMapResize │ │ │ │ │ + * This function can be implemented by subclasses │ │ │ │ │ */ │ │ │ │ │ - hide: function() { │ │ │ │ │ - this.div.style.display = 'none'; │ │ │ │ │ + onMapResize: function() { │ │ │ │ │ + //this function can be implemented by subclasses │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setSize │ │ │ │ │ - * Used to adjust the size of the popup. │ │ │ │ │ + * APIMethod: redraw │ │ │ │ │ + * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * contentSize - {} the new size for the popup's │ │ │ │ │ - * contents div (in pixels). │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer was redrawn. │ │ │ │ │ */ │ │ │ │ │ - setSize: function(contentSize) { │ │ │ │ │ - this.size = contentSize.clone(); │ │ │ │ │ - │ │ │ │ │ - // if our contentDiv has a css 'padding' set on it by a stylesheet, we │ │ │ │ │ - // must add that to the desired "size". │ │ │ │ │ - var contentDivPadding = this.getContentDivPadding(); │ │ │ │ │ - var wPadding = contentDivPadding.left + contentDivPadding.right; │ │ │ │ │ - var hPadding = contentDivPadding.top + contentDivPadding.bottom; │ │ │ │ │ - │ │ │ │ │ - // take into account the popup's 'padding' property │ │ │ │ │ - this.fixPadding(); │ │ │ │ │ - wPadding += this.padding.left + this.padding.right; │ │ │ │ │ - hPadding += this.padding.top + this.padding.bottom; │ │ │ │ │ + redraw: function() { │ │ │ │ │ + var redrawn = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ │ │ │ │ │ - // make extra space for the close div │ │ │ │ │ - if (this.closeDiv) { │ │ │ │ │ - var closeDivWidth = parseInt(this.closeDiv.style.width); │ │ │ │ │ - wPadding += closeDivWidth + contentDivPadding.right; │ │ │ │ │ - } │ │ │ │ │ + // min/max Range may have changed │ │ │ │ │ + this.inRange = this.calculateInRange(); │ │ │ │ │ │ │ │ │ │ - //increase size of the main popup div to take into account the │ │ │ │ │ - // users's desired padding and close div. │ │ │ │ │ - this.size.w += wPadding; │ │ │ │ │ - this.size.h += hPadding; │ │ │ │ │ + // map's center might not yet be set │ │ │ │ │ + var extent = this.getExtent(); │ │ │ │ │ │ │ │ │ │ - //now if our browser is IE, we need to actually make the contents │ │ │ │ │ - // div itself bigger to take its own padding into effect. this makes │ │ │ │ │ - // me want to shoot someone, but so it goes. │ │ │ │ │ - if (OpenLayers.BROWSER_NAME == "msie") { │ │ │ │ │ - this.contentSize.w += │ │ │ │ │ - contentDivPadding.left + contentDivPadding.right; │ │ │ │ │ - this.contentSize.h += │ │ │ │ │ - contentDivPadding.bottom + contentDivPadding.top; │ │ │ │ │ + if (extent && this.inRange && this.visibility) { │ │ │ │ │ + var zoomChanged = true; │ │ │ │ │ + this.moveTo(extent, zoomChanged, false); │ │ │ │ │ + this.events.triggerEvent("moveend", { │ │ │ │ │ + "zoomChanged": zoomChanged │ │ │ │ │ + }); │ │ │ │ │ + redrawn = true; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return redrawn; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - this.div.style.width = this.size.w + "px"; │ │ │ │ │ - this.div.style.height = this.size.h + "px"; │ │ │ │ │ - } │ │ │ │ │ - if (this.contentDiv != null) { │ │ │ │ │ - this.contentDiv.style.width = contentSize.w + "px"; │ │ │ │ │ - this.contentDiv.style.height = contentSize.h + "px"; │ │ │ │ │ + /** │ │ │ │ │ + * Method: 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: updateSize │ │ │ │ │ - * Auto size the popup so that it precisely fits its contents (as │ │ │ │ │ - * determined by this.contentDiv.innerHTML). Popup size will, of │ │ │ │ │ - * course, be limited by the available space on the current map │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - updateSize: function() { │ │ │ │ │ - │ │ │ │ │ - // determine actual render dimensions of the contents by putting its │ │ │ │ │ - // contents into a fake contentDiv (for the CSS) and then measuring it │ │ │ │ │ - var preparedHTML = "
" + │ │ │ │ │ - this.contentDiv.innerHTML + │ │ │ │ │ - "
"; │ │ │ │ │ - │ │ │ │ │ - var containerElement = (this.map) ? this.map.div : document.body; │ │ │ │ │ - var realSize = OpenLayers.Util.getRenderedDimensions( │ │ │ │ │ - preparedHTML, null, { │ │ │ │ │ - displayClass: this.displayClass, │ │ │ │ │ - containerElement: containerElement │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ + moveByPx: function(dx, dy) {}, │ │ │ │ │ │ │ │ │ │ - // is the "real" size of the div is safe to display in our map? │ │ │ │ │ - var safeSize = this.getSafeContentSize(realSize); │ │ │ │ │ + /** │ │ │ │ │ + * 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) { │ │ │ │ │ │ │ │ │ │ - var newSize = null; │ │ │ │ │ - if (safeSize.equals(realSize)) { │ │ │ │ │ - //real size of content is small enough to fit on the map, │ │ │ │ │ - // so we use real size. │ │ │ │ │ - newSize = realSize; │ │ │ │ │ + this.map = map; │ │ │ │ │ │ │ │ │ │ - } else { │ │ │ │ │ + // 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 a new 'size' object with the clipped dimensions │ │ │ │ │ - // set or null if not clipped. │ │ │ │ │ - var fixedSize = { │ │ │ │ │ - w: (safeSize.w < realSize.w) ? safeSize.w : null, │ │ │ │ │ - h: (safeSize.h < realSize.h) ? safeSize.h : null │ │ │ │ │ - }; │ │ │ │ │ + this.projection = this.projection || this.map.projection; │ │ │ │ │ + if (typeof this.projection == "string") { │ │ │ │ │ + this.projection = new OpenLayers.Projection(this.projection); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (fixedSize.w && fixedSize.h) { │ │ │ │ │ - //content is too big in both directions, so we will use │ │ │ │ │ - // max popup size (safeSize), knowing well that it will │ │ │ │ │ - // overflow both ways. │ │ │ │ │ - newSize = safeSize; │ │ │ │ │ - } else { │ │ │ │ │ - //content is clipped in only one direction, so we need to │ │ │ │ │ - // run getRenderedDimensions() again with a fixed dimension │ │ │ │ │ - var clippedSize = OpenLayers.Util.getRenderedDimensions( │ │ │ │ │ - preparedHTML, fixedSize, { │ │ │ │ │ - displayClass: this.contentDisplayClass, │ │ │ │ │ - containerElement: containerElement │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ + // 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 the clipped size is still the same as the safeSize, │ │ │ │ │ - // that means that our content must be fixed in the │ │ │ │ │ - // offending direction. If overflow is 'auto', this means │ │ │ │ │ - // we are going to have a scrollbar for sure, so we must │ │ │ │ │ - // adjust for that. │ │ │ │ │ - // │ │ │ │ │ - var currentOverflow = OpenLayers.Element.getStyle( │ │ │ │ │ - this.contentDiv, "overflow" │ │ │ │ │ - ); │ │ │ │ │ - if ((currentOverflow != "hidden") && │ │ │ │ │ - (clippedSize.equals(safeSize))) { │ │ │ │ │ - var scrollBar = OpenLayers.Util.getScrollbarWidth(); │ │ │ │ │ - if (fixedSize.w) { │ │ │ │ │ - clippedSize.h += scrollBar; │ │ │ │ │ - } else { │ │ │ │ │ - clippedSize.w += scrollBar; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + this.initResolutions(); │ │ │ │ │ │ │ │ │ │ - newSize = this.getSafeContentSize(clippedSize); │ │ │ │ │ + if (!this.isBaseLayer) { │ │ │ │ │ + this.inRange = this.calculateInRange(); │ │ │ │ │ + var show = ((this.visibility) && (this.inRange)); │ │ │ │ │ + this.div.style.display = show ? "" : "none"; │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + // deal with gutters │ │ │ │ │ + this.setTileSize(); │ │ │ │ │ } │ │ │ │ │ - this.setSize(newSize); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setBackgroundColor │ │ │ │ │ - * Sets the background color of the popup. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * color - {String} the background color. eg "#FFBBBB" │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - setBackgroundColor: function(color) { │ │ │ │ │ - if (color != undefined) { │ │ │ │ │ - this.backgroundColor = color; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - this.div.style.backgroundColor = this.backgroundColor; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + afterAdd: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Sets the opacity of the popup. │ │ │ │ │ + * 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: │ │ │ │ │ - * opacity - {float} A value between 0.0 (transparent) and 1.0 (solid). │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - setOpacity: function(opacity) { │ │ │ │ │ - if (opacity != undefined) { │ │ │ │ │ - this.opacity = opacity; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - // for Mozilla and Safari │ │ │ │ │ - this.div.style.opacity = this.opacity; │ │ │ │ │ - │ │ │ │ │ - // for IE │ │ │ │ │ - this.div.style.filter = 'alpha(opacity=' + this.opacity * 100 + ')'; │ │ │ │ │ - } │ │ │ │ │ + removeMap: function(map) { │ │ │ │ │ + //to be overridden by subclasses │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setBorder │ │ │ │ │ - * Sets the border style of the popup. │ │ │ │ │ + * APIMethod: getImageSize │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * border - {String} The border style value. eg 2px │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - setBorder: function(border) { │ │ │ │ │ - if (border != undefined) { │ │ │ │ │ - this.border = border; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - this.div.style.border = this.border; │ │ │ │ │ - } │ │ │ │ │ + getImageSize: function(bounds) { │ │ │ │ │ + return (this.imageSize || this.tileSize); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setContentHTML │ │ │ │ │ - * Allows the user to set the HTML content of the popup. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: setTileSize │ │ │ │ │ + * Set the tile size based on the map size. This also sets layer.imageSize │ │ │ │ │ + * or use by Tile.Image. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * contentHTML - {String} HTML for the div. │ │ │ │ │ + * size - {} │ │ │ │ │ */ │ │ │ │ │ - setContentHTML: function(contentHTML) { │ │ │ │ │ - │ │ │ │ │ - if (contentHTML != null) { │ │ │ │ │ - this.contentHTML = contentHTML; │ │ │ │ │ + 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)); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if ((this.contentDiv != null) && │ │ │ │ │ - (this.contentHTML != null) && │ │ │ │ │ - (this.contentHTML != this.contentDiv.innerHTML)) { │ │ │ │ │ - │ │ │ │ │ - this.contentDiv.innerHTML = this.contentHTML; │ │ │ │ │ - │ │ │ │ │ - if (this.autoSize) { │ │ │ │ │ - │ │ │ │ │ - //if popup has images, listen for when they finish │ │ │ │ │ - // loading and resize accordingly │ │ │ │ │ - this.registerImageListeners(); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getVisibility │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The layer should be displayed (if in range). │ │ │ │ │ + */ │ │ │ │ │ + getVisibility: function() { │ │ │ │ │ + return this.visibility; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //auto size the popup to its current contents │ │ │ │ │ - this.updateSize(); │ │ │ │ │ + /** │ │ │ │ │ + * 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"; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: registerImageListeners │ │ │ │ │ - * Called when an image contained by the popup loaded. this function │ │ │ │ │ - * updates the popup size, then unregisters the image load listener. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - registerImageListeners: function() { │ │ │ │ │ + calculateInRange: function() { │ │ │ │ │ + var inRange = false; │ │ │ │ │ │ │ │ │ │ - // As the images load, this function will call updateSize() to │ │ │ │ │ - // resize the popup to fit the content div (which presumably is now │ │ │ │ │ - // bigger than when the image was not loaded). │ │ │ │ │ - // │ │ │ │ │ - // If the 'panMapIfOutOfView' property is set, we will pan the newly │ │ │ │ │ - // resized popup back into view. │ │ │ │ │ - // │ │ │ │ │ - // Note that this function, when called, will have 'popup' and │ │ │ │ │ - // 'img' properties in the context. │ │ │ │ │ - // │ │ │ │ │ - var onImgLoad = function() { │ │ │ │ │ - if (this.popup.id === null) { // this.popup has been destroyed! │ │ │ │ │ - return; │ │ │ │ │ + if (this.alwaysInRange) { │ │ │ │ │ + inRange = true; │ │ │ │ │ + } else { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + var resolution = this.map.getResolution(); │ │ │ │ │ + inRange = ((resolution >= this.minResolution) && │ │ │ │ │ + (resolution <= this.maxResolution)); │ │ │ │ │ } │ │ │ │ │ - this.popup.updateSize(); │ │ │ │ │ + } │ │ │ │ │ + return inRange; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.popup.visible() && this.popup.panMapIfOutOfView) { │ │ │ │ │ - this.popup.panIntoView(); │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - OpenLayers.Event.stopObserving( │ │ │ │ │ - this.img, "load", this.img._onImgLoad │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - }; │ │ │ │ │ + /********************************************************/ │ │ │ │ │ + /* */ │ │ │ │ │ + /* Baselayer Functions */ │ │ │ │ │ + /* */ │ │ │ │ │ + /********************************************************/ │ │ │ │ │ │ │ │ │ │ - //cycle through the images and if their size is 0x0, that means that │ │ │ │ │ - // they haven't been loaded yet, so we attach the listener, which │ │ │ │ │ - // will fire when the images finish loading and will resize the │ │ │ │ │ - // popup accordingly to its new size. │ │ │ │ │ - var images = this.contentDiv.getElementsByTagName("img"); │ │ │ │ │ - for (var i = 0, len = images.length; i < len; i++) { │ │ │ │ │ - var img = images[i]; │ │ │ │ │ - if (img.width == 0 || img.height == 0) { │ │ │ │ │ + /** │ │ │ │ │ + * 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() { │ │ │ │ │ │ │ │ │ │ - var context = { │ │ │ │ │ - 'popup': this, │ │ │ │ │ - 'img': img │ │ │ │ │ - }; │ │ │ │ │ + // 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! │ │ │ │ │ │ │ │ │ │ - //expando this function to the image itself before registering │ │ │ │ │ - // it. This way we can easily and properly unregister it. │ │ │ │ │ - img._onImgLoad = OpenLayers.Function.bind(onImgLoad, context); │ │ │ │ │ + var i, len, p; │ │ │ │ │ + var props = {}, │ │ │ │ │ + alwaysInRange = true; │ │ │ │ │ │ │ │ │ │ - OpenLayers.Event.observe(img, 'load', img._onImgLoad); │ │ │ │ │ + // 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; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getSafeContentSize │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * size - {} Desired size to make the popup. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A size to make the popup which is neither smaller │ │ │ │ │ - * than the specified minimum size, nor bigger than the maximum │ │ │ │ │ - * size (which is calculated relative to the size of the viewport). │ │ │ │ │ - */ │ │ │ │ │ - getSafeContentSize: function(size) { │ │ │ │ │ + // if we don't have resolutions then attempt to derive them from scales │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + props.resolutions = this.resolutionsFromScales(props.scales); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var safeContentSize = size.clone(); │ │ │ │ │ + // if we still don't have resolutions then attempt to calculate them │ │ │ │ │ + if (props.resolutions == null) { │ │ │ │ │ + props.resolutions = this.calculateResolutions(props); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // if our contentDiv has a css 'padding' set on it by a stylesheet, we │ │ │ │ │ - // must add that to the desired "size". │ │ │ │ │ - var contentDivPadding = this.getContentDivPadding(); │ │ │ │ │ - var wPadding = contentDivPadding.left + contentDivPadding.right; │ │ │ │ │ - var hPadding = contentDivPadding.top + contentDivPadding.bottom; │ │ │ │ │ + // 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // take into account the popup's 'padding' property │ │ │ │ │ - this.fixPadding(); │ │ │ │ │ - wPadding += this.padding.left + this.padding.right; │ │ │ │ │ - hPadding += this.padding.top + this.padding.bottom; │ │ │ │ │ + // ok, we new need to set properties in the instance │ │ │ │ │ │ │ │ │ │ - if (this.closeDiv) { │ │ │ │ │ - var closeDivWidth = parseInt(this.closeDiv.style.width); │ │ │ │ │ - wPadding += closeDivWidth + contentDivPadding.right; │ │ │ │ │ + // get maxResolution from the config if it's defined there │ │ │ │ │ + var maxResolution; │ │ │ │ │ + if (this.options.maxResolution && │ │ │ │ │ + this.options.maxResolution !== "auto") { │ │ │ │ │ + maxResolution = this.options.maxResolution; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // prevent the popup from being smaller than a specified minimal size │ │ │ │ │ - if (this.minSize) { │ │ │ │ │ - safeContentSize.w = Math.max(safeContentSize.w, │ │ │ │ │ - (this.minSize.w - wPadding)); │ │ │ │ │ - safeContentSize.h = Math.max(safeContentSize.h, │ │ │ │ │ - (this.minSize.h - hPadding)); │ │ │ │ │ + if (this.options.minScale) { │ │ │ │ │ + maxResolution = OpenLayers.Util.getResolutionFromScale( │ │ │ │ │ + this.options.minScale, this.units); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // prevent the popup from being bigger than a specified maximum size │ │ │ │ │ - if (this.maxSize) { │ │ │ │ │ - safeContentSize.w = Math.min(safeContentSize.w, │ │ │ │ │ - (this.maxSize.w - wPadding)); │ │ │ │ │ - safeContentSize.h = Math.min(safeContentSize.h, │ │ │ │ │ - (this.maxSize.h - hPadding)); │ │ │ │ │ + // 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); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - //make sure the desired size to set doesn't result in a popup that │ │ │ │ │ - // is bigger than the map's viewport. │ │ │ │ │ - // │ │ │ │ │ - if (this.map && this.map.size) { │ │ │ │ │ - │ │ │ │ │ - var extraX = 0, │ │ │ │ │ - extraY = 0; │ │ │ │ │ - if (this.keepInMap && !this.panMapIfOutOfView) { │ │ │ │ │ - var px = this.map.getPixelFromLonLat(this.lonlat); │ │ │ │ │ - switch (this.relativePosition) { │ │ │ │ │ - case "tr": │ │ │ │ │ - extraX = px.x; │ │ │ │ │ - extraY = this.map.size.h - px.y; │ │ │ │ │ - break; │ │ │ │ │ - case "tl": │ │ │ │ │ - extraX = this.map.size.w - px.x; │ │ │ │ │ - extraY = this.map.size.h - px.y; │ │ │ │ │ - break; │ │ │ │ │ - case "bl": │ │ │ │ │ - extraX = this.map.size.w - px.x; │ │ │ │ │ - extraY = px.y; │ │ │ │ │ - break; │ │ │ │ │ - case "br": │ │ │ │ │ - extraX = px.x; │ │ │ │ │ - extraY = px.y; │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - extraX = px.x; │ │ │ │ │ - extraY = this.map.size.h - px.y; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + if (props.resolutions) { │ │ │ │ │ │ │ │ │ │ - var maxY = this.map.size.h - │ │ │ │ │ - this.map.paddingForPopups.top - │ │ │ │ │ - this.map.paddingForPopups.bottom - │ │ │ │ │ - hPadding - extraY; │ │ │ │ │ + //sort resolutions array descendingly │ │ │ │ │ + props.resolutions.sort(function(a, b) { │ │ │ │ │ + return (b - a); │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - var maxX = this.map.size.w - │ │ │ │ │ - this.map.paddingForPopups.left - │ │ │ │ │ - this.map.paddingForPopups.right - │ │ │ │ │ - wPadding - extraX; │ │ │ │ │ + // if we still don't have a maxResolution get it from the │ │ │ │ │ + // resolutions array │ │ │ │ │ + if (!maxResolution) { │ │ │ │ │ + maxResolution = props.resolutions[0]; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - safeContentSize.w = Math.min(safeContentSize.w, maxX); │ │ │ │ │ - safeContentSize.h = Math.min(safeContentSize.h, maxY); │ │ │ │ │ + // 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]; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - return safeContentSize; │ │ │ │ │ + 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: getContentDivPadding │ │ │ │ │ - * Glorious, oh glorious hack in order to determine the css 'padding' of │ │ │ │ │ - * the contentDiv. IE/Opera return null here unless we actually add the │ │ │ │ │ - * popup's main 'div' element (which contains contentDiv) to the DOM. │ │ │ │ │ - * So we make it invisible and then add it to the document temporarily. │ │ │ │ │ + * Method: resolutionsFromScales │ │ │ │ │ + * Derive resolutions from scales. │ │ │ │ │ * │ │ │ │ │ - * Once we've taken the padding readings we need, we then remove it │ │ │ │ │ - * from the DOM (it will actually get added to the DOM in │ │ │ │ │ - * Map.js's addPopup) │ │ │ │ │ + * Parameters: │ │ │ │ │ + * scales - {Array(Number)} Scales │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Returns │ │ │ │ │ + * {Array(Number)} Resolutions │ │ │ │ │ */ │ │ │ │ │ - getContentDivPadding: function() { │ │ │ │ │ - │ │ │ │ │ - //use cached value if we have it │ │ │ │ │ - var contentDivPadding = this._contentDivPadding; │ │ │ │ │ - if (!contentDivPadding) { │ │ │ │ │ - │ │ │ │ │ - if (this.div.parentNode == null) { │ │ │ │ │ - //make the div invisible and add it to the page │ │ │ │ │ - this.div.style.display = "none"; │ │ │ │ │ - document.body.appendChild(this.div); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - //read the padding settings from css, put them in an OL.Bounds │ │ │ │ │ - contentDivPadding = new OpenLayers.Bounds( │ │ │ │ │ - OpenLayers.Element.getStyle(this.contentDiv, "padding-left"), │ │ │ │ │ - OpenLayers.Element.getStyle(this.contentDiv, "padding-bottom"), │ │ │ │ │ - OpenLayers.Element.getStyle(this.contentDiv, "padding-right"), │ │ │ │ │ - OpenLayers.Element.getStyle(this.contentDiv, "padding-top") │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - //cache the value │ │ │ │ │ - this._contentDivPadding = contentDivPadding; │ │ │ │ │ - │ │ │ │ │ - if (this.div.parentNode == document.body) { │ │ │ │ │ - //remove the div from the page and make it visible again │ │ │ │ │ - document.body.removeChild(this.div); │ │ │ │ │ - this.div.style.display = ""; │ │ │ │ │ - } │ │ │ │ │ + resolutionsFromScales: function(scales) { │ │ │ │ │ + if (scales == null) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - return contentDivPadding; │ │ │ │ │ + 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: addCloseBox │ │ │ │ │ - * │ │ │ │ │ + * Method: calculateResolutions │ │ │ │ │ + * Calculate resolutions based on the provided properties. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * callback - {Function} The callback to be called when the close button │ │ │ │ │ - * is clicked. │ │ │ │ │ + * props - {Object} Properties │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array({Number})} Array of resolutions. │ │ │ │ │ */ │ │ │ │ │ - addCloseBox: function(callback) { │ │ │ │ │ + calculateResolutions: function(props) { │ │ │ │ │ │ │ │ │ │ - this.closeDiv = OpenLayers.Util.createDiv( │ │ │ │ │ - this.id + "_close", null, { │ │ │ │ │ - w: 17, │ │ │ │ │ - h: 17 │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - this.closeDiv.className = "olPopupCloseBox"; │ │ │ │ │ + var viewSize, wRes, hRes; │ │ │ │ │ │ │ │ │ │ - // use the content div's css padding to determine if we should │ │ │ │ │ - // padd the close div │ │ │ │ │ - var contentDivPadding = this.getContentDivPadding(); │ │ │ │ │ + // 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); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - this.closeDiv.style.right = contentDivPadding.right + "px"; │ │ │ │ │ - this.closeDiv.style.top = contentDivPadding.top + "px"; │ │ │ │ │ - this.groupDiv.appendChild(this.closeDiv); │ │ │ │ │ + // 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); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var closePopup = callback || function(e) { │ │ │ │ │ - this.hide(); │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Event.observe(this.closeDiv, "touchend", │ │ │ │ │ - OpenLayers.Function.bindAsEventListener(closePopup, this)); │ │ │ │ │ - OpenLayers.Event.observe(this.closeDiv, "click", │ │ │ │ │ - OpenLayers.Function.bindAsEventListener(closePopup, this)); │ │ │ │ │ - }, │ │ │ │ │ + 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 │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: panIntoView │ │ │ │ │ - * Pans the map such that the popup is totaly viewable (if necessary) │ │ │ │ │ - */ │ │ │ │ │ - panIntoView: function() { │ │ │ │ │ + // 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; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var mapSize = this.map.getSize(); │ │ │ │ │ + // are we able to calculate resolutions? │ │ │ │ │ + if (typeof numZoomLevels !== "number" || numZoomLevels <= 0 || │ │ │ │ │ + (typeof maxResolution !== "number" && │ │ │ │ │ + typeof minResolution !== "number")) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - //start with the top left corner of the popup, in px, │ │ │ │ │ - // relative to the viewport │ │ │ │ │ - var origTL = this.map.getViewPortPxFromLayerPx(new OpenLayers.Pixel( │ │ │ │ │ - parseInt(this.div.style.left), │ │ │ │ │ - parseInt(this.div.style.top) │ │ │ │ │ - )); │ │ │ │ │ - var newTL = origTL.clone(); │ │ │ │ │ + // now we have numZoomLevels and at least one of maxResolution │ │ │ │ │ + // or minResolution, we can populate the resolutions array │ │ │ │ │ │ │ │ │ │ - //new left (compare to margins, using this.size to calculate right) │ │ │ │ │ - if (origTL.x < this.map.paddingForPopups.left) { │ │ │ │ │ - newTL.x = this.map.paddingForPopups.left; │ │ │ │ │ - } else │ │ │ │ │ - if ((origTL.x + this.size.w) > (mapSize.w - this.map.paddingForPopups.right)) { │ │ │ │ │ - newTL.x = mapSize.w - this.map.paddingForPopups.right - this.size.w; │ │ │ │ │ + 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)) │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - //new top (compare to margins, using this.size to calculate bottom) │ │ │ │ │ - if (origTL.y < this.map.paddingForPopups.top) { │ │ │ │ │ - newTL.y = this.map.paddingForPopups.top; │ │ │ │ │ - } else │ │ │ │ │ - if ((origTL.y + this.size.h) > (mapSize.h - this.map.paddingForPopups.bottom)) { │ │ │ │ │ - newTL.y = mapSize.h - this.map.paddingForPopups.bottom - this.size.h; │ │ │ │ │ + var 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); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - var dx = origTL.x - newTL.x; │ │ │ │ │ - var dy = origTL.y - newTL.y; │ │ │ │ │ + return resolutions; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.map.pan(dx, dy); │ │ │ │ │ + /** │ │ │ │ │ + * 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: registerEvents │ │ │ │ │ - * Registers events on the popup. │ │ │ │ │ - * │ │ │ │ │ - * Do this in a separate function so that subclasses can │ │ │ │ │ - * choose to override it if they wish to deal differently │ │ │ │ │ - * with mouse events │ │ │ │ │ - * │ │ │ │ │ - * Note in the following handler functions that some special │ │ │ │ │ - * care is needed to deal correctly with mousing and popups. │ │ │ │ │ - * │ │ │ │ │ - * Because the user might select the zoom-rectangle option and │ │ │ │ │ - * then drag it over a popup, we need a safe way to allow the │ │ │ │ │ - * mousemove and mouseup events to pass through the popup when │ │ │ │ │ - * they are initiated from outside. The same procedure is needed for │ │ │ │ │ - * touchmove and touchend events. │ │ │ │ │ + * APIMethod: getExtent │ │ │ │ │ * │ │ │ │ │ - * Otherwise, we want to essentially kill the event propagation │ │ │ │ │ - * for all other events, though we have to do so carefully, │ │ │ │ │ - * without disabling basic html functionality, like clicking on │ │ │ │ │ - * hyperlinks or drag-selecting text. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A Bounds object which represents the lon/lat │ │ │ │ │ + * bounds of the current viewPort. │ │ │ │ │ */ │ │ │ │ │ - registerEvents: function() { │ │ │ │ │ - this.events = new OpenLayers.Events(this, this.div, null, true); │ │ │ │ │ + getExtent: function() { │ │ │ │ │ + // just use stock map calculateBounds function -- passing no arguments │ │ │ │ │ + // means it will user map's current center & resolution │ │ │ │ │ + // │ │ │ │ │ + return this.map.calculateBounds(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - function onTouchstart(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ - } │ │ │ │ │ - this.events.on({ │ │ │ │ │ - "mousedown": this.onmousedown, │ │ │ │ │ - "mousemove": this.onmousemove, │ │ │ │ │ - "mouseup": this.onmouseup, │ │ │ │ │ - "click": this.onclick, │ │ │ │ │ - "mouseout": this.onmouseout, │ │ │ │ │ - "dblclick": this.ondblclick, │ │ │ │ │ - "touchstart": onTouchstart, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + /** │ │ │ │ │ + * 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: onmousedown │ │ │ │ │ - * When mouse goes down within the popup, make a note of │ │ │ │ │ - * it locally, and then do not propagate the mousedown │ │ │ │ │ - * (but do so safely so that user can select text inside) │ │ │ │ │ + * Method: getDataExtent │ │ │ │ │ + * Calculates the max extent which includes all of the data for the layer. │ │ │ │ │ + * This function is to be implemented by subclasses. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - onmousedown: function(evt) { │ │ │ │ │ - this.mousedown = true; │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ + getDataExtent: function() { │ │ │ │ │ + //to be implemented by subclasses │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onmousemove │ │ │ │ │ - * If the drag was started within the popup, then │ │ │ │ │ - * do not propagate the mousemove (but do so safely │ │ │ │ │ - * so that user can select text inside) │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getResolutionForZoom │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * zoom - {Float} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} A suitable resolution for the specified zoom. │ │ │ │ │ */ │ │ │ │ │ - onmousemove: function(evt) { │ │ │ │ │ - if (this.mousedown) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ + getResolutionForZoom: function(zoom) { │ │ │ │ │ + zoom = Math.max(0, Math.min(zoom, this.resolutions.length - 1)); │ │ │ │ │ + var resolution; │ │ │ │ │ + if (this.map.fractionalZoom) { │ │ │ │ │ + var low = Math.floor(zoom); │ │ │ │ │ + var high = Math.ceil(zoom); │ │ │ │ │ + resolution = this.resolutions[low] - │ │ │ │ │ + ((zoom - low) * (this.resolutions[low] - this.resolutions[high])); │ │ │ │ │ + } else { │ │ │ │ │ + resolution = this.resolutions[Math.round(zoom)]; │ │ │ │ │ } │ │ │ │ │ + return resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onmouseup │ │ │ │ │ - * When mouse comes up within the popup, after going down │ │ │ │ │ - * in it, reset the flag, and then (once again) do not │ │ │ │ │ - * propagate the event, but do so safely so that user can │ │ │ │ │ - * select text inside │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getZoomForResolution │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * resolution - {Float} │ │ │ │ │ + * closest - {Boolean} Find the zoom level that corresponds to the absolute │ │ │ │ │ + * closest resolution, which may result in a zoom whose corresponding │ │ │ │ │ + * resolution is actually smaller than we would have desired (if this │ │ │ │ │ + * is being called from a getZoomForExtent() call, then this means that │ │ │ │ │ + * the returned zoom index might not actually contain the entire │ │ │ │ │ + * extent specified... but it'll be close). │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} The index of the zoomLevel (entry in the resolutions array) │ │ │ │ │ + * that corresponds to the best fit resolution given the passed in │ │ │ │ │ + * value and the 'closest' specification. │ │ │ │ │ */ │ │ │ │ │ - onmouseup: function(evt) { │ │ │ │ │ - if (this.mousedown) { │ │ │ │ │ - this.mousedown = false; │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ + getZoomForResolution: function(resolution, closest) { │ │ │ │ │ + var zoom, i, len; │ │ │ │ │ + if (this.map.fractionalZoom) { │ │ │ │ │ + var lowZoom = 0; │ │ │ │ │ + var highZoom = this.resolutions.length - 1; │ │ │ │ │ + var highRes = this.resolutions[lowZoom]; │ │ │ │ │ + var lowRes = this.resolutions[highZoom]; │ │ │ │ │ + var res; │ │ │ │ │ + for (i = 0, len = this.resolutions.length; i < len; ++i) { │ │ │ │ │ + res = this.resolutions[i]; │ │ │ │ │ + if (res >= resolution) { │ │ │ │ │ + highRes = res; │ │ │ │ │ + lowZoom = i; │ │ │ │ │ + } │ │ │ │ │ + if (res <= resolution) { │ │ │ │ │ + lowRes = res; │ │ │ │ │ + highZoom = i; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var dRes = highRes - lowRes; │ │ │ │ │ + if (dRes > 0) { │ │ │ │ │ + zoom = lowZoom + ((highRes - resolution) / dRes); │ │ │ │ │ + } else { │ │ │ │ │ + zoom = lowZoom; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + var diff; │ │ │ │ │ + var minDiff = Number.POSITIVE_INFINITY; │ │ │ │ │ + for (i = 0, len = this.resolutions.length; i < len; i++) { │ │ │ │ │ + if (closest) { │ │ │ │ │ + diff = Math.abs(this.resolutions[i] - resolution); │ │ │ │ │ + if (diff > minDiff) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + minDiff = diff; │ │ │ │ │ + } else { │ │ │ │ │ + if (this.resolutions[i] < resolution) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + zoom = Math.max(0, i - 1); │ │ │ │ │ } │ │ │ │ │ + return zoom; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onclick │ │ │ │ │ - * Ignore clicks, but allowing default browser handling │ │ │ │ │ + * APIMethod: getLonLatFromViewPortPx │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * viewPortPx - {|Object} An OpenLayers.Pixel or │ │ │ │ │ + * an object with a 'x' │ │ │ │ │ + * and 'y' properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An OpenLayers.LonLat which is the passed-in │ │ │ │ │ + * view port , translated into lon/lat by the layer. │ │ │ │ │ */ │ │ │ │ │ - onclick: function(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ + getLonLatFromViewPortPx: function(viewPortPx) { │ │ │ │ │ + var lonlat = null; │ │ │ │ │ + var map = this.map; │ │ │ │ │ + if (viewPortPx != null && map.minPx) { │ │ │ │ │ + var res = map.getResolution(); │ │ │ │ │ + var maxExtent = map.getMaxExtent({ │ │ │ │ │ + restricted: true │ │ │ │ │ + }); │ │ │ │ │ + var lon = (viewPortPx.x - map.minPx.x) * res + maxExtent.left; │ │ │ │ │ + var lat = (map.minPx.y - viewPortPx.y) * res + maxExtent.top; │ │ │ │ │ + lonlat = new OpenLayers.LonLat(lon, lat); │ │ │ │ │ + │ │ │ │ │ + if (this.wrapDateLine) { │ │ │ │ │ + lonlat = lonlat.wrapDateLine(this.maxExtent); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return lonlat; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onmouseout │ │ │ │ │ - * When mouse goes out of the popup set the flag to false so that │ │ │ │ │ - * if they let go and then drag back in, we won't be confused. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getViewPortPxFromLonLat │ │ │ │ │ + * Returns a pixel location given a map location. This method will return │ │ │ │ │ + * fractional pixel values. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * lonlat - {|Object} An OpenLayers.LonLat or │ │ │ │ │ + * an object with a 'lon' │ │ │ │ │ + * and 'lat' properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An which is the passed-in │ │ │ │ │ + * lonlat translated into view port pixels. │ │ │ │ │ */ │ │ │ │ │ - onmouseout: function(evt) { │ │ │ │ │ - this.mousedown = false; │ │ │ │ │ + getViewPortPxFromLonLat: function(lonlat, resolution) { │ │ │ │ │ + var px = null; │ │ │ │ │ + if (lonlat != null) { │ │ │ │ │ + resolution = resolution || this.map.getResolution(); │ │ │ │ │ + var extent = this.map.calculateBounds(null, resolution); │ │ │ │ │ + px = new OpenLayers.Pixel( │ │ │ │ │ + (1 / resolution * (lonlat.lon - extent.left)), │ │ │ │ │ + (1 / resolution * (extent.top - lonlat.lat)) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return px; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: ondblclick │ │ │ │ │ - * Ignore double-clicks, but allowing default browser handling │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setOpacity │ │ │ │ │ + * Sets the opacity for the entire layer (all images) │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * opacity - {Float} │ │ │ │ │ */ │ │ │ │ │ - ondblclick: function(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt, true); │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + if (opacity != this.opacity) { │ │ │ │ │ + this.opacity = opacity; │ │ │ │ │ + var childNodes = this.div.childNodes; │ │ │ │ │ + for (var i = 0, len = childNodes.length; i < len; ++i) { │ │ │ │ │ + var element = childNodes[i].firstChild || childNodes[i]; │ │ │ │ │ + var lastChild = childNodes[i].lastChild; │ │ │ │ │ + //TODO de-uglify this │ │ │ │ │ + if (lastChild && lastChild.nodeName.toLowerCase() === "iframe") { │ │ │ │ │ + element = lastChild.parentNode; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.modifyDOMElement(element, null, null, null, │ │ │ │ │ + null, null, null, opacity); │ │ │ │ │ + } │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: this, │ │ │ │ │ + property: "opacity" │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Popup" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Popup.WIDTH = 200; │ │ │ │ │ -OpenLayers.Popup.HEIGHT = 200; │ │ │ │ │ -OpenLayers.Popup.COLOR = "white"; │ │ │ │ │ -OpenLayers.Popup.OPACITY = 1; │ │ │ │ │ -OpenLayers.Popup.BORDER = "0px"; │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/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 │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: getZIndex │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Integer} the z-index of this layer │ │ │ │ │ + */ │ │ │ │ │ + getZIndex: function() { │ │ │ │ │ + return this.div.style.zIndex; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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 │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: setZIndex │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * zIndex - {Integer} │ │ │ │ │ + */ │ │ │ │ │ + setZIndex: function(zIndex) { │ │ │ │ │ + this.div.style.zIndex = zIndex; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -OpenLayers.Spherical = OpenLayers.Spherical || {}; │ │ │ │ │ + /** │ │ │ │ │ + * Method: adjustBounds │ │ │ │ │ + * This function will take a bounds, and if wrapDateLine option is set │ │ │ │ │ + * on the layer, it will return a bounds which is wrapped around the │ │ │ │ │ + * world. We do not wrap for bounds which *cross* the │ │ │ │ │ + * maxExtent.left/right, only bounds which are entirely to the left │ │ │ │ │ + * or entirely to the right. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ + */ │ │ │ │ │ + adjustBounds: function(bounds) { │ │ │ │ │ │ │ │ │ │ -OpenLayers.Spherical.DEFAULT_RADIUS = 6378137; │ │ │ │ │ + if (this.gutter) { │ │ │ │ │ + // Adjust the extent of a bounds in map units by the │ │ │ │ │ + // layer's gutter in pixels. │ │ │ │ │ + var mapGutter = this.gutter * this.map.getResolution(); │ │ │ │ │ + bounds = new OpenLayers.Bounds(bounds.left - mapGutter, │ │ │ │ │ + bounds.bottom - mapGutter, │ │ │ │ │ + bounds.right + mapGutter, │ │ │ │ │ + bounds.top + mapGutter); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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)); │ │ │ │ │ -}; │ │ │ │ │ + if (this.wrapDateLine) { │ │ │ │ │ + // wrap around the date line, within the limits of rounding error │ │ │ │ │ + var wrappingOptions = { │ │ │ │ │ + 'rightTolerance': this.getResolution(), │ │ │ │ │ + 'leftTolerance': this.getResolution() │ │ │ │ │ + }; │ │ │ │ │ + bounds = bounds.wrapDateLine(this.maxExtent, wrappingOptions); │ │ │ │ │ │ │ │ │ │ + } │ │ │ │ │ + return bounds; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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; │ │ │ │ │ -}; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Layer" │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Marker.js │ │ │ │ │ + OpenLayers/Layer/HTTPRequest.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - * @requires OpenLayers/Icon.js │ │ │ │ │ + * @requires OpenLayers/Layer.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. │ │ │ │ │ + * Class: OpenLayers.Layer.HTTPRequest │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Marker = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: icon │ │ │ │ │ - * {} The icon used by this marker. │ │ │ │ │ + * Constant: URL_HASH_FACTOR │ │ │ │ │ + * {Float} Used to hash URL param strings for multi-WMS server selection. │ │ │ │ │ + * Set to the Golden Ratio per Knuth's recommendation. │ │ │ │ │ */ │ │ │ │ │ - icon: null, │ │ │ │ │ + URL_HASH_FACTOR: (Math.sqrt(5) - 1) / 2, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lonlat │ │ │ │ │ - * {} location of object │ │ │ │ │ + * Property: url │ │ │ │ │ + * {Array(String) or String} This is either an array of url strings or │ │ │ │ │ + * a single url string. │ │ │ │ │ */ │ │ │ │ │ - lonlat: null, │ │ │ │ │ + url: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: events │ │ │ │ │ - * {} the event handler. │ │ │ │ │ + * Property: params │ │ │ │ │ + * {Object} Hashtable of key/value parameters │ │ │ │ │ */ │ │ │ │ │ - events: null, │ │ │ │ │ + params: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} the map this marker is attached to │ │ │ │ │ + * APIProperty: reproject │ │ │ │ │ + * *Deprecated*. See http://docs.openlayers.org/library/spherical_mercator.html │ │ │ │ │ + * for information on the replacement for this functionality. │ │ │ │ │ + * {Boolean} Whether layer should reproject itself based on base layer │ │ │ │ │ + * locations. This allows reprojection onto commercial layers. │ │ │ │ │ + * Default is false: Most layers can't reproject, but layers │ │ │ │ │ + * which can create non-square geographic pixels can, like WMS. │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - map: null, │ │ │ │ │ + reproject: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Marker │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Layer.HTTPRequest │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {} the position of this marker │ │ │ │ │ - * icon - {} the icon for this marker │ │ │ │ │ + * name - {String} │ │ │ │ │ + * url - {Array(String) or String} │ │ │ │ │ + * params - {Object} │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + initialize: function(name, url, params, options) { │ │ │ │ │ + OpenLayers.Layer.prototype.initialize.apply(this, [name, options]); │ │ │ │ │ + this.url = url; │ │ │ │ │ + if (!this.params) { │ │ │ │ │ + this.params = OpenLayers.Util.extend({}, params); │ │ │ │ │ } │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ + this.url = null; │ │ │ │ │ + this.params = null; │ │ │ │ │ + OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Calls draw on the icon, and returns that output. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ + * obj - {Object} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} A new DOM Image with this marker's icon set at the │ │ │ │ │ - * location passed-in │ │ │ │ │ + * {} An exact clone of this │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - return this.icon.draw(px); │ │ │ │ │ - }, │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: erase │ │ │ │ │ - * Erases any drawn elements for this marker. │ │ │ │ │ - */ │ │ │ │ │ - erase: function() { │ │ │ │ │ - if (this.icon != null) { │ │ │ │ │ - this.icon.erase(); │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer.HTTPRequest(this.name, │ │ │ │ │ + this.url, │ │ │ │ │ + this.params, │ │ │ │ │ + this.getOptions()); │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + //get all additions from superclasses │ │ │ │ │ + obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]); │ │ │ │ │ + │ │ │ │ │ + // copy/set any non-init, non-simple values here │ │ │ │ │ + │ │ │ │ │ + return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Move the marker to the new location. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setUrl │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {|Object} the pixel position to move to. │ │ │ │ │ - * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ + * newUrl - {String} │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(px) { │ │ │ │ │ - if ((px != null) && (this.icon != null)) { │ │ │ │ │ - this.icon.moveTo(px); │ │ │ │ │ - } │ │ │ │ │ - this.lonlat = this.map.getLonLatFromLayerPx(px); │ │ │ │ │ + setUrl: function(newUrl) { │ │ │ │ │ + this.url = newUrl; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: isDrawn │ │ │ │ │ + * APIMethod: mergeNewParams │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newParams - {Object} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the marker is drawn. │ │ │ │ │ + * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ */ │ │ │ │ │ - isDrawn: function() { │ │ │ │ │ - var isDrawn = (this.icon && this.icon.isDrawn()); │ │ │ │ │ - return isDrawn; │ │ │ │ │ + mergeNewParams: function(newParams) { │ │ │ │ │ + this.params = OpenLayers.Util.extend(this.params, newParams); │ │ │ │ │ + var ret = this.redraw(); │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.events.triggerEvent("changelayer", { │ │ │ │ │ + layer: this, │ │ │ │ │ + property: "params" │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + return ret; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onScreen │ │ │ │ │ + * APIMethod: redraw │ │ │ │ │ + * Redraws the layer. Returns true if the layer was redrawn, false if not. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * force - {Boolean} Force redraw by adding random parameter. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Whether or not the marker is currently visible on screen. │ │ │ │ │ + * {Boolean} The layer was redrawn. │ │ │ │ │ */ │ │ │ │ │ - onScreen: function() { │ │ │ │ │ - │ │ │ │ │ - var onScreen = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - var screenBounds = this.map.getExtent(); │ │ │ │ │ - onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ + redraw: function(force) { │ │ │ │ │ + if (force) { │ │ │ │ │ + return this.mergeNewParams({ │ │ │ │ │ + "_olSalt": Math.random() │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + return OpenLayers.Layer.prototype.redraw.apply(this, []); │ │ │ │ │ } │ │ │ │ │ - return onScreen; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: inflate │ │ │ │ │ - * Englarges the markers icon by the specified ratio. │ │ │ │ │ + * Method: selectUrl │ │ │ │ │ + * selectUrl() implements the standard floating-point multiplicative │ │ │ │ │ + * hash function described by Knuth, and hashes the contents of the │ │ │ │ │ + * given param string into a float between 0 and 1. This float is then │ │ │ │ │ + * scaled to the size of the provided urls array, and used to select │ │ │ │ │ + * a URL. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * inflate - {float} the ratio to enlarge the marker by (passing 2 │ │ │ │ │ - * will double the size). │ │ │ │ │ + * paramString - {String} │ │ │ │ │ + * urls - {Array(String)} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} An entry from the urls array, deterministically selected based │ │ │ │ │ + * on the paramString. │ │ │ │ │ */ │ │ │ │ │ - inflate: function(inflate) { │ │ │ │ │ - if (this.icon) { │ │ │ │ │ - this.icon.setSize({ │ │ │ │ │ - w: this.icon.size.w * inflate, │ │ │ │ │ - h: this.icon.size.h * inflate │ │ │ │ │ - }); │ │ │ │ │ + selectUrl: function(paramString, urls) { │ │ │ │ │ + var product = 1; │ │ │ │ │ + for (var i = 0, len = paramString.length; i < len; i++) { │ │ │ │ │ + product *= paramString.charCodeAt(i) * this.URL_HASH_FACTOR; │ │ │ │ │ + product -= Math.floor(product); │ │ │ │ │ } │ │ │ │ │ + return urls[Math.floor(product * urls.length)]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setOpacity │ │ │ │ │ - * Change the opacity of the marker by changin the opacity of │ │ │ │ │ - * its icon │ │ │ │ │ + * Method: getFullRequestString │ │ │ │ │ + * Combine url with layer's params and these newParams. │ │ │ │ │ + * │ │ │ │ │ + * does checking on the serverPath variable, allowing for cases when it │ │ │ │ │ + * is supplied with trailing ? or &, as well as cases where not. │ │ │ │ │ + * │ │ │ │ │ + * return in formatted string like this: │ │ │ │ │ + * "server?key1=value1&key2=value2&key3=value3" │ │ │ │ │ * │ │ │ │ │ + * WARNING: The altUrl parameter is deprecated and will be removed in 3.0. │ │ │ │ │ + * │ │ │ │ │ * 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} │ │ │ │ │ + * newParams - {Object} │ │ │ │ │ + * altUrl - {String} Use this as the url instead of the layer's url │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - setUrl: function(url) { │ │ │ │ │ - this.icon.setUrl(url); │ │ │ │ │ - }, │ │ │ │ │ + getFullRequestString: function(newParams, altUrl) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Hide or show the icon │ │ │ │ │ - * │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - this.icon.display(display); │ │ │ │ │ - }, │ │ │ │ │ + // if not altUrl passed in, use layer's url │ │ │ │ │ + var url = altUrl || this.url; │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Marker" │ │ │ │ │ -}); │ │ │ │ │ + // create a new params hashtable with all the layer params and the │ │ │ │ │ + // new params together. then convert to string │ │ │ │ │ + var allParams = OpenLayers.Util.extend({}, this.params); │ │ │ │ │ + allParams = OpenLayers.Util.extend(allParams, newParams); │ │ │ │ │ + var paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ │ │ │ │ │ + // if url is not a string, it should be an array of strings, │ │ │ │ │ + // in which case we will deterministically select one of them in │ │ │ │ │ + // order to evenly distribute requests to different urls. │ │ │ │ │ + // │ │ │ │ │ + if (OpenLayers.Util.isArray(url)) { │ │ │ │ │ + url = this.selectUrl(paramsString, url); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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 │ │ │ │ │ - }); │ │ │ │ │ -}; │ │ │ │ │ + // ignore parameters that are already in the url search string │ │ │ │ │ + var urlParams = │ │ │ │ │ + OpenLayers.Util.upperCaseObject(OpenLayers.Util.getParameters(url)); │ │ │ │ │ + for (var key in allParams) { │ │ │ │ │ + if (key.toUpperCase() in urlParams) { │ │ │ │ │ + delete allParams[key]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + paramsString = OpenLayers.Util.getParameterString(allParams); │ │ │ │ │ │ │ │ │ │ + return OpenLayers.Util.urlAppend(url, paramsString); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Layer.HTTPRequest" │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Strategy.js │ │ │ │ │ + OpenLayers/Tile.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Strategy │ │ │ │ │ - * Abstract vector layer strategy class. Not to be instantiated directly. Use │ │ │ │ │ - * one of the strategy subclasses instead. │ │ │ │ │ + * Class: OpenLayers.Tile │ │ │ │ │ + * This is a class designed to designate a single tile, however │ │ │ │ │ + * it is explicitly designed to do relatively little. Tiles store │ │ │ │ │ + * information about themselves -- such as the URL that they are related │ │ │ │ │ + * to, and their size - but do not add themselves to the layer div │ │ │ │ │ + * automatically, for example. Create a new tile with the │ │ │ │ │ + * constructor, or a subclass. │ │ │ │ │ + * │ │ │ │ │ + * TBD 3.0 - remove reference to url in above paragraph │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Strategy = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Tile = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} The layer this strategy belongs to. │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} An events object that handles all │ │ │ │ │ + * events on the tile. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * tile.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types: │ │ │ │ │ + * beforedraw - Triggered before the tile is drawn. Used to defer │ │ │ │ │ + * drawing to an animation queue. To defer drawing, listeners need │ │ │ │ │ + * to return false, which will abort drawing. The queue handler needs │ │ │ │ │ + * to call (true) to actually draw the tile. │ │ │ │ │ + * loadstart - Triggered when tile loading starts. │ │ │ │ │ + * loadend - Triggered when tile loading ends. │ │ │ │ │ + * loaderror - Triggered before the loadend event (i.e. when the tile is │ │ │ │ │ + * still hidden) if the tile could not be loaded. │ │ │ │ │ + * reload - Triggered when an already loading tile is reloaded. │ │ │ │ │ + * unload - Triggered before a tile is unloaded. │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: options │ │ │ │ │ - * {Object} Any options sent to the constructor. │ │ │ │ │ - */ │ │ │ │ │ - options: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: active │ │ │ │ │ - * {Boolean} The control is active. │ │ │ │ │ + * APIProperty: eventListeners │ │ │ │ │ + * {Object} If set as an option at construction, the eventListeners │ │ │ │ │ + * object will be registered with . Object │ │ │ │ │ + * structure must be a listeners object as shown in the example for │ │ │ │ │ + * the events.on method. │ │ │ │ │ + * │ │ │ │ │ + * This options can be set in the ``tileOptions`` option from │ │ │ │ │ + * . For example, to be notified of the │ │ │ │ │ + * ``loadend`` event of each tiles: │ │ │ │ │ + * (code) │ │ │ │ │ + * new OpenLayers.Layer.OSM('osm', 'http://tile.openstreetmap.org/${z}/${x}/${y}.png', { │ │ │ │ │ + * tileOptions: { │ │ │ │ │ + * eventListeners: { │ │ │ │ │ + * 'loadend': function(evt) { │ │ │ │ │ + * // do something on loadend │ │ │ │ │ + * } │ │ │ │ │ + * } │ │ │ │ │ + * } │ │ │ │ │ + * }); │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ - active: null, │ │ │ │ │ + eventListeners: 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. │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} null │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: autoDestroy │ │ │ │ │ - * {Boolean} The creator of the strategy can set autoDestroy to false │ │ │ │ │ - * to fully control when the strategy is destroyed. Defaults to │ │ │ │ │ - * true. │ │ │ │ │ + /** │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} layer the tile is attached to │ │ │ │ │ */ │ │ │ │ │ - autoDestroy: true, │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Strategy │ │ │ │ │ - * Abstract class for vector strategies. Create instances of a subclass. │ │ │ │ │ + * Property: url │ │ │ │ │ + * {String} url of the request. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * instance. │ │ │ │ │ + * TBD 3.0 │ │ │ │ │ + * Deprecated. The base tile class does not need an url. This should be │ │ │ │ │ + * handled in subclasses. Does not belong here. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + url: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Clean up the strategy. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: bounds │ │ │ │ │ + * {} null │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - this.layer = null; │ │ │ │ │ - this.options = null; │ │ │ │ │ - }, │ │ │ │ │ + bounds: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setLayer │ │ │ │ │ - * Called to set the property. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} null │ │ │ │ │ */ │ │ │ │ │ - setLayer: function(layer) { │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - }, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: position │ │ │ │ │ + * {} Top Left pixel of the tile │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (!this.active) { │ │ │ │ │ - this.active = true; │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ + position: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: isLoading │ │ │ │ │ + * {Boolean} Is the tile loading? │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.active = false; │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Strategy" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Hover.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.Hover │ │ │ │ │ - * The hover handler is to be used to emulate mouseovers on objects │ │ │ │ │ - * on the map that aren't DOM elements. For example one can use │ │ │ │ │ - * this handler to send WMS/GetFeatureInfo requests as the user │ │ │ │ │ - * moves the mouve over the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Hover = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ + isLoading: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: delay │ │ │ │ │ - * {Integer} - Number of milliseconds between mousemoves before │ │ │ │ │ - * the event is considered a hover. Default is 500. │ │ │ │ │ + /** TBD 3.0 -- remove 'url' from the list of parameters to the constructor. │ │ │ │ │ + * there is no need for the base tile class to have a url. │ │ │ │ │ */ │ │ │ │ │ - delay: 500, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: pixelTolerance │ │ │ │ │ - * {Integer} - Maximum number of pixels between mousemoves for │ │ │ │ │ - * an event to be considered a hover. Default is null. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Tile │ │ │ │ │ + * Constructor for a new instance. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} layer that the tile will go in. │ │ │ │ │ + * position - {} │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * url - {} │ │ │ │ │ + * size - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - pixelTolerance: null, │ │ │ │ │ + initialize: function(layer, position, bounds, url, size, options) { │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.position = position.clone(); │ │ │ │ │ + this.setBounds(bounds); │ │ │ │ │ + this.url = url; │ │ │ │ │ + if (size) { │ │ │ │ │ + this.size = size.clone(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: stopMove │ │ │ │ │ - * {Boolean} - Stop other listeners from being notified on mousemoves. │ │ │ │ │ - * Default is false. │ │ │ │ │ - */ │ │ │ │ │ - stopMove: false, │ │ │ │ │ + //give the tile a unique id based on its BBOX. │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID("Tile_"); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: px │ │ │ │ │ - * {} - The location of the last mousemove, expressed │ │ │ │ │ - * in pixels. │ │ │ │ │ - */ │ │ │ │ │ - px: null, │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * {Number} - The id of the timer. │ │ │ │ │ - */ │ │ │ │ │ - timerId: null, │ │ │ │ │ + this.events = new OpenLayers.Events(this); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Hover │ │ │ │ │ - * Construct a hover 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. │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: unload │ │ │ │ │ + * Call immediately before destroying if you are listening to tile │ │ │ │ │ + * events, so that counters are properly handled if tile is still │ │ │ │ │ + * loading at destroy-time. Will only fire an event if the tile is │ │ │ │ │ + * still loading. │ │ │ │ │ */ │ │ │ │ │ + unload: function() { │ │ │ │ │ + if (this.isLoading) { │ │ │ │ │ + this.isLoading = false; │ │ │ │ │ + this.events.triggerEvent("unload"); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mousemove │ │ │ │ │ - * Called when the mouse moves on the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Nullify references to prevent circular references and memory leaks. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - ); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.layer = null; │ │ │ │ │ + this.bounds = null; │ │ │ │ │ + this.size = null; │ │ │ │ │ + this.position = null; │ │ │ │ │ + │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ } │ │ │ │ │ - return !this.stopMove; │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ + this.events = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mouseout │ │ │ │ │ - * Called when the mouse goes out of the map. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Clear whatever is currently in the tile, then return whether or not │ │ │ │ │ + * it should actually be re-drawn. This is an example implementation │ │ │ │ │ + * that can be overridden by subclasses. The minimum thing to do here │ │ │ │ │ + * is to call and return the result from . │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - * │ │ │ │ │ + * force - {Boolean} If true, the tile will not be cleared and no beforedraw │ │ │ │ │ + * event will be fired. This is used for drawing tiles asynchronously │ │ │ │ │ + * after drawing has been cancelled by returning false from a beforedraw │ │ │ │ │ + * listener. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * {Boolean} Whether or not the tile should actually be drawn. Returns null │ │ │ │ │ + * if a beforedraw listener returned false. │ │ │ │ │ */ │ │ │ │ │ - mouseout: function(evt) { │ │ │ │ │ - if (OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - this.callback('move', [evt]); │ │ │ │ │ + draw: function(force) { │ │ │ │ │ + if (!force) { │ │ │ │ │ + //clear tile's contents and mark as not drawn │ │ │ │ │ + this.clear(); │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + var draw = this.shouldDraw(); │ │ │ │ │ + if (draw && !force && this.events.triggerEvent("beforedraw") === false) { │ │ │ │ │ + draw = null; │ │ │ │ │ + } │ │ │ │ │ + return draw; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: passesTolerance │ │ │ │ │ - * Determine whether the mouse move is within the optional pixel tolerance. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - * │ │ │ │ │ + * Method: shouldDraw │ │ │ │ │ + * Return whether or not the tile should actually be (re-)drawn. The only │ │ │ │ │ + * case where we *wouldn't* want to draw the tile is if the tile is outside │ │ │ │ │ + * its layer's maxExtent │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The mouse move is within the pixel tolerance. │ │ │ │ │ + * {Boolean} Whether or not the tile should actually be drawn. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + shouldDraw: function() { │ │ │ │ │ + var withinMaxExtent = false, │ │ │ │ │ + maxExtent = this.layer.maxExtent; │ │ │ │ │ + if (maxExtent) { │ │ │ │ │ + var map = this.layer.map; │ │ │ │ │ + var worldBounds = map.baseLayer.wrapDateLine && map.getMaxExtent(); │ │ │ │ │ + if (this.bounds.intersectsBounds(maxExtent, { │ │ │ │ │ + inclusive: false, │ │ │ │ │ + worldBounds: worldBounds │ │ │ │ │ + })) { │ │ │ │ │ + withinMaxExtent = true; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return passes; │ │ │ │ │ + │ │ │ │ │ + return withinMaxExtent || this.layer.displayOutsideMaxExtent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearTimer │ │ │ │ │ - * Clear the timer and set to null. │ │ │ │ │ + * Method: setBounds │ │ │ │ │ + * Sets the bounds on this instance │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds {} │ │ │ │ │ */ │ │ │ │ │ - clearTimer: function() { │ │ │ │ │ - if (this.timerId != null) { │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ + setBounds: function(bounds) { │ │ │ │ │ + bounds = bounds.clone(); │ │ │ │ │ + if (this.layer.map.baseLayer.wrapDateLine) { │ │ │ │ │ + var worldExtent = this.layer.map.getMaxExtent(), │ │ │ │ │ + tolerance = this.layer.map.getResolution(); │ │ │ │ │ + bounds = bounds.wrapDateLine(worldExtent, { │ │ │ │ │ + leftTolerance: tolerance, │ │ │ │ │ + rightTolerance: tolerance │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ + this.bounds = bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: delayedCall │ │ │ │ │ - * Triggers pause callback. │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * Reposition the tile. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * position - {} │ │ │ │ │ + * redraw - {Boolean} Call draw method on tile after moving. │ │ │ │ │ + * Default is true │ │ │ │ │ */ │ │ │ │ │ - delayedCall: function(evt) { │ │ │ │ │ - this.callback('pause', [evt]); │ │ │ │ │ + moveTo: function(bounds, position, redraw) { │ │ │ │ │ + if (redraw == null) { │ │ │ │ │ + redraw = true; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.setBounds(bounds); │ │ │ │ │ + this.position = position.clone(); │ │ │ │ │ + if (redraw) { │ │ │ │ │ + this.draw(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + /** │ │ │ │ │ + * Method: clear │ │ │ │ │ + * Clear the tile of any bounds/position-related data so that it can │ │ │ │ │ + * be reused in a new location. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ - deactivated = true; │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ + clear: function(draw) { │ │ │ │ │ + // to be extended by subclasses │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Hover" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Tile" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Click.js │ │ │ │ │ + OpenLayers/Tile/Image.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ + * @requires OpenLayers/Tile.js │ │ │ │ │ + * @requires OpenLayers/Animation.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Handler.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.Tile.Image │ │ │ │ │ + * Instances of OpenLayers.Tile.Image are used to manage the image tiles │ │ │ │ │ + * used by various layers. Create a new image tile with the │ │ │ │ │ + * constructor. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: delay │ │ │ │ │ - * {Number} Number of milliseconds between clicks before the event is │ │ │ │ │ - * considered a double-click. │ │ │ │ │ - */ │ │ │ │ │ - delay: 300, │ │ │ │ │ +OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: single │ │ │ │ │ - * {Boolean} Handle single clicks. Default is true. If false, clicks │ │ │ │ │ - * will not be reported. If true, single-clicks will be reported. │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} An events object that handles all │ │ │ │ │ + * events on the tile. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * tile.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to the events): │ │ │ │ │ + * beforeload - Triggered before an image is prepared for loading, when the │ │ │ │ │ + * url for the image is known already. Listeners may call on │ │ │ │ │ + * the tile instance. If they do so, that image will be used and no new │ │ │ │ │ + * one will be created. │ │ │ │ │ */ │ │ │ │ │ - single: true, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: double │ │ │ │ │ - * {Boolean} Handle double-clicks. Default is false. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: url │ │ │ │ │ + * {String} The URL of the image being requested. No default. Filled in by │ │ │ │ │ + * layer.getURL() function. May be modified by loadstart listeners. │ │ │ │ │ */ │ │ │ │ │ - 'double': false, │ │ │ │ │ + url: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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: imgDiv │ │ │ │ │ + * {HTMLImageElement} The image for this tile. │ │ │ │ │ */ │ │ │ │ │ - pixelTolerance: 0, │ │ │ │ │ + imgDiv: 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: frame │ │ │ │ │ + * {DOMElement} The image element is appended to the frame. Any gutter on │ │ │ │ │ + * the image will be hidden behind the frame. If no gutter is set, │ │ │ │ │ + * this will be null. │ │ │ │ │ */ │ │ │ │ │ - dblclickTolerance: 13, │ │ │ │ │ + frame: 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: imageReloadAttempts │ │ │ │ │ + * {Integer} Attempts to load the image. │ │ │ │ │ */ │ │ │ │ │ - stopSingle: false, │ │ │ │ │ + imageReloadAttempts: 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: layerAlphaHack │ │ │ │ │ + * {Boolean} True if the png alpha hack needs to be applied on the layer's div. │ │ │ │ │ */ │ │ │ │ │ - stopDouble: false, │ │ │ │ │ + layerAlphaHack: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * {Number} The id of the timeout waiting to clear the . │ │ │ │ │ + * Property: asyncRequestId │ │ │ │ │ + * {Integer} ID of an request to see if request is still valid. This is a │ │ │ │ │ + * number which increments by 1 for each asynchronous request. │ │ │ │ │ */ │ │ │ │ │ - timerId: null, │ │ │ │ │ + asyncRequestId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: maxGetUrlLength │ │ │ │ │ + * {Number} If set, requests that would result in GET urls with more │ │ │ │ │ + * characters than the number provided will be made using form-encoded │ │ │ │ │ + * HTTP POST. It is good practice to avoid urls that are longer than 2048 │ │ │ │ │ + * characters. │ │ │ │ │ + * │ │ │ │ │ + * Caution: │ │ │ │ │ + * Older versions of Gecko based browsers (e.g. Firefox < 3.5) and most │ │ │ │ │ + * Opera versions do not fully support this option. On all browsers, │ │ │ │ │ + * transition effects are not supported if POST requests are used. │ │ │ │ │ */ │ │ │ │ │ - down: null, │ │ │ │ │ + maxGetUrlLength: 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. │ │ │ │ │ + * Property: canvasContext │ │ │ │ │ + * {CanvasRenderingContext2D} A canvas context associated with │ │ │ │ │ + * the tile image. │ │ │ │ │ */ │ │ │ │ │ - last: null, │ │ │ │ │ + canvasContext: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: first │ │ │ │ │ - * {Object} When waiting for double clicks, this object will store │ │ │ │ │ - * information about the first click in a two click sequence. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: crossOriginKeyword │ │ │ │ │ + * The value of the crossorigin keyword to use when loading images. This is │ │ │ │ │ + * only relevant when using for tiles from remote │ │ │ │ │ + * origins and should be set to either 'anonymous' or 'use-credentials' │ │ │ │ │ + * for servers that send Access-Control-Allow-Origin headers with their │ │ │ │ │ + * tiles. │ │ │ │ │ */ │ │ │ │ │ - first: null, │ │ │ │ │ + crossOriginKeyword: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: rightclickTimerId │ │ │ │ │ - * {Number} The id of the right mouse timeout waiting to clear the │ │ │ │ │ - * . │ │ │ │ │ + /** TBD 3.0 - reorder the parameters to the init function to remove │ │ │ │ │ + * URL. the getUrl() function on the layer gets called on │ │ │ │ │ + * each draw(), so no need to specify it here. │ │ │ │ │ */ │ │ │ │ │ - rightclickTimerId: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Click │ │ │ │ │ - * Create a new click handler. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Tile.Image │ │ │ │ │ + * Constructor for a new instance. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * layer - {} layer that the tile will go in. │ │ │ │ │ + * position - {} │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * url - {} Deprecated. Remove me in 3.0. │ │ │ │ │ + * size - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ + initialize: function(layer, position, bounds, url, size, options) { │ │ │ │ │ + OpenLayers.Tile.prototype.initialize.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - this.down = this.getEventInfo(evt); │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ + this.url = url; //deprecated remove me │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Store position of last move, because touchend event can have │ │ │ │ │ - * an empty "touches" property. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ + this.layerAlphaHack = this.layer.alpha && OpenLayers.Util.alphaHack(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Correctly set event xy property, and add lastTouches to have │ │ │ │ │ - * touches property from last touchstart or touchmove │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - touchend: function(evt) { │ │ │ │ │ - // touchstart may not have been allowed to propagate │ │ │ │ │ - if (this.down) { │ │ │ │ │ - evt.xy = this.last.xy; │ │ │ │ │ - evt.lastTouches = this.last.touches; │ │ │ │ │ - this.handleSingle(evt); │ │ │ │ │ - this.down = null; │ │ │ │ │ + if (this.maxGetUrlLength != null || this.layer.gutter || this.layerAlphaHack) { │ │ │ │ │ + // only create frame if it's needed │ │ │ │ │ + this.frame = document.createElement("div"); │ │ │ │ │ + this.frame.style.position = "absolute"; │ │ │ │ │ + this.frame.style.overflow = "hidden"; │ │ │ │ │ + } │ │ │ │ │ + if (this.maxGetUrlLength != null) { │ │ │ │ │ + OpenLayers.Util.extend(this, OpenLayers.Tile.Image.IFrame); │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: mousedown │ │ │ │ │ - * Handle mousedown. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ - */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - this.down = this.getEventInfo(evt); │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ - return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mouseup │ │ │ │ │ - * Handle mouseup. Installed to support collection of right mouse events. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.imgDiv) { │ │ │ │ │ + this.clear(); │ │ │ │ │ + this.imgDiv = null; │ │ │ │ │ + this.frame = null; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return propagate; │ │ │ │ │ + // don't handle async requests any more │ │ │ │ │ + this.asyncRequestId = null; │ │ │ │ │ + OpenLayers.Tile.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: draw │ │ │ │ │ + * Check that a tile should be drawn, and draw it. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * {Boolean} Was a tile drawn? Or null if a beforedraw listener returned │ │ │ │ │ + * false. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + draw: function() { │ │ │ │ │ + var shouldDraw = OpenLayers.Tile.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (shouldDraw) { │ │ │ │ │ + // The layer's reproject option is deprecated. │ │ │ │ │ + if (this.layer != this.layer.map.baseLayer && this.layer.reproject) { │ │ │ │ │ + // getBoundsFromBaseLayer is defined in deprecated.js. │ │ │ │ │ + this.bounds = this.getBoundsFromBaseLayer(this.position); │ │ │ │ │ + } │ │ │ │ │ + if (this.isLoading) { │ │ │ │ │ + //if we're already loading, send 'reload' instead of 'loadstart'. │ │ │ │ │ + this._loadEvent = "reload"; │ │ │ │ │ } else { │ │ │ │ │ - //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 │ │ │ │ │ - ); │ │ │ │ │ + this.isLoading = true; │ │ │ │ │ + this._loadEvent = "loadstart"; │ │ │ │ │ } │ │ │ │ │ + this.renderTile(); │ │ │ │ │ + this.positionTile(); │ │ │ │ │ + } else if (shouldDraw === false) { │ │ │ │ │ + this.unload(); │ │ │ │ │ } │ │ │ │ │ - return !this.stopSingle; │ │ │ │ │ + return shouldDraw; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: delayedRightCall │ │ │ │ │ - * Sets to null. And optionally triggers the │ │ │ │ │ - * rightclick callback if evt is set. │ │ │ │ │ + * Method: renderTile │ │ │ │ │ + * Internal function to actually initialize the image tile, │ │ │ │ │ + * position it correctly, and set its url. │ │ │ │ │ */ │ │ │ │ │ - delayedRightCall: function(evt) { │ │ │ │ │ - this.rightclickTimerId = null; │ │ │ │ │ - if (evt) { │ │ │ │ │ - this.callback('rightclick', [evt]); │ │ │ │ │ + renderTile: function() { │ │ │ │ │ + if (this.layer.async) { │ │ │ │ │ + // Asynchronous image requests call the asynchronous getURL method │ │ │ │ │ + // on the layer to fetch an image that covers 'this.bounds'. │ │ │ │ │ + var id = this.asyncRequestId = (this.asyncRequestId || 0) + 1; │ │ │ │ │ + this.layer.getURLasync(this.bounds, function(url) { │ │ │ │ │ + if (id == this.asyncRequestId) { │ │ │ │ │ + this.url = url; │ │ │ │ │ + this.initImage(); │ │ │ │ │ + } │ │ │ │ │ + }, this); │ │ │ │ │ + } else { │ │ │ │ │ + // synchronous image requests get the url immediately. │ │ │ │ │ + this.url = this.layer.getURL(this.bounds); │ │ │ │ │ + this.initImage(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: click │ │ │ │ │ - * Handle click events from the browser. This is registered as a listener │ │ │ │ │ - * for click events and should not be called from other events in this │ │ │ │ │ - * handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Continue propagating this event. │ │ │ │ │ + * Method: positionTile │ │ │ │ │ + * Using the properties currenty set on the layer, position the tile correctly. │ │ │ │ │ + * This method is used both by the async and non-async versions of the Tile.Image │ │ │ │ │ + * code. │ │ │ │ │ */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - if (!this.last) { │ │ │ │ │ - this.last = this.getEventInfo(evt); │ │ │ │ │ + positionTile: function() { │ │ │ │ │ + var style = this.getTile().style, │ │ │ │ │ + size = this.frame ? this.size : │ │ │ │ │ + this.layer.getImageSize(this.bounds), │ │ │ │ │ + ratio = 1; │ │ │ │ │ + if (this.layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ + ratio = this.layer.getServerResolution() / this.layer.map.getResolution(); │ │ │ │ │ } │ │ │ │ │ - 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; │ │ │ │ │ + style.left = this.position.x + "px"; │ │ │ │ │ + style.top = this.position.y + "px"; │ │ │ │ │ + style.width = Math.round(ratio * size.w) + "px"; │ │ │ │ │ + style.height = Math.round(ratio * size.h) + "px"; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleDouble │ │ │ │ │ - * Handle double-click sequence. │ │ │ │ │ + * Method: clear │ │ │ │ │ + * Remove the tile from the DOM, clear it of any image related data so that │ │ │ │ │ + * it can be reused in a new location. │ │ │ │ │ */ │ │ │ │ │ - handleDouble: function(evt) { │ │ │ │ │ - if (this.passesDblclickTolerance(evt)) { │ │ │ │ │ - if (this["double"]) { │ │ │ │ │ - this.callback("dblclick", [evt]); │ │ │ │ │ + clear: function() { │ │ │ │ │ + OpenLayers.Tile.prototype.clear.apply(this, arguments); │ │ │ │ │ + var img = this.imgDiv; │ │ │ │ │ + if (img) { │ │ │ │ │ + var tile = this.getTile(); │ │ │ │ │ + if (tile.parentNode === this.layer.div) { │ │ │ │ │ + this.layer.div.removeChild(tile); │ │ │ │ │ } │ │ │ │ │ - // to prevent a dblclick from firing the click callback in IE │ │ │ │ │ - this.clearTimer(); │ │ │ │ │ + this.setImgSrc(); │ │ │ │ │ + if (this.layerAlphaHack === true) { │ │ │ │ │ + img.style.filter = ""; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Element.removeClass(img, "olImageLoadError"); │ │ │ │ │ } │ │ │ │ │ + this.canvasContext = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleSingle │ │ │ │ │ - * Handle single click sequence. │ │ │ │ │ + /** │ │ │ │ │ + * Method: getImage │ │ │ │ │ + * Returns or creates and returns the tile image. │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ + getImage: function() { │ │ │ │ │ + if (!this.imgDiv) { │ │ │ │ │ + this.imgDiv = OpenLayers.Tile.Image.IMAGE.cloneNode(false); │ │ │ │ │ + │ │ │ │ │ + var style = this.imgDiv.style; │ │ │ │ │ + if (this.frame) { │ │ │ │ │ + var left = 0, │ │ │ │ │ + top = 0; │ │ │ │ │ + if (this.layer.gutter) { │ │ │ │ │ + left = this.layer.gutter / this.layer.tileSize.w * 100; │ │ │ │ │ + top = this.layer.gutter / this.layer.tileSize.h * 100; │ │ │ │ │ } │ │ │ │ │ - } 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); │ │ │ │ │ + style.left = -left + "%"; │ │ │ │ │ + style.top = -top + "%"; │ │ │ │ │ + style.width = (2 * left + 100) + "%"; │ │ │ │ │ + style.height = (2 * top + 100) + "%"; │ │ │ │ │ + } │ │ │ │ │ + style.visibility = "hidden"; │ │ │ │ │ + style.opacity = 0; │ │ │ │ │ + if (this.layer.opacity < 1) { │ │ │ │ │ + style.filter = 'alpha(opacity=' + │ │ │ │ │ + (this.layer.opacity * 100) + │ │ │ │ │ + ')'; │ │ │ │ │ + } │ │ │ │ │ + style.position = "absolute"; │ │ │ │ │ + if (this.layerAlphaHack) { │ │ │ │ │ + // move the image out of sight │ │ │ │ │ + style.paddingTop = style.height; │ │ │ │ │ + style.height = "0"; │ │ │ │ │ + style.width = "100%"; │ │ │ │ │ + } │ │ │ │ │ + if (this.frame) { │ │ │ │ │ + this.frame.appendChild(this.imgDiv); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + return this.imgDiv; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: queuePotentialClick │ │ │ │ │ - * This method is separated out largely to make testing easier (so we │ │ │ │ │ - * don't have to override window.setTimeout) │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setImage │ │ │ │ │ + * Sets the image element for this tile. This method should only be called │ │ │ │ │ + * from beforeload listeners. │ │ │ │ │ + * │ │ │ │ │ + * Parameters │ │ │ │ │ + * img - {HTMLImageElement} The image to use for this tile. │ │ │ │ │ */ │ │ │ │ │ - queuePotentialClick: function(evt) { │ │ │ │ │ - this.timerId = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(this.delayedCall, this, evt), │ │ │ │ │ - this.delay │ │ │ │ │ - ); │ │ │ │ │ + setImage: function(img) { │ │ │ │ │ + this.imgDiv = img; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: passesTolerance │ │ │ │ │ - * Determine whether the event is within the optional pixel tolerance. Note │ │ │ │ │ - * that the pixel tolerance check only works if mousedown events get to │ │ │ │ │ - * the listeners registered here. If they are stopped by other elements, │ │ │ │ │ - * the will have no effect here (this method will always │ │ │ │ │ - * return true). │ │ │ │ │ + * Method: initImage │ │ │ │ │ + * Creates the content for the frame on the tile. │ │ │ │ │ + */ │ │ │ │ │ + initImage: function() { │ │ │ │ │ + if (!this.url && !this.imgDiv) { │ │ │ │ │ + // fast path out - if there is no tile url and no previous image │ │ │ │ │ + this.isLoading = false; │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent('beforeload'); │ │ │ │ │ + this.layer.div.appendChild(this.getTile()); │ │ │ │ │ + this.events.triggerEvent(this._loadEvent); │ │ │ │ │ + var img = this.getImage(); │ │ │ │ │ + var src = img.getAttribute('src') || ''; │ │ │ │ │ + if (this.url && OpenLayers.Util.isEquivalentUrl(src, this.url)) { │ │ │ │ │ + this._loadTimeout = window.setTimeout( │ │ │ │ │ + OpenLayers.Function.bind(this.onImageLoad, this), 0 │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + this.stopLoading(); │ │ │ │ │ + if (this.crossOriginKeyword) { │ │ │ │ │ + img.removeAttribute("crossorigin"); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Event.observe(img, "load", │ │ │ │ │ + OpenLayers.Function.bind(this.onImageLoad, this) │ │ │ │ │ + ); │ │ │ │ │ + OpenLayers.Event.observe(img, "error", │ │ │ │ │ + OpenLayers.Function.bind(this.onImageError, this) │ │ │ │ │ + ); │ │ │ │ │ + this.imageReloadAttempts = 0; │ │ │ │ │ + this.setImgSrc(this.url); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setImgSrc │ │ │ │ │ + * Sets the source for the tile image │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The click is within the pixel tolerance (if specified). │ │ │ │ │ + * Parameters: │ │ │ │ │ + * url - {String} or undefined to hide the image │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ + setImgSrc: function(url) { │ │ │ │ │ + var img = this.imgDiv; │ │ │ │ │ + if (url) { │ │ │ │ │ + img.style.visibility = 'hidden'; │ │ │ │ │ + img.style.opacity = 0; │ │ │ │ │ + // don't set crossOrigin if the url is a data URL │ │ │ │ │ + if (this.crossOriginKeyword) { │ │ │ │ │ + if (url.substr(0, 5) !== 'data:') { │ │ │ │ │ + img.setAttribute("crossorigin", this.crossOriginKeyword); │ │ │ │ │ + } else { │ │ │ │ │ + img.removeAttribute("crossorigin"); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + img.src = url; │ │ │ │ │ + } else { │ │ │ │ │ + // Remove reference to the image, and leave it to the browser's │ │ │ │ │ + // caching and garbage collection. │ │ │ │ │ + this.stopLoading(); │ │ │ │ │ + this.imgDiv = null; │ │ │ │ │ + if (img.parentNode) { │ │ │ │ │ + img.parentNode.removeChild(img); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return passes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getTouchDistance │ │ │ │ │ + /** │ │ │ │ │ + * Method: getTile │ │ │ │ │ + * Get the tile's markup. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The pixel displacement between two touches. │ │ │ │ │ + * {DOMElement} The tile's markup │ │ │ │ │ */ │ │ │ │ │ - getTouchDistance: function(from, to) { │ │ │ │ │ - return Math.sqrt( │ │ │ │ │ - Math.pow(from.clientX - to.clientX, 2) + │ │ │ │ │ - Math.pow(from.clientY - to.clientY, 2) │ │ │ │ │ - ); │ │ │ │ │ + getTile: function() { │ │ │ │ │ + return this.frame ? this.frame : this.getImage(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: passesDblclickTolerance │ │ │ │ │ - * Determine whether the event is within the optional double-cick pixel │ │ │ │ │ - * tolerance. │ │ │ │ │ + * Method: createBackBuffer │ │ │ │ │ + * Create a backbuffer for this tile. A backbuffer isn't exactly a clone │ │ │ │ │ + * of the tile's markup, because we want to avoid the reloading of the │ │ │ │ │ + * image. So we clone the frame, and steal the image from the tile. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The click is within the double-click pixel tolerance. │ │ │ │ │ + * {DOMElement} The markup, or undefined if the tile has no image │ │ │ │ │ + * or if it's currently loading. │ │ │ │ │ */ │ │ │ │ │ - passesDblclickTolerance: function(evt) { │ │ │ │ │ - var passes = true; │ │ │ │ │ - if (this.down && this.first) { │ │ │ │ │ - passes = this.down.xy.distanceTo(this.first.xy) <= this.dblclickTolerance; │ │ │ │ │ + createBackBuffer: function() { │ │ │ │ │ + if (!this.imgDiv || this.isLoading) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - return passes; │ │ │ │ │ + var backBuffer; │ │ │ │ │ + if (this.frame) { │ │ │ │ │ + backBuffer = this.frame.cloneNode(false); │ │ │ │ │ + backBuffer.appendChild(this.imgDiv); │ │ │ │ │ + } else { │ │ │ │ │ + backBuffer = this.imgDiv; │ │ │ │ │ + } │ │ │ │ │ + this.imgDiv = null; │ │ │ │ │ + return backBuffer; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearTimer │ │ │ │ │ - * Clear the timer and set to null. │ │ │ │ │ + * Method: onImageLoad │ │ │ │ │ + * Handler for the image onload event │ │ │ │ │ */ │ │ │ │ │ - clearTimer: function() { │ │ │ │ │ - if (this.timerId != null) { │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.rightclickTimerId != null) { │ │ │ │ │ - window.clearTimeout(this.rightclickTimerId); │ │ │ │ │ - this.rightclickTimerId = null; │ │ │ │ │ + onImageLoad: function() { │ │ │ │ │ + var img = this.imgDiv; │ │ │ │ │ + this.stopLoading(); │ │ │ │ │ + img.style.visibility = 'inherit'; │ │ │ │ │ + img.style.opacity = this.layer.opacity; │ │ │ │ │ + this.isLoading = false; │ │ │ │ │ + this.canvasContext = null; │ │ │ │ │ + this.events.triggerEvent("loadend"); │ │ │ │ │ + │ │ │ │ │ + if (this.layerAlphaHack === true) { │ │ │ │ │ + img.style.filter = │ │ │ │ │ + "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + │ │ │ │ │ + img.src + "', sizingMethod='scale')"; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: delayedCall │ │ │ │ │ - * Sets to null. And optionally triggers the click callback if │ │ │ │ │ - * evt is set. │ │ │ │ │ + * Method: onImageError │ │ │ │ │ + * Handler for the image onerror event │ │ │ │ │ */ │ │ │ │ │ - delayedCall: function(evt) { │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - if (evt) { │ │ │ │ │ - this.callback("click", [evt]); │ │ │ │ │ + onImageError: function() { │ │ │ │ │ + var img = this.imgDiv; │ │ │ │ │ + if (img.src != null) { │ │ │ │ │ + this.imageReloadAttempts++; │ │ │ │ │ + if (this.imageReloadAttempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) { │ │ │ │ │ + this.setImgSrc(this.layer.getURL(this.bounds)); │ │ │ │ │ + } else { │ │ │ │ │ + OpenLayers.Element.addClass(img, "olImageLoadError"); │ │ │ │ │ + this.events.triggerEvent("loaderror"); │ │ │ │ │ + this.onImageLoad(); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getEventInfo │ │ │ │ │ - * This method allows us to store event information without storing the │ │ │ │ │ - * actual event. In touch devices (at least), the same event is │ │ │ │ │ - * modified between touchstart, touchmove, and touchend. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object with event related info. │ │ │ │ │ + * Method: stopLoading │ │ │ │ │ + * Stops a loading sequence so won't be executed. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ + stopLoading: function() { │ │ │ │ │ + OpenLayers.Event.stopObservingElement(this.imgDiv); │ │ │ │ │ + window.clearTimeout(this._loadTimeout); │ │ │ │ │ + delete this._loadTimeout; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ + * APIMethod: getCanvasContext │ │ │ │ │ + * Returns a canvas context associated with the tile image (with │ │ │ │ │ + * the image drawn on it). │ │ │ │ │ + * Returns undefined if the browser does not support canvas, if │ │ │ │ │ + * the tile has no image or if it's currently loading. │ │ │ │ │ + * │ │ │ │ │ + * The function returns a canvas context instance but the │ │ │ │ │ + * underlying canvas is still available in the 'canvas' property: │ │ │ │ │ + * (code) │ │ │ │ │ + * var context = tile.getCanvasContext(); │ │ │ │ │ + * if (context) { │ │ │ │ │ + * var data = context.canvas.toDataURL('image/jpeg'); │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + getCanvasContext: function() { │ │ │ │ │ + if (OpenLayers.CANVAS_SUPPORTED && this.imgDiv && !this.isLoading) { │ │ │ │ │ + if (!this.canvasContext) { │ │ │ │ │ + var canvas = document.createElement("canvas"); │ │ │ │ │ + canvas.width = this.size.w; │ │ │ │ │ + canvas.height = this.size.h; │ │ │ │ │ + this.canvasContext = canvas.getContext("2d"); │ │ │ │ │ + this.canvasContext.drawImage(this.imgDiv, 0, 0); │ │ │ │ │ + } │ │ │ │ │ + return this.canvasContext; │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Click" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Tile.Image" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Tile.Image.IMAGE │ │ │ │ │ + * {HTMLImageElement} The image for a tile. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Tile.Image.IMAGE = (function() { │ │ │ │ │ + var img = new Image(); │ │ │ │ │ + img.className = "olTileImage"; │ │ │ │ │ + // avoid image gallery menu in IE6 │ │ │ │ │ + img.galleryImg = "no"; │ │ │ │ │ + return img; │ │ │ │ │ +}()); │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/UTFGrid.js │ │ │ │ │ + OpenLayers/Layer/Grid.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + * @requires OpenLayers/Layer/HTTPRequest.js │ │ │ │ │ + * @requires OpenLayers/Tile/Image.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.UTFGrid │ │ │ │ │ - * │ │ │ │ │ - * This Control provides behavior associated with UTFGrid Layers. │ │ │ │ │ - * These 'hit grids' provide underlying feature attributes without │ │ │ │ │ - * calling the server (again). This control allows Mousemove, Hovering │ │ │ │ │ - * and Click events to trigger callbacks that use the attributes in │ │ │ │ │ - * whatever way you need. │ │ │ │ │ - * │ │ │ │ │ - * The most common example may be a UTFGrid layer containing feature │ │ │ │ │ - * attributes that are displayed in a div as you mouseover. │ │ │ │ │ - * │ │ │ │ │ - * Example Code: │ │ │ │ │ - * │ │ │ │ │ - * (start code) │ │ │ │ │ - * var world_utfgrid = new OpenLayers.Layer.UTFGrid( │ │ │ │ │ - * 'UTFGrid Layer', │ │ │ │ │ - * "http://tiles/world_utfgrid/${z}/${x}/${y}.json" │ │ │ │ │ - * ); │ │ │ │ │ - * map.addLayer(world_utfgrid); │ │ │ │ │ - * │ │ │ │ │ - * var control = new OpenLayers.Control.UTFGrid({ │ │ │ │ │ - * layers: [world_utfgrid], │ │ │ │ │ - * handlerMode: 'move', │ │ │ │ │ - * callback: function(infoLookup) { │ │ │ │ │ - * // do something with returned data │ │ │ │ │ - * │ │ │ │ │ - * } │ │ │ │ │ - * }) │ │ │ │ │ - * (end code) │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Layer.Grid │ │ │ │ │ + * Base class for layers that use a lattice of tiles. Create a new grid │ │ │ │ │ + * layer with the constructor. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * APIProperty: tileSize │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + tileSize: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: Layers │ │ │ │ │ - * List of layers to consider. Must be Layer.UTFGrids │ │ │ │ │ - * `null` is the default indicating all UTFGrid Layers are queried. │ │ │ │ │ - * {Array} │ │ │ │ │ + /** │ │ │ │ │ + * Property: tileOriginCorner │ │ │ │ │ + * {String} If the property is not provided, the tile origin │ │ │ │ │ + * will be derived from the layer's . The corner of the │ │ │ │ │ + * used is determined by this property. Acceptable values │ │ │ │ │ + * are "tl" (top left), "tr" (top right), "bl" (bottom left), and "br" │ │ │ │ │ + * (bottom right). Default is "bl". │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + tileOriginCorner: "bl", │ │ │ │ │ │ │ │ │ │ - /* Property: defaultHandlerOptions │ │ │ │ │ - * The default opts passed to the handler constructors │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: tileOrigin │ │ │ │ │ + * {} Optional origin for aligning the grid of tiles. │ │ │ │ │ + * If provided, requests for tiles at all resolutions will be aligned │ │ │ │ │ + * with this location (no tiles shall overlap this location). If │ │ │ │ │ + * not provided, the grid of tiles will be aligned with the layer's │ │ │ │ │ + * . Default is ``null``. │ │ │ │ │ */ │ │ │ │ │ - defaultHandlerOptions: { │ │ │ │ │ - 'delay': 300, │ │ │ │ │ - 'pixelTolerance': 4, │ │ │ │ │ - 'stopMove': false, │ │ │ │ │ - 'single': true, │ │ │ │ │ - 'double': false, │ │ │ │ │ - 'stopSingle': false, │ │ │ │ │ - 'stopDouble': false │ │ │ │ │ - }, │ │ │ │ │ + tileOrigin: null, │ │ │ │ │ │ │ │ │ │ - /* APIProperty: handlerMode │ │ │ │ │ - * Defaults to 'click'. Can be 'hover' or 'move'. │ │ │ │ │ + /** APIProperty: tileOptions │ │ │ │ │ + * {Object} optional configuration options for instances │ │ │ │ │ + * created by this Layer, if supported by the tile class. │ │ │ │ │ */ │ │ │ │ │ - handlerMode: 'click', │ │ │ │ │ + tileOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setHandler │ │ │ │ │ - * sets this.handlerMode and calls resetHandler() │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * hm - {String} Handler Mode string; 'click', 'hover' or 'move'. │ │ │ │ │ + * APIProperty: tileClass │ │ │ │ │ + * {} The tile class to use for this layer. │ │ │ │ │ + * Defaults is OpenLayers.Tile.Image. │ │ │ │ │ */ │ │ │ │ │ - setHandler: function(hm) { │ │ │ │ │ - this.handlerMode = hm; │ │ │ │ │ - this.resetHandler(); │ │ │ │ │ - }, │ │ │ │ │ + tileClass: OpenLayers.Tile.Image, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: resetHandler │ │ │ │ │ - * Deactivates the old hanlder and creates a new │ │ │ │ │ - * based on the mode specified in │ │ │ │ │ - * this.handlerMode │ │ │ │ │ - * │ │ │ │ │ + * Property: grid │ │ │ │ │ + * {Array(Array())} This is an array of rows, each row is │ │ │ │ │ + * an array of tiles. │ │ │ │ │ */ │ │ │ │ │ - resetHandler: function() { │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.deactivate(); │ │ │ │ │ - this.handler.destroy(); │ │ │ │ │ - this.handler = null; │ │ │ │ │ - } │ │ │ │ │ + grid: null, │ │ │ │ │ │ │ │ │ │ - if (this.handlerMode == 'hover') { │ │ │ │ │ - // Handle this event on hover │ │ │ │ │ - this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ - this, { │ │ │ │ │ - 'pause': this.handleEvent, │ │ │ │ │ - 'move': this.reset │ │ │ │ │ - }, │ │ │ │ │ - this.handlerOptions │ │ │ │ │ - ); │ │ │ │ │ - } else if (this.handlerMode == 'click') { │ │ │ │ │ - // Handle this event on click │ │ │ │ │ - this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ - this, { │ │ │ │ │ - 'click': this.handleEvent │ │ │ │ │ - }, this.handlerOptions │ │ │ │ │ - ); │ │ │ │ │ - } else if (this.handlerMode == 'move') { │ │ │ │ │ - this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ - this, │ │ │ │ │ - // Handle this event while hovering OR moving │ │ │ │ │ - { │ │ │ │ │ - 'pause': this.handleEvent, │ │ │ │ │ - 'move': this.handleEvent │ │ │ │ │ - }, │ │ │ │ │ - this.handlerOptions │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: singleTile │ │ │ │ │ + * {Boolean} Moves the layer into single-tile mode, meaning that one tile │ │ │ │ │ + * will be loaded. The tile's size will be determined by the 'ratio' │ │ │ │ │ + * property. When the tile is dragged such that it does not cover the │ │ │ │ │ + * entire viewport, it is reloaded. │ │ │ │ │ + */ │ │ │ │ │ + singleTile: false, │ │ │ │ │ + │ │ │ │ │ + /** APIProperty: ratio │ │ │ │ │ + * {Float} Used only when in single-tile mode, this specifies the │ │ │ │ │ + * ratio of the size of the single tile to the size of the map. │ │ │ │ │ + * Default value is 1.5. │ │ │ │ │ + */ │ │ │ │ │ + ratio: 1.5, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * APIProperty: buffer │ │ │ │ │ + * {Integer} Used only when in gridded mode, this specifies the number of │ │ │ │ │ + * extra rows and colums of tiles on each side which will │ │ │ │ │ + * surround the minimum grid tiles to cover the map. │ │ │ │ │ + * For very slow loading layers, a larger value may increase │ │ │ │ │ + * performance somewhat when dragging, but will increase bandwidth │ │ │ │ │ + * use significantly. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - options.handlerOptions = options.handlerOptions || this.defaultHandlerOptions; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.resetHandler(); │ │ │ │ │ - }, │ │ │ │ │ + buffer: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: transitionEffect │ │ │ │ │ + * {String} The transition effect to use when the map is zoomed. │ │ │ │ │ + * Two posible values: │ │ │ │ │ * │ │ │ │ │ - * Passes the attributes to the callback │ │ │ │ │ + * "resize" - Existing tiles are resized on zoom to provide a visual │ │ │ │ │ + * effect of the zoom having taken place immediately. As the │ │ │ │ │ + * new tiles become available, they are drawn on top of the │ │ │ │ │ + * resized tiles (this is the default setting). │ │ │ │ │ + * "map-resize" - Existing tiles are resized on zoom and placed below the │ │ │ │ │ + * base layer. New tiles for the base layer will cover existing tiles. │ │ │ │ │ + * This setting is recommended when having an overlay duplicated during │ │ │ │ │ + * the transition is undesirable (e.g. street labels or big transparent │ │ │ │ │ + * fills). │ │ │ │ │ + * null - No transition effect. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * Using "resize" on non-opaque layers can cause undesired visual │ │ │ │ │ + * effects. Set transitionEffect to null in this case. │ │ │ │ │ */ │ │ │ │ │ - handleEvent: function(evt) { │ │ │ │ │ - if (evt == null) { │ │ │ │ │ - this.reset(); │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var lonLat = this.map.getLonLatFromPixel(evt.xy); │ │ │ │ │ - if (!lonLat) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + transitionEffect: "resize", │ │ │ │ │ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: numLoadingTiles │ │ │ │ │ + * {Integer} How many tiles are still loading? │ │ │ │ │ + */ │ │ │ │ │ + numLoadingTiles: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: callback │ │ │ │ │ - * Function to be called when a mouse event corresponds with a location that │ │ │ │ │ - * includes data in one of the configured UTFGrid layers. │ │ │ │ │ - * │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: serverResolutions │ │ │ │ │ + * {Array(Number}} This property is documented in subclasses as │ │ │ │ │ + * an API property. │ │ │ │ │ */ │ │ │ │ │ - callback: function(infoLookup) { │ │ │ │ │ - // to be provided in the constructor │ │ │ │ │ - }, │ │ │ │ │ + serverResolutions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: reset │ │ │ │ │ - * Calls the callback with null. │ │ │ │ │ + * Property: loading │ │ │ │ │ + * {Boolean} Indicates if tiles are being loaded. │ │ │ │ │ */ │ │ │ │ │ - reset: function(evt) { │ │ │ │ │ - this.callback(null); │ │ │ │ │ - }, │ │ │ │ │ + loading: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * None │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} Layers to handle on each event │ │ │ │ │ + * Property: backBuffer │ │ │ │ │ + * {DOMElement} The back buffer. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - }, │ │ │ │ │ + backBuffer: null, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.UTFGrid" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ScaleLine.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: gridResolution │ │ │ │ │ + * {Number} The resolution of the current grid. Used for backbuffer and │ │ │ │ │ + * client zoom. This property is updated every time the grid is │ │ │ │ │ + * initialized. │ │ │ │ │ + */ │ │ │ │ │ + gridResolution: null, │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: backBufferResolution │ │ │ │ │ + * {Number} The resolution of the current back buffer. This property is │ │ │ │ │ + * updated each time a back buffer is created. │ │ │ │ │ + */ │ │ │ │ │ + backBufferResolution: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: backBufferLonLat │ │ │ │ │ + * {Object} The top-left corner of the current back buffer. Includes lon │ │ │ │ │ + * and lat properties. This object is updated each time a back buffer │ │ │ │ │ + * is created. │ │ │ │ │ + */ │ │ │ │ │ + backBufferLonLat: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.ScaleLine │ │ │ │ │ - * The ScaleLine displays a small line indicator representing the current │ │ │ │ │ - * map scale on the map. By default it is drawn in the lower left corner of │ │ │ │ │ - * the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * │ │ │ │ │ - * Is a very close copy of: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ScaleLine = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + /** │ │ │ │ │ + * Property: backBufferTimerId │ │ │ │ │ + * {Number} The id of the back buffer timer. This timer is used to │ │ │ │ │ + * delay the removal of the back buffer, thereby preventing │ │ │ │ │ + * flash effects caused by tile animation. │ │ │ │ │ + */ │ │ │ │ │ + backBufferTimerId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: maxWidth │ │ │ │ │ - * {Integer} Maximum width of the scale line in pixels. Default is 100. │ │ │ │ │ + * APIProperty: removeBackBufferDelay │ │ │ │ │ + * {Number} Delay for removing the backbuffer when all tiles have finished │ │ │ │ │ + * loading. Can be set to 0 when no css opacity transitions for the │ │ │ │ │ + * olTileImage class are used. Default is 0 for layers, │ │ │ │ │ + * 2500 for tiled layers. See for more information on │ │ │ │ │ + * tile animation. │ │ │ │ │ */ │ │ │ │ │ - maxWidth: 100, │ │ │ │ │ + removeBackBufferDelay: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: topOutUnits │ │ │ │ │ - * {String} Units for zoomed out on top bar. Default is km. │ │ │ │ │ + * APIProperty: className │ │ │ │ │ + * {String} Name of the class added to the layer div. If not set in the │ │ │ │ │ + * options passed to the constructor then className defaults to │ │ │ │ │ + * "olLayerGridSingleTile" for single tile layers (see ), │ │ │ │ │ + * and "olLayerGrid" for non single tile layers. │ │ │ │ │ + * │ │ │ │ │ + * Note: │ │ │ │ │ + * │ │ │ │ │ + * The displaying of tiles is not animated by default for single tile │ │ │ │ │ + * layers - OpenLayers' default theme (style.css) includes this: │ │ │ │ │ + * (code) │ │ │ │ │ + * .olLayerGrid .olTileImage { │ │ │ │ │ + * -webkit-transition: opacity 0.2s linear; │ │ │ │ │ + * -moz-transition: opacity 0.2s linear; │ │ │ │ │ + * -o-transition: opacity 0.2s linear; │ │ │ │ │ + * transition: opacity 0.2s linear; │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * To animate tile displaying for any grid layer the following │ │ │ │ │ + * CSS rule can be used: │ │ │ │ │ + * (code) │ │ │ │ │ + * .olTileImage { │ │ │ │ │ + * -webkit-transition: opacity 0.2s linear; │ │ │ │ │ + * -moz-transition: opacity 0.2s linear; │ │ │ │ │ + * -o-transition: opacity 0.2s linear; │ │ │ │ │ + * transition: opacity 0.2s linear; │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + * In that case, to avoid flash effects, │ │ │ │ │ + * should not be zero. │ │ │ │ │ */ │ │ │ │ │ - topOutUnits: "km", │ │ │ │ │ + className: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: topInUnits │ │ │ │ │ - * {String} Units for zoomed in on top bar. Default is m. │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * layer.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Listeners will be called with a reference to an event object. The │ │ │ │ │ + * properties of this event depends on exactly what happened. │ │ │ │ │ + * │ │ │ │ │ + * All event objects have at least the following properties: │ │ │ │ │ + * object - {Object} A reference to layer.events.object. │ │ │ │ │ + * element - {DOMElement} A reference to layer.events.element. │ │ │ │ │ + * │ │ │ │ │ + * Supported event types: │ │ │ │ │ + * addtile - Triggered when a tile is added to this layer. Listeners receive │ │ │ │ │ + * an object as first argument, which has a tile property that │ │ │ │ │ + * references the tile that has been added. │ │ │ │ │ + * tileloadstart - Triggered when a tile starts loading. Listeners receive │ │ │ │ │ + * an object as first argument, which has a tile property that │ │ │ │ │ + * references the tile that starts loading. │ │ │ │ │ + * tileloaded - Triggered when each new tile is │ │ │ │ │ + * loaded, as a means of progress update to listeners. │ │ │ │ │ + * listeners can access 'numLoadingTiles' if they wish to keep │ │ │ │ │ + * track of the loading progress. Listeners are called with an object │ │ │ │ │ + * with a 'tile' property as first argument, making the loaded tile │ │ │ │ │ + * available to the listener, and an 'aborted' property, which will be │ │ │ │ │ + * true when loading was aborted and no tile data is available. │ │ │ │ │ + * tileerror - Triggered before the tileloaded event (i.e. when the tile is │ │ │ │ │ + * still hidden) if a tile failed to load. Listeners receive an object │ │ │ │ │ + * as first argument, which has a tile property that references the │ │ │ │ │ + * tile that could not be loaded. │ │ │ │ │ + * retile - Triggered when the layer recreates its tile grid. │ │ │ │ │ */ │ │ │ │ │ - topInUnits: "m", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: bottomOutUnits │ │ │ │ │ - * {String} Units for zoomed out on bottom bar. Default is mi. │ │ │ │ │ + * Property: gridLayout │ │ │ │ │ + * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ + * startrow │ │ │ │ │ */ │ │ │ │ │ - bottomOutUnits: "mi", │ │ │ │ │ + gridLayout: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: bottomInUnits │ │ │ │ │ - * {String} Units for zoomed in on bottom bar. Default is ft. │ │ │ │ │ + * Property: rowSign │ │ │ │ │ + * {Number} 1 for grids starting at the top, -1 for grids starting at the │ │ │ │ │ + * bottom. This is used for several grid index and offset calculations. │ │ │ │ │ */ │ │ │ │ │ - bottomInUnits: "ft", │ │ │ │ │ + rowSign: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: eTop │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * Property: transitionendEvents │ │ │ │ │ + * {Array} Event names for transitionend │ │ │ │ │ */ │ │ │ │ │ - eTop: null, │ │ │ │ │ + transitionendEvents: [ │ │ │ │ │ + 'transitionend', 'webkitTransitionEnd', 'otransitionend', │ │ │ │ │ + 'oTransitionEnd' │ │ │ │ │ + ], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: eBottom │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * Constructor: OpenLayers.Layer.Grid │ │ │ │ │ + * Create a new grid layer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * name - {String} │ │ │ │ │ + * url - {String} │ │ │ │ │ + * params - {Object} │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ */ │ │ │ │ │ - eBottom: null, │ │ │ │ │ + initialize: function(name, url, params, options) { │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this, │ │ │ │ │ + arguments); │ │ │ │ │ + this.grid = []; │ │ │ │ │ + this._removeBackBuffer = OpenLayers.Function.bind(this.removeBackBuffer, this); │ │ │ │ │ + │ │ │ │ │ + this.initProperties(); │ │ │ │ │ + │ │ │ │ │ + this.rowSign = this.tileOriginCorner.substr(0, 1) === "t" ? 1 : -1; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: geodesic │ │ │ │ │ - * {Boolean} Use geodesic measurement. Default is false. The recommended │ │ │ │ │ - * setting for maps in EPSG:4326 is false, and true EPSG:900913. If set to │ │ │ │ │ - * true, the scale will be calculated based on the horizontal size of the │ │ │ │ │ - * pixel in the center of the map viewport. │ │ │ │ │ + * Method: initProperties │ │ │ │ │ + * Set any properties that depend on the value of singleTile. │ │ │ │ │ + * Currently sets removeBackBufferDelay and className │ │ │ │ │ */ │ │ │ │ │ - geodesic: false, │ │ │ │ │ + initProperties: function() { │ │ │ │ │ + if (this.options.removeBackBufferDelay === undefined) { │ │ │ │ │ + this.removeBackBufferDelay = this.singleTile ? 0 : 2500; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.options.className === undefined) { │ │ │ │ │ + this.className = this.singleTile ? 'olLayerGridSingleTile' : │ │ │ │ │ + 'olLayerGrid'; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.ScaleLine │ │ │ │ │ - * Create a new scale line control. │ │ │ │ │ - * │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * map - {} The map. │ │ │ │ │ */ │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.setMap.call(this, map); │ │ │ │ │ + OpenLayers.Element.addClass(this.div, this.className); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * Method: removeMap │ │ │ │ │ + * Called when the layer is removed from the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} The map. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (!this.eTop) { │ │ │ │ │ - // stick in the top bar │ │ │ │ │ - this.eTop = document.createElement("div"); │ │ │ │ │ - this.eTop.className = this.displayClass + "Top"; │ │ │ │ │ - var theLen = this.topInUnits.length; │ │ │ │ │ - this.div.appendChild(this.eTop); │ │ │ │ │ - if ((this.topOutUnits == "") || (this.topInUnits == "")) { │ │ │ │ │ - this.eTop.style.visibility = "hidden"; │ │ │ │ │ - } else { │ │ │ │ │ - this.eTop.style.visibility = "visible"; │ │ │ │ │ - } │ │ │ │ │ + removeMap: function(map) { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // and the bottom bar │ │ │ │ │ - this.eBottom = document.createElement("div"); │ │ │ │ │ - this.eBottom.className = this.displayClass + "Bottom"; │ │ │ │ │ - this.div.appendChild(this.eBottom); │ │ │ │ │ - if ((this.bottomOutUnits == "") || (this.bottomInUnits == "")) { │ │ │ │ │ - this.eBottom.style.visibility = "hidden"; │ │ │ │ │ - } else { │ │ │ │ │ - this.eBottom.style.visibility = "visible"; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.map.events.register('moveend', this, this.update); │ │ │ │ │ - this.update(); │ │ │ │ │ - return this.div; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Deconstruct the layer and clear the grid. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + this.clearGrid(); │ │ │ │ │ + │ │ │ │ │ + this.grid = null; │ │ │ │ │ + this.tileSize = null; │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getBarLen │ │ │ │ │ - * Given a number, round it down to the nearest 1,2,5 times a power of 10. │ │ │ │ │ - * That seems a fairly useful set of number groups to use. │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: mergeNewParams │ │ │ │ │ + * Refetches tiles with new params merged, keeping a backbuffer. Each │ │ │ │ │ + * loading new tile will have a css class of '.olTileReplacing'. If a │ │ │ │ │ + * stylesheet applies a 'display: none' style to that class, any fade-in │ │ │ │ │ + * transition will not apply, and backbuffers for each tile will be removed │ │ │ │ │ + * as soon as the tile is loaded. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * maxLen - {float} the number we're rounding down from │ │ │ │ │ - * │ │ │ │ │ + * newParams - {Object} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Float} the rounded number (less than or equal to maxLen) │ │ │ │ │ + * redrawn: {Boolean} whether the layer was actually redrawn. │ │ │ │ │ */ │ │ │ │ │ - getBarLen: function(maxLen) { │ │ │ │ │ - // nearest power of 10 lower than maxLen │ │ │ │ │ - var digits = parseInt(Math.log(maxLen) / Math.log(10)); │ │ │ │ │ - var pow10 = Math.pow(10, digits); │ │ │ │ │ - │ │ │ │ │ - // ok, find first character │ │ │ │ │ - var firstChar = parseInt(maxLen / pow10); │ │ │ │ │ │ │ │ │ │ - // right, put it into the correct bracket │ │ │ │ │ - var barLen; │ │ │ │ │ - if (firstChar > 5) { │ │ │ │ │ - barLen = 5; │ │ │ │ │ - } else if (firstChar > 2) { │ │ │ │ │ - barLen = 2; │ │ │ │ │ - } else { │ │ │ │ │ - barLen = 1; │ │ │ │ │ + /** │ │ │ │ │ + * Method: clearGrid │ │ │ │ │ + * Go through and remove all tiles from the grid, calling │ │ │ │ │ + * destroy() on each of them to kill circular references │ │ │ │ │ + */ │ │ │ │ │ + clearGrid: function() { │ │ │ │ │ + if (this.grid) { │ │ │ │ │ + for (var iRow = 0, len = this.grid.length; iRow < len; iRow++) { │ │ │ │ │ + var row = this.grid[iRow]; │ │ │ │ │ + for (var iCol = 0, clen = row.length; iCol < clen; iCol++) { │ │ │ │ │ + var tile = row[iCol]; │ │ │ │ │ + this.destroyTile(tile); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.grid = []; │ │ │ │ │ + this.gridResolution = null; │ │ │ │ │ + this.gridLayout = null; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // scale it up the correct power of 10 │ │ │ │ │ - return barLen * pow10; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: update │ │ │ │ │ - * Update the size of the bars, and the labels they contain. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - update: function() { │ │ │ │ │ - var res = this.map.getResolution(); │ │ │ │ │ - if (!res) { │ │ │ │ │ - return; │ │ │ │ │ + addOptions: function(newOptions, reinitialize) { │ │ │ │ │ + var singleTileChanged = newOptions.singleTile !== undefined && │ │ │ │ │ + newOptions.singleTile !== this.singleTile; │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.addOptions.apply(this, arguments); │ │ │ │ │ + if (this.map && singleTileChanged) { │ │ │ │ │ + this.initProperties(); │ │ │ │ │ + this.clearGrid(); │ │ │ │ │ + this.tileSize = this.options.tileSize; │ │ │ │ │ + this.setTileSize(); │ │ │ │ │ + this.moveTo(null, true); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var curMapUnits = this.map.getUnits(); │ │ │ │ │ - var inches = OpenLayers.INCHES_PER_UNIT; │ │ │ │ │ - │ │ │ │ │ - // convert maxWidth to map units │ │ │ │ │ - var maxSizeData = this.maxWidth * res * inches[curMapUnits]; │ │ │ │ │ - var geodesicRatio = 1; │ │ │ │ │ - if (this.geodesic === true) { │ │ │ │ │ - var maxSizeGeodesic = (this.map.getGeodesicPixelSize().w || │ │ │ │ │ - 0.000001) * this.maxWidth; │ │ │ │ │ - var maxSizeKilometers = maxSizeData / inches["km"]; │ │ │ │ │ - geodesicRatio = maxSizeGeodesic / maxSizeKilometers; │ │ │ │ │ - maxSizeData *= geodesicRatio; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Create a clone of this layer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {Object} Is this ever used? │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this OpenLayers.Layer.Grid │ │ │ │ │ + */ │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ │ │ │ │ │ - // decide whether to use large or small scale units │ │ │ │ │ - var topUnits; │ │ │ │ │ - var bottomUnits; │ │ │ │ │ - if (maxSizeData > 100000) { │ │ │ │ │ - topUnits = this.topOutUnits; │ │ │ │ │ - bottomUnits = this.bottomOutUnits; │ │ │ │ │ - } else { │ │ │ │ │ - topUnits = this.topInUnits; │ │ │ │ │ - bottomUnits = this.bottomInUnits; │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer.Grid(this.name, │ │ │ │ │ + this.url, │ │ │ │ │ + this.params, │ │ │ │ │ + this.getOptions()); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // and to map units units │ │ │ │ │ - var topMax = maxSizeData / inches[topUnits]; │ │ │ │ │ - var bottomMax = maxSizeData / inches[bottomUnits]; │ │ │ │ │ - │ │ │ │ │ - // now trim this down to useful block length │ │ │ │ │ - var topRounded = this.getBarLen(topMax); │ │ │ │ │ - var bottomRounded = this.getBarLen(bottomMax); │ │ │ │ │ - │ │ │ │ │ - // and back to display units │ │ │ │ │ - topMax = topRounded / inches[curMapUnits] * inches[topUnits]; │ │ │ │ │ - bottomMax = bottomRounded / inches[curMapUnits] * inches[bottomUnits]; │ │ │ │ │ - │ │ │ │ │ - // and to pixel units │ │ │ │ │ - var topPx = topMax / res / geodesicRatio; │ │ │ │ │ - var bottomPx = bottomMax / res / geodesicRatio; │ │ │ │ │ - │ │ │ │ │ - // now set the pixel widths │ │ │ │ │ - // and the values inside them │ │ │ │ │ + //get all additions from superclasses │ │ │ │ │ + obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]); │ │ │ │ │ │ │ │ │ │ - if (this.eBottom.style.visibility == "visible") { │ │ │ │ │ - this.eBottom.style.width = Math.round(bottomPx) + "px"; │ │ │ │ │ - this.eBottom.innerHTML = bottomRounded + " " + bottomUnits; │ │ │ │ │ + // copy/set any non-init, non-simple values here │ │ │ │ │ + if (this.tileSize != null) { │ │ │ │ │ + obj.tileSize = this.tileSize.clone(); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (this.eTop.style.visibility == "visible") { │ │ │ │ │ - this.eTop.style.width = Math.round(topPx) + "px"; │ │ │ │ │ - this.eTop.innerHTML = topRounded + " " + topUnits; │ │ │ │ │ - } │ │ │ │ │ + // we do not want to copy reference to grid, so we make a new array │ │ │ │ │ + obj.grid = []; │ │ │ │ │ + obj.gridResolution = null; │ │ │ │ │ + // same for backbuffer │ │ │ │ │ + obj.backBuffer = null; │ │ │ │ │ + obj.backBufferTimerId = null; │ │ │ │ │ + obj.loading = false; │ │ │ │ │ + obj.numLoadingTiles = 0; │ │ │ │ │ │ │ │ │ │ + return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ScaleLine" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Drag.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * This function is called whenever the map is moved. All the moving │ │ │ │ │ + * of actual 'tiles' is done by the map, but moveTo's role is to accept │ │ │ │ │ + * a bounds and make sure the data that that bounds requires is pre-loaded. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * zoomChanged - {Boolean} │ │ │ │ │ + * dragging - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - */ │ │ │ │ │ + bounds = bounds || this.map.getExtent(); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.Drag │ │ │ │ │ - * The drag handler is used to deal with sequences of browser events related │ │ │ │ │ - * to dragging. The handler is used by controls that want to know when │ │ │ │ │ - * a drag sequence begins, when a drag is happening, and when it has │ │ │ │ │ - * finished. │ │ │ │ │ - * │ │ │ │ │ - * Controls that use the drag handler typically construct it with callbacks │ │ │ │ │ - * for 'down', 'move', and 'done'. Callbacks for these keys are called │ │ │ │ │ - * when the drag begins, with each move, and when the drag is done. In │ │ │ │ │ - * addition, controls can have callbacks keyed to 'up' and 'out' if they │ │ │ │ │ - * care to differentiate between the types of events that correspond with │ │ │ │ │ - * the end of a drag sequence. If no drag actually occurs (no mouse move) │ │ │ │ │ - * the 'down' and 'up' callbacks will be called, but not the 'done' │ │ │ │ │ - * callback. │ │ │ │ │ - * │ │ │ │ │ - * Create a new drag handler with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ + if (bounds != null) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: started │ │ │ │ │ - * {Boolean} When a mousedown or touchstart event is received, we want to │ │ │ │ │ - * record it, but not set 'dragging' until the mouse moves after starting. │ │ │ │ │ - */ │ │ │ │ │ - started: false, │ │ │ │ │ + // if grid is empty or zoom has changed, we *must* re-tile │ │ │ │ │ + var forceReTile = !this.grid.length || zoomChanged; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: stopDown │ │ │ │ │ - * {Boolean} Stop propagation of mousedown events from getting to listeners │ │ │ │ │ - * on the same element. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - stopDown: true, │ │ │ │ │ + // total bounds of the tiles │ │ │ │ │ + var tilesBounds = this.getTilesBounds(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: dragging │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - dragging: false, │ │ │ │ │ + // the new map resolution │ │ │ │ │ + var resolution = this.map.getResolution(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: last │ │ │ │ │ - * {} The last pixel location of the drag. │ │ │ │ │ - */ │ │ │ │ │ - last: null, │ │ │ │ │ + // the server-supported resolution for the new map resolution │ │ │ │ │ + var serverResolution = this.getServerResolution(resolution); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: start │ │ │ │ │ - * {} The first pixel location of the drag. │ │ │ │ │ - */ │ │ │ │ │ - start: null, │ │ │ │ │ + if (this.singleTile) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: lastMoveEvt │ │ │ │ │ - * {Object} The last mousemove event that occurred. Used to │ │ │ │ │ - * position the map correctly when our "delay drag" │ │ │ │ │ - * timeout expired. │ │ │ │ │ - */ │ │ │ │ │ - lastMoveEvt: null, │ │ │ │ │ + // We want to redraw whenever even the slightest part of the │ │ │ │ │ + // current bounds is not contained by our tile. │ │ │ │ │ + // (thus, we do not specify partial -- its default is false) │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: oldOnselectstart │ │ │ │ │ - * {Function} │ │ │ │ │ - */ │ │ │ │ │ - oldOnselectstart: null, │ │ │ │ │ + if (forceReTile || │ │ │ │ │ + (!dragging && !tilesBounds.containsBounds(bounds))) { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: interval │ │ │ │ │ - * {Integer} In order to increase performance, an interval (in │ │ │ │ │ - * milliseconds) can be set to reduce the number of drag events │ │ │ │ │ - * called. If set, a new drag event will not be set until the │ │ │ │ │ - * interval has passed. │ │ │ │ │ - * Defaults to 0, meaning no interval. │ │ │ │ │ - */ │ │ │ │ │ - interval: 0, │ │ │ │ │ + // In single tile mode with no transition effect, we insert │ │ │ │ │ + // a non-scaled backbuffer when the layer is moved. But if │ │ │ │ │ + // a zoom occurs right after a move, i.e. before the new │ │ │ │ │ + // image is received, we need to remove the backbuffer, or │ │ │ │ │ + // an ill-positioned image will be visible during the zoom │ │ │ │ │ + // transition. │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: timeoutId │ │ │ │ │ - * {String} The id of the timeout used for the mousedown interval. │ │ │ │ │ - * This is "private", and should be left alone. │ │ │ │ │ - */ │ │ │ │ │ - timeoutId: null, │ │ │ │ │ + if (zoomChanged && this.transitionEffect !== 'resize') { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} If set to true, the handler will also handle mouse moves when │ │ │ │ │ - * the cursor has moved out of the map viewport. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ + if (!zoomChanged || this.transitionEffect === 'resize') { │ │ │ │ │ + this.applyBackBuffer(resolution); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: documentEvents │ │ │ │ │ - * {Boolean} Are we currently observing document events? │ │ │ │ │ - */ │ │ │ │ │ - documentEvents: null, │ │ │ │ │ + this.initSingleTile(bounds); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Drag │ │ │ │ │ - * Returns OpenLayers.Handler.Drag │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control that is making use of │ │ │ │ │ - * this handler. If a handler is being used without a control, the │ │ │ │ │ - * handlers setMap method must be overridden to deal properly with │ │ │ │ │ - * the map. │ │ │ │ │ - * callbacks - {Object} An object containing a single function to be │ │ │ │ │ - * called when the drag operation is finished. The callback should │ │ │ │ │ - * expect to recieve a single argument, the pixel location of the event. │ │ │ │ │ - * Callbacks for 'move' and 'done' are supported. You can also speficy │ │ │ │ │ - * callbacks for 'down', 'up', and 'out' to respond to those events. │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ + // if the bounds have changed such that they are not even │ │ │ │ │ + // *partially* contained by our tiles (e.g. when user has │ │ │ │ │ + // programmatically panned to the other side of the earth on │ │ │ │ │ + // zoom level 18), then moveGriddedTiles could potentially have │ │ │ │ │ + // to run through thousands of cycles, so we want to reTile │ │ │ │ │ + // instead (thus, partial true). │ │ │ │ │ + forceReTile = forceReTile || │ │ │ │ │ + !tilesBounds.intersectsBounds(bounds, { │ │ │ │ │ + worldBounds: this.map.baseLayer.wrapDateLine && │ │ │ │ │ + this.map.getMaxExtent() │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - if (this.documentDrag === true) { │ │ │ │ │ - var me = this; │ │ │ │ │ - this._docMove = function(evt) { │ │ │ │ │ - me.mousemove({ │ │ │ │ │ - xy: { │ │ │ │ │ - x: evt.clientX, │ │ │ │ │ - y: evt.clientY │ │ │ │ │ - }, │ │ │ │ │ - element: document │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ - this._docUp = function(evt) { │ │ │ │ │ - me.mouseup({ │ │ │ │ │ - xy: { │ │ │ │ │ - x: evt.clientX, │ │ │ │ │ - y: evt.clientY │ │ │ │ │ + if (forceReTile) { │ │ │ │ │ + if (zoomChanged && (this.transitionEffect === 'resize' || │ │ │ │ │ + this.gridResolution === resolution)) { │ │ │ │ │ + this.applyBackBuffer(resolution); │ │ │ │ │ } │ │ │ │ │ - }); │ │ │ │ │ - }; │ │ │ │ │ + this.initGriddedTiles(bounds); │ │ │ │ │ + } else { │ │ │ │ │ + this.moveGriddedTiles(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: dragstart │ │ │ │ │ - * This private method is factorized from mousedown and touchstart methods │ │ │ │ │ + * Method: getTileData │ │ │ │ │ + * Given a map location, retrieve a tile and the pixel offset within that │ │ │ │ │ + * tile corresponding to the location. If there is not an existing │ │ │ │ │ + * tile in the grid that covers the given location, null will be │ │ │ │ │ + * returned. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ + * loc - {} map location │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {Object} Object with the following properties: tile ({}), │ │ │ │ │ + * i ({Number} x-pixel offset from top left), and j ({Integer} y-pixel │ │ │ │ │ + * offset from top left). │ │ │ │ │ */ │ │ │ │ │ - dragstart: function(evt) { │ │ │ │ │ - var propagate = true; │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - if (this.checkModifiers(evt) && │ │ │ │ │ - (OpenLayers.Event.isLeftClick(evt) || │ │ │ │ │ - OpenLayers.Event.isSingleTouch(evt))) { │ │ │ │ │ - this.started = true; │ │ │ │ │ - this.start = evt.xy; │ │ │ │ │ - this.last = evt.xy; │ │ │ │ │ - OpenLayers.Element.addClass( │ │ │ │ │ - this.map.viewPortDiv, "olDragDown" │ │ │ │ │ - ); │ │ │ │ │ - this.down(evt); │ │ │ │ │ - this.callback("down", [evt.xy]); │ │ │ │ │ + getTileData: function(loc) { │ │ │ │ │ + var data = null, │ │ │ │ │ + x = loc.lon, │ │ │ │ │ + y = loc.lat, │ │ │ │ │ + numRows = this.grid.length; │ │ │ │ │ │ │ │ │ │ - // prevent document dragging │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ + if (this.map && numRows) { │ │ │ │ │ + var res = this.map.getResolution(), │ │ │ │ │ + tileWidth = this.tileSize.w, │ │ │ │ │ + tileHeight = this.tileSize.h, │ │ │ │ │ + bounds = this.grid[0][0].bounds, │ │ │ │ │ + left = bounds.left, │ │ │ │ │ + top = bounds.top; │ │ │ │ │ │ │ │ │ │ - if (!this.oldOnselectstart) { │ │ │ │ │ - this.oldOnselectstart = document.onselectstart ? │ │ │ │ │ - document.onselectstart : OpenLayers.Function.True; │ │ │ │ │ + if (x < left) { │ │ │ │ │ + // deal with multiple worlds │ │ │ │ │ + if (this.map.baseLayer.wrapDateLine) { │ │ │ │ │ + var worldWidth = this.map.getMaxExtent().getWidth(); │ │ │ │ │ + var worldsAway = Math.ceil((left - x) / worldWidth); │ │ │ │ │ + x += worldWidth * worldsAway; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // tile distance to location (fractional number of tiles); │ │ │ │ │ + var dtx = (x - left) / (res * tileWidth); │ │ │ │ │ + var dty = (top - y) / (res * tileHeight); │ │ │ │ │ + // index of tile in grid │ │ │ │ │ + var col = Math.floor(dtx); │ │ │ │ │ + var row = Math.floor(dty); │ │ │ │ │ + if (row >= 0 && row < numRows) { │ │ │ │ │ + var tile = this.grid[row][col]; │ │ │ │ │ + if (tile) { │ │ │ │ │ + data = { │ │ │ │ │ + tile: tile, │ │ │ │ │ + // pixel index within tile │ │ │ │ │ + i: Math.floor((dtx - col) * tileWidth), │ │ │ │ │ + j: Math.floor((dty - row) * tileHeight) │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - document.onselectstart = OpenLayers.Function.False; │ │ │ │ │ - │ │ │ │ │ - propagate = !this.stopDown; │ │ │ │ │ - } else { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ } │ │ │ │ │ - return propagate; │ │ │ │ │ + return data; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragmove │ │ │ │ │ - * This private method is factorized from mousemove and touchmove methods │ │ │ │ │ + * Method: destroyTile │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * tile - {} │ │ │ │ │ */ │ │ │ │ │ - dragmove: function(evt) { │ │ │ │ │ - this.lastMoveEvt = evt; │ │ │ │ │ - if (this.started && !this.timeoutId && (evt.xy.x != this.last.x || │ │ │ │ │ - evt.xy.y != this.last.y)) { │ │ │ │ │ - if (this.documentDrag === true && this.documentEvents) { │ │ │ │ │ - if (evt.element === document) { │ │ │ │ │ - this.adjustXY(evt); │ │ │ │ │ - // do setEvent manually because the documentEvents are not │ │ │ │ │ - // registered with the map │ │ │ │ │ - this.setEvent(evt); │ │ │ │ │ - } else { │ │ │ │ │ - this.removeDocumentEvents(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.interval > 0) { │ │ │ │ │ - this.timeoutId = setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(this.removeTimeout, this), │ │ │ │ │ - this.interval); │ │ │ │ │ - } │ │ │ │ │ - this.dragging = true; │ │ │ │ │ - │ │ │ │ │ - this.move(evt); │ │ │ │ │ - this.callback("move", [evt.xy]); │ │ │ │ │ - if (!this.oldOnselectstart) { │ │ │ │ │ - this.oldOnselectstart = document.onselectstart; │ │ │ │ │ - document.onselectstart = OpenLayers.Function.False; │ │ │ │ │ - } │ │ │ │ │ - this.last = evt.xy; │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ + destroyTile: function(tile) { │ │ │ │ │ + this.removeTileMonitoringHooks(tile); │ │ │ │ │ + tile.destroy(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragend │ │ │ │ │ - * This private method is factorized from mouseup and touchend methods │ │ │ │ │ + * Method: getServerResolution │ │ │ │ │ + * Return the closest server-supported resolution. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The event │ │ │ │ │ + * resolution - {Number} The base resolution. If undefined the │ │ │ │ │ + * map resolution is used. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {Number} The closest server resolution value. │ │ │ │ │ */ │ │ │ │ │ - dragend: function(evt) { │ │ │ │ │ - if (this.started) { │ │ │ │ │ - if (this.documentDrag === true && this.documentEvents) { │ │ │ │ │ - this.adjustXY(evt); │ │ │ │ │ - this.removeDocumentEvents(); │ │ │ │ │ - } │ │ │ │ │ - var dragged = (this.start != this.last); │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, "olDragDown" │ │ │ │ │ - ); │ │ │ │ │ - this.up(evt); │ │ │ │ │ - this.callback("up", [evt.xy]); │ │ │ │ │ - if (dragged) { │ │ │ │ │ - this.callback("done", [evt.xy]); │ │ │ │ │ + getServerResolution: function(resolution) { │ │ │ │ │ + var distance = Number.POSITIVE_INFINITY; │ │ │ │ │ + resolution = resolution || this.map.getResolution(); │ │ │ │ │ + if (this.serverResolutions && │ │ │ │ │ + OpenLayers.Util.indexOf(this.serverResolutions, resolution) === -1) { │ │ │ │ │ + var i, newDistance, newResolution, serverResolution; │ │ │ │ │ + for (i = this.serverResolutions.length - 1; i >= 0; i--) { │ │ │ │ │ + newResolution = this.serverResolutions[i]; │ │ │ │ │ + newDistance = Math.abs(newResolution - resolution); │ │ │ │ │ + if (newDistance > distance) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + distance = newDistance; │ │ │ │ │ + serverResolution = newResolution; │ │ │ │ │ } │ │ │ │ │ - document.onselectstart = this.oldOnselectstart; │ │ │ │ │ + resolution = serverResolution; │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ + return resolution; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * The four methods below (down, move, up, and out) are used by subclasses │ │ │ │ │ - * to do their own processing related to these mouse events. │ │ │ │ │ + * Method: getServerZoom │ │ │ │ │ + * Return the zoom value corresponding to the best matching server │ │ │ │ │ + * resolution, taking into account and . │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} The closest server supported zoom. This is not the map zoom │ │ │ │ │ + * level, but an index of the server's resolutions array. │ │ │ │ │ */ │ │ │ │ │ + getServerZoom: function() { │ │ │ │ │ + var resolution = this.getServerResolution(); │ │ │ │ │ + return this.serverResolutions ? │ │ │ │ │ + OpenLayers.Util.indexOf(this.serverResolutions, resolution) : │ │ │ │ │ + this.map.getZoomForResolution(resolution) + (this.zoomOffset || 0); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: down │ │ │ │ │ - * This method is called during the handling of the mouse down event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ + * Method: applyBackBuffer │ │ │ │ │ + * Create, insert, scale and position a back buffer for the layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The mouse down event │ │ │ │ │ + * resolution - {Number} The resolution to transition to. │ │ │ │ │ */ │ │ │ │ │ - down: function(evt) {}, │ │ │ │ │ + applyBackBuffer: function(resolution) { │ │ │ │ │ + if (this.backBufferTimerId !== null) { │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + } │ │ │ │ │ + var backBuffer = this.backBuffer; │ │ │ │ │ + if (!backBuffer) { │ │ │ │ │ + backBuffer = this.createBackBuffer(); │ │ │ │ │ + if (!backBuffer) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + if (resolution === this.gridResolution) { │ │ │ │ │ + this.div.insertBefore(backBuffer, this.div.firstChild); │ │ │ │ │ + } else { │ │ │ │ │ + this.map.baseLayer.div.parentNode.insertBefore(backBuffer, this.map.baseLayer.div); │ │ │ │ │ + } │ │ │ │ │ + this.backBuffer = backBuffer; │ │ │ │ │ + │ │ │ │ │ + // set some information in the instance for subsequent │ │ │ │ │ + // calls to applyBackBuffer where the same back buffer │ │ │ │ │ + // is reused │ │ │ │ │ + var topLeftTileBounds = this.grid[0][0].bounds; │ │ │ │ │ + this.backBufferLonLat = { │ │ │ │ │ + lon: topLeftTileBounds.left, │ │ │ │ │ + lat: topLeftTileBounds.top │ │ │ │ │ + }; │ │ │ │ │ + this.backBufferResolution = this.gridResolution; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var ratio = this.backBufferResolution / resolution; │ │ │ │ │ + │ │ │ │ │ + // scale the tiles inside the back buffer │ │ │ │ │ + var tiles = backBuffer.childNodes, │ │ │ │ │ + tile; │ │ │ │ │ + for (var i = tiles.length - 1; i >= 0; --i) { │ │ │ │ │ + tile = tiles[i]; │ │ │ │ │ + tile.style.top = ((ratio * tile._i * tile._h) | 0) + 'px'; │ │ │ │ │ + tile.style.left = ((ratio * tile._j * tile._w) | 0) + 'px'; │ │ │ │ │ + tile.style.width = Math.round(ratio * tile._w) + 'px'; │ │ │ │ │ + tile.style.height = Math.round(ratio * tile._h) + 'px'; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // and position it (based on the grid's top-left corner) │ │ │ │ │ + var position = this.getViewPortPxFromLonLat( │ │ │ │ │ + this.backBufferLonLat, resolution); │ │ │ │ │ + var leftOffset = this.map.layerContainerOriginPx.x; │ │ │ │ │ + var topOffset = this.map.layerContainerOriginPx.y; │ │ │ │ │ + backBuffer.style.left = Math.round(position.x - leftOffset) + 'px'; │ │ │ │ │ + backBuffer.style.top = Math.round(position.y - topOffset) + 'px'; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * This method is called during the handling of the mouse move event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The mouse move event │ │ │ │ │ + * Method: createBackBuffer │ │ │ │ │ + * Create a back buffer. │ │ │ │ │ * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The DOM element for the back buffer, undefined if the │ │ │ │ │ + * grid isn't initialized yet. │ │ │ │ │ */ │ │ │ │ │ - move: function(evt) {}, │ │ │ │ │ + createBackBuffer: function() { │ │ │ │ │ + var backBuffer; │ │ │ │ │ + if (this.grid.length > 0) { │ │ │ │ │ + backBuffer = document.createElement('div'); │ │ │ │ │ + backBuffer.id = this.div.id + '_bb'; │ │ │ │ │ + backBuffer.className = 'olBackBuffer'; │ │ │ │ │ + backBuffer.style.position = 'absolute'; │ │ │ │ │ + var map = this.map; │ │ │ │ │ + backBuffer.style.zIndex = this.transitionEffect === 'resize' ? │ │ │ │ │ + this.getZIndex() - 1 : │ │ │ │ │ + // 'map-resize': │ │ │ │ │ + map.Z_INDEX_BASE.BaseLayer - │ │ │ │ │ + (map.getNumLayers() - map.getLayerIndex(this)); │ │ │ │ │ + for (var i = 0, lenI = this.grid.length; i < lenI; i++) { │ │ │ │ │ + for (var j = 0, lenJ = this.grid[i].length; j < lenJ; j++) { │ │ │ │ │ + var tile = this.grid[i][j], │ │ │ │ │ + markup = this.grid[i][j].createBackBuffer(); │ │ │ │ │ + if (markup) { │ │ │ │ │ + markup._i = i; │ │ │ │ │ + markup._j = j; │ │ │ │ │ + markup._w = tile.size.w; │ │ │ │ │ + markup._h = tile.size.h; │ │ │ │ │ + markup.id = tile.id + '_bb'; │ │ │ │ │ + backBuffer.appendChild(markup); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return backBuffer; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: up │ │ │ │ │ - * This method is called during the handling of the mouse up event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The mouse up event │ │ │ │ │ + * Method: removeBackBuffer │ │ │ │ │ + * Remove back buffer from DOM. │ │ │ │ │ */ │ │ │ │ │ - up: function(evt) {}, │ │ │ │ │ + removeBackBuffer: function() { │ │ │ │ │ + if (this._transitionElement) { │ │ │ │ │ + for (var i = this.transitionendEvents.length - 1; i >= 0; --i) { │ │ │ │ │ + OpenLayers.Event.stopObserving(this._transitionElement, │ │ │ │ │ + this.transitionendEvents[i], this._removeBackBuffer); │ │ │ │ │ + } │ │ │ │ │ + delete this._transitionElement; │ │ │ │ │ + } │ │ │ │ │ + if (this.backBuffer) { │ │ │ │ │ + if (this.backBuffer.parentNode) { │ │ │ │ │ + this.backBuffer.parentNode.removeChild(this.backBuffer); │ │ │ │ │ + } │ │ │ │ │ + this.backBuffer = null; │ │ │ │ │ + this.backBufferResolution = null; │ │ │ │ │ + if (this.backBufferTimerId !== null) { │ │ │ │ │ + window.clearTimeout(this.backBufferTimerId); │ │ │ │ │ + this.backBufferTimerId = null; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: out │ │ │ │ │ - * This method is called during the handling of the mouse out event. │ │ │ │ │ - * Subclasses can do their own processing here. │ │ │ │ │ + * Method: moveByPx │ │ │ │ │ + * Move the layer based on pixel vector. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The mouse out event │ │ │ │ │ + * dx - {Number} │ │ │ │ │ + * dy - {Number} │ │ │ │ │ */ │ │ │ │ │ - out: function(evt) {}, │ │ │ │ │ + moveByPx: function(dx, dy) { │ │ │ │ │ + if (!this.singleTile) { │ │ │ │ │ + this.moveGriddedTiles(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * The methods below are part of the magic of event handling. Because │ │ │ │ │ - * they are named like browser events, they are registered as listeners │ │ │ │ │ - * for the events they represent. │ │ │ │ │ + * APIMethod: setTileSize │ │ │ │ │ + * Check if we are in singleTile mode and if so, set the size as a ratio │ │ │ │ │ + * of the map size (as specified by the layer's 'ratio' property). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * size - {} │ │ │ │ │ */ │ │ │ │ │ + setTileSize: function(size) { │ │ │ │ │ + if (this.singleTile) { │ │ │ │ │ + size = this.map.getSize(); │ │ │ │ │ + size.h = parseInt(size.h * this.ratio, 10); │ │ │ │ │ + size.w = parseInt(size.w * this.ratio, 10); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Layer.HTTPRequest.prototype.setTileSize.apply(this, [size]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousedown │ │ │ │ │ - * Handle mousedown events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * APIMethod: getTilesBounds │ │ │ │ │ + * Return the bounds of the tile grid. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {} A Bounds object representing the bounds of all the │ │ │ │ │ + * currently loaded tiles (including those partially or not at all seen │ │ │ │ │ + * onscreen). │ │ │ │ │ */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - return this.dragstart(evt); │ │ │ │ │ + getTilesBounds: function() { │ │ │ │ │ + var bounds = null; │ │ │ │ │ + │ │ │ │ │ + var length = this.grid.length; │ │ │ │ │ + if (length) { │ │ │ │ │ + var bottomLeftTileBounds = this.grid[length - 1][0].bounds, │ │ │ │ │ + width = this.grid[0].length * bottomLeftTileBounds.getWidth(), │ │ │ │ │ + height = this.grid.length * bottomLeftTileBounds.getHeight(); │ │ │ │ │ + │ │ │ │ │ + bounds = new OpenLayers.Bounds(bottomLeftTileBounds.left, │ │ │ │ │ + bottomLeftTileBounds.bottom, │ │ │ │ │ + bottomLeftTileBounds.left + width, │ │ │ │ │ + bottomLeftTileBounds.bottom + height); │ │ │ │ │ + } │ │ │ │ │ + return bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart events │ │ │ │ │ + * Method: initSingleTile │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ + */ │ │ │ │ │ + initSingleTile: function(bounds) { │ │ │ │ │ + this.events.triggerEvent("retile"); │ │ │ │ │ + │ │ │ │ │ + //determine new tile bounds │ │ │ │ │ + var center = bounds.getCenterLonLat(); │ │ │ │ │ + var tileWidth = bounds.getWidth() * this.ratio; │ │ │ │ │ + var tileHeight = bounds.getHeight() * this.ratio; │ │ │ │ │ + │ │ │ │ │ + var tileBounds = │ │ │ │ │ + new OpenLayers.Bounds(center.lon - (tileWidth / 2), │ │ │ │ │ + center.lat - (tileHeight / 2), │ │ │ │ │ + center.lon + (tileWidth / 2), │ │ │ │ │ + center.lat + (tileHeight / 2)); │ │ │ │ │ + │ │ │ │ │ + var px = this.map.getLayerPxFromLonLat({ │ │ │ │ │ + lon: tileBounds.left, │ │ │ │ │ + lat: tileBounds.top │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + if (!this.grid.length) { │ │ │ │ │ + this.grid[0] = []; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var tile = this.grid[0][0]; │ │ │ │ │ + if (!tile) { │ │ │ │ │ + tile = this.addTile(tileBounds, px); │ │ │ │ │ + │ │ │ │ │ + this.addTileMonitoringHooks(tile); │ │ │ │ │ + tile.draw(); │ │ │ │ │ + this.grid[0][0] = tile; │ │ │ │ │ + } else { │ │ │ │ │ + tile.moveTo(tileBounds, px); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + //remove all but our single tile │ │ │ │ │ + this.removeExcessTiles(1, 1); │ │ │ │ │ + │ │ │ │ │ + // store the resolution of the grid │ │ │ │ │ + this.gridResolution = this.getServerResolution(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: calculateGridLayout │ │ │ │ │ + * Generate parameters for the grid layout. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * bounds - {|Object} OpenLayers.Bounds or an │ │ │ │ │ + * object with a 'left' and 'top' properties. │ │ │ │ │ + * origin - {|Object} OpenLayers.LonLat or an │ │ │ │ │ + * object with a 'lon' and 'lat' properties. │ │ │ │ │ + * resolution - {Number} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {Object} Object containing properties tilelon, tilelat, startcol, │ │ │ │ │ + * startrow │ │ │ │ │ */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - return this.dragstart(evt); │ │ │ │ │ + calculateGridLayout: function(bounds, origin, resolution) { │ │ │ │ │ + var tilelon = resolution * this.tileSize.w; │ │ │ │ │ + var tilelat = resolution * this.tileSize.h; │ │ │ │ │ + │ │ │ │ │ + var offsetlon = bounds.left - origin.lon; │ │ │ │ │ + var tilecol = Math.floor(offsetlon / tilelon) - this.buffer; │ │ │ │ │ + │ │ │ │ │ + var rowSign = this.rowSign; │ │ │ │ │ + │ │ │ │ │ + var offsetlat = rowSign * (origin.lat - bounds.top + tilelat); │ │ │ │ │ + var tilerow = Math[~rowSign ? 'floor' : 'ceil'](offsetlat / tilelat) - this.buffer * rowSign; │ │ │ │ │ + │ │ │ │ │ + return { │ │ │ │ │ + tilelon: tilelon, │ │ │ │ │ + tilelat: tilelat, │ │ │ │ │ + startcol: tilecol, │ │ │ │ │ + startrow: tilerow │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousemove │ │ │ │ │ - * Handle mousemove events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Method: getTileOrigin │ │ │ │ │ + * Determine the origin for aligning the grid of tiles. If a │ │ │ │ │ + * property is supplied, that will be returned. Otherwise, the origin │ │ │ │ │ + * will be derived from the layer's property. In this case, │ │ │ │ │ + * the tile origin will be the corner of the given by the │ │ │ │ │ + * property. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {} The tile origin. │ │ │ │ │ */ │ │ │ │ │ - mousemove: function(evt) { │ │ │ │ │ - return this.dragmove(evt); │ │ │ │ │ + getTileOrigin: function() { │ │ │ │ │ + var origin = this.tileOrigin; │ │ │ │ │ + if (!origin) { │ │ │ │ │ + var extent = this.getMaxExtent(); │ │ │ │ │ + var edges = ({ │ │ │ │ │ + "tl": ["left", "top"], │ │ │ │ │ + "tr": ["right", "top"], │ │ │ │ │ + "bl": ["left", "bottom"], │ │ │ │ │ + "br": ["right", "bottom"] │ │ │ │ │ + })[this.tileOriginCorner]; │ │ │ │ │ + origin = new OpenLayers.LonLat(extent[edges[0]], extent[edges[1]]); │ │ │ │ │ + } │ │ │ │ │ + return origin; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Handle touchmove events │ │ │ │ │ + * Method: getTileBoundsForGridIndex │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * row - {Number} The row of the grid │ │ │ │ │ + * col - {Number} The column of the grid │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {} The bounds for the tile at (row, col) │ │ │ │ │ */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - return this.dragmove(evt); │ │ │ │ │ + getTileBoundsForGridIndex: function(row, col) { │ │ │ │ │ + var origin = this.getTileOrigin(); │ │ │ │ │ + var tileLayout = this.gridLayout; │ │ │ │ │ + var tilelon = tileLayout.tilelon; │ │ │ │ │ + var tilelat = tileLayout.tilelat; │ │ │ │ │ + var startcol = tileLayout.startcol; │ │ │ │ │ + var startrow = tileLayout.startrow; │ │ │ │ │ + var rowSign = this.rowSign; │ │ │ │ │ + return new OpenLayers.Bounds( │ │ │ │ │ + origin.lon + (startcol + col) * tilelon, │ │ │ │ │ + origin.lat - (startrow + row * rowSign) * tilelat * rowSign, │ │ │ │ │ + origin.lon + (startcol + col + 1) * tilelon, │ │ │ │ │ + origin.lat - (startrow + (row - 1) * rowSign) * tilelat * rowSign │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeTimeout │ │ │ │ │ - * Private. Called by mousemove() to remove the drag timeout. │ │ │ │ │ + * Method: initGriddedTiles │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} │ │ │ │ │ */ │ │ │ │ │ - removeTimeout: function() { │ │ │ │ │ - this.timeoutId = null; │ │ │ │ │ - // if timeout expires while we're still dragging (mouseup │ │ │ │ │ - // hasn't occurred) then call mousemove to move to the │ │ │ │ │ - // correct position │ │ │ │ │ - if (this.dragging) { │ │ │ │ │ - this.mousemove(this.lastMoveEvt); │ │ │ │ │ + initGriddedTiles: function(bounds) { │ │ │ │ │ + this.events.triggerEvent("retile"); │ │ │ │ │ + │ │ │ │ │ + // work out mininum number of rows and columns; this is the number of │ │ │ │ │ + // tiles required to cover the viewport plus at least one for panning │ │ │ │ │ + │ │ │ │ │ + var viewSize = this.map.getSize(); │ │ │ │ │ + │ │ │ │ │ + var origin = this.getTileOrigin(); │ │ │ │ │ + var resolution = this.map.getResolution(), │ │ │ │ │ + serverResolution = this.getServerResolution(), │ │ │ │ │ + ratio = resolution / serverResolution, │ │ │ │ │ + tileSize = { │ │ │ │ │ + w: this.tileSize.w / ratio, │ │ │ │ │ + h: this.tileSize.h / ratio │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + var minRows = Math.ceil(viewSize.h / tileSize.h) + │ │ │ │ │ + 2 * this.buffer + 1; │ │ │ │ │ + var minCols = Math.ceil(viewSize.w / tileSize.w) + │ │ │ │ │ + 2 * this.buffer + 1; │ │ │ │ │ + │ │ │ │ │ + var tileLayout = this.calculateGridLayout(bounds, origin, serverResolution); │ │ │ │ │ + this.gridLayout = tileLayout; │ │ │ │ │ + │ │ │ │ │ + var tilelon = tileLayout.tilelon; │ │ │ │ │ + var tilelat = tileLayout.tilelat; │ │ │ │ │ + │ │ │ │ │ + var layerContainerDivLeft = this.map.layerContainerOriginPx.x; │ │ │ │ │ + var layerContainerDivTop = this.map.layerContainerOriginPx.y; │ │ │ │ │ + │ │ │ │ │ + var tileBounds = this.getTileBoundsForGridIndex(0, 0); │ │ │ │ │ + var startPx = this.map.getViewPortPxFromLonLat( │ │ │ │ │ + new OpenLayers.LonLat(tileBounds.left, tileBounds.top) │ │ │ │ │ + ); │ │ │ │ │ + startPx.x = Math.round(startPx.x) - layerContainerDivLeft; │ │ │ │ │ + startPx.y = Math.round(startPx.y) - layerContainerDivTop; │ │ │ │ │ + │ │ │ │ │ + var tileData = [], │ │ │ │ │ + center = this.map.getCenter(); │ │ │ │ │ + │ │ │ │ │ + var rowidx = 0; │ │ │ │ │ + do { │ │ │ │ │ + var row = this.grid[rowidx]; │ │ │ │ │ + if (!row) { │ │ │ │ │ + row = []; │ │ │ │ │ + this.grid.push(row); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var colidx = 0; │ │ │ │ │ + do { │ │ │ │ │ + tileBounds = this.getTileBoundsForGridIndex(rowidx, colidx); │ │ │ │ │ + var px = startPx.clone(); │ │ │ │ │ + px.x = px.x + colidx * Math.round(tileSize.w); │ │ │ │ │ + px.y = px.y + rowidx * Math.round(tileSize.h); │ │ │ │ │ + var tile = row[colidx]; │ │ │ │ │ + if (!tile) { │ │ │ │ │ + tile = this.addTile(tileBounds, px); │ │ │ │ │ + this.addTileMonitoringHooks(tile); │ │ │ │ │ + row.push(tile); │ │ │ │ │ + } else { │ │ │ │ │ + tile.moveTo(tileBounds, px, false); │ │ │ │ │ + } │ │ │ │ │ + var tileCenter = tileBounds.getCenterLonLat(); │ │ │ │ │ + tileData.push({ │ │ │ │ │ + tile: tile, │ │ │ │ │ + distance: Math.pow(tileCenter.lon - center.lon, 2) + │ │ │ │ │ + Math.pow(tileCenter.lat - center.lat, 2) │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + colidx += 1; │ │ │ │ │ + } while ((tileBounds.right <= bounds.right + tilelon * this.buffer) || │ │ │ │ │ + colidx < minCols); │ │ │ │ │ + │ │ │ │ │ + rowidx += 1; │ │ │ │ │ + } while ((tileBounds.bottom >= bounds.bottom - tilelat * this.buffer) || │ │ │ │ │ + rowidx < minRows); │ │ │ │ │ + │ │ │ │ │ + //shave off exceess rows and colums │ │ │ │ │ + this.removeExcessTiles(rowidx, colidx); │ │ │ │ │ + │ │ │ │ │ + var resolution = this.getServerResolution(); │ │ │ │ │ + // store the resolution of the grid │ │ │ │ │ + this.gridResolution = resolution; │ │ │ │ │ + │ │ │ │ │ + //now actually draw the tiles │ │ │ │ │ + tileData.sort(function(a, b) { │ │ │ │ │ + return a.distance - b.distance; │ │ │ │ │ + }); │ │ │ │ │ + for (var i = 0, ii = tileData.length; i < ii; ++i) { │ │ │ │ │ + tileData[i].tile.draw(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mouseup │ │ │ │ │ - * Handle mouseup events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Method: getMaxExtent │ │ │ │ │ + * Get this layer's maximum extent. (Implemented as a getter for │ │ │ │ │ + * potential specific implementations in sub-classes.) │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - return this.dragend(evt); │ │ │ │ │ + getMaxExtent: function() { │ │ │ │ │ + return this.maxExtent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Handle touchend events │ │ │ │ │ + * APIMethod: addTile │ │ │ │ │ + * Create a tile, initialize it, and add it to the layer div. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Parameters │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * position - {} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * {} The added OpenLayers.Tile │ │ │ │ │ */ │ │ │ │ │ - touchend: function(evt) { │ │ │ │ │ - // override evt.xy with last position since touchend does not have │ │ │ │ │ - // any touch position │ │ │ │ │ - evt.xy = this.last; │ │ │ │ │ - return this.dragend(evt); │ │ │ │ │ + addTile: function(bounds, position) { │ │ │ │ │ + var tile = new this.tileClass( │ │ │ │ │ + this, position, bounds, null, this.tileSize, this.tileOptions │ │ │ │ │ + ); │ │ │ │ │ + this.events.triggerEvent("addtile", { │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + return tile; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: mouseout │ │ │ │ │ - * Handle mouseout events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + /** │ │ │ │ │ + * Method: addTileMonitoringHooks │ │ │ │ │ + * This function takes a tile as input and adds the appropriate hooks to │ │ │ │ │ + * the tile so that the layer can keep track of the loading tiles. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * tile - {} │ │ │ │ │ */ │ │ │ │ │ - mouseout: function(evt) { │ │ │ │ │ - if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ - if (this.documentDrag === true) { │ │ │ │ │ - this.addDocumentEvents(); │ │ │ │ │ - } else { │ │ │ │ │ - var dragged = (this.start != this.last); │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, "olDragDown" │ │ │ │ │ - ); │ │ │ │ │ - this.out(evt); │ │ │ │ │ - this.callback("out", []); │ │ │ │ │ - if (dragged) { │ │ │ │ │ - this.callback("done", [evt.xy]); │ │ │ │ │ + addTileMonitoringHooks: function(tile) { │ │ │ │ │ + │ │ │ │ │ + var replacingCls = 'olTileReplacing'; │ │ │ │ │ + │ │ │ │ │ + tile.onLoadStart = function() { │ │ │ │ │ + //if that was first tile then trigger a 'loadstart' on the layer │ │ │ │ │ + if (this.loading === false) { │ │ │ │ │ + this.loading = true; │ │ │ │ │ + this.events.triggerEvent("loadstart"); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("tileloadstart", { │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + this.numLoadingTiles++; │ │ │ │ │ + if (!this.singleTile && this.backBuffer && this.gridResolution === this.backBufferResolution) { │ │ │ │ │ + OpenLayers.Element.addClass(tile.getTile(), replacingCls); │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + tile.onLoadEnd = function(evt) { │ │ │ │ │ + this.numLoadingTiles--; │ │ │ │ │ + var aborted = evt.type === 'unload'; │ │ │ │ │ + this.events.triggerEvent("tileloaded", { │ │ │ │ │ + tile: tile, │ │ │ │ │ + aborted: aborted │ │ │ │ │ + }); │ │ │ │ │ + if (!this.singleTile && !aborted && this.backBuffer && this.gridResolution === this.backBufferResolution) { │ │ │ │ │ + var tileDiv = tile.getTile(); │ │ │ │ │ + if (OpenLayers.Element.getStyle(tileDiv, 'display') === 'none') { │ │ │ │ │ + var bufferTile = document.getElementById(tile.id + '_bb'); │ │ │ │ │ + if (bufferTile) { │ │ │ │ │ + bufferTile.parentNode.removeChild(bufferTile); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - if (document.onselectstart) { │ │ │ │ │ - document.onselectstart = this.oldOnselectstart; │ │ │ │ │ + OpenLayers.Element.removeClass(tileDiv, replacingCls); │ │ │ │ │ + } │ │ │ │ │ + //if that was the last tile, then trigger a 'loadend' on the layer │ │ │ │ │ + if (this.numLoadingTiles === 0) { │ │ │ │ │ + if (this.backBuffer) { │ │ │ │ │ + if (this.backBuffer.childNodes.length === 0) { │ │ │ │ │ + // no tiles transitioning, remove immediately │ │ │ │ │ + this.removeBackBuffer(); │ │ │ │ │ + } else { │ │ │ │ │ + // wait until transition has ended or delay has passed │ │ │ │ │ + this._transitionElement = aborted ? │ │ │ │ │ + this.div.lastChild : tile.imgDiv; │ │ │ │ │ + var transitionendEvents = this.transitionendEvents; │ │ │ │ │ + for (var i = transitionendEvents.length - 1; i >= 0; --i) { │ │ │ │ │ + OpenLayers.Event.observe(this._transitionElement, │ │ │ │ │ + transitionendEvents[i], │ │ │ │ │ + this._removeBackBuffer); │ │ │ │ │ + } │ │ │ │ │ + // the removal of the back buffer is delayed to prevent │ │ │ │ │ + // flash effects due to the animation of tile displaying │ │ │ │ │ + this.backBufferTimerId = window.setTimeout( │ │ │ │ │ + this._removeBackBuffer, this.removeBackBufferDelay │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + this.loading = false; │ │ │ │ │ + this.events.triggerEvent("loadend"); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + tile.onLoadError = function() { │ │ │ │ │ + this.events.triggerEvent("tileerror", { │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + tile.events.on({ │ │ │ │ │ + "loadstart": tile.onLoadStart, │ │ │ │ │ + "loadend": tile.onLoadEnd, │ │ │ │ │ + "unload": tile.onLoadEnd, │ │ │ │ │ + "loaderror": tile.onLoadError, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: click │ │ │ │ │ - * The drag handler captures the click event. If something else registers │ │ │ │ │ - * for clicks on the same element, its listener will not be called │ │ │ │ │ - * after a drag. │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeTileMonitoringHooks │ │ │ │ │ + * This function takes a tile as input and removes the tile hooks │ │ │ │ │ + * that were added in addTileMonitoringHooks() │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ + * tile - {} │ │ │ │ │ */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - // let the click event propagate only if the mouse moved │ │ │ │ │ - return (this.start == this.last); │ │ │ │ │ + removeTileMonitoringHooks: function(tile) { │ │ │ │ │ + tile.unload(); │ │ │ │ │ + tile.events.un({ │ │ │ │ │ + "loadstart": tile.onLoadStart, │ │ │ │ │ + "loadend": tile.onLoadEnd, │ │ │ │ │ + "unload": tile.onLoadEnd, │ │ │ │ │ + "loaderror": tile.onLoadError, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully activated. │ │ │ │ │ + * Method: moveGriddedTiles │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - activated = true; │ │ │ │ │ + moveGriddedTiles: function() { │ │ │ │ │ + var buffer = this.buffer + 1; │ │ │ │ │ + while (true) { │ │ │ │ │ + var tlTile = this.grid[0][0]; │ │ │ │ │ + var tlViewPort = { │ │ │ │ │ + x: tlTile.position.x + │ │ │ │ │ + this.map.layerContainerOriginPx.x, │ │ │ │ │ + y: tlTile.position.y + │ │ │ │ │ + this.map.layerContainerOriginPx.y │ │ │ │ │ + }; │ │ │ │ │ + var ratio = this.getServerResolution() / this.map.getResolution(); │ │ │ │ │ + var tileSize = { │ │ │ │ │ + w: Math.round(this.tileSize.w * ratio), │ │ │ │ │ + h: Math.round(this.tileSize.h * ratio) │ │ │ │ │ + }; │ │ │ │ │ + if (tlViewPort.x > -tileSize.w * (buffer - 1)) { │ │ │ │ │ + this.shiftColumn(true, tileSize); │ │ │ │ │ + } else if (tlViewPort.x < -tileSize.w * buffer) { │ │ │ │ │ + this.shiftColumn(false, tileSize); │ │ │ │ │ + } else if (tlViewPort.y > -tileSize.h * (buffer - 1)) { │ │ │ │ │ + this.shiftRow(true, tileSize); │ │ │ │ │ + } else if (tlViewPort.y < -tileSize.h * buffer) { │ │ │ │ │ + this.shiftRow(false, tileSize); │ │ │ │ │ + } else { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + * Method: shiftRow │ │ │ │ │ + * Shifty grid work │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * prepend - {Boolean} if true, prepend to beginning. │ │ │ │ │ + * if false, then append to end │ │ │ │ │ + * tileSize - {Object} rendered tile size; object with w and h properties │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.dragging = false; │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ - deactivated = true; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, "olDragDown" │ │ │ │ │ - ); │ │ │ │ │ + shiftRow: function(prepend, tileSize) { │ │ │ │ │ + var grid = this.grid; │ │ │ │ │ + var rowIndex = prepend ? 0 : (grid.length - 1); │ │ │ │ │ + var sign = prepend ? -1 : 1; │ │ │ │ │ + var rowSign = this.rowSign; │ │ │ │ │ + var tileLayout = this.gridLayout; │ │ │ │ │ + tileLayout.startrow += sign * rowSign; │ │ │ │ │ + │ │ │ │ │ + var modelRow = grid[rowIndex]; │ │ │ │ │ + var row = grid[prepend ? 'pop' : 'shift'](); │ │ │ │ │ + for (var i = 0, len = row.length; i < len; i++) { │ │ │ │ │ + var tile = row[i]; │ │ │ │ │ + var position = modelRow[i].position.clone(); │ │ │ │ │ + position.y += tileSize.h * sign; │ │ │ │ │ + tile.moveTo(this.getTileBoundsForGridIndex(rowIndex, i), position); │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + grid[prepend ? 'unshift' : 'push'](row); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: adjustXY │ │ │ │ │ - * Converts event coordinates that are relative to the document body to │ │ │ │ │ - * ones that are relative to the map viewport. The latter is the default in │ │ │ │ │ - * OpenLayers. │ │ │ │ │ - * │ │ │ │ │ + * Method: shiftColumn │ │ │ │ │ + * Shift grid work in the other dimension │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ - */ │ │ │ │ │ - adjustXY: function(evt) { │ │ │ │ │ - var pos = OpenLayers.Util.pagePosition(this.map.viewPortDiv); │ │ │ │ │ - evt.xy.x -= pos[0]; │ │ │ │ │ - evt.xy.y -= pos[1]; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addDocumentEvents │ │ │ │ │ - * Start observing document events when documentDrag is true and the mouse │ │ │ │ │ - * cursor leaves the map viewport while dragging. │ │ │ │ │ + * prepend - {Boolean} if true, prepend to beginning. │ │ │ │ │ + * if false, then append to end │ │ │ │ │ + * tileSize - {Object} rendered tile size; object with w and h properties │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + shiftColumn: function(prepend, tileSize) { │ │ │ │ │ + var grid = this.grid; │ │ │ │ │ + var colIndex = prepend ? 0 : (grid[0].length - 1); │ │ │ │ │ + var sign = prepend ? -1 : 1; │ │ │ │ │ + var tileLayout = this.gridLayout; │ │ │ │ │ + tileLayout.startcol += sign; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeDocumentEvents │ │ │ │ │ - * Stops observing document events when documentDrag is true and the mouse │ │ │ │ │ - * cursor re-enters the map viewport while dragging. │ │ │ │ │ - */ │ │ │ │ │ - removeDocumentEvents: function() { │ │ │ │ │ - OpenLayers.Element.removeClass(document.body, "olDragDown"); │ │ │ │ │ - this.documentEvents = false; │ │ │ │ │ - OpenLayers.Event.stopObserving(document, "mousemove", this._docMove); │ │ │ │ │ - OpenLayers.Event.stopObserving(document, "mouseup", this._docUp); │ │ │ │ │ + for (var i = 0, len = grid.length; i < len; i++) { │ │ │ │ │ + var row = grid[i]; │ │ │ │ │ + var position = row[colIndex].position.clone(); │ │ │ │ │ + var tile = row[prepend ? 'pop' : 'shift'](); │ │ │ │ │ + position.x += tileSize.w * sign; │ │ │ │ │ + tile.moveTo(this.getTileBoundsForGridIndex(i, colIndex), position); │ │ │ │ │ + row[prepend ? 'unshift' : 'push'](tile); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Drag" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Keyboard.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.handler.Keyboard │ │ │ │ │ - * A handler for keyboard events. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Keyboard = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - │ │ │ │ │ - /* http://www.quirksmode.org/js/keys.html explains key x-browser │ │ │ │ │ - key handling quirks in pretty nice detail */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constant: KEY_EVENTS │ │ │ │ │ - * keydown, keypress, keyup │ │ │ │ │ - */ │ │ │ │ │ - KEY_EVENTS: ["keydown", "keyup"], │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: eventListener │ │ │ │ │ - * {Function} │ │ │ │ │ - */ │ │ │ │ │ - eventListener: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: observeElement │ │ │ │ │ - * {DOMElement|String} The DOM element on which we listen for │ │ │ │ │ - * key events. Default to the document. │ │ │ │ │ - */ │ │ │ │ │ - observeElement: null, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Keyboard │ │ │ │ │ - * Returns a new keyboard handler. │ │ │ │ │ + * Method: removeExcessTiles │ │ │ │ │ + * When the size of the map or the buffer changes, we may need to │ │ │ │ │ + * remove some excess rows and columns. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * rows - {Integer} Maximum number of rows we want our grid to have. │ │ │ │ │ + * columns - {Integer} Maximum number of columns we want our grid to have. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + removeExcessTiles: function(rows, columns) { │ │ │ │ │ + var i, l; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - this.eventListener = null; │ │ │ │ │ - OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + // remove extra rows │ │ │ │ │ + while (this.grid.length > rows) { │ │ │ │ │ + var row = this.grid.pop(); │ │ │ │ │ + for (i = 0, l = row.length; i < l; i++) { │ │ │ │ │ + var tile = row[i]; │ │ │ │ │ + this.destroyTile(tile); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.observeElement = this.observeElement || document; │ │ │ │ │ - for (var i = 0, len = this.KEY_EVENTS.length; i < len; i++) { │ │ │ │ │ - OpenLayers.Event.observe( │ │ │ │ │ - this.observeElement, this.KEY_EVENTS[i], this.eventListener); │ │ │ │ │ + // remove extra columns │ │ │ │ │ + for (i = 0, l = this.grid.length; i < l; i++) { │ │ │ │ │ + while (this.grid[i].length > columns) { │ │ │ │ │ + var row = this.grid[i]; │ │ │ │ │ + var tile = row.pop(); │ │ │ │ │ + this.destroyTile(tile); │ │ │ │ │ } │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ + * Method: onMapResize │ │ │ │ │ + * For singleTile layers, this will set a new tile size according to the │ │ │ │ │ + * dimensions of the map pane. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - for (var i = 0, len = this.KEY_EVENTS.length; i < len; i++) { │ │ │ │ │ - OpenLayers.Event.stopObserving( │ │ │ │ │ - this.observeElement, this.KEY_EVENTS[i], this.eventListener); │ │ │ │ │ - } │ │ │ │ │ - deactivated = true; │ │ │ │ │ + onMapResize: function() { │ │ │ │ │ + if (this.singleTile) { │ │ │ │ │ + this.clearGrid(); │ │ │ │ │ + this.setTileSize(); │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleKeyEvent │ │ │ │ │ + * APIMethod: getTileBounds │ │ │ │ │ + * Returns The tile bounds for a layer given a pixel location. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * viewPortPx - {} The location in the viewport. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} Bounds of the tile at the given pixel location. │ │ │ │ │ */ │ │ │ │ │ - handleKeyEvent: function(evt) { │ │ │ │ │ - if (this.checkModifiers(evt)) { │ │ │ │ │ - this.callback(evt.type, [evt]); │ │ │ │ │ - } │ │ │ │ │ + getTileBounds: function(viewPortPx) { │ │ │ │ │ + var maxExtent = this.maxExtent; │ │ │ │ │ + var resolution = this.getResolution(); │ │ │ │ │ + var tileMapWidth = resolution * this.tileSize.w; │ │ │ │ │ + var tileMapHeight = resolution * this.tileSize.h; │ │ │ │ │ + var mapPoint = this.getLonLatFromViewPortPx(viewPortPx); │ │ │ │ │ + var tileLeft = maxExtent.left + (tileMapWidth * │ │ │ │ │ + Math.floor((mapPoint.lon - │ │ │ │ │ + maxExtent.left) / │ │ │ │ │ + tileMapWidth)); │ │ │ │ │ + var tileBottom = maxExtent.bottom + (tileMapHeight * │ │ │ │ │ + Math.floor((mapPoint.lat - │ │ │ │ │ + maxExtent.bottom) / │ │ │ │ │ + tileMapHeight)); │ │ │ │ │ + return new OpenLayers.Bounds(tileLeft, tileBottom, │ │ │ │ │ + tileLeft + tileMapWidth, │ │ │ │ │ + tileBottom + tileMapHeight); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Keyboard" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Layer.Grid" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ModifyFeature.js │ │ │ │ │ + OpenLayers/TileManager.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ - * @requires OpenLayers/Handler/Keyboard.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Element.js │ │ │ │ │ + * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ + * @requires OpenLayers/Tile/Image.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.ModifyFeature │ │ │ │ │ - * Control to modify features. When activated, a click renders the vertices │ │ │ │ │ - * of a feature - these vertices can then be dragged. By default, the │ │ │ │ │ - * delete key will delete the vertex under the mouse. New features are │ │ │ │ │ - * added by dragging "virtual vertices" between vertices. Create a new │ │ │ │ │ - * control with the constructor. │ │ │ │ │ + * Class: OpenLayers.TileManager │ │ │ │ │ + * Provides queueing of image requests and caching of image elements. │ │ │ │ │ * │ │ │ │ │ - * Inherits From: │ │ │ │ │ - * - │ │ │ │ │ + * Queueing avoids unnecessary image requests while changing zoom levels │ │ │ │ │ + * quickly, and helps improve dragging performance on mobile devices that show │ │ │ │ │ + * a lag in dragging when loading of new images starts. and │ │ │ │ │ + * are the configuration options to control this behavior. │ │ │ │ │ + * │ │ │ │ │ + * Caching avoids setting the src on image elements for images that have already │ │ │ │ │ + * been used. Several maps can share a TileManager instance, in which case each │ │ │ │ │ + * map gets its own tile queue, but all maps share the same tile cache. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} If set to true, dragging vertices will continue even if the │ │ │ │ │ - * mouse cursor leaves the map viewport. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geometryTypes │ │ │ │ │ - * {Array(String)} To restrict modification to a limited set of geometry │ │ │ │ │ - * types, send a list of strings corresponding to the geometry class │ │ │ │ │ - * names. │ │ │ │ │ - */ │ │ │ │ │ - geometryTypes: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: clickout │ │ │ │ │ - * {Boolean} Unselect features when clicking outside any feature. │ │ │ │ │ - * Default is true. │ │ │ │ │ - */ │ │ │ │ │ - clickout: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: toggle │ │ │ │ │ - * {Boolean} Unselect a selected feature on click. │ │ │ │ │ - * Default is true. │ │ │ │ │ - */ │ │ │ │ │ - toggle: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: standalone │ │ │ │ │ - * {Boolean} Set to true to create a control without SelectFeature │ │ │ │ │ - * capabilities. Default is false. If standalone is true, to modify │ │ │ │ │ - * a feature, call the method with the target feature. │ │ │ │ │ - * Note that you must call the method to finish │ │ │ │ │ - * feature modification in standalone mode (before starting to modify │ │ │ │ │ - * another feature). │ │ │ │ │ - */ │ │ │ │ │ - standalone: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: feature │ │ │ │ │ - * {} Feature currently available for modification. │ │ │ │ │ - */ │ │ │ │ │ - feature: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: vertex │ │ │ │ │ - * {} Vertex currently being modified. │ │ │ │ │ - */ │ │ │ │ │ - vertex: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: vertices │ │ │ │ │ - * {Array()} Verticies currently available │ │ │ │ │ - * for dragging. │ │ │ │ │ - */ │ │ │ │ │ - vertices: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: virtualVertices │ │ │ │ │ - * {Array()} Virtual vertices in the middle │ │ │ │ │ - * of each edge. │ │ │ │ │ - */ │ │ │ │ │ - virtualVertices: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: handlers │ │ │ │ │ - * {Object} │ │ │ │ │ - */ │ │ │ │ │ - handlers: null, │ │ │ │ │ +OpenLayers.TileManager = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: deleteCodes │ │ │ │ │ - * {Array(Integer)} Keycodes for deleting verticies. Set to null to disable │ │ │ │ │ - * vertex deltion by keypress. If non-null, keypresses with codes │ │ │ │ │ - * in this array will delete vertices under the mouse. Default │ │ │ │ │ - * is 46 and 68, the 'delete' and lowercase 'd' keys. │ │ │ │ │ + * APIProperty: cacheSize │ │ │ │ │ + * {Number} Number of image elements to keep referenced in this instance's │ │ │ │ │ + * cache for fast reuse. Default is 256. │ │ │ │ │ */ │ │ │ │ │ - deleteCodes: null, │ │ │ │ │ + cacheSize: 256, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: virtualStyle │ │ │ │ │ - * {Object} A symbolizer to be used for virtual vertices. │ │ │ │ │ + * APIProperty: tilesPerFrame │ │ │ │ │ + * {Number} Number of queued tiles to load per frame (see ). │ │ │ │ │ + * Default is 2. │ │ │ │ │ */ │ │ │ │ │ - virtualStyle: null, │ │ │ │ │ + tilesPerFrame: 2, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: vertexRenderIntent │ │ │ │ │ - * {String} The renderIntent to use for vertices. If no is │ │ │ │ │ - * provided, this renderIntent will also be used for virtual vertices, with │ │ │ │ │ - * a fillOpacity and strokeOpacity of 0.3. Default is null, which means │ │ │ │ │ - * that the layer's default style will be used for vertices. │ │ │ │ │ + * APIProperty: frameDelay │ │ │ │ │ + * {Number} Delay between tile loading frames (see ) in │ │ │ │ │ + * milliseconds. Default is 16. │ │ │ │ │ */ │ │ │ │ │ - vertexRenderIntent: null, │ │ │ │ │ + frameDelay: 16, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: mode │ │ │ │ │ - * {Integer} Bitfields specifying the modification mode. Defaults to │ │ │ │ │ - * OpenLayers.Control.ModifyFeature.RESHAPE. To set the mode to a │ │ │ │ │ - * combination of options, use the | operator. For example, to allow │ │ │ │ │ - * the control to both resize and rotate features, use the following │ │ │ │ │ - * syntax │ │ │ │ │ - * (code) │ │ │ │ │ - * control.mode = OpenLayers.Control.ModifyFeature.RESIZE | │ │ │ │ │ - * OpenLayers.Control.ModifyFeature.ROTATE; │ │ │ │ │ - * (end) │ │ │ │ │ + * APIProperty: moveDelay │ │ │ │ │ + * {Number} Delay in milliseconds after a map's move event before loading │ │ │ │ │ + * tiles. Default is 100. │ │ │ │ │ */ │ │ │ │ │ - mode: null, │ │ │ │ │ + moveDelay: 100, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: createVertices │ │ │ │ │ - * {Boolean} Create new vertices by dragging the virtual vertices │ │ │ │ │ - * in the middle of each edge. Default is true. │ │ │ │ │ + * APIProperty: zoomDelay │ │ │ │ │ + * {Number} Delay in milliseconds after a map's zoomend event before loading │ │ │ │ │ + * tiles. Default is 200. │ │ │ │ │ */ │ │ │ │ │ - createVertices: true, │ │ │ │ │ + zoomDelay: 200, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: modified │ │ │ │ │ - * {Boolean} The currently selected feature has been modified. │ │ │ │ │ + * Property: maps │ │ │ │ │ + * {Array()} The maps to manage tiles on. │ │ │ │ │ */ │ │ │ │ │ - modified: false, │ │ │ │ │ + maps: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: radiusHandle │ │ │ │ │ - * {} A handle for rotating/resizing a feature. │ │ │ │ │ + * Property: tileQueueId │ │ │ │ │ + * {Object} The ids of the loop, keyed by map id. │ │ │ │ │ */ │ │ │ │ │ - radiusHandle: null, │ │ │ │ │ + tileQueueId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: dragHandle │ │ │ │ │ - * {} A handle for dragging a feature. │ │ │ │ │ + * Property: tileQueue │ │ │ │ │ + * {Object(Array())} Tiles queued for drawing, keyed by │ │ │ │ │ + * map id. │ │ │ │ │ */ │ │ │ │ │ - dragHandle: null, │ │ │ │ │ + tileQueue: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: onModificationStart │ │ │ │ │ - * {Function} *Deprecated*. Register for "beforefeaturemodified" instead. │ │ │ │ │ - * The "beforefeaturemodified" event is triggered on the layer before │ │ │ │ │ - * any modification begins. │ │ │ │ │ - * │ │ │ │ │ - * Optional function to be called when a feature is selected │ │ │ │ │ - * to be modified. The function should expect to be called with a │ │ │ │ │ - * feature. This could be used for example to allow to lock the │ │ │ │ │ - * feature on server-side. │ │ │ │ │ + * Property: tileCache │ │ │ │ │ + * {Object} Cached image elements, keyed by URL. │ │ │ │ │ */ │ │ │ │ │ - onModificationStart: function() {}, │ │ │ │ │ + tileCache: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: onModification │ │ │ │ │ - * {Function} *Deprecated*. Register for "featuremodified" instead. │ │ │ │ │ - * The "featuremodified" event is triggered on the layer with each │ │ │ │ │ - * feature modification. │ │ │ │ │ - * │ │ │ │ │ - * Optional function to be called when a feature has been │ │ │ │ │ - * modified. The function should expect to be called with a feature. │ │ │ │ │ + * Property: tileCacheIndex │ │ │ │ │ + * {Array(String)} URLs of cached tiles. First entry is the least recently │ │ │ │ │ + * used. │ │ │ │ │ */ │ │ │ │ │ - onModification: function() {}, │ │ │ │ │ + tileCacheIndex: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onModificationEnd │ │ │ │ │ - * {Function} *Deprecated*. Register for "afterfeaturemodified" instead. │ │ │ │ │ - * The "afterfeaturemodified" event is triggered on the layer after │ │ │ │ │ - * a feature has been modified. │ │ │ │ │ - * │ │ │ │ │ - * Optional function to be called when a feature is finished │ │ │ │ │ - * being modified. The function should expect to be called with a │ │ │ │ │ - * feature. │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.TileManager │ │ │ │ │ + * Constructor for a new instance. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Configuration for this instance. │ │ │ │ │ */ │ │ │ │ │ - onModificationEnd: function() {}, │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.maps = []; │ │ │ │ │ + this.tileQueueId = {}; │ │ │ │ │ + this.tileQueue = {}; │ │ │ │ │ + this.tileCache = {}; │ │ │ │ │ + this.tileCacheIndex = []; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.ModifyFeature │ │ │ │ │ - * Create a new modify feature control. │ │ │ │ │ + * Method: addMap │ │ │ │ │ + * Binds this instance to a map │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} Layer that contains features that │ │ │ │ │ - * will be modified. │ │ │ │ │ - * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ - * control. │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(layer, options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - this.virtualVertices = []; │ │ │ │ │ - this.virtualStyle = OpenLayers.Util.extend({}, │ │ │ │ │ - this.layer.style || │ │ │ │ │ - this.layer.styleMap.createSymbolizer(null, options.vertexRenderIntent) │ │ │ │ │ - ); │ │ │ │ │ - this.virtualStyle.fillOpacity = 0.3; │ │ │ │ │ - this.virtualStyle.strokeOpacity = 0.3; │ │ │ │ │ - this.deleteCodes = [46, 68]; │ │ │ │ │ - this.mode = OpenLayers.Control.ModifyFeature.RESHAPE; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - if (!(OpenLayers.Util.isArray(this.deleteCodes))) { │ │ │ │ │ - this.deleteCodes = [this.deleteCodes]; │ │ │ │ │ + addMap: function(map) { │ │ │ │ │ + if (this._destroyed || !OpenLayers.Layer.Grid) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // configure the drag handler │ │ │ │ │ - var dragCallbacks = { │ │ │ │ │ - down: function(pixel) { │ │ │ │ │ - this.vertex = null; │ │ │ │ │ - var feature = this.layer.getFeatureFromEvent( │ │ │ │ │ - this.handlers.drag.evt); │ │ │ │ │ - if (feature) { │ │ │ │ │ - this.dragStart(feature); │ │ │ │ │ - } else if (this.clickout) { │ │ │ │ │ - this._unselect = this.feature; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - move: function(pixel) { │ │ │ │ │ - delete this._unselect; │ │ │ │ │ - if (this.vertex) { │ │ │ │ │ - this.dragVertex(this.vertex, pixel); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - up: function() { │ │ │ │ │ - this.handlers.drag.stopDown = false; │ │ │ │ │ - if (this._unselect) { │ │ │ │ │ - this.unselectFeature(this._unselect); │ │ │ │ │ - delete this._unselect; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - done: function(pixel) { │ │ │ │ │ - if (this.vertex) { │ │ │ │ │ - this.dragComplete(this.vertex); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - var dragOptions = { │ │ │ │ │ - documentDrag: this.documentDrag, │ │ │ │ │ - stopDown: false │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - // configure the keyboard handler │ │ │ │ │ - var keyboardOptions = { │ │ │ │ │ - keydown: this.handleKeypress │ │ │ │ │ - }; │ │ │ │ │ - this.handlers = { │ │ │ │ │ - keyboard: new OpenLayers.Handler.Keyboard(this, keyboardOptions), │ │ │ │ │ - drag: new OpenLayers.Handler.Drag(this, dragCallbacks, dragOptions) │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Take care of things that are not handled in superclass. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - "removelayer": this.handleMapEvents, │ │ │ │ │ - "changelayer": this.handleMapEvents, │ │ │ │ │ - scope: this │ │ │ │ │ + this.maps.push(map); │ │ │ │ │ + this.tileQueue[map.id] = []; │ │ │ │ │ + for (var i = 0, ii = map.layers.length; i < ii; ++i) { │ │ │ │ │ + this.addLayer({ │ │ │ │ │ + layer: map.layers[i] │ │ │ │ │ }); │ │ │ │ │ } │ │ │ │ │ - this.layer = null; │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, []); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Successfully activated the control. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - this.moveLayerToTop(); │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - "removelayer": this.handleMapEvents, │ │ │ │ │ - "changelayer": this.handleMapEvents, │ │ │ │ │ + map.events.on({ │ │ │ │ │ + move: this.move, │ │ │ │ │ + zoomend: this.zoomEnd, │ │ │ │ │ + changelayer: this.changeLayer, │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + preremovelayer: this.removeLayer, │ │ │ │ │ scope: this │ │ │ │ │ }); │ │ │ │ │ - return (this.handlers.keyboard.activate() && │ │ │ │ │ - this.handlers.drag.activate() && │ │ │ │ │ - OpenLayers.Control.prototype.activate.apply(this, arguments)); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the control. │ │ │ │ │ + * Method: removeMap │ │ │ │ │ + * Unbinds this instance from a map │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Successfully deactivated the control. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - // the return from the controls is unimportant in this case │ │ │ │ │ - if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.moveLayerBack(); │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - "removelayer": this.handleMapEvents, │ │ │ │ │ - "changelayer": this.handleMapEvents, │ │ │ │ │ + removeMap: function(map) { │ │ │ │ │ + if (this._destroyed || !OpenLayers.Layer.Grid) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + window.clearTimeout(this.tileQueueId[map.id]); │ │ │ │ │ + if (map.layers) { │ │ │ │ │ + for (var i = 0, ii = map.layers.length; i < ii; ++i) { │ │ │ │ │ + this.removeLayer({ │ │ │ │ │ + layer: map.layers[i] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (map.events) { │ │ │ │ │ + map.events.un({ │ │ │ │ │ + move: this.move, │ │ │ │ │ + zoomend: this.zoomEnd, │ │ │ │ │ + changelayer: this.changeLayer, │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + preremovelayer: this.removeLayer, │ │ │ │ │ scope: this │ │ │ │ │ }); │ │ │ │ │ - this.layer.removeFeatures(this.vertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.layer.removeFeatures(this.virtualVertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - this.handlers.drag.deactivate(); │ │ │ │ │ - this.handlers.keyboard.deactivate(); │ │ │ │ │ - var feature = this.feature; │ │ │ │ │ - if (feature && feature.geometry && feature.layer) { │ │ │ │ │ - this.unselectFeature(feature); │ │ │ │ │ - } │ │ │ │ │ - deactivated = true; │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + delete this.tileQueue[map.id]; │ │ │ │ │ + delete this.tileQueueId[map.id]; │ │ │ │ │ + OpenLayers.Util.removeItem(this.maps, map); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: beforeSelectFeature │ │ │ │ │ - * Called before a feature is selected. │ │ │ │ │ + * Method: move │ │ │ │ │ + * Handles the map's move event │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} The feature about to be selected. │ │ │ │ │ + * evt - {Object} Listener argument │ │ │ │ │ */ │ │ │ │ │ - beforeSelectFeature: function(feature) { │ │ │ │ │ - return this.layer.events.triggerEvent( │ │ │ │ │ - "beforefeaturemodified", { │ │ │ │ │ - feature: feature │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ + move: function(evt) { │ │ │ │ │ + this.updateTimeout(evt.object, this.moveDelay, true); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: selectFeature │ │ │ │ │ - * Select a feature for modification in standalone mode. In non-standalone │ │ │ │ │ - * mode, this method is called when a feature is selected by clicking. │ │ │ │ │ - * Register a listener to the beforefeaturemodified event and return false │ │ │ │ │ - * to prevent feature modification. │ │ │ │ │ + * Method: zoomEnd │ │ │ │ │ + * Handles the map's zoomEnd event │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} the selected feature. │ │ │ │ │ + * evt - {Object} Listener argument │ │ │ │ │ */ │ │ │ │ │ - selectFeature: function(feature) { │ │ │ │ │ - if (this.feature === feature || │ │ │ │ │ - (this.geometryTypes && OpenLayers.Util.indexOf(this.geometryTypes, │ │ │ │ │ - feature.geometry.CLASS_NAME) == -1)) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (this.beforeSelectFeature(feature) !== false) { │ │ │ │ │ - if (this.feature) { │ │ │ │ │ - this.unselectFeature(this.feature); │ │ │ │ │ - } │ │ │ │ │ - this.feature = feature; │ │ │ │ │ - this.layer.selectedFeatures.push(feature); │ │ │ │ │ - this.layer.drawFeature(feature, 'select'); │ │ │ │ │ - this.modified = false; │ │ │ │ │ - this.resetVertices(); │ │ │ │ │ - this.onModificationStart(this.feature); │ │ │ │ │ - } │ │ │ │ │ - // keep track of geometry modifications │ │ │ │ │ - var modified = feature.modified; │ │ │ │ │ - if (feature.geometry && !(modified && modified.geometry)) { │ │ │ │ │ - this._originalGeometry = feature.geometry.clone(); │ │ │ │ │ - } │ │ │ │ │ + zoomEnd: function(evt) { │ │ │ │ │ + this.updateTimeout(evt.object, this.zoomDelay); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: unselectFeature │ │ │ │ │ - * Called when the select feature control unselects a feature. │ │ │ │ │ + * Method: changeLayer │ │ │ │ │ + * Handles the map's changeLayer event │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} The unselected feature. │ │ │ │ │ + * evt - {Object} Listener argument │ │ │ │ │ */ │ │ │ │ │ - unselectFeature: function(feature) { │ │ │ │ │ - this.layer.removeFeatures(this.vertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - this.layer.destroyFeatures(this.virtualVertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.virtualVertices = []; │ │ │ │ │ - if (this.dragHandle) { │ │ │ │ │ - this.layer.destroyFeatures([this.dragHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - delete this.dragHandle; │ │ │ │ │ - } │ │ │ │ │ - if (this.radiusHandle) { │ │ │ │ │ - this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - delete this.radiusHandle; │ │ │ │ │ + changeLayer: function(evt) { │ │ │ │ │ + if (evt.property === 'visibility' || evt.property === 'params') { │ │ │ │ │ + this.updateTimeout(evt.object, 0); │ │ │ │ │ } │ │ │ │ │ - this.layer.drawFeature(this.feature, 'default'); │ │ │ │ │ - this.feature = null; │ │ │ │ │ - OpenLayers.Util.removeItem(this.layer.selectedFeatures, feature); │ │ │ │ │ - this.onModificationEnd(feature); │ │ │ │ │ - this.layer.events.triggerEvent("afterfeaturemodified", { │ │ │ │ │ - feature: feature, │ │ │ │ │ - modified: this.modified │ │ │ │ │ - }); │ │ │ │ │ - this.modified = false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: dragStart │ │ │ │ │ - * Called by the drag handler before a feature is dragged. This method is │ │ │ │ │ - * used to differentiate between points and vertices │ │ │ │ │ - * of higher order geometries. │ │ │ │ │ + * Method: addLayer │ │ │ │ │ + * Handles the map's addlayer event │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} The point or vertex about to be │ │ │ │ │ - * dragged. │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ */ │ │ │ │ │ - dragStart: function(feature) { │ │ │ │ │ - var isPoint = feature.geometry.CLASS_NAME == │ │ │ │ │ - 'OpenLayers.Geometry.Point'; │ │ │ │ │ - if (!this.standalone && │ │ │ │ │ - ((!feature._sketch && isPoint) || !feature._sketch)) { │ │ │ │ │ - if (this.toggle && this.feature === feature) { │ │ │ │ │ - // mark feature for unselection │ │ │ │ │ - this._unselect = feature; │ │ │ │ │ + addLayer: function(evt) { │ │ │ │ │ + var layer = evt.layer; │ │ │ │ │ + if (layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ + layer.events.on({ │ │ │ │ │ + addtile: this.addTile, │ │ │ │ │ + retile: this.clearTileQueue, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + var i, j, tile; │ │ │ │ │ + for (i = layer.grid.length - 1; i >= 0; --i) { │ │ │ │ │ + for (j = layer.grid[i].length - 1; j >= 0; --j) { │ │ │ │ │ + tile = layer.grid[i][j]; │ │ │ │ │ + this.addTile({ │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + if (tile.url && !tile.imgDiv) { │ │ │ │ │ + this.manageTileCache({ │ │ │ │ │ + object: tile │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.selectFeature(feature); │ │ │ │ │ - } │ │ │ │ │ - if (feature._sketch || isPoint) { │ │ │ │ │ - // feature is a drag or virtual handle or point │ │ │ │ │ - this.vertex = feature; │ │ │ │ │ - this.handlers.drag.stopDown = true; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragVertex │ │ │ │ │ - * Called by the drag handler with each drag move of a vertex. │ │ │ │ │ + * Method: removeLayer │ │ │ │ │ + * Handles the map's preremovelayer event │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * vertex - {} The vertex being dragged. │ │ │ │ │ - * pixel - {} Pixel location of the mouse event. │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ */ │ │ │ │ │ - dragVertex: function(vertex, pixel) { │ │ │ │ │ - var pos = this.map.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - var geom = vertex.geometry; │ │ │ │ │ - geom.move(pos.lon - geom.x, pos.lat - geom.y); │ │ │ │ │ - this.modified = true; │ │ │ │ │ - /** │ │ │ │ │ - * Five cases: │ │ │ │ │ - * 1) dragging a simple point │ │ │ │ │ - * 2) dragging a virtual vertex │ │ │ │ │ - * 3) dragging a drag handle │ │ │ │ │ - * 4) dragging a real vertex │ │ │ │ │ - * 5) dragging a radius handle │ │ │ │ │ - */ │ │ │ │ │ - if (this.feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - // dragging a simple point │ │ │ │ │ - this.layer.events.triggerEvent("vertexmodified", { │ │ │ │ │ - vertex: vertex.geometry, │ │ │ │ │ - feature: this.feature, │ │ │ │ │ - pixel: pixel │ │ │ │ │ + removeLayer: function(evt) { │ │ │ │ │ + var layer = evt.layer; │ │ │ │ │ + if (layer instanceof OpenLayers.Layer.Grid) { │ │ │ │ │ + this.clearTileQueue({ │ │ │ │ │ + object: layer │ │ │ │ │ }); │ │ │ │ │ - } else { │ │ │ │ │ - if (vertex._index) { │ │ │ │ │ - // dragging a virtual vertex │ │ │ │ │ - vertex.geometry.parent.addComponent(vertex.geometry, │ │ │ │ │ - vertex._index); │ │ │ │ │ - // move from virtual to real vertex │ │ │ │ │ - delete vertex._index; │ │ │ │ │ - OpenLayers.Util.removeItem(this.virtualVertices, vertex); │ │ │ │ │ - this.vertices.push(vertex); │ │ │ │ │ - } else if (vertex == this.dragHandle) { │ │ │ │ │ - // dragging a drag handle │ │ │ │ │ - this.layer.removeFeatures(this.vertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - if (this.radiusHandle) { │ │ │ │ │ - this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.radiusHandle = null; │ │ │ │ │ - } │ │ │ │ │ - } else if (vertex !== this.radiusHandle) { │ │ │ │ │ - // dragging a real vertex │ │ │ │ │ - this.layer.events.triggerEvent("vertexmodified", { │ │ │ │ │ - vertex: vertex.geometry, │ │ │ │ │ - feature: this.feature, │ │ │ │ │ - pixel: pixel │ │ │ │ │ + if (layer.events) { │ │ │ │ │ + layer.events.un({ │ │ │ │ │ + addtile: this.addTile, │ │ │ │ │ + retile: this.clearTileQueue, │ │ │ │ │ + scope: this │ │ │ │ │ }); │ │ │ │ │ } │ │ │ │ │ - // dragging a radius handle - no special treatment │ │ │ │ │ - if (this.virtualVertices.length > 0) { │ │ │ │ │ - this.layer.destroyFeatures(this.virtualVertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.virtualVertices = []; │ │ │ │ │ + if (layer.grid) { │ │ │ │ │ + var i, j, tile; │ │ │ │ │ + for (i = layer.grid.length - 1; i >= 0; --i) { │ │ │ │ │ + for (j = layer.grid[i].length - 1; j >= 0; --j) { │ │ │ │ │ + tile = layer.grid[i][j]; │ │ │ │ │ + this.unloadTile({ │ │ │ │ │ + object: tile │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.layer.drawFeature(this.feature, this.standalone ? undefined : │ │ │ │ │ - 'select'); │ │ │ │ │ } │ │ │ │ │ - // keep the vertex on top so it gets the mouseout after dragging │ │ │ │ │ - // this should be removed in favor of an option to draw under or │ │ │ │ │ - // maintain node z-index │ │ │ │ │ - this.layer.drawFeature(vertex); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dragComplete │ │ │ │ │ - * Called by the drag handler when the feature dragging is complete. │ │ │ │ │ + * Method: updateTimeout │ │ │ │ │ + * Applies the or to the loop, │ │ │ │ │ + * and schedules more queue processing after if there are still │ │ │ │ │ + * tiles in the queue. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * vertex - {} The vertex being dragged. │ │ │ │ │ - */ │ │ │ │ │ - dragComplete: function(vertex) { │ │ │ │ │ - this.resetVertices(); │ │ │ │ │ - this.setFeatureState(); │ │ │ │ │ - this.onModification(this.feature); │ │ │ │ │ - this.layer.events.triggerEvent("featuremodified", { │ │ │ │ │ - feature: this.feature │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setFeatureState │ │ │ │ │ - * Called when the feature is modified. If the current state is not │ │ │ │ │ - * INSERT or DELETE, the state is set to UPDATE. │ │ │ │ │ + * map - {} The map to update the timeout for │ │ │ │ │ + * delay - {Number} The delay to apply │ │ │ │ │ + * nice - {Boolean} If true, the timeout function will only be created if │ │ │ │ │ + * the tilequeue is not empty. This is used by the move handler to │ │ │ │ │ + * avoid impacts on dragging performance. For other events, the tile │ │ │ │ │ + * queue may not be populated yet, so we need to set the timer │ │ │ │ │ + * regardless of the queue size. │ │ │ │ │ */ │ │ │ │ │ - setFeatureState: function() { │ │ │ │ │ - if (this.feature.state != OpenLayers.State.INSERT && │ │ │ │ │ - this.feature.state != OpenLayers.State.DELETE) { │ │ │ │ │ - this.feature.state = OpenLayers.State.UPDATE; │ │ │ │ │ - if (this.modified && this._originalGeometry) { │ │ │ │ │ - var feature = this.feature; │ │ │ │ │ - feature.modified = OpenLayers.Util.extend(feature.modified, { │ │ │ │ │ - geometry: this._originalGeometry │ │ │ │ │ - }); │ │ │ │ │ - delete this._originalGeometry; │ │ │ │ │ - } │ │ │ │ │ + updateTimeout: function(map, delay, nice) { │ │ │ │ │ + window.clearTimeout(this.tileQueueId[map.id]); │ │ │ │ │ + var tileQueue = this.tileQueue[map.id]; │ │ │ │ │ + if (!nice || tileQueue.length) { │ │ │ │ │ + this.tileQueueId[map.id] = window.setTimeout( │ │ │ │ │ + OpenLayers.Function.bind(function() { │ │ │ │ │ + this.drawTilesFromQueue(map); │ │ │ │ │ + if (tileQueue.length) { │ │ │ │ │ + this.updateTimeout(map, this.frameDelay); │ │ │ │ │ + } │ │ │ │ │ + }, this), delay │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: resetVertices │ │ │ │ │ + * Method: addTile │ │ │ │ │ + * Listener for the layer's addtile event │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ */ │ │ │ │ │ - resetVertices: function() { │ │ │ │ │ - if (this.vertices.length > 0) { │ │ │ │ │ - this.layer.removeFeatures(this.vertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - } │ │ │ │ │ - if (this.virtualVertices.length > 0) { │ │ │ │ │ - this.layer.removeFeatures(this.virtualVertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.virtualVertices = []; │ │ │ │ │ - } │ │ │ │ │ - if (this.dragHandle) { │ │ │ │ │ - this.layer.destroyFeatures([this.dragHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ + addTile: function(evt) { │ │ │ │ │ + if (evt.tile instanceof OpenLayers.Tile.Image) { │ │ │ │ │ + evt.tile.events.on({ │ │ │ │ │ + beforedraw: this.queueTileDraw, │ │ │ │ │ + beforeload: this.manageTileCache, │ │ │ │ │ + loadend: this.addToCache, │ │ │ │ │ + unload: this.unloadTile, │ │ │ │ │ + scope: this │ │ │ │ │ }); │ │ │ │ │ - this.dragHandle = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.radiusHandle) { │ │ │ │ │ - this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ + } else { │ │ │ │ │ + // Layer has the wrong tile type, so don't handle it any longer │ │ │ │ │ + this.removeLayer({ │ │ │ │ │ + layer: evt.tile.layer │ │ │ │ │ }); │ │ │ │ │ - this.radiusHandle = null; │ │ │ │ │ - } │ │ │ │ │ - if (this.feature && │ │ │ │ │ - this.feature.geometry.CLASS_NAME != "OpenLayers.Geometry.Point") { │ │ │ │ │ - if ((this.mode & OpenLayers.Control.ModifyFeature.DRAG)) { │ │ │ │ │ - this.collectDragHandle(); │ │ │ │ │ - } │ │ │ │ │ - if ((this.mode & (OpenLayers.Control.ModifyFeature.ROTATE | │ │ │ │ │ - OpenLayers.Control.ModifyFeature.RESIZE))) { │ │ │ │ │ - this.collectRadiusHandle(); │ │ │ │ │ - } │ │ │ │ │ - if (this.mode & OpenLayers.Control.ModifyFeature.RESHAPE) { │ │ │ │ │ - // Don't collect vertices when we're resizing │ │ │ │ │ - if (!(this.mode & OpenLayers.Control.ModifyFeature.RESIZE)) { │ │ │ │ │ - this.collectVertices(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleKeypress │ │ │ │ │ - * Called by the feature handler on keypress. This is used to delete │ │ │ │ │ - * vertices. If the property is set, vertices will │ │ │ │ │ - * be deleted when a feature is selected for modification and │ │ │ │ │ - * the mouse is over a vertex. │ │ │ │ │ + * Method: unloadTile │ │ │ │ │ + * Listener for the tile's unload event │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} Keypress event. │ │ │ │ │ + * evt - {Object} The listener argument │ │ │ │ │ */ │ │ │ │ │ - handleKeypress: function(evt) { │ │ │ │ │ - var code = evt.keyCode; │ │ │ │ │ - │ │ │ │ │ - // check for delete key │ │ │ │ │ - if (this.feature && │ │ │ │ │ - OpenLayers.Util.indexOf(this.deleteCodes, code) != -1) { │ │ │ │ │ - var vertex = this.layer.getFeatureFromEvent(this.handlers.drag.evt); │ │ │ │ │ - if (vertex && │ │ │ │ │ - OpenLayers.Util.indexOf(this.vertices, vertex) != -1 && │ │ │ │ │ - !this.handlers.drag.dragging && vertex.geometry.parent) { │ │ │ │ │ - // remove the vertex │ │ │ │ │ - vertex.geometry.parent.removeComponent(vertex.geometry); │ │ │ │ │ - this.layer.events.triggerEvent("vertexremoved", { │ │ │ │ │ - vertex: vertex.geometry, │ │ │ │ │ - feature: this.feature, │ │ │ │ │ - pixel: evt.xy │ │ │ │ │ - }); │ │ │ │ │ - this.layer.drawFeature(this.feature, this.standalone ? │ │ │ │ │ - undefined : 'select'); │ │ │ │ │ - this.modified = true; │ │ │ │ │ - this.resetVertices(); │ │ │ │ │ - this.setFeatureState(); │ │ │ │ │ - this.onModification(this.feature); │ │ │ │ │ - this.layer.events.triggerEvent("featuremodified", { │ │ │ │ │ - feature: this.feature │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + unloadTile: function(evt) { │ │ │ │ │ + var tile = evt.object; │ │ │ │ │ + tile.events.un({ │ │ │ │ │ + beforedraw: this.queueTileDraw, │ │ │ │ │ + beforeload: this.manageTileCache, │ │ │ │ │ + loadend: this.addToCache, │ │ │ │ │ + unload: this.unloadTile, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + OpenLayers.Util.removeItem(this.tileQueue[tile.layer.map.id], tile); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: collectVertices │ │ │ │ │ - * Collect the vertices from the modifiable feature's geometry and push │ │ │ │ │ - * them on to the control's vertices array. │ │ │ │ │ + * Method: queueTileDraw │ │ │ │ │ + * Adds a tile to the queue that will draw it. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Listener argument of the tile's beforedraw event │ │ │ │ │ */ │ │ │ │ │ - collectVertices: function() { │ │ │ │ │ - this.vertices = []; │ │ │ │ │ - this.virtualVertices = []; │ │ │ │ │ - var control = this; │ │ │ │ │ - │ │ │ │ │ - function collectComponentVertices(geometry) { │ │ │ │ │ - var i, vertex, component, len; │ │ │ │ │ - if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - vertex = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ - vertex._sketch = true; │ │ │ │ │ - vertex.renderIntent = control.vertexRenderIntent; │ │ │ │ │ - control.vertices.push(vertex); │ │ │ │ │ - } else { │ │ │ │ │ - var numVert = geometry.components.length; │ │ │ │ │ - if (geometry.CLASS_NAME == "OpenLayers.Geometry.LinearRing") { │ │ │ │ │ - numVert -= 1; │ │ │ │ │ - } │ │ │ │ │ - for (i = 0; i < numVert; ++i) { │ │ │ │ │ - component = geometry.components[i]; │ │ │ │ │ - if (component.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - vertex = new OpenLayers.Feature.Vector(component); │ │ │ │ │ - vertex._sketch = true; │ │ │ │ │ - vertex.renderIntent = control.vertexRenderIntent; │ │ │ │ │ - control.vertices.push(vertex); │ │ │ │ │ - } else { │ │ │ │ │ - collectComponentVertices(component); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // add virtual vertices in the middle of each edge │ │ │ │ │ - if (control.createVertices && geometry.CLASS_NAME != "OpenLayers.Geometry.MultiPoint") { │ │ │ │ │ - for (i = 0, len = geometry.components.length; i < len - 1; ++i) { │ │ │ │ │ - var prevVertex = geometry.components[i]; │ │ │ │ │ - var nextVertex = geometry.components[i + 1]; │ │ │ │ │ - if (prevVertex.CLASS_NAME == "OpenLayers.Geometry.Point" && │ │ │ │ │ - nextVertex.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ - var x = (prevVertex.x + nextVertex.x) / 2; │ │ │ │ │ - var y = (prevVertex.y + nextVertex.y) / 2; │ │ │ │ │ - var point = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.Point(x, y), │ │ │ │ │ - null, control.virtualStyle │ │ │ │ │ - ); │ │ │ │ │ - // set the virtual parent and intended index │ │ │ │ │ - point.geometry.parent = geometry; │ │ │ │ │ - point._index = i + 1; │ │ │ │ │ - point._sketch = true; │ │ │ │ │ - control.virtualVertices.push(point); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + queueTileDraw: function(evt) { │ │ │ │ │ + var tile = evt.object; │ │ │ │ │ + var queued = false; │ │ │ │ │ + var layer = tile.layer; │ │ │ │ │ + var url = layer.getURL(tile.bounds); │ │ │ │ │ + var img = this.tileCache[url]; │ │ │ │ │ + if (img && img.className !== 'olTileImage') { │ │ │ │ │ + // cached image no longer valid, e.g. because we're olTileReplacing │ │ │ │ │ + delete this.tileCache[url]; │ │ │ │ │ + OpenLayers.Util.removeItem(this.tileCacheIndex, url); │ │ │ │ │ + img = null; │ │ │ │ │ + } │ │ │ │ │ + // queue only if image with same url not cached already │ │ │ │ │ + if (layer.url && (layer.async || !img)) { │ │ │ │ │ + // add to queue only if not in queue already │ │ │ │ │ + var tileQueue = this.tileQueue[layer.map.id]; │ │ │ │ │ + if (!~OpenLayers.Util.indexOf(tileQueue, tile)) { │ │ │ │ │ + tileQueue.push(tile); │ │ │ │ │ } │ │ │ │ │ + queued = true; │ │ │ │ │ } │ │ │ │ │ - collectComponentVertices.call(this, this.feature.geometry); │ │ │ │ │ - this.layer.addFeatures(this.virtualVertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.layer.addFeatures(this.vertices, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ + return !queued; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: collectDragHandle │ │ │ │ │ - * Collect the drag handle for the selected geometry. │ │ │ │ │ + * Method: drawTilesFromQueue │ │ │ │ │ + * Draws tiles from the tileQueue, and unqueues the tiles │ │ │ │ │ */ │ │ │ │ │ - collectDragHandle: function() { │ │ │ │ │ - var geometry = this.feature.geometry; │ │ │ │ │ - var center = geometry.getBounds().getCenterLonLat(); │ │ │ │ │ - var originGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - center.lon, center.lat │ │ │ │ │ - ); │ │ │ │ │ - var origin = new OpenLayers.Feature.Vector(originGeometry); │ │ │ │ │ - originGeometry.move = function(x, y) { │ │ │ │ │ - OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ - geometry.move(x, y); │ │ │ │ │ - }; │ │ │ │ │ - origin._sketch = true; │ │ │ │ │ - this.dragHandle = origin; │ │ │ │ │ - this.dragHandle.renderIntent = this.vertexRenderIntent; │ │ │ │ │ - this.layer.addFeatures([this.dragHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ + drawTilesFromQueue: function(map) { │ │ │ │ │ + var tileQueue = this.tileQueue[map.id]; │ │ │ │ │ + var limit = this.tilesPerFrame; │ │ │ │ │ + var animating = map.zoomTween && map.zoomTween.playing; │ │ │ │ │ + while (!animating && tileQueue.length && limit) { │ │ │ │ │ + tileQueue.shift().draw(true); │ │ │ │ │ + --limit; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: collectRadiusHandle │ │ │ │ │ - * Collect the radius handle for the selected geometry. │ │ │ │ │ + * Method: manageTileCache │ │ │ │ │ + * Adds, updates, removes and fetches cache entries. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Listener argument of the tile's beforeload event │ │ │ │ │ */ │ │ │ │ │ - collectRadiusHandle: function() { │ │ │ │ │ - var geometry = this.feature.geometry; │ │ │ │ │ - var bounds = geometry.getBounds(); │ │ │ │ │ - var center = bounds.getCenterLonLat(); │ │ │ │ │ - var originGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - center.lon, center.lat │ │ │ │ │ - ); │ │ │ │ │ - var radiusGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - bounds.right, bounds.bottom │ │ │ │ │ - ); │ │ │ │ │ - var radius = new OpenLayers.Feature.Vector(radiusGeometry); │ │ │ │ │ - var resize = (this.mode & OpenLayers.Control.ModifyFeature.RESIZE); │ │ │ │ │ - var reshape = (this.mode & OpenLayers.Control.ModifyFeature.RESHAPE); │ │ │ │ │ - var rotate = (this.mode & OpenLayers.Control.ModifyFeature.ROTATE); │ │ │ │ │ - │ │ │ │ │ - radiusGeometry.move = function(x, y) { │ │ │ │ │ - OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ - var dx1 = this.x - originGeometry.x; │ │ │ │ │ - var dy1 = this.y - originGeometry.y; │ │ │ │ │ - var dx0 = dx1 - x; │ │ │ │ │ - var dy0 = dy1 - y; │ │ │ │ │ - if (rotate) { │ │ │ │ │ - var a0 = Math.atan2(dy0, dx0); │ │ │ │ │ - var a1 = Math.atan2(dy1, dx1); │ │ │ │ │ - var angle = a1 - a0; │ │ │ │ │ - angle *= 180 / Math.PI; │ │ │ │ │ - geometry.rotate(angle, originGeometry); │ │ │ │ │ + manageTileCache: function(evt) { │ │ │ │ │ + var tile = evt.object; │ │ │ │ │ + var img = this.tileCache[tile.url]; │ │ │ │ │ + if (img) { │ │ │ │ │ + // if image is on its layer's backbuffer, remove it from backbuffer │ │ │ │ │ + if (img.parentNode && │ │ │ │ │ + OpenLayers.Element.hasClass(img.parentNode, 'olBackBuffer')) { │ │ │ │ │ + img.parentNode.removeChild(img); │ │ │ │ │ + img.id = null; │ │ │ │ │ } │ │ │ │ │ - if (resize) { │ │ │ │ │ - var scale, ratio; │ │ │ │ │ - // 'resize' together with 'reshape' implies that the aspect │ │ │ │ │ - // ratio of the geometry will not be preserved whilst resizing │ │ │ │ │ - if (reshape) { │ │ │ │ │ - scale = dy1 / dy0; │ │ │ │ │ - ratio = (dx1 / dx0) / scale; │ │ │ │ │ - } else { │ │ │ │ │ - var l0 = Math.sqrt((dx0 * dx0) + (dy0 * dy0)); │ │ │ │ │ - var l1 = Math.sqrt((dx1 * dx1) + (dy1 * dy1)); │ │ │ │ │ - scale = l1 / l0; │ │ │ │ │ - } │ │ │ │ │ - geometry.resize(scale, originGeometry, ratio); │ │ │ │ │ + // only use image from cache if it is not on a layer already │ │ │ │ │ + if (!img.parentNode) { │ │ │ │ │ + img.style.visibility = 'hidden'; │ │ │ │ │ + img.style.opacity = 0; │ │ │ │ │ + tile.setImage(img); │ │ │ │ │ + // LRU - move tile to the end of the array to mark it as the most │ │ │ │ │ + // recently used │ │ │ │ │ + OpenLayers.Util.removeItem(this.tileCacheIndex, tile.url); │ │ │ │ │ + this.tileCacheIndex.push(tile.url); │ │ │ │ │ } │ │ │ │ │ - }; │ │ │ │ │ - radius._sketch = true; │ │ │ │ │ - this.radiusHandle = radius; │ │ │ │ │ - this.radiusHandle.renderIntent = this.vertexRenderIntent; │ │ │ │ │ - this.layer.addFeatures([this.radiusHandle], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control and all handlers. │ │ │ │ │ + * Method: addToCache │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} The control's map. │ │ │ │ │ + * evt - {Object} Listener argument for the tile's loadend event │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.handlers.drag.setMap(map); │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + addToCache: function(evt) { │ │ │ │ │ + var tile = evt.object; │ │ │ │ │ + if (!this.tileCache[tile.url]) { │ │ │ │ │ + if (!OpenLayers.Element.hasClass(tile.imgDiv, 'olImageLoadError')) { │ │ │ │ │ + if (this.tileCacheIndex.length >= this.cacheSize) { │ │ │ │ │ + delete this.tileCache[this.tileCacheIndex[0]]; │ │ │ │ │ + this.tileCacheIndex.shift(); │ │ │ │ │ + } │ │ │ │ │ + this.tileCache[tile.url] = tile.imgDiv; │ │ │ │ │ + this.tileCacheIndex.push(tile.url); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleMapEvents │ │ │ │ │ - * │ │ │ │ │ + * Method: clearTileQueue │ │ │ │ │ + * Clears the tile queue from tiles of a specific layer │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ + * evt - {Object} Listener argument of the layer's retile event │ │ │ │ │ */ │ │ │ │ │ - handleMapEvents: function(evt) { │ │ │ │ │ - if (evt.type == "removelayer" || evt.property == "order") { │ │ │ │ │ - this.moveLayerToTop(); │ │ │ │ │ + clearTileQueue: function(evt) { │ │ │ │ │ + var layer = evt.object; │ │ │ │ │ + var tileQueue = this.tileQueue[layer.map.id]; │ │ │ │ │ + for (var i = tileQueue.length - 1; i >= 0; --i) { │ │ │ │ │ + if (tileQueue[i].layer === layer) { │ │ │ │ │ + tileQueue.splice(i, 1); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveLayerToTop │ │ │ │ │ - * Moves the layer for this handler to the top, so mouse events can reach │ │ │ │ │ - * it. │ │ │ │ │ - */ │ │ │ │ │ - moveLayerToTop: function() { │ │ │ │ │ - var index = Math.max(this.map.Z_INDEX_BASE['Feature'] - 1, │ │ │ │ │ - this.layer.getZIndex()) + 1; │ │ │ │ │ - this.layer.setZIndex(index); │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveLayerBack │ │ │ │ │ - * Moves the layer back to the position determined by the map's layers │ │ │ │ │ - * array. │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ - moveLayerBack: function() { │ │ │ │ │ - var index = this.layer.getZIndex() - 1; │ │ │ │ │ - if (index >= this.map.Z_INDEX_BASE['Feature']) { │ │ │ │ │ - this.layer.setZIndex(index); │ │ │ │ │ - } else { │ │ │ │ │ - this.map.setLayerZIndex(this.layer, │ │ │ │ │ - this.map.getLayerIndex(this.layer)); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var i = this.maps.length - 1; i >= 0; --i) { │ │ │ │ │ + this.removeMap(this.maps[i]); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ + this.maps = null; │ │ │ │ │ + this.tileQueue = null; │ │ │ │ │ + this.tileQueueId = null; │ │ │ │ │ + this.tileCache = null; │ │ │ │ │ + this.tileCacheIndex = null; │ │ │ │ │ + this._destroyed = true; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ModifyFeature" │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Constant: RESHAPE │ │ │ │ │ - * {Integer} Constant used to make the control work in reshape mode │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ModifyFeature.RESHAPE = 1; │ │ │ │ │ -/** │ │ │ │ │ - * Constant: RESIZE │ │ │ │ │ - * {Integer} Constant used to make the control work in resize mode │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ModifyFeature.RESIZE = 2; │ │ │ │ │ -/** │ │ │ │ │ - * Constant: ROTATE │ │ │ │ │ - * {Integer} Constant used to make the control work in rotate mode │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ModifyFeature.ROTATE = 4; │ │ │ │ │ -/** │ │ │ │ │ - * Constant: DRAG │ │ │ │ │ - * {Integer} Constant used to make the control work in drag mode │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ModifyFeature.DRAG = 8; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Attribution.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/Control.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Attribution │ │ │ │ │ - * The attribution control adds attribution from layers to the map display. │ │ │ │ │ - * It uses 'attribution' property of each layer. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Rule │ │ │ │ │ + * This class represents an SLD Rule, as being used for rule-based SLD styling. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Attribution = │ │ │ │ │ - OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: separator │ │ │ │ │ - * {String} String used to separate layers. │ │ │ │ │ - */ │ │ │ │ │ - separator: ", ", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: template │ │ │ │ │ - * {String} Template for the attribution. This has to include the substring │ │ │ │ │ - * "${layers}", which will be replaced by the layer specific │ │ │ │ │ - * attributions, separated by . The default is "${layers}". │ │ │ │ │ - */ │ │ │ │ │ - template: "${layers}", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Attribution │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Options for control. │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Destroy control. │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - "removelayer": this.updateAttribution, │ │ │ │ │ - "addlayer": this.updateAttribution, │ │ │ │ │ - "changelayer": this.updateAttribution, │ │ │ │ │ - "changebaselayer": this.updateAttribution, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Initialize control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ - */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - 'changebaselayer': this.updateAttribution, │ │ │ │ │ - 'changelayer': this.updateAttribution, │ │ │ │ │ - 'addlayer': this.updateAttribution, │ │ │ │ │ - 'removelayer': this.updateAttribution, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - this.updateAttribution(); │ │ │ │ │ - │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: updateAttribution │ │ │ │ │ - * Update attribution string. │ │ │ │ │ - */ │ │ │ │ │ - updateAttribution: function() { │ │ │ │ │ - var attributions = []; │ │ │ │ │ - if (this.map && this.map.layers) { │ │ │ │ │ - for (var i = 0, len = this.map.layers.length; i < len; i++) { │ │ │ │ │ - var layer = this.map.layers[i]; │ │ │ │ │ - if (layer.attribution && layer.getVisibility()) { │ │ │ │ │ - // add attribution only if attribution text is unique │ │ │ │ │ - if (OpenLayers.Util.indexOf( │ │ │ │ │ - attributions, layer.attribution) === -1) { │ │ │ │ │ - attributions.push(layer.attribution); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.div.innerHTML = OpenLayers.String.format(this.template, { │ │ │ │ │ - layers: attributions.join(this.separator) │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +OpenLayers.Rule = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Attribution" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Events/buttonclick.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique id for this session. │ │ │ │ │ + */ │ │ │ │ │ + id: 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: name │ │ │ │ │ + * {String} name of this rule │ │ │ │ │ + */ │ │ │ │ │ + name: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: title │ │ │ │ │ + * {String} Title of this rule (set if included in SLD) │ │ │ │ │ + */ │ │ │ │ │ + title: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * 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.Events.buttonclick = OpenLayers.Class({ │ │ │ │ │ + /** │ │ │ │ │ + * Property: description │ │ │ │ │ + * {String} Description of this rule (set if abstract is included in SLD) │ │ │ │ │ + */ │ │ │ │ │ + description: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: target │ │ │ │ │ - * {} The events instance that the buttonclick event will │ │ │ │ │ - * be triggered on. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - target: null, │ │ │ │ │ + context: 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. │ │ │ │ │ + * Property: filter │ │ │ │ │ + * {} Optional filter for the rule. │ │ │ │ │ */ │ │ │ │ │ - events: [ │ │ │ │ │ - 'mousedown', 'mouseup', 'click', 'dblclick', │ │ │ │ │ - 'touchstart', 'touchmove', 'touchend', 'keydown' │ │ │ │ │ - ], │ │ │ │ │ + filter: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: startRegEx │ │ │ │ │ - * {RegExp} Regular expression to test Event.type for events that start │ │ │ │ │ - * a buttonclick sequence. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - startRegEx: /^mousedown|touchstart$/, │ │ │ │ │ + elseFilter: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: cancelRegEx │ │ │ │ │ - * {RegExp} Regular expression to test Event.type for events that cancel │ │ │ │ │ - * a buttonclick sequence. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - cancelRegEx: /^touchmove$/, │ │ │ │ │ + symbolizer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: completeRegEx │ │ │ │ │ - * {RegExp} Regular expression to test Event.type for events that complete │ │ │ │ │ - * a buttonclick sequence. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - completeRegEx: /^mouseup|touchend$/, │ │ │ │ │ + symbolizers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: startEvt │ │ │ │ │ - * {Event} The event that started the click sequence │ │ │ │ │ + * 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, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * 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/Control/LayerSwitcher.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Lang.js │ │ │ │ │ - * @requires OpenLayers/Util.js │ │ │ │ │ - * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.LayerSwitcher │ │ │ │ │ - * The LayerSwitcher control displays a table of contents for the map. This │ │ │ │ │ - * allows the user interface to switch between BaseLasyers and to show or hide │ │ │ │ │ - * Overlays. By default the switcher is shown minimized on the right edge of │ │ │ │ │ - * the map, the user may expand it by clicking on the handle. │ │ │ │ │ - * │ │ │ │ │ - * To create the LayerSwitcher outside of the map, pass the Id of a html div │ │ │ │ │ - * as the first argument to the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Symbolizer │ │ │ │ │ + * Base class representing a symbolizer used for feature rendering. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layerStates │ │ │ │ │ - * {Array(Object)} Basically a copy of the "state" of the map's layers │ │ │ │ │ - * the last time the control was drawn. We have this in order to avoid │ │ │ │ │ - * unnecessarily redrawing the control. │ │ │ │ │ - */ │ │ │ │ │ - layerStates: null, │ │ │ │ │ +OpenLayers.Symbolizer = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - // DOM Elements │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layersDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - layersDiv: null, │ │ │ │ │ + zIndex: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: baseLayersDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - baseLayersDiv: null, │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Util.extend(this, config); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: baseLayers │ │ │ │ │ - * {Array(Object)} │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: clone │ │ │ │ │ + * Create a copy of this symbolizer. │ │ │ │ │ + * │ │ │ │ │ + * Returns a symbolizer of the same type with the same properties. │ │ │ │ │ */ │ │ │ │ │ - baseLayers: null, │ │ │ │ │ + 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, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: dataLbl │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - dataLbl: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: dataLayersDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * APIProperty: strokeOpacity │ │ │ │ │ + * {Number} Stroke opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - dataLayersDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: dataLayers │ │ │ │ │ - * {Array(Object)} │ │ │ │ │ + * APIProperty: strokeWidth │ │ │ │ │ + * {Number} Pixel stroke width. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - dataLayers: null, │ │ │ │ │ - │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: minimizeDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * APIProperty: strokeLinecap │ │ │ │ │ + * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - minimizeDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: maximizeDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - maximizeDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: ascending │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * APIProperty: fillColor │ │ │ │ │ + * {String} RGB hex fill color (e.g. "#ff0000" for red). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - ascending: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.LayerSwitcher │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * APIProperty: fillOpacity │ │ │ │ │ + * {Number} Fill opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.layerStates = []; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + * APIProperty: pointRadius │ │ │ │ │ + * {Number} Pixel point radius. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - │ │ │ │ │ - //clear out layers info and unregister their events │ │ │ │ │ - this.clearLayersArray("base"); │ │ │ │ │ - this.clearLayersArray("data"); │ │ │ │ │ - │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - buttonclick: this.onButtonClick, │ │ │ │ │ - addlayer: this.redraw, │ │ │ │ │ - changelayer: this.redraw, │ │ │ │ │ - removelayer: this.redraw, │ │ │ │ │ - changebaselayer: this.redraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - this.events.unregister("buttonclick", this, this.onButtonClick); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * │ │ │ │ │ - * Properties: │ │ │ │ │ - * map - {} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - addlayer: this.redraw, │ │ │ │ │ - changelayer: this.redraw, │ │ │ │ │ - removelayer: this.redraw, │ │ │ │ │ - changebaselayer: this.redraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - if (this.outsideViewport) { │ │ │ │ │ - this.events.attachToElement(this.div); │ │ │ │ │ - this.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ - } else { │ │ │ │ │ - this.map.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} A reference to the DIV DOMElement containing the │ │ │ │ │ - * switcher tabs. │ │ │ │ │ + * APIProperty: graphicWidth │ │ │ │ │ + * {Number} Pixel width for sizing an external graphic. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this); │ │ │ │ │ - │ │ │ │ │ - // create layout divs │ │ │ │ │ - this.loadContents(); │ │ │ │ │ - │ │ │ │ │ - // set mode to minimize │ │ │ │ │ - if (!this.outsideViewport) { │ │ │ │ │ - this.minimizeControl(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // populate div with current info │ │ │ │ │ - this.redraw(); │ │ │ │ │ - │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onButtonClick │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * APIProperty: graphicHeight │ │ │ │ │ + * {Number} Pixel height for sizing an external graphic. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - onButtonClick: function(evt) { │ │ │ │ │ - var button = evt.buttonElement; │ │ │ │ │ - if (button === this.minimizeDiv) { │ │ │ │ │ - this.minimizeControl(); │ │ │ │ │ - } else if (button === this.maximizeDiv) { │ │ │ │ │ - this.maximizeControl(); │ │ │ │ │ - } else if (button._layerSwitcher === this.id) { │ │ │ │ │ - if (button["for"]) { │ │ │ │ │ - button = document.getElementById(button["for"]); │ │ │ │ │ - } │ │ │ │ │ - if (!button.disabled) { │ │ │ │ │ - if (button.type == "radio") { │ │ │ │ │ - button.checked = true; │ │ │ │ │ - this.map.setBaseLayer(this.map.getLayer(button._layer)); │ │ │ │ │ - } else { │ │ │ │ │ - button.checked = !button.checked; │ │ │ │ │ - this.updateMap(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clearLayersArray │ │ │ │ │ - * User specifies either "base" or "data". we then clear all the │ │ │ │ │ - * corresponding listeners, the div, and reinitialize a new array. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layersType - {String} │ │ │ │ │ + * APIProperty: graphicOpacity │ │ │ │ │ + * {Number} Opacity (0-1) for an external graphic. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - clearLayersArray: function(layersType) { │ │ │ │ │ - this[layersType + "LayersDiv"].innerHTML = ""; │ │ │ │ │ - this[layersType + "Layers"] = []; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: checkRedraw │ │ │ │ │ - * Checks if the layer state has changed since the last redraw() call. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The layer state changed since the last redraw() call. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - checkRedraw: function() { │ │ │ │ │ - if (!this.layerStates.length || │ │ │ │ │ - (this.map.layers.length != this.layerStates.length)) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - for (var i = 0, len = this.layerStates.length; i < len; i++) { │ │ │ │ │ - var layerState = this.layerStates[i]; │ │ │ │ │ - var layer = this.map.layers[i]; │ │ │ │ │ - if ((layerState.name != layer.name) || │ │ │ │ │ - (layerState.inRange != layer.inRange) || │ │ │ │ │ - (layerState.id != layer.id) || │ │ │ │ │ - (layerState.visibility != layer.visibility)) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: redraw │ │ │ │ │ - * Goes through and takes the current state of the Map and rebuilds the │ │ │ │ │ - * control to display that state. Groups base layers into a │ │ │ │ │ - * radio-button group and lists each data layer with a checkbox. │ │ │ │ │ + * 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: │ │ │ │ │ - * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ + * A new point symbolizer. │ │ │ │ │ */ │ │ │ │ │ - redraw: function() { │ │ │ │ │ - //if the state hasn't changed since last redraw, no need │ │ │ │ │ - // to do anything. Just return the existing div. │ │ │ │ │ - if (!this.checkRedraw()) { │ │ │ │ │ - return this.div; │ │ │ │ │ - } │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //clear out previous layers │ │ │ │ │ - this.clearLayersArray("base"); │ │ │ │ │ - this.clearLayersArray("data"); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Point" │ │ │ │ │ │ │ │ │ │ - var containsOverlays = false; │ │ │ │ │ - var containsBaseLayers = false; │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - // Save state -- for checking layer if the map state changed. │ │ │ │ │ - // We save this before redrawing, because in the process of redrawing │ │ │ │ │ - // we will trigger more visibility changes, and we want to not redraw │ │ │ │ │ - // and enter an infinite loop. │ │ │ │ │ - var len = this.map.layers.length; │ │ │ │ │ - this.layerStates = new Array(len); │ │ │ │ │ - for (var i = 0; i < len; i++) { │ │ │ │ │ - var layer = this.map.layers[i]; │ │ │ │ │ - this.layerStates[i] = { │ │ │ │ │ - 'name': layer.name, │ │ │ │ │ - 'visibility': layer.visibility, │ │ │ │ │ - 'inRange': layer.inRange, │ │ │ │ │ - 'id': layer.id │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Symbolizer/Line.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - var layers = this.map.layers.slice(); │ │ │ │ │ - if (!this.ascending) { │ │ │ │ │ - layers.reverse(); │ │ │ │ │ - } │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - var layer = layers[i]; │ │ │ │ │ - var baseLayer = layer.isBaseLayer; │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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 (layer.displayInLayerSwitcher) { │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Symbolizer.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (baseLayer) { │ │ │ │ │ - containsBaseLayers = true; │ │ │ │ │ - } else { │ │ │ │ │ - containsOverlays = true; │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Line │ │ │ │ │ + * A symbolizer used to render line features. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Symbolizer.Line = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ - // only check a baselayer if it is *the* baselayer, check data │ │ │ │ │ - // layers if they are visible │ │ │ │ │ - var checked = (baseLayer) ? (layer == this.map.baseLayer) : │ │ │ │ │ - layer.getVisibility(); │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - // create input element │ │ │ │ │ - var inputElem = document.createElement("input"), │ │ │ │ │ - // The input shall have an id attribute so we can use │ │ │ │ │ - // labels to interact with them. │ │ │ │ │ - inputId = OpenLayers.Util.createUniqueID( │ │ │ │ │ - this.id + "_input_" │ │ │ │ │ - ); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: strokeOpacity │ │ │ │ │ + * {Number} Stroke opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - inputElem.id = inputId; │ │ │ │ │ - inputElem.name = (baseLayer) ? this.id + "_baseLayers" : layer.name; │ │ │ │ │ - inputElem.type = (baseLayer) ? "radio" : "checkbox"; │ │ │ │ │ - inputElem.value = layer.name; │ │ │ │ │ - inputElem.checked = checked; │ │ │ │ │ - inputElem.defaultChecked = checked; │ │ │ │ │ - inputElem.className = "olButton"; │ │ │ │ │ - inputElem._layer = layer.id; │ │ │ │ │ - inputElem._layerSwitcher = this.id; │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: strokeWidth │ │ │ │ │ + * {Number} Pixel stroke width. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (!baseLayer && !layer.inRange) { │ │ │ │ │ - inputElem.disabled = true; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: strokeLinecap │ │ │ │ │ + * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - // create span │ │ │ │ │ - var labelSpan = document.createElement("label"); │ │ │ │ │ - // this isn't the DOM attribute 'for', but an arbitrary name we │ │ │ │ │ - // use to find the appropriate input element in │ │ │ │ │ - labelSpan["for"] = inputElem.id; │ │ │ │ │ - OpenLayers.Element.addClass(labelSpan, "labelSpan olButton"); │ │ │ │ │ - labelSpan._layer = layer.id; │ │ │ │ │ - labelSpan._layerSwitcher = this.id; │ │ │ │ │ - if (!baseLayer && !layer.inRange) { │ │ │ │ │ - labelSpan.style.color = "gray"; │ │ │ │ │ - } │ │ │ │ │ - labelSpan.innerHTML = layer.name; │ │ │ │ │ - labelSpan.style.verticalAlign = (baseLayer) ? "bottom" : │ │ │ │ │ - "baseline"; │ │ │ │ │ - // create line break │ │ │ │ │ - var br = document.createElement("br"); │ │ │ │ │ + /** │ │ │ │ │ + * 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); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var groupArray = (baseLayer) ? this.baseLayers : │ │ │ │ │ - this.dataLayers; │ │ │ │ │ - groupArray.push({ │ │ │ │ │ - 'layer': layer, │ │ │ │ │ - 'inputElem': inputElem, │ │ │ │ │ - 'labelSpan': labelSpan │ │ │ │ │ - }); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Line" │ │ │ │ │ │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - var groupDiv = (baseLayer) ? this.baseLayersDiv : │ │ │ │ │ - this.dataLayersDiv; │ │ │ │ │ - groupDiv.appendChild(inputElem); │ │ │ │ │ - groupDiv.appendChild(labelSpan); │ │ │ │ │ - groupDiv.appendChild(br); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Symbolizer/Polygon.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - // if no overlays, dont display the overlay label │ │ │ │ │ - this.dataLbl.style.display = (containsOverlays) ? "" : "none"; │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - // if no baselayers, dont display the baselayer label │ │ │ │ │ - this.baseLbl.style.display = (containsBaseLayers) ? "" : "none"; │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Symbolizer.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Polygon │ │ │ │ │ + * A symbolizer used to render line features. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Symbolizer.Polygon = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateMap │ │ │ │ │ - * Cycles through the loaded data and base layer input arrays and makes │ │ │ │ │ - * the necessary calls to the Map object such that that the map's │ │ │ │ │ - * visual state corresponds to what the user has selected in │ │ │ │ │ - * the control. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - updateMap: function() { │ │ │ │ │ - │ │ │ │ │ - // set the newly selected base layer │ │ │ │ │ - for (var i = 0, len = this.baseLayers.length; i < len; i++) { │ │ │ │ │ - var layerEntry = this.baseLayers[i]; │ │ │ │ │ - if (layerEntry.inputElem.checked) { │ │ │ │ │ - this.map.setBaseLayer(layerEntry.layer, false); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - // set the correct visibilities for the overlays │ │ │ │ │ - for (var i = 0, len = this.dataLayers.length; i < len; i++) { │ │ │ │ │ - var layerEntry = this.dataLayers[i]; │ │ │ │ │ - layerEntry.layer.setVisibility(layerEntry.inputElem.checked); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: maximizeControl │ │ │ │ │ - * Set up the labels and divs for the control │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * e - {Event} │ │ │ │ │ + * APIProperty: strokeLinecap │ │ │ │ │ + * {String} Stroke cap type ("butt", "round", or "square"). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - maximizeControl: function(e) { │ │ │ │ │ │ │ │ │ │ - // set the div's width and height to empty values, so │ │ │ │ │ - // the div dimensions can be controlled by CSS │ │ │ │ │ - this.div.style.width = ""; │ │ │ │ │ - this.div.style.height = ""; │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.showControls(false); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fillColor │ │ │ │ │ + * {String} RGB hex fill color (e.g. "#ff0000" for red). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (e != null) { │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fillOpacity │ │ │ │ │ + * {Number} Fill opacity (0-1). │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: minimizeControl │ │ │ │ │ - * Hide all the contents of the control, shrink the size, │ │ │ │ │ - * add the maximize icon │ │ │ │ │ + * Constructor: OpenLayers.Symbolizer.Polygon │ │ │ │ │ + * Create a symbolizer for rendering polygons. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * e - {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 polygon symbolizer. │ │ │ │ │ */ │ │ │ │ │ - minimizeControl: function(e) { │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Symbolizer.prototype.initialize.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // to minimize the control we set its div's width │ │ │ │ │ - // and height to 0px, we cannot just set "display" │ │ │ │ │ - // to "none" because it would hide the maximize │ │ │ │ │ - // div │ │ │ │ │ - this.div.style.width = "0px"; │ │ │ │ │ - this.div.style.height = "0px"; │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Polygon" │ │ │ │ │ │ │ │ │ │ - this.showControls(true); │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - if (e != null) { │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Symbolizer/Text.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: showControls │ │ │ │ │ - * Hide/Show all LayerSwitcher controls depending on whether we are │ │ │ │ │ - * minimized or not │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * minimize - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - showControls: function(minimize) { │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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.maximizeDiv.style.display = minimize ? "" : "none"; │ │ │ │ │ - this.minimizeDiv.style.display = minimize ? "none" : ""; │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Symbolizer.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.layersDiv.style.display = minimize ? "none" : ""; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Symbolizer.Text │ │ │ │ │ + * A symbolizer used to render text labels for features. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Symbolizer.Text = OpenLayers.Class(OpenLayers.Symbolizer, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: loadContents │ │ │ │ │ - * Set up the labels and divs for the control │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: label │ │ │ │ │ + * {String} The text for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ */ │ │ │ │ │ - loadContents: function() { │ │ │ │ │ │ │ │ │ │ - // layers list div │ │ │ │ │ - this.layersDiv = document.createElement("div"); │ │ │ │ │ - this.layersDiv.id = this.id + "_layersDiv"; │ │ │ │ │ - OpenLayers.Element.addClass(this.layersDiv, "layersDiv"); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fontFamily │ │ │ │ │ + * {String} The font family for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.baseLbl = document.createElement("div"); │ │ │ │ │ - this.baseLbl.innerHTML = OpenLayers.i18n("Base Layer"); │ │ │ │ │ - OpenLayers.Element.addClass(this.baseLbl, "baseLbl"); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fontSize │ │ │ │ │ + * {String} The font size for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.baseLayersDiv = document.createElement("div"); │ │ │ │ │ - OpenLayers.Element.addClass(this.baseLayersDiv, "baseLayersDiv"); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: fontWeight │ │ │ │ │ + * {String} The font weight for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.dataLbl = document.createElement("div"); │ │ │ │ │ - this.dataLbl.innerHTML = OpenLayers.i18n("Overlays"); │ │ │ │ │ - OpenLayers.Element.addClass(this.dataLbl, "dataLbl"); │ │ │ │ │ + /** │ │ │ │ │ + * Property: fontStyle │ │ │ │ │ + * {String} The font style for the label. │ │ │ │ │ + * │ │ │ │ │ + * No default set here. Use OpenLayers.Renderer.defaultRenderer for defaults. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.dataLayersDiv = document.createElement("div"); │ │ │ │ │ - OpenLayers.Element.addClass(this.dataLayersDiv, "dataLayersDiv"); │ │ │ │ │ + /** │ │ │ │ │ + * 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); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.ascending) { │ │ │ │ │ - this.layersDiv.appendChild(this.baseLbl); │ │ │ │ │ - this.layersDiv.appendChild(this.baseLayersDiv); │ │ │ │ │ - this.layersDiv.appendChild(this.dataLbl); │ │ │ │ │ - this.layersDiv.appendChild(this.dataLayersDiv); │ │ │ │ │ - } else { │ │ │ │ │ - this.layersDiv.appendChild(this.dataLbl); │ │ │ │ │ - this.layersDiv.appendChild(this.dataLayersDiv); │ │ │ │ │ - this.layersDiv.appendChild(this.baseLbl); │ │ │ │ │ - this.layersDiv.appendChild(this.baseLayersDiv); │ │ │ │ │ - } │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Text" │ │ │ │ │ │ │ │ │ │ - this.div.appendChild(this.layersDiv); │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - // maximize button div │ │ │ │ │ - var img = OpenLayers.Util.getImageLocation('layer-switcher-maximize.png'); │ │ │ │ │ - this.maximizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ - "OpenLayers_Control_MaximizeDiv", │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - img, │ │ │ │ │ - "absolute"); │ │ │ │ │ - OpenLayers.Element.addClass(this.maximizeDiv, "maximizeDiv olButton"); │ │ │ │ │ - this.maximizeDiv.style.display = "none"; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Symbolizer/Raster.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - this.div.appendChild(this.maximizeDiv); │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - // minimize button div │ │ │ │ │ - var img = OpenLayers.Util.getImageLocation('layer-switcher-minimize.png'); │ │ │ │ │ - this.minimizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ - "OpenLayers_Control_MinimizeDiv", │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - img, │ │ │ │ │ - "absolute"); │ │ │ │ │ - OpenLayers.Element.addClass(this.minimizeDiv, "minimizeDiv olButton"); │ │ │ │ │ - this.minimizeDiv.style.display = "none"; │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Symbolizer.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.div.appendChild(this.minimizeDiv); │ │ │ │ │ +/** │ │ │ │ │ + * 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.Control.LayerSwitcher" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Symbolizer.Raster" │ │ │ │ │ + │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/KeyboardDefaults.js │ │ │ │ │ + OpenLayers/Style2.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Keyboard.js │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Rule.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer/Point.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer/Line.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer/Polygon.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer/Text.js │ │ │ │ │ + * @requires OpenLayers/Symbolizer/Raster.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.KeyboardDefaults │ │ │ │ │ - * The KeyboardDefaults control adds panning and zooming functions, controlled │ │ │ │ │ - * with the keyboard. By default arrow keys pan, +/- keys zoom & Page Up/Page │ │ │ │ │ - * Down/Home/End scroll by three quarters of a page. │ │ │ │ │ - * │ │ │ │ │ - * This control has no visible appearance. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Style2 │ │ │ │ │ + * This class represents a collection of rules for rendering features. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Style2 = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} A unique id for this session. │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: slideFactor │ │ │ │ │ - * Pixels to slide by. │ │ │ │ │ + * APIProperty: name │ │ │ │ │ + * {String} Style identifier. │ │ │ │ │ */ │ │ │ │ │ - slideFactor: 75, │ │ │ │ │ + name: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: observeElement │ │ │ │ │ - * {DOMelement|String} The DOM element to handle keys for. You │ │ │ │ │ - * can use the map div here, to have the navigation keys │ │ │ │ │ - * work when the map div has the focus. If undefined the │ │ │ │ │ - * document is used. │ │ │ │ │ + * APIProperty: title │ │ │ │ │ + * {String} Title of this style. │ │ │ │ │ */ │ │ │ │ │ - observeElement: null, │ │ │ │ │ + title: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.KeyboardDefaults │ │ │ │ │ + * APIProperty: description │ │ │ │ │ + * {String} Description of this style. │ │ │ │ │ */ │ │ │ │ │ + description: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Create handler. │ │ │ │ │ + * APIProperty: layerName │ │ │ │ │ + * {} Name of the layer that this style belongs to, usually │ │ │ │ │ + * according to the NamedLayer attribute of an SLD document. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var observeElement = this.observeElement || document; │ │ │ │ │ - this.handler = new OpenLayers.Handler.Keyboard(this, { │ │ │ │ │ - "keydown": this.defaultKeyPress │ │ │ │ │ - }, { │ │ │ │ │ - observeElement: observeElement │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + layerName: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultKeyPress │ │ │ │ │ - * When handling the key event, we only use evt.keyCode. This holds │ │ │ │ │ - * some drawbacks, though we get around them below. When interpretting │ │ │ │ │ - * the keycodes below (including the comments associated with them), │ │ │ │ │ - * consult the URL below. For instance, the Safari browser returns │ │ │ │ │ - * "IE keycodes", and so is supported by any keycode labeled "IE". │ │ │ │ │ - * │ │ │ │ │ - * Very informative URL: │ │ │ │ │ - * http://unixpapa.com/js/key.html │ │ │ │ │ + * 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: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - defaultKeyPress: function(evt) { │ │ │ │ │ - var size, handled = true; │ │ │ │ │ + initialize: function(config) { │ │ │ │ │ + OpenLayers.Util.extend(this, config); │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var target = OpenLayers.Event.element(evt); │ │ │ │ │ - if (target && │ │ │ │ │ - (target.tagName == 'INPUT' || │ │ │ │ │ - target.tagName == 'TEXTAREA' || │ │ │ │ │ - target.tagName == 'SELECT')) { │ │ │ │ │ - return; │ │ │ │ │ + /** │ │ │ │ │ + * 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - switch (evt.keyCode) { │ │ │ │ │ - case OpenLayers.Event.KEY_LEFT: │ │ │ │ │ - this.map.pan(-this.slideFactor, 0); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Event.KEY_RIGHT: │ │ │ │ │ - this.map.pan(this.slideFactor, 0); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Event.KEY_UP: │ │ │ │ │ - this.map.pan(0, -this.slideFactor); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Event.KEY_DOWN: │ │ │ │ │ - this.map.pan(0, this.slideFactor); │ │ │ │ │ - break; │ │ │ │ │ - │ │ │ │ │ - case 33: // Page Up. Same in all browsers. │ │ │ │ │ - size = this.map.getSize(); │ │ │ │ │ - this.map.pan(0, -0.75 * size.h); │ │ │ │ │ - break; │ │ │ │ │ - case 34: // Page Down. Same in all browsers. │ │ │ │ │ - size = this.map.getSize(); │ │ │ │ │ - this.map.pan(0, 0.75 * size.h); │ │ │ │ │ - break; │ │ │ │ │ - case 35: // End. Same in all browsers. │ │ │ │ │ - size = this.map.getSize(); │ │ │ │ │ - this.map.pan(0.75 * size.w, 0); │ │ │ │ │ - break; │ │ │ │ │ - case 36: // Home. Same in all browsers. │ │ │ │ │ - size = this.map.getSize(); │ │ │ │ │ - this.map.pan(-0.75 * size.w, 0); │ │ │ │ │ - break; │ │ │ │ │ - │ │ │ │ │ - case 43: // +/= (ASCII), keypad + (ASCII, Opera) │ │ │ │ │ - case 61: // +/= (Mozilla, Opera, some ASCII) │ │ │ │ │ - case 187: // +/= (IE) │ │ │ │ │ - case 107: // keypad + (IE, Mozilla) │ │ │ │ │ - this.map.zoomIn(); │ │ │ │ │ - break; │ │ │ │ │ - case 45: // -/_ (ASCII, Opera), keypad - (ASCII, Opera) │ │ │ │ │ - case 109: // -/_ (Mozilla), keypad - (Mozilla, IE) │ │ │ │ │ - case 189: // -/_ (IE) │ │ │ │ │ - case 95: // -/_ (some ASCII) │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ - break; │ │ │ │ │ - default: │ │ │ │ │ - handled = false; │ │ │ │ │ - } │ │ │ │ │ - if (handled) { │ │ │ │ │ - // prevent browser default not to move the page │ │ │ │ │ - // when moving the page with the keyboard │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ + /** │ │ │ │ │ + * 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.Control.KeyboardDefaults" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Style2" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Point.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/Geometry/Point.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Handler.Point │ │ │ │ │ - * Handler to draw a point on the map. Point is displayed on activation, │ │ │ │ │ - * moves on mouse move, and is finished on mouse up. The handler triggers │ │ │ │ │ - * callbacks for 'done', 'cancel', and 'modify'. The modify callback is │ │ │ │ │ - * called with each change in the sketch and will receive the latest point │ │ │ │ │ - * drawn. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ + * Class: OpenLayers.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.Point = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ +OpenLayers.Renderer = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: point │ │ │ │ │ - * {} The currently drawn point │ │ │ │ │ + /** │ │ │ │ │ + * Property: container │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - point: null, │ │ │ │ │ + container: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} The temporary drawing layer │ │ │ │ │ + * Property: root │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + root: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: multi │ │ │ │ │ - * {Boolean} Cast features to multi-part geometries before passing to the │ │ │ │ │ - * layer. Default is false. │ │ │ │ │ + /** │ │ │ │ │ + * Property: extent │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - multi: false, │ │ │ │ │ + extent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: citeCompliant │ │ │ │ │ - * {Boolean} If set to true, coordinates of features drawn in a map extent │ │ │ │ │ - * crossing the date line won't exceed the world bounds. Default is false. │ │ │ │ │ + * Property: 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. │ │ │ │ │ */ │ │ │ │ │ - citeCompliant: false, │ │ │ │ │ + locked: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: mouseDown │ │ │ │ │ - * {Boolean} The mouse is down │ │ │ │ │ + /** │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - mouseDown: false, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: stoppedDown │ │ │ │ │ - * {Boolean} Indicate whether the last mousedown stopped the event │ │ │ │ │ - * propagation. │ │ │ │ │ + * Property: resolution │ │ │ │ │ + * {Float} cache of current map resolution │ │ │ │ │ */ │ │ │ │ │ - stoppedDown: null, │ │ │ │ │ + resolution: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lastDown │ │ │ │ │ - * {} Location of the last mouse down │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} Reference to the map -- this is set in Vector's setMap() │ │ │ │ │ */ │ │ │ │ │ - lastDown: null, │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lastUp │ │ │ │ │ - * {} │ │ │ │ │ + * Property: featureDx │ │ │ │ │ + * {Number} Feature offset in x direction. Will be calculated for and │ │ │ │ │ + * applied to the current feature while rendering (see │ │ │ │ │ + * ). │ │ │ │ │ */ │ │ │ │ │ - lastUp: null, │ │ │ │ │ + featureDx: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: persist │ │ │ │ │ - * {Boolean} Leave the feature rendered until destroyFeature is called. │ │ │ │ │ - * Default is false. If set to true, the feature remains rendered until │ │ │ │ │ - * destroyFeature is called, typically by deactivating the handler or │ │ │ │ │ - * starting another drawing. │ │ │ │ │ + * Constructor: OpenLayers.Renderer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * containerID - {} │ │ │ │ │ + * options - {Object} options for this renderer. See sublcasses for │ │ │ │ │ + * supported options. │ │ │ │ │ */ │ │ │ │ │ - persist: false, │ │ │ │ │ + initialize: function(containerID, options) { │ │ │ │ │ + this.container = OpenLayers.Util.getElement(containerID); │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: stopDown │ │ │ │ │ - * {Boolean} Stop event propagation on mousedown. Must be false to │ │ │ │ │ - * allow "pan while drawing". Defaults to false. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ - stopDown: false, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.container = null; │ │ │ │ │ + this.extent = null; │ │ │ │ │ + this.size = null; │ │ │ │ │ + this.resolution = null; │ │ │ │ │ + this.map = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIPropery: stopUp │ │ │ │ │ - * {Boolean} Stop event propagation on mouse. Must be false to │ │ │ │ │ - * allow "pan while dragging". Defaults to fase. │ │ │ │ │ + * APIMethod: supported │ │ │ │ │ + * This should be overridden by specific subclasses │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Whether or not the browser supports the renderer class │ │ │ │ │ */ │ │ │ │ │ - stopUp: false, │ │ │ │ │ + supported: function() { │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layerOptions │ │ │ │ │ - * {Object} Any optional properties to be set on the sketch layer. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - layerOptions: 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: pixelTolerance │ │ │ │ │ - * {Number} Maximum number of pixels between down and up (mousedown │ │ │ │ │ - * and mouseup, or touchstart and touchend) for the handler to │ │ │ │ │ - * add a new point. If set to an integer value, if the │ │ │ │ │ - * displacement between down and up is great to this value │ │ │ │ │ - * no point will be added. Default value is 5. │ │ │ │ │ + * Method: 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 - {} │ │ │ │ │ */ │ │ │ │ │ - pixelTolerance: 5, │ │ │ │ │ + setSize: function(size) { │ │ │ │ │ + this.size = size.clone(); │ │ │ │ │ + this.resolution = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: lastTouchPx │ │ │ │ │ - * {} The last pixel used to know the distance between │ │ │ │ │ - * two touches (for double touch). │ │ │ │ │ + /** │ │ │ │ │ + * Method: getResolution │ │ │ │ │ + * Uses cached copy of resolution if available to minimize computing │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The current map's resolution │ │ │ │ │ */ │ │ │ │ │ - lastTouchPx: null, │ │ │ │ │ + getResolution: function() { │ │ │ │ │ + this.resolution = this.resolution || this.map.getResolution(); │ │ │ │ │ + return this.resolution; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Point │ │ │ │ │ - * Create a new point handler. │ │ │ │ │ + * 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: │ │ │ │ │ - * control - {} The control that owns this handler │ │ │ │ │ - * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ - * functions. Various callbacks described below. │ │ │ │ │ - * options - {Object} An optional object with properties to be set on the │ │ │ │ │ - * handler │ │ │ │ │ - * │ │ │ │ │ - * Named callbacks: │ │ │ │ │ - * create - Called when a sketch is first created. Callback called with │ │ │ │ │ - * the creation point geometry and sketch feature. │ │ │ │ │ - * modify - Called with each move of a vertex with the vertex (point) │ │ │ │ │ - * geometry and the sketch feature. │ │ │ │ │ - * done - Called when the point drawing is finished. The callback will │ │ │ │ │ - * recieve a single argument, the point geometry. │ │ │ │ │ - * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ - * cancel callback will receive a geometry. │ │ │ │ │ + * feature - {} │ │ │ │ │ + * style - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} true if the feature has been drawn completely, false if not, │ │ │ │ │ + * undefined if the feature had no geometry │ │ │ │ │ */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - if (!(options && options.layerOptions && options.layerOptions.styleMap)) { │ │ │ │ │ - this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {}); │ │ │ │ │ + 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) { │ │ │ │ │ │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * turn on the 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. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * bounds - {} Bounds of the feature │ │ │ │ │ + * worldBounds - {} Bounds of the world │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (!OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - return false; │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - // create temporary vector layer for rendering geometry sketch │ │ │ │ │ - // TBD: this could be moved to initialize/destroy - setting visibility here │ │ │ │ │ - var options = OpenLayers.Util.extend({ │ │ │ │ │ - displayInLayerSwitcher: false, │ │ │ │ │ - // indicate that the temp vector layer will never be out of range │ │ │ │ │ - // without this, resolution properties must be specified at the │ │ │ │ │ - // map-level for this temporary layer to init its resolutions │ │ │ │ │ - // correctly │ │ │ │ │ - calculateInRange: OpenLayers.Function.True, │ │ │ │ │ - wrapDateLine: this.citeCompliant │ │ │ │ │ - }, this.layerOptions); │ │ │ │ │ - this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); │ │ │ │ │ - this.map.addLayer(this.layer); │ │ │ │ │ - return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: createFeature │ │ │ │ │ - * Add temporary features │ │ │ │ │ + /** │ │ │ │ │ + * Method: drawGeometry │ │ │ │ │ + * │ │ │ │ │ + * Draw a geometry. This should only be called from the renderer itself. │ │ │ │ │ + * Use layer.drawFeature() from outside the renderer. │ │ │ │ │ + * virtual function │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pixel - {} A pixel location on the map. │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * style - {Object} │ │ │ │ │ + * featureId - {} │ │ │ │ │ */ │ │ │ │ │ - createFeature: function(pixel) { │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - var geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - lonlat.lon, lonlat.lat │ │ │ │ │ - ); │ │ │ │ │ - this.point = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ - this.callback("create", [this.point.geometry, this.point]); │ │ │ │ │ - this.point.geometry.clearBounds(); │ │ │ │ │ - this.layer.addFeatures([this.point], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + drawGeometry: function(geometry, style, featureId) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * turn off the handler │ │ │ │ │ + * Method: drawText │ │ │ │ │ + * Function for drawing text labels. │ │ │ │ │ + * This method is only called by the renderer itself. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * featureId - {String} │ │ │ │ │ + * style - │ │ │ │ │ + * location - {} │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (!OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - this.cancel(); │ │ │ │ │ - // If a layer's map property is set to null, it means that that layer │ │ │ │ │ - // isn't added to the map. Since we ourself added the layer to the map │ │ │ │ │ - // in activate(), we can assume that if this.layer.map is null it means │ │ │ │ │ - // that the layer has been destroyed (as a result of map.destroy() for │ │ │ │ │ - // example. │ │ │ │ │ - if (this.layer.map != null) { │ │ │ │ │ - this.destroyFeature(true); │ │ │ │ │ - this.layer.destroy(false); │ │ │ │ │ - } │ │ │ │ │ - this.layer = null; │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ + drawText: function(featureId, style, location) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyFeature │ │ │ │ │ - * Destroy the temporary geometries │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ + * Method: removeText │ │ │ │ │ + * Function for removing text labels. │ │ │ │ │ + * This method is only called by the renderer itself. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * featureId - {String} │ │ │ │ │ */ │ │ │ │ │ - destroyFeature: function(force) { │ │ │ │ │ - if (this.layer && (force || !this.persist)) { │ │ │ │ │ - this.layer.destroyFeatures(); │ │ │ │ │ - } │ │ │ │ │ - this.point = null; │ │ │ │ │ - }, │ │ │ │ │ + removeText: function(featureId) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyPersistedFeature │ │ │ │ │ - * Destroy the persisted feature. │ │ │ │ │ + * Method: clear │ │ │ │ │ + * Clear all vectors from the renderer. │ │ │ │ │ + * virtual function. │ │ │ │ │ */ │ │ │ │ │ - destroyPersistedFeature: function() { │ │ │ │ │ - var layer = this.layer; │ │ │ │ │ - if (layer && layer.features.length > 1) { │ │ │ │ │ - this.layer.features[0].destroy(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + clear: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: finalize │ │ │ │ │ - * Finish the geometry and call the "done" callback. │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * cancel - {Boolean} Call cancel instead of done callback. Default │ │ │ │ │ - * is false. │ │ │ │ │ + * evt - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A feature id or undefined. │ │ │ │ │ */ │ │ │ │ │ - finalize: function(cancel) { │ │ │ │ │ - var key = cancel ? "cancel" : "done"; │ │ │ │ │ - this.mouseDown = false; │ │ │ │ │ - this.lastDown = null; │ │ │ │ │ - this.lastUp = null; │ │ │ │ │ - this.lastTouchPx = null; │ │ │ │ │ - this.callback(key, [this.geometryClone()]); │ │ │ │ │ - this.destroyFeature(cancel); │ │ │ │ │ - }, │ │ │ │ │ + getFeatureIdFromEvent: function(evt) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Finish the geometry and call the "cancel" callback. │ │ │ │ │ + * Method: eraseFeatures │ │ │ │ │ + * This is called by the layer to erase features │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * features - {Array()} │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - this.finalize(true); │ │ │ │ │ + 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: click │ │ │ │ │ - * Handle clicks. Clicks are stopped from propagating to other listeners │ │ │ │ │ - * on map.events or other dom elements. │ │ │ │ │ + * Method: eraseGeometry │ │ │ │ │ + * Remove a geometry from the renderer (by id). │ │ │ │ │ + * virtual function. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * featureId - {String} │ │ │ │ │ */ │ │ │ │ │ - click: function(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ + eraseGeometry: function(geometry, featureId) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: dblclick │ │ │ │ │ - * Handle double-clicks. Double-clicks are stopped from propagating to other │ │ │ │ │ - * listeners on map.events or other dom elements. │ │ │ │ │ + * 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: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * renderer - {} target renderer for the moved root │ │ │ │ │ */ │ │ │ │ │ - dblclick: function(evt) { │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - return false; │ │ │ │ │ + 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: modifyFeature │ │ │ │ │ - * Modify the existing geometry given a pixel location. │ │ │ │ │ - * │ │ │ │ │ + * Method: applyDefaultSymbolizer │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pixel - {} A pixel location on the map. │ │ │ │ │ + * symbolizer - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} │ │ │ │ │ */ │ │ │ │ │ - modifyFeature: function(pixel) { │ │ │ │ │ - if (!this.point) { │ │ │ │ │ - this.createFeature(pixel); │ │ │ │ │ + applyDefaultSymbolizer: function(symbolizer) { │ │ │ │ │ + var result = OpenLayers.Util.extend({}, │ │ │ │ │ + OpenLayers.Renderer.defaultSymbolizer); │ │ │ │ │ + if (symbolizer.stroke === false) { │ │ │ │ │ + delete result.strokeWidth; │ │ │ │ │ + delete result.strokeColor; │ │ │ │ │ } │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - this.point.geometry.x = lonlat.lon; │ │ │ │ │ - this.point.geometry.y = lonlat.lat; │ │ │ │ │ - this.callback("modify", [this.point.geometry, this.point, false]); │ │ │ │ │ - this.point.geometry.clearBounds(); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ + 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({ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ - * Render features on the temporary layer. │ │ │ │ │ + * Property: format │ │ │ │ │ + * {} The format used by this protocol. │ │ │ │ │ */ │ │ │ │ │ - drawFeature: function() { │ │ │ │ │ - this.layer.drawFeature(this.point, this.style); │ │ │ │ │ - }, │ │ │ │ │ + format: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getGeometry │ │ │ │ │ - * Return the sketch geometry. If is true, this will return │ │ │ │ │ - * a multi-part geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} Any options sent to the constructor. │ │ │ │ │ */ │ │ │ │ │ - getGeometry: function() { │ │ │ │ │ - var geometry = this.point && this.point.geometry; │ │ │ │ │ - if (geometry && this.multi) { │ │ │ │ │ - geometry = new OpenLayers.Geometry.MultiPoint([geometry]); │ │ │ │ │ - } │ │ │ │ │ - return geometry; │ │ │ │ │ - }, │ │ │ │ │ + options: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: geometryClone │ │ │ │ │ - * Return a clone of the relevant geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Property: autoDestroy │ │ │ │ │ + * {Boolean} The creator of the protocol can set autoDestroy to false │ │ │ │ │ + * to fully control when the protocol is destroyed. Defaults to │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - geometryClone: function() { │ │ │ │ │ - var geom = this.getGeometry(); │ │ │ │ │ - return geom && geom.clone(); │ │ │ │ │ - }, │ │ │ │ │ + autoDestroy: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousedown │ │ │ │ │ - * Handle mousedown. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Property: defaultFilter │ │ │ │ │ + * {} Optional default filter to read requests │ │ │ │ │ */ │ │ │ │ │ - mousedown: function(evt) { │ │ │ │ │ - return this.down(evt); │ │ │ │ │ - }, │ │ │ │ │ + defaultFilter: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * Constructor: OpenLayers.Protocol │ │ │ │ │ + * Abstract class for vector protocols. Create instances of a subclass. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - this.startTouch(); │ │ │ │ │ - this.lastTouchPx = evt.xy; │ │ │ │ │ - return this.down(evt); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ + this.options = options; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mousemove │ │ │ │ │ - * Handle mousemove. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * Method: mergeWithDefaultFilter │ │ │ │ │ + * Merge filter passed to the read method with the default one │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Parameters: │ │ │ │ │ + * filter - {} │ │ │ │ │ */ │ │ │ │ │ - mousemove: function(evt) { │ │ │ │ │ - return this.move(evt); │ │ │ │ │ + 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: touchmove │ │ │ │ │ - * Handle touchmove. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Clean up the protocol. │ │ │ │ │ */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - this.lastTouchPx = evt.xy; │ │ │ │ │ - return this.move(evt); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.options = null; │ │ │ │ │ + this.format = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mouseup │ │ │ │ │ - * Handle mouseup. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Construct a request for reading new features. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * options - {Object} Optional object for configuring the request. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An │ │ │ │ │ + * object, the same object will be passed to the callback function passed │ │ │ │ │ + * if one exists in the options object. │ │ │ │ │ */ │ │ │ │ │ - mouseup: function(evt) { │ │ │ │ │ - return this.up(evt); │ │ │ │ │ + read: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + options.filter = this.mergeWithDefaultFilter(options.filter); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Handle touchend. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: create │ │ │ │ │ + * Construct a request for writing newly created features. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * features - {Array({})} or │ │ │ │ │ + * {} │ │ │ │ │ + * options - {Object} Optional object for configuring the request. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An │ │ │ │ │ + * object, the same object will be passed to the callback function passed │ │ │ │ │ + * if one exists in the options object. │ │ │ │ │ */ │ │ │ │ │ - touchend: function(evt) { │ │ │ │ │ - evt.xy = this.lastTouchPx; │ │ │ │ │ - return this.up(evt); │ │ │ │ │ - }, │ │ │ │ │ + create: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: down │ │ │ │ │ - * Handle mousedown and touchstart. Adjust the geometry and redraw. │ │ │ │ │ - * Return determines whether to propagate the event on the map. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: update │ │ │ │ │ + * Construct a request updating modified features. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * features - {Array({})} or │ │ │ │ │ + * {} │ │ │ │ │ + * options - {Object} Optional object for configuring the request. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An │ │ │ │ │ + * object, the same object will be passed to the callback function passed │ │ │ │ │ + * if one exists in the options object. │ │ │ │ │ */ │ │ │ │ │ - down: function(evt) { │ │ │ │ │ - this.mouseDown = true; │ │ │ │ │ - this.lastDown = evt.xy; │ │ │ │ │ - if (!this.touch) { // no point displayed until up on touch devices │ │ │ │ │ - this.modifyFeature(evt.xy); │ │ │ │ │ - } │ │ │ │ │ - this.stoppedDown = this.stopDown; │ │ │ │ │ - return !this.stopDown; │ │ │ │ │ - }, │ │ │ │ │ + update: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Handle mousemove and touchmove. Adjust the geometry and redraw. │ │ │ │ │ - * Return determines whether to propagate the event on the map. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: delete │ │ │ │ │ + * Construct a request deleting a removed feature. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * feature - {} │ │ │ │ │ + * options - {Object} Optional object for configuring the request. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An │ │ │ │ │ + * object, the same object will be passed to the callback function passed │ │ │ │ │ + * if one exists in the options object. │ │ │ │ │ */ │ │ │ │ │ - move: function(evt) { │ │ │ │ │ - if (!this.touch // no point displayed until up on touch devices │ │ │ │ │ - && │ │ │ │ │ - (!this.mouseDown || this.stoppedDown)) { │ │ │ │ │ - this.modifyFeature(evt.xy); │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ + "delete": function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: up │ │ │ │ │ - * Handle mouseup and touchend. Send the latest point in the geometry to the control. │ │ │ │ │ - * Return determines whether to propagate the event on the map. │ │ │ │ │ + * APIMethod: commit │ │ │ │ │ + * Go over the features and for each take action │ │ │ │ │ + * based on the feature state. Possible actions are create, │ │ │ │ │ + * update and delete. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * features - {Array({})} │ │ │ │ │ + * options - {Object} Object whose possible keys are "create", "update", │ │ │ │ │ + * "delete", "callback" and "scope", the values referenced by the │ │ │ │ │ + * first three are objects as passed to the "create", "update", and │ │ │ │ │ + * "delete" methods, the value referenced by the "callback" key is │ │ │ │ │ + * a function which is called when the commit operation is complete │ │ │ │ │ + * using the scope referenced by the "scope" key. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array({})} An array of │ │ │ │ │ + * objects. │ │ │ │ │ */ │ │ │ │ │ - up: function(evt) { │ │ │ │ │ - this.mouseDown = false; │ │ │ │ │ - this.stoppedDown = this.stopDown; │ │ │ │ │ - │ │ │ │ │ - // check keyboard modifiers │ │ │ │ │ - if (!this.checkModifiers(evt)) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - // ignore double-clicks │ │ │ │ │ - if (this.lastUp && this.lastUp.equals(evt.xy)) { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - if (this.lastDown && this.passesTolerance(this.lastDown, evt.xy, │ │ │ │ │ - this.pixelTolerance)) { │ │ │ │ │ - if (this.touch) { │ │ │ │ │ - this.modifyFeature(evt.xy); │ │ │ │ │ - } │ │ │ │ │ - if (this.persist) { │ │ │ │ │ - this.destroyPersistedFeature(); │ │ │ │ │ - } │ │ │ │ │ - this.lastUp = evt.xy; │ │ │ │ │ - this.finalize(); │ │ │ │ │ - return !this.stopUp; │ │ │ │ │ - } else { │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + commit: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mouseout │ │ │ │ │ - * Handle mouse out. For better user experience reset mouseDown │ │ │ │ │ - * and stoppedDown when the mouse leaves the map viewport. │ │ │ │ │ + * Method: abort │ │ │ │ │ + * Abort an ongoing request. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * response - {} │ │ │ │ │ */ │ │ │ │ │ - mouseout: function(evt) { │ │ │ │ │ - if (OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ - this.stoppedDown = this.stopDown; │ │ │ │ │ - this.mouseDown = false; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + abort: function(response) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: passesTolerance │ │ │ │ │ - * Determine whether the event is within the optional pixel tolerance. │ │ │ │ │ + * Method: createCallback │ │ │ │ │ + * Returns a function that applies the given public method with resp and │ │ │ │ │ + * options arguments. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The event is within the pixel tolerance (if specified). │ │ │ │ │ + * Parameters: │ │ │ │ │ + * method - {Function} The method to be applied by the callback. │ │ │ │ │ + * response - {} The protocol response object. │ │ │ │ │ + * options - {Object} Options sent to the protocol method │ │ │ │ │ */ │ │ │ │ │ - passesTolerance: function(pixel1, pixel2, tolerance) { │ │ │ │ │ - var passes = true; │ │ │ │ │ - │ │ │ │ │ - if (tolerance != null && pixel1 && pixel2) { │ │ │ │ │ - var dist = pixel1.distanceTo(pixel2); │ │ │ │ │ - if (dist > tolerance) { │ │ │ │ │ - passes = false; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return passes; │ │ │ │ │ + createCallback: function(method, response, options) { │ │ │ │ │ + return OpenLayers.Function.bind(function() { │ │ │ │ │ + method.apply(this, [response, options]); │ │ │ │ │ + }, this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Point" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Protocol" │ │ │ │ │ }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Path.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler/Point.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ - */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Handler.Path │ │ │ │ │ - * Handler to draw a path on the map. Path is displayed on mouse down, │ │ │ │ │ - * moves on mouse move, and is finished on mouse up. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Protocol.Response │ │ │ │ │ + * Protocols return Response objects to their users. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { │ │ │ │ │ - │ │ │ │ │ +OpenLayers.Protocol.Response = OpenLayers.Class({ │ │ │ │ │ /** │ │ │ │ │ - * Property: line │ │ │ │ │ - * {} │ │ │ │ │ + * Property: code │ │ │ │ │ + * {Number} - OpenLayers.Protocol.Response.SUCCESS or │ │ │ │ │ + * OpenLayers.Protocol.Response.FAILURE │ │ │ │ │ */ │ │ │ │ │ - line: null, │ │ │ │ │ + code: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxVertices │ │ │ │ │ - * {Number} The maximum number of vertices which can be drawn by this │ │ │ │ │ - * handler. When the number of vertices reaches maxVertices, the │ │ │ │ │ - * geometry is automatically finalized. Default is null. │ │ │ │ │ + * Property: requestType │ │ │ │ │ + * {String} The type of request this response corresponds to. Either │ │ │ │ │ + * "create", "read", "update" or "delete". │ │ │ │ │ */ │ │ │ │ │ - maxVertices: null, │ │ │ │ │ + requestType: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: doubleTouchTolerance │ │ │ │ │ - * {Number} Maximum number of pixels between two touches for │ │ │ │ │ - * the gesture to be considered a "finalize feature" action. │ │ │ │ │ - * Default is 20. │ │ │ │ │ + * Property: last │ │ │ │ │ + * {Boolean} - true if this is the last response expected in a commit, │ │ │ │ │ + * false otherwise, defaults to true. │ │ │ │ │ */ │ │ │ │ │ - doubleTouchTolerance: 20, │ │ │ │ │ + last: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: freehand │ │ │ │ │ - * {Boolean} In freehand mode, the handler starts the path on mouse down, │ │ │ │ │ - * adds a point for every mouse move, and finishes the path on mouse up. │ │ │ │ │ - * Outside of freehand mode, a point is added to the path on every mouse │ │ │ │ │ - * click and double-click finishes the path. │ │ │ │ │ + * Property: 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. │ │ │ │ │ */ │ │ │ │ │ - freehand: false, │ │ │ │ │ + features: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: freehandToggle │ │ │ │ │ - * {String} If set, freehandToggle is checked on mouse events and will set │ │ │ │ │ - * the freehand mode to the opposite of this.freehand. To disallow │ │ │ │ │ - * toggling between freehand and non-freehand mode, set freehandToggle to │ │ │ │ │ - * null. Acceptable toggle values are 'shiftKey', 'ctrlKey', and 'altKey'. │ │ │ │ │ + * Property: 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. │ │ │ │ │ */ │ │ │ │ │ - freehandToggle: 'shiftKey', │ │ │ │ │ + data: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: timerId │ │ │ │ │ - * {Integer} The timer used to test the double touch. │ │ │ │ │ + * Property: reqFeatures │ │ │ │ │ + * {Array({})} or {} │ │ │ │ │ + * The features provided by the user and placed in the request by the │ │ │ │ │ + * protocol. │ │ │ │ │ */ │ │ │ │ │ - timerId: null, │ │ │ │ │ + reqFeatures: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: redoStack │ │ │ │ │ - * {Array} Stack containing points removed with . │ │ │ │ │ + * Property: priv │ │ │ │ │ */ │ │ │ │ │ - redoStack: null, │ │ │ │ │ + priv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Path │ │ │ │ │ - * Create a new path hander │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control that owns this handler │ │ │ │ │ - * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ - * functions. Various callbacks described below. │ │ │ │ │ - * options - {Object} An optional object with properties to be set on the │ │ │ │ │ - * handler │ │ │ │ │ - * │ │ │ │ │ - * Named callbacks: │ │ │ │ │ - * create - Called when a sketch is first created. Callback called with │ │ │ │ │ - * the creation point geometry and sketch feature. │ │ │ │ │ - * modify - Called with each move of a vertex with the vertex (point) │ │ │ │ │ - * geometry and the sketch feature. │ │ │ │ │ - * point - Called as each point is added. Receives the new point geometry. │ │ │ │ │ - * done - Called when the point drawing is finished. The callback will │ │ │ │ │ - * recieve a single argument, the linestring geometry. │ │ │ │ │ - * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ - * cancel callback will receive a geometry. │ │ │ │ │ + * Property: error │ │ │ │ │ + * {Object} The error object in case a service exception was encountered. │ │ │ │ │ */ │ │ │ │ │ + error: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createFeature │ │ │ │ │ - * Add temporary geometries │ │ │ │ │ + * Constructor: OpenLayers.Protocol.Response │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pixel - {} The initial pixel location for the new │ │ │ │ │ - * feature. │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * instance. │ │ │ │ │ */ │ │ │ │ │ - createFeature: function(pixel) { │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - var geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - lonlat.lon, lonlat.lat │ │ │ │ │ - ); │ │ │ │ │ - this.point = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ - this.line = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.LineString([this.point.geometry]) │ │ │ │ │ - ); │ │ │ │ │ - this.callback("create", [this.point.geometry, this.getSketch()]); │ │ │ │ │ - this.point.geometry.clearBounds(); │ │ │ │ │ - this.layer.addFeatures([this.line, this.point], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyFeature │ │ │ │ │ - * Destroy temporary geometries │ │ │ │ │ + * Method: success │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} - true on success, false otherwise │ │ │ │ │ */ │ │ │ │ │ - destroyFeature: function(force) { │ │ │ │ │ - OpenLayers.Handler.Point.prototype.destroyFeature.call( │ │ │ │ │ - this, force); │ │ │ │ │ - this.line = null; │ │ │ │ │ + success: function() { │ │ │ │ │ + return this.code > 0; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroyPersistedFeature │ │ │ │ │ - * Destroy the persisted feature. │ │ │ │ │ - */ │ │ │ │ │ - destroyPersistedFeature: function() { │ │ │ │ │ - var layer = this.layer; │ │ │ │ │ - if (layer && layer.features.length > 2) { │ │ │ │ │ - this.layer.features[0].destroy(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Protocol.Response" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removePoint │ │ │ │ │ - * Destroy the temporary point. │ │ │ │ │ - */ │ │ │ │ │ - removePoint: function() { │ │ │ │ │ - if (this.point) { │ │ │ │ │ - this.layer.removeFeatures([this.point]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +OpenLayers.Protocol.Response.SUCCESS = 1; │ │ │ │ │ +OpenLayers.Protocol.Response.FAILURE = 0; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Kinetic.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: addPoint │ │ │ │ │ - * Add point to geometry. Send the point index to override │ │ │ │ │ - * the behavior of LinearRing that disregards adding duplicate points. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} The pixel location for the new point. │ │ │ │ │ - */ │ │ │ │ │ - addPoint: function(pixel) { │ │ │ │ │ - this.layer.removeFeatures([this.point]); │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - this.point = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat) │ │ │ │ │ - ); │ │ │ │ │ - this.line.geometry.addComponent( │ │ │ │ │ - this.point.geometry, this.line.geometry.components.length │ │ │ │ │ - ); │ │ │ │ │ - this.layer.addFeatures([this.point]); │ │ │ │ │ - this.callback("point", [this.point.geometry, this.getGeometry()]); │ │ │ │ │ - this.callback("modify", [this.point.geometry, this.getSketch()]); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ - delete this.redoStack; │ │ │ │ │ - }, │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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: insertXY │ │ │ │ │ - * Insert a point in the current sketch given x & y coordinates. The new │ │ │ │ │ - * point is inserted immediately before the most recently drawn point. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * x - {Number} The x-coordinate of the point. │ │ │ │ │ - * y - {Number} The y-coordinate of the point. │ │ │ │ │ - */ │ │ │ │ │ - insertXY: function(x, y) { │ │ │ │ │ - this.line.geometry.addComponent( │ │ │ │ │ - new OpenLayers.Geometry.Point(x, y), │ │ │ │ │ - this.getCurrentPointIndex() │ │ │ │ │ - ); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ - delete this.redoStack; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Animation.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: insertDeltaXY │ │ │ │ │ - * Insert a point given offsets from the previously inserted point. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * dx - {Number} The x-coordinate offset of the point. │ │ │ │ │ - * dy - {Number} The y-coordinate offset of the point. │ │ │ │ │ - */ │ │ │ │ │ - insertDeltaXY: function(dx, dy) { │ │ │ │ │ - var previousIndex = this.getCurrentPointIndex() - 1; │ │ │ │ │ - var p0 = this.line.geometry.components[previousIndex]; │ │ │ │ │ - if (p0 && !isNaN(p0.x) && !isNaN(p0.y)) { │ │ │ │ │ - this.insertXY(p0.x + dx, p0.y + dy); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +OpenLayers.Kinetic = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: insertDirectionLength │ │ │ │ │ - * Insert a point in the current sketch given a direction and a length. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * direction - {Number} Degrees clockwise from the positive x-axis. │ │ │ │ │ - * length - {Number} Distance from the previously drawn point. │ │ │ │ │ + * Property: threshold │ │ │ │ │ + * In most cases changing the threshold isn't needed. │ │ │ │ │ + * In px/ms, default to 0. │ │ │ │ │ */ │ │ │ │ │ - insertDirectionLength: function(direction, length) { │ │ │ │ │ - direction *= Math.PI / 180; │ │ │ │ │ - var dx = length * Math.cos(direction); │ │ │ │ │ - var dy = length * Math.sin(direction); │ │ │ │ │ - this.insertDeltaXY(dx, dy); │ │ │ │ │ - }, │ │ │ │ │ + threshold: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: insertDeflectionLength │ │ │ │ │ - * Insert a point in the current sketch given a deflection and a length. │ │ │ │ │ - * The deflection should be degrees clockwise from the previously │ │ │ │ │ - * digitized segment. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * deflection - {Number} Degrees clockwise from the previous segment. │ │ │ │ │ - * length - {Number} Distance from the previously drawn point. │ │ │ │ │ + * Property: deceleration │ │ │ │ │ + * {Float} the deseleration in px/ms², default to 0.0035. │ │ │ │ │ */ │ │ │ │ │ - insertDeflectionLength: function(deflection, length) { │ │ │ │ │ - var previousIndex = this.getCurrentPointIndex() - 1; │ │ │ │ │ - if (previousIndex > 0) { │ │ │ │ │ - var p1 = this.line.geometry.components[previousIndex]; │ │ │ │ │ - var p0 = this.line.geometry.components[previousIndex - 1]; │ │ │ │ │ - var theta = Math.atan2(p1.y - p0.y, p1.x - p0.x); │ │ │ │ │ - this.insertDirectionLength( │ │ │ │ │ - (theta * 180 / Math.PI) + deflection, length │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + deceleration: 0.0035, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getCurrentPointIndex │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} The index of the most recently drawn point. │ │ │ │ │ + * Property: nbPoints │ │ │ │ │ + * {Integer} the number of points we use to calculate the kinetic │ │ │ │ │ + * initial values. │ │ │ │ │ */ │ │ │ │ │ - getCurrentPointIndex: function() { │ │ │ │ │ - return this.line.geometry.components.length - 1; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ + nbPoints: 100, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: undo │ │ │ │ │ - * Remove the most recently added point in the sketch geometry. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} A point was removed. │ │ │ │ │ + * Property: delay │ │ │ │ │ + * {Float} time to consider to calculate the kinetic initial values. │ │ │ │ │ + * In ms, default to 200. │ │ │ │ │ */ │ │ │ │ │ - undo: function() { │ │ │ │ │ - var geometry = this.line.geometry; │ │ │ │ │ - var components = geometry.components; │ │ │ │ │ - var index = this.getCurrentPointIndex() - 1; │ │ │ │ │ - var target = components[index]; │ │ │ │ │ - var undone = geometry.removeComponent(target); │ │ │ │ │ - if (undone) { │ │ │ │ │ - // On touch devices, set the current ("mouse location") point to │ │ │ │ │ - // match the last digitized point. │ │ │ │ │ - if (this.touch && index > 0) { │ │ │ │ │ - components = geometry.components; // safety │ │ │ │ │ - var lastpt = components[index - 1]; │ │ │ │ │ - var curptidx = this.getCurrentPointIndex(); │ │ │ │ │ - var curpt = components[curptidx]; │ │ │ │ │ - curpt.x = lastpt.x; │ │ │ │ │ - curpt.y = lastpt.y; │ │ │ │ │ - } │ │ │ │ │ - if (!this.redoStack) { │ │ │ │ │ - this.redoStack = []; │ │ │ │ │ - } │ │ │ │ │ - this.redoStack.push(target); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ - } │ │ │ │ │ - return undone; │ │ │ │ │ - }, │ │ │ │ │ + delay: 200, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: redo │ │ │ │ │ - * Reinsert the most recently removed point resulting from an call. │ │ │ │ │ - * The undo stack is deleted whenever a point is added by other means. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} A point was added. │ │ │ │ │ + * Property: points │ │ │ │ │ + * List of points use to calculate the kinetic initial values. │ │ │ │ │ */ │ │ │ │ │ - redo: function() { │ │ │ │ │ - var target = this.redoStack && this.redoStack.pop(); │ │ │ │ │ - if (target) { │ │ │ │ │ - this.line.geometry.addComponent(target, this.getCurrentPointIndex()); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ - } │ │ │ │ │ - return !!target; │ │ │ │ │ - }, │ │ │ │ │ + points: undefined, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: freehandMode │ │ │ │ │ - * Determine whether to behave in freehand mode or not. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} │ │ │ │ │ + * Property: timerId │ │ │ │ │ + * ID of the timer. │ │ │ │ │ */ │ │ │ │ │ - freehandMode: function(evt) { │ │ │ │ │ - return (this.freehandToggle && evt[this.freehandToggle]) ? │ │ │ │ │ - !this.freehand : this.freehand; │ │ │ │ │ - }, │ │ │ │ │ + timerId: undefined, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: modifyFeature │ │ │ │ │ - * Modify the existing geometry given the new point │ │ │ │ │ + * Constructor: OpenLayers.Kinetic │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pixel - {} The updated pixel location for the latest │ │ │ │ │ - * point. │ │ │ │ │ - * drawing - {Boolean} Indicate if we're currently drawing. │ │ │ │ │ - */ │ │ │ │ │ - modifyFeature: function(pixel, drawing) { │ │ │ │ │ - if (!this.line) { │ │ │ │ │ - this.createFeature(pixel); │ │ │ │ │ - } │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - this.point.geometry.x = lonlat.lon; │ │ │ │ │ - this.point.geometry.y = lonlat.lat; │ │ │ │ │ - this.callback("modify", [this.point.geometry, this.getSketch(), drawing]); │ │ │ │ │ - this.point.geometry.clearBounds(); │ │ │ │ │ - this.drawFeature(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ - * Render geometries on the temporary layer. │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - drawFeature: function() { │ │ │ │ │ - this.layer.drawFeature(this.line, this.style); │ │ │ │ │ - this.layer.drawFeature(this.point, this.style); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getSketch │ │ │ │ │ - * Return the sketch feature. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Method: begin │ │ │ │ │ + * Begins the dragging. │ │ │ │ │ */ │ │ │ │ │ - getSketch: function() { │ │ │ │ │ - return this.line; │ │ │ │ │ + begin: function() { │ │ │ │ │ + OpenLayers.Animation.stop(this.timerId); │ │ │ │ │ + this.timerId = undefined; │ │ │ │ │ + this.points = []; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getGeometry │ │ │ │ │ - * Return the sketch geometry. If is true, this will return │ │ │ │ │ - * a multi-part geometry. │ │ │ │ │ + * Method: update │ │ │ │ │ + * Updates during the dragging. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * xy - {} The new position. │ │ │ │ │ */ │ │ │ │ │ - getGeometry: function() { │ │ │ │ │ - var geometry = this.line && this.line.geometry; │ │ │ │ │ - if (geometry && this.multi) { │ │ │ │ │ - geometry = new OpenLayers.Geometry.MultiLineString([geometry]); │ │ │ │ │ + update: function(xy) { │ │ │ │ │ + this.points.unshift({ │ │ │ │ │ + xy: xy, │ │ │ │ │ + tick: new Date().getTime() │ │ │ │ │ + }); │ │ │ │ │ + if (this.points.length > this.nbPoints) { │ │ │ │ │ + this.points.pop(); │ │ │ │ │ } │ │ │ │ │ - return geometry; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * method: touchstart │ │ │ │ │ - * handle touchstart. │ │ │ │ │ - * │ │ │ │ │ - * parameters: │ │ │ │ │ - * evt - {event} the browser event │ │ │ │ │ + * Method: end │ │ │ │ │ + * Ends the dragging, start the kinetic. │ │ │ │ │ * │ │ │ │ │ - * returns: │ │ │ │ │ - * {boolean} allow event propagation │ │ │ │ │ - */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - if (this.timerId && │ │ │ │ │ - this.passesTolerance(this.lastTouchPx, evt.xy, │ │ │ │ │ - this.doubleTouchTolerance)) { │ │ │ │ │ - // double-tap, finalize the geometry │ │ │ │ │ - this.finishGeometry(); │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - return false; │ │ │ │ │ - } else { │ │ │ │ │ - if (this.timerId) { │ │ │ │ │ - window.clearTimeout(this.timerId); │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - } │ │ │ │ │ - this.timerId = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(function() { │ │ │ │ │ - this.timerId = null; │ │ │ │ │ - }, this), 300); │ │ │ │ │ - return OpenLayers.Handler.Point.prototype.touchstart.call(this, evt); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: down │ │ │ │ │ - * Handle mousedown and touchstart. Add a new point to the geometry and │ │ │ │ │ - * render it. Return determines whether to propagate the event on the map. │ │ │ │ │ - * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * xy - {} The last position. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - down: function(evt) { │ │ │ │ │ - var stopDown = this.stopDown; │ │ │ │ │ - if (this.freehandMode(evt)) { │ │ │ │ │ - stopDown = true; │ │ │ │ │ - if (this.touch) { │ │ │ │ │ - this.modifyFeature(evt.xy, !!this.lastUp); │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ + 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 (!this.touch && (!this.lastDown || │ │ │ │ │ - !this.passesTolerance(this.lastDown, evt.xy, │ │ │ │ │ - this.pixelTolerance))) { │ │ │ │ │ - this.modifyFeature(evt.xy, !!this.lastUp); │ │ │ │ │ + if (!last) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - this.mouseDown = true; │ │ │ │ │ - this.lastDown = evt.xy; │ │ │ │ │ - this.stoppedDown = stopDown; │ │ │ │ │ - return !stopDown; │ │ │ │ │ + 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 │ │ │ │ │ - * Handle mousemove and touchmove. Adjust the geometry and redraw. │ │ │ │ │ - * Return determines whether to propagate the event on the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ + * Launch the kinetic move pan. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ + * 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(evt) { │ │ │ │ │ - if (this.stoppedDown && this.freehandMode(evt)) { │ │ │ │ │ - if (this.persist) { │ │ │ │ │ - this.destroyPersistedFeature(); │ │ │ │ │ - } │ │ │ │ │ - if (this.maxVertices && this.line && │ │ │ │ │ - this.line.geometry.components.length === this.maxVertices) { │ │ │ │ │ - this.removePoint(); │ │ │ │ │ - this.finalize(); │ │ │ │ │ - } else { │ │ │ │ │ - this.addPoint(evt.xy); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - if (!this.touch && (!this.mouseDown || this.stoppedDown)) { │ │ │ │ │ - this.modifyFeature(evt.xy, !!this.lastUp); │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: up │ │ │ │ │ - * Handle mouseup and touchend. Send the latest point in the geometry to │ │ │ │ │ - * the control. Return determines whether to propagate the event on the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ - */ │ │ │ │ │ - up: function(evt) { │ │ │ │ │ - if (this.mouseDown && (!this.lastUp || !this.lastUp.equals(evt.xy))) { │ │ │ │ │ - if (this.stoppedDown && this.freehandMode(evt)) { │ │ │ │ │ - if (this.persist) { │ │ │ │ │ - this.destroyPersistedFeature(); │ │ │ │ │ - } │ │ │ │ │ - this.removePoint(); │ │ │ │ │ - this.finalize(); │ │ │ │ │ - } else { │ │ │ │ │ - if (this.passesTolerance(this.lastDown, evt.xy, │ │ │ │ │ - this.pixelTolerance)) { │ │ │ │ │ - if (this.touch) { │ │ │ │ │ - this.modifyFeature(evt.xy); │ │ │ │ │ - } │ │ │ │ │ - if (this.lastUp == null && this.persist) { │ │ │ │ │ - this.destroyPersistedFeature(); │ │ │ │ │ - } │ │ │ │ │ - this.addPoint(evt.xy); │ │ │ │ │ - this.lastUp = evt.xy; │ │ │ │ │ - if (this.line.geometry.components.length === this.maxVertices + 1) { │ │ │ │ │ - this.finishGeometry(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - this.stoppedDown = this.stopDown; │ │ │ │ │ - this.mouseDown = false; │ │ │ │ │ - return !this.stopUp; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: finishGeometry │ │ │ │ │ - * Finish the geometry and send it back to the control. │ │ │ │ │ - */ │ │ │ │ │ - finishGeometry: function() { │ │ │ │ │ - var index = this.line.geometry.components.length - 1; │ │ │ │ │ - this.line.geometry.removeComponent(this.line.geometry.components[index]); │ │ │ │ │ - this.removePoint(); │ │ │ │ │ - this.finalize(); │ │ │ │ │ - }, │ │ │ │ │ + args.x = x - lastX; │ │ │ │ │ + args.y = y - lastY; │ │ │ │ │ + lastX = x; │ │ │ │ │ + lastY = y; │ │ │ │ │ + callback(args.x, args.y, args.end); │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: dblclick │ │ │ │ │ - * Handle double-clicks. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} The browser event │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow event propagation │ │ │ │ │ - */ │ │ │ │ │ - dblclick: function(evt) { │ │ │ │ │ - if (!this.freehandMode(evt)) { │ │ │ │ │ - this.finishGeometry(); │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ + this.timerId = OpenLayers.Animation.start( │ │ │ │ │ + OpenLayers.Function.bind(timerCallback, this) │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Path" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Kinetic" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/Vector.js │ │ │ │ │ + OpenLayers/Popup.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Layer.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. │ │ │ │ │ + * Class: OpenLayers.Popup │ │ │ │ │ + * A popup is a small div that can opened and closed on the map. │ │ │ │ │ + * Typically opened in response to clicking on a marker. │ │ │ │ │ + * See . Popup's don't require their own │ │ │ │ │ + * layer and are added the the map using the │ │ │ │ │ + * method. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Example: │ │ │ │ │ + * (code) │ │ │ │ │ + * popup = new OpenLayers.Popup("chicken", │ │ │ │ │ + * new OpenLayers.LonLat(5,40), │ │ │ │ │ + * new OpenLayers.Size(200,200), │ │ │ │ │ + * "example popup", │ │ │ │ │ + * true); │ │ │ │ │ + * │ │ │ │ │ + * map.addPopup(popup); │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ +OpenLayers.Popup = 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: events │ │ │ │ │ + * {} custom event manager │ │ │ │ │ */ │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} The layer is a base layer. Default is false. Set this property │ │ │ │ │ - * in the layer options. │ │ │ │ │ + /** Property: id │ │ │ │ │ + * {String} the unique identifier assigned to this popup. │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: false, │ │ │ │ │ + id: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: lonlat │ │ │ │ │ + * {} the position of this popup on the map │ │ │ │ │ */ │ │ │ │ │ - isFixed: false, │ │ │ │ │ + lonlat: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: features │ │ │ │ │ - * {Array()} │ │ │ │ │ + * Property: div │ │ │ │ │ + * {DOMElement} the div that contains this popup. │ │ │ │ │ */ │ │ │ │ │ - features: null, │ │ │ │ │ + div: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: filter │ │ │ │ │ - * {} The filter set in this layer, │ │ │ │ │ - * a strategy launching read requests can combined │ │ │ │ │ - * this filter with its own filter. │ │ │ │ │ + * Property: contentSize │ │ │ │ │ + * {} the width and height of the content. │ │ │ │ │ */ │ │ │ │ │ - filter: null, │ │ │ │ │ + contentSize: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: selectedFeatures │ │ │ │ │ - * {Array()} │ │ │ │ │ + * Property: size │ │ │ │ │ + * {} the width and height of the popup. │ │ │ │ │ */ │ │ │ │ │ - selectedFeatures: null, │ │ │ │ │ + size: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: unrenderedFeatures │ │ │ │ │ - * {Object} hash of features, keyed by feature.id, that the renderer │ │ │ │ │ - * failed to draw │ │ │ │ │ + /** │ │ │ │ │ + * Property: contentHTML │ │ │ │ │ + * {String} An HTML string for this popup to display. │ │ │ │ │ */ │ │ │ │ │ - unrenderedFeatures: null, │ │ │ │ │ + contentHTML: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: reportError │ │ │ │ │ - * {Boolean} report friendly error message when loading of renderer │ │ │ │ │ - * fails. │ │ │ │ │ + /** │ │ │ │ │ + * Property: backgroundColor │ │ │ │ │ + * {String} the background color used by the popup. │ │ │ │ │ */ │ │ │ │ │ - reportError: true, │ │ │ │ │ + backgroundColor: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: style │ │ │ │ │ - * {Object} Default style for the layer │ │ │ │ │ + * Property: opacity │ │ │ │ │ + * {float} the opacity of this popup (between 0.0 and 1.0) │ │ │ │ │ */ │ │ │ │ │ - style: null, │ │ │ │ │ + opacity: "", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: styleMap │ │ │ │ │ - * {} │ │ │ │ │ + /** │ │ │ │ │ + * Property: border │ │ │ │ │ + * {String} the border size of the popup. (eg 2px) │ │ │ │ │ */ │ │ │ │ │ - styleMap: null, │ │ │ │ │ + border: "", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: strategies │ │ │ │ │ - * {Array(})} Optional list of strategies for the layer. │ │ │ │ │ + /** │ │ │ │ │ + * Property: contentDiv │ │ │ │ │ + * {DOMElement} a reference to the element that holds the content of │ │ │ │ │ + * the div. │ │ │ │ │ */ │ │ │ │ │ - strategies: null, │ │ │ │ │ + contentDiv: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: protocol │ │ │ │ │ - * {} Optional protocol for the layer. │ │ │ │ │ + /** │ │ │ │ │ + * Property: groupDiv │ │ │ │ │ + * {DOMElement} First and only child of 'div'. The group Div contains the │ │ │ │ │ + * 'contentDiv' and the 'closeDiv'. │ │ │ │ │ */ │ │ │ │ │ - protocol: null, │ │ │ │ │ + groupDiv: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + /** │ │ │ │ │ + * Property: closeDiv │ │ │ │ │ + * {DOMElement} the optional closer image │ │ │ │ │ */ │ │ │ │ │ - renderers: ['SVG', 'VML', 'Canvas'], │ │ │ │ │ + closeDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: renderer │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: autoSize │ │ │ │ │ + * {Boolean} Resize the popup to auto-fit the contents. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - renderer: null, │ │ │ │ │ + autoSize: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: rendererOptions │ │ │ │ │ - * {Object} Options for the renderer. See {} for │ │ │ │ │ - * supported options. │ │ │ │ │ + * APIProperty: minSize │ │ │ │ │ + * {} Minimum size allowed for the popup's contents. │ │ │ │ │ */ │ │ │ │ │ - rendererOptions: null, │ │ │ │ │ + minSize: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxSize │ │ │ │ │ + * {} Maximum size allowed for the popup's contents. │ │ │ │ │ + */ │ │ │ │ │ + maxSize: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: displayClass │ │ │ │ │ + * {String} The CSS class of the popup. │ │ │ │ │ */ │ │ │ │ │ - geometryType: null, │ │ │ │ │ + displayClass: "olPopup", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: drawn │ │ │ │ │ - * {Boolean} Whether the Vector Layer features have been drawn yet. │ │ │ │ │ + * Property: contentDisplayClass │ │ │ │ │ + * {String} The CSS class of the popup content div. │ │ │ │ │ */ │ │ │ │ │ - drawn: false, │ │ │ │ │ + contentDisplayClass: "olPopupContent", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: padding │ │ │ │ │ + * {int or } An extra opportunity to specify internal │ │ │ │ │ + * padding of the content div inside the popup. This was originally │ │ │ │ │ + * confused with the css padding as specified in style.css's │ │ │ │ │ + * 'olPopupContent' class. We would like to get rid of this altogether, │ │ │ │ │ + * except that it does come in handy for the framed and anchoredbubble │ │ │ │ │ + * popups, who need to maintain yet another barrier between their │ │ │ │ │ + * content and the outer border of the popup itself. │ │ │ │ │ + * │ │ │ │ │ + * Note that in order to not break API, we must continue to support │ │ │ │ │ + * this property being set as an integer. Really, though, we'd like to │ │ │ │ │ + * have this specified as a Bounds object so that user can specify │ │ │ │ │ + * distinct left, top, right, bottom paddings. With the 3.0 release │ │ │ │ │ + * we can make this only a bounds. │ │ │ │ │ */ │ │ │ │ │ - ratio: 1, │ │ │ │ │ + padding: 0, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.Vector │ │ │ │ │ - * Create a new vector layer │ │ │ │ │ - * │ │ │ │ │ - * 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 │ │ │ │ │ + /** │ │ │ │ │ + * Property: disableFirefoxOverflowHack │ │ │ │ │ + * {Boolean} The hack for overflow in Firefox causes all elements │ │ │ │ │ + * to be re-drawn, which causes Flash elements to be │ │ │ │ │ + * re-initialized, which is troublesome. │ │ │ │ │ + * With this property the hack can be disabled. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, options) { │ │ │ │ │ - OpenLayers.Layer.prototype.initialize.apply(this, arguments); │ │ │ │ │ + disableFirefoxOverflowHack: false, │ │ │ │ │ │ │ │ │ │ - // allow user-set renderer, otherwise assign one │ │ │ │ │ - if (!this.renderer || !this.renderer.supported()) { │ │ │ │ │ - this.assignRenderer(); │ │ │ │ │ + /** │ │ │ │ │ + * Method: fixPadding │ │ │ │ │ + * To be removed in 3.0, this function merely helps us to deal with the │ │ │ │ │ + * case where the user may have set an integer value for padding, │ │ │ │ │ + * instead of an object. │ │ │ │ │ + */ │ │ │ │ │ + fixPadding: function() { │ │ │ │ │ + if (typeof this.padding == "number") { │ │ │ │ │ + this.padding = new OpenLayers.Bounds( │ │ │ │ │ + this.padding, this.padding, this.padding, this.padding │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // if no valid renderer found, display error │ │ │ │ │ - if (!this.renderer || !this.renderer.supported()) { │ │ │ │ │ - this.renderer = null; │ │ │ │ │ - this.displayError(); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: panMapIfOutOfView │ │ │ │ │ + * {Boolean} When drawn, pan map such that the entire popup is visible in │ │ │ │ │ + * the current viewport (if necessary). │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + panMapIfOutOfView: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: keepInMap │ │ │ │ │ + * {Boolean} If panMapIfOutOfView is false, and this property is true, │ │ │ │ │ + * contrain the popup such that it always fits in the available map │ │ │ │ │ + * space. By default, this is not set on the base class. If you are │ │ │ │ │ + * creating popups that are near map edges and not allowing pannning, │ │ │ │ │ + * and especially if you have a popup which has a │ │ │ │ │ + * fixedRelativePosition, setting this to false may be a smart thing to │ │ │ │ │ + * do. Subclasses may want to override this setting. │ │ │ │ │ + * │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + keepInMap: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: closeOnMove │ │ │ │ │ + * {Boolean} When map pans, close the popup. │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + closeOnMove: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} this gets set in Map.js when the popup is added to the map │ │ │ │ │ + */ │ │ │ │ │ + map: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Popup │ │ │ │ │ + * Create a popup. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * id - {String} a unqiue identifier for this popup. If null is passed │ │ │ │ │ + * an identifier will be automatically generated. │ │ │ │ │ + * lonlat - {} The position on the map the popup will │ │ │ │ │ + * be shown. │ │ │ │ │ + * contentSize - {} The size of the content. │ │ │ │ │ + * contentHTML - {String} An HTML string to display inside the │ │ │ │ │ + * popup. │ │ │ │ │ + * closeBox - {Boolean} Whether to display a close box inside │ │ │ │ │ + * the popup. │ │ │ │ │ + * closeBoxCallback - {Function} Function to be called on closeBox click. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(id, lonlat, contentSize, contentHTML, closeBox, closeBoxCallback) { │ │ │ │ │ + if (id == null) { │ │ │ │ │ + id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (!this.styleMap) { │ │ │ │ │ - this.styleMap = new OpenLayers.StyleMap(); │ │ │ │ │ + this.id = id; │ │ │ │ │ + this.lonlat = lonlat; │ │ │ │ │ + │ │ │ │ │ + this.contentSize = (contentSize != null) ? contentSize : │ │ │ │ │ + new OpenLayers.Size( │ │ │ │ │ + OpenLayers.Popup.WIDTH, │ │ │ │ │ + OpenLayers.Popup.HEIGHT); │ │ │ │ │ + if (contentHTML != null) { │ │ │ │ │ + this.contentHTML = contentHTML; │ │ │ │ │ } │ │ │ │ │ + this.backgroundColor = OpenLayers.Popup.COLOR; │ │ │ │ │ + this.opacity = OpenLayers.Popup.OPACITY; │ │ │ │ │ + this.border = OpenLayers.Popup.BORDER; │ │ │ │ │ │ │ │ │ │ - this.features = []; │ │ │ │ │ - this.selectedFeatures = []; │ │ │ │ │ - this.unrenderedFeatures = {}; │ │ │ │ │ + this.div = OpenLayers.Util.createDiv(this.id, null, null, │ │ │ │ │ + null, null, null, "hidden"); │ │ │ │ │ + this.div.className = this.displayClass; │ │ │ │ │ │ │ │ │ │ - // Allow for custom layer behavior │ │ │ │ │ - if (this.strategies) { │ │ │ │ │ - for (var i = 0, len = this.strategies.length; i < len; i++) { │ │ │ │ │ - this.strategies[i].setLayer(this); │ │ │ │ │ - } │ │ │ │ │ + var groupDivId = this.id + "_GroupDiv"; │ │ │ │ │ + this.groupDiv = OpenLayers.Util.createDiv(groupDivId, null, null, │ │ │ │ │ + null, "relative", null, │ │ │ │ │ + "hidden"); │ │ │ │ │ + │ │ │ │ │ + var id = this.div.id + "_contentDiv"; │ │ │ │ │ + this.contentDiv = OpenLayers.Util.createDiv(id, null, this.contentSize.clone(), │ │ │ │ │ + null, "relative"); │ │ │ │ │ + this.contentDiv.className = this.contentDisplayClass; │ │ │ │ │ + this.groupDiv.appendChild(this.contentDiv); │ │ │ │ │ + this.div.appendChild(this.groupDiv); │ │ │ │ │ + │ │ │ │ │ + if (closeBox) { │ │ │ │ │ + this.addCloseBox(closeBoxCallback); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ + this.registerEvents(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Destroy this layer │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * nullify references to prevent circular references and memory leaks │ │ │ │ │ */ │ │ │ │ │ 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; │ │ │ │ │ + │ │ │ │ │ + this.id = null; │ │ │ │ │ + this.lonlat = null; │ │ │ │ │ + this.size = null; │ │ │ │ │ + this.contentHTML = null; │ │ │ │ │ + │ │ │ │ │ + this.backgroundColor = null; │ │ │ │ │ + this.opacity = null; │ │ │ │ │ + this.border = null; │ │ │ │ │ + │ │ │ │ │ + if (this.closeOnMove && this.map) { │ │ │ │ │ + this.map.events.unregister("movestart", this, this.hide); │ │ │ │ │ } │ │ │ │ │ - if (this.protocol) { │ │ │ │ │ - if (this.protocol.autoDestroy) { │ │ │ │ │ - this.protocol.destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.protocol = null; │ │ │ │ │ + │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ + │ │ │ │ │ + if (this.closeDiv) { │ │ │ │ │ + OpenLayers.Event.stopObservingElement(this.closeDiv); │ │ │ │ │ + this.groupDiv.removeChild(this.closeDiv); │ │ │ │ │ } │ │ │ │ │ - this.destroyFeatures(); │ │ │ │ │ - this.features = null; │ │ │ │ │ - this.selectedFeatures = null; │ │ │ │ │ - this.unrenderedFeatures = null; │ │ │ │ │ - if (this.renderer) { │ │ │ │ │ - this.renderer.destroy(); │ │ │ │ │ + this.closeDiv = null; │ │ │ │ │ + │ │ │ │ │ + this.div.removeChild(this.groupDiv); │ │ │ │ │ + this.groupDiv = null; │ │ │ │ │ + │ │ │ │ │ + if (this.map != null) { │ │ │ │ │ + this.map.removePopup(this); │ │ │ │ │ } │ │ │ │ │ - this.renderer = null; │ │ │ │ │ - this.geometryType = null; │ │ │ │ │ - this.drawn = null; │ │ │ │ │ - OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ + this.map = null; │ │ │ │ │ + this.div = null; │ │ │ │ │ + │ │ │ │ │ + this.autoSize = null; │ │ │ │ │ + this.minSize = null; │ │ │ │ │ + this.maxSize = null; │ │ │ │ │ + this.padding = null; │ │ │ │ │ + this.panMapIfOutOfView = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this layer. │ │ │ │ │ - * │ │ │ │ │ - * Note: Features of the layer are also cloned. │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Constructs the elements that make up the popup. │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} the position the popup in pixels. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An exact clone of this layer │ │ │ │ │ + * {DOMElement} Reference to a div that contains the drawn popup │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.Vector(this.name, this.getOptions()); │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + if (px == null) { │ │ │ │ │ + if ((this.lonlat != null) && (this.map != null)) { │ │ │ │ │ + px = this.map.getLayerPxFromLonLat(this.lonlat); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]); │ │ │ │ │ + // this assumes that this.map already exists, which is okay because │ │ │ │ │ + // this.draw is only called once the popup has been added to the map. │ │ │ │ │ + if (this.closeOnMove) { │ │ │ │ │ + this.map.events.register("movestart", this, this.hide); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // 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(); │ │ │ │ │ + //listen to movestart, moveend to disable overflow (FF bug) │ │ │ │ │ + if (!this.disableFirefoxOverflowHack && OpenLayers.BROWSER_NAME == 'firefox') { │ │ │ │ │ + this.map.events.register("movestart", this, function() { │ │ │ │ │ + var style = document.defaultView.getComputedStyle( │ │ │ │ │ + this.contentDiv, null │ │ │ │ │ + ); │ │ │ │ │ + var currentOverflow = style.getPropertyValue("overflow"); │ │ │ │ │ + if (currentOverflow != "hidden") { │ │ │ │ │ + this.contentDiv._oldOverflow = currentOverflow; │ │ │ │ │ + this.contentDiv.style.overflow = "hidden"; │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + this.map.events.register("moveend", this, function() { │ │ │ │ │ + var oldOverflow = this.contentDiv._oldOverflow; │ │ │ │ │ + if (oldOverflow) { │ │ │ │ │ + this.contentDiv.style.overflow = oldOverflow; │ │ │ │ │ + this.contentDiv._oldOverflow = null; │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - obj.features = clonedFeatures; │ │ │ │ │ │ │ │ │ │ - return obj; │ │ │ │ │ - }, │ │ │ │ │ + this.moveTo(px); │ │ │ │ │ + if (!this.autoSize && !this.size) { │ │ │ │ │ + this.setSize(this.contentSize); │ │ │ │ │ + } │ │ │ │ │ + this.setBackgroundColor(); │ │ │ │ │ + this.setOpacity(); │ │ │ │ │ + this.setBorder(); │ │ │ │ │ + this.setContentHTML(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: refresh │ │ │ │ │ - * Ask the layer to request features again and redraw them. Triggers │ │ │ │ │ - * the refresh event if the layer is in range and visible. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} Optional object with properties for any listener of │ │ │ │ │ - * the refresh event. │ │ │ │ │ - */ │ │ │ │ │ - refresh: function(obj) { │ │ │ │ │ - if (this.calculateInRange() && this.visibility) { │ │ │ │ │ - this.events.triggerEvent("refresh", obj); │ │ │ │ │ + if (this.panMapIfOutOfView) { │ │ │ │ │ + this.panIntoView(); │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: assignRenderer │ │ │ │ │ - * Iterates through the available renderer implementations and selects │ │ │ │ │ - * and assigns the first one whose "supported()" function returns true. │ │ │ │ │ + * Method: updatePosition │ │ │ │ │ + * if the popup has a lonlat and its map members set, │ │ │ │ │ + * then have it move itself to its proper position │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + updatePosition: function() { │ │ │ │ │ + if ((this.lonlat) && (this.map)) { │ │ │ │ │ + var px = this.map.getLayerPxFromLonLat(this.lonlat); │ │ │ │ │ + if (px) { │ │ │ │ │ + this.moveTo(px); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: displayError │ │ │ │ │ - * Let the user know their browser isn't supported. │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} the top and left position of the popup div. │ │ │ │ │ */ │ │ │ │ │ - displayError: function() { │ │ │ │ │ - if (this.reportError) { │ │ │ │ │ - OpenLayers.Console.userError(OpenLayers.i18n("browserNotSupported", { │ │ │ │ │ - renderers: this.renderers.join('\n') │ │ │ │ │ - })); │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + if ((px != null) && (this.div != null)) { │ │ │ │ │ + this.div.style.left = px.x + "px"; │ │ │ │ │ + this.div.style.top = px.y + "px"; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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 - {} │ │ │ │ │ + /** │ │ │ │ │ + * Method: visible │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Boolean indicating whether or not the popup is visible │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.prototype.setMap.apply(this, arguments); │ │ │ │ │ + visible: function() { │ │ │ │ │ + return OpenLayers.Element.visible(this.div); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (!this.renderer) { │ │ │ │ │ - this.map.removeLayer(this); │ │ │ │ │ + /** │ │ │ │ │ + * Method: toggle │ │ │ │ │ + * Toggles visibility of the popup. │ │ │ │ │ + */ │ │ │ │ │ + toggle: function() { │ │ │ │ │ + if (this.visible()) { │ │ │ │ │ + this.hide(); │ │ │ │ │ } else { │ │ │ │ │ - this.renderer.map = this.map; │ │ │ │ │ - │ │ │ │ │ - var newSize = this.map.getSize(); │ │ │ │ │ - newSize.w = newSize.w * this.ratio; │ │ │ │ │ - newSize.h = newSize.h * this.ratio; │ │ │ │ │ - this.renderer.setSize(newSize); │ │ │ │ │ + this.show(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: show │ │ │ │ │ + * Makes the popup visible. │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + show: function() { │ │ │ │ │ + this.div.style.display = ''; │ │ │ │ │ + │ │ │ │ │ + if (this.panMapIfOutOfView) { │ │ │ │ │ + this.panIntoView(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeMap │ │ │ │ │ - * The layer has been removed from the map. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * Method: hide │ │ │ │ │ + * Makes the popup invisible. │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + hide: function() { │ │ │ │ │ + this.div.style.display = 'none'; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onMapResize │ │ │ │ │ - * Notify the renderer of the change in size. │ │ │ │ │ - * │ │ │ │ │ + * Method: setSize │ │ │ │ │ + * Used to adjust the size of the popup. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * contentSize - {} the new size for the popup's │ │ │ │ │ + * contents div (in pixels). │ │ │ │ │ */ │ │ │ │ │ - onMapResize: function() { │ │ │ │ │ - OpenLayers.Layer.prototype.onMapResize.apply(this, arguments); │ │ │ │ │ + setSize: function(contentSize) { │ │ │ │ │ + this.size = contentSize.clone(); │ │ │ │ │ │ │ │ │ │ - var newSize = this.map.getSize(); │ │ │ │ │ - newSize.w = newSize.w * this.ratio; │ │ │ │ │ - newSize.h = newSize.h * this.ratio; │ │ │ │ │ - this.renderer.setSize(newSize); │ │ │ │ │ + // if our contentDiv has a css 'padding' set on it by a stylesheet, we │ │ │ │ │ + // must add that to the desired "size". │ │ │ │ │ + var contentDivPadding = this.getContentDivPadding(); │ │ │ │ │ + var wPadding = contentDivPadding.left + contentDivPadding.right; │ │ │ │ │ + var hPadding = contentDivPadding.top + contentDivPadding.bottom; │ │ │ │ │ + │ │ │ │ │ + // take into account the popup's 'padding' property │ │ │ │ │ + this.fixPadding(); │ │ │ │ │ + wPadding += this.padding.left + this.padding.right; │ │ │ │ │ + hPadding += this.padding.top + this.padding.bottom; │ │ │ │ │ + │ │ │ │ │ + // make extra space for the close div │ │ │ │ │ + if (this.closeDiv) { │ │ │ │ │ + var closeDivWidth = parseInt(this.closeDiv.style.width); │ │ │ │ │ + wPadding += closeDivWidth + contentDivPadding.right; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + //increase size of the main popup div to take into account the │ │ │ │ │ + // users's desired padding and close div. │ │ │ │ │ + this.size.w += wPadding; │ │ │ │ │ + this.size.h += hPadding; │ │ │ │ │ + │ │ │ │ │ + //now if our browser is IE, we need to actually make the contents │ │ │ │ │ + // div itself bigger to take its own padding into effect. this makes │ │ │ │ │ + // me want to shoot someone, but so it goes. │ │ │ │ │ + if (OpenLayers.BROWSER_NAME == "msie") { │ │ │ │ │ + this.contentSize.w += │ │ │ │ │ + contentDivPadding.left + contentDivPadding.right; │ │ │ │ │ + this.contentSize.h += │ │ │ │ │ + contentDivPadding.bottom + contentDivPadding.top; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.div != null) { │ │ │ │ │ + this.div.style.width = this.size.w + "px"; │ │ │ │ │ + this.div.style.height = this.size.h + "px"; │ │ │ │ │ + } │ │ │ │ │ + if (this.contentDiv != null) { │ │ │ │ │ + this.contentDiv.style.width = contentSize.w + "px"; │ │ │ │ │ + this.contentDiv.style.height = contentSize.h + "px"; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ + * APIMethod: updateSize │ │ │ │ │ + * Auto size the popup so that it precisely fits its contents (as │ │ │ │ │ + * determined by this.contentDiv.innerHTML). Popup size will, of │ │ │ │ │ + * course, be limited by the available space on the current map │ │ │ │ │ */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - OpenLayers.Layer.prototype.moveTo.apply(this, arguments); │ │ │ │ │ + updateSize: function() { │ │ │ │ │ │ │ │ │ │ - var coordSysUnchanged = true; │ │ │ │ │ - if (!dragging) { │ │ │ │ │ - this.renderer.root.style.visibility = 'hidden'; │ │ │ │ │ + // determine actual render dimensions of the contents by putting its │ │ │ │ │ + // contents into a fake contentDiv (for the CSS) and then measuring it │ │ │ │ │ + var preparedHTML = "
" + │ │ │ │ │ + this.contentDiv.innerHTML + │ │ │ │ │ + "
"; │ │ │ │ │ │ │ │ │ │ - var 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); │ │ │ │ │ + var containerElement = (this.map) ? this.map.div : document.body; │ │ │ │ │ + var realSize = OpenLayers.Util.getRenderedDimensions( │ │ │ │ │ + preparedHTML, null, { │ │ │ │ │ + displayClass: this.displayClass, │ │ │ │ │ + containerElement: containerElement │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ │ │ │ │ │ - this.div.style.left = offsetLeft + 'px'; │ │ │ │ │ - this.div.style.top = offsetTop + 'px'; │ │ │ │ │ + // is the "real" size of the div is safe to display in our map? │ │ │ │ │ + var safeSize = this.getSafeContentSize(realSize); │ │ │ │ │ │ │ │ │ │ - var extent = this.map.getExtent().scale(this.ratio); │ │ │ │ │ - coordSysUnchanged = this.renderer.setExtent(extent, zoomChanged); │ │ │ │ │ + var newSize = null; │ │ │ │ │ + if (safeSize.equals(realSize)) { │ │ │ │ │ + //real size of content is small enough to fit on the map, │ │ │ │ │ + // so we use real size. │ │ │ │ │ + newSize = realSize; │ │ │ │ │ │ │ │ │ │ - this.renderer.root.style.visibility = 'visible'; │ │ │ │ │ + } else { │ │ │ │ │ │ │ │ │ │ - // 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; │ │ │ │ │ - } │ │ │ │ │ + // make a new 'size' object with the clipped dimensions │ │ │ │ │ + // set or null if not clipped. │ │ │ │ │ + var fixedSize = { │ │ │ │ │ + w: (safeSize.w < realSize.w) ? safeSize.w : null, │ │ │ │ │ + h: (safeSize.h < realSize.h) ? safeSize.h : null │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - if (!zoomChanged && coordSysUnchanged) { │ │ │ │ │ - for (var i in this.unrenderedFeatures) { │ │ │ │ │ - var feature = this.unrenderedFeatures[i]; │ │ │ │ │ - this.drawFeature(feature); │ │ │ │ │ + if (fixedSize.w && fixedSize.h) { │ │ │ │ │ + //content is too big in both directions, so we will use │ │ │ │ │ + // max popup size (safeSize), knowing well that it will │ │ │ │ │ + // overflow both ways. │ │ │ │ │ + newSize = safeSize; │ │ │ │ │ + } else { │ │ │ │ │ + //content is clipped in only one direction, so we need to │ │ │ │ │ + // run getRenderedDimensions() again with a fixed dimension │ │ │ │ │ + var clippedSize = OpenLayers.Util.getRenderedDimensions( │ │ │ │ │ + preparedHTML, fixedSize, { │ │ │ │ │ + displayClass: this.contentDisplayClass, │ │ │ │ │ + containerElement: containerElement │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + //if the clipped size is still the same as the safeSize, │ │ │ │ │ + // that means that our content must be fixed in the │ │ │ │ │ + // offending direction. If overflow is 'auto', this means │ │ │ │ │ + // we are going to have a scrollbar for sure, so we must │ │ │ │ │ + // adjust for that. │ │ │ │ │ + // │ │ │ │ │ + var currentOverflow = OpenLayers.Element.getStyle( │ │ │ │ │ + this.contentDiv, "overflow" │ │ │ │ │ + ); │ │ │ │ │ + if ((currentOverflow != "hidden") && │ │ │ │ │ + (clippedSize.equals(safeSize))) { │ │ │ │ │ + var scrollBar = OpenLayers.Util.getScrollbarWidth(); │ │ │ │ │ + if (fixedSize.w) { │ │ │ │ │ + clippedSize.h += scrollBar; │ │ │ │ │ + } else { │ │ │ │ │ + clippedSize.w += scrollBar; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + newSize = this.getSafeContentSize(clippedSize); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ + this.setSize(newSize); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setBackgroundColor │ │ │ │ │ + * Sets the background color of the popup. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * color - {String} the background color. eg "#FFBBBB" │ │ │ │ │ + */ │ │ │ │ │ + setBackgroundColor: function(color) { │ │ │ │ │ + if (color != undefined) { │ │ │ │ │ + this.backgroundColor = color; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.div != null) { │ │ │ │ │ + this.div.style.backgroundColor = this.backgroundColor; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: display │ │ │ │ │ - * Hide or show the Layer │ │ │ │ │ + /** │ │ │ │ │ + * Method: setOpacity │ │ │ │ │ + * Sets the opacity of the popup. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ + * opacity - {float} A value between 0.0 (transparent) and 1.0 (solid). │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + setOpacity: function(opacity) { │ │ │ │ │ + if (opacity != undefined) { │ │ │ │ │ + this.opacity = opacity; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.div != null) { │ │ │ │ │ + // for Mozilla and Safari │ │ │ │ │ + this.div.style.opacity = this.opacity; │ │ │ │ │ + │ │ │ │ │ + // for IE │ │ │ │ │ + this.div.style.filter = 'alpha(opacity=' + this.opacity * 100 + ')'; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addFeatures │ │ │ │ │ - * Add Features to the layer. │ │ │ │ │ + * Method: setBorder │ │ │ │ │ + * Sets the border style of the popup. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array()} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * border - {String} The border style value. eg 2px │ │ │ │ │ */ │ │ │ │ │ - addFeatures: function(features, options) { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ - features = [features]; │ │ │ │ │ + setBorder: function(border) { │ │ │ │ │ + if (border != undefined) { │ │ │ │ │ + this.border = border; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ + if (this.div != null) { │ │ │ │ │ + this.div.style.border = this.border; │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // 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]; │ │ │ │ │ + /** │ │ │ │ │ + * Method: setContentHTML │ │ │ │ │ + * Allows the user to set the HTML content of the popup. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * contentHTML - {String} HTML for the div. │ │ │ │ │ + */ │ │ │ │ │ + setContentHTML: function(contentHTML) { │ │ │ │ │ │ │ │ │ │ - if (this.geometryType && │ │ │ │ │ - !(feature.geometry instanceof this.geometryType)) { │ │ │ │ │ - throw new TypeError('addFeatures: component should be an ' + │ │ │ │ │ - this.geometryType.prototype.CLASS_NAME); │ │ │ │ │ - } │ │ │ │ │ + if (contentHTML != null) { │ │ │ │ │ + this.contentHTML = contentHTML; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - //give feature reference to its layer │ │ │ │ │ - feature.layer = this; │ │ │ │ │ + if ((this.contentDiv != null) && │ │ │ │ │ + (this.contentHTML != null) && │ │ │ │ │ + (this.contentHTML != this.contentDiv.innerHTML)) { │ │ │ │ │ │ │ │ │ │ - if (!feature.style && this.style) { │ │ │ │ │ - feature.style = OpenLayers.Util.extend({}, this.style); │ │ │ │ │ - } │ │ │ │ │ + this.contentDiv.innerHTML = this.contentHTML; │ │ │ │ │ │ │ │ │ │ - if (notify) { │ │ │ │ │ - if (this.events.triggerEvent("beforefeatureadded", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }) === false) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - this.preFeatureInsert(feature); │ │ │ │ │ - } │ │ │ │ │ + if (this.autoSize) { │ │ │ │ │ │ │ │ │ │ - featuresAdded.push(feature); │ │ │ │ │ - this.features.push(feature); │ │ │ │ │ - this.drawFeature(feature); │ │ │ │ │ + //if popup has images, listen for when they finish │ │ │ │ │ + // loading and resize accordingly │ │ │ │ │ + this.registerImageListeners(); │ │ │ │ │ │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("featureadded", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - this.onFeatureInsert(feature); │ │ │ │ │ + //auto size the popup to its current contents │ │ │ │ │ + this.updateSize(); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - 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. │ │ │ │ │ + * Method: registerImageListeners │ │ │ │ │ + * Called when an image contained by the popup loaded. this function │ │ │ │ │ + * updates the popup size, then unregisters the image load listener. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + registerImageListeners: function() { │ │ │ │ │ │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent( │ │ │ │ │ - "beforefeaturesremoved", { │ │ │ │ │ - features: features │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + // As the images load, this function will call updateSize() to │ │ │ │ │ + // resize the popup to fit the content div (which presumably is now │ │ │ │ │ + // bigger than when the image was not loaded). │ │ │ │ │ + // │ │ │ │ │ + // If the 'panMapIfOutOfView' property is set, we will pan the newly │ │ │ │ │ + // resized popup back into view. │ │ │ │ │ + // │ │ │ │ │ + // Note that this function, when called, will have 'popup' and │ │ │ │ │ + // 'img' properties in the context. │ │ │ │ │ + // │ │ │ │ │ + var onImgLoad = function() { │ │ │ │ │ + if (this.popup.id === null) { // this.popup has been destroyed! │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + this.popup.updateSize(); │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ + if (this.popup.visible() && this.popup.panMapIfOutOfView) { │ │ │ │ │ + this.popup.panIntoView(); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - var feature = features[i]; │ │ │ │ │ - delete this.unrenderedFeatures[feature.id]; │ │ │ │ │ + OpenLayers.Event.stopObserving( │ │ │ │ │ + this.img, "load", this.img._onImgLoad │ │ │ │ │ + ); │ │ │ │ │ │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("beforefeatureremoved", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - this.features = OpenLayers.Util.removeItem(this.features, feature); │ │ │ │ │ - // feature has no layer at this point │ │ │ │ │ - feature.layer = null; │ │ │ │ │ + //cycle through the images and if their size is 0x0, that means that │ │ │ │ │ + // they haven't been loaded yet, so we attach the listener, which │ │ │ │ │ + // will fire when the images finish loading and will resize the │ │ │ │ │ + // popup accordingly to its new size. │ │ │ │ │ + var images = this.contentDiv.getElementsByTagName("img"); │ │ │ │ │ + for (var i = 0, len = images.length; i < len; i++) { │ │ │ │ │ + var img = images[i]; │ │ │ │ │ + if (img.width == 0 || img.height == 0) { │ │ │ │ │ │ │ │ │ │ - if (feature.geometry) { │ │ │ │ │ - this.renderer.eraseFeatures(feature); │ │ │ │ │ - } │ │ │ │ │ + var context = { │ │ │ │ │ + 'popup': this, │ │ │ │ │ + 'img': img │ │ │ │ │ + }; │ │ │ │ │ │ │ │ │ │ - //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); │ │ │ │ │ - } │ │ │ │ │ + //expando this function to the image itself before registering │ │ │ │ │ + // it. This way we can easily and properly unregister it. │ │ │ │ │ + img._onImgLoad = OpenLayers.Function.bind(onImgLoad, context); │ │ │ │ │ │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("featureremoved", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ + OpenLayers.Event.observe(img, 'load', img._onImgLoad); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("featuresremoved", { │ │ │ │ │ - features: features │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: removeAllFeatures │ │ │ │ │ - * Remove all features from the layer. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getSafeContentSize │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Optional properties for changing behavior of the │ │ │ │ │ - * removal. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * silent - {Boolean} Supress event triggering. Default is false. │ │ │ │ │ + * size - {} Desired size to make the popup. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A size to make the popup which is neither smaller │ │ │ │ │ + * than the specified minimum size, nor bigger than the maximum │ │ │ │ │ + * size (which is calculated relative to the size of the viewport). │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + getSafeContentSize: function(size) { │ │ │ │ │ + │ │ │ │ │ + var safeContentSize = size.clone(); │ │ │ │ │ + │ │ │ │ │ + // if our contentDiv has a css 'padding' set on it by a stylesheet, we │ │ │ │ │ + // must add that to the desired "size". │ │ │ │ │ + var contentDivPadding = this.getContentDivPadding(); │ │ │ │ │ + var wPadding = contentDivPadding.left + contentDivPadding.right; │ │ │ │ │ + var hPadding = contentDivPadding.top + contentDivPadding.bottom; │ │ │ │ │ + │ │ │ │ │ + // take into account the popup's 'padding' property │ │ │ │ │ + this.fixPadding(); │ │ │ │ │ + wPadding += this.padding.left + this.padding.right; │ │ │ │ │ + hPadding += this.padding.top + this.padding.bottom; │ │ │ │ │ + │ │ │ │ │ + if (this.closeDiv) { │ │ │ │ │ + var closeDivWidth = parseInt(this.closeDiv.style.width); │ │ │ │ │ + wPadding += closeDivWidth + contentDivPadding.right; │ │ │ │ │ } │ │ │ │ │ - this.renderer.clear(); │ │ │ │ │ - this.features = []; │ │ │ │ │ - this.unrenderedFeatures = {}; │ │ │ │ │ - this.selectedFeatures = []; │ │ │ │ │ - if (notify) { │ │ │ │ │ - this.events.triggerEvent("featuresremoved", { │ │ │ │ │ - features: features │ │ │ │ │ - }); │ │ │ │ │ + │ │ │ │ │ + // prevent the popup from being smaller than a specified minimal size │ │ │ │ │ + if (this.minSize) { │ │ │ │ │ + safeContentSize.w = Math.max(safeContentSize.w, │ │ │ │ │ + (this.minSize.w - wPadding)); │ │ │ │ │ + safeContentSize.h = Math.max(safeContentSize.h, │ │ │ │ │ + (this.minSize.h - hPadding)); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroyFeatures │ │ │ │ │ - * Erase and destroy features on the layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * features - {Array()} An optional array of │ │ │ │ │ - * features to destroy. If not supplied, all features on the layer │ │ │ │ │ - * will be destroyed. │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - destroyFeatures: function(features, options) { │ │ │ │ │ - var all = (features == undefined); // evaluates to true if │ │ │ │ │ - // features is null │ │ │ │ │ - if (all) { │ │ │ │ │ - features = this.features; │ │ │ │ │ + // prevent the popup from being bigger than a specified maximum size │ │ │ │ │ + if (this.maxSize) { │ │ │ │ │ + safeContentSize.w = Math.min(safeContentSize.w, │ │ │ │ │ + (this.maxSize.w - wPadding)); │ │ │ │ │ + safeContentSize.h = Math.min(safeContentSize.h, │ │ │ │ │ + (this.maxSize.h - hPadding)); │ │ │ │ │ } │ │ │ │ │ - if (features) { │ │ │ │ │ - this.removeFeatures(features, options); │ │ │ │ │ - for (var i = features.length - 1; i >= 0; i--) { │ │ │ │ │ - features[i].destroy(); │ │ │ │ │ + │ │ │ │ │ + //make sure the desired size to set doesn't result in a popup that │ │ │ │ │ + // is bigger than the map's viewport. │ │ │ │ │ + // │ │ │ │ │ + if (this.map && this.map.size) { │ │ │ │ │ + │ │ │ │ │ + var extraX = 0, │ │ │ │ │ + extraY = 0; │ │ │ │ │ + if (this.keepInMap && !this.panMapIfOutOfView) { │ │ │ │ │ + var px = this.map.getPixelFromLonLat(this.lonlat); │ │ │ │ │ + switch (this.relativePosition) { │ │ │ │ │ + case "tr": │ │ │ │ │ + extraX = px.x; │ │ │ │ │ + extraY = this.map.size.h - px.y; │ │ │ │ │ + break; │ │ │ │ │ + case "tl": │ │ │ │ │ + extraX = this.map.size.w - px.x; │ │ │ │ │ + extraY = this.map.size.h - px.y; │ │ │ │ │ + break; │ │ │ │ │ + case "bl": │ │ │ │ │ + extraX = this.map.size.w - px.x; │ │ │ │ │ + extraY = px.y; │ │ │ │ │ + break; │ │ │ │ │ + case "br": │ │ │ │ │ + extraX = px.x; │ │ │ │ │ + extraY = px.y; │ │ │ │ │ + break; │ │ │ │ │ + default: │ │ │ │ │ + extraX = px.x; │ │ │ │ │ + extraY = this.map.size.h - px.y; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + var maxY = this.map.size.h - │ │ │ │ │ + this.map.paddingForPopups.top - │ │ │ │ │ + this.map.paddingForPopups.bottom - │ │ │ │ │ + hPadding - extraY; │ │ │ │ │ + │ │ │ │ │ + var maxX = this.map.size.w - │ │ │ │ │ + this.map.paddingForPopups.left - │ │ │ │ │ + this.map.paddingForPopups.right - │ │ │ │ │ + wPadding - extraX; │ │ │ │ │ + │ │ │ │ │ + safeContentSize.w = Math.min(safeContentSize.w, maxX); │ │ │ │ │ + safeContentSize.h = Math.min(safeContentSize.h, maxY); │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ + return safeContentSize; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: getContentDivPadding │ │ │ │ │ + * Glorious, oh glorious hack in order to determine the css 'padding' of │ │ │ │ │ + * the contentDiv. IE/Opera return null here unless we actually add the │ │ │ │ │ + * popup's main 'div' element (which contains contentDiv) to the DOM. │ │ │ │ │ + * So we make it invisible and then add it to the document temporarily. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - * style - {String | Object} Named render intent or full symbolizer object. │ │ │ │ │ + * Once we've taken the padding readings we need, we then remove it │ │ │ │ │ + * from the DOM (it will actually get added to the DOM in │ │ │ │ │ + * Map.js's addPopup) │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + getContentDivPadding: function() { │ │ │ │ │ + │ │ │ │ │ + //use cached value if we have it │ │ │ │ │ + var contentDivPadding = this._contentDivPadding; │ │ │ │ │ + if (!contentDivPadding) { │ │ │ │ │ + │ │ │ │ │ + if (this.div.parentNode == null) { │ │ │ │ │ + //make the div invisible and add it to the page │ │ │ │ │ + this.div.style.display = "none"; │ │ │ │ │ + document.body.appendChild(this.div); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - 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]; │ │ │ │ │ + //read the padding settings from css, put them in an OL.Bounds │ │ │ │ │ + contentDivPadding = new OpenLayers.Bounds( │ │ │ │ │ + OpenLayers.Element.getStyle(this.contentDiv, "padding-left"), │ │ │ │ │ + OpenLayers.Element.getStyle(this.contentDiv, "padding-bottom"), │ │ │ │ │ + OpenLayers.Element.getStyle(this.contentDiv, "padding-right"), │ │ │ │ │ + OpenLayers.Element.getStyle(this.contentDiv, "padding-top") │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + //cache the value │ │ │ │ │ + this._contentDivPadding = contentDivPadding; │ │ │ │ │ + │ │ │ │ │ + if (this.div.parentNode == document.body) { │ │ │ │ │ + //remove the div from the page and make it visible again │ │ │ │ │ + document.body.removeChild(this.div); │ │ │ │ │ + this.div.style.display = ""; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return contentDivPadding; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: eraseFeatures │ │ │ │ │ - * Erase features from the layer. │ │ │ │ │ - * │ │ │ │ │ + * Method: addCloseBox │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array()} │ │ │ │ │ + * callback - {Function} The callback to be called when the close button │ │ │ │ │ + * is clicked. │ │ │ │ │ */ │ │ │ │ │ - eraseFeatures: function(features) { │ │ │ │ │ - this.renderer.eraseFeatures(features); │ │ │ │ │ + addCloseBox: function(callback) { │ │ │ │ │ + │ │ │ │ │ + this.closeDiv = OpenLayers.Util.createDiv( │ │ │ │ │ + this.id + "_close", null, { │ │ │ │ │ + w: 17, │ │ │ │ │ + h: 17 │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + this.closeDiv.className = "olPopupCloseBox"; │ │ │ │ │ + │ │ │ │ │ + // use the content div's css padding to determine if we should │ │ │ │ │ + // padd the close div │ │ │ │ │ + var contentDivPadding = this.getContentDivPadding(); │ │ │ │ │ + │ │ │ │ │ + this.closeDiv.style.right = contentDivPadding.right + "px"; │ │ │ │ │ + this.closeDiv.style.top = contentDivPadding.top + "px"; │ │ │ │ │ + this.groupDiv.appendChild(this.closeDiv); │ │ │ │ │ + │ │ │ │ │ + var closePopup = callback || function(e) { │ │ │ │ │ + this.hide(); │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ + }; │ │ │ │ │ + OpenLayers.Event.observe(this.closeDiv, "touchend", │ │ │ │ │ + OpenLayers.Function.bindAsEventListener(closePopup, this)); │ │ │ │ │ + OpenLayers.Event.observe(this.closeDiv, "click", │ │ │ │ │ + OpenLayers.Function.bindAsEventListener(closePopup, this)); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getFeatureFromEvent │ │ │ │ │ - * Given an event, return a feature if the event occurred over one. │ │ │ │ │ - * Otherwise, return null. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A feature if one was under the event. │ │ │ │ │ + * Method: panIntoView │ │ │ │ │ + * Pans the map such that the popup is totaly viewable (if necessary) │ │ │ │ │ */ │ │ │ │ │ - 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.'); │ │ │ │ │ + panIntoView: function() { │ │ │ │ │ + │ │ │ │ │ + var mapSize = this.map.getSize(); │ │ │ │ │ + │ │ │ │ │ + //start with the top left corner of the popup, in px, │ │ │ │ │ + // relative to the viewport │ │ │ │ │ + var origTL = this.map.getViewPortPxFromLayerPx(new OpenLayers.Pixel( │ │ │ │ │ + parseInt(this.div.style.left), │ │ │ │ │ + parseInt(this.div.style.top) │ │ │ │ │ + )); │ │ │ │ │ + var newTL = origTL.clone(); │ │ │ │ │ + │ │ │ │ │ + //new left (compare to margins, using this.size to calculate right) │ │ │ │ │ + if (origTL.x < this.map.paddingForPopups.left) { │ │ │ │ │ + newTL.x = this.map.paddingForPopups.left; │ │ │ │ │ + } else │ │ │ │ │ + if ((origTL.x + this.size.w) > (mapSize.w - this.map.paddingForPopups.right)) { │ │ │ │ │ + newTL.x = mapSize.w - this.map.paddingForPopups.right - this.size.w; │ │ │ │ │ } │ │ │ │ │ - var feature = null; │ │ │ │ │ - var featureId = this.renderer.getFeatureIdFromEvent(evt); │ │ │ │ │ - if (featureId) { │ │ │ │ │ - if (typeof featureId === "string") { │ │ │ │ │ - feature = this.getFeatureById(featureId); │ │ │ │ │ - } else { │ │ │ │ │ - feature = featureId; │ │ │ │ │ - } │ │ │ │ │ + │ │ │ │ │ + //new top (compare to margins, using this.size to calculate bottom) │ │ │ │ │ + if (origTL.y < this.map.paddingForPopups.top) { │ │ │ │ │ + newTL.y = this.map.paddingForPopups.top; │ │ │ │ │ + } else │ │ │ │ │ + if ((origTL.y + this.size.h) > (mapSize.h - this.map.paddingForPopups.bottom)) { │ │ │ │ │ + newTL.y = mapSize.h - this.map.paddingForPopups.bottom - this.size.h; │ │ │ │ │ } │ │ │ │ │ - return feature; │ │ │ │ │ + │ │ │ │ │ + var dx = origTL.x - newTL.x; │ │ │ │ │ + var dy = origTL.y - newTL.y; │ │ │ │ │ + │ │ │ │ │ + this.map.pan(dx, dy); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getFeatureBy │ │ │ │ │ - * Given a property value, return the feature if it exists in the features array │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * property - {String} │ │ │ │ │ - * value - {String} │ │ │ │ │ + /** │ │ │ │ │ + * Method: registerEvents │ │ │ │ │ + * Registers events on the popup. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A feature corresponding to the given │ │ │ │ │ - * property value or null if there is no such feature. │ │ │ │ │ + * Do this in a separate function so that subclasses can │ │ │ │ │ + * choose to override it if they wish to deal differently │ │ │ │ │ + * with mouse events │ │ │ │ │ + * │ │ │ │ │ + * Note in the following handler functions that some special │ │ │ │ │ + * care is needed to deal correctly with mousing and popups. │ │ │ │ │ + * │ │ │ │ │ + * Because the user might select the zoom-rectangle option and │ │ │ │ │ + * then drag it over a popup, we need a safe way to allow the │ │ │ │ │ + * mousemove and mouseup events to pass through the popup when │ │ │ │ │ + * they are initiated from outside. The same procedure is needed for │ │ │ │ │ + * touchmove and touchend events. │ │ │ │ │ + * │ │ │ │ │ + * Otherwise, we want to essentially kill the event propagation │ │ │ │ │ + * for all other events, though we have to do so carefully, │ │ │ │ │ + * without disabling basic html functionality, like clicking on │ │ │ │ │ + * hyperlinks or drag-selecting text. │ │ │ │ │ */ │ │ │ │ │ - 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]; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + registerEvents: function() { │ │ │ │ │ + this.events = new OpenLayers.Events(this, this.div, null, true); │ │ │ │ │ + │ │ │ │ │ + function onTouchstart(evt) { │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ } │ │ │ │ │ - return feature; │ │ │ │ │ - }, │ │ │ │ │ + this.events.on({ │ │ │ │ │ + "mousedown": this.onmousedown, │ │ │ │ │ + "mousemove": this.onmousemove, │ │ │ │ │ + "mouseup": this.onmouseup, │ │ │ │ │ + "click": this.onclick, │ │ │ │ │ + "mouseout": this.onmouseout, │ │ │ │ │ + "dblclick": this.ondblclick, │ │ │ │ │ + "touchstart": onTouchstart, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: 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: onmousedown │ │ │ │ │ + * When mouse goes down within the popup, make a note of │ │ │ │ │ + * it locally, and then do not propagate the mousedown │ │ │ │ │ + * (but do so safely so that user can select text inside) │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * featureFid - {String} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A feature corresponding to the given │ │ │ │ │ - * featureFid or null if there is no such feature. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - getFeatureByFid: function(featureFid) { │ │ │ │ │ - return this.getFeatureBy('fid', featureFid); │ │ │ │ │ + onmousedown: function(evt) { │ │ │ │ │ + this.mousedown = true; │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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: onmousemove │ │ │ │ │ + * If the drag was started within the popup, then │ │ │ │ │ + * do not propagate the mousemove (but do so safely │ │ │ │ │ + * so that user can select text inside) │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * attrName - {String} │ │ │ │ │ - * attrValue - {Mixed} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * Array({}) An array of features that have the │ │ │ │ │ - * passed named attribute set to the given value. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + onmousemove: function(evt) { │ │ │ │ │ + if (this.mousedown) { │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ } │ │ │ │ │ - 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); │ │ │ │ │ + /** │ │ │ │ │ + * Method: onmouseup │ │ │ │ │ + * When mouse comes up within the popup, after going down │ │ │ │ │ + * in it, reset the flag, and then (once again) do not │ │ │ │ │ + * propagate the event, but do so safely so that user can │ │ │ │ │ + * select text inside │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + */ │ │ │ │ │ + onmouseup: function(evt) { │ │ │ │ │ + if (this.mousedown) { │ │ │ │ │ + this.mousedown = false; │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ } │ │ │ │ │ - this.map.featureSelection = []; │ │ │ │ │ }, │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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 - {} │ │ │ │ │ + * Method: onclick │ │ │ │ │ + * Ignore clicks, but allowing default browser handling │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - onFeatureInsert: function(feature) {}, │ │ │ │ │ + onclick: function(evt) { │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: onmouseout │ │ │ │ │ + * When mouse goes out of the popup set the flag to false so that │ │ │ │ │ + * if they let go and then drag back in, we won't be confused. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - preFeatureInsert: function(feature) {}, │ │ │ │ │ + onmouseout: function(evt) { │ │ │ │ │ + this.mousedown = false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getDataExtent │ │ │ │ │ - * Calculates the max extent which includes all of the features. │ │ │ │ │ + * Method: ondblclick │ │ │ │ │ + * Ignore double-clicks, but allowing default browser handling │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} or null if the layer has no features with │ │ │ │ │ - * geometries. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - 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()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return maxExtent; │ │ │ │ │ + ondblclick: function(evt) { │ │ │ │ │ + OpenLayers.Event.stop(evt, true); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.Vector" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Popup" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Popup.WIDTH = 200; │ │ │ │ │ +OpenLayers.Popup.HEIGHT = 200; │ │ │ │ │ +OpenLayers.Popup.COLOR = "white"; │ │ │ │ │ +OpenLayers.Popup.OPACITY = 1; │ │ │ │ │ +OpenLayers.Popup.BORDER = "0px"; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Split.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Path.js │ │ │ │ │ - * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Split │ │ │ │ │ - * Acts as a split feature agent while editing vector features. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Strategy │ │ │ │ │ + * Abstract vector layer strategy class. Not to be instantiated directly. Use │ │ │ │ │ + * one of the strategy subclasses instead. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Split = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * beforesplit - Triggered before a split occurs. Listeners receive an │ │ │ │ │ - * event object with *source* and *target* properties. │ │ │ │ │ - * split - Triggered when a split occurs. Listeners receive an event with │ │ │ │ │ - * an *original* property and a *features* property. The original │ │ │ │ │ - * is a reference to the target feature that the sketch or modified │ │ │ │ │ - * feature intersects. The features property is a list of all features │ │ │ │ │ - * that result from this single split. This event is triggered before │ │ │ │ │ - * the resulting features are added to the layer (while the layer still │ │ │ │ │ - * has a reference to the original). │ │ │ │ │ - * aftersplit - Triggered after all splits resulting from a single sketch │ │ │ │ │ - * or feature modification have occurred. The original features │ │ │ │ │ - * have been destroyed and features that result from the split │ │ │ │ │ - * have already been added to the layer. Listeners receive an event │ │ │ │ │ - * with a *source* and *features* property. The source references the │ │ │ │ │ - * sketch or modified feature used as a splitter. The features │ │ │ │ │ - * property is a list of all resulting features. │ │ │ │ │ - */ │ │ │ │ │ +OpenLayers.Strategy = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layer │ │ │ │ │ - * {} The target layer with features to be split. │ │ │ │ │ - * Set at construction or after construction with . │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} The layer this strategy belongs to. │ │ │ │ │ */ │ │ │ │ │ layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: source │ │ │ │ │ - * {} Optional source layer. Any newly created │ │ │ │ │ - * or modified features from this layer will be used to split features │ │ │ │ │ - * on the target layer. If not provided, a temporary sketch layer will │ │ │ │ │ - * be created. │ │ │ │ │ - */ │ │ │ │ │ - source: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: sourceOptions │ │ │ │ │ - * {Options} If a temporary sketch layer is created, these layer options │ │ │ │ │ - * will be applied. │ │ │ │ │ - */ │ │ │ │ │ - sourceOptions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: tolerance │ │ │ │ │ - * {Number} Distance between the calculated intersection and a vertex on │ │ │ │ │ - * the source geometry below which the existing vertex will be used │ │ │ │ │ - * for the split. Default is null. │ │ │ │ │ + * Property: options │ │ │ │ │ + * {Object} Any options sent to the constructor. │ │ │ │ │ */ │ │ │ │ │ - tolerance: null, │ │ │ │ │ + options: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: edge │ │ │ │ │ - * {Boolean} Allow splits given intersection of edges only. Default is │ │ │ │ │ - * true. If false, a vertex on the source must be within the │ │ │ │ │ - * distance of the calculated intersection for a split │ │ │ │ │ - * to occur. │ │ │ │ │ + /** │ │ │ │ │ + * Property: active │ │ │ │ │ + * {Boolean} The control is active. │ │ │ │ │ */ │ │ │ │ │ - edge: true, │ │ │ │ │ + active: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: deferDelete │ │ │ │ │ - * {Boolean} Instead of removing features from the layer, set feature │ │ │ │ │ - * states of split features to DELETE. This assumes a save strategy │ │ │ │ │ - * or other component is in charge of removing features from the │ │ │ │ │ - * layer. Default is false. If false, split features will be │ │ │ │ │ - * immediately deleted from the layer. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - deferDelete: false, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: mutual │ │ │ │ │ - * {Boolean} If source and target layers are the same, split source │ │ │ │ │ - * features and target features where they intersect. Default is │ │ │ │ │ - * true. If false, only target features will be split. │ │ │ │ │ + * Property: autoDestroy │ │ │ │ │ + * {Boolean} The creator of the strategy can set autoDestroy to false │ │ │ │ │ + * to fully control when the strategy is destroyed. Defaults to │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - mutual: true, │ │ │ │ │ + autoDestroy: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: targetFilter │ │ │ │ │ - * {} Optional filter that will be evaluated │ │ │ │ │ - * to determine if a feature from the target layer is eligible for │ │ │ │ │ - * splitting. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - targetFilter: 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: sourceFilter │ │ │ │ │ - * {} Optional filter that will be evaluated │ │ │ │ │ - * to determine if a feature from the source layer is eligible for │ │ │ │ │ - * splitting. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Clean up the strategy. │ │ │ │ │ */ │ │ │ │ │ - sourceFilter: null, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + this.layer = null; │ │ │ │ │ + this.options = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: handler │ │ │ │ │ - * {} The temporary sketch handler created if │ │ │ │ │ - * no source layer is provided. │ │ │ │ │ + * Method: setLayer │ │ │ │ │ + * Called to set the property. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ */ │ │ │ │ │ - handler: null, │ │ │ │ │ + setLayer: function(layer) { │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Split │ │ │ │ │ - * Creates a new split control. A control is constructed with a target │ │ │ │ │ - * layer and an optional source layer. While the control is active, │ │ │ │ │ - * creating new features or modifying existing features on the source │ │ │ │ │ - * layer will result in splitting any eligible features on the target │ │ │ │ │ - * layer. If no source layer is provided, a temporary sketch layer will │ │ │ │ │ - * be created to create lines for splitting features on the target. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An object containing all configuration properties for │ │ │ │ │ - * the control. │ │ │ │ │ + * Method: activate │ │ │ │ │ + * Activate the strategy. Register any listeners, do appropriate setup. │ │ │ │ │ * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * layer - {} The target layer. Features from this │ │ │ │ │ - * layer will be split by new or modified features on the source layer │ │ │ │ │ - * or temporary sketch layer. │ │ │ │ │ - * source - {} Optional source layer. If provided │ │ │ │ │ - * newly created features or modified features will be used to split │ │ │ │ │ - * features on the target layer. If not provided, a temporary sketch │ │ │ │ │ - * layer will be created for drawing lines. │ │ │ │ │ - * tolerance - {Number} Optional value for the distance between a source │ │ │ │ │ - * vertex and the calculated intersection below which the split will │ │ │ │ │ - * occur at the vertex. │ │ │ │ │ - * edge - {Boolean} Allow splits given intersection of edges only. Default │ │ │ │ │ - * is true. If false, a vertex on the source must be within the │ │ │ │ │ - * distance of the calculated intersection for a split │ │ │ │ │ - * to occur. │ │ │ │ │ - * mutual - {Boolean} If source and target are the same, split source │ │ │ │ │ - * features and target features where they intersect. Default is │ │ │ │ │ - * true. If false, only target features will be split. │ │ │ │ │ - * targetFilter - {} Optional filter that will be evaluated │ │ │ │ │ - * to determine if a feature from the target layer is eligible for │ │ │ │ │ - * splitting. │ │ │ │ │ - * sourceFilter - {} Optional filter that will be evaluated │ │ │ │ │ - * to determine if a feature from the target layer is eligible for │ │ │ │ │ - * splitting. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} True if the strategy was successfully activated or false if │ │ │ │ │ + * the strategy was already active. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.options = options || {}; // TODO: this could be done by the super │ │ │ │ │ - │ │ │ │ │ - // set the source layer if provided │ │ │ │ │ - if (this.options.source) { │ │ │ │ │ - this.setSource(this.options.source); │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (!this.active) { │ │ │ │ │ + this.active = true; │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setSource │ │ │ │ │ - * Set the source layer for edits layer. │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + * Deactivate the strategy. Unregister any listeners, do appropriate │ │ │ │ │ + * tear-down. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} The new source layer layer. If │ │ │ │ │ - * null, a temporary sketch layer will be created. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} True if the strategy was successfully deactivated or false if │ │ │ │ │ + * the strategy was already inactive. │ │ │ │ │ */ │ │ │ │ │ - setSource: function(layer) { │ │ │ │ │ + deactivate: function() { │ │ │ │ │ if (this.active) { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - if (this.handler) { │ │ │ │ │ - this.handler.destroy(); │ │ │ │ │ - delete this.handler; │ │ │ │ │ - } │ │ │ │ │ - this.source = layer; │ │ │ │ │ - this.activate(); │ │ │ │ │ - } else { │ │ │ │ │ - this.source = layer; │ │ │ │ │ + this.active = false; │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the control. Activating the control registers listeners for │ │ │ │ │ - * editing related events so that during feature creation and │ │ │ │ │ - * modification, features in the target will be considered for │ │ │ │ │ - * splitting. │ │ │ │ │ + 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. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = OpenLayers.Control.prototype.activate.call(this); │ │ │ │ │ - if (activated) { │ │ │ │ │ - if (!this.source) { │ │ │ │ │ - if (!this.handler) { │ │ │ │ │ - this.handler = new OpenLayers.Handler.Path(this, { │ │ │ │ │ - done: function(geometry) { │ │ │ │ │ - this.onSketchComplete({ │ │ │ │ │ - feature: new OpenLayers.Feature.Vector(geometry) │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, { │ │ │ │ │ - layerOptions: this.sourceOptions │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - this.handler.activate(); │ │ │ │ │ - } else if (this.source.events) { │ │ │ │ │ - this.source.events.on({ │ │ │ │ │ - sketchcomplete: this.onSketchComplete, │ │ │ │ │ - afterfeaturemodified: this.afterFeatureModified, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - return activated; │ │ │ │ │ + this.events = new OpenLayers.Events(this, this.icon.imageDiv); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the control. Deactivating the control unregisters listeners │ │ │ │ │ - * so feature editing may proceed without engaging the split agent. │ │ │ │ │ + * 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.) │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = OpenLayers.Control.prototype.deactivate.call(this); │ │ │ │ │ - if (deactivated) { │ │ │ │ │ - if (this.source && this.source.events) { │ │ │ │ │ - this.source.events.un({ │ │ │ │ │ - sketchcomplete: this.onSketchComplete, │ │ │ │ │ - afterfeaturemodified: this.afterFeatureModified, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onSketchComplete │ │ │ │ │ - * Registered as a listener for the sketchcomplete event on the editable │ │ │ │ │ - * layer. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Calls draw on the icon, and returns that output. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * event - {Object} The sketch complete event. │ │ │ │ │ - * │ │ │ │ │ + * px - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} Stop the sketch from being added to the layer (it has been │ │ │ │ │ - * split). │ │ │ │ │ + * {DOMElement} A new DOM Image with this marker's icon set at the │ │ │ │ │ + * location passed-in │ │ │ │ │ */ │ │ │ │ │ - onSketchComplete: function(event) { │ │ │ │ │ - this.feature = null; │ │ │ │ │ - return !this.considerSplit(event.feature); │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + return this.icon.draw(px); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: afterFeatureModified │ │ │ │ │ - * Registered as a listener for the afterfeaturemodified event on the │ │ │ │ │ - * editable layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * event - {Object} The after feature modified event. │ │ │ │ │ + /** │ │ │ │ │ + * Method: erase │ │ │ │ │ + * Erases any drawn elements for this marker. │ │ │ │ │ */ │ │ │ │ │ - afterFeatureModified: function(event) { │ │ │ │ │ - if (event.modified) { │ │ │ │ │ - var feature = event.feature; │ │ │ │ │ - if (typeof feature.geometry.split === "function") { │ │ │ │ │ - this.feature = event.feature; │ │ │ │ │ - this.considerSplit(event.feature); │ │ │ │ │ - } │ │ │ │ │ + erase: function() { │ │ │ │ │ + if (this.icon != null) { │ │ │ │ │ + this.icon.erase(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeByGeometry │ │ │ │ │ - * Remove a feature from a list based on the given geometry. │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * Move the marker to the new location. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array()} A list of features. │ │ │ │ │ - * geometry - {} A geometry. │ │ │ │ │ + * px - {|Object} the pixel position to move to. │ │ │ │ │ + * An OpenLayers.Pixel or an object with a 'x' and 'y' properties. │ │ │ │ │ */ │ │ │ │ │ - removeByGeometry: function(features, geometry) { │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - if (features[i].geometry === geometry) { │ │ │ │ │ - features.splice(i, 1); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + if ((px != null) && (this.icon != null)) { │ │ │ │ │ + this.icon.moveTo(px); │ │ │ │ │ } │ │ │ │ │ + this.lonlat = this.map.getLonLatFromLayerPx(px); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: isEligible │ │ │ │ │ - * Test if a target feature is eligible for splitting. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * target - {} The target feature. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: isDrawn │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The target is eligible for splitting. │ │ │ │ │ + * {Boolean} Whether or not the marker is drawn. │ │ │ │ │ */ │ │ │ │ │ - isEligible: function(target) { │ │ │ │ │ - if (!target.geometry) { │ │ │ │ │ - return false; │ │ │ │ │ - } else { │ │ │ │ │ - return ( │ │ │ │ │ - target.state !== OpenLayers.State.DELETE │ │ │ │ │ - ) && ( │ │ │ │ │ - typeof target.geometry.split === "function" │ │ │ │ │ - ) && ( │ │ │ │ │ - this.feature !== target │ │ │ │ │ - ) && ( │ │ │ │ │ - !this.targetFilter || │ │ │ │ │ - this.targetFilter.evaluate(target.attributes) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + isDrawn: function() { │ │ │ │ │ + var isDrawn = (this.icon && this.icon.isDrawn()); │ │ │ │ │ + return isDrawn; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: considerSplit │ │ │ │ │ - * Decide whether or not to split target features with the supplied │ │ │ │ │ - * feature. If is true, both the source and target features │ │ │ │ │ - * will be split if eligible. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} The newly created or modified │ │ │ │ │ - * feature. │ │ │ │ │ + * Method: onScreen │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Boolean} The supplied feature was split (and destroyed). │ │ │ │ │ + * {Boolean} Whether or not the marker is currently visible on screen. │ │ │ │ │ */ │ │ │ │ │ - considerSplit: function(feature) { │ │ │ │ │ - var sourceSplit = false; │ │ │ │ │ - var targetSplit = false; │ │ │ │ │ - if (!this.sourceFilter || │ │ │ │ │ - this.sourceFilter.evaluate(feature.attributes)) { │ │ │ │ │ - var features = this.layer && this.layer.features || []; │ │ │ │ │ - var target, results, proceed; │ │ │ │ │ - var additions = [], │ │ │ │ │ - removals = []; │ │ │ │ │ - var mutual = (this.layer === this.source) && this.mutual; │ │ │ │ │ - var options = { │ │ │ │ │ - edge: this.edge, │ │ │ │ │ - tolerance: this.tolerance, │ │ │ │ │ - mutual: mutual │ │ │ │ │ - }; │ │ │ │ │ - var sourceParts = [feature.geometry]; │ │ │ │ │ - var targetFeature, targetParts; │ │ │ │ │ - var source, parts; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - targetFeature = features[i]; │ │ │ │ │ - if (this.isEligible(targetFeature)) { │ │ │ │ │ - targetParts = [targetFeature.geometry]; │ │ │ │ │ - // work through source geoms - this array may change │ │ │ │ │ - for (var j = 0; j < sourceParts.length; ++j) { │ │ │ │ │ - source = sourceParts[j]; │ │ │ │ │ - // work through target parts - this array may change │ │ │ │ │ - for (var k = 0; k < targetParts.length; ++k) { │ │ │ │ │ - target = targetParts[k]; │ │ │ │ │ - if (source.getBounds().intersectsBounds(target.getBounds())) { │ │ │ │ │ - results = source.split(target, options); │ │ │ │ │ - if (results) { │ │ │ │ │ - proceed = this.events.triggerEvent( │ │ │ │ │ - "beforesplit", { │ │ │ │ │ - source: feature, │ │ │ │ │ - target: targetFeature │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - if (proceed !== false) { │ │ │ │ │ - if (mutual) { │ │ │ │ │ - parts = results[0]; │ │ │ │ │ - // handle parts that result from source splitting │ │ │ │ │ - if (parts.length > 1) { │ │ │ │ │ - // splice in new source parts │ │ │ │ │ - parts.unshift(j, 1); // add args for splice below │ │ │ │ │ - Array.prototype.splice.apply(sourceParts, parts); │ │ │ │ │ - j += parts.length - 3; │ │ │ │ │ - } │ │ │ │ │ - results = results[1]; │ │ │ │ │ - } │ │ │ │ │ - // handle parts that result from target splitting │ │ │ │ │ - if (results.length > 1) { │ │ │ │ │ - // splice in new target parts │ │ │ │ │ - results.unshift(k, 1); // add args for splice below │ │ │ │ │ - Array.prototype.splice.apply(targetParts, results); │ │ │ │ │ - k += results.length - 3; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (targetParts && targetParts.length > 1) { │ │ │ │ │ - this.geomsToFeatures(targetFeature, targetParts); │ │ │ │ │ - this.events.triggerEvent("split", { │ │ │ │ │ - original: targetFeature, │ │ │ │ │ - features: targetParts │ │ │ │ │ - }); │ │ │ │ │ - Array.prototype.push.apply(additions, targetParts); │ │ │ │ │ - removals.push(targetFeature); │ │ │ │ │ - targetSplit = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (sourceParts && sourceParts.length > 1) { │ │ │ │ │ - this.geomsToFeatures(feature, sourceParts); │ │ │ │ │ - this.events.triggerEvent("split", { │ │ │ │ │ - original: feature, │ │ │ │ │ - features: sourceParts │ │ │ │ │ - }); │ │ │ │ │ - Array.prototype.push.apply(additions, sourceParts); │ │ │ │ │ - removals.push(feature); │ │ │ │ │ - sourceSplit = true; │ │ │ │ │ - } │ │ │ │ │ - if (sourceSplit || targetSplit) { │ │ │ │ │ - // remove and add feature events are suppressed │ │ │ │ │ - // listen for split event on this control instead │ │ │ │ │ - if (this.deferDelete) { │ │ │ │ │ - // Set state instead of removing. Take care to avoid │ │ │ │ │ - // setting delete for features that have not yet been │ │ │ │ │ - // inserted - those should be destroyed immediately. │ │ │ │ │ - var feat, destroys = []; │ │ │ │ │ - for (var i = 0, len = removals.length; i < len; ++i) { │ │ │ │ │ - feat = removals[i]; │ │ │ │ │ - if (feat.state === OpenLayers.State.INSERT) { │ │ │ │ │ - destroys.push(feat); │ │ │ │ │ - } else { │ │ │ │ │ - feat.state = OpenLayers.State.DELETE; │ │ │ │ │ - this.layer.drawFeature(feat); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.layer.destroyFeatures(destroys, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - for (var i = 0, len = additions.length; i < len; ++i) { │ │ │ │ │ - additions[i].state = OpenLayers.State.INSERT; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - this.layer.destroyFeatures(removals, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - this.layer.addFeatures(additions, { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.events.triggerEvent("aftersplit", { │ │ │ │ │ - source: feature, │ │ │ │ │ - features: additions │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + onScreen: function() { │ │ │ │ │ + │ │ │ │ │ + var onScreen = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + var screenBounds = this.map.getExtent(); │ │ │ │ │ + onScreen = screenBounds.containsLonLat(this.lonlat); │ │ │ │ │ } │ │ │ │ │ - return sourceSplit; │ │ │ │ │ + return onScreen; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: geomsToFeatures │ │ │ │ │ - * Create new features given a template feature and a list of geometries. │ │ │ │ │ - * The list of geometries is modified in place. The result will be │ │ │ │ │ - * a list of new features. │ │ │ │ │ + * Method: inflate │ │ │ │ │ + * Englarges the markers icon by the specified ratio. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} The feature to be cloned. │ │ │ │ │ - * geoms - {Array()} List of goemetries. This will │ │ │ │ │ - * become a list of new features. │ │ │ │ │ + * inflate - {float} the ratio to enlarge the marker by (passing 2 │ │ │ │ │ + * will double the size). │ │ │ │ │ */ │ │ │ │ │ - geomsToFeatures: function(feature, geoms) { │ │ │ │ │ - var clone = feature.clone(); │ │ │ │ │ - delete clone.geometry; │ │ │ │ │ - var newFeature; │ │ │ │ │ - for (var i = 0, len = geoms.length; i < len; ++i) { │ │ │ │ │ - // turn results list from geoms to features │ │ │ │ │ - newFeature = clone.clone(); │ │ │ │ │ - newFeature.geometry = geoms[i]; │ │ │ │ │ - newFeature.state = OpenLayers.State.INSERT; │ │ │ │ │ - geoms[i] = newFeature; │ │ │ │ │ + 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: destroy │ │ │ │ │ - * Clean up the control. │ │ │ │ │ + * Method: setUrl │ │ │ │ │ + * Change URL of the Icon Image. │ │ │ │ │ + * │ │ │ │ │ + * url - {String} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.deactivate(); // TODO: this should be handled by the super │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.prototype.destroy.call(this); │ │ │ │ │ + setUrl: function(url) { │ │ │ │ │ + this.icon.setUrl(url); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Split" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Button.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: display │ │ │ │ │ + * Hide or show the icon │ │ │ │ │ + * │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + display: function(display) { │ │ │ │ │ + this.icon.display(display); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of 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_NAME: "OpenLayers.Marker" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Button │ │ │ │ │ - * The Button control is a very simple push-button, for use with │ │ │ │ │ - * . │ │ │ │ │ - * When clicked, the function trigger() is executed. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * │ │ │ │ │ - * Use: │ │ │ │ │ - * (code) │ │ │ │ │ - * var button = new OpenLayers.Control.Button({ │ │ │ │ │ - * displayClass: "MyButton", trigger: myFunction │ │ │ │ │ - * }); │ │ │ │ │ - * panel.addControls([button]); │ │ │ │ │ - * (end) │ │ │ │ │ + * Function: defaultIcon │ │ │ │ │ + * Creates a default . │ │ │ │ │ * │ │ │ │ │ - * Will create a button with CSS class MyButtonItemInactive, that │ │ │ │ │ - * will call the function MyFunction() when clicked. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A default OpenLayers.Icon to use for a marker │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Button = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - /** │ │ │ │ │ - * Property: type │ │ │ │ │ - * {Integer} OpenLayers.Control.TYPE_BUTTON. │ │ │ │ │ - */ │ │ │ │ │ - type: OpenLayers.Control.TYPE_BUTTON, │ │ │ │ │ +OpenLayers.Marker.defaultIcon = function() { │ │ │ │ │ + return new OpenLayers.Icon(OpenLayers.Util.getImageLocation("marker.png"), { │ │ │ │ │ + w: 21, │ │ │ │ │ + h: 25 │ │ │ │ │ + }, { │ │ │ │ │ + x: -10.5, │ │ │ │ │ + y: -25 │ │ │ │ │ + }); │ │ │ │ │ +}; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: trigger │ │ │ │ │ - * Called by a control panel when the button is clicked. │ │ │ │ │ - */ │ │ │ │ │ - trigger: function() {}, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Button" │ │ │ │ │ -}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Panel.js │ │ │ │ │ + OpenLayers/Handler.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Panel │ │ │ │ │ - * The Panel control is a container for other controls. With it toolbars │ │ │ │ │ - * may be composed. │ │ │ │ │ + * Class: OpenLayers.Handler │ │ │ │ │ + * Base class to construct a higher-level handler for event sequences. All │ │ │ │ │ + * handlers have activate and deactivate methods. In addition, they have │ │ │ │ │ + * methods named like browser events. When a handler is activated, any │ │ │ │ │ + * additional methods named like a browser event is registered as a │ │ │ │ │ + * listener for the corresponding event. When a handler is deactivated, │ │ │ │ │ + * those same methods are unregistered as event listeners. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * Handlers also typically have a callbacks object with keys named like │ │ │ │ │ + * the abstracted events or event sequences that they are in charge of │ │ │ │ │ + * handling. The controls that wrap handlers define the methods that │ │ │ │ │ + * correspond to these abstract events - so instead of listening for │ │ │ │ │ + * individual browser events, they only listen for the abstract events │ │ │ │ │ + * defined by the handler. │ │ │ │ │ + * │ │ │ │ │ + * Handlers are created by controls, which ultimately have the responsibility │ │ │ │ │ + * of making changes to the the state of the application. Handlers │ │ │ │ │ + * themselves may make temporary changes, but in general are expected to │ │ │ │ │ + * return the application in the same state that they found it. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - /** │ │ │ │ │ - * Property: controls │ │ │ │ │ - * {Array()} │ │ │ │ │ - */ │ │ │ │ │ - controls: null, │ │ │ │ │ +OpenLayers.Handler = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: defaultControl │ │ │ │ │ - * {} The control which is activated when the control is │ │ │ │ │ - * activated (turned on), which also happens at instantiation. │ │ │ │ │ - * If is true, will be nullified after the │ │ │ │ │ - * first activation of the panel. │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - defaultControl: null, │ │ │ │ │ + control: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: saveState │ │ │ │ │ - * {Boolean} If set to true, the active state of this panel's controls will │ │ │ │ │ - * be stored on panel deactivation, and restored on reactivation. Default │ │ │ │ │ - * is false. │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - saveState: false, │ │ │ │ │ + map: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: allowDepress │ │ │ │ │ - * {Boolean} If is true the controls can │ │ │ │ │ - * be deactivated by clicking the icon that represents them. Default │ │ │ │ │ - * is false. │ │ │ │ │ + * 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) │ │ │ │ │ */ │ │ │ │ │ - allowDepress: false, │ │ │ │ │ + keyMask: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: activeState │ │ │ │ │ - * {Object} stores the active state of this panel's controls. │ │ │ │ │ + * Property: active │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - activeState: null, │ │ │ │ │ + active: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Panel │ │ │ │ │ - * Create a new control panel. │ │ │ │ │ - * │ │ │ │ │ - * Each control in the panel is represented by an icon. When clicking │ │ │ │ │ - * on an icon, the method is called. │ │ │ │ │ - * │ │ │ │ │ - * Specific properties for controls on a panel: │ │ │ │ │ - * type - {Number} One of , │ │ │ │ │ - * , . │ │ │ │ │ - * If not provided, is assumed. │ │ │ │ │ - * title - {string} Text displayed when mouse is over the icon that │ │ │ │ │ - * represents the control. │ │ │ │ │ - * │ │ │ │ │ - * The of a control determines the behavior when │ │ │ │ │ - * clicking its icon: │ │ │ │ │ - * - The control is activated and other │ │ │ │ │ - * controls of this type in the same panel are deactivated. This is │ │ │ │ │ - * the default type. │ │ │ │ │ - * - The active state of the control is │ │ │ │ │ - * toggled. │ │ │ │ │ - * - The │ │ │ │ │ - * method of the control is called, │ │ │ │ │ - * but its active state is not changed. │ │ │ │ │ - * │ │ │ │ │ - * If a control is , it will be drawn with the │ │ │ │ │ - * olControl[Name]ItemActive class, otherwise with the │ │ │ │ │ - * olControl[Name]ItemInactive class. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.controls = []; │ │ │ │ │ - this.activeState = {}; │ │ │ │ │ - }, │ │ │ │ │ + evt: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.events.unregister("buttonclick", this, this.onButtonClick); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - for (var ctl, i = this.controls.length - 1; i >= 0; i--) { │ │ │ │ │ - ctl = this.controls[i]; │ │ │ │ │ - if (ctl.events) { │ │ │ │ │ - ctl.events.un({ │ │ │ │ │ - activate: this.iconOn, │ │ │ │ │ - deactivate: this.iconOff │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - ctl.panel_div = null; │ │ │ │ │ - } │ │ │ │ │ - this.activeState = null; │ │ │ │ │ - }, │ │ │ │ │ + touch: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - var control; │ │ │ │ │ - for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ - control = this.controls[i]; │ │ │ │ │ - if (control === this.defaultControl || │ │ │ │ │ - (this.saveState && this.activeState[control.id])) { │ │ │ │ │ - control.activate(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.saveState === true) { │ │ │ │ │ - this.defaultControl = null; │ │ │ │ │ - } │ │ │ │ │ - this.redraw(); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ + 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 + "_"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ + * Method: setMap │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - var control; │ │ │ │ │ - for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ - control = this.controls[i]; │ │ │ │ │ - this.activeState[control.id] = control.deactivate(); │ │ │ │ │ - } │ │ │ │ │ - this.redraw(); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.map = map; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * 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: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * {Boolean} The keyMask matches the keys down on an event. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (this.outsideViewport) { │ │ │ │ │ - this.events.attachToElement(this.div); │ │ │ │ │ - this.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ - } else { │ │ │ │ │ - this.map.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ + checkModifiers: function(evt) { │ │ │ │ │ + if (this.keyMask == null) { │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ - this.addControlsToMap(this.controls); │ │ │ │ │ - return this.div; │ │ │ │ │ + /* 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: redraw │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Turn on the handler. Returns false if the handler was already active. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was activated. │ │ │ │ │ */ │ │ │ │ │ - redraw: function() { │ │ │ │ │ - for (var l = this.div.childNodes.length, i = l - 1; i >= 0; i--) { │ │ │ │ │ - this.div.removeChild(this.div.childNodes[i]); │ │ │ │ │ - } │ │ │ │ │ - this.div.innerHTML = ""; │ │ │ │ │ + activate: function() { │ │ │ │ │ if (this.active) { │ │ │ │ │ - for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ - this.div.appendChild(this.controls[i].panel_div); │ │ │ │ │ + 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: activateControl │ │ │ │ │ - * This method is called when the user click on the icon representing a │ │ │ │ │ - * control in the panel. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Turn off the handler. Returns false if the handler was already inactive. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was deactivated. │ │ │ │ │ */ │ │ │ │ │ - activateControl: function(control) { │ │ │ │ │ + deactivate: function() { │ │ │ │ │ if (!this.active) { │ │ │ │ │ return false; │ │ │ │ │ } │ │ │ │ │ - if (control.type == OpenLayers.Control.TYPE_BUTTON) { │ │ │ │ │ - control.trigger(); │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (control.type == OpenLayers.Control.TYPE_TOGGLE) { │ │ │ │ │ - if (control.active) { │ │ │ │ │ - control.deactivate(); │ │ │ │ │ - } else { │ │ │ │ │ - control.activate(); │ │ │ │ │ + // 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]]); │ │ │ │ │ } │ │ │ │ │ - return; │ │ │ │ │ } │ │ │ │ │ - if (this.allowDepress && control.active) { │ │ │ │ │ - control.deactivate(); │ │ │ │ │ - } else { │ │ │ │ │ - var c; │ │ │ │ │ - for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ - c = this.controls[i]; │ │ │ │ │ - if (c != control && │ │ │ │ │ - (c.type === OpenLayers.Control.TYPE_TOOL || c.type == null)) { │ │ │ │ │ - c.deactivate(); │ │ │ │ │ + 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]]); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - control.activate(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: addControls │ │ │ │ │ - * To build a toolbar, you add a set of controls to it. addControls │ │ │ │ │ - * lets you add a single control or a list of controls to the │ │ │ │ │ - * Control Panel. │ │ │ │ │ + * Method: callback │ │ │ │ │ + * Trigger the control's named callback with the given arguments │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * controls - {} Controls to add in the panel. │ │ │ │ │ + * 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). │ │ │ │ │ */ │ │ │ │ │ - addControls: function(controls) { │ │ │ │ │ - if (!(OpenLayers.Util.isArray(controls))) { │ │ │ │ │ - controls = [controls]; │ │ │ │ │ + callback: function(name, args) { │ │ │ │ │ + if (name && this.callbacks[name]) { │ │ │ │ │ + this.callbacks[name].apply(this.control, args); │ │ │ │ │ } │ │ │ │ │ - this.controls = this.controls.concat(controls); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - for (var i = 0, len = controls.length; i < len; i++) { │ │ │ │ │ - var control = controls[i], │ │ │ │ │ - element = this.createControlMarkup(control); │ │ │ │ │ - OpenLayers.Element.addClass(element, │ │ │ │ │ - control.displayClass + "ItemInactive"); │ │ │ │ │ - OpenLayers.Element.addClass(element, "olButton"); │ │ │ │ │ - if (control.title != "" && !element.title) { │ │ │ │ │ - element.title = control.title; │ │ │ │ │ - } │ │ │ │ │ - control.panel_div = element; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.map) { // map.addControl() has already been called on the panel │ │ │ │ │ - this.addControlsToMap(controls); │ │ │ │ │ - this.redraw(); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * 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); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: createControlMarkup │ │ │ │ │ - * This function just creates a div for the control. If specific HTML │ │ │ │ │ - * markup is needed this function can be overridden in specific classes, │ │ │ │ │ - * or at panel instantiation time: │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * var panel = new OpenLayers.Control.Panel({ │ │ │ │ │ - * defaultControl: control, │ │ │ │ │ - * // ovverride createControlMarkup to create actual buttons │ │ │ │ │ - * // including texts wrapped into span elements. │ │ │ │ │ - * createControlMarkup: function(control) { │ │ │ │ │ - * var button = document.createElement('button'), │ │ │ │ │ - * span = document.createElement('span'); │ │ │ │ │ - * if (control.text) { │ │ │ │ │ - * span.innerHTML = control.text; │ │ │ │ │ - * } │ │ │ │ │ - * return button; │ │ │ │ │ - * } │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ + * 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: │ │ │ │ │ - * control - {} The control to create the HTML │ │ │ │ │ - * markup for. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The markup. │ │ │ │ │ + * evt - {Event} The browser event. │ │ │ │ │ */ │ │ │ │ │ - createControlMarkup: function(control) { │ │ │ │ │ - return document.createElement("div"); │ │ │ │ │ + setEvent: function(evt) { │ │ │ │ │ + this.evt = evt; │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addControlsToMap │ │ │ │ │ - * Only for internal use in draw() and addControls() methods. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * controls - {Array()} Controls to add into map. │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Deconstruct the handler. │ │ │ │ │ */ │ │ │ │ │ - addControlsToMap: function(controls) { │ │ │ │ │ - var control; │ │ │ │ │ - for (var i = 0, len = controls.length; i < len; i++) { │ │ │ │ │ - control = controls[i]; │ │ │ │ │ - if (control.autoActivate === true) { │ │ │ │ │ - control.autoActivate = false; │ │ │ │ │ - this.map.addControl(control); │ │ │ │ │ - control.autoActivate = true; │ │ │ │ │ - } else { │ │ │ │ │ - this.map.addControl(control); │ │ │ │ │ - control.deactivate(); │ │ │ │ │ - } │ │ │ │ │ - control.events.on({ │ │ │ │ │ - activate: this.iconOn, │ │ │ │ │ - deactivate: this.iconOff │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + destroy: function() { │ │ │ │ │ + // unregister event listeners │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + // eliminate circular references │ │ │ │ │ + this.control = this.map = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: iconOn │ │ │ │ │ - * Internal use, for use only with "controls[i].events.on/un". │ │ │ │ │ - */ │ │ │ │ │ - iconOn: function() { │ │ │ │ │ - var d = this.panel_div; // "this" refers to a control on panel! │ │ │ │ │ - var re = new RegExp("\\b(" + this.displayClass + "Item)Inactive\\b"); │ │ │ │ │ - d.className = d.className.replace(re, "$1Active"); │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: iconOff │ │ │ │ │ - * Internal use, for use only with "controls[i].events.on/un". │ │ │ │ │ - */ │ │ │ │ │ - iconOff: function() { │ │ │ │ │ - var d = this.panel_div; // "this" refers to a control on panel! │ │ │ │ │ - var re = new RegExp("\\b(" + this.displayClass + "Item)Active\\b"); │ │ │ │ │ - d.className = d.className.replace(re, "$1Inactive"); │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_NONE │ │ │ │ │ + * If set as the , returns false if any key is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_NONE = 0; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: onButtonClick │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onButtonClick: function(evt) { │ │ │ │ │ - var controls = this.controls, │ │ │ │ │ - button = evt.buttonElement; │ │ │ │ │ - for (var i = controls.length - 1; i >= 0; --i) { │ │ │ │ │ - if (controls[i].panel_div === button) { │ │ │ │ │ - this.activateControl(controls[i]); │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_SHIFT │ │ │ │ │ + * If set as the , returns false if Shift is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_SHIFT = 1; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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(control[property]) evaluates to true, the control will be │ │ │ │ │ - * included in the array returned. If no controls 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. │ │ │ │ │ - */ │ │ │ │ │ - getControlsBy: function(property, match) { │ │ │ │ │ - var test = (typeof match.test == "function"); │ │ │ │ │ - var found = OpenLayers.Array.filter(this.controls, function(item) { │ │ │ │ │ - return item[property] == match || (test && match.test(item[property])); │ │ │ │ │ - }); │ │ │ │ │ - return found; │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_CTRL │ │ │ │ │ + * If set as the , returns false if Ctrl is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_CTRL = 2; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getControlsByName │ │ │ │ │ - * Get a list of contorls with names matching the given name. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * match - {String | Object} A control 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(control.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 name. │ │ │ │ │ - * An empty array is returned if no matches are found. │ │ │ │ │ - */ │ │ │ │ │ - getControlsByName: function(match) { │ │ │ │ │ - return this.getControlsBy("name", match); │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_ALT │ │ │ │ │ + * If set as the , returns false if Alt is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_ALT = 4; │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getControlsByClass │ │ │ │ │ - * Get a list of controls of a given type (CLASS_NAME). │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * match - {String | Object} A control class name. The type 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 type. │ │ │ │ │ - * An empty array is returned if no matches are found. │ │ │ │ │ - */ │ │ │ │ │ - getControlsByClass: function(match) { │ │ │ │ │ - return this.getControlsBy("CLASS_NAME", match); │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Handler.MOD_META │ │ │ │ │ + * If set as the , returns false if Cmd is down. │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MOD_META = 8; │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Panel" │ │ │ │ │ -}); │ │ │ │ │ │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Box.js │ │ │ │ │ + OpenLayers/Control.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes/Class.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Handler.Box │ │ │ │ │ - * Handler for dragging a rectangle across the map. Box is displayed │ │ │ │ │ - * on mouse down, moves on mouse move, and is finished on mouse up. │ │ │ │ │ + * Class: OpenLayers.Control │ │ │ │ │ + * Controls affect the display or behavior of the map. They allow everything │ │ │ │ │ + * from panning and zooming to displaying a scale indicator. Controls by │ │ │ │ │ + * default are added to the map they are contained within however it is │ │ │ │ │ + * possible to add a control to an external div by passing the div in the │ │ │ │ │ + * options parameter. │ │ │ │ │ + * │ │ │ │ │ + * Example: │ │ │ │ │ + * The following example shows how to add many of the common controls │ │ │ │ │ + * to a map. │ │ │ │ │ + * │ │ │ │ │ + * > var map = new OpenLayers.Map('map', { controls: [] }); │ │ │ │ │ + * > │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.PanZoomBar()); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.Permalink()); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.Permalink('permalink')); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.MousePosition()); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.OverviewMap()); │ │ │ │ │ + * > map.addControl(new OpenLayers.Control.KeyboardDefaults()); │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * The next code fragment is a quick example of how to intercept │ │ │ │ │ + * shift-mouse click to display the extent of the bounding box │ │ │ │ │ + * dragged out by the user. Usually controls are not created │ │ │ │ │ + * in exactly this manner. See the source for a more complete │ │ │ │ │ + * example: │ │ │ │ │ + * │ │ │ │ │ + * > var control = new OpenLayers.Control(); │ │ │ │ │ + * > OpenLayers.Util.extend(control, { │ │ │ │ │ + * > draw: function () { │ │ │ │ │ + * > // this Handler.Box will intercept the shift-mousedown │ │ │ │ │ + * > // before Control.MouseDefault gets to see it │ │ │ │ │ + * > this.box = new OpenLayers.Handler.Box( control, │ │ │ │ │ + * > {"done": this.notice}, │ │ │ │ │ + * > {keyMask: OpenLayers.Handler.MOD_SHIFT}); │ │ │ │ │ + * > this.box.activate(); │ │ │ │ │ + * > }, │ │ │ │ │ + * > │ │ │ │ │ + * > notice: function (bounds) { │ │ │ │ │ + * > OpenLayers.Console.userError(bounds); │ │ │ │ │ + * > } │ │ │ │ │ + * > }); │ │ │ │ │ + * > map.addControl(control); │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ +OpenLayers.Control = OpenLayers.Class({ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: dragHandler │ │ │ │ │ - * {} │ │ │ │ │ + * Property: id │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - dragHandler: null, │ │ │ │ │ + id: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: boxDivClassName │ │ │ │ │ - * {String} The CSS class to use for drawing the box. Default is │ │ │ │ │ - * olHandlerBoxZoomBox │ │ │ │ │ + /** │ │ │ │ │ + * Property: map │ │ │ │ │ + * {} this gets set in the addControl() function in │ │ │ │ │ + * OpenLayers.Map │ │ │ │ │ */ │ │ │ │ │ - boxDivClassName: 'olHandlerBoxZoomBox', │ │ │ │ │ + map: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: div │ │ │ │ │ + * {DOMElement} The element that contains the control, if not present the │ │ │ │ │ + * control is placed inside the map. │ │ │ │ │ + */ │ │ │ │ │ + div: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: type │ │ │ │ │ + * {Number} Controls can have a 'type'. The type determines the type of │ │ │ │ │ + * interactions which are possible with them when they are placed in an │ │ │ │ │ + * . │ │ │ │ │ + */ │ │ │ │ │ + type: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: allowSelection │ │ │ │ │ + * {Boolean} By default, controls do not allow selection, because │ │ │ │ │ + * it may interfere with map dragging. If this is true, OpenLayers │ │ │ │ │ + * will not prevent selection of the control. │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + allowSelection: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: displayClass │ │ │ │ │ + * {string} This property is used for CSS related to the drawing of the │ │ │ │ │ + * Control. │ │ │ │ │ + */ │ │ │ │ │ + displayClass: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: boxOffsets │ │ │ │ │ - * {Object} Caches box offsets from css. This is used by the getBoxOffsets │ │ │ │ │ - * method. │ │ │ │ │ + * APIProperty: title │ │ │ │ │ + * {string} This property is used for showing a tooltip over the │ │ │ │ │ + * Control. │ │ │ │ │ */ │ │ │ │ │ - boxOffsets: null, │ │ │ │ │ + title: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Box │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} │ │ │ │ │ - * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ - * functions. Various callbacks described below. │ │ │ │ │ - * options - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Named callbacks: │ │ │ │ │ - * start - Called when the box drag operation starts. │ │ │ │ │ - * done - Called when the box drag operation is finished. │ │ │ │ │ - * The callback should expect to receive a single argument, the box │ │ │ │ │ - * bounds or a pixel. If the box dragging didn't span more than a 5 │ │ │ │ │ - * pixel distance, a pixel will be returned instead of a bounds object. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * false. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.dragHandler = new OpenLayers.Handler.Drag( │ │ │ │ │ - this, { │ │ │ │ │ - down: this.startBox, │ │ │ │ │ - move: this.moveBox, │ │ │ │ │ - out: this.removeBox, │ │ │ │ │ - up: this.endBox │ │ │ │ │ - }, { │ │ │ │ │ - keyMask: this.keyMask │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + autoActivate: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: active │ │ │ │ │ + * {Boolean} The control is active (read-only). Use and │ │ │ │ │ + * to change control state. │ │ │ │ │ + */ │ │ │ │ │ + active: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * Property: handlerOptions │ │ │ │ │ + * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ - if (this.dragHandler) { │ │ │ │ │ - this.dragHandler.destroy(); │ │ │ │ │ - this.dragHandler = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + handlerOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: handler │ │ │ │ │ + * {} null │ │ │ │ │ + */ │ │ │ │ │ + handler: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Handler.prototype.setMap.apply(this, arguments); │ │ │ │ │ - if (this.dragHandler) { │ │ │ │ │ - this.dragHandler.setMap(map); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + eventListeners: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Listeners will be called with a reference to an event object. The │ │ │ │ │ + * properties of this event depends on exactly what happened. │ │ │ │ │ + * │ │ │ │ │ + * All event objects have at least the following properties: │ │ │ │ │ + * object - {Object} A reference to control.events.object (a reference │ │ │ │ │ + * to the control). │ │ │ │ │ + * element - {DOMElement} A reference to control.events.element (which │ │ │ │ │ + * will be null unless documented otherwise). │ │ │ │ │ + * │ │ │ │ │ + * Supported map event types: │ │ │ │ │ + * activate - Triggered when activated. │ │ │ │ │ + * deactivate - Triggered when deactivated. │ │ │ │ │ + */ │ │ │ │ │ + events: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: startBox │ │ │ │ │ + * Constructor: OpenLayers.Control │ │ │ │ │ + * Create an OpenLayers Control. The options passed as a parameter │ │ │ │ │ + * directly extend the control. For example passing the following: │ │ │ │ │ + * │ │ │ │ │ + * > var control = new OpenLayers.Control({div: myDiv}); │ │ │ │ │ * │ │ │ │ │ + * Overrides the default div attribute value of null. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * xy - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - startBox: function(xy) { │ │ │ │ │ - this.callback("start", []); │ │ │ │ │ - this.zoomBox = OpenLayers.Util.createDiv('zoomBox', { │ │ │ │ │ - x: -9999, │ │ │ │ │ - y: -9999 │ │ │ │ │ - }); │ │ │ │ │ - this.zoomBox.className = this.boxDivClassName; │ │ │ │ │ - this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + // We do this before the extend so that instances can override │ │ │ │ │ + // className in options. │ │ │ │ │ + this.displayClass = │ │ │ │ │ + this.CLASS_NAME.replace("OpenLayers.", "ol").replace(/\./g, ""); │ │ │ │ │ │ │ │ │ │ - this.map.viewPortDiv.appendChild(this.zoomBox); │ │ │ │ │ + OpenLayers.Util.extend(this, options); │ │ │ │ │ │ │ │ │ │ - OpenLayers.Element.addClass( │ │ │ │ │ - this.map.viewPortDiv, "olDrawBox" │ │ │ │ │ - ); │ │ │ │ │ + this.events = new OpenLayers.Events(this); │ │ │ │ │ + if (this.eventListeners instanceof Object) { │ │ │ │ │ + this.events.on(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + if (this.id == null) { │ │ │ │ │ + this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_"); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveBox │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * The destroy method is used to perform any clean up before the control │ │ │ │ │ + * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ + * to prevent memory leaks. │ │ │ │ │ */ │ │ │ │ │ - moveBox: function(xy) { │ │ │ │ │ - var startX = this.dragHandler.start.x; │ │ │ │ │ - var startY = this.dragHandler.start.y; │ │ │ │ │ - var deltaX = Math.abs(startX - xy.x); │ │ │ │ │ - var deltaY = Math.abs(startY - xy.y); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.events) { │ │ │ │ │ + if (this.eventListeners) { │ │ │ │ │ + this.events.un(this.eventListeners); │ │ │ │ │ + } │ │ │ │ │ + this.events.destroy(); │ │ │ │ │ + this.events = null; │ │ │ │ │ + } │ │ │ │ │ + this.eventListeners = null; │ │ │ │ │ │ │ │ │ │ - var offset = this.getBoxOffsets(); │ │ │ │ │ - this.zoomBox.style.width = (deltaX + offset.width + 1) + "px"; │ │ │ │ │ - this.zoomBox.style.height = (deltaY + offset.height + 1) + "px"; │ │ │ │ │ - this.zoomBox.style.left = (xy.x < startX ? │ │ │ │ │ - startX - deltaX - offset.left : startX - offset.left) + "px"; │ │ │ │ │ - this.zoomBox.style.top = (xy.y < startY ? │ │ │ │ │ - startY - deltaY - offset.top : startY - offset.top) + "px"; │ │ │ │ │ + // eliminate circular references │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.destroy(); │ │ │ │ │ + this.handler = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.handlers) { │ │ │ │ │ + for (var key in this.handlers) { │ │ │ │ │ + if (this.handlers.hasOwnProperty(key) && │ │ │ │ │ + typeof this.handlers[key].destroy == "function") { │ │ │ │ │ + this.handlers[key].destroy(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.handlers = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.removeControl(this); │ │ │ │ │ + this.map = null; │ │ │ │ │ + } │ │ │ │ │ + this.div = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: endBox │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control. This is done through an accessor │ │ │ │ │ + * so that subclasses can override this and take special action once │ │ │ │ │ + * they have their map variable set. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - endBox: function(end) { │ │ │ │ │ - var result; │ │ │ │ │ - if (Math.abs(this.dragHandler.start.x - end.x) > 5 || │ │ │ │ │ - Math.abs(this.dragHandler.start.y - end.y) > 5) { │ │ │ │ │ - var start = this.dragHandler.start; │ │ │ │ │ - var top = Math.min(start.y, end.y); │ │ │ │ │ - var bottom = Math.max(start.y, end.y); │ │ │ │ │ - var left = Math.min(start.x, end.x); │ │ │ │ │ - var right = Math.max(start.x, end.x); │ │ │ │ │ - result = new OpenLayers.Bounds(left, bottom, right, top); │ │ │ │ │ - } else { │ │ │ │ │ - result = this.dragHandler.start.clone(); // i.e. OL.Pixel │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.map = map; │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.setMap(map); │ │ │ │ │ } │ │ │ │ │ - this.removeBox(); │ │ │ │ │ - │ │ │ │ │ - this.callback("done", [result]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeBox │ │ │ │ │ - * Remove the zoombox from the screen and nullify our reference to it. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * The draw method is called when the control is ready to be displayed │ │ │ │ │ + * on the page. If a div has not been created one is created. Controls │ │ │ │ │ + * with a visual component will almost always want to override this method │ │ │ │ │ + * to customize the look of control. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} The top-left pixel position of the control │ │ │ │ │ + * or null. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ */ │ │ │ │ │ - removeBox: function() { │ │ │ │ │ - this.map.viewPortDiv.removeChild(this.zoomBox); │ │ │ │ │ - this.zoomBox = null; │ │ │ │ │ - this.boxOffsets = null; │ │ │ │ │ - OpenLayers.Element.removeClass( │ │ │ │ │ - this.map.viewPortDiv, "olDrawBox" │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + if (this.div == null) { │ │ │ │ │ + this.div = OpenLayers.Util.createDiv(this.id); │ │ │ │ │ + this.div.className = this.displayClass; │ │ │ │ │ + if (!this.allowSelection) { │ │ │ │ │ + this.div.className += " olControlNoSelect"; │ │ │ │ │ + this.div.setAttribute("unselectable", "on", 0); │ │ │ │ │ + this.div.onselectstart = OpenLayers.Function.False; │ │ │ │ │ + } │ │ │ │ │ + if (this.title != "") { │ │ │ │ │ + this.div.title = this.title; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (px != null) { │ │ │ │ │ + this.position = px.clone(); │ │ │ │ │ + } │ │ │ │ │ + this.moveTo(this.position); │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ + * Method: moveTo │ │ │ │ │ + * Sets the left and top style attributes to the passed in pixel │ │ │ │ │ + * coordinates. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.dragHandler.activate(); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ + moveTo: function(px) { │ │ │ │ │ + if ((px != null) && (this.div != null)) { │ │ │ │ │ + this.div.style.left = px.x + "px"; │ │ │ │ │ + this.div.style.top = px.y + "px"; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Explicitly activates a control and it's associated │ │ │ │ │ + * handler if one has been set. Controls can be │ │ │ │ │ + * deactivated by calling the deactivate() method. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} True if the control was successfully activated or │ │ │ │ │ + * false if the control was already active. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - if (this.dragHandler.deactivate()) { │ │ │ │ │ - if (this.zoomBox) { │ │ │ │ │ - this.removeBox(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ return false; │ │ │ │ │ } │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.activate(); │ │ │ │ │ + } │ │ │ │ │ + this.active = true; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + OpenLayers.Element.addClass( │ │ │ │ │ + this.map.viewPortDiv, │ │ │ │ │ + this.displayClass.replace(/ /g, "") + "Active" │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("activate"); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getBoxOffsets │ │ │ │ │ - * Determines border offsets for a box, according to the box model. │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivates a control and it's associated handler if any. The exact │ │ │ │ │ + * effect of this depends on the control itself. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} an object with the following offsets: │ │ │ │ │ - * - left │ │ │ │ │ - * - right │ │ │ │ │ - * - top │ │ │ │ │ - * - bottom │ │ │ │ │ - * - width │ │ │ │ │ - * - height │ │ │ │ │ + * {Boolean} True if the control was effectively deactivated or false │ │ │ │ │ + * if the control was already inactive. │ │ │ │ │ */ │ │ │ │ │ - getBoxOffsets: function() { │ │ │ │ │ - if (!this.boxOffsets) { │ │ │ │ │ - // Determine the box model. If the testDiv's clientWidth is 3, then │ │ │ │ │ - // the borders are outside and we are dealing with the w3c box │ │ │ │ │ - // model. Otherwise, the browser uses the traditional box model and │ │ │ │ │ - // the borders are inside the box bounds, leaving us with a │ │ │ │ │ - // clientWidth of 1. │ │ │ │ │ - var testDiv = document.createElement("div"); │ │ │ │ │ - //testDiv.style.visibility = "hidden"; │ │ │ │ │ - testDiv.style.position = "absolute"; │ │ │ │ │ - testDiv.style.border = "1px solid black"; │ │ │ │ │ - testDiv.style.width = "3px"; │ │ │ │ │ - document.body.appendChild(testDiv); │ │ │ │ │ - var w3cBoxModel = testDiv.clientWidth == 3; │ │ │ │ │ - document.body.removeChild(testDiv); │ │ │ │ │ - │ │ │ │ │ - var left = parseInt(OpenLayers.Element.getStyle(this.zoomBox, │ │ │ │ │ - "border-left-width")); │ │ │ │ │ - var right = parseInt(OpenLayers.Element.getStyle( │ │ │ │ │ - this.zoomBox, "border-right-width")); │ │ │ │ │ - var top = parseInt(OpenLayers.Element.getStyle(this.zoomBox, │ │ │ │ │ - "border-top-width")); │ │ │ │ │ - var bottom = parseInt(OpenLayers.Element.getStyle( │ │ │ │ │ - this.zoomBox, "border-bottom-width")); │ │ │ │ │ - this.boxOffsets = { │ │ │ │ │ - left: left, │ │ │ │ │ - right: right, │ │ │ │ │ - top: top, │ │ │ │ │ - bottom: bottom, │ │ │ │ │ - width: w3cBoxModel === false ? left + right : 0, │ │ │ │ │ - height: w3cBoxModel === false ? top + bottom : 0 │ │ │ │ │ - }; │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.deactivate(); │ │ │ │ │ + } │ │ │ │ │ + this.active = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + OpenLayers.Element.removeClass( │ │ │ │ │ + this.map.viewPortDiv, │ │ │ │ │ + this.displayClass.replace(/ /g, "") + "Active" │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + this.events.triggerEvent("deactivate"); │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ - return this.boxOffsets; │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Box" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Control.TYPE_BUTTON │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.TYPE_BUTTON = 1; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Control.TYPE_TOGGLE │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.TYPE_TOGGLE = 2; │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: OpenLayers.Control.TYPE_TOOL │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.TYPE_TOOL = 3; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ZoomBox.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/Handler/Box.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.ZoomBox │ │ │ │ │ - * The ZoomBox control enables zooming directly to a given extent, by drawing │ │ │ │ │ - * a box on the map. The box is drawn by holding down shift, whilst dragging │ │ │ │ │ - * the mouse. │ │ │ │ │ + * Class: OpenLayers.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. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * 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.ZoomBox = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Events.buttonclick = OpenLayers.Class({ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Property: type │ │ │ │ │ - * {OpenLayers.Control.TYPE} │ │ │ │ │ + * Property: target │ │ │ │ │ + * {} The events instance that the buttonclick event will │ │ │ │ │ + * be triggered on. │ │ │ │ │ */ │ │ │ │ │ - type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ + target: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: out │ │ │ │ │ - * {Boolean} Should the control be used for zooming out? │ │ │ │ │ + * Property: events │ │ │ │ │ + * {Array} Events to observe and conditionally stop from propagating when │ │ │ │ │ + * an element with the olButton class (or its olAlphaImg child) is │ │ │ │ │ + * clicked. │ │ │ │ │ */ │ │ │ │ │ - out: false, │ │ │ │ │ + events: [ │ │ │ │ │ + 'mousedown', 'mouseup', 'click', 'dblclick', │ │ │ │ │ + 'touchstart', 'touchmove', 'touchend', 'keydown' │ │ │ │ │ + ], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: keyMask │ │ │ │ │ - * {Integer} Zoom only occurs if the keyMask matches the combination of │ │ │ │ │ - * keys down. Use bitwise operators and one or more of the │ │ │ │ │ - * constants to construct a keyMask. Leave null if │ │ │ │ │ - * not used mask. Default is null. │ │ │ │ │ + * Property: startRegEx │ │ │ │ │ + * {RegExp} Regular expression to test Event.type for events that start │ │ │ │ │ + * a buttonclick sequence. │ │ │ │ │ */ │ │ │ │ │ - keyMask: null, │ │ │ │ │ + startRegEx: /^mousedown|touchstart$/, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: alwaysZoom │ │ │ │ │ - * {Boolean} Always zoom in/out when box drawn, even if the zoom level does │ │ │ │ │ - * not change. │ │ │ │ │ + * Property: cancelRegEx │ │ │ │ │ + * {RegExp} Regular expression to test Event.type for events that cancel │ │ │ │ │ + * a buttonclick sequence. │ │ │ │ │ */ │ │ │ │ │ - alwaysZoom: false, │ │ │ │ │ + cancelRegEx: /^touchmove$/, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomOnClick │ │ │ │ │ - * {Boolean} Should we zoom when no box was dragged, i.e. the user only │ │ │ │ │ - * clicked? Default is true. │ │ │ │ │ + * Property: completeRegEx │ │ │ │ │ + * {RegExp} Regular expression to test Event.type for events that complete │ │ │ │ │ + * a buttonclick sequence. │ │ │ │ │ */ │ │ │ │ │ - zoomOnClick: true, │ │ │ │ │ + completeRegEx: /^mouseup|touchend$/, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * Property: startEvt │ │ │ │ │ + * {Event} The event that started the click sequence │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - this.handler = new OpenLayers.Handler.Box(this, { │ │ │ │ │ - done: this.zoomBox │ │ │ │ │ - }, { │ │ │ │ │ - keyMask: this.keyMask │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: zoomBox │ │ │ │ │ + * 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: │ │ │ │ │ - * position - {} or {} │ │ │ │ │ + * target - {} The events instance that the buttonclick │ │ │ │ │ + * event will be triggered on. │ │ │ │ │ */ │ │ │ │ │ - zoomBox: function(position) { │ │ │ │ │ - if (position instanceof OpenLayers.Bounds) { │ │ │ │ │ - var bounds, │ │ │ │ │ - targetCenterPx = position.getCenterPixel(); │ │ │ │ │ - if (!this.out) { │ │ │ │ │ - var minXY = this.map.getLonLatFromPixel({ │ │ │ │ │ - x: position.left, │ │ │ │ │ - y: position.bottom │ │ │ │ │ - }); │ │ │ │ │ - var maxXY = this.map.getLonLatFromPixel({ │ │ │ │ │ - x: position.right, │ │ │ │ │ - y: position.top │ │ │ │ │ - }); │ │ │ │ │ - bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat, │ │ │ │ │ - maxXY.lon, maxXY.lat); │ │ │ │ │ - } else { │ │ │ │ │ - var pixWidth = position.right - position.left; │ │ │ │ │ - var pixHeight = position.bottom - position.top; │ │ │ │ │ - var zoomFactor = Math.min((this.map.size.h / pixHeight), │ │ │ │ │ - (this.map.size.w / pixWidth)); │ │ │ │ │ - var extent = this.map.getExtent(); │ │ │ │ │ - var center = this.map.getLonLatFromPixel(targetCenterPx); │ │ │ │ │ - var xmin = center.lon - (extent.getWidth() / 2) * zoomFactor; │ │ │ │ │ - var xmax = center.lon + (extent.getWidth() / 2) * zoomFactor; │ │ │ │ │ - var ymin = center.lat - (extent.getHeight() / 2) * zoomFactor; │ │ │ │ │ - var ymax = center.lat + (extent.getHeight() / 2) * zoomFactor; │ │ │ │ │ - bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax); │ │ │ │ │ - } │ │ │ │ │ - // always zoom in/out │ │ │ │ │ - var lastZoom = this.map.getZoom(), │ │ │ │ │ - size = this.map.getSize(), │ │ │ │ │ - centerPx = { │ │ │ │ │ - x: size.w / 2, │ │ │ │ │ - y: size.h / 2 │ │ │ │ │ - }, │ │ │ │ │ - zoom = this.map.getZoomForExtent(bounds), │ │ │ │ │ - oldRes = this.map.getResolution(), │ │ │ │ │ - newRes = this.map.getResolutionForZoom(zoom); │ │ │ │ │ - if (oldRes == newRes) { │ │ │ │ │ - this.map.setCenter(this.map.getLonLatFromPixel(targetCenterPx)); │ │ │ │ │ - } else { │ │ │ │ │ - var zoomOriginPx = { │ │ │ │ │ - x: (oldRes * targetCenterPx.x - newRes * centerPx.x) / │ │ │ │ │ - (oldRes - newRes), │ │ │ │ │ - y: (oldRes * targetCenterPx.y - newRes * centerPx.y) / │ │ │ │ │ - (oldRes - newRes) │ │ │ │ │ - }; │ │ │ │ │ - this.map.zoomTo(zoom, zoomOriginPx); │ │ │ │ │ + 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 │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var i = this.events.length - 1; i >= 0; --i) { │ │ │ │ │ + this.target.unregister(this.events[i], this, this.buttonClick); │ │ │ │ │ + } │ │ │ │ │ + delete this.target; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getPressedButton │ │ │ │ │ + * Get the pressed button, if any. Returns undefined if no button │ │ │ │ │ + * was pressed. │ │ │ │ │ + * │ │ │ │ │ + * Arguments: │ │ │ │ │ + * element - {DOMElement} The event target. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The button element, or undefined. │ │ │ │ │ + */ │ │ │ │ │ + getPressedButton: function(element) { │ │ │ │ │ + var depth = 3, // limit the search depth │ │ │ │ │ + button; │ │ │ │ │ + do { │ │ │ │ │ + if (OpenLayers.Element.hasClass(element, "olButton")) { │ │ │ │ │ + // hit! │ │ │ │ │ + button = element; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - if (lastZoom == this.map.getZoom() && this.alwaysZoom == true) { │ │ │ │ │ - this.map.zoomTo(lastZoom + (this.out ? -1 : 1)); │ │ │ │ │ + element = element.parentNode; │ │ │ │ │ + } while (--depth > 0 && element); │ │ │ │ │ + return button; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: ignore │ │ │ │ │ + * Check for event target elements that should be ignored by OpenLayers. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} The event target. │ │ │ │ │ + */ │ │ │ │ │ + ignore: function(element) { │ │ │ │ │ + var depth = 3, │ │ │ │ │ + ignore = false; │ │ │ │ │ + do { │ │ │ │ │ + if (element.nodeName.toLowerCase() === 'a') { │ │ │ │ │ + ignore = true; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - } else if (this.zoomOnClick) { // it's a pixel │ │ │ │ │ - if (!this.out) { │ │ │ │ │ - this.map.zoomTo(this.map.getZoom() + 1, position); │ │ │ │ │ + element = element.parentNode; │ │ │ │ │ + } while (--depth > 0 && element); │ │ │ │ │ + return ignore; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: buttonClick │ │ │ │ │ + * Check if a button was clicked, and fire the buttonclick event │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + */ │ │ │ │ │ + buttonClick: function(evt) { │ │ │ │ │ + var propagate = true, │ │ │ │ │ + element = OpenLayers.Event.element(evt); │ │ │ │ │ + if (element && (OpenLayers.Event.isLeftClick(evt) || !~evt.type.indexOf("mouse"))) { │ │ │ │ │ + // was a button pressed? │ │ │ │ │ + var button = this.getPressedButton(element); │ │ │ │ │ + if (button) { │ │ │ │ │ + if (evt.type === "keydown") { │ │ │ │ │ + switch (evt.keyCode) { │ │ │ │ │ + case OpenLayers.Event.KEY_RETURN: │ │ │ │ │ + case OpenLayers.Event.KEY_SPACE: │ │ │ │ │ + this.target.triggerEvent("buttonclick", { │ │ │ │ │ + buttonElement: button │ │ │ │ │ + }); │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + propagate = false; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } else if (this.startEvt) { │ │ │ │ │ + if (this.completeRegEx.test(evt.type)) { │ │ │ │ │ + var pos = OpenLayers.Util.pagePosition(button); │ │ │ │ │ + var viewportElement = OpenLayers.Util.getViewportElement(); │ │ │ │ │ + var scrollTop = window.pageYOffset || viewportElement.scrollTop; │ │ │ │ │ + var scrollLeft = window.pageXOffset || viewportElement.scrollLeft; │ │ │ │ │ + pos[0] = pos[0] - scrollLeft; │ │ │ │ │ + pos[1] = pos[1] - scrollTop; │ │ │ │ │ + │ │ │ │ │ + this.target.triggerEvent("buttonclick", { │ │ │ │ │ + buttonElement: button, │ │ │ │ │ + buttonXY: { │ │ │ │ │ + x: this.startEvt.clientX - pos[0], │ │ │ │ │ + y: this.startEvt.clientY - pos[1] │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (this.cancelRegEx.test(evt.type)) { │ │ │ │ │ + delete this.startEvt; │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + propagate = false; │ │ │ │ │ + } │ │ │ │ │ + if (this.startRegEx.test(evt.type)) { │ │ │ │ │ + this.startEvt = evt; │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + propagate = false; │ │ │ │ │ + } │ │ │ │ │ } else { │ │ │ │ │ - this.map.zoomTo(this.map.getZoom() - 1, position); │ │ │ │ │ + propagate = !this.ignore(OpenLayers.Event.element(evt)); │ │ │ │ │ + delete this.startEvt; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ + return propagate; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ZoomBox" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/DragPan.js │ │ │ │ │ + OpenLayers/Handler/Click.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.DragPan │ │ │ │ │ - * The DragPan control pans the map with a drag of the mouse. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Handler.Click │ │ │ │ │ + * A handler for mouse clicks. The intention of this handler is to give │ │ │ │ │ + * controls more flexibility with handling clicks. Browsers trigger │ │ │ │ │ + * click events twice for a double-click. In addition, the mousedown, │ │ │ │ │ + * mousemove, mouseup sequence fires a click event. With this handler, │ │ │ │ │ + * controls can decide whether to ignore clicks associated with a double │ │ │ │ │ + * click. By setting a , controls can also ignore clicks │ │ │ │ │ + * that include a drag. Create a new instance with the │ │ │ │ │ + * constructor. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.DragPan = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: delay │ │ │ │ │ + * {Number} Number of milliseconds between clicks before the event is │ │ │ │ │ + * considered a double-click. │ │ │ │ │ + */ │ │ │ │ │ + delay: 300, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: type │ │ │ │ │ - * {OpenLayers.Control.TYPES} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: single │ │ │ │ │ + * {Boolean} Handle single clicks. Default is true. If false, clicks │ │ │ │ │ + * will not be reported. If true, single-clicks will be reported. │ │ │ │ │ */ │ │ │ │ │ - type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ + single: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: panned │ │ │ │ │ - * {Boolean} The map moved. │ │ │ │ │ + * APIProperty: double │ │ │ │ │ + * {Boolean} Handle double-clicks. Default is false. │ │ │ │ │ */ │ │ │ │ │ - panned: false, │ │ │ │ │ + 'double': false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: interval │ │ │ │ │ - * {Integer} The number of milliseconds that should ellapse before │ │ │ │ │ - * panning the map again. Defaults to 0 milliseconds, which means that │ │ │ │ │ - * no separate cycle is used for panning. In most cases you won't want │ │ │ │ │ - * to change this value. For slow machines/devices larger values can be │ │ │ │ │ - * tried out. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - interval: 0, │ │ │ │ │ + pixelTolerance: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} If set to true, mouse dragging will continue even if the │ │ │ │ │ - * mouse cursor leaves the map viewport. Default is false. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ + dblclickTolerance: 13, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: kinetic │ │ │ │ │ - * {} The OpenLayers.Kinetic object. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - kinetic: null, │ │ │ │ │ + stopSingle: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: enableKinetic │ │ │ │ │ - * {Boolean} Set this option to enable "kinetic dragging". Can be │ │ │ │ │ - * set to true or to an object. If set to an object this │ │ │ │ │ - * object will be passed to the {} │ │ │ │ │ - * constructor. Defaults to true. │ │ │ │ │ - * To get kinetic dragging, ensure that OpenLayers/Kinetic.js is │ │ │ │ │ - * included in your build config. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - enableKinetic: true, │ │ │ │ │ + stopDouble: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: kineticInterval │ │ │ │ │ - * {Integer} Interval in milliseconds between 2 steps in the "kinetic │ │ │ │ │ - * scrolling". Applies only if enableKinetic is set. Defaults │ │ │ │ │ - * to 10 milliseconds. │ │ │ │ │ + * Property: timerId │ │ │ │ │ + * {Number} The id of the timeout waiting to clear the . │ │ │ │ │ */ │ │ │ │ │ - kineticInterval: 10, │ │ │ │ │ + timerId: null, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * Property: down │ │ │ │ │ + * {Object} Object that store relevant information about the last │ │ │ │ │ + * mousedown or touchstart. Its 'xy' OpenLayers.Pixel property gives │ │ │ │ │ + * the average location of the mouse/touch event. Its 'touches' │ │ │ │ │ + * property records clientX/clientY of each touches. │ │ │ │ │ + */ │ │ │ │ │ + down: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Creates a Drag handler, using and │ │ │ │ │ - * as callbacks. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - if (this.enableKinetic && OpenLayers.Kinetic) { │ │ │ │ │ - var config = { │ │ │ │ │ - interval: this.kineticInterval │ │ │ │ │ - }; │ │ │ │ │ - if (typeof this.enableKinetic === "object") { │ │ │ │ │ - config = OpenLayers.Util.extend(config, this.enableKinetic); │ │ │ │ │ - } │ │ │ │ │ - this.kinetic = new OpenLayers.Kinetic(config); │ │ │ │ │ - } │ │ │ │ │ - this.handler = new OpenLayers.Handler.Drag(this, { │ │ │ │ │ - "move": this.panMap, │ │ │ │ │ - "done": this.panMapDone, │ │ │ │ │ - "down": this.panMapStart │ │ │ │ │ - }, { │ │ │ │ │ - interval: this.interval, │ │ │ │ │ - documentDrag: this.documentDrag │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + last: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: first │ │ │ │ │ + * {Object} When waiting for double clicks, this object will store │ │ │ │ │ + * information about the first click in a two click sequence. │ │ │ │ │ + */ │ │ │ │ │ + first: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: panMapStart │ │ │ │ │ + * Property: rightclickTimerId │ │ │ │ │ + * {Number} The id of the right mouse timeout waiting to clear the │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - panMapStart: function() { │ │ │ │ │ - if (this.kinetic) { │ │ │ │ │ - this.kinetic.begin(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + rightclickTimerId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: panMap │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Handler.Click │ │ │ │ │ + * Create a new click handler. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * xy - {} Pixel of the mouse position │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - panMap: function(xy) { │ │ │ │ │ - if (this.kinetic) { │ │ │ │ │ - this.kinetic.update(xy); │ │ │ │ │ - } │ │ │ │ │ - this.panned = true; │ │ │ │ │ - this.map.pan( │ │ │ │ │ - this.handler.last.x - xy.x, │ │ │ │ │ - this.handler.last.y - xy.y, { │ │ │ │ │ - dragging: true, │ │ │ │ │ - animate: false │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: panMapDone │ │ │ │ │ - * Finish the panning operation. Only call setCenter (through ) │ │ │ │ │ - * if the map has actually been moved. │ │ │ │ │ + * Method: touchstart │ │ │ │ │ + * Handle touchstart. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * xy - {} Pixel of the mouse position │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - panMapDone: function(xy) { │ │ │ │ │ - if (this.panned) { │ │ │ │ │ - var res = null; │ │ │ │ │ - if (this.kinetic) { │ │ │ │ │ - res = this.kinetic.end(xy); │ │ │ │ │ - } │ │ │ │ │ - this.map.pan( │ │ │ │ │ - this.handler.last.x - xy.x, │ │ │ │ │ - this.handler.last.y - xy.y, { │ │ │ │ │ - dragging: !!res, │ │ │ │ │ - animate: false │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - if (res) { │ │ │ │ │ - var self = this; │ │ │ │ │ - this.kinetic.move(res, function(x, y, end) { │ │ │ │ │ - self.map.pan(x, y, { │ │ │ │ │ - dragging: !end, │ │ │ │ │ - animate: false │ │ │ │ │ - }); │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - this.panned = false; │ │ │ │ │ - } │ │ │ │ │ + touchstart: function(evt) { │ │ │ │ │ + this.startTouch(); │ │ │ │ │ + this.down = this.getEventInfo(evt); │ │ │ │ │ + this.last = this.getEventInfo(evt); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.DragPan" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/MouseWheel.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.MouseWheel │ │ │ │ │ - * Handler for wheel up/down events. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - /** │ │ │ │ │ - * Property: wheelListener │ │ │ │ │ - * {function} │ │ │ │ │ + /** │ │ │ │ │ + * Method: touchmove │ │ │ │ │ + * Store position of last move, because touchend event can have │ │ │ │ │ + * an empty "touches" property. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - wheelListener: null, │ │ │ │ │ + touchmove: function(evt) { │ │ │ │ │ + this.last = this.getEventInfo(evt); │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: interval │ │ │ │ │ - * {Integer} In order to increase server performance, an interval (in │ │ │ │ │ - * milliseconds) can be set to reduce the number of up/down events │ │ │ │ │ - * called. If set, a new up/down event will not be set until the │ │ │ │ │ - * interval has passed. │ │ │ │ │ - * Defaults to 0, meaning no interval. │ │ │ │ │ + * Method: touchend │ │ │ │ │ + * Correctly set event xy property, and add lastTouches to have │ │ │ │ │ + * touches property from last touchstart or touchmove │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - interval: 0, │ │ │ │ │ + touchend: function(evt) { │ │ │ │ │ + // touchstart may not have been allowed to propagate │ │ │ │ │ + if (this.down) { │ │ │ │ │ + evt.xy = this.last.xy; │ │ │ │ │ + evt.lastTouches = this.last.touches; │ │ │ │ │ + this.handleSingle(evt); │ │ │ │ │ + this.down = null; │ │ │ │ │ + } │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: maxDelta │ │ │ │ │ - * {Integer} Maximum delta to collect before breaking from the current │ │ │ │ │ - * interval. In cumulative mode, this also limits the maximum delta │ │ │ │ │ - * returned from the handler. Default is Number.POSITIVE_INFINITY. │ │ │ │ │ + * Method: mousedown │ │ │ │ │ + * Handle mousedown. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - maxDelta: Number.POSITIVE_INFINITY, │ │ │ │ │ + mousedown: function(evt) { │ │ │ │ │ + this.down = this.getEventInfo(evt); │ │ │ │ │ + this.last = this.getEventInfo(evt); │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: delta │ │ │ │ │ - * {Integer} When interval is set, delta collects the mousewheel z-deltas │ │ │ │ │ - * of the events that occur within the interval. │ │ │ │ │ - * See also the cumulative option │ │ │ │ │ + * Method: mouseup │ │ │ │ │ + * Handle mouseup. Installed to support collection of right mouse events. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - delta: 0, │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: cumulative │ │ │ │ │ - * {Boolean} When interval is set: true to collect all the mousewheel │ │ │ │ │ - * z-deltas, false to only record the delta direction (positive or │ │ │ │ │ - * negative) │ │ │ │ │ + * Method: rightclick │ │ │ │ │ + * Handle rightclick. For a dblrightclick, we get two clicks so we need │ │ │ │ │ + * to always register for dblrightclick to properly handle single │ │ │ │ │ + * clicks. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - cumulative: true, │ │ │ │ │ + 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 │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return !this.stopSingle; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.MouseWheel │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} │ │ │ │ │ - * callbacks - {Object} An object containing a single function to be │ │ │ │ │ - * called when the drag operation is finished. │ │ │ │ │ - * The callback should expect to recieve a single │ │ │ │ │ - * argument, the point geometry. │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * Method: delayedRightCall │ │ │ │ │ + * Sets to null. And optionally triggers the │ │ │ │ │ + * rightclick callback if evt is set. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(control, callbacks, options) { │ │ │ │ │ - OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.wheelListener = OpenLayers.Function.bindAsEventListener( │ │ │ │ │ - this.onWheelEvent, this │ │ │ │ │ - ); │ │ │ │ │ + delayedRightCall: function(evt) { │ │ │ │ │ + this.rightclickTimerId = null; │ │ │ │ │ + if (evt) { │ │ │ │ │ + this.callback('rightclick', [evt]); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * Method: click │ │ │ │ │ + * Handle click events from the browser. This is registered as a listener │ │ │ │ │ + * for click events and should not be called from other events in this │ │ │ │ │ + * handler. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ - this.wheelListener = null; │ │ │ │ │ + click: function(evt) { │ │ │ │ │ + if (!this.last) { │ │ │ │ │ + this.last = this.getEventInfo(evt); │ │ │ │ │ + } │ │ │ │ │ + this.handleSingle(evt); │ │ │ │ │ + return !this.stopSingle; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/ │ │ │ │ │ + * 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: onWheelEvent │ │ │ │ │ - * Catch the wheel event and handle it xbrowserly │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * e - {Event} │ │ │ │ │ + * Method: handleDouble │ │ │ │ │ + * Handle double-click sequence. │ │ │ │ │ */ │ │ │ │ │ - onWheelEvent: function(e) { │ │ │ │ │ - │ │ │ │ │ - // make sure we have a map and check keyboard modifiers │ │ │ │ │ - if (!this.map || !this.checkModifiers(e)) { │ │ │ │ │ - return; │ │ │ │ │ + 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(); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // Ride up the element's DOM hierarchy to determine if it or any of │ │ │ │ │ - // its ancestors was: │ │ │ │ │ - // * specifically marked as scrollable (CSS overflow property) │ │ │ │ │ - // * one of our layer divs or a div marked as scrollable │ │ │ │ │ - // ('olScrollable' CSS class) │ │ │ │ │ - // * the map div │ │ │ │ │ - // │ │ │ │ │ - var overScrollableDiv = false; │ │ │ │ │ - var allowScroll = false; │ │ │ │ │ - var overMapDiv = false; │ │ │ │ │ - │ │ │ │ │ - var elem = OpenLayers.Event.element(e); │ │ │ │ │ - while ((elem != null) && !overMapDiv && !overScrollableDiv) { │ │ │ │ │ - │ │ │ │ │ - if (!overScrollableDiv) { │ │ │ │ │ - try { │ │ │ │ │ - var overflow; │ │ │ │ │ - if (elem.currentStyle) { │ │ │ │ │ - overflow = elem.currentStyle["overflow"]; │ │ │ │ │ - } else { │ │ │ │ │ - var style = │ │ │ │ │ - document.defaultView.getComputedStyle(elem, null); │ │ │ │ │ - overflow = style.getPropertyValue("overflow"); │ │ │ │ │ + /** │ │ │ │ │ + * Method: handleSingle │ │ │ │ │ + * Handle single click sequence. │ │ │ │ │ + */ │ │ │ │ │ + handleSingle: function(evt) { │ │ │ │ │ + if (this.passesTolerance(evt)) { │ │ │ │ │ + if (this.timerId != null) { │ │ │ │ │ + // already received a click │ │ │ │ │ + if (this.last.touches && this.last.touches.length === 1) { │ │ │ │ │ + // touch device, no dblclick event - this may be a double │ │ │ │ │ + if (this["double"]) { │ │ │ │ │ + // on Android don't let the browser zoom on the page │ │ │ │ │ + OpenLayers.Event.preventDefault(evt); │ │ │ │ │ } │ │ │ │ │ - overScrollableDiv = (overflow && │ │ │ │ │ - (overflow == "auto") || (overflow == "scroll")); │ │ │ │ │ - } catch (err) { │ │ │ │ │ - //sometimes when scrolling in a popup, this causes │ │ │ │ │ - // obscure browser error │ │ │ │ │ + this.handleDouble(evt); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (!allowScroll) { │ │ │ │ │ - allowScroll = OpenLayers.Element.hasClass(elem, 'olScrollable'); │ │ │ │ │ - if (!allowScroll) { │ │ │ │ │ - for (var i = 0, len = this.map.layers.length; i < len; i++) { │ │ │ │ │ - // Are we in the layer div? Note that we have two cases │ │ │ │ │ - // here: one is to catch EventPane layers, which have a │ │ │ │ │ - // pane above the layer (layer.pane) │ │ │ │ │ - var layer = this.map.layers[i]; │ │ │ │ │ - if (elem == layer.div || elem == layer.pane) { │ │ │ │ │ - allowScroll = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + // if 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); │ │ │ │ │ } │ │ │ │ │ - overMapDiv = (elem == this.map.div); │ │ │ │ │ - │ │ │ │ │ - elem = elem.parentNode; │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // Logic below is the following: │ │ │ │ │ - // │ │ │ │ │ - // If we are over a scrollable div or not over the map div: │ │ │ │ │ - // * do nothing (let the browser handle scrolling) │ │ │ │ │ - // │ │ │ │ │ - // otherwise │ │ │ │ │ - // │ │ │ │ │ - // If we are over the layer div or a 'olScrollable' div: │ │ │ │ │ - // * zoom/in out │ │ │ │ │ - // then │ │ │ │ │ - // * kill event (so as not to also scroll the page after zooming) │ │ │ │ │ - // │ │ │ │ │ - // otherwise │ │ │ │ │ - // │ │ │ │ │ - // Kill the event (dont scroll the page if we wheel over the │ │ │ │ │ - // layerswitcher or the pan/zoom control) │ │ │ │ │ - // │ │ │ │ │ - if (!overScrollableDiv && overMapDiv) { │ │ │ │ │ - if (allowScroll) { │ │ │ │ │ - var delta = 0; │ │ │ │ │ + /** │ │ │ │ │ + * Method: queuePotentialClick │ │ │ │ │ + * This method is separated out largely to make testing easier (so we │ │ │ │ │ + * don't have to override window.setTimeout) │ │ │ │ │ + */ │ │ │ │ │ + queuePotentialClick: function(evt) { │ │ │ │ │ + this.timerId = window.setTimeout( │ │ │ │ │ + OpenLayers.Function.bind(this.delayedCall, this, evt), │ │ │ │ │ + this.delay │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (e.wheelDelta) { │ │ │ │ │ - delta = e.wheelDelta; │ │ │ │ │ - if (delta % 160 === 0) { │ │ │ │ │ - // opera have steps of 160 instead of 120 │ │ │ │ │ - delta = delta * 0.75; │ │ │ │ │ + /** │ │ │ │ │ + * Method: passesTolerance │ │ │ │ │ + * Determine whether the event is within the optional pixel tolerance. Note │ │ │ │ │ + * that the pixel tolerance check only works if mousedown events get to │ │ │ │ │ + * the listeners registered here. If they are stopped by other elements, │ │ │ │ │ + * the will have no effect here (this method will always │ │ │ │ │ + * return true). │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The click is within the pixel tolerance (if specified). │ │ │ │ │ + */ │ │ │ │ │ + passesTolerance: function(evt) { │ │ │ │ │ + var passes = true; │ │ │ │ │ + if (this.pixelTolerance != null && this.down && this.down.xy) { │ │ │ │ │ + passes = this.pixelTolerance >= this.down.xy.distanceTo(evt.xy); │ │ │ │ │ + // for touch environments, we also enforce that all touches │ │ │ │ │ + // start and end within the given tolerance to be considered a click │ │ │ │ │ + if (passes && this.touch && │ │ │ │ │ + this.down.touches.length === this.last.touches.length) { │ │ │ │ │ + // the touchend event doesn't come with touches, so we check │ │ │ │ │ + // down and last │ │ │ │ │ + for (var i = 0, ii = this.down.touches.length; i < ii; ++i) { │ │ │ │ │ + if (this.getTouchDistance( │ │ │ │ │ + this.down.touches[i], │ │ │ │ │ + this.last.touches[i] │ │ │ │ │ + ) > this.pixelTolerance) { │ │ │ │ │ + passes = false; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - delta = delta / 120; │ │ │ │ │ - } else if (e.detail) { │ │ │ │ │ - // detail in Firefox on OS X is 1/3 of Windows │ │ │ │ │ - // so force delta 1 / -1 │ │ │ │ │ - delta = -(e.detail / Math.abs(e.detail)); │ │ │ │ │ - } │ │ │ │ │ - this.delta += delta; │ │ │ │ │ - │ │ │ │ │ - window.clearTimeout(this._timeoutId); │ │ │ │ │ - if (this.interval && Math.abs(this.delta) < this.maxDelta) { │ │ │ │ │ - // store e because window.event might change during delay │ │ │ │ │ - var evt = OpenLayers.Util.extend({}, e); │ │ │ │ │ - this._timeoutId = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(function() { │ │ │ │ │ - this.wheelZoom(evt); │ │ │ │ │ - }, this), │ │ │ │ │ - this.interval │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - this.wheelZoom(e); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ } │ │ │ │ │ + return passes; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getTouchDistance │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The pixel displacement between two touches. │ │ │ │ │ + */ │ │ │ │ │ + getTouchDistance: function(from, to) { │ │ │ │ │ + return Math.sqrt( │ │ │ │ │ + Math.pow(from.clientX - to.clientX, 2) + │ │ │ │ │ + Math.pow(from.clientY - to.clientY, 2) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: passesDblclickTolerance │ │ │ │ │ + * Determine whether the event is within the optional double-cick pixel │ │ │ │ │ + * tolerance. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The click is within the double-click pixel tolerance. │ │ │ │ │ + */ │ │ │ │ │ + passesDblclickTolerance: function(evt) { │ │ │ │ │ + var passes = true; │ │ │ │ │ + if (this.down && this.first) { │ │ │ │ │ + passes = this.down.xy.distanceTo(this.first.xy) <= this.dblclickTolerance; │ │ │ │ │ + } │ │ │ │ │ + return passes; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: wheelZoom │ │ │ │ │ - * Given the wheel event, we carry out the appropriate zooming in or out, │ │ │ │ │ - * based on the 'wheelDelta' or 'detail' property of the event. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * e - {Event} │ │ │ │ │ + * Method: clearTimer │ │ │ │ │ + * Clear the timer and set to null. │ │ │ │ │ */ │ │ │ │ │ - wheelZoom: function(e) { │ │ │ │ │ - var delta = this.delta; │ │ │ │ │ - this.delta = 0; │ │ │ │ │ + clearTimer: function() { │ │ │ │ │ + if (this.timerId != null) { │ │ │ │ │ + window.clearTimeout(this.timerId); │ │ │ │ │ + this.timerId = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.rightclickTimerId != null) { │ │ │ │ │ + window.clearTimeout(this.rightclickTimerId); │ │ │ │ │ + this.rightclickTimerId = null; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (delta) { │ │ │ │ │ - e.xy = this.map.events.getMousePosition(e); │ │ │ │ │ - if (delta < 0) { │ │ │ │ │ - this.callback("down", │ │ │ │ │ - [e, this.cumulative ? Math.max(-this.maxDelta, delta) : -1]); │ │ │ │ │ - } else { │ │ │ │ │ - this.callback("up", │ │ │ │ │ - [e, this.cumulative ? Math.min(this.maxDelta, delta) : 1]); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: delayedCall │ │ │ │ │ + * Sets to null. And optionally triggers the click callback if │ │ │ │ │ + * evt is set. │ │ │ │ │ + */ │ │ │ │ │ + delayedCall: function(evt) { │ │ │ │ │ + this.timerId = null; │ │ │ │ │ + if (evt) { │ │ │ │ │ + this.callback("click", [evt]); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ + * Method: getEventInfo │ │ │ │ │ + * This method allows us to store event information without storing the │ │ │ │ │ + * actual event. In touch devices (at least), the same event is │ │ │ │ │ + * modified between touchstart, touchmove, and touchend. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object with event related info. │ │ │ │ │ */ │ │ │ │ │ - activate: function(evt) { │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - //register mousewheel events specifically on the window and document │ │ │ │ │ - var wheelListener = this.wheelListener; │ │ │ │ │ - OpenLayers.Event.observe(window, "DOMMouseScroll", wheelListener); │ │ │ │ │ - OpenLayers.Event.observe(window, "mousewheel", wheelListener); │ │ │ │ │ - OpenLayers.Event.observe(document, "mousewheel", wheelListener); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ + 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 │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the handler. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was successfully deactivated. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function(evt) { │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = false; │ │ │ │ │ if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - // unregister mousewheel events specifically on the window and document │ │ │ │ │ - var wheelListener = this.wheelListener; │ │ │ │ │ - OpenLayers.Event.stopObserving(window, "DOMMouseScroll", wheelListener); │ │ │ │ │ - OpenLayers.Event.stopObserving(window, "mousewheel", wheelListener); │ │ │ │ │ - OpenLayers.Event.stopObserving(document, "mousewheel", wheelListener); │ │ │ │ │ - return true; │ │ │ │ │ - } else { │ │ │ │ │ - return false; │ │ │ │ │ + this.clearTimer(); │ │ │ │ │ + this.down = null; │ │ │ │ │ + this.first = null; │ │ │ │ │ + this.last = null; │ │ │ │ │ + deactivated = true; │ │ │ │ │ } │ │ │ │ │ + return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.MouseWheel" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Click" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Navigation.js │ │ │ │ │ + OpenLayers/Handler/Drag.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control/ZoomBox.js │ │ │ │ │ - * @requires OpenLayers/Control/DragPan.js │ │ │ │ │ - * @requires OpenLayers/Handler/MouseWheel.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Navigation │ │ │ │ │ - * The navigation control handles map browsing with mouse events (dragging, │ │ │ │ │ - * double-clicking, and scrolling the wheel). Create a new navigation │ │ │ │ │ - * control with the control. │ │ │ │ │ - * │ │ │ │ │ - * Note that this control is added to the map by default (if no controls │ │ │ │ │ - * array is sent in the options object to the │ │ │ │ │ - * constructor). │ │ │ │ │ - * │ │ │ │ │ - * Inherits: │ │ │ │ │ - * - │ │ │ │ │ + * Class: OpenLayers.Handler.Drag │ │ │ │ │ + * The drag handler is used to deal with sequences of browser events related │ │ │ │ │ + * to dragging. The handler is used by controls that want to know when │ │ │ │ │ + * a drag sequence begins, when a drag is happening, and when it has │ │ │ │ │ + * finished. │ │ │ │ │ + * │ │ │ │ │ + * Controls that use the drag handler typically construct it with callbacks │ │ │ │ │ + * for 'down', 'move', and 'done'. Callbacks for these keys are called │ │ │ │ │ + * when the drag begins, with each move, and when the drag is done. In │ │ │ │ │ + * addition, controls can have callbacks keyed to 'up' and 'out' if they │ │ │ │ │ + * care to differentiate between the types of events that correspond with │ │ │ │ │ + * the end of a drag sequence. If no drag actually occurs (no mouse move) │ │ │ │ │ + * the 'down' and 'up' callbacks will be called, but not the 'done' │ │ │ │ │ + * callback. │ │ │ │ │ + * │ │ │ │ │ + * Create a new drag handler with the constructor. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: dragPan │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - dragPan: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: dragPanOptions │ │ │ │ │ - * {Object} Options passed to the DragPan control. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - dragPanOptions: null, │ │ │ │ │ + started: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: pinchZoom │ │ │ │ │ - * {} │ │ │ │ │ + * Property: stopDown │ │ │ │ │ + * {Boolean} Stop propagation of mousedown events from getting to listeners │ │ │ │ │ + * on the same element. Default is true. │ │ │ │ │ */ │ │ │ │ │ - pinchZoom: null, │ │ │ │ │ + stopDown: true, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: pinchZoomOptions │ │ │ │ │ - * {Object} Options passed to the PinchZoom control. │ │ │ │ │ + /** │ │ │ │ │ + * Property: dragging │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - pinchZoomOptions: null, │ │ │ │ │ + dragging: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} Allow panning of the map by dragging outside map viewport. │ │ │ │ │ - * Default is false. │ │ │ │ │ + /** │ │ │ │ │ + * Property: last │ │ │ │ │ + * {} The last pixel location of the drag. │ │ │ │ │ */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ + last: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: zoomBox │ │ │ │ │ - * {} │ │ │ │ │ + * Property: start │ │ │ │ │ + * {} The first pixel location of the drag. │ │ │ │ │ */ │ │ │ │ │ - zoomBox: null, │ │ │ │ │ + start: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomBoxEnabled │ │ │ │ │ - * {Boolean} Whether the user can draw a box to zoom │ │ │ │ │ + * Property: lastMoveEvt │ │ │ │ │ + * {Object} The last mousemove event that occurred. Used to │ │ │ │ │ + * position the map correctly when our "delay drag" │ │ │ │ │ + * timeout expired. │ │ │ │ │ */ │ │ │ │ │ - zoomBoxEnabled: true, │ │ │ │ │ + lastMoveEvt: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomWheelEnabled │ │ │ │ │ - * {Boolean} Whether the mousewheel should zoom the map │ │ │ │ │ + * Property: oldOnselectstart │ │ │ │ │ + * {Function} │ │ │ │ │ */ │ │ │ │ │ - zoomWheelEnabled: true, │ │ │ │ │ + oldOnselectstart: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: mouseWheelOptions │ │ │ │ │ - * {Object} Options passed to the MouseWheel control (only useful if │ │ │ │ │ - * is set to true). Default is no options for maps │ │ │ │ │ - * with fractionalZoom set to true, otherwise │ │ │ │ │ - * {cumulative: false, interval: 50, maxDelta: 6} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - mouseWheelOptions: null, │ │ │ │ │ + interval: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handleRightClicks │ │ │ │ │ - * {Boolean} Whether or not to handle right clicks. Default is false. │ │ │ │ │ + * Property: timeoutId │ │ │ │ │ + * {String} The id of the timeout used for the mousedown interval. │ │ │ │ │ + * This is "private", and should be left alone. │ │ │ │ │ */ │ │ │ │ │ - handleRightClicks: false, │ │ │ │ │ + timeoutId: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomBoxKeyMask │ │ │ │ │ - * {Integer} key code of the key, which has to be │ │ │ │ │ - * pressed, while drawing the zoom box with the mouse on the screen. │ │ │ │ │ - * You should probably set handleRightClicks to true if you use this │ │ │ │ │ - * with MOD_CTRL, to disable the context menu for machines which use │ │ │ │ │ - * CTRL-Click as a right click. │ │ │ │ │ - * Default: │ │ │ │ │ + * APIProperty: 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. │ │ │ │ │ */ │ │ │ │ │ - zoomBoxKeyMask: OpenLayers.Handler.MOD_SHIFT, │ │ │ │ │ + documentDrag: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * Property: documentEvents │ │ │ │ │ + * {Boolean} Are we currently observing document events? │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + documentEvents: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Navigation │ │ │ │ │ - * Create a new navigation control │ │ │ │ │ + * Constructor: OpenLayers.Handler.Drag │ │ │ │ │ + * Returns OpenLayers.Handler.Drag │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * the control │ │ │ │ │ + * control - {} The control that is making use of │ │ │ │ │ + * this handler. If a handler is being used without a control, the │ │ │ │ │ + * handlers setMap method must be overridden to deal properly with │ │ │ │ │ + * the map. │ │ │ │ │ + * callbacks - {Object} An object containing a single function to be │ │ │ │ │ + * called when the drag operation is finished. The callback should │ │ │ │ │ + * expect to recieve a single argument, the pixel location of the event. │ │ │ │ │ + * Callbacks for 'move' and 'done' are supported. You can also speficy │ │ │ │ │ + * callbacks for 'down', 'up', and 'out' to respond to those events. │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.handlers = {}; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ + initialize: function(control, callbacks, options) { │ │ │ │ │ + OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + if (this.documentDrag === true) { │ │ │ │ │ + var me = this; │ │ │ │ │ + this._docMove = function(evt) { │ │ │ │ │ + me.mousemove({ │ │ │ │ │ + xy: { │ │ │ │ │ + x: evt.clientX, │ │ │ │ │ + y: evt.clientY │ │ │ │ │ + }, │ │ │ │ │ + element: document │ │ │ │ │ + }); │ │ │ │ │ + }; │ │ │ │ │ + this._docUp = function(evt) { │ │ │ │ │ + me.mouseup({ │ │ │ │ │ + xy: { │ │ │ │ │ + x: evt.clientX, │ │ │ │ │ + y: evt.clientY │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * The destroy method is used to perform any clean up before the control │ │ │ │ │ - * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ - * to prevent memory leaks. │ │ │ │ │ + * Method: dragstart │ │ │ │ │ + * This private method is factorized from mousedown and touchstart methods │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ + 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]); │ │ │ │ │ │ │ │ │ │ - if (this.dragPan) { │ │ │ │ │ - this.dragPan.destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.dragPan = null; │ │ │ │ │ + // prevent document dragging │ │ │ │ │ + OpenLayers.Event.preventDefault(evt); │ │ │ │ │ │ │ │ │ │ - if (this.zoomBox) { │ │ │ │ │ - this.zoomBox.destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.zoomBox = null; │ │ │ │ │ + if (!this.oldOnselectstart) { │ │ │ │ │ + this.oldOnselectstart = document.onselectstart ? │ │ │ │ │ + document.onselectstart : OpenLayers.Function.True; │ │ │ │ │ + } │ │ │ │ │ + document.onselectstart = OpenLayers.Function.False; │ │ │ │ │ │ │ │ │ │ - if (this.pinchZoom) { │ │ │ │ │ - this.pinchZoom.destroy(); │ │ │ │ │ + propagate = !this.stopDown; │ │ │ │ │ + } else { │ │ │ │ │ + this.started = false; │ │ │ │ │ + this.start = null; │ │ │ │ │ + this.last = null; │ │ │ │ │ } │ │ │ │ │ - this.pinchZoom = null; │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + return propagate; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ + * Method: dragmove │ │ │ │ │ + * This private method is factorized from mousemove and touchmove methods │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - this.dragPan.activate(); │ │ │ │ │ - if (this.zoomWheelEnabled) { │ │ │ │ │ - this.handlers.wheel.activate(); │ │ │ │ │ - } │ │ │ │ │ - this.handlers.click.activate(); │ │ │ │ │ - if (this.zoomBoxEnabled) { │ │ │ │ │ - this.zoomBox.activate(); │ │ │ │ │ - } │ │ │ │ │ - if (this.pinchZoom) { │ │ │ │ │ - this.pinchZoom.activate(); │ │ │ │ │ + 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 OpenLayers.Control.prototype.activate.apply(this, arguments); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ + * Method: dragend │ │ │ │ │ + * This private method is factorized from mouseup and touchend methods │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.pinchZoom) { │ │ │ │ │ - this.pinchZoom.deactivate(); │ │ │ │ │ + dragend: function(evt) { │ │ │ │ │ + if (this.started) { │ │ │ │ │ + if (this.documentDrag === true && this.documentEvents) { │ │ │ │ │ + this.adjustXY(evt); │ │ │ │ │ + this.removeDocumentEvents(); │ │ │ │ │ + } │ │ │ │ │ + var dragged = (this.start != this.last); │ │ │ │ │ + this.started = false; │ │ │ │ │ + this.dragging = false; │ │ │ │ │ + OpenLayers.Element.removeClass( │ │ │ │ │ + this.map.viewPortDiv, "olDragDown" │ │ │ │ │ + ); │ │ │ │ │ + this.up(evt); │ │ │ │ │ + this.callback("up", [evt.xy]); │ │ │ │ │ + if (dragged) { │ │ │ │ │ + this.callback("done", [evt.xy]); │ │ │ │ │ + } │ │ │ │ │ + document.onselectstart = this.oldOnselectstart; │ │ │ │ │ } │ │ │ │ │ - this.zoomBox.deactivate(); │ │ │ │ │ - this.dragPan.deactivate(); │ │ │ │ │ - this.handlers.click.deactivate(); │ │ │ │ │ - this.handlers.wheel.deactivate(); │ │ │ │ │ - return OpenLayers.Control.prototype.deactivate.apply(this, arguments); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * The four methods below (down, move, up, and out) are used by subclasses │ │ │ │ │ + * to do their own processing related to these mouse events. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - // disable right mouse context menu for support of right click events │ │ │ │ │ - if (this.handleRightClicks) { │ │ │ │ │ - this.map.viewPortDiv.oncontextmenu = OpenLayers.Function.False; │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - var clickCallbacks = { │ │ │ │ │ - 'click': this.defaultClick, │ │ │ │ │ - 'dblclick': this.defaultDblClick, │ │ │ │ │ - 'dblrightclick': this.defaultDblRightClick │ │ │ │ │ - }; │ │ │ │ │ - var clickOptions = { │ │ │ │ │ - 'double': true, │ │ │ │ │ - 'stopDouble': true │ │ │ │ │ - }; │ │ │ │ │ - this.handlers.click = new OpenLayers.Handler.Click( │ │ │ │ │ - this, clickCallbacks, clickOptions │ │ │ │ │ - ); │ │ │ │ │ - this.dragPan = new OpenLayers.Control.DragPan( │ │ │ │ │ - OpenLayers.Util.extend({ │ │ │ │ │ - map: this.map, │ │ │ │ │ - documentDrag: this.documentDrag │ │ │ │ │ - }, this.dragPanOptions) │ │ │ │ │ - ); │ │ │ │ │ - this.zoomBox = new OpenLayers.Control.ZoomBox({ │ │ │ │ │ - map: this.map, │ │ │ │ │ - keyMask: this.zoomBoxKeyMask │ │ │ │ │ - }); │ │ │ │ │ - this.dragPan.draw(); │ │ │ │ │ - this.zoomBox.draw(); │ │ │ │ │ - var wheelOptions = this.map.fractionalZoom ? {} : { │ │ │ │ │ - cumulative: false, │ │ │ │ │ - interval: 50, │ │ │ │ │ - maxDelta: 6 │ │ │ │ │ - }; │ │ │ │ │ - this.handlers.wheel = new OpenLayers.Handler.MouseWheel( │ │ │ │ │ - this, { │ │ │ │ │ - up: this.wheelUp, │ │ │ │ │ - down: this.wheelDown │ │ │ │ │ - }, │ │ │ │ │ - OpenLayers.Util.extend(wheelOptions, this.mouseWheelOptions) │ │ │ │ │ - ); │ │ │ │ │ - if (OpenLayers.Control.PinchZoom) { │ │ │ │ │ - this.pinchZoom = new OpenLayers.Control.PinchZoom( │ │ │ │ │ - OpenLayers.Util.extend({ │ │ │ │ │ - map: this.map │ │ │ │ │ - }, this.pinchZoomOptions)); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Method: down │ │ │ │ │ + * This method is called during the handling of the mouse down event. │ │ │ │ │ + * Subclasses can do their own processing here. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The mouse down event │ │ │ │ │ + */ │ │ │ │ │ + down: function(evt) {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultClick │ │ │ │ │ + * Method: move │ │ │ │ │ + * This method is called during the handling of the mouse move event. │ │ │ │ │ + * Subclasses can do their own processing here. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The mouse move event │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + move: function(evt) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: up │ │ │ │ │ + * This method is called during the handling of the mouse up event. │ │ │ │ │ + * Subclasses can do their own processing here. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The mouse up event │ │ │ │ │ + */ │ │ │ │ │ + up: function(evt) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: out │ │ │ │ │ + * This method is called during the handling of the mouse out event. │ │ │ │ │ + * Subclasses can do their own processing here. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The mouse out event │ │ │ │ │ + */ │ │ │ │ │ + out: function(evt) {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * The methods below are part of the magic of event handling. Because │ │ │ │ │ + * they are named like browser events, they are registered as listeners │ │ │ │ │ + * for the events they represent. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: mousedown │ │ │ │ │ + * Handle mousedown events │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - defaultClick: function(evt) { │ │ │ │ │ - if (evt.lastTouches && evt.lastTouches.length == 2) { │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ - } │ │ │ │ │ + mousedown: function(evt) { │ │ │ │ │ + return this.dragstart(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultDblClick │ │ │ │ │ - * │ │ │ │ │ + * Method: touchstart │ │ │ │ │ + * Handle touchstart events │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - defaultDblClick: function(evt) { │ │ │ │ │ - this.map.zoomTo(this.map.zoom + 1, evt.xy); │ │ │ │ │ + touchstart: function(evt) { │ │ │ │ │ + this.startTouch(); │ │ │ │ │ + return this.dragstart(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultDblRightClick │ │ │ │ │ - * │ │ │ │ │ + * Method: mousemove │ │ │ │ │ + * Handle mousemove events │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - defaultDblRightClick: function(evt) { │ │ │ │ │ - this.map.zoomTo(this.map.zoom - 1, evt.xy); │ │ │ │ │ + mousemove: function(evt) { │ │ │ │ │ + return this.dragmove(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: wheelChange │ │ │ │ │ + * Method: touchmove │ │ │ │ │ + * Handle touchmove events │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ * evt - {Event} │ │ │ │ │ - * deltaZ - {Integer} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - wheelChange: function(evt, deltaZ) { │ │ │ │ │ - if (!this.map.fractionalZoom) { │ │ │ │ │ - deltaZ = Math.round(deltaZ); │ │ │ │ │ - } │ │ │ │ │ - var currentZoom = this.map.getZoom(), │ │ │ │ │ - newZoom = currentZoom + deltaZ; │ │ │ │ │ - newZoom = Math.max(newZoom, 0); │ │ │ │ │ - newZoom = Math.min(newZoom, this.map.getNumZoomLevels()); │ │ │ │ │ - if (newZoom === currentZoom) { │ │ │ │ │ - return; │ │ │ │ │ + touchmove: function(evt) { │ │ │ │ │ + return this.dragmove(evt); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeTimeout │ │ │ │ │ + * Private. Called by mousemove() to remove the drag timeout. │ │ │ │ │ + */ │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - this.map.zoomTo(newZoom, evt.xy); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: wheelUp │ │ │ │ │ - * User spun scroll wheel up │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: mouseup │ │ │ │ │ + * Handle mouseup events │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ * evt - {Event} │ │ │ │ │ - * delta - {Integer} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - wheelUp: function(evt, delta) { │ │ │ │ │ - this.wheelChange(evt, delta || 1); │ │ │ │ │ + mouseup: function(evt) { │ │ │ │ │ + return this.dragend(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: wheelDown │ │ │ │ │ - * User spun scroll wheel down │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: touchend │ │ │ │ │ + * Handle touchend events │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ * evt - {Event} │ │ │ │ │ - * delta - {Integer} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - wheelDown: function(evt, delta) { │ │ │ │ │ - this.wheelChange(evt, delta || -1); │ │ │ │ │ + touchend: function(evt) { │ │ │ │ │ + // override evt.xy with last position since touchend does not have │ │ │ │ │ + // any touch position │ │ │ │ │ + evt.xy = this.last; │ │ │ │ │ + return this.dragend(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: disableZoomBox │ │ │ │ │ + * Method: mouseout │ │ │ │ │ + * Handle mouseout events │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - disableZoomBox: function() { │ │ │ │ │ - this.zoomBoxEnabled = false; │ │ │ │ │ - this.zoomBox.deactivate(); │ │ │ │ │ + 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: enableZoomBox │ │ │ │ │ + * Method: click │ │ │ │ │ + * The drag handler captures the click event. If something else registers │ │ │ │ │ + * for clicks on the same element, its listener will not be called │ │ │ │ │ + * after a drag. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Let the event propagate. │ │ │ │ │ */ │ │ │ │ │ - enableZoomBox: function() { │ │ │ │ │ - this.zoomBoxEnabled = true; │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.zoomBox.activate(); │ │ │ │ │ + click: function(evt) { │ │ │ │ │ + // let the click event propagate only if the mouse moved │ │ │ │ │ + return (this.start == this.last); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: activate │ │ │ │ │ + * Activate the handler. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was successfully activated. │ │ │ │ │ + */ │ │ │ │ │ + activate: function() { │ │ │ │ │ + var activated = false; │ │ │ │ │ + if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + this.dragging = false; │ │ │ │ │ + activated = true; │ │ │ │ │ } │ │ │ │ │ + return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: disableZoomWheel │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + * Deactivate the handler. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was successfully deactivated. │ │ │ │ │ */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = false; │ │ │ │ │ + if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + this.started = false; │ │ │ │ │ + this.dragging = false; │ │ │ │ │ + this.start = null; │ │ │ │ │ + this.last = null; │ │ │ │ │ + deactivated = true; │ │ │ │ │ + OpenLayers.Element.removeClass( │ │ │ │ │ + this.map.viewPortDiv, "olDragDown" │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return deactivated; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - disableZoomWheel: function() { │ │ │ │ │ - this.zoomWheelEnabled = false; │ │ │ │ │ - this.handlers.wheel.deactivate(); │ │ │ │ │ + /** │ │ │ │ │ + * Method: adjustXY │ │ │ │ │ + * Converts event coordinates that are relative to the document body to │ │ │ │ │ + * ones that are relative to the map viewport. The latter is the default in │ │ │ │ │ + * OpenLayers. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} │ │ │ │ │ + */ │ │ │ │ │ + adjustXY: function(evt) { │ │ │ │ │ + var pos = OpenLayers.Util.pagePosition(this.map.viewPortDiv); │ │ │ │ │ + evt.xy.x -= pos[0]; │ │ │ │ │ + evt.xy.y -= pos[1]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: enableZoomWheel │ │ │ │ │ + * Method: addDocumentEvents │ │ │ │ │ + * Start observing document events when documentDrag is true and the mouse │ │ │ │ │ + * cursor leaves the map viewport while dragging. │ │ │ │ │ */ │ │ │ │ │ + addDocumentEvents: function() { │ │ │ │ │ + OpenLayers.Element.addClass(document.body, "olDragDown"); │ │ │ │ │ + this.documentEvents = true; │ │ │ │ │ + OpenLayers.Event.observe(document, "mousemove", this._docMove); │ │ │ │ │ + OpenLayers.Event.observe(document, "mouseup", this._docUp); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - enableZoomWheel: function() { │ │ │ │ │ - this.zoomWheelEnabled = true; │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.handlers.wheel.activate(); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeDocumentEvents │ │ │ │ │ + * Stops observing document events when documentDrag is true and the mouse │ │ │ │ │ + * cursor re-enters the map viewport while dragging. │ │ │ │ │ + */ │ │ │ │ │ + removeDocumentEvents: function() { │ │ │ │ │ + OpenLayers.Element.removeClass(document.body, "olDragDown"); │ │ │ │ │ + this.documentEvents = false; │ │ │ │ │ + OpenLayers.Event.stopObserving(document, "mousemove", this._docMove); │ │ │ │ │ + OpenLayers.Event.stopObserving(document, "mouseup", this._docUp); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Navigation" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Drag" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/DrawFeature.js │ │ │ │ │ + OpenLayers/Control/OverviewMap.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ +/** │ │ │ │ │ * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ + * @requires OpenLayers/BaseTypes.js │ │ │ │ │ + * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ + * @requires OpenLayers/Map.js │ │ │ │ │ + * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.DrawFeature │ │ │ │ │ - * The DrawFeature control draws point, line or polygon features on a vector │ │ │ │ │ - * layer when active. │ │ │ │ │ + * Class: OpenLayers.Control.OverviewMap │ │ │ │ │ + * The OverMap control creates a small overview map, useful to display the │ │ │ │ │ + * extent of a zoomed map and your main map and provide additional │ │ │ │ │ + * navigation options to the User. By default the overview map is drawn in │ │ │ │ │ + * the lower right corner of the main map. Create a new overview map with the │ │ │ │ │ + * constructor. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.DrawFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} │ │ │ │ │ + * Property: element │ │ │ │ │ + * {DOMElement} The DOM element that contains the overview map │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + element: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: callbacks │ │ │ │ │ - * {Object} The functions that are sent to the handler for callback │ │ │ │ │ + * APIProperty: ovmap │ │ │ │ │ + * {} A reference to the overview map itself. │ │ │ │ │ */ │ │ │ │ │ - callbacks: null, │ │ │ │ │ + ovmap: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: size │ │ │ │ │ + * {} The overvew map size in pixels. Note that this is │ │ │ │ │ + * the size of the map itself - the element that contains the map (default │ │ │ │ │ + * class name olControlOverviewMapElement) may have padding or other style │ │ │ │ │ + * attributes added via CSS. │ │ │ │ │ + */ │ │ │ │ │ + size: { │ │ │ │ │ + w: 180, │ │ │ │ │ + h: 90 │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: layers │ │ │ │ │ + * {Array()} Ordered list of layers in the overview map. │ │ │ │ │ + * If none are sent at construction, the base layer for the main map is used. │ │ │ │ │ + */ │ │ │ │ │ + layers: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minRectSize │ │ │ │ │ + * {Integer} The minimum width or height (in pixels) of the extent │ │ │ │ │ + * rectangle on the overview map. When the extent rectangle reaches │ │ │ │ │ + * this size, it will be replaced depending on the value of the │ │ │ │ │ + * property. Default is 15 pixels. │ │ │ │ │ + */ │ │ │ │ │ + minRectSize: 15, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: minRectDisplayClass │ │ │ │ │ + * {String} Replacement style class name for the extent rectangle when │ │ │ │ │ + * is reached. This string will be suffixed on to the │ │ │ │ │ + * displayClass. Default is "RectReplacement". │ │ │ │ │ * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * Example CSS declaration: │ │ │ │ │ * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ + * .olControlOverviewMapRectReplacement { │ │ │ │ │ + * overflow: hidden; │ │ │ │ │ + * cursor: move; │ │ │ │ │ + * background-image: url("img/overview_replacement.gif"); │ │ │ │ │ + * background-repeat: no-repeat; │ │ │ │ │ + * background-position: center; │ │ │ │ │ + * } │ │ │ │ │ * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * featureadded - Triggered when a feature is added │ │ │ │ │ */ │ │ │ │ │ + minRectDisplayClass: "RectReplacement", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: multi │ │ │ │ │ - * {Boolean} Cast features to multi-part geometries before passing to the │ │ │ │ │ - * layer. Default is false. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - multi: false, │ │ │ │ │ + minRatio: 8, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: featureAdded │ │ │ │ │ - * {Function} Called after each feature is added │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - featureAdded: function() {}, │ │ │ │ │ + maxRatio: 32, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ + * APIProperty: mapOptions │ │ │ │ │ + * {Object} An object containing any non-default properties to be sent to │ │ │ │ │ + * the overview map's map constructor. These should include any │ │ │ │ │ + * non-default options that the main map was constructed with. │ │ │ │ │ */ │ │ │ │ │ + mapOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.DrawFeature │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * handler - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - }, │ │ │ │ │ + autoPan: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ + * Property: handlers │ │ │ │ │ + * {Object} │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + handlers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: resolutionFactor │ │ │ │ │ + * {Object} │ │ │ │ │ */ │ │ │ │ │ - insertXY: function(x, y) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertXY(x, y); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + resolutionFactor: 1, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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: maximized │ │ │ │ │ + * {Boolean} Start as maximized (visible). Defaults to false. │ │ │ │ │ */ │ │ │ │ │ - insertDeltaXY: function(dx, dy) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertDeltaXY(dx, dy); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + maximized: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: maximizeTitle │ │ │ │ │ + * {String} This property is used for showing a tooltip over the │ │ │ │ │ + * maximize div. Defaults to "" (no title). │ │ │ │ │ */ │ │ │ │ │ - insertDirectionLength: function(direction, length) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertDirectionLength(direction, length); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + maximizeTitle: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: minimizeTitle │ │ │ │ │ + * {String} This property is used for showing a tooltip over the │ │ │ │ │ + * minimize div. Defaults to "" (no title). │ │ │ │ │ */ │ │ │ │ │ - insertDeflectionLength: function(deflection, length) { │ │ │ │ │ - if (this.handler && this.handler.line) { │ │ │ │ │ - this.handler.insertDeflectionLength(deflection, length); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + minimizeTitle: "", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: undo │ │ │ │ │ - * Remove the most recently added point in the current sketch geometry. │ │ │ │ │ + * Constructor: OpenLayers.Control.OverviewMap │ │ │ │ │ + * Create a new overview map │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} An edit was undone. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - undo: function() { │ │ │ │ │ - return this.handler.undo && this.handler.undo(); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.layers = []; │ │ │ │ │ + this.handlers = {}; │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: redo │ │ │ │ │ - * Reinsert the most recently removed point resulting from an call. │ │ │ │ │ - * The undo stack is deleted whenever a point is added by other means. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} An edit was redone. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Deconstruct the control │ │ │ │ │ */ │ │ │ │ │ - redo: function() { │ │ │ │ │ - return this.handler.redo && this.handler.redo(); │ │ │ │ │ - }, │ │ │ │ │ + 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(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ - */ │ │ │ │ │ - finishSketch: function() { │ │ │ │ │ - this.handler.finishGeometry(); │ │ │ │ │ + this.ovmap && this.ovmap.viewPortDiv.removeChild(this.extentRectangle); │ │ │ │ │ + this.extentRectangle = null; │ │ │ │ │ + │ │ │ │ │ + if (this.rectEvents) { │ │ │ │ │ + this.rectEvents.destroy(); │ │ │ │ │ + this.rectEvents = null; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.ovmap) { │ │ │ │ │ + this.ovmap.destroy(); │ │ │ │ │ + this.ovmap = null; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.element.removeChild(this.mapDiv); │ │ │ │ │ + this.mapDiv = null; │ │ │ │ │ + │ │ │ │ │ + this.div.removeChild(this.element); │ │ │ │ │ + this.element = null; │ │ │ │ │ + │ │ │ │ │ + if (this.maximizeDiv) { │ │ │ │ │ + this.div.removeChild(this.maximizeDiv); │ │ │ │ │ + this.maximizeDiv = null; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.minimizeDiv) { │ │ │ │ │ + this.div.removeChild(this.minimizeDiv); │ │ │ │ │ + this.minimizeDiv = null; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + buttonclick: this.onButtonClick, │ │ │ │ │ + moveend: this.update, │ │ │ │ │ + changebaselayer: this.baseLayerDraw, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Cancel the current sketch. This removes the current sketch and keeps │ │ │ │ │ - * the drawing control active. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Render the control in the browser. │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - this.handler.cancel(); │ │ │ │ │ - }, │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.DrawFeature" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Polygon.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + // create overview map DOM elements │ │ │ │ │ + this.element = document.createElement('div'); │ │ │ │ │ + this.element.className = this.displayClass + 'Element'; │ │ │ │ │ + this.element.style.display = 'none'; │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ + this.mapDiv = document.createElement('div'); │ │ │ │ │ + this.mapDiv.style.width = this.size.w + 'px'; │ │ │ │ │ + this.mapDiv.style.height = this.size.h + 'px'; │ │ │ │ │ + this.mapDiv.style.position = 'relative'; │ │ │ │ │ + this.mapDiv.style.overflow = 'hidden'; │ │ │ │ │ + this.mapDiv.id = OpenLayers.Util.createUniqueID('overviewMap'); │ │ │ │ │ │ │ │ │ │ + this.extentRectangle = document.createElement('div'); │ │ │ │ │ + this.extentRectangle.style.position = 'absolute'; │ │ │ │ │ + this.extentRectangle.style.zIndex = 1000; //HACK │ │ │ │ │ + this.extentRectangle.className = this.displayClass + 'ExtentRectangle'; │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler/Path.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ - */ │ │ │ │ │ + this.element.appendChild(this.mapDiv); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.Polygon │ │ │ │ │ - * Handler to draw a polygon on the map. Polygon is displayed on mouse down, │ │ │ │ │ - * moves on mouse move, and is finished on mouse up. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, { │ │ │ │ │ + this.div.appendChild(this.element); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: holeModifier │ │ │ │ │ - * {String} Key modifier to trigger hole digitizing. Acceptable values are │ │ │ │ │ - * "altKey", "shiftKey", or "ctrlKey". If not set, no hole digitizing │ │ │ │ │ - * will take place. Default is null. │ │ │ │ │ - */ │ │ │ │ │ - holeModifier: null, │ │ │ │ │ + // Optionally add min/max buttons if the control will go in the │ │ │ │ │ + // map viewport. │ │ │ │ │ + if (!this.outsideViewport) { │ │ │ │ │ + this.div.className += " " + this.displayClass + 'Container'; │ │ │ │ │ + // maximize button div │ │ │ │ │ + var img = OpenLayers.Util.getImageLocation('layer-switcher-maximize.png'); │ │ │ │ │ + this.maximizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ + this.displayClass + 'MaximizeButton', │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + img, │ │ │ │ │ + 'absolute'); │ │ │ │ │ + this.maximizeDiv.style.display = 'none'; │ │ │ │ │ + this.maximizeDiv.className = this.displayClass + 'MaximizeButton olButton'; │ │ │ │ │ + if (this.maximizeTitle) { │ │ │ │ │ + this.maximizeDiv.title = this.maximizeTitle; │ │ │ │ │ + } │ │ │ │ │ + this.div.appendChild(this.maximizeDiv); │ │ │ │ │ + │ │ │ │ │ + // minimize button div │ │ │ │ │ + var img = OpenLayers.Util.getImageLocation('layer-switcher-minimize.png'); │ │ │ │ │ + this.minimizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ + 'OpenLayers_Control_minimizeDiv', │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + img, │ │ │ │ │ + 'absolute'); │ │ │ │ │ + this.minimizeDiv.style.display = 'none'; │ │ │ │ │ + this.minimizeDiv.className = this.displayClass + 'MinimizeButton olButton'; │ │ │ │ │ + if (this.minimizeTitle) { │ │ │ │ │ + this.minimizeDiv.title = this.minimizeTitle; │ │ │ │ │ + } │ │ │ │ │ + this.div.appendChild(this.minimizeDiv); │ │ │ │ │ + this.minimizeControl(); │ │ │ │ │ + } else { │ │ │ │ │ + // show the overview map │ │ │ │ │ + this.element.style.display = ''; │ │ │ │ │ + } │ │ │ │ │ + if (this.map.getExtent()) { │ │ │ │ │ + this.update(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + buttonclick: this.onButtonClick, │ │ │ │ │ + moveend: this.update, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + if (this.maximized) { │ │ │ │ │ + this.maximizeControl(); │ │ │ │ │ + } │ │ │ │ │ + return this.div; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: drawingHole │ │ │ │ │ - * {Boolean} Currently drawing an interior ring. │ │ │ │ │ + * Method: baseLayerDraw │ │ │ │ │ + * Draw the base layer - called if unable to complete in the initial draw │ │ │ │ │ */ │ │ │ │ │ - drawingHole: false, │ │ │ │ │ + baseLayerDraw: function() { │ │ │ │ │ + this.draw(); │ │ │ │ │ + this.map.events.unregister("changebaselayer", this, this.baseLayerDraw); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: polygon │ │ │ │ │ - * {} │ │ │ │ │ + * Method: rectDrag │ │ │ │ │ + * Handle extent rectangle drag │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} The pixel location of the drag. │ │ │ │ │ */ │ │ │ │ │ - polygon: null, │ │ │ │ │ + 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)); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Polygon │ │ │ │ │ - * Create a Polygon Handler. │ │ │ │ │ + * Method: mapDivClick │ │ │ │ │ + * Handle browser events │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * control - {} The control that owns this handler │ │ │ │ │ - * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ - * functions. Various callbacks described below. │ │ │ │ │ - * options - {Object} An optional object with properties to be set on the │ │ │ │ │ - * handler │ │ │ │ │ - * │ │ │ │ │ - * Named callbacks: │ │ │ │ │ - * create - Called when a sketch is first created. Callback called with │ │ │ │ │ - * the creation point geometry and sketch feature. │ │ │ │ │ - * modify - Called with each move of a vertex with the vertex (point) │ │ │ │ │ - * geometry and the sketch feature. │ │ │ │ │ - * point - Called as each point is added. Receives the new point geometry. │ │ │ │ │ - * done - Called when the point drawing is finished. The callback will │ │ │ │ │ - * recieve a single argument, the polygon geometry. │ │ │ │ │ - * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ - * cancel callback will receive a geometry. │ │ │ │ │ + * evt - {} evt │ │ │ │ │ */ │ │ │ │ │ + mapDivClick: function(evt) { │ │ │ │ │ + var pxCenter = this.rectPxBounds.getCenterPixel(); │ │ │ │ │ + var deltaX = evt.xy.x - pxCenter.x; │ │ │ │ │ + var deltaY = evt.xy.y - pxCenter.y; │ │ │ │ │ + var top = this.rectPxBounds.top; │ │ │ │ │ + var left = this.rectPxBounds.left; │ │ │ │ │ + var height = Math.abs(this.rectPxBounds.getHeight()); │ │ │ │ │ + var width = this.rectPxBounds.getWidth(); │ │ │ │ │ + var newTop = Math.max(0, (top + deltaY)); │ │ │ │ │ + newTop = Math.min(newTop, this.ovmap.size.h - height); │ │ │ │ │ + var newLeft = Math.max(0, (left + deltaX)); │ │ │ │ │ + newLeft = Math.min(newLeft, this.ovmap.size.w - width); │ │ │ │ │ + this.setRectPxBounds(new OpenLayers.Bounds(newLeft, │ │ │ │ │ + newTop + height, │ │ │ │ │ + newLeft + width, │ │ │ │ │ + newTop)); │ │ │ │ │ + this.updateMapToRect(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createFeature │ │ │ │ │ - * Add temporary geometries │ │ │ │ │ + * Method: onButtonClick │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pixel - {} The initial pixel location for the new │ │ │ │ │ - * feature. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - createFeature: function(pixel) { │ │ │ │ │ - var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ - var geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - lonlat.lon, lonlat.lat │ │ │ │ │ - ); │ │ │ │ │ - this.point = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ - this.line = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.LinearRing([this.point.geometry]) │ │ │ │ │ - ); │ │ │ │ │ - this.polygon = new OpenLayers.Feature.Vector( │ │ │ │ │ - new OpenLayers.Geometry.Polygon([this.line.geometry]) │ │ │ │ │ - ); │ │ │ │ │ - this.callback("create", [this.point.geometry, this.getSketch()]); │ │ │ │ │ - this.point.geometry.clearBounds(); │ │ │ │ │ - this.layer.addFeatures([this.polygon, this.point], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ + onButtonClick: function(evt) { │ │ │ │ │ + if (evt.buttonElement === this.minimizeDiv) { │ │ │ │ │ + this.minimizeControl(); │ │ │ │ │ + } else if (evt.buttonElement === this.maximizeDiv) { │ │ │ │ │ + this.maximizeControl(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addPoint │ │ │ │ │ - * Add point to geometry. │ │ │ │ │ + * Method: maximizeControl │ │ │ │ │ + * Unhide the control. Called when the control is in the map viewport. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pixel - {} The pixel location for the new point. │ │ │ │ │ + * e - {} │ │ │ │ │ */ │ │ │ │ │ - addPoint: function(pixel) { │ │ │ │ │ - if (!this.drawingHole && this.holeModifier && │ │ │ │ │ - this.evt && this.evt[this.holeModifier]) { │ │ │ │ │ - var geometry = this.point.geometry; │ │ │ │ │ - var features = this.control.layer.features; │ │ │ │ │ - var candidate, polygon; │ │ │ │ │ - // look for intersections, last drawn gets priority │ │ │ │ │ - for (var i = features.length - 1; i >= 0; --i) { │ │ │ │ │ - candidate = features[i].geometry; │ │ │ │ │ - if ((candidate instanceof OpenLayers.Geometry.Polygon || │ │ │ │ │ - candidate instanceof OpenLayers.Geometry.MultiPolygon) && │ │ │ │ │ - candidate.intersects(geometry)) { │ │ │ │ │ - polygon = features[i]; │ │ │ │ │ - this.control.layer.removeFeatures([polygon], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.control.layer.events.registerPriority( │ │ │ │ │ - "sketchcomplete", this, this.finalizeInteriorRing │ │ │ │ │ - ); │ │ │ │ │ - this.control.layer.events.registerPriority( │ │ │ │ │ - "sketchmodified", this, this.enforceTopology │ │ │ │ │ - ); │ │ │ │ │ - polygon.geometry.addComponent(this.line.geometry); │ │ │ │ │ - this.polygon = polygon; │ │ │ │ │ - this.drawingHole = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + maximizeControl: function(e) { │ │ │ │ │ + this.element.style.display = ''; │ │ │ │ │ + this.showToggle(false); │ │ │ │ │ + if (e != null) { │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Handler.Path.prototype.addPoint.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getCurrentPointIndex │ │ │ │ │ + * Method: minimizeControl │ │ │ │ │ + * Hide all the contents of the control, shrink the size, │ │ │ │ │ + * add the maximize icon │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} The index of the most recently drawn point. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * e - {} │ │ │ │ │ */ │ │ │ │ │ - getCurrentPointIndex: function() { │ │ │ │ │ - return this.line.geometry.components.length - 2; │ │ │ │ │ + minimizeControl: function(e) { │ │ │ │ │ + this.element.style.display = 'none'; │ │ │ │ │ + this.showToggle(true); │ │ │ │ │ + if (e != null) { │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: enforceTopology │ │ │ │ │ - * Simple topology enforcement for drawing interior rings. Ensures vertices │ │ │ │ │ - * of interior rings are contained by exterior ring. Other topology │ │ │ │ │ - * rules are enforced in to allow drawing of │ │ │ │ │ - * rings that intersect only during the sketch (e.g. a "C" shaped ring │ │ │ │ │ - * that nearly encloses another ring). │ │ │ │ │ + * Method: showToggle │ │ │ │ │ + * Hide/Show the toggle depending on whether the control is minimized │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * minimize - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - enforceTopology: function(event) { │ │ │ │ │ - var point = event.vertex; │ │ │ │ │ - var components = this.line.geometry.components; │ │ │ │ │ - // ensure that vertices of interior ring are contained by exterior ring │ │ │ │ │ - if (!this.polygon.geometry.intersects(point)) { │ │ │ │ │ - var last = components[components.length - 3]; │ │ │ │ │ - point.x = last.x; │ │ │ │ │ - point.y = last.y; │ │ │ │ │ + showToggle: function(minimize) { │ │ │ │ │ + if (this.maximizeDiv) { │ │ │ │ │ + this.maximizeDiv.style.display = minimize ? '' : 'none'; │ │ │ │ │ + } │ │ │ │ │ + if (this.minimizeDiv) { │ │ │ │ │ + this.minimizeDiv.style.display = minimize ? 'none' : ''; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: finishGeometry │ │ │ │ │ - * Finish the geometry and send it back to the control. │ │ │ │ │ + * Method: update │ │ │ │ │ + * Update the overview map after layers move. │ │ │ │ │ */ │ │ │ │ │ - finishGeometry: function() { │ │ │ │ │ - var index = this.line.geometry.components.length - 2; │ │ │ │ │ - this.line.geometry.removeComponent(this.line.geometry.components[index]); │ │ │ │ │ - this.removePoint(); │ │ │ │ │ - this.finalize(); │ │ │ │ │ + update: function() { │ │ │ │ │ + if (this.ovmap == null) { │ │ │ │ │ + this.createMap(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.autoPan || !this.isSuitableOverview()) { │ │ │ │ │ + this.updateOverview(); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // update extent rectangle │ │ │ │ │ + this.updateRectToMap(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: finalizeInteriorRing │ │ │ │ │ - * Enforces that new ring has some area and doesn't contain vertices of any │ │ │ │ │ - * other rings. │ │ │ │ │ + * Method: isSuitableOverview │ │ │ │ │ + * Determines if the overview map is suitable given the extent and │ │ │ │ │ + * resolution of the main map. │ │ │ │ │ */ │ │ │ │ │ - finalizeInteriorRing: function() { │ │ │ │ │ - var ring = this.line.geometry; │ │ │ │ │ - // ensure that ring has some area │ │ │ │ │ - var modified = (ring.getArea() !== 0); │ │ │ │ │ - if (modified) { │ │ │ │ │ - // ensure that new ring doesn't intersect any other rings │ │ │ │ │ - var rings = this.polygon.geometry.components; │ │ │ │ │ - for (var i = rings.length - 2; i >= 0; --i) { │ │ │ │ │ - if (ring.intersects(rings[i])) { │ │ │ │ │ - modified = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (modified) { │ │ │ │ │ - // ensure that new ring doesn't contain any other rings │ │ │ │ │ - var target; │ │ │ │ │ - outer: for (var i = rings.length - 2; i > 0; --i) { │ │ │ │ │ - var points = rings[i].components; │ │ │ │ │ - for (var j = 0, jj = points.length; j < jj; ++j) { │ │ │ │ │ - if (ring.containsPoint(points[j])) { │ │ │ │ │ - modified = false; │ │ │ │ │ - break outer; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (modified) { │ │ │ │ │ - if (this.polygon.state !== OpenLayers.State.INSERT) { │ │ │ │ │ - this.polygon.state = OpenLayers.State.UPDATE; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - this.polygon.geometry.removeComponent(ring); │ │ │ │ │ + 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()); │ │ │ │ │ } │ │ │ │ │ - this.restoreFeature(); │ │ │ │ │ - return false; │ │ │ │ │ + │ │ │ │ │ + var resRatio = this.ovmap.getResolution() / this.map.getResolution(); │ │ │ │ │ + return ((resRatio > this.minRatio) && │ │ │ │ │ + (resRatio <= this.maxRatio) && │ │ │ │ │ + (this.ovmap.getExtent().containsBounds(testExtent))); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Finish the geometry and call the "cancel" callback. │ │ │ │ │ + * Method updateOverview │ │ │ │ │ + * Called by if returns true │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - if (this.drawingHole) { │ │ │ │ │ - this.polygon.geometry.removeComponent(this.line.geometry); │ │ │ │ │ - this.restoreFeature(true); │ │ │ │ │ + updateOverview: function() { │ │ │ │ │ + var mapRes = this.map.getResolution(); │ │ │ │ │ + var targetRes = this.ovmap.getResolution(); │ │ │ │ │ + var resRatio = targetRes / mapRes; │ │ │ │ │ + if (resRatio > this.maxRatio) { │ │ │ │ │ + // zoom in overview map │ │ │ │ │ + targetRes = this.minRatio * mapRes; │ │ │ │ │ + } else if (resRatio <= this.minRatio) { │ │ │ │ │ + // zoom out overview map │ │ │ │ │ + targetRes = this.maxRatio * mapRes; │ │ │ │ │ } │ │ │ │ │ - return OpenLayers.Handler.Path.prototype.cancel.apply(this, arguments); │ │ │ │ │ + var center; │ │ │ │ │ + if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ + center = this.map.center.clone(); │ │ │ │ │ + center.transform(this.map.getProjectionObject(), │ │ │ │ │ + this.ovmap.getProjectionObject()); │ │ │ │ │ + } else { │ │ │ │ │ + center = this.map.center; │ │ │ │ │ + } │ │ │ │ │ + this.ovmap.setCenter(center, this.ovmap.getZoomForResolution( │ │ │ │ │ + targetRes * this.resolutionFactor)); │ │ │ │ │ + this.updateRectToMap(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: restoreFeature │ │ │ │ │ - * Move the feature from the sketch layer to the target layer. │ │ │ │ │ - * │ │ │ │ │ - * Properties: │ │ │ │ │ - * cancel - {Boolean} Cancel drawing. If falsey, the "sketchcomplete" event │ │ │ │ │ - * will be fired. │ │ │ │ │ + * Method: createMap │ │ │ │ │ + * Construct the map that this control contains │ │ │ │ │ */ │ │ │ │ │ - restoreFeature: function(cancel) { │ │ │ │ │ - this.control.layer.events.unregister( │ │ │ │ │ - "sketchcomplete", this, this.finalizeInteriorRing │ │ │ │ │ + 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.control.layer.events.unregister( │ │ │ │ │ - "sketchmodified", this, this.enforceTopology │ │ │ │ │ + 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.layer.removeFeatures([this.polygon], { │ │ │ │ │ - silent: true │ │ │ │ │ + this.handlers.click.activate(); │ │ │ │ │ + │ │ │ │ │ + this.rectEvents = new OpenLayers.Events(this, this.extentRectangle, │ │ │ │ │ + null, true); │ │ │ │ │ + this.rectEvents.register("mouseover", this, function(e) { │ │ │ │ │ + if (!this.handlers.drag.active && !this.map.dragging) { │ │ │ │ │ + this.handlers.drag.activate(); │ │ │ │ │ + } │ │ │ │ │ }); │ │ │ │ │ - this.control.layer.addFeatures([this.polygon], { │ │ │ │ │ - silent: true │ │ │ │ │ + this.rectEvents.register("mouseout", this, function(e) { │ │ │ │ │ + if (!this.handlers.drag.dragging) { │ │ │ │ │ + this.handlers.drag.deactivate(); │ │ │ │ │ + } │ │ │ │ │ }); │ │ │ │ │ - this.drawingHole = false; │ │ │ │ │ - if (!cancel) { │ │ │ │ │ - // Re-trigger "sketchcomplete" so other listeners can do their │ │ │ │ │ - // business. While this is somewhat sloppy (if a listener is │ │ │ │ │ - // registered with registerPriority - not common - between the start │ │ │ │ │ - // and end of a single ring drawing - very uncommon - it will be │ │ │ │ │ - // called twice). │ │ │ │ │ - // TODO: In 3.0, collapse sketch handlers into geometry specific │ │ │ │ │ - // drawing controls. │ │ │ │ │ - this.control.layer.events.triggerEvent( │ │ │ │ │ - "sketchcomplete", { │ │ │ │ │ - feature: this.polygon │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ + │ │ │ │ │ + if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ + var sourceUnits = this.map.getProjectionObject().getUnits() || │ │ │ │ │ + this.map.units || this.map.baseLayer.units; │ │ │ │ │ + var targetUnits = this.ovmap.getProjectionObject().getUnits() || │ │ │ │ │ + this.ovmap.units || this.ovmap.baseLayer.units; │ │ │ │ │ + this.resolutionFactor = sourceUnits && targetUnits ? │ │ │ │ │ + OpenLayers.INCHES_PER_UNIT[sourceUnits] / │ │ │ │ │ + OpenLayers.INCHES_PER_UNIT[targetUnits] : 1; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroyFeature │ │ │ │ │ - * Destroy temporary geometries │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ + * Method: updateRectToMap │ │ │ │ │ + * Updates the extent rectangle position and size to match the map extent │ │ │ │ │ */ │ │ │ │ │ - destroyFeature: function(force) { │ │ │ │ │ - OpenLayers.Handler.Path.prototype.destroyFeature.call( │ │ │ │ │ - this, force); │ │ │ │ │ - this.polygon = null; │ │ │ │ │ + updateRectToMap: function() { │ │ │ │ │ + // If the projections differ we need to reproject │ │ │ │ │ + var bounds; │ │ │ │ │ + if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ + bounds = this.map.getExtent().transform( │ │ │ │ │ + this.map.getProjectionObject(), │ │ │ │ │ + this.ovmap.getProjectionObject()); │ │ │ │ │ + } else { │ │ │ │ │ + bounds = this.map.getExtent(); │ │ │ │ │ + } │ │ │ │ │ + var pxBounds = this.getRectBoundsFromMapBounds(bounds); │ │ │ │ │ + if (pxBounds) { │ │ │ │ │ + this.setRectPxBounds(pxBounds); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: drawFeature │ │ │ │ │ - * Render geometries on the temporary layer. │ │ │ │ │ + * Method: updateMapToRect │ │ │ │ │ + * Updates the map extent to match the extent rectangle position and size │ │ │ │ │ */ │ │ │ │ │ - drawFeature: function() { │ │ │ │ │ - this.layer.drawFeature(this.polygon, this.style); │ │ │ │ │ - this.layer.drawFeature(this.point, this.style); │ │ │ │ │ + updateMapToRect: function() { │ │ │ │ │ + var lonLatBounds = this.getMapBoundsFromRectBounds(this.rectPxBounds); │ │ │ │ │ + if (this.ovmap.getProjection() != this.map.getProjection()) { │ │ │ │ │ + lonLatBounds = lonLatBounds.transform( │ │ │ │ │ + this.ovmap.getProjectionObject(), │ │ │ │ │ + this.map.getProjectionObject()); │ │ │ │ │ + } │ │ │ │ │ + this.map.panTo(lonLatBounds.getCenterLonLat()); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getSketch │ │ │ │ │ - * Return the sketch feature. │ │ │ │ │ + * Method: setRectPxBounds │ │ │ │ │ + * Set extent rectangle pixel bounds. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * pxBounds - {} │ │ │ │ │ */ │ │ │ │ │ - getSketch: function() { │ │ │ │ │ - return this.polygon; │ │ │ │ │ + setRectPxBounds: function(pxBounds) { │ │ │ │ │ + var top = Math.max(pxBounds.top, 0); │ │ │ │ │ + var left = Math.max(pxBounds.left, 0); │ │ │ │ │ + var bottom = Math.min(pxBounds.top + Math.abs(pxBounds.getHeight()), │ │ │ │ │ + this.ovmap.size.h - this.hComp); │ │ │ │ │ + var right = Math.min(pxBounds.left + pxBounds.getWidth(), │ │ │ │ │ + this.ovmap.size.w - this.wComp); │ │ │ │ │ + var width = Math.max(right - left, 0); │ │ │ │ │ + var height = Math.max(bottom - top, 0); │ │ │ │ │ + if (width < this.minRectSize || height < this.minRectSize) { │ │ │ │ │ + this.extentRectangle.className = this.displayClass + │ │ │ │ │ + this.minRectDisplayClass; │ │ │ │ │ + var rLeft = left + (width / 2) - (this.minRectSize / 2); │ │ │ │ │ + var rTop = top + (height / 2) - (this.minRectSize / 2); │ │ │ │ │ + this.extentRectangle.style.top = Math.round(rTop) + 'px'; │ │ │ │ │ + this.extentRectangle.style.left = Math.round(rLeft) + 'px'; │ │ │ │ │ + this.extentRectangle.style.height = this.minRectSize + 'px'; │ │ │ │ │ + this.extentRectangle.style.width = this.minRectSize + 'px'; │ │ │ │ │ + } else { │ │ │ │ │ + this.extentRectangle.className = this.displayClass + │ │ │ │ │ + 'ExtentRectangle'; │ │ │ │ │ + this.extentRectangle.style.top = Math.round(top) + 'px'; │ │ │ │ │ + this.extentRectangle.style.left = Math.round(left) + 'px'; │ │ │ │ │ + this.extentRectangle.style.height = Math.round(height) + 'px'; │ │ │ │ │ + this.extentRectangle.style.width = Math.round(width) + 'px'; │ │ │ │ │ + } │ │ │ │ │ + this.rectPxBounds = new OpenLayers.Bounds( │ │ │ │ │ + Math.round(left), Math.round(bottom), │ │ │ │ │ + Math.round(right), Math.round(top) │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getGeometry │ │ │ │ │ - * Return the sketch geometry. If is true, this will return │ │ │ │ │ - * a multi-part geometry. │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - getGeometry: function() { │ │ │ │ │ - var geometry = this.polygon && this.polygon.geometry; │ │ │ │ │ - if (geometry && this.multi) { │ │ │ │ │ - geometry = new OpenLayers.Geometry.MultiPolygon([geometry]); │ │ │ │ │ + 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 geometry; │ │ │ │ │ + return bounds; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Polygon" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/EditingToolbar.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control/Panel.js │ │ │ │ │ - * @requires OpenLayers/Control/Navigation.js │ │ │ │ │ - * @requires OpenLayers/Control/DrawFeature.js │ │ │ │ │ - * @requires OpenLayers/Handler/Point.js │ │ │ │ │ - * @requires OpenLayers/Handler/Path.js │ │ │ │ │ - * @requires OpenLayers/Handler/Polygon.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.EditingToolbar │ │ │ │ │ - * The EditingToolbar is a panel of 4 controls to draw polygons, lines, │ │ │ │ │ - * points, or to navigate the map by panning. By default it appears in the │ │ │ │ │ - * upper right corner of the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.EditingToolbar = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Control.Panel, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: citeCompliant │ │ │ │ │ - * {Boolean} If set to true, coordinates of features drawn in a map extent │ │ │ │ │ - * crossing the date line won't exceed the world bounds. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - citeCompliant: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.EditingToolbar │ │ │ │ │ - * Create an editing toolbar for a given layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(layer, options) { │ │ │ │ │ - OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ - │ │ │ │ │ - this.addControls( │ │ │ │ │ - [new OpenLayers.Control.Navigation()] │ │ │ │ │ - ); │ │ │ │ │ - var controls = [ │ │ │ │ │ - new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, { │ │ │ │ │ - displayClass: 'olControlDrawFeaturePoint', │ │ │ │ │ - handlerOptions: { │ │ │ │ │ - citeCompliant: this.citeCompliant │ │ │ │ │ - } │ │ │ │ │ - }), │ │ │ │ │ - new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, { │ │ │ │ │ - displayClass: 'olControlDrawFeaturePath', │ │ │ │ │ - handlerOptions: { │ │ │ │ │ - citeCompliant: this.citeCompliant │ │ │ │ │ - } │ │ │ │ │ - }), │ │ │ │ │ - new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, { │ │ │ │ │ - displayClass: 'olControlDrawFeaturePolygon', │ │ │ │ │ - handlerOptions: { │ │ │ │ │ - citeCompliant: this.citeCompliant │ │ │ │ │ - } │ │ │ │ │ - }) │ │ │ │ │ - ]; │ │ │ │ │ - this.addControls(controls); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * calls the default draw, and then activates mouse defaults. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (this.defaultControl === null) { │ │ │ │ │ - this.defaultControl = this.controls[0]; │ │ │ │ │ - } │ │ │ │ │ - return div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.EditingToolbar" │ │ │ │ │ - }); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Scale.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Lang.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.Scale │ │ │ │ │ - * The Scale control displays the current map scale as a ratio (e.g. Scale = │ │ │ │ │ - * 1:1M). By default it is displayed in the lower right corner of the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.Scale = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: element │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - element: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geodesic │ │ │ │ │ - * {Boolean} Use geodesic measurement. Default is false. The recommended │ │ │ │ │ - * setting for maps in EPSG:4326 is false, and true EPSG:900913. If set to │ │ │ │ │ - * true, the scale will be calculated based on the horizontal size of the │ │ │ │ │ - * pixel in the center of the map viewport. │ │ │ │ │ - */ │ │ │ │ │ - geodesic: false, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Scale │ │ │ │ │ - * │ │ │ │ │ + * Method: getMapBoundsFromRectBounds │ │ │ │ │ + * Get the map bounds from the rect bounds. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * element - {DOMElement} │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(element, options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.element = OpenLayers.Util.getElement(element); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * │ │ │ │ │ + * pxBounds - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * {} Bounds which is the passed-in overview rect bounds │ │ │ │ │ + * translated into lon/lat bounds for the overview map │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (!this.element) { │ │ │ │ │ - this.element = document.createElement("div"); │ │ │ │ │ - this.div.appendChild(this.element); │ │ │ │ │ - } │ │ │ │ │ - this.map.events.register('moveend', this, this.updateScale); │ │ │ │ │ - this.updateScale(); │ │ │ │ │ - return this.div; │ │ │ │ │ + getMapBoundsFromRectBounds: function(pxBounds) { │ │ │ │ │ + var leftBottomLonLat = this.getLonLatFromOverviewPx({ │ │ │ │ │ + x: pxBounds.left, │ │ │ │ │ + y: pxBounds.bottom │ │ │ │ │ + }); │ │ │ │ │ + var rightTopLonLat = this.getLonLatFromOverviewPx({ │ │ │ │ │ + x: pxBounds.right, │ │ │ │ │ + y: pxBounds.top │ │ │ │ │ + }); │ │ │ │ │ + return new OpenLayers.Bounds(leftBottomLonLat.lon, leftBottomLonLat.lat, │ │ │ │ │ + rightTopLonLat.lon, rightTopLonLat.lat); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateScale │ │ │ │ │ + * Method: getLonLatFromOverviewPx │ │ │ │ │ + * Get a map location from a pixel location │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * overviewMapPx - {|Object} OpenLayers.Pixel or │ │ │ │ │ + * an object with a │ │ │ │ │ + * 'x' and 'y' properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} Location which is the passed-in overview map │ │ │ │ │ + * OpenLayers.Pixel, translated into lon/lat by the overview │ │ │ │ │ + * map. An object with a 'lon' and 'lat' properties. │ │ │ │ │ */ │ │ │ │ │ - updateScale: function() { │ │ │ │ │ - var scale; │ │ │ │ │ - if (this.geodesic === true) { │ │ │ │ │ - var units = this.map.getUnits(); │ │ │ │ │ - if (!units) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var inches = OpenLayers.INCHES_PER_UNIT; │ │ │ │ │ - scale = (this.map.getGeodesicPixelSize().w || 0.000001) * │ │ │ │ │ - inches["km"] * OpenLayers.DOTS_PER_INCH; │ │ │ │ │ - } else { │ │ │ │ │ - scale = this.map.getScale(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (!scale) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + getLonLatFromOverviewPx: function(overviewMapPx) { │ │ │ │ │ + var size = this.ovmap.size; │ │ │ │ │ + var res = this.ovmap.getResolution(); │ │ │ │ │ + var center = this.ovmap.getExtent().getCenterLonLat(); │ │ │ │ │ │ │ │ │ │ - if (scale >= 9500 && scale <= 950000) { │ │ │ │ │ - scale = Math.round(scale / 1000) + "K"; │ │ │ │ │ - } else if (scale >= 950000) { │ │ │ │ │ - scale = Math.round(scale / 1000000) + "M"; │ │ │ │ │ - } else { │ │ │ │ │ - scale = Math.round(scale); │ │ │ │ │ - } │ │ │ │ │ + var deltaX = overviewMapPx.x - (size.w / 2); │ │ │ │ │ + var deltaY = overviewMapPx.y - (size.h / 2); │ │ │ │ │ │ │ │ │ │ - this.element.innerHTML = OpenLayers.i18n("Scale = 1 : ${scaleDenom}", { │ │ │ │ │ - 'scaleDenom': scale │ │ │ │ │ - }); │ │ │ │ │ + return { │ │ │ │ │ + lon: center.lon + deltaX * res, │ │ │ │ │ + lat: center.lat - deltaY * res │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Scale" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ZoomIn.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control/Button.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.ZoomIn │ │ │ │ │ - * The ZoomIn control is a button to increase the zoom level of a map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ZoomIn = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: trigger │ │ │ │ │ + * Method: getOverviewPxFromLonLat │ │ │ │ │ + * Get a pixel location from a map location │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ + * object with a 'lon' and 'lat' properties. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} Location which is the passed-in OpenLayers.LonLat, │ │ │ │ │ + * translated into overview map pixels │ │ │ │ │ */ │ │ │ │ │ - trigger: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.zoomIn(); │ │ │ │ │ + getOverviewPxFromLonLat: function(lonlat) { │ │ │ │ │ + var res = this.ovmap.getResolution(); │ │ │ │ │ + var extent = this.ovmap.getExtent(); │ │ │ │ │ + if (extent) { │ │ │ │ │ + return { │ │ │ │ │ + x: Math.round(1 / res * (lonlat.lon - extent.left)), │ │ │ │ │ + y: Math.round(1 / res * (extent.top - lonlat.lat)) │ │ │ │ │ + }; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ZoomIn" │ │ │ │ │ + CLASS_NAME: 'OpenLayers.Control.OverviewMap' │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Snapping.js │ │ │ │ │ + OpenLayers/Layer/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. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ + * @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 │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Snapping │ │ │ │ │ - * Acts as a snapping agent while editing vector features. │ │ │ │ │ + * 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: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Snapping = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ + /** │ │ │ │ │ * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ + * {} │ │ │ │ │ * │ │ │ │ │ * Register a listener for a particular event with the following syntax: │ │ │ │ │ * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ + * layer.events.register(type, obj, listener); │ │ │ │ │ * (end) │ │ │ │ │ * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * beforesnap - Triggered before a snap occurs. Listeners receive an │ │ │ │ │ - * event object with *point*, *x*, *y*, *distance*, *layer*, and │ │ │ │ │ - * *snapType* properties. The point property will be original point │ │ │ │ │ - * geometry considered for snapping. The x and y properties represent │ │ │ │ │ - * coordinates the point will receive. The distance is the distance │ │ │ │ │ - * of the snap. The layer is the target layer. The snapType property │ │ │ │ │ - * will be one of "node", "vertex", or "edge". Return false to stop │ │ │ │ │ - * snapping from occurring. │ │ │ │ │ - * snap - Triggered when a snap occurs. Listeners receive an event with │ │ │ │ │ - * *point*, *snapType*, *layer*, and *distance* properties. The point │ │ │ │ │ - * will be the location snapped to. The snapType will be one of "node", │ │ │ │ │ - * "vertex", or "edge". The layer will be the target layer. The │ │ │ │ │ - * distance will be the distance of the snap in map units. │ │ │ │ │ - * unsnap - Triggered when a vertex is unsnapped. Listeners receive an │ │ │ │ │ - * event with a *point* property. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * CONSTANT: DEFAULTS │ │ │ │ │ - * Default target properties. │ │ │ │ │ + * APIProperty: isBaseLayer │ │ │ │ │ + * {Boolean} The layer is a base layer. Default is false. Set this property │ │ │ │ │ + * in the layer options. │ │ │ │ │ */ │ │ │ │ │ - DEFAULTS: { │ │ │ │ │ - tolerance: 10, │ │ │ │ │ - node: true, │ │ │ │ │ - edge: true, │ │ │ │ │ - vertex: true │ │ │ │ │ - }, │ │ │ │ │ + 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. │ │ │ │ │ + */ │ │ │ │ │ + filter: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: selectedFeatures │ │ │ │ │ + * {Array()} │ │ │ │ │ + */ │ │ │ │ │ + selectedFeatures: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: greedy │ │ │ │ │ - * {Boolean} Snap to closest feature in first layer with an eligible │ │ │ │ │ - * feature. Default is true. │ │ │ │ │ + * Property: unrenderedFeatures │ │ │ │ │ + * {Object} hash of features, keyed by feature.id, that the renderer │ │ │ │ │ + * failed to draw │ │ │ │ │ */ │ │ │ │ │ - greedy: true, │ │ │ │ │ + unrenderedFeatures: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: precedence │ │ │ │ │ - * {Array} List representing precedence of different snapping types. │ │ │ │ │ - * Default is "node", "vertex", "edge". │ │ │ │ │ + * APIProperty: reportError │ │ │ │ │ + * {Boolean} report friendly error message when loading of renderer │ │ │ │ │ + * fails. │ │ │ │ │ */ │ │ │ │ │ - precedence: ["node", "vertex", "edge"], │ │ │ │ │ + reportError: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: style │ │ │ │ │ + * {Object} Default style for the layer │ │ │ │ │ + */ │ │ │ │ │ + style: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: resolution │ │ │ │ │ - * {Float} The map resolution for the previously considered snap. │ │ │ │ │ + * Property: styleMap │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - resolution: null, │ │ │ │ │ + styleMap: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: geoToleranceCache │ │ │ │ │ - * {Object} A cache of geo-tolerances. Tolerance values (in map units) are │ │ │ │ │ - * calculated when the map resolution changes. │ │ │ │ │ + * Property: strategies │ │ │ │ │ + * {Array(})} Optional list of strategies for the layer. │ │ │ │ │ */ │ │ │ │ │ - geoToleranceCache: null, │ │ │ │ │ + strategies: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} The current editable layer. Set at │ │ │ │ │ - * construction or after construction with . │ │ │ │ │ + * Property: protocol │ │ │ │ │ + * {} Optional protocol for the layer. │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + protocol: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: feature │ │ │ │ │ - * {} The current editable feature. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - feature: null, │ │ │ │ │ + renderers: ['SVG', 'VML', 'Canvas'], │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: renderer │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + renderer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: point │ │ │ │ │ - * {} The currently snapped vertex. │ │ │ │ │ + * APIProperty: rendererOptions │ │ │ │ │ + * {Object} Options for the renderer. See {} for │ │ │ │ │ + * supported options. │ │ │ │ │ */ │ │ │ │ │ - point: null, │ │ │ │ │ + rendererOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: drawn │ │ │ │ │ + * {Boolean} Whether the Vector Layer features have been drawn yet. │ │ │ │ │ + */ │ │ │ │ │ + drawn: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: ratio │ │ │ │ │ + * {Float} This specifies the ratio of the size of the visiblity of the Vector Layer features to the size of the map. │ │ │ │ │ + */ │ │ │ │ │ + ratio: 1, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Snapping │ │ │ │ │ - * Creates a new snapping control. A control is constructed with an editable │ │ │ │ │ - * layer and a set of configuration objects for target layers. While the │ │ │ │ │ - * control is active, dragging vertices while drawing new features or │ │ │ │ │ - * modifying existing features on the editable layer will engage │ │ │ │ │ - * snapping to features on the target layers. Whether a vertex snaps to │ │ │ │ │ - * a feature on a target layer depends on the target layer configuration. │ │ │ │ │ + * Constructor: OpenLayers.Layer.Vector │ │ │ │ │ + * Create a new vector layer │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An object containing all configuration properties for │ │ │ │ │ - * the control. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * layer - {} The editable layer. Features from this │ │ │ │ │ - * layer that are digitized or modified may have vertices snapped to │ │ │ │ │ - * features from any of the target layers. │ │ │ │ │ - * targets - {Array(Object | OpenLayers.Layer.Vector)} A list of objects for │ │ │ │ │ - * configuring target layers. See valid properties of the target │ │ │ │ │ - * objects below. If the items in the targets list are vector layers │ │ │ │ │ - * (instead of configuration objects), the defaults from the │ │ │ │ │ - * property will apply. The editable layer itself may be a target │ │ │ │ │ - * layer, allowing newly created or edited features to be snapped to │ │ │ │ │ - * existing features from the same layer. If no targets are provided │ │ │ │ │ - * the layer given in the constructor (as ) will become the │ │ │ │ │ - * initial target. │ │ │ │ │ - * defaults - {Object} An object with default properties to be applied │ │ │ │ │ - * to all target objects. │ │ │ │ │ - * greedy - {Boolean} Snap to closest feature in first target layer that │ │ │ │ │ - * applies. Default is true. If false, all features in all target │ │ │ │ │ - * layers will be checked and the closest feature in all target layers │ │ │ │ │ - * will be chosen. The greedy property determines if the order of the │ │ │ │ │ - * target layers is significant. By default, the order of the target │ │ │ │ │ - * layers is significant where layers earlier in the target layer list │ │ │ │ │ - * have precedence over layers later in the list. Within a single │ │ │ │ │ - * layer, the closest feature is always chosen for snapping. This │ │ │ │ │ - * property only determines whether the search for a closer feature │ │ │ │ │ - * continues after an eligible feature is found in a target layer. │ │ │ │ │ + * name - {String} A name for the layer │ │ │ │ │ + * options - {Object} Optional object with non-default properties to set on │ │ │ │ │ + * the layer. │ │ │ │ │ * │ │ │ │ │ - * Valid target properties: │ │ │ │ │ - * layer - {} A target layer. Features from this │ │ │ │ │ - * layer will be eligible to act as snapping target for the editable │ │ │ │ │ - * layer. │ │ │ │ │ - * tolerance - {Float} The distance (in pixels) at which snapping may occur. │ │ │ │ │ - * Default is 10. │ │ │ │ │ - * node - {Boolean} Snap to nodes (first or last point in a geometry) in │ │ │ │ │ - * target layer. Default is true. │ │ │ │ │ - * nodeTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ - * for nodes specifically. If none is provided, will be │ │ │ │ │ - * used. │ │ │ │ │ - * vertex - {Boolean} Snap to vertices in target layer. Default is true. │ │ │ │ │ - * vertexTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ - * for vertices specifically. If none is provided, will be │ │ │ │ │ - * used. │ │ │ │ │ - * edge - {Boolean} Snap to edges in target layer. Default is true. │ │ │ │ │ - * edgeTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ - * for edges specifically. If none is provided, will be │ │ │ │ │ - * used. │ │ │ │ │ - * filter - {} Optional filter to evaluate to determine if │ │ │ │ │ - * feature is eligible for snapping. If filter evaluates to true for a │ │ │ │ │ - * target feature a vertex may be snapped to the feature. │ │ │ │ │ - * minResolution - {Number} If a minResolution is provided, snapping to this │ │ │ │ │ - * target will only be considered if the map resolution is greater than │ │ │ │ │ - * or equal to this value (the minResolution is inclusive). Default is │ │ │ │ │ - * no minimum resolution limit. │ │ │ │ │ - * maxResolution - {Number} If a maxResolution is provided, snapping to this │ │ │ │ │ - * target will only be considered if the map resolution is strictly │ │ │ │ │ - * less than this value (the maxResolution is exclusive). Default is │ │ │ │ │ - * no maximum resolution limit. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A new vector layer │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.options = options || {}; // TODO: this could be done by the super │ │ │ │ │ + initialize: function(name, options) { │ │ │ │ │ + OpenLayers.Layer.prototype.initialize.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - // set the editable layer if provided │ │ │ │ │ - if (this.options.layer) { │ │ │ │ │ - this.setLayer(this.options.layer); │ │ │ │ │ + // allow user-set renderer, otherwise assign one │ │ │ │ │ + if (!this.renderer || !this.renderer.supported()) { │ │ │ │ │ + this.assignRenderer(); │ │ │ │ │ } │ │ │ │ │ - // configure target layers │ │ │ │ │ - var defaults = OpenLayers.Util.extend({}, this.options.defaults); │ │ │ │ │ - this.defaults = OpenLayers.Util.applyDefaults(defaults, this.DEFAULTS); │ │ │ │ │ - this.setTargets(this.options.targets); │ │ │ │ │ - if (this.targets.length === 0 && this.layer) { │ │ │ │ │ - this.addTargetLayer(this.layer); │ │ │ │ │ + │ │ │ │ │ + // if no valid renderer found, display error │ │ │ │ │ + if (!this.renderer || !this.renderer.supported()) { │ │ │ │ │ + this.renderer = null; │ │ │ │ │ + this.displayError(); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - this.geoToleranceCache = {}; │ │ │ │ │ - }, │ │ │ │ │ + if (!this.styleMap) { │ │ │ │ │ + this.styleMap = new OpenLayers.StyleMap(); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setLayer │ │ │ │ │ - * Set the editable layer. Call the setLayer method if the editable layer │ │ │ │ │ - * changes and the same control should be used on a new editable layer. │ │ │ │ │ - * If the control is already active, it will be active after the new │ │ │ │ │ - * layer is set. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} The new editable layer. │ │ │ │ │ - */ │ │ │ │ │ - setLayer: function(layer) { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - this.layer = layer; │ │ │ │ │ - this.activate(); │ │ │ │ │ - } else { │ │ │ │ │ - this.layer = layer; │ │ │ │ │ + this.features = []; │ │ │ │ │ + this.selectedFeatures = []; │ │ │ │ │ + this.unrenderedFeatures = {}; │ │ │ │ │ + │ │ │ │ │ + // Allow for custom layer behavior │ │ │ │ │ + if (this.strategies) { │ │ │ │ │ + for (var i = 0, len = this.strategies.length; i < len; i++) { │ │ │ │ │ + this.strategies[i].setLayer(this); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setTargets │ │ │ │ │ - * Set the targets for the snapping agent. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * targets - {Array} An array of target configs or target layers. │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Destroy this layer │ │ │ │ │ */ │ │ │ │ │ - setTargets: function(targets) { │ │ │ │ │ - this.targets = []; │ │ │ │ │ - if (targets && targets.length) { │ │ │ │ │ - var target; │ │ │ │ │ - for (var i = 0, len = targets.length; i < len; ++i) { │ │ │ │ │ - target = targets[i]; │ │ │ │ │ - if (target instanceof OpenLayers.Layer.Vector) { │ │ │ │ │ - this.addTargetLayer(target); │ │ │ │ │ - } else { │ │ │ │ │ - this.addTarget(target); │ │ │ │ │ + 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(); │ │ │ │ │ } │ │ │ │ │ + this.renderer = null; │ │ │ │ │ + this.geometryType = null; │ │ │ │ │ + this.drawn = null; │ │ │ │ │ + OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addTargetLayer │ │ │ │ │ - * Add a target layer with the default target config. │ │ │ │ │ + * Method: clone │ │ │ │ │ + * Create a clone of this layer. │ │ │ │ │ + * │ │ │ │ │ + * Note: Features of the layer are also cloned. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} A target layer. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} An exact clone of this layer │ │ │ │ │ */ │ │ │ │ │ - addTargetLayer: function(layer) { │ │ │ │ │ - this.addTarget({ │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ + clone: function(obj) { │ │ │ │ │ + │ │ │ │ │ + if (obj == null) { │ │ │ │ │ + obj = new OpenLayers.Layer.Vector(this.name, this.getOptions()); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + //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(); │ │ │ │ │ + } │ │ │ │ │ + obj.features = clonedFeatures; │ │ │ │ │ + │ │ │ │ │ + return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addTarget │ │ │ │ │ - * Add a configured target layer. │ │ │ │ │ + * Method: refresh │ │ │ │ │ + * Ask the layer to request features again and redraw them. Triggers │ │ │ │ │ + * the refresh event if the layer is in range and visible. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * target - {Object} A target config. │ │ │ │ │ + * obj - {Object} Optional object with properties for any listener of │ │ │ │ │ + * the refresh event. │ │ │ │ │ */ │ │ │ │ │ - addTarget: function(target) { │ │ │ │ │ - target = OpenLayers.Util.applyDefaults(target, this.defaults); │ │ │ │ │ - target.nodeTolerance = target.nodeTolerance || target.tolerance; │ │ │ │ │ - target.vertexTolerance = target.vertexTolerance || target.tolerance; │ │ │ │ │ - target.edgeTolerance = target.edgeTolerance || target.tolerance; │ │ │ │ │ - this.targets.push(target); │ │ │ │ │ + refresh: function(obj) { │ │ │ │ │ + if (this.calculateInRange() && this.visibility) { │ │ │ │ │ + this.events.triggerEvent("refresh", obj); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeTargetLayer │ │ │ │ │ - * Remove a target layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} The target layer to remove. │ │ │ │ │ + /** │ │ │ │ │ + * Method: assignRenderer │ │ │ │ │ + * Iterates through the available renderer implementations and selects │ │ │ │ │ + * and assigns the first one whose "supported()" function returns true. │ │ │ │ │ */ │ │ │ │ │ - removeTargetLayer: function(layer) { │ │ │ │ │ - var target; │ │ │ │ │ - for (var i = this.targets.length - 1; i >= 0; --i) { │ │ │ │ │ - target = this.targets[i]; │ │ │ │ │ - if (target.layer === layer) { │ │ │ │ │ - this.removeTarget(target); │ │ │ │ │ + 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; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeTarget │ │ │ │ │ - * Remove a target. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: displayError │ │ │ │ │ + * Let the user know their browser isn't supported. │ │ │ │ │ + */ │ │ │ │ │ + displayError: function() { │ │ │ │ │ + if (this.reportError) { │ │ │ │ │ + OpenLayers.Console.userError(OpenLayers.i18n("browserNotSupported", { │ │ │ │ │ + renderers: this.renderers.join('\n') │ │ │ │ │ + })); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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: │ │ │ │ │ - * target - {Object} A target config. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} The targets array. │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - removeTarget: function(target) { │ │ │ │ │ - return OpenLayers.Util.removeItem(this.targets, target); │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Layer.prototype.setMap.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + if (!this.renderer) { │ │ │ │ │ + this.map.removeLayer(this); │ │ │ │ │ + } else { │ │ │ │ │ + this.renderer.map = this.map; │ │ │ │ │ + │ │ │ │ │ + var newSize = this.map.getSize(); │ │ │ │ │ + newSize.w = newSize.w * this.ratio; │ │ │ │ │ + newSize.h = newSize.h * this.ratio; │ │ │ │ │ + this.renderer.setSize(newSize); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the control. Activating the control registers listeners for │ │ │ │ │ - * editing related events so that during feature creation and │ │ │ │ │ - * modification, moving vertices will trigger snapping. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = OpenLayers.Control.prototype.activate.call(this); │ │ │ │ │ - if (activated) { │ │ │ │ │ - if (this.layer && this.layer.events) { │ │ │ │ │ - this.layer.events.on({ │ │ │ │ │ - sketchstarted: this.onSketchModified, │ │ │ │ │ - sketchmodified: this.onSketchModified, │ │ │ │ │ - vertexmodified: this.onVertexModified, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + 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(); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the control. Deactivating the control unregisters listeners │ │ │ │ │ - * so feature editing may proceed without engaging the snapping agent. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = OpenLayers.Control.prototype.deactivate.call(this); │ │ │ │ │ - if (deactivated) { │ │ │ │ │ - if (this.layer && this.layer.events) { │ │ │ │ │ - this.layer.events.un({ │ │ │ │ │ - sketchstarted: this.onSketchModified, │ │ │ │ │ - sketchmodified: this.onSketchModified, │ │ │ │ │ - vertexmodified: this.onVertexModified, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + * Method: removeMap │ │ │ │ │ + * The layer has been removed from the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ + */ │ │ │ │ │ + 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(); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - this.feature = null; │ │ │ │ │ - this.point = null; │ │ │ │ │ - return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onSketchModified │ │ │ │ │ - * Registered as a listener for the sketchmodified event on the editable │ │ │ │ │ - * layer. │ │ │ │ │ - * │ │ │ │ │ + * Method: onMapResize │ │ │ │ │ + * Notify the renderer of the change in size. │ │ │ │ │ + * │ │ │ │ │ + */ │ │ │ │ │ + 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); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * event - {Object} The sketch modified event. │ │ │ │ │ + * bounds - {} │ │ │ │ │ + * zoomChanged - {Boolean} │ │ │ │ │ + * dragging - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - onSketchModified: function(event) { │ │ │ │ │ - this.feature = event.feature; │ │ │ │ │ - this.considerSnapping(event.vertex, event.vertex); │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: display │ │ │ │ │ + * Hide or show the Layer │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * display - {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onVertexModified │ │ │ │ │ - * Registered as a listener for the vertexmodified event on the editable │ │ │ │ │ - * layer. │ │ │ │ │ + * APIMethod: addFeatures │ │ │ │ │ + * Add Features to the layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * event - {Object} The vertex modified event. │ │ │ │ │ + * features - {Array()} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - onVertexModified: function(event) { │ │ │ │ │ - this.feature = event.feature; │ │ │ │ │ - var loc = this.layer.map.getLonLatFromViewPortPx(event.pixel); │ │ │ │ │ - this.considerSnapping( │ │ │ │ │ - event.vertex, new OpenLayers.Geometry.Point(loc.lon, loc.lat) │ │ │ │ │ - ); │ │ │ │ │ + addFeatures: function(features, options) { │ │ │ │ │ + if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ + features = [features]; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // 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]; │ │ │ │ │ + │ │ │ │ │ + if (this.geometryType && │ │ │ │ │ + !(feature.geometry instanceof this.geometryType)) { │ │ │ │ │ + throw new TypeError('addFeatures: component should be an ' + │ │ │ │ │ + this.geometryType.prototype.CLASS_NAME); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + //give feature reference to its layer │ │ │ │ │ + feature.layer = this; │ │ │ │ │ + │ │ │ │ │ + if (!feature.style && this.style) { │ │ │ │ │ + feature.style = OpenLayers.Util.extend({}, this.style); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (notify) { │ │ │ │ │ + if (this.events.triggerEvent("beforefeatureadded", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }) === false) { │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + this.preFeatureInsert(feature); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + featuresAdded.push(feature); │ │ │ │ │ + this.features.push(feature); │ │ │ │ │ + this.drawFeature(feature); │ │ │ │ │ + │ │ │ │ │ + if (notify) { │ │ │ │ │ + this.events.triggerEvent("featureadded", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ + this.onFeatureInsert(feature); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (notify) { │ │ │ │ │ + this.events.triggerEvent("featuresadded", { │ │ │ │ │ + features: featuresAdded │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: considerSnapping │ │ │ │ │ - * │ │ │ │ │ + * 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: │ │ │ │ │ - * point - {} The vertex to be snapped (or │ │ │ │ │ - * unsnapped). │ │ │ │ │ - * loc - {} The location of the mouse in map │ │ │ │ │ - * coords. │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - considerSnapping: function(point, loc) { │ │ │ │ │ - var best = { │ │ │ │ │ - rank: Number.POSITIVE_INFINITY, │ │ │ │ │ - dist: Number.POSITIVE_INFINITY, │ │ │ │ │ - x: null, │ │ │ │ │ - y: null │ │ │ │ │ - }; │ │ │ │ │ - var snapped = false; │ │ │ │ │ - var result, target; │ │ │ │ │ - for (var i = 0, len = this.targets.length; i < len; ++i) { │ │ │ │ │ - target = this.targets[i]; │ │ │ │ │ - result = this.testTarget(target, loc); │ │ │ │ │ - if (result) { │ │ │ │ │ - if (this.greedy) { │ │ │ │ │ - best = result; │ │ │ │ │ - best.target = target; │ │ │ │ │ - snapped = true; │ │ │ │ │ - break; │ │ │ │ │ - } else { │ │ │ │ │ - if ((result.rank < best.rank) || │ │ │ │ │ - (result.rank === best.rank && result.dist < best.dist)) { │ │ │ │ │ - best = result; │ │ │ │ │ - best.target = target; │ │ │ │ │ - snapped = true; │ │ │ │ │ - } │ │ │ │ │ + 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 │ │ │ │ │ } │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + 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; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var feature = features[i]; │ │ │ │ │ + delete this.unrenderedFeatures[feature.id]; │ │ │ │ │ + │ │ │ │ │ + if (notify) { │ │ │ │ │ + this.events.triggerEvent("beforefeatureremoved", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.features = OpenLayers.Util.removeItem(this.features, feature); │ │ │ │ │ + // feature has no layer at this point │ │ │ │ │ + feature.layer = null; │ │ │ │ │ + │ │ │ │ │ + if (feature.geometry) { │ │ │ │ │ + this.renderer.eraseFeatures(feature); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + //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); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (notify) { │ │ │ │ │ + this.events.triggerEvent("featureremoved", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - if (snapped) { │ │ │ │ │ - var proceed = this.events.triggerEvent("beforesnap", { │ │ │ │ │ - point: point, │ │ │ │ │ - x: best.x, │ │ │ │ │ - y: best.y, │ │ │ │ │ - distance: best.dist, │ │ │ │ │ - layer: best.target.layer, │ │ │ │ │ - snapType: this.precedence[best.rank] │ │ │ │ │ + │ │ │ │ │ + if (notify) { │ │ │ │ │ + this.events.triggerEvent("featuresremoved", { │ │ │ │ │ + features: features │ │ │ │ │ }); │ │ │ │ │ - if (proceed !== false) { │ │ │ │ │ - point.x = best.x; │ │ │ │ │ - point.y = best.y; │ │ │ │ │ - this.point = point; │ │ │ │ │ - this.events.triggerEvent("snap", { │ │ │ │ │ - point: point, │ │ │ │ │ - snapType: this.precedence[best.rank], │ │ │ │ │ - layer: best.target.layer, │ │ │ │ │ - distance: best.dist │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: removeAllFeatures │ │ │ │ │ + * Remove all features from the layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Optional properties for changing behavior of the │ │ │ │ │ + * removal. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * silent - {Boolean} Supress event triggering. Default is false. │ │ │ │ │ + */ │ │ │ │ │ + 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 │ │ │ │ │ }); │ │ │ │ │ - } else { │ │ │ │ │ - snapped = false; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - if (this.point && !snapped) { │ │ │ │ │ - point.x = loc.x; │ │ │ │ │ - point.y = loc.y; │ │ │ │ │ - this.point = null; │ │ │ │ │ - this.events.triggerEvent("unsnap", { │ │ │ │ │ - point: point │ │ │ │ │ + this.renderer.clear(); │ │ │ │ │ + this.features = []; │ │ │ │ │ + this.unrenderedFeatures = {}; │ │ │ │ │ + this.selectedFeatures = []; │ │ │ │ │ + if (notify) { │ │ │ │ │ + this.events.triggerEvent("featuresremoved", { │ │ │ │ │ + features: features │ │ │ │ │ }); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: testTarget │ │ │ │ │ + * APIMethod: destroyFeatures │ │ │ │ │ + * Erase and destroy features on the layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * target - {Object} Object with target layer configuration. │ │ │ │ │ - * loc - {} The location of the mouse in map │ │ │ │ │ - * coords. │ │ │ │ │ + * features - {Array()} An optional array of │ │ │ │ │ + * features to destroy. If not supplied, all features on the layer │ │ │ │ │ + * will be destroyed. │ │ │ │ │ + * options - {Object} │ │ │ │ │ + */ │ │ │ │ │ + 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(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} A result object with rank, dist, x, and y properties. │ │ │ │ │ - * Returns null if candidate is not eligible for snapping. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} │ │ │ │ │ + * style - {String | Object} Named render intent or full symbolizer object. │ │ │ │ │ */ │ │ │ │ │ - testTarget: function(target, loc) { │ │ │ │ │ - var resolution = this.layer.map.getResolution(); │ │ │ │ │ - if ("minResolution" in target) { │ │ │ │ │ - if (resolution < target.minResolution) { │ │ │ │ │ - return null; │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - if ("maxResolution" in target) { │ │ │ │ │ - if (resolution >= target.maxResolution) { │ │ │ │ │ - return null; │ │ │ │ │ + │ │ │ │ │ + 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]; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: eraseFeatures │ │ │ │ │ + * Erase features from the layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * features - {Array()} │ │ │ │ │ + */ │ │ │ │ │ + eraseFeatures: function(features) { │ │ │ │ │ + this.renderer.eraseFeatures(features); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getFeatureFromEvent │ │ │ │ │ + * Given an event, return a feature if the event occurred over one. │ │ │ │ │ + * Otherwise, return null. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A feature if one was under the event. │ │ │ │ │ + */ │ │ │ │ │ + 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.'); │ │ │ │ │ + } │ │ │ │ │ + var feature = null; │ │ │ │ │ + var featureId = this.renderer.getFeatureIdFromEvent(evt); │ │ │ │ │ + if (featureId) { │ │ │ │ │ + if (typeof featureId === "string") { │ │ │ │ │ + feature = this.getFeatureById(featureId); │ │ │ │ │ + } else { │ │ │ │ │ + feature = featureId; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - var tolerance = { │ │ │ │ │ - node: this.getGeoTolerance(target.nodeTolerance, resolution), │ │ │ │ │ - vertex: this.getGeoTolerance(target.vertexTolerance, resolution), │ │ │ │ │ - edge: this.getGeoTolerance(target.edgeTolerance, resolution) │ │ │ │ │ - }; │ │ │ │ │ - // this could be cached if we don't support setting tolerance values directly │ │ │ │ │ - var maxTolerance = Math.max( │ │ │ │ │ - tolerance.node, tolerance.vertex, tolerance.edge │ │ │ │ │ - ); │ │ │ │ │ - var result = { │ │ │ │ │ - rank: Number.POSITIVE_INFINITY, │ │ │ │ │ - dist: Number.POSITIVE_INFINITY │ │ │ │ │ - }; │ │ │ │ │ - var eligible = false; │ │ │ │ │ - var features = target.layer.features; │ │ │ │ │ - var feature, type, vertices, vertex, closest, dist, found; │ │ │ │ │ - var numTypes = this.precedence.length; │ │ │ │ │ - var ll = new OpenLayers.LonLat(loc.x, loc.y); │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - if (feature !== this.feature && !feature._sketch && │ │ │ │ │ - feature.state !== OpenLayers.State.DELETE && │ │ │ │ │ - (!target.filter || target.filter.evaluate(feature))) { │ │ │ │ │ - if (feature.atPoint(ll, maxTolerance, maxTolerance)) { │ │ │ │ │ - for (var j = 0, stop = Math.min(result.rank + 1, numTypes); j < stop; ++j) { │ │ │ │ │ - type = this.precedence[j]; │ │ │ │ │ - if (target[type]) { │ │ │ │ │ - if (type === "edge") { │ │ │ │ │ - closest = feature.geometry.distanceTo(loc, { │ │ │ │ │ - details: true │ │ │ │ │ - }); │ │ │ │ │ - dist = closest.distance; │ │ │ │ │ - if (dist <= tolerance[type] && dist < result.dist) { │ │ │ │ │ - result = { │ │ │ │ │ - rank: j, │ │ │ │ │ - dist: dist, │ │ │ │ │ - x: closest.x0, │ │ │ │ │ - y: closest.y0 // closest coords on feature │ │ │ │ │ - }; │ │ │ │ │ - eligible = true; │ │ │ │ │ - // don't look for lower precedence types for this feature │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // look for nodes or vertices │ │ │ │ │ - vertices = feature.geometry.getVertices(type === "node"); │ │ │ │ │ - found = false; │ │ │ │ │ - for (var k = 0, klen = vertices.length; k < klen; ++k) { │ │ │ │ │ - vertex = vertices[k]; │ │ │ │ │ - dist = vertex.distanceTo(loc); │ │ │ │ │ - if (dist <= tolerance[type] && │ │ │ │ │ - (j < result.rank || (j === result.rank && dist < result.dist))) { │ │ │ │ │ - result = { │ │ │ │ │ - rank: j, │ │ │ │ │ - dist: dist, │ │ │ │ │ - x: vertex.x, │ │ │ │ │ - y: vertex.y │ │ │ │ │ - }; │ │ │ │ │ - eligible = true; │ │ │ │ │ - found = true; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (found) { │ │ │ │ │ - // don't look for lower precedence types for this feature │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + return feature; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getFeatureBy │ │ │ │ │ + * Given a property value, return the feature if it exists in the features array │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * property - {String} │ │ │ │ │ + * value - {String} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A feature corresponding to the given │ │ │ │ │ + * property value or null if there is no such feature. │ │ │ │ │ + */ │ │ │ │ │ + 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]; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return eligible ? result : null; │ │ │ │ │ + return feature; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getGeoTolerance │ │ │ │ │ - * Calculate a tolerance in map units given a tolerance in pixels. This │ │ │ │ │ - * takes advantage of the when the map resolution │ │ │ │ │ - * has not changed. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: getFeatureById │ │ │ │ │ + * Given a feature id, return the feature if it exists in the features array │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * tolerance - {Number} A tolerance value in pixels. │ │ │ │ │ - * resolution - {Number} Map resolution. │ │ │ │ │ + * featureId - {String} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Number} A tolerance value in map units. │ │ │ │ │ + * {} A feature corresponding to the given │ │ │ │ │ + * featureId or null if there is no such feature. │ │ │ │ │ */ │ │ │ │ │ - getGeoTolerance: function(tolerance, resolution) { │ │ │ │ │ - if (resolution !== this.resolution) { │ │ │ │ │ - this.resolution = resolution; │ │ │ │ │ - this.geoToleranceCache = {}; │ │ │ │ │ + getFeatureById: function(featureId) { │ │ │ │ │ + return this.getFeatureBy('id', featureId); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getFeatureByFid │ │ │ │ │ + * Given a feature fid, return the feature if it exists in the features array │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * featureFid - {String} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} A feature corresponding to the given │ │ │ │ │ + * featureFid or null if there is no such feature. │ │ │ │ │ + */ │ │ │ │ │ + getFeatureByFid: function(featureFid) { │ │ │ │ │ + return this.getFeatureBy('fid', featureFid); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * 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. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * attrName - {String} │ │ │ │ │ + * attrValue - {Mixed} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * Array({}) An array of features that have the │ │ │ │ │ + * passed named attribute set to the given value. │ │ │ │ │ + */ │ │ │ │ │ + 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); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - var geoTolerance = this.geoToleranceCache[tolerance]; │ │ │ │ │ - if (geoTolerance === undefined) { │ │ │ │ │ - geoTolerance = tolerance * resolution; │ │ │ │ │ - this.geoToleranceCache[tolerance] = geoTolerance; │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - return geoTolerance; │ │ │ │ │ + this.map.featureSelection = []; │ │ │ │ │ }, │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * Clean up the control. │ │ │ │ │ + * 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 - {} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.deactivate(); // TODO: this should be handled by the super │ │ │ │ │ + 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. │ │ │ │ │ + */ │ │ │ │ │ + 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()); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - delete this.layer; │ │ │ │ │ - delete this.targets; │ │ │ │ │ - OpenLayers.Control.prototype.destroy.call(this); │ │ │ │ │ + return maxExtent; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Snapping" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Layer.Vector" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/MousePosition.js │ │ │ │ │ + OpenLayers/Control/Graticule.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Lang.js │ │ │ │ │ + * @requires OpenLayers/Rule.js │ │ │ │ │ + * @requires OpenLayers/StyleMap.js │ │ │ │ │ + * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.MousePosition │ │ │ │ │ - * The MousePosition control displays geographic coordinates of the mouse │ │ │ │ │ - * pointer, as it is moved about the map. │ │ │ │ │ - * │ │ │ │ │ - * You can use the - or -properties to provide more information │ │ │ │ │ - * about the displayed coordinates to the user: │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * var mousePositionCtrl = new OpenLayers.Control.MousePosition({ │ │ │ │ │ - * prefix: '' + │ │ │ │ │ - * 'EPSG:4326 coordinates: ' │ │ │ │ │ - * } │ │ │ │ │ - * ); │ │ │ │ │ - * (end code) │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Control.Graticule │ │ │ │ │ + * The Graticule displays a grid of latitude/longitude lines reprojected on │ │ │ │ │ + * the map. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.Graticule = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: element │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * APIProperty: intervals │ │ │ │ │ + * {Array(Float)} A list of possible graticule widths in degrees. │ │ │ │ │ */ │ │ │ │ │ - element: null, │ │ │ │ │ + intervals: [45, 30, 20, 10, 5, 2, 1, │ │ │ │ │ + 0.5, 0.2, 0.1, 0.05, 0.01, │ │ │ │ │ + 0.005, 0.002, 0.001 │ │ │ │ │ + ], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: prefix │ │ │ │ │ - * {String} A string to be prepended to the current pointers coordinates │ │ │ │ │ - * when it is rendered. Defaults to the empty string ''. │ │ │ │ │ + * APIProperty: displayInLayerSwitcher │ │ │ │ │ + * {Boolean} Allows the Graticule control to be switched on and off by │ │ │ │ │ + * LayerSwitcher control. Defaults is true. │ │ │ │ │ */ │ │ │ │ │ - prefix: '', │ │ │ │ │ + displayInLayerSwitcher: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: separator │ │ │ │ │ - * {String} A string to be used to seperate the two coordinates from each │ │ │ │ │ - * other. Defaults to the string ', ', which will result in a │ │ │ │ │ - * rendered coordinate of e.g. '42.12, 21.22'. │ │ │ │ │ + * APIProperty: visible │ │ │ │ │ + * {Boolean} should the graticule be initially visible (default=true) │ │ │ │ │ */ │ │ │ │ │ - separator: ', ', │ │ │ │ │ + visible: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: suffix │ │ │ │ │ - * {String} A string to be appended to the current pointers coordinates │ │ │ │ │ - * when it is rendered. Defaults to the empty string ''. │ │ │ │ │ + * APIProperty: numPoints │ │ │ │ │ + * {Integer} The number of points to use in each graticule line. Higher │ │ │ │ │ + * numbers result in a smoother curve for projected maps │ │ │ │ │ */ │ │ │ │ │ - suffix: '', │ │ │ │ │ + numPoints: 50, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: numDigits │ │ │ │ │ - * {Integer} The number of digits each coordinate shall have when being │ │ │ │ │ - * rendered, Defaults to 5. │ │ │ │ │ + * APIProperty: targetSize │ │ │ │ │ + * {Integer} The maximum size of the grid in pixels on the map │ │ │ │ │ */ │ │ │ │ │ - numDigits: 5, │ │ │ │ │ + targetSize: 200, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: granularity │ │ │ │ │ - * {Integer} │ │ │ │ │ + * APIProperty: layerName │ │ │ │ │ + * {String} The name to be displayed in the layer switcher, default is set │ │ │ │ │ + * by {}. │ │ │ │ │ */ │ │ │ │ │ - granularity: 10, │ │ │ │ │ + layerName: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: emptyString │ │ │ │ │ - * {String} Set this to some value to set when the mouse is outside the │ │ │ │ │ - * map. │ │ │ │ │ + * APIProperty: labelled │ │ │ │ │ + * {Boolean} Should the graticule lines be labelled?. default=true │ │ │ │ │ */ │ │ │ │ │ - emptyString: null, │ │ │ │ │ + labelled: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: lastXy │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: labelFormat │ │ │ │ │ + * {String} the format of the labels, default = 'dm'. See │ │ │ │ │ + * for other options. │ │ │ │ │ */ │ │ │ │ │ - lastXy: null, │ │ │ │ │ + labelFormat: 'dm', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displayProjection │ │ │ │ │ - * {} The projection in which the mouse position is │ │ │ │ │ - * displayed. │ │ │ │ │ + * APIProperty: lineSymbolizer │ │ │ │ │ + * {symbolizer} the symbolizer used to render lines │ │ │ │ │ */ │ │ │ │ │ - displayProjection: null, │ │ │ │ │ + lineSymbolizer: { │ │ │ │ │ + strokeColor: "#333", │ │ │ │ │ + strokeWidth: 1, │ │ │ │ │ + strokeOpacity: 0.5 │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.MousePosition │ │ │ │ │ - * │ │ │ │ │ + * APIProperty: labelSymbolizer │ │ │ │ │ + * {symbolizer} the symbolizer used to render labels │ │ │ │ │ + */ │ │ │ │ │ + labelSymbolizer: {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: gratLayer │ │ │ │ │ + * {} vector layer used to draw the graticule on │ │ │ │ │ + */ │ │ │ │ │ + gratLayer: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.Graticule │ │ │ │ │ + * Create a new graticule control to display a grid of latitude longitude │ │ │ │ │ + * lines. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} Options for control. │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + options.layerName = options.layerName || OpenLayers.i18n("Graticule"); │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + │ │ │ │ │ + this.labelSymbolizer.stroke = false; │ │ │ │ │ + this.labelSymbolizer.fill = false; │ │ │ │ │ + this.labelSymbolizer.label = "${label}"; │ │ │ │ │ + this.labelSymbolizer.labelAlign = "${labelAlign}"; │ │ │ │ │ + this.labelSymbolizer.labelXOffset = "${xOffset}"; │ │ │ │ │ + this.labelSymbolizer.labelYOffset = "${yOffset}"; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ this.deactivate(); │ │ │ │ │ OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + if (this.gratLayer) { │ │ │ │ │ + this.gratLayer.destroy(); │ │ │ │ │ + this.gratLayer = null; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * │ │ │ │ │ + * initializes the graticule layer and does the initial update │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIMethod: activate │ │ │ │ │ */ │ │ │ │ │ activate: function() { │ │ │ │ │ if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.map.events.register('mousemove', this, this.redraw); │ │ │ │ │ - this.map.events.register('mouseout', this, this.reset); │ │ │ │ │ - this.redraw(); │ │ │ │ │ + this.map.addLayer(this.gratLayer); │ │ │ │ │ + this.map.events.register('moveend', this, this.update); │ │ │ │ │ + this.update(); │ │ │ │ │ return true; │ │ │ │ │ } else { │ │ │ │ │ return false; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIMethod: deactivate │ │ │ │ │ */ │ │ │ │ │ deactivate: function() { │ │ │ │ │ if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.map.events.unregister('mousemove', this, this.redraw); │ │ │ │ │ - this.map.events.unregister('mouseout', this, this.reset); │ │ │ │ │ - this.element.innerHTML = ""; │ │ │ │ │ + this.map.events.unregister('moveend', this, this.update); │ │ │ │ │ + this.map.removeLayer(this.gratLayer); │ │ │ │ │ return true; │ │ │ │ │ } else { │ │ │ │ │ return false; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * Method: update │ │ │ │ │ + * │ │ │ │ │ + * calculates the grid to be displayed and actually draws it │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - if (!this.element) { │ │ │ │ │ - this.div.left = ""; │ │ │ │ │ - this.div.top = ""; │ │ │ │ │ - this.element = this.div; │ │ │ │ │ + update: function() { │ │ │ │ │ + //wait for the map to be initialized before proceeding │ │ │ │ │ + var mapBounds = this.map.getExtent(); │ │ │ │ │ + if (!mapBounds) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ + //clear out the old grid │ │ │ │ │ + this.gratLayer.destroyFeatures(); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: redraw │ │ │ │ │ - */ │ │ │ │ │ - redraw: function(evt) { │ │ │ │ │ + //get the projection objects required │ │ │ │ │ + var llProj = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ + var mapProj = this.map.getProjectionObject(); │ │ │ │ │ + var mapRes = this.map.getResolution(); │ │ │ │ │ │ │ │ │ │ - var lonLat; │ │ │ │ │ + //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; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (evt == null) { │ │ │ │ │ - this.reset(); │ │ │ │ │ - return; │ │ │ │ │ - } else { │ │ │ │ │ - if (this.lastXy == null || │ │ │ │ │ - Math.abs(evt.xy.x - this.lastXy.x) > this.granularity || │ │ │ │ │ - Math.abs(evt.xy.y - this.lastXy.y) > this.granularity) { │ │ │ │ │ - this.lastXy = evt.xy; │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + //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); │ │ │ │ │ │ │ │ │ │ - lonLat = this.map.getLonLatFromPixel(evt.xy); │ │ │ │ │ - if (!lonLat) { │ │ │ │ │ - // map has not yet been properly initialized │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (this.displayProjection) { │ │ │ │ │ - lonLat.transform(this.map.getProjectionObject(), │ │ │ │ │ - this.displayProjection); │ │ │ │ │ + /* This 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; │ │ │ │ │ } │ │ │ │ │ - this.lastXy = evt.xy; │ │ │ │ │ - │ │ │ │ │ } │ │ │ │ │ + //alert(llInterval); │ │ │ │ │ │ │ │ │ │ - var newHtml = this.formatOutput(lonLat); │ │ │ │ │ + //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? │ │ │ │ │ │ │ │ │ │ - if (newHtml != this.element.innerHTML) { │ │ │ │ │ - this.element.innerHTML = newHtml; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /* 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); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: reset │ │ │ │ │ - */ │ │ │ │ │ - reset: function(evt) { │ │ │ │ │ - if (this.emptyString != null) { │ │ │ │ │ - this.element.innerHTML = this.emptyString; │ │ │ │ │ + //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); │ │ │ │ │ + │ │ │ │ │ + //now generate a line for each node in the central lat and lon lines │ │ │ │ │ + //first loop over constant longitude │ │ │ │ │ + var lines = []; │ │ │ │ │ + for (var i = 0; i < centerLatPoints.length; ++i) { │ │ │ │ │ + var lon = centerLatPoints[i].x; │ │ │ │ │ + var pointList = []; │ │ │ │ │ + var labelPoint = null; │ │ │ │ │ + var latEnd = Math.min(centerLonPoints[0].y, 90); │ │ │ │ │ + var latStart = Math.max(centerLonPoints[centerLonPoints.length - 1].y, -90); │ │ │ │ │ + var latDelta = (latEnd - latStart) / this.numPoints; │ │ │ │ │ + var lat = latStart; │ │ │ │ │ + for (var j = 0; j <= this.numPoints; ++j) { │ │ │ │ │ + var gridPoint = new OpenLayers.Geometry.Point(lon, lat); │ │ │ │ │ + gridPoint.transform(llProj, mapProj); │ │ │ │ │ + pointList.push(gridPoint); │ │ │ │ │ + lat += latDelta; │ │ │ │ │ + if (gridPoint.y >= mapBounds.bottom && !labelPoint) { │ │ │ │ │ + labelPoint = gridPoint; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.labelled) { │ │ │ │ │ + //keep track of when this grid line crosses the map bounds to set │ │ │ │ │ + //the label position │ │ │ │ │ + //labels along the bottom, add 10 pixel offset up into the map │ │ │ │ │ + //TODO add option for labels on top │ │ │ │ │ + var labelPos = new OpenLayers.Geometry.Point(labelPoint.x, mapBounds.bottom); │ │ │ │ │ + var labelAttrs = { │ │ │ │ │ + value: lon, │ │ │ │ │ + label: this.labelled ? OpenLayers.Util.getFormattedLonLat(lon, "lon", this.labelFormat) : "", │ │ │ │ │ + labelAlign: "cb", │ │ │ │ │ + xOffset: 0, │ │ │ │ │ + yOffset: 2 │ │ │ │ │ + }; │ │ │ │ │ + this.gratLayer.addFeatures(new OpenLayers.Feature.Vector(labelPos, labelAttrs)); │ │ │ │ │ + } │ │ │ │ │ + var geom = new OpenLayers.Geometry.LineString(pointList); │ │ │ │ │ + lines.push(new OpenLayers.Feature.Vector(geom)); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: formatOutput │ │ │ │ │ - * Override to provide custom display output │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonLat - {} Location to display │ │ │ │ │ - */ │ │ │ │ │ - formatOutput: function(lonLat) { │ │ │ │ │ - var digits = parseInt(this.numDigits); │ │ │ │ │ - var newHtml = │ │ │ │ │ - this.prefix + │ │ │ │ │ - lonLat.lon.toFixed(digits) + │ │ │ │ │ - this.separator + │ │ │ │ │ - lonLat.lat.toFixed(digits) + │ │ │ │ │ - this.suffix; │ │ │ │ │ - return newHtml; │ │ │ │ │ + //now draw the lines of constant latitude │ │ │ │ │ + for (var j = 0; j < centerLonPoints.length; ++j) { │ │ │ │ │ + lat = centerLonPoints[j].y; │ │ │ │ │ + if (lat < -90 || lat > 90) { //latitudes only valid between -90 and 90 │ │ │ │ │ + continue; │ │ │ │ │ + } │ │ │ │ │ + var pointList = []; │ │ │ │ │ + var lonStart = centerLatPoints[0].x; │ │ │ │ │ + var lonEnd = centerLatPoints[centerLatPoints.length - 1].x; │ │ │ │ │ + var lonDelta = (lonEnd - lonStart) / this.numPoints; │ │ │ │ │ + var lon = lonStart; │ │ │ │ │ + var labelPoint = null; │ │ │ │ │ + for (var i = 0; i <= this.numPoints; ++i) { │ │ │ │ │ + var gridPoint = new OpenLayers.Geometry.Point(lon, lat); │ │ │ │ │ + gridPoint.transform(llProj, mapProj); │ │ │ │ │ + pointList.push(gridPoint); │ │ │ │ │ + lon += lonDelta; │ │ │ │ │ + if (gridPoint.x < mapBounds.right) { │ │ │ │ │ + labelPoint = gridPoint; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.labelled) { │ │ │ │ │ + //keep track of when this grid line crosses the map bounds to set │ │ │ │ │ + //the label position │ │ │ │ │ + //labels along the right, 30 pixel offset left into the map │ │ │ │ │ + //TODO add option for labels on left │ │ │ │ │ + var labelPos = new OpenLayers.Geometry.Point(mapBounds.right, labelPoint.y); │ │ │ │ │ + var labelAttrs = { │ │ │ │ │ + value: lat, │ │ │ │ │ + label: this.labelled ? OpenLayers.Util.getFormattedLonLat(lat, "lat", this.labelFormat) : "", │ │ │ │ │ + labelAlign: "rb", │ │ │ │ │ + xOffset: -2, │ │ │ │ │ + yOffset: 2 │ │ │ │ │ + }; │ │ │ │ │ + this.gratLayer.addFeatures(new OpenLayers.Feature.Vector(labelPos, labelAttrs)); │ │ │ │ │ + } │ │ │ │ │ + var geom = new OpenLayers.Geometry.LineString(pointList); │ │ │ │ │ + lines.push(new OpenLayers.Feature.Vector(geom)); │ │ │ │ │ + } │ │ │ │ │ + this.gratLayer.addFeatures(lines); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.MousePosition" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Graticule" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/NavToolbar.js │ │ │ │ │ + OpenLayers/Handler/Hover.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control/Panel.js │ │ │ │ │ - * @requires OpenLayers/Control/Navigation.js │ │ │ │ │ - * @requires OpenLayers/Control/ZoomBox.js │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.NavToolbar │ │ │ │ │ - * This Toolbar is an alternative to the Navigation control that displays │ │ │ │ │ - * the state of the control, and provides a UI for changing state to │ │ │ │ │ - * use the zoomBox via a Panel control. │ │ │ │ │ - * │ │ │ │ │ - * If you wish to change the properties of the Navigation control used │ │ │ │ │ - * in the NavToolbar, see: │ │ │ │ │ - * http://trac.openlayers.org/wiki/Toolbars#SubclassingNavToolbar │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Handler.Hover │ │ │ │ │ + * The hover handler is to be used to emulate mouseovers on objects │ │ │ │ │ + * on the map that aren't DOM elements. For example one can use │ │ │ │ │ + * this handler to send WMS/GetFeatureInfo requests as the user │ │ │ │ │ + * moves the mouve over the map. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.NavToolbar = OpenLayers.Class(OpenLayers.Control.Panel, { │ │ │ │ │ +OpenLayers.Handler.Hover = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.NavToolbar │ │ │ │ │ - * Add our two mousedefaults controls. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * APIProperty: delay │ │ │ │ │ + * {Integer} - Number of milliseconds between mousemoves before │ │ │ │ │ + * the event is considered a hover. Default is 500. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.addControls([ │ │ │ │ │ - new OpenLayers.Control.Navigation(), │ │ │ │ │ - new OpenLayers.Control.ZoomBox() │ │ │ │ │ - ]); │ │ │ │ │ - }, │ │ │ │ │ + delay: 500, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * calls the default draw, and then activates mouse defaults. │ │ │ │ │ + * APIProperty: pixelTolerance │ │ │ │ │ + * {Integer} - Maximum number of pixels between mousemoves for │ │ │ │ │ + * an event to be considered a hover. Default is null. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (this.defaultControl === null) { │ │ │ │ │ - this.defaultControl = this.controls[0]; │ │ │ │ │ - } │ │ │ │ │ - return div; │ │ │ │ │ - }, │ │ │ │ │ + pixelTolerance: null, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.NavToolbar" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ZoomOut.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: stopMove │ │ │ │ │ + * {Boolean} - Stop other listeners from being notified on mousemoves. │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + stopMove: 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. */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: px │ │ │ │ │ + * {} - The location of the last mousemove, expressed │ │ │ │ │ + * in pixels. │ │ │ │ │ + */ │ │ │ │ │ + px: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control/Button.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Property: timerId │ │ │ │ │ + * {Number} - The id of the timer. │ │ │ │ │ + */ │ │ │ │ │ + timerId: null, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.ZoomOut │ │ │ │ │ - * The ZoomOut control is a button to decrease the zoom level of a map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ZoomOut = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Handler.Hover │ │ │ │ │ + * Construct a hover 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. │ │ │ │ │ + * 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. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: trigger │ │ │ │ │ + * Method: mousemove │ │ │ │ │ + * Called when the mouse moves on the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - trigger: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ + mousemove: function(evt) { │ │ │ │ │ + if (this.passesTolerance(evt.xy)) { │ │ │ │ │ + this.clearTimer(); │ │ │ │ │ + this.callback('move', [evt]); │ │ │ │ │ + this.px = evt.xy; │ │ │ │ │ + // clone the evt so original properties can be accessed even │ │ │ │ │ + // if the browser deletes them during the delay │ │ │ │ │ + evt = OpenLayers.Util.extend({}, evt); │ │ │ │ │ + this.timerId = window.setTimeout( │ │ │ │ │ + OpenLayers.Function.bind(this.delayedCall, this, evt), │ │ │ │ │ + this.delay │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ + return !this.stopMove; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ZoomOut" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ZoomToMaxExtent.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control/Button.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.ZoomToMaxExtent │ │ │ │ │ - * The ZoomToMaxExtent control is a button that zooms out to the maximum │ │ │ │ │ - * extent of the map. It is designed to be used with a │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ZoomToMaxExtent = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: trigger │ │ │ │ │ - * │ │ │ │ │ - * Called whenever this control is being rendered inside of a panel and a │ │ │ │ │ - * click occurs on this controls element. Actually zooms to the maximum │ │ │ │ │ - * extent of this controls map. │ │ │ │ │ + * Method: mouseout │ │ │ │ │ + * Called when the mouse goes out of the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Continue propagating this event. │ │ │ │ │ */ │ │ │ │ │ - trigger: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.zoomToMaxExtent(); │ │ │ │ │ + mouseout: function(evt) { │ │ │ │ │ + if (OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ + this.clearTimer(); │ │ │ │ │ + this.callback('move', [evt]); │ │ │ │ │ } │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ZoomToMaxExtent" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/ZoomPanel.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control/Panel.js │ │ │ │ │ - * @requires OpenLayers/Control/ZoomIn.js │ │ │ │ │ - * @requires OpenLayers/Control/ZoomOut.js │ │ │ │ │ - * @requires OpenLayers/Control/ZoomToMaxExtent.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: passesTolerance │ │ │ │ │ + * Determine whether the mouse move is within the optional pixel tolerance. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * px - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The mouse move is within the pixel tolerance. │ │ │ │ │ + */ │ │ │ │ │ + passesTolerance: function(px) { │ │ │ │ │ + var passes = true; │ │ │ │ │ + if (this.pixelTolerance && this.px) { │ │ │ │ │ + var dpx = Math.sqrt( │ │ │ │ │ + Math.pow(this.px.x - px.x, 2) + │ │ │ │ │ + Math.pow(this.px.y - px.y, 2) │ │ │ │ │ + ); │ │ │ │ │ + if (dpx < this.pixelTolerance) { │ │ │ │ │ + passes = false; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return passes; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.ZoomPanel │ │ │ │ │ - * The ZoomPanel control is a compact collecton of 3 zoom controls: a │ │ │ │ │ - * , a , and a │ │ │ │ │ - * . By default it is drawn in the upper left │ │ │ │ │ - * corner of the map. │ │ │ │ │ - * │ │ │ │ │ - * Note: │ │ │ │ │ - * If you wish to use this class with the default images and you want │ │ │ │ │ - * it to look nice in ie6, you should add the following, conditionally │ │ │ │ │ - * added css stylesheet to your HTML file: │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.ZoomPanel = OpenLayers.Class(OpenLayers.Control.Panel, { │ │ │ │ │ + /** │ │ │ │ │ + * Method: clearTimer │ │ │ │ │ + * Clear the timer and set to null. │ │ │ │ │ + */ │ │ │ │ │ + clearTimer: function() { │ │ │ │ │ + if (this.timerId != null) { │ │ │ │ │ + window.clearTimeout(this.timerId); │ │ │ │ │ + this.timerId = null; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.ZoomPanel │ │ │ │ │ - * Add the three zooming controls. │ │ │ │ │ + * Method: delayedCall │ │ │ │ │ + * Triggers pause callback. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ - this.addControls([ │ │ │ │ │ - new OpenLayers.Control.ZoomIn(), │ │ │ │ │ - new OpenLayers.Control.ZoomToMaxExtent(), │ │ │ │ │ - new OpenLayers.Control.ZoomOut() │ │ │ │ │ - ]); │ │ │ │ │ + delayedCall: function(evt) { │ │ │ │ │ + this.callback('pause', [evt]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.ZoomPanel" │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the handler. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was successfully deactivated. │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = false; │ │ │ │ │ + if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + this.clearTimer(); │ │ │ │ │ + deactivated = true; │ │ │ │ │ + } │ │ │ │ │ + return deactivated; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Hover" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/WMSGetFeatureInfo.js │ │ │ │ │ + OpenLayers/Control/UTFGrid.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published 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/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ + * @requires OpenLayers/Handler/Click.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.WMSGetFeatureInfo │ │ │ │ │ - * Class to read GetFeatureInfo responses from Web Mapping Services │ │ │ │ │ + * Class: OpenLayers.Control.UTFGrid │ │ │ │ │ + * │ │ │ │ │ + * This Control provides behavior associated with UTFGrid Layers. │ │ │ │ │ + * These 'hit grids' provide underlying feature attributes without │ │ │ │ │ + * calling the server (again). This control allows Mousemove, Hovering │ │ │ │ │ + * and Click events to trigger callbacks that use the attributes in │ │ │ │ │ + * whatever way you need. │ │ │ │ │ + * │ │ │ │ │ + * The most common example may be a UTFGrid layer containing feature │ │ │ │ │ + * attributes that are displayed in a div as you mouseover. │ │ │ │ │ + * │ │ │ │ │ + * Example Code: │ │ │ │ │ + * │ │ │ │ │ + * (start code) │ │ │ │ │ + * var world_utfgrid = new OpenLayers.Layer.UTFGrid( │ │ │ │ │ + * 'UTFGrid Layer', │ │ │ │ │ + * "http://tiles/world_utfgrid/${z}/${x}/${y}.json" │ │ │ │ │ + * ); │ │ │ │ │ + * map.addLayer(world_utfgrid); │ │ │ │ │ + * │ │ │ │ │ + * var control = new OpenLayers.Control.UTFGrid({ │ │ │ │ │ + * layers: [world_utfgrid], │ │ │ │ │ + * handlerMode: 'move', │ │ │ │ │ + * callback: function(infoLookup) { │ │ │ │ │ + * // do something with returned data │ │ │ │ │ + * │ │ │ │ │ + * } │ │ │ │ │ + * }) │ │ │ │ │ + * (end code) │ │ │ │ │ + * │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ +OpenLayers.Control.UTFGrid = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layerIdentifier │ │ │ │ │ - * {String} All xml nodes containing this search criteria will populate an │ │ │ │ │ - * internal array of layer nodes. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - layerIdentifier: '_layer', │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: featureIdentifier │ │ │ │ │ - * {String} All xml nodes containing this search criteria will populate an │ │ │ │ │ - * internal array of feature nodes for each layer node found. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: Layers │ │ │ │ │ + * List of layers to consider. Must be Layer.UTFGrids │ │ │ │ │ + * `null` is the default indicating all UTFGrid Layers are queried. │ │ │ │ │ + * {Array} │ │ │ │ │ */ │ │ │ │ │ - featureIdentifier: '_feature', │ │ │ │ │ + layers: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: regExes │ │ │ │ │ - * Compiled regular expressions for manipulating strings. │ │ │ │ │ + /* Property: defaultHandlerOptions │ │ │ │ │ + * The default opts passed to the handler constructors │ │ │ │ │ */ │ │ │ │ │ - regExes: { │ │ │ │ │ - trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ - removeSpace: (/\s*/g), │ │ │ │ │ - splitSpace: (/\s+/), │ │ │ │ │ - trimComma: (/\s*,\s*/g) │ │ │ │ │ + defaultHandlerOptions: { │ │ │ │ │ + 'delay': 300, │ │ │ │ │ + 'pixelTolerance': 4, │ │ │ │ │ + 'stopMove': false, │ │ │ │ │ + 'single': true, │ │ │ │ │ + 'double': false, │ │ │ │ │ + 'stopSingle': false, │ │ │ │ │ + 'stopDouble': false │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: gmlFormat │ │ │ │ │ - * {} internal GML format for parsing geometries │ │ │ │ │ - * in msGMLOutput │ │ │ │ │ + /* APIProperty: handlerMode │ │ │ │ │ + * Defaults to 'click'. Can be 'hover' or 'move'. │ │ │ │ │ */ │ │ │ │ │ - gmlFormat: null, │ │ │ │ │ + handlerMode: 'click', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.WMSGetFeatureInfo │ │ │ │ │ - * Create a new parser for WMS GetFeatureInfo responses │ │ │ │ │ + * APIMethod: setHandler │ │ │ │ │ + * sets this.handlerMode and calls resetHandler() │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * hm - {String} Handler Mode string; 'click', 'hover' or 'move'. │ │ │ │ │ */ │ │ │ │ │ + setHandler: function(hm) { │ │ │ │ │ + this.handlerMode = hm; │ │ │ │ │ + this.resetHandler(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Read WMS GetFeatureInfo data from a string, and return an array of features │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * Method: resetHandler │ │ │ │ │ + * Deactivates the old hanlder and creates a new │ │ │ │ │ + * based on the mode specified in │ │ │ │ │ + * this.handlerMode │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array()} An array of features. │ │ │ │ │ */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - var result; │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ + resetHandler: function() { │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.deactivate(); │ │ │ │ │ + this.handler.destroy(); │ │ │ │ │ + this.handler = null; │ │ │ │ │ } │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ + │ │ │ │ │ + if (this.handlerMode == 'hover') { │ │ │ │ │ + // Handle this event on hover │ │ │ │ │ + this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ + this, { │ │ │ │ │ + 'pause': this.handleEvent, │ │ │ │ │ + 'move': this.reset │ │ │ │ │ + }, │ │ │ │ │ + this.handlerOptions │ │ │ │ │ + ); │ │ │ │ │ + } else if (this.handlerMode == 'click') { │ │ │ │ │ + // Handle this event on click │ │ │ │ │ + this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ + this, { │ │ │ │ │ + 'click': this.handleEvent │ │ │ │ │ + }, this.handlerOptions │ │ │ │ │ + ); │ │ │ │ │ + } else if (this.handlerMode == 'move') { │ │ │ │ │ + this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ + this, │ │ │ │ │ + // Handle this event while hovering OR moving │ │ │ │ │ + { │ │ │ │ │ + 'pause': this.handleEvent, │ │ │ │ │ + 'move': this.handleEvent │ │ │ │ │ + }, │ │ │ │ │ + this.handlerOptions │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + return true; │ │ │ │ │ } else { │ │ │ │ │ - result = data; │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: read_msGMLOutput │ │ │ │ │ - * Parse msGMLOutput nodes. │ │ │ │ │ + * Constructor: │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {DOMElement} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - 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 response; │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + options.handlerOptions = options.handlerOptions || this.defaultHandlerOptions; │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.resetHandler(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: read_FeatureInfoResponse │ │ │ │ │ - * Parse FeatureInfoResponse nodes. │ │ │ │ │ + * Method: handleEvent │ │ │ │ │ + * Internal method called when specified event is triggered. │ │ │ │ │ + * │ │ │ │ │ + * This method does several things: │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * data - {DOMElement} │ │ │ │ │ + * Gets the lonLat of the event. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array} │ │ │ │ │ + * Loops through the appropriate hit grid layers and gathers the attributes. │ │ │ │ │ + * │ │ │ │ │ + * Passes the attributes to the callback │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - read_FeatureInfoResponse: function(data) { │ │ │ │ │ - var response = []; │ │ │ │ │ - var featureNodes = this.getElementsByTagNameNS(data, '*', │ │ │ │ │ - 'FIELDS'); │ │ │ │ │ + handleEvent: function(evt) { │ │ │ │ │ + if (evt == null) { │ │ │ │ │ + this.reset(); │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - for (var i = 0, len = featureNodes.length; i < len; i++) { │ │ │ │ │ - var featureNode = featureNodes[i]; │ │ │ │ │ - var geom = null; │ │ │ │ │ + var lonLat = this.map.getLonLatFromPixel(evt.xy); │ │ │ │ │ + if (!lonLat) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - // 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"); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + 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); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - response.push( │ │ │ │ │ - new OpenLayers.Feature.Vector(geom, attributes, null) │ │ │ │ │ - ); │ │ │ │ │ + this.callback(infoLookup, lonLat, evt.xy); │ │ │ │ │ } │ │ │ │ │ - return response; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: callback │ │ │ │ │ + * Function to be called when a mouse event corresponds with a location that │ │ │ │ │ + * includes data in one of the configured UTFGrid layers. │ │ │ │ │ + * │ │ │ │ │ * 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 │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + callback: function(infoLookup) { │ │ │ │ │ + // to be provided in the constructor │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseAttributes │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An attributes object. │ │ │ │ │ - * │ │ │ │ │ - * Notes: │ │ │ │ │ - * Assumes that attributes are direct child xml nodes of the passed node │ │ │ │ │ - * and contain only a single text node. │ │ │ │ │ + * Method: reset │ │ │ │ │ + * Calls the callback with null. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + reset: function(evt) { │ │ │ │ │ + this.callback(null); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseGeometry │ │ │ │ │ - * Parse the geometry and the feature bounds out of the node using │ │ │ │ │ - * Format.GML │ │ │ │ │ + * 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. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * node - {} │ │ │ │ │ + * None │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} An object containing the geometry and the feature bounds │ │ │ │ │ + * {Array} Layers to handle on each event │ │ │ │ │ */ │ │ │ │ │ - parseGeometry: function(node) { │ │ │ │ │ - // we need to use the old Format.GML parser since we do not know the │ │ │ │ │ - // geometry name │ │ │ │ │ - if (!this.gmlFormat) { │ │ │ │ │ - this.gmlFormat = new OpenLayers.Format.GML(); │ │ │ │ │ - } │ │ │ │ │ - var feature = this.gmlFormat.parseFeature(node); │ │ │ │ │ - var geometry, bounds = null; │ │ │ │ │ - if (feature) { │ │ │ │ │ - geometry = feature.geometry && feature.geometry.clone(); │ │ │ │ │ - bounds = feature.bounds && feature.bounds.clone(); │ │ │ │ │ - feature.destroy(); │ │ │ │ │ + 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 { │ │ │ │ │ - geometry: geometry, │ │ │ │ │ - bounds: bounds │ │ │ │ │ - }; │ │ │ │ │ + return layers; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.WMSGetFeatureInfo" │ │ │ │ │ - │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.UTFGrid" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/WMSGetFeatureInfo.js │ │ │ │ │ + OpenLayers/Control/DrawFeature.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ - * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ - * @requires OpenLayers/Format/WMSGetFeatureInfo.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.WMSGetFeatureInfo │ │ │ │ │ - * The WMSGetFeatureInfo control uses a WMS query to get information about a point on the map. The │ │ │ │ │ - * information may be in a display-friendly format such as HTML, or a machine-friendly format such │ │ │ │ │ - * as GML, depending on the server's capabilities and the client's configuration. This control │ │ │ │ │ - * handles click or hover events, attempts to parse the results using an OpenLayers.Format, and │ │ │ │ │ - * fires a 'getfeatureinfo' event with the click position, the raw body of the response, and an │ │ │ │ │ - * array of features if it successfully read the response. │ │ │ │ │ + * Class: OpenLayers.Control.DrawFeature │ │ │ │ │ + * The DrawFeature control draws point, line or polygon features on a vector │ │ │ │ │ + * layer when active. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.DrawFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: hover │ │ │ │ │ - * {Boolean} Send GetFeatureInfo requests when mouse stops moving. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - hover: false, │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: drillDown │ │ │ │ │ - * {Boolean} Drill down over all WMS layers in the map. When │ │ │ │ │ - * using drillDown mode, hover is not possible, and an infoFormat that │ │ │ │ │ - * returns parseable features is required. Default is false. │ │ │ │ │ + * Property: callbacks │ │ │ │ │ + * {Object} The functions that are sent to the handler for callback │ │ │ │ │ */ │ │ │ │ │ - drillDown: false, │ │ │ │ │ + callbacks: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: maxFeatures │ │ │ │ │ - * {Integer} Maximum number of features to return from a WMS query. This │ │ │ │ │ - * sets the feature_count parameter on WMS GetFeatureInfo │ │ │ │ │ - * requests. │ │ │ │ │ + /** │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - maxFeatures: 10, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: clickCallback │ │ │ │ │ - * {String} The click callback to register in the │ │ │ │ │ - * {} object created when the hover │ │ │ │ │ - * option is set to false. Default is "click". │ │ │ │ │ + * APIProperty: multi │ │ │ │ │ + * {Boolean} Cast features to multi-part geometries before passing to the │ │ │ │ │ + * layer. Default is false. │ │ │ │ │ */ │ │ │ │ │ - clickCallback: "click", │ │ │ │ │ + multi: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: output │ │ │ │ │ - * {String} Either "features" or "object". When triggering a getfeatureinfo │ │ │ │ │ - * request should we pass on an array of features or an object with with │ │ │ │ │ - * a "features" property and other properties (such as the url of the │ │ │ │ │ - * WMS). Default is "features". │ │ │ │ │ + * APIProperty: featureAdded │ │ │ │ │ + * {Function} Called after each feature is added │ │ │ │ │ */ │ │ │ │ │ - output: "features", │ │ │ │ │ + featureAdded: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array()} The layers to query for feature info. │ │ │ │ │ - * If omitted, all map WMS layers with a url that matches this or │ │ │ │ │ - * will be considered. │ │ │ │ │ + * APIProperty: handlerOptions │ │ │ │ │ + * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: queryVisible │ │ │ │ │ - * {Boolean} If true, filter out hidden layers when searching the map for │ │ │ │ │ - * layers to query. Default is false. │ │ │ │ │ + * Constructor: OpenLayers.Control.DrawFeature │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * handler - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - queryVisible: 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); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: url │ │ │ │ │ - * {String} The URL of the WMS service to use. If not provided, the url │ │ │ │ │ - * of the first eligible layer will be used. │ │ │ │ │ + * Method: drawFeature │ │ │ │ │ */ │ │ │ │ │ - url: null, │ │ │ │ │ + drawFeature: function(geometry) { │ │ │ │ │ + var feature = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ + var proceed = this.layer.events.triggerEvent( │ │ │ │ │ + "sketchcomplete", { │ │ │ │ │ + feature: feature │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + if (proceed !== false) { │ │ │ │ │ + feature.state = OpenLayers.State.INSERT; │ │ │ │ │ + this.layer.addFeatures([feature]); │ │ │ │ │ + this.featureAdded(feature); │ │ │ │ │ + this.events.triggerEvent("featureadded", { │ │ │ │ │ + feature: feature │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layerUrls │ │ │ │ │ - * {Array(String)} Optional list of urls for layers that should be queried. │ │ │ │ │ - * This can be used when the layer url differs from the url used for │ │ │ │ │ - * making GetFeatureInfo requests (in the case of a layer using cached │ │ │ │ │ - * tiles). │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - layerUrls: null, │ │ │ │ │ + insertXY: function(x, y) { │ │ │ │ │ + if (this.handler && this.handler.line) { │ │ │ │ │ + this.handler.insertXY(x, y); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: infoFormat │ │ │ │ │ - * {String} The mimetype to request from the server. If you are using │ │ │ │ │ - * drillDown mode and have multiple servers that do not share a common │ │ │ │ │ - * infoFormat, you can override the control's infoFormat by providing an │ │ │ │ │ - * INFO_FORMAT parameter in your instance(s). │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - infoFormat: 'text/html', │ │ │ │ │ + insertDeltaXY: function(dx, dy) { │ │ │ │ │ + if (this.handler && this.handler.line) { │ │ │ │ │ + this.handler.insertDeltaXY(dx, dy); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: vendorParams │ │ │ │ │ - * {Object} Additional parameters that will be added to the request, for │ │ │ │ │ - * WMS implementations that support them. This could e.g. look like │ │ │ │ │ - * (start code) │ │ │ │ │ - * { │ │ │ │ │ - * radius: 5 │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - vendorParams: {}, │ │ │ │ │ + insertDirectionLength: function(direction, length) { │ │ │ │ │ + if (this.handler && this.handler.line) { │ │ │ │ │ + this.handler.insertDirectionLength(direction, length); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: format │ │ │ │ │ - * {} A format for parsing GetFeatureInfo responses. │ │ │ │ │ - * Default is . │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - format: null, │ │ │ │ │ + insertDeflectionLength: function(deflection, length) { │ │ │ │ │ + if (this.handler && this.handler.line) { │ │ │ │ │ + this.handler.insertDeflectionLength(deflection, length); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: formatOptions │ │ │ │ │ - * {Object} Optional properties to set on the format (if one is not provided │ │ │ │ │ - * in the property. │ │ │ │ │ + * APIMethod: undo │ │ │ │ │ + * Remove the most recently added point in the current sketch geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} An edit was undone. │ │ │ │ │ */ │ │ │ │ │ - formatOptions: null, │ │ │ │ │ + undo: function() { │ │ │ │ │ + return this.handler.undo && this.handler.undo(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Additional options for the handlers used by this control, e.g. │ │ │ │ │ - * (start code) │ │ │ │ │ - * { │ │ │ │ │ - * "click": {delay: 100}, │ │ │ │ │ - * "hover": {delay: 300} │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * APIMethod: redo │ │ │ │ │ + * Reinsert the most recently removed point resulting from an call. │ │ │ │ │ + * The undo stack is deleted whenever a point is added by other means. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} An edit was redone. │ │ │ │ │ */ │ │ │ │ │ + redo: function() { │ │ │ │ │ + return this.handler.redo && this.handler.redo(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: handler │ │ │ │ │ - * {Object} Reference to the for this control │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - handler: null, │ │ │ │ │ + finishSketch: function() { │ │ │ │ │ + this.handler.finishGeometry(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: hoverRequest │ │ │ │ │ - * {} contains the currently running hover request │ │ │ │ │ - * (if any). │ │ │ │ │ + * APIMethod: cancel │ │ │ │ │ + * Cancel the current sketch. This removes the current sketch and keeps │ │ │ │ │ + * the drawing control active. │ │ │ │ │ */ │ │ │ │ │ - hoverRequest: null, │ │ │ │ │ + cancel: function() { │ │ │ │ │ + this.handler.cancel(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * beforegetfeatureinfo - Triggered before the request is sent. │ │ │ │ │ - * The event object has an *xy* property with the position of the │ │ │ │ │ - * mouse click or hover event that triggers the request. │ │ │ │ │ - * nogetfeatureinfo - no queryable layers were found. │ │ │ │ │ - * getfeatureinfo - Triggered when a GetFeatureInfo response is received. │ │ │ │ │ - * The event object has a *text* property with the body of the │ │ │ │ │ - * response (String), a *features* property with an array of the │ │ │ │ │ - * parsed features, an *xy* property with the position of the mouse │ │ │ │ │ - * click or hover event that triggered the request, and a *request* │ │ │ │ │ - * property with the request itself. If drillDown is set to true and │ │ │ │ │ - * multiple requests were issued to collect feature info from all │ │ │ │ │ - * layers, *text* and *request* will only contain the response body │ │ │ │ │ - * and request object of the last request. │ │ │ │ │ - */ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.DrawFeature" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Handler/Keyboard.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - options.handlerOptions = options.handlerOptions || {}; │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (!this.format) { │ │ │ │ │ - this.format = new OpenLayers.Format.WMSGetFeatureInfo( │ │ │ │ │ - options.formatOptions │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * 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, { │ │ │ │ │ │ │ │ │ │ - if (this.drillDown === true) { │ │ │ │ │ - this.hover = false; │ │ │ │ │ - } │ │ │ │ │ + /* http://www.quirksmode.org/js/keys.html explains key x-browser │ │ │ │ │ + key handling quirks in pretty nice detail */ │ │ │ │ │ │ │ │ │ │ - if (this.hover) { │ │ │ │ │ - this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ - this, { │ │ │ │ │ - 'move': this.cancelHover, │ │ │ │ │ - 'pause': this.getInfoForHover │ │ │ │ │ - }, │ │ │ │ │ - OpenLayers.Util.extend(this.handlerOptions.hover || {}, { │ │ │ │ │ - 'delay': 250 │ │ │ │ │ - })); │ │ │ │ │ - } else { │ │ │ │ │ - var callbacks = {}; │ │ │ │ │ - callbacks[this.clickCallback] = this.getInfoForClick; │ │ │ │ │ - this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ - this, callbacks, this.handlerOptions.click || {}); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constant: KEY_EVENTS │ │ │ │ │ + * keydown, keypress, keyup │ │ │ │ │ + */ │ │ │ │ │ + KEY_EVENTS: ["keydown", "keyup"], │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: eventListener │ │ │ │ │ + * {Function} │ │ │ │ │ + */ │ │ │ │ │ + eventListener: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getInfoForClick │ │ │ │ │ - * Called on click │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * Property: observeElement │ │ │ │ │ + * {DOMElement|String} The DOM element on which we listen for │ │ │ │ │ + * key events. Default to the document. │ │ │ │ │ */ │ │ │ │ │ - getInfoForClick: function(evt) { │ │ │ │ │ - this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ - xy: evt.xy │ │ │ │ │ - }); │ │ │ │ │ - // Set the cursor to "wait" to tell the user we're working on their │ │ │ │ │ - // click. │ │ │ │ │ - OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - this.request(evt.xy, {}); │ │ │ │ │ - }, │ │ │ │ │ + observeElement: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getInfoForHover │ │ │ │ │ - * Pause callback for the hover handler │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Handler.Keyboard │ │ │ │ │ + * Returns a new keyboard handler. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ + * 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. │ │ │ │ │ */ │ │ │ │ │ - getInfoForHover: function(evt) { │ │ │ │ │ - this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ - xy: evt.xy │ │ │ │ │ - }); │ │ │ │ │ - this.request(evt.xy, { │ │ │ │ │ - hover: true │ │ │ │ │ - }); │ │ │ │ │ + initialize: function(control, callbacks, options) { │ │ │ │ │ + OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ + // cache the bound event listener method so it can be unobserved later │ │ │ │ │ + this.eventListener = OpenLayers.Function.bindAsEventListener( │ │ │ │ │ + this.handleKeyEvent, this │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cancelHover │ │ │ │ │ - * Cancel callback for the hover handler │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ - cancelHover: function() { │ │ │ │ │ - if (this.hoverRequest) { │ │ │ │ │ - this.hoverRequest.abort(); │ │ │ │ │ - this.hoverRequest = null; │ │ │ │ │ - } │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + this.eventListener = null; │ │ │ │ │ + OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: findLayers │ │ │ │ │ - * Internal method to get the layers, independent of whether we are │ │ │ │ │ - * inspecting the map or using a client-provided array │ │ │ │ │ + * Method: activate │ │ │ │ │ */ │ │ │ │ │ - findLayers: function() { │ │ │ │ │ - │ │ │ │ │ - var candidates = this.layers || this.map.layers; │ │ │ │ │ - var layers = []; │ │ │ │ │ - var layer, url; │ │ │ │ │ - for (var i = candidates.length - 1; i >= 0; --i) { │ │ │ │ │ - layer = candidates[i]; │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.WMS && │ │ │ │ │ - (!this.queryVisible || layer.getVisibility())) { │ │ │ │ │ - url = OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url; │ │ │ │ │ - // if the control was not configured with a url, set it │ │ │ │ │ - // to the first layer url │ │ │ │ │ - if (this.drillDown === false && !this.url) { │ │ │ │ │ - this.url = url; │ │ │ │ │ - } │ │ │ │ │ - if (this.drillDown === true || this.urlMatches(url)) { │ │ │ │ │ - layers.push(layer); │ │ │ │ │ - } │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + this.observeElement = this.observeElement || document; │ │ │ │ │ + for (var i = 0, len = this.KEY_EVENTS.length; i < len; i++) { │ │ │ │ │ + OpenLayers.Event.observe( │ │ │ │ │ + this.observeElement, this.KEY_EVENTS[i], this.eventListener); │ │ │ │ │ } │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - return layers; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: urlMatches │ │ │ │ │ - * Test to see if the provided url matches either the control or one │ │ │ │ │ - * of the . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * url - {String} The url to test. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The provided url matches the control or one of the │ │ │ │ │ - * . │ │ │ │ │ + * Method: deactivate │ │ │ │ │ */ │ │ │ │ │ - urlMatches: function(url) { │ │ │ │ │ - var matches = OpenLayers.Util.isEquivalentUrl(this.url, url); │ │ │ │ │ - if (!matches && this.layerUrls) { │ │ │ │ │ - for (var i = 0, len = this.layerUrls.length; i < len; ++i) { │ │ │ │ │ - if (OpenLayers.Util.isEquivalentUrl(this.layerUrls[i], url)) { │ │ │ │ │ - matches = true; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = false; │ │ │ │ │ + if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + for (var i = 0, len = this.KEY_EVENTS.length; i < len; i++) { │ │ │ │ │ + OpenLayers.Event.stopObserving( │ │ │ │ │ + this.observeElement, this.KEY_EVENTS[i], this.eventListener); │ │ │ │ │ } │ │ │ │ │ + deactivated = true; │ │ │ │ │ } │ │ │ │ │ - return matches; │ │ │ │ │ + return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: buildWMSOptions │ │ │ │ │ - * Build an object with the relevant WMS options for the GetFeatureInfo request │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * url - {String} The url to be used for sending the request │ │ │ │ │ - * layers - {Array(} The position on the map where the mouse │ │ │ │ │ - * event occurred. │ │ │ │ │ - * format - {String} The format from the corresponding GetMap request │ │ │ │ │ + * Method: handleKeyEvent │ │ │ │ │ */ │ │ │ │ │ - buildWMSOptions: function(url, layers, clickPosition, format) { │ │ │ │ │ - var layerNames = [], │ │ │ │ │ - styleNames = []; │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - if (layers[i].params.LAYERS != null) { │ │ │ │ │ - layerNames = layerNames.concat(layers[i].params.LAYERS); │ │ │ │ │ - styleNames = styleNames.concat(this.getStyleNames(layers[i])); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var firstLayer = layers[0]; │ │ │ │ │ - // use the firstLayer's projection if it matches the map projection - │ │ │ │ │ - // this assumes that all layers will be available in this projection │ │ │ │ │ - var projection = this.map.getProjection(); │ │ │ │ │ - var layerProj = firstLayer.projection; │ │ │ │ │ - if (layerProj && layerProj.equals(this.map.getProjectionObject())) { │ │ │ │ │ - projection = layerProj.getCode(); │ │ │ │ │ - } │ │ │ │ │ - var params = OpenLayers.Util.extend({ │ │ │ │ │ - service: "WMS", │ │ │ │ │ - version: firstLayer.params.VERSION, │ │ │ │ │ - request: "GetFeatureInfo", │ │ │ │ │ - exceptions: firstLayer.params.EXCEPTIONS, │ │ │ │ │ - bbox: this.map.getExtent().toBBOX(null, │ │ │ │ │ - firstLayer.reverseAxisOrder()), │ │ │ │ │ - feature_count: this.maxFeatures, │ │ │ │ │ - height: this.map.getSize().h, │ │ │ │ │ - width: this.map.getSize().w, │ │ │ │ │ - format: format, │ │ │ │ │ - info_format: firstLayer.params.INFO_FORMAT || this.infoFormat │ │ │ │ │ - }, (parseFloat(firstLayer.params.VERSION) >= 1.3) ? { │ │ │ │ │ - crs: projection, │ │ │ │ │ - i: parseInt(clickPosition.x), │ │ │ │ │ - j: parseInt(clickPosition.y) │ │ │ │ │ - } : { │ │ │ │ │ - srs: projection, │ │ │ │ │ - x: parseInt(clickPosition.x), │ │ │ │ │ - y: parseInt(clickPosition.y) │ │ │ │ │ - }); │ │ │ │ │ - if (layerNames.length != 0) { │ │ │ │ │ - params = OpenLayers.Util.extend({ │ │ │ │ │ - layers: layerNames, │ │ │ │ │ - query_layers: layerNames, │ │ │ │ │ - styles: styleNames │ │ │ │ │ - }, params); │ │ │ │ │ + handleKeyEvent: function(evt) { │ │ │ │ │ + if (this.checkModifiers(evt)) { │ │ │ │ │ + this.callback(evt.type, [evt]); │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Util.applyDefaults(params, this.vendorParams); │ │ │ │ │ - return { │ │ │ │ │ - url: url, │ │ │ │ │ - params: OpenLayers.Util.upperCaseObject(params), │ │ │ │ │ - callback: function(request) { │ │ │ │ │ - this.handleResponse(clickPosition, request, url); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Keyboard" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/KeyboardDefaults.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler/Keyboard.js │ │ │ │ │ + * @requires OpenLayers/Events.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.KeyboardDefaults │ │ │ │ │ + * The KeyboardDefaults control adds panning and zooming functions, controlled │ │ │ │ │ + * with the keyboard. By default arrow keys pan, +/- keys zoom & Page Up/Page │ │ │ │ │ + * Down/Home/End scroll by three quarters of a page. │ │ │ │ │ + * │ │ │ │ │ + * This control has no visible appearance. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: getStyleNames │ │ │ │ │ - * Gets the STYLES parameter for the layer. Make sure the STYLES parameter │ │ │ │ │ - * matches the LAYERS parameter │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array(String)} The STYLES parameter │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - getStyleNames: function(layer) { │ │ │ │ │ - // in the event of a WMS layer bundling multiple layers but not │ │ │ │ │ - // specifying styles,we need the same number of commas to specify │ │ │ │ │ - // the default style for each of the layers. We can't just leave it │ │ │ │ │ - // blank as we may be including other layers that do specify styles. │ │ │ │ │ - var styleNames; │ │ │ │ │ - if (layer.params.STYLES) { │ │ │ │ │ - styleNames = layer.params.STYLES; │ │ │ │ │ - } else { │ │ │ │ │ - if (OpenLayers.Util.isArray(layer.params.LAYERS)) { │ │ │ │ │ - styleNames = new Array(layer.params.LAYERS.length); │ │ │ │ │ - } else { // Assume it's a String │ │ │ │ │ - styleNames = layer.params.LAYERS.replace(/[^,]/g, ""); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return styleNames; │ │ │ │ │ - }, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: request │ │ │ │ │ - * Sends a GetFeatureInfo request to the WMS │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * clickPosition - {} The position on the map where the │ │ │ │ │ - * mouse event occurred. │ │ │ │ │ - * options - {Object} additional options for this method. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * - *hover* {Boolean} true if we do the request for the hover handler │ │ │ │ │ + * APIProperty: slideFactor │ │ │ │ │ + * Pixels to slide by. │ │ │ │ │ */ │ │ │ │ │ - request: function(clickPosition, options) { │ │ │ │ │ - var layers = this.findLayers(); │ │ │ │ │ - if (layers.length == 0) { │ │ │ │ │ - this.events.triggerEvent("nogetfeatureinfo"); │ │ │ │ │ - // Reset the cursor. │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ + slideFactor: 75, │ │ │ │ │ │ │ │ │ │ - options = options || {}; │ │ │ │ │ - if (this.drillDown === false) { │ │ │ │ │ - var wmsOptions = this.buildWMSOptions(this.url, layers, │ │ │ │ │ - clickPosition, layers[0].params.FORMAT); │ │ │ │ │ - var request = OpenLayers.Request.GET(wmsOptions); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: observeElement │ │ │ │ │ + * {DOMelement|String} The DOM element to handle keys for. You │ │ │ │ │ + * can use the map div here, to have the navigation keys │ │ │ │ │ + * work when the map div has the focus. If undefined the │ │ │ │ │ + * document is used. │ │ │ │ │ + */ │ │ │ │ │ + observeElement: null, │ │ │ │ │ │ │ │ │ │ - if (options.hover === true) { │ │ │ │ │ - this.hoverRequest = request; │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - this._requestCount = 0; │ │ │ │ │ - this._numRequests = 0; │ │ │ │ │ - this.features = []; │ │ │ │ │ - // group according to service url to combine requests │ │ │ │ │ - var services = {}, │ │ │ │ │ - url; │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - var layer = layers[i]; │ │ │ │ │ - var service, found = false; │ │ │ │ │ - url = OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url; │ │ │ │ │ - if (url in services) { │ │ │ │ │ - services[url].push(layer); │ │ │ │ │ - } else { │ │ │ │ │ - this._numRequests++; │ │ │ │ │ - services[url] = [layer]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var layers; │ │ │ │ │ - for (var url in services) { │ │ │ │ │ - layers = services[url]; │ │ │ │ │ - var wmsOptions = this.buildWMSOptions(url, layers, │ │ │ │ │ - clickPosition, layers[0].params.FORMAT); │ │ │ │ │ - OpenLayers.Request.GET(wmsOptions); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.KeyboardDefaults │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: triggerGetFeatureInfo │ │ │ │ │ - * Trigger the getfeatureinfo event when all is done │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * request - {XMLHttpRequest} The request object │ │ │ │ │ - * xy - {} The position on the map where the │ │ │ │ │ - * mouse event occurred. │ │ │ │ │ - * features - {Array()} or │ │ │ │ │ - * {Array({Object}) when output is "object". The object has a url and a │ │ │ │ │ - * features property which contains an array of features. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Create handler. │ │ │ │ │ */ │ │ │ │ │ - triggerGetFeatureInfo: function(request, xy, features) { │ │ │ │ │ - this.events.triggerEvent("getfeatureinfo", { │ │ │ │ │ - text: request.responseText, │ │ │ │ │ - features: features, │ │ │ │ │ - request: request, │ │ │ │ │ - xy: xy │ │ │ │ │ + draw: function() { │ │ │ │ │ + var observeElement = this.observeElement || document; │ │ │ │ │ + this.handler = new OpenLayers.Handler.Keyboard(this, { │ │ │ │ │ + "keydown": this.defaultKeyPress │ │ │ │ │ + }, { │ │ │ │ │ + observeElement: observeElement │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ - // Reset the cursor. │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: handleResponse │ │ │ │ │ - * Handler for the GetFeatureInfo response. │ │ │ │ │ + * Method: defaultKeyPress │ │ │ │ │ + * When handling the key event, we only use evt.keyCode. This holds │ │ │ │ │ + * some drawbacks, though we get around them below. When interpretting │ │ │ │ │ + * the keycodes below (including the comments associated with them), │ │ │ │ │ + * consult the URL below. For instance, the Safari browser returns │ │ │ │ │ + * "IE keycodes", and so is supported by any keycode labeled "IE". │ │ │ │ │ + * │ │ │ │ │ + * Very informative URL: │ │ │ │ │ + * http://unixpapa.com/js/key.html │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * xy - {} The position on the map where the │ │ │ │ │ - * mouse event occurred. │ │ │ │ │ - * request - {XMLHttpRequest} The request object. │ │ │ │ │ - * url - {String} The url which was used for this request. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - handleResponse: function(xy, request, url) { │ │ │ │ │ + defaultKeyPress: function(evt) { │ │ │ │ │ + var size, handled = true; │ │ │ │ │ │ │ │ │ │ - var doc = request.responseXML; │ │ │ │ │ - if (!doc || !doc.documentElement) { │ │ │ │ │ - doc = request.responseText; │ │ │ │ │ + var target = OpenLayers.Event.element(evt); │ │ │ │ │ + if (target && │ │ │ │ │ + (target.tagName == 'INPUT' || │ │ │ │ │ + target.tagName == 'TEXTAREA' || │ │ │ │ │ + target.tagName == 'SELECT')) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ - var features = this.format.read(doc); │ │ │ │ │ - if (this.drillDown === false) { │ │ │ │ │ - this.triggerGetFeatureInfo(request, xy, features); │ │ │ │ │ - } else { │ │ │ │ │ - this._requestCount++; │ │ │ │ │ - if (this.output === "object") { │ │ │ │ │ - this._features = (this._features || []).concat({ │ │ │ │ │ - url: url, │ │ │ │ │ - features: features │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - this._features = (this._features || []).concat(features); │ │ │ │ │ - } │ │ │ │ │ - if (this._requestCount === this._numRequests) { │ │ │ │ │ - this.triggerGetFeatureInfo(request, xy, this._features.concat()); │ │ │ │ │ - delete this._features; │ │ │ │ │ - delete this._requestCount; │ │ │ │ │ - delete this._numRequests; │ │ │ │ │ - } │ │ │ │ │ + │ │ │ │ │ + switch (evt.keyCode) { │ │ │ │ │ + case OpenLayers.Event.KEY_LEFT: │ │ │ │ │ + this.map.pan(-this.slideFactor, 0); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Event.KEY_RIGHT: │ │ │ │ │ + this.map.pan(this.slideFactor, 0); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Event.KEY_UP: │ │ │ │ │ + this.map.pan(0, -this.slideFactor); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Event.KEY_DOWN: │ │ │ │ │ + this.map.pan(0, this.slideFactor); │ │ │ │ │ + break; │ │ │ │ │ + │ │ │ │ │ + case 33: // Page Up. Same in all browsers. │ │ │ │ │ + size = this.map.getSize(); │ │ │ │ │ + this.map.pan(0, -0.75 * size.h); │ │ │ │ │ + break; │ │ │ │ │ + case 34: // Page Down. Same in all browsers. │ │ │ │ │ + size = this.map.getSize(); │ │ │ │ │ + this.map.pan(0, 0.75 * size.h); │ │ │ │ │ + break; │ │ │ │ │ + case 35: // End. Same in all browsers. │ │ │ │ │ + size = this.map.getSize(); │ │ │ │ │ + this.map.pan(0.75 * size.w, 0); │ │ │ │ │ + break; │ │ │ │ │ + case 36: // Home. Same in all browsers. │ │ │ │ │ + size = this.map.getSize(); │ │ │ │ │ + this.map.pan(-0.75 * size.w, 0); │ │ │ │ │ + break; │ │ │ │ │ + │ │ │ │ │ + case 43: // +/= (ASCII), keypad + (ASCII, Opera) │ │ │ │ │ + case 61: // +/= (Mozilla, Opera, some ASCII) │ │ │ │ │ + case 187: // +/= (IE) │ │ │ │ │ + case 107: // keypad + (IE, Mozilla) │ │ │ │ │ + this.map.zoomIn(); │ │ │ │ │ + break; │ │ │ │ │ + case 45: // -/_ (ASCII, Opera), keypad - (ASCII, Opera) │ │ │ │ │ + case 109: // -/_ (Mozilla), keypad - (Mozilla, IE) │ │ │ │ │ + case 189: // -/_ (IE) │ │ │ │ │ + case 95: // -/_ (some ASCII) │ │ │ │ │ + this.map.zoomOut(); │ │ │ │ │ + break; │ │ │ │ │ + default: │ │ │ │ │ + handled = false; │ │ │ │ │ + } │ │ │ │ │ + if (handled) { │ │ │ │ │ + // prevent browser default not to move the page │ │ │ │ │ + // when moving the page with the keyboard │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.WMSGetFeatureInfo" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.KeyboardDefaults" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/OverviewMap.js │ │ │ │ │ + OpenLayers/Control/Button.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ +/** │ │ │ │ │ * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/BaseTypes.js │ │ │ │ │ - * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ - * @requires OpenLayers/Map.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.OverviewMap │ │ │ │ │ - * The OverMap control creates a small overview map, useful to display the │ │ │ │ │ - * extent of a zoomed map and your main map and provide additional │ │ │ │ │ - * navigation options to the User. By default the overview map is drawn in │ │ │ │ │ - * the lower right corner of the main map. Create a new overview map with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Control.Button │ │ │ │ │ + * The Button control is a very simple push-button, for use with │ │ │ │ │ + * . │ │ │ │ │ + * When clicked, the function trigger() is executed. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ + * │ │ │ │ │ + * Use: │ │ │ │ │ + * (code) │ │ │ │ │ + * var button = new OpenLayers.Control.Button({ │ │ │ │ │ + * displayClass: "MyButton", trigger: myFunction │ │ │ │ │ + * }); │ │ │ │ │ + * panel.addControls([button]); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Will create a button with CSS class MyButtonItemInactive, that │ │ │ │ │ + * will call the function MyFunction() when clicked. │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ +OpenLayers.Control.Button = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ /** │ │ │ │ │ - * Property: element │ │ │ │ │ - * {DOMElement} The DOM element that contains the overview map │ │ │ │ │ + * Property: type │ │ │ │ │ + * {Integer} OpenLayers.Control.TYPE_BUTTON. │ │ │ │ │ */ │ │ │ │ │ - element: null, │ │ │ │ │ + type: OpenLayers.Control.TYPE_BUTTON, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: ovmap │ │ │ │ │ - * {} A reference to the overview map itself. │ │ │ │ │ + * Method: trigger │ │ │ │ │ + * Called by a control panel when the button is clicked. │ │ │ │ │ */ │ │ │ │ │ - ovmap: null, │ │ │ │ │ + trigger: function() {}, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Button" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/NavigationHistory.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Control/Button.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.NavigationHistory │ │ │ │ │ + * A navigation history control. This is a meta-control, that creates two │ │ │ │ │ + * dependent controls: and . Call the trigger method │ │ │ │ │ + * on the and controls to restore previous and next │ │ │ │ │ + * history states. The previous and next controls will become active │ │ │ │ │ + * when there are available states to restore and will become deactive │ │ │ │ │ + * when there are no states to restore. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: type │ │ │ │ │ + * {String} Note that this control is not intended to be added directly │ │ │ │ │ + * to a control panel. Instead, add the sub-controls previous and │ │ │ │ │ + * next. These sub-controls are button type controls that activate │ │ │ │ │ + * and deactivate themselves. If this parent control is added to │ │ │ │ │ + * a panel, it will act as a toggle. │ │ │ │ │ */ │ │ │ │ │ - size: { │ │ │ │ │ - w: 180, │ │ │ │ │ - h: 90 │ │ │ │ │ - }, │ │ │ │ │ + type: OpenLayers.Control.TYPE_TOGGLE, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: previous │ │ │ │ │ + * {} A button type control whose trigger method restores │ │ │ │ │ + * the previous state managed by this control. │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + previous: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: minRectSize │ │ │ │ │ - * {Integer} The minimum width or height (in pixels) of the extent │ │ │ │ │ - * rectangle on the overview map. When the extent rectangle reaches │ │ │ │ │ - * this size, it will be replaced depending on the value of the │ │ │ │ │ - * property. Default is 15 pixels. │ │ │ │ │ + * APIProperty: previousOptions │ │ │ │ │ + * {Object} Set this property on the options argument of the constructor │ │ │ │ │ + * to set optional properties on the control. │ │ │ │ │ */ │ │ │ │ │ - minRectSize: 15, │ │ │ │ │ + previousOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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) │ │ │ │ │ + * APIProperty: next │ │ │ │ │ + * {} A button type control whose trigger method restores │ │ │ │ │ + * the next state managed by this control. │ │ │ │ │ */ │ │ │ │ │ - minRectDisplayClass: "RectReplacement", │ │ │ │ │ + next: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: nextOptions │ │ │ │ │ + * {Object} Set this property on the options argument of the constructor │ │ │ │ │ + * to set optional properties on the control. │ │ │ │ │ */ │ │ │ │ │ - minRatio: 8, │ │ │ │ │ + nextOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: limit │ │ │ │ │ + * {Integer} Optional limit on the number of history items to retain. If │ │ │ │ │ + * null, there is no limit. Default is 50. │ │ │ │ │ */ │ │ │ │ │ - maxRatio: 32, │ │ │ │ │ + limit: 50, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - mapOptions: null, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Property: clearOnDeactivate │ │ │ │ │ + * {Boolean} Clear the history when the control is deactivated. Default │ │ │ │ │ + * is false. │ │ │ │ │ */ │ │ │ │ │ - autoPan: false, │ │ │ │ │ + clearOnDeactivate: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: handlers │ │ │ │ │ - * {Object} │ │ │ │ │ + * Property: registry │ │ │ │ │ + * {Object} An object with keys corresponding to event types. Values │ │ │ │ │ + * are functions that return an object representing the current state. │ │ │ │ │ */ │ │ │ │ │ - handlers: null, │ │ │ │ │ + registry: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: resolutionFactor │ │ │ │ │ - * {Object} │ │ │ │ │ + * Property: nextStack │ │ │ │ │ + * {Array} Array of items in the history. │ │ │ │ │ */ │ │ │ │ │ - resolutionFactor: 1, │ │ │ │ │ + nextStack: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maximized │ │ │ │ │ - * {Boolean} Start as maximized (visible). Defaults to false. │ │ │ │ │ + * Property: previousStack │ │ │ │ │ + * {Array} List of items in the history. First item represents the current │ │ │ │ │ + * state. │ │ │ │ │ */ │ │ │ │ │ - maximized: false, │ │ │ │ │ + previousStack: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maximizeTitle │ │ │ │ │ - * {String} This property is used for showing a tooltip over the │ │ │ │ │ - * maximize div. Defaults to "" (no title). │ │ │ │ │ + * Property: listeners │ │ │ │ │ + * {Object} An object containing properties corresponding to event types. │ │ │ │ │ + * This object is used to configure the control and is modified on │ │ │ │ │ + * construction. │ │ │ │ │ */ │ │ │ │ │ - maximizeTitle: "", │ │ │ │ │ + listeners: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: minimizeTitle │ │ │ │ │ - * {String} This property is used for showing a tooltip over the │ │ │ │ │ - * minimize div. Defaults to "" (no title). │ │ │ │ │ + * Property: restoring │ │ │ │ │ + * {Boolean} Currently restoring a history state. This is set to true │ │ │ │ │ + * before calling restore and set to false after restore returns. │ │ │ │ │ */ │ │ │ │ │ - minimizeTitle: "", │ │ │ │ │ + restoring: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.OverviewMap │ │ │ │ │ - * Create a new overview map │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Control.NavigationHistory │ │ │ │ │ + * │ │ │ │ │ * 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. │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ - this.layers = []; │ │ │ │ │ - this.handlers = {}; │ │ │ │ │ OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Deconstruct the control │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (!this.mapDiv) { // we've already been destroyed │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (this.handlers.click) { │ │ │ │ │ - this.handlers.click.destroy(); │ │ │ │ │ - } │ │ │ │ │ - if (this.handlers.drag) { │ │ │ │ │ - this.handlers.drag.destroy(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.ovmap && this.ovmap.viewPortDiv.removeChild(this.extentRectangle); │ │ │ │ │ - this.extentRectangle = null; │ │ │ │ │ - │ │ │ │ │ - if (this.rectEvents) { │ │ │ │ │ - this.rectEvents.destroy(); │ │ │ │ │ - this.rectEvents = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.ovmap) { │ │ │ │ │ - this.ovmap.destroy(); │ │ │ │ │ - this.ovmap = null; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.element.removeChild(this.mapDiv); │ │ │ │ │ - this.mapDiv = null; │ │ │ │ │ - │ │ │ │ │ - this.div.removeChild(this.element); │ │ │ │ │ - this.element = null; │ │ │ │ │ │ │ │ │ │ - if (this.maximizeDiv) { │ │ │ │ │ - this.div.removeChild(this.maximizeDiv); │ │ │ │ │ - this.maximizeDiv = null; │ │ │ │ │ - } │ │ │ │ │ + this.registry = OpenLayers.Util.extend({ │ │ │ │ │ + "moveend": this.getState │ │ │ │ │ + }, this.registry); │ │ │ │ │ │ │ │ │ │ - if (this.minimizeDiv) { │ │ │ │ │ - this.div.removeChild(this.minimizeDiv); │ │ │ │ │ - this.minimizeDiv = null; │ │ │ │ │ - } │ │ │ │ │ + var previousOptions = { │ │ │ │ │ + trigger: OpenLayers.Function.bind(this.previousTrigger, this), │ │ │ │ │ + displayClass: this.displayClass + " " + this.displayClass + "Previous" │ │ │ │ │ + }; │ │ │ │ │ + OpenLayers.Util.extend(previousOptions, this.previousOptions); │ │ │ │ │ + this.previous = new OpenLayers.Control.Button(previousOptions); │ │ │ │ │ │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - buttonclick: this.onButtonClick, │ │ │ │ │ - moveend: this.update, │ │ │ │ │ - changebaselayer: this.baseLayerDraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + var nextOptions = { │ │ │ │ │ + trigger: OpenLayers.Function.bind(this.nextTrigger, this), │ │ │ │ │ + displayClass: this.displayClass + " " + this.displayClass + "Next" │ │ │ │ │ + }; │ │ │ │ │ + OpenLayers.Util.extend(nextOptions, this.nextOptions); │ │ │ │ │ + this.next = new OpenLayers.Control.Button(nextOptions); │ │ │ │ │ │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + this.clear(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Render the control in the browser. │ │ │ │ │ + * Method: onPreviousChange │ │ │ │ │ + * Called when the previous history stack changes. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * state - {Object} An object representing the state to be restored │ │ │ │ │ + * if previous is triggered again or null if no previous states remain. │ │ │ │ │ + * length - {Integer} The number of remaining previous states that can │ │ │ │ │ + * be restored. │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (this.layers.length === 0) { │ │ │ │ │ - if (this.map.baseLayer) { │ │ │ │ │ - var layer = this.map.baseLayer.clone(); │ │ │ │ │ - this.layers = [layer]; │ │ │ │ │ - } else { │ │ │ │ │ - this.map.events.register("changebaselayer", this, this.baseLayerDraw); │ │ │ │ │ - return this.div; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // create overview map DOM elements │ │ │ │ │ - this.element = document.createElement('div'); │ │ │ │ │ - this.element.className = this.displayClass + 'Element'; │ │ │ │ │ - this.element.style.display = 'none'; │ │ │ │ │ - │ │ │ │ │ - this.mapDiv = document.createElement('div'); │ │ │ │ │ - this.mapDiv.style.width = this.size.w + 'px'; │ │ │ │ │ - this.mapDiv.style.height = this.size.h + 'px'; │ │ │ │ │ - this.mapDiv.style.position = 'relative'; │ │ │ │ │ - this.mapDiv.style.overflow = 'hidden'; │ │ │ │ │ - this.mapDiv.id = OpenLayers.Util.createUniqueID('overviewMap'); │ │ │ │ │ - │ │ │ │ │ - this.extentRectangle = document.createElement('div'); │ │ │ │ │ - this.extentRectangle.style.position = 'absolute'; │ │ │ │ │ - this.extentRectangle.style.zIndex = 1000; //HACK │ │ │ │ │ - this.extentRectangle.className = this.displayClass + 'ExtentRectangle'; │ │ │ │ │ - │ │ │ │ │ - this.element.appendChild(this.mapDiv); │ │ │ │ │ - │ │ │ │ │ - this.div.appendChild(this.element); │ │ │ │ │ - │ │ │ │ │ - // Optionally add min/max buttons if the control will go in the │ │ │ │ │ - // map viewport. │ │ │ │ │ - if (!this.outsideViewport) { │ │ │ │ │ - this.div.className += " " + this.displayClass + 'Container'; │ │ │ │ │ - // maximize button div │ │ │ │ │ - var img = OpenLayers.Util.getImageLocation('layer-switcher-maximize.png'); │ │ │ │ │ - this.maximizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ - this.displayClass + 'MaximizeButton', │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - img, │ │ │ │ │ - 'absolute'); │ │ │ │ │ - this.maximizeDiv.style.display = 'none'; │ │ │ │ │ - this.maximizeDiv.className = this.displayClass + 'MaximizeButton olButton'; │ │ │ │ │ - if (this.maximizeTitle) { │ │ │ │ │ - this.maximizeDiv.title = this.maximizeTitle; │ │ │ │ │ - } │ │ │ │ │ - this.div.appendChild(this.maximizeDiv); │ │ │ │ │ - │ │ │ │ │ - // minimize button div │ │ │ │ │ - var img = OpenLayers.Util.getImageLocation('layer-switcher-minimize.png'); │ │ │ │ │ - this.minimizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ - 'OpenLayers_Control_minimizeDiv', │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - img, │ │ │ │ │ - 'absolute'); │ │ │ │ │ - this.minimizeDiv.style.display = 'none'; │ │ │ │ │ - this.minimizeDiv.className = this.displayClass + 'MinimizeButton olButton'; │ │ │ │ │ - if (this.minimizeTitle) { │ │ │ │ │ - this.minimizeDiv.title = this.minimizeTitle; │ │ │ │ │ - } │ │ │ │ │ - this.div.appendChild(this.minimizeDiv); │ │ │ │ │ - this.minimizeControl(); │ │ │ │ │ - } else { │ │ │ │ │ - // show the overview map │ │ │ │ │ - this.element.style.display = ''; │ │ │ │ │ - } │ │ │ │ │ - if (this.map.getExtent()) { │ │ │ │ │ - this.update(); │ │ │ │ │ + onPreviousChange: function(state, length) { │ │ │ │ │ + if (state && !this.previous.active) { │ │ │ │ │ + this.previous.activate(); │ │ │ │ │ + } else if (!state && this.previous.active) { │ │ │ │ │ + this.previous.deactivate(); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - buttonclick: this.onButtonClick, │ │ │ │ │ - moveend: this.update, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - if (this.maximized) { │ │ │ │ │ - this.maximizeControl(); │ │ │ │ │ + /** │ │ │ │ │ + * Method: onNextChange │ │ │ │ │ + * Called when the next history stack changes. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * state - {Object} An object representing the state to be restored │ │ │ │ │ + * if next is triggered again or null if no next states remain. │ │ │ │ │ + * length - {Integer} The number of remaining next states that can │ │ │ │ │ + * be restored. │ │ │ │ │ + */ │ │ │ │ │ + onNextChange: function(state, length) { │ │ │ │ │ + if (state && !this.next.active) { │ │ │ │ │ + this.next.activate(); │ │ │ │ │ + } else if (!state && this.next.active) { │ │ │ │ │ + this.next.deactivate(); │ │ │ │ │ } │ │ │ │ │ - return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: baseLayerDraw │ │ │ │ │ - * Draw the base layer - called if unable to complete in the initial draw │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Destroy the control. │ │ │ │ │ */ │ │ │ │ │ - baseLayerDraw: function() { │ │ │ │ │ - this.draw(); │ │ │ │ │ - this.map.events.unregister("changebaselayer", this, this.baseLayerDraw); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this); │ │ │ │ │ + this.previous.destroy(); │ │ │ │ │ + this.next.destroy(); │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + for (var prop in this) { │ │ │ │ │ + this[prop] = null; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: rectDrag │ │ │ │ │ - * Handle extent rectangle drag │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control and and child │ │ │ │ │ + * controls. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * px - {} The pixel location of the drag. │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - 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)); │ │ │ │ │ - } │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.map = map; │ │ │ │ │ + this.next.setMap(map); │ │ │ │ │ + this.previous.setMap(map); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: mapDivClick │ │ │ │ │ - * Handle browser events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} evt │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Called when the control is added to the map. │ │ │ │ │ */ │ │ │ │ │ - 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(); │ │ │ │ │ + draw: function() { │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + this.next.draw(); │ │ │ │ │ + this.previous.draw(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onButtonClick │ │ │ │ │ + * Method: previousTrigger │ │ │ │ │ + * Restore the previous state. If no items are in the previous history │ │ │ │ │ + * stack, this has no effect. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} Item representing state that was restored. Undefined if no │ │ │ │ │ + * items are in the previous history stack. │ │ │ │ │ */ │ │ │ │ │ - onButtonClick: function(evt) { │ │ │ │ │ - if (evt.buttonElement === this.minimizeDiv) { │ │ │ │ │ - this.minimizeControl(); │ │ │ │ │ - } else if (evt.buttonElement === this.maximizeDiv) { │ │ │ │ │ - this.maximizeControl(); │ │ │ │ │ + previousTrigger: function() { │ │ │ │ │ + var current = this.previousStack.shift(); │ │ │ │ │ + var state = this.previousStack.shift(); │ │ │ │ │ + if (state != undefined) { │ │ │ │ │ + this.nextStack.unshift(current); │ │ │ │ │ + this.previousStack.unshift(state); │ │ │ │ │ + this.restoring = true; │ │ │ │ │ + this.restore(state); │ │ │ │ │ + this.restoring = false; │ │ │ │ │ + this.onNextChange(this.nextStack[0], this.nextStack.length); │ │ │ │ │ + this.onPreviousChange( │ │ │ │ │ + this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + this.previousStack.unshift(current); │ │ │ │ │ } │ │ │ │ │ + return state; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: maximizeControl │ │ │ │ │ - * Unhide the control. Called when the control is in the map viewport. │ │ │ │ │ + * APIMethod: nextTrigger │ │ │ │ │ + * Restore the next state. If no items are in the next history │ │ │ │ │ + * stack, this has no effect. The next history stack is populated │ │ │ │ │ + * as states are restored from the previous history stack. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * e - {} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} Item representing state that was restored. Undefined if no │ │ │ │ │ + * items are in the next history stack. │ │ │ │ │ */ │ │ │ │ │ - maximizeControl: function(e) { │ │ │ │ │ - this.element.style.display = ''; │ │ │ │ │ - this.showToggle(false); │ │ │ │ │ - if (e != null) { │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ + nextTrigger: function() { │ │ │ │ │ + var state = this.nextStack.shift(); │ │ │ │ │ + if (state != undefined) { │ │ │ │ │ + this.previousStack.unshift(state); │ │ │ │ │ + this.restoring = true; │ │ │ │ │ + this.restore(state); │ │ │ │ │ + this.restoring = false; │ │ │ │ │ + this.onNextChange(this.nextStack[0], this.nextStack.length); │ │ │ │ │ + this.onPreviousChange( │ │ │ │ │ + this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ + return state; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: minimizeControl │ │ │ │ │ - * Hide all the contents of the control, shrink the size, │ │ │ │ │ - * add the maximize icon │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * e - {} │ │ │ │ │ + * APIMethod: clear │ │ │ │ │ + * Clear history. │ │ │ │ │ */ │ │ │ │ │ - minimizeControl: function(e) { │ │ │ │ │ - this.element.style.display = 'none'; │ │ │ │ │ - this.showToggle(true); │ │ │ │ │ - if (e != null) { │ │ │ │ │ - OpenLayers.Event.stop(e); │ │ │ │ │ - } │ │ │ │ │ + clear: function() { │ │ │ │ │ + this.previousStack = []; │ │ │ │ │ + this.previous.deactivate(); │ │ │ │ │ + this.nextStack = []; │ │ │ │ │ + this.next.deactivate(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: showToggle │ │ │ │ │ - * Hide/Show the toggle depending on whether the control is minimized │ │ │ │ │ + * Method: getState │ │ │ │ │ + * Get the current state and return it. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * minimize - {Boolean} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object representing the current state. │ │ │ │ │ */ │ │ │ │ │ - showToggle: function(minimize) { │ │ │ │ │ - if (this.maximizeDiv) { │ │ │ │ │ - this.maximizeDiv.style.display = minimize ? '' : 'none'; │ │ │ │ │ - } │ │ │ │ │ - if (this.minimizeDiv) { │ │ │ │ │ - this.minimizeDiv.style.display = minimize ? 'none' : ''; │ │ │ │ │ - } │ │ │ │ │ + getState: function() { │ │ │ │ │ + return { │ │ │ │ │ + center: this.map.getCenter(), │ │ │ │ │ + resolution: this.map.getResolution(), │ │ │ │ │ + projection: this.map.getProjectionObject(), │ │ │ │ │ + units: this.map.getProjectionObject().getUnits() || │ │ │ │ │ + this.map.units || this.map.baseLayer.units │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: update │ │ │ │ │ - * Update the overview map after layers move. │ │ │ │ │ + * Method: restore │ │ │ │ │ + * Update the state with the given object. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * state - {Object} An object representing the state to restore. │ │ │ │ │ */ │ │ │ │ │ - update: function() { │ │ │ │ │ - if (this.ovmap == null) { │ │ │ │ │ - this.createMap(); │ │ │ │ │ + restore: function(state) { │ │ │ │ │ + var center, zoom; │ │ │ │ │ + if (this.map.getProjectionObject() == state.projection) { │ │ │ │ │ + zoom = this.map.getZoomForResolution(state.resolution); │ │ │ │ │ + center = state.center; │ │ │ │ │ + } else { │ │ │ │ │ + center = state.center.clone(); │ │ │ │ │ + center.transform(state.projection, this.map.getProjectionObject()); │ │ │ │ │ + var sourceUnits = state.units; │ │ │ │ │ + var targetUnits = this.map.getProjectionObject().getUnits() || │ │ │ │ │ + this.map.units || this.map.baseLayer.units; │ │ │ │ │ + var resolutionFactor = sourceUnits && targetUnits ? │ │ │ │ │ + OpenLayers.INCHES_PER_UNIT[sourceUnits] / OpenLayers.INCHES_PER_UNIT[targetUnits] : 1; │ │ │ │ │ + zoom = this.map.getZoomForResolution(resolutionFactor * state.resolution); │ │ │ │ │ } │ │ │ │ │ + this.map.setCenter(center, zoom); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.autoPan || !this.isSuitableOverview()) { │ │ │ │ │ - this.updateOverview(); │ │ │ │ │ + /** │ │ │ │ │ + * Method: setListeners │ │ │ │ │ + * Sets functions to be registered in the listeners object. │ │ │ │ │ + */ │ │ │ │ │ + setListeners: function() { │ │ │ │ │ + this.listeners = {}; │ │ │ │ │ + for (var type in this.registry) { │ │ │ │ │ + this.listeners[type] = OpenLayers.Function.bind(function() { │ │ │ │ │ + if (!this.restoring) { │ │ │ │ │ + var state = this.registry[type].apply(this, arguments); │ │ │ │ │ + this.previousStack.unshift(state); │ │ │ │ │ + if (this.previousStack.length > 1) { │ │ │ │ │ + this.onPreviousChange( │ │ │ │ │ + this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (this.previousStack.length > (this.limit + 1)) { │ │ │ │ │ + this.previousStack.pop(); │ │ │ │ │ + } │ │ │ │ │ + if (this.nextStack.length > 0) { │ │ │ │ │ + this.nextStack = []; │ │ │ │ │ + this.onNextChange(null, 0); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return true; │ │ │ │ │ + }, this); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // update extent rectangle │ │ │ │ │ - this.updateRectToMap(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: isSuitableOverview │ │ │ │ │ - * Determines if the overview map is suitable given the extent and │ │ │ │ │ - * resolution of the main map. │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Activate the control. This registers any listeners. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Control successfully activated. │ │ │ │ │ */ │ │ │ │ │ - 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()); │ │ │ │ │ + activate: function() { │ │ │ │ │ + var activated = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + if (OpenLayers.Control.prototype.activate.apply(this)) { │ │ │ │ │ + if (this.listeners == null) { │ │ │ │ │ + this.setListeners(); │ │ │ │ │ + } │ │ │ │ │ + for (var type in this.listeners) { │ │ │ │ │ + this.map.events.register(type, this, this.listeners[type]); │ │ │ │ │ + } │ │ │ │ │ + activated = true; │ │ │ │ │ + if (this.previousStack.length == 0) { │ │ │ │ │ + this.initStack(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - var resRatio = this.ovmap.getResolution() / this.map.getResolution(); │ │ │ │ │ - return ((resRatio > this.minRatio) && │ │ │ │ │ - (resRatio <= this.maxRatio) && │ │ │ │ │ - (this.ovmap.getExtent().containsBounds(testExtent))); │ │ │ │ │ + return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method updateOverview │ │ │ │ │ - * Called by if returns true │ │ │ │ │ + * Method: initStack │ │ │ │ │ + * Called after the control is activated if the previous history stack is │ │ │ │ │ + * empty. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + initStack: function() { │ │ │ │ │ + if (this.map.getCenter()) { │ │ │ │ │ + this.listeners.moveend(); │ │ │ │ │ } │ │ │ │ │ - this.ovmap.setCenter(center, this.ovmap.getZoomForResolution( │ │ │ │ │ - targetRes * this.resolutionFactor)); │ │ │ │ │ - this.updateRectToMap(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createMap │ │ │ │ │ - * Construct the map that this control contains │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the control. This unregisters any listeners. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Control successfully deactivated. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = false; │ │ │ │ │ + if (this.map) { │ │ │ │ │ + if (OpenLayers.Control.prototype.deactivate.apply(this)) { │ │ │ │ │ + for (var type in this.listeners) { │ │ │ │ │ + this.map.events.unregister( │ │ │ │ │ + type, this, this.listeners[type] │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (this.clearOnDeactivate) { │ │ │ │ │ + this.clear(); │ │ │ │ │ + } │ │ │ │ │ + deactivated = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return deactivated; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // 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); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.NavigationHistory" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/CacheRead.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - 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(); │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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.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(); │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.CacheRead │ │ │ │ │ + * A control for using image tiles cached with │ │ │ │ │ + * from the browser's local storage. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.CacheRead = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateRectToMap │ │ │ │ │ - * Updates the extent rectangle position and size to match the map extent │ │ │ │ │ + * APIProperty: fetchEvent │ │ │ │ │ + * {String} The layer event to listen to for replacing remote resource tile │ │ │ │ │ + * URLs with cached data URIs. Supported values are "tileerror" (try │ │ │ │ │ + * remote first, fall back to cached) and "tileloadstart" (try cache │ │ │ │ │ + * first, fall back to remote). Default is "tileloadstart". │ │ │ │ │ + * │ │ │ │ │ + * Note that "tileerror" will not work for CORS enabled images (see │ │ │ │ │ + * https://developer.mozilla.org/en/CORS_Enabled_Image), i.e. layers │ │ │ │ │ + * configured with a in │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + fetchEvent: "tileloadstart", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateMapToRect │ │ │ │ │ - * Updates the map extent to match the extent rectangle position and size │ │ │ │ │ + * APIProperty: layers │ │ │ │ │ + * {Array()}. Optional. If provided, only these │ │ │ │ │ + * layers will receive tiles from the cache. │ │ │ │ │ */ │ │ │ │ │ - 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()); │ │ │ │ │ - }, │ │ │ │ │ + layers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setRectPxBounds │ │ │ │ │ - * Set extent rectangle pixel bounds. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ + */ │ │ │ │ │ + autoActivate: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.CacheRead │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pxBounds - {} │ │ │ │ │ + * options - {Object} Object with API properties for this control │ │ │ │ │ */ │ │ │ │ │ - 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'; │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ + */ │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + var i, layers = this.layers || map.layers; │ │ │ │ │ + for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ + this.addLayer({ │ │ │ │ │ + layer: layers[i] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (!this.layers) { │ │ │ │ │ + map.events.on({ │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + removeLayer: this.removeLayer, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - this.rectPxBounds = new OpenLayers.Bounds( │ │ │ │ │ - Math.round(left), Math.round(bottom), │ │ │ │ │ - Math.round(right), Math.round(top) │ │ │ │ │ - ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getRectBoundsFromMapBounds │ │ │ │ │ - * Get the rect bounds from the map bounds. │ │ │ │ │ + * Method: addLayer │ │ │ │ │ + * Adds a layer to the control. Once added, tiles requested for this layer │ │ │ │ │ + * will be cached. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonLatBounds - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {}A bounds which is the passed-in map lon/lat extent │ │ │ │ │ - * translated into pixel bounds for the overview map │ │ │ │ │ + * evt - {Object} Object with a layer property referencing an │ │ │ │ │ + * instance │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + addLayer: function(evt) { │ │ │ │ │ + evt.layer.events.register(this.fetchEvent, this, this.fetch); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getMapBoundsFromRectBounds │ │ │ │ │ - * Get the map bounds from the rect bounds. │ │ │ │ │ + * Method: removeLayer │ │ │ │ │ + * Removes a layer from the control. Once removed, tiles requested for this │ │ │ │ │ + * layer will no longer be cached. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * pxBounds - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} Bounds which is the passed-in overview rect bounds │ │ │ │ │ - * translated into lon/lat bounds for the overview map │ │ │ │ │ + * evt - {Object} Object with a layer property referencing an │ │ │ │ │ + * instance │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ + removeLayer: function(evt) { │ │ │ │ │ + evt.layer.events.unregister(this.fetchEvent, this, this.fetch); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getLonLatFromOverviewPx │ │ │ │ │ - * Get a map location from a pixel location │ │ │ │ │ + * Method: fetch │ │ │ │ │ + * Listener to the event. Replaces a tile's url with a data │ │ │ │ │ + * URI from the cache. │ │ │ │ │ * │ │ │ │ │ * 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. │ │ │ │ │ + * evt - {Object} Event object with a tile property. │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }; │ │ │ │ │ + fetch: function(evt) { │ │ │ │ │ + if (this.active && window.localStorage && │ │ │ │ │ + evt.tile instanceof OpenLayers.Tile.Image) { │ │ │ │ │ + var tile = evt.tile, │ │ │ │ │ + url = tile.url; │ │ │ │ │ + // deal with modified tile urls when both CacheWrite and CacheRead │ │ │ │ │ + // are active │ │ │ │ │ + if (!tile.layer.crossOriginKeyword && OpenLayers.ProxyHost && │ │ │ │ │ + url.indexOf(OpenLayers.ProxyHost) === 0) { │ │ │ │ │ + url = OpenLayers.Control.CacheWrite.urlMap[url]; │ │ │ │ │ + } │ │ │ │ │ + var dataURI = window.localStorage.getItem("olCache_" + url); │ │ │ │ │ + if (dataURI) { │ │ │ │ │ + tile.url = dataURI; │ │ │ │ │ + if (evt.type === "tileerror") { │ │ │ │ │ + tile.setImgSrc(dataURI); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getOverviewPxFromLonLat │ │ │ │ │ - * Get a pixel location from a map location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * lonlat - {|Object} OpenLayers.LonLat or an │ │ │ │ │ - * object with a 'lon' and 'lat' properties. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Location which is the passed-in OpenLayers.LonLat, │ │ │ │ │ - * translated into overview map pixels │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * The destroy method is used to perform any clean up before the control │ │ │ │ │ + * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ + * to prevent memory leaks. │ │ │ │ │ */ │ │ │ │ │ - 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)) │ │ │ │ │ - }; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.layers || this.map) { │ │ │ │ │ + var i, layers = this.layers || this.map.layers; │ │ │ │ │ + for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ + this.removeLayer({ │ │ │ │ │ + layer: layers[i] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + removeLayer: this.removeLayer, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: 'OpenLayers.Control.OverviewMap' │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.CacheRead" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/WMTSGetFeatureInfo.js │ │ │ │ │ + OpenLayers/Control/MousePosition.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ - * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ - * @requires OpenLayers/Format/WMSGetFeatureInfo.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.WMTSGetFeatureInfo │ │ │ │ │ - * The WMTSGetFeatureInfo control uses a WMTS query to get information about a │ │ │ │ │ - * point on the map. The information may be in a display-friendly format │ │ │ │ │ - * such as HTML, or a machine-friendly format such as GML, depending on the │ │ │ │ │ - * server's capabilities and the client's configuration. This control │ │ │ │ │ - * handles click or hover events, attempts to parse the results using an │ │ │ │ │ - * OpenLayers.Format, and fires a 'getfeatureinfo' event for each layer │ │ │ │ │ - * queried. │ │ │ │ │ + * Class: OpenLayers.Control.MousePosition │ │ │ │ │ + * The MousePosition control displays geographic coordinates of the mouse │ │ │ │ │ + * pointer, as it is moved about the map. │ │ │ │ │ + * │ │ │ │ │ + * You can use the - or -properties to provide more information │ │ │ │ │ + * about the displayed coordinates to the user: │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * var mousePositionCtrl = new OpenLayers.Control.MousePosition({ │ │ │ │ │ + * prefix: '' + │ │ │ │ │ + * 'EPSG:4326 coordinates: ' │ │ │ │ │ + * } │ │ │ │ │ + * ); │ │ │ │ │ + * (end code) │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.WMTSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: hover │ │ │ │ │ - * {Boolean} Send GetFeatureInfo requests when mouse stops moving. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - hover: false, │ │ │ │ │ + autoActivate: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: requestEncoding │ │ │ │ │ - * {String} One of "KVP" or "REST". Only KVP encoding is supported at this │ │ │ │ │ - * time. │ │ │ │ │ + * Property: element │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - requestEncoding: "KVP", │ │ │ │ │ + element: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: drillDown │ │ │ │ │ - * {Boolean} Drill down over all WMTS layers in the map. When │ │ │ │ │ - * using drillDown mode, hover is not possible. A getfeatureinfo event │ │ │ │ │ - * will be fired for each layer queried. │ │ │ │ │ + * APIProperty: prefix │ │ │ │ │ + * {String} A string to be prepended to the current pointers coordinates │ │ │ │ │ + * when it is rendered. Defaults to the empty string ''. │ │ │ │ │ */ │ │ │ │ │ - drillDown: false, │ │ │ │ │ + prefix: '', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxFeatures │ │ │ │ │ - * {Integer} Maximum number of features to return from a WMTS query. This │ │ │ │ │ - * sets the feature_count parameter on WMTS GetFeatureInfo │ │ │ │ │ - * requests. │ │ │ │ │ + * APIProperty: separator │ │ │ │ │ + * {String} A string to be used to seperate the two coordinates from each │ │ │ │ │ + * other. Defaults to the string ', ', which will result in a │ │ │ │ │ + * rendered coordinate of e.g. '42.12, 21.22'. │ │ │ │ │ */ │ │ │ │ │ - maxFeatures: 10, │ │ │ │ │ + separator: ', ', │ │ │ │ │ │ │ │ │ │ - /** APIProperty: clickCallback │ │ │ │ │ - * {String} The click callback to register in the │ │ │ │ │ - * {} object created when the hover │ │ │ │ │ - * option is set to false. Default is "click". │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: suffix │ │ │ │ │ + * {String} A string to be appended to the current pointers coordinates │ │ │ │ │ + * when it is rendered. Defaults to the empty string ''. │ │ │ │ │ */ │ │ │ │ │ - clickCallback: "click", │ │ │ │ │ + suffix: '', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layers │ │ │ │ │ - * {Array()} The layers to query for feature info. │ │ │ │ │ - * If omitted, all map WMTS layers will be considered. │ │ │ │ │ + * APIProperty: numDigits │ │ │ │ │ + * {Integer} The number of digits each coordinate shall have when being │ │ │ │ │ + * rendered, Defaults to 5. │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + numDigits: 5, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: queryVisible │ │ │ │ │ - * {Boolean} Filter out hidden layers when searching the map for layers to │ │ │ │ │ - * query. Default is true. │ │ │ │ │ + * APIProperty: granularity │ │ │ │ │ + * {Integer} │ │ │ │ │ */ │ │ │ │ │ - queryVisible: true, │ │ │ │ │ + granularity: 10, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: infoFormat │ │ │ │ │ - * {String} The mimetype to request from the server │ │ │ │ │ + * APIProperty: emptyString │ │ │ │ │ + * {String} Set this to some value to set when the mouse is outside the │ │ │ │ │ + * map. │ │ │ │ │ */ │ │ │ │ │ - infoFormat: 'text/html', │ │ │ │ │ + emptyString: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: vendorParams │ │ │ │ │ - * {Object} Additional parameters that will be added to the request, for │ │ │ │ │ - * WMTS implementations that support them. This could e.g. look like │ │ │ │ │ - * (start code) │ │ │ │ │ - * { │ │ │ │ │ - * radius: 5 │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * Property: lastXy │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - vendorParams: {}, │ │ │ │ │ + lastXy: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: format │ │ │ │ │ - * {} A format for parsing GetFeatureInfo responses. │ │ │ │ │ - * Default is . │ │ │ │ │ + * APIProperty: displayProjection │ │ │ │ │ + * {} The projection in which the mouse position is │ │ │ │ │ + * displayed. │ │ │ │ │ */ │ │ │ │ │ - format: null, │ │ │ │ │ + displayProjection: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: formatOptions │ │ │ │ │ - * {Object} Optional properties to set on the format (if one is not provided │ │ │ │ │ - * in the property. │ │ │ │ │ + * Constructor: OpenLayers.Control.MousePosition │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Options for control. │ │ │ │ │ */ │ │ │ │ │ - formatOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Additional options for the handlers used by this control, e.g. │ │ │ │ │ - * (start code) │ │ │ │ │ - * { │ │ │ │ │ - * "click": {delay: 100}, │ │ │ │ │ - * "hover": {delay: 300} │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: handler │ │ │ │ │ - * {Object} Reference to the for this control │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ */ │ │ │ │ │ - handler: null, │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + this.map.events.register('mousemove', this, this.redraw); │ │ │ │ │ + this.map.events.register('mouseout', this, this.reset); │ │ │ │ │ + this.redraw(); │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: hoverRequest │ │ │ │ │ - * {} contains the currently running hover request │ │ │ │ │ - * (if any). │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ */ │ │ │ │ │ - hoverRequest: null, │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + this.map.events.unregister('mousemove', this, this.redraw); │ │ │ │ │ + this.map.events.unregister('mouseout', this, this.reset); │ │ │ │ │ + this.element.innerHTML = ""; │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * beforegetfeatureinfo - Triggered before each request is sent. │ │ │ │ │ - * The event object has an *xy* property with the position of the │ │ │ │ │ - * mouse click or hover event that triggers the request and a *layer* │ │ │ │ │ - * property referencing the layer about to be queried. If a listener │ │ │ │ │ - * returns false, the request will not be issued. │ │ │ │ │ - * getfeatureinfo - Triggered when a GetFeatureInfo response is received. │ │ │ │ │ - * The event object has a *text* property with the body of the │ │ │ │ │ - * response (String), a *features* property with an array of the │ │ │ │ │ - * parsed features, an *xy* property with the position of the mouse │ │ │ │ │ - * click or hover event that triggered the request, a *layer* property │ │ │ │ │ - * referencing the layer queried and a *request* property with the │ │ │ │ │ - * request itself. If drillDown is set to true, one event will be fired │ │ │ │ │ - * for each layer queried. │ │ │ │ │ - * exception - Triggered when a GetFeatureInfo request fails (with a │ │ │ │ │ - * status other than 200) or whenparsing fails. Listeners will receive │ │ │ │ │ - * an event with *request*, *xy*, and *layer* properties. In the case │ │ │ │ │ - * of a parsing error, the event will also contain an *error* property. │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: pending │ │ │ │ │ - * {Number} The number of pending requests. │ │ │ │ │ - */ │ │ │ │ │ - pending: 0, │ │ │ │ │ + if (!this.element) { │ │ │ │ │ + this.div.left = ""; │ │ │ │ │ + this.div.top = ""; │ │ │ │ │ + this.element = this.div; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return this.div; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * Method: redraw │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - options.handlerOptions = options.handlerOptions || {}; │ │ │ │ │ + redraw: function(evt) { │ │ │ │ │ │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + var lonLat; │ │ │ │ │ + │ │ │ │ │ + if (evt == null) { │ │ │ │ │ + this.reset(); │ │ │ │ │ + return; │ │ │ │ │ + } else { │ │ │ │ │ + if (this.lastXy == null || │ │ │ │ │ + Math.abs(evt.xy.x - this.lastXy.x) > this.granularity || │ │ │ │ │ + Math.abs(evt.xy.y - this.lastXy.y) > this.granularity) { │ │ │ │ │ + this.lastXy = evt.xy; │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + lonLat = this.map.getLonLatFromPixel(evt.xy); │ │ │ │ │ + if (!lonLat) { │ │ │ │ │ + // map has not yet been properly initialized │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + if (this.displayProjection) { │ │ │ │ │ + lonLat.transform(this.map.getProjectionObject(), │ │ │ │ │ + this.displayProjection); │ │ │ │ │ + } │ │ │ │ │ + this.lastXy = evt.xy; │ │ │ │ │ │ │ │ │ │ - if (!this.format) { │ │ │ │ │ - this.format = new OpenLayers.Format.WMSGetFeatureInfo( │ │ │ │ │ - options.formatOptions │ │ │ │ │ - ); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (this.drillDown === true) { │ │ │ │ │ - this.hover = false; │ │ │ │ │ + var newHtml = this.formatOutput(lonLat); │ │ │ │ │ + │ │ │ │ │ + if (newHtml != this.element.innerHTML) { │ │ │ │ │ + this.element.innerHTML = newHtml; │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (this.hover) { │ │ │ │ │ - this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ - this, { │ │ │ │ │ - move: this.cancelHover, │ │ │ │ │ - pause: this.getInfoForHover │ │ │ │ │ - }, │ │ │ │ │ - OpenLayers.Util.extend( │ │ │ │ │ - this.handlerOptions.hover || {}, { │ │ │ │ │ - delay: 250 │ │ │ │ │ - } │ │ │ │ │ - ) │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - var callbacks = {}; │ │ │ │ │ - callbacks[this.clickCallback] = this.getInfoForClick; │ │ │ │ │ - this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ - this, callbacks, this.handlerOptions.click || {} │ │ │ │ │ - ); │ │ │ │ │ + /** │ │ │ │ │ + * Method: reset │ │ │ │ │ + */ │ │ │ │ │ + reset: function(evt) { │ │ │ │ │ + if (this.emptyString != null) { │ │ │ │ │ + this.element.innerHTML = this.emptyString; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getInfoForClick │ │ │ │ │ - * Called on click │ │ │ │ │ + * Method: formatOutput │ │ │ │ │ + * Override to provide custom display output │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * lonLat - {} Location to display │ │ │ │ │ */ │ │ │ │ │ - getInfoForClick: function(evt) { │ │ │ │ │ - this.request(evt.xy, {}); │ │ │ │ │ + formatOutput: function(lonLat) { │ │ │ │ │ + var digits = parseInt(this.numDigits); │ │ │ │ │ + var newHtml = │ │ │ │ │ + this.prefix + │ │ │ │ │ + lonLat.lon.toFixed(digits) + │ │ │ │ │ + this.separator + │ │ │ │ │ + lonLat.lat.toFixed(digits) + │ │ │ │ │ + this.suffix; │ │ │ │ │ + return newHtml; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.MousePosition" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/PanZoom.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.PanZoom │ │ │ │ │ + * The PanZoom is a visible control, composed of a │ │ │ │ │ + * and a . By │ │ │ │ │ + * default it is drawn in the upper left corner of the map. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.PanZoom = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: slideFactor │ │ │ │ │ + * {Integer} Number of pixels by which we'll pan the map in any direction │ │ │ │ │ + * on clicking the arrow buttons. If you want to pan by some ratio │ │ │ │ │ + * of the map dimensions, use instead. │ │ │ │ │ + */ │ │ │ │ │ + slideFactor: 50, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: slideRatio │ │ │ │ │ + * {Number} The fraction of map width/height by which we'll pan the map │ │ │ │ │ + * on clicking the arrow buttons. Default is null. If set, will │ │ │ │ │ + * override . E.g. if slideRatio is .5, then the Pan Up │ │ │ │ │ + * button will pan up half the map height. │ │ │ │ │ + */ │ │ │ │ │ + slideRatio: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: buttons │ │ │ │ │ + * {Array(DOMElement)} Array of Button Divs │ │ │ │ │ + */ │ │ │ │ │ + buttons: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: position │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + position: null, │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: getInfoForHover │ │ │ │ │ - * Pause callback for the hover handler │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Control.PanZoom │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - getInfoForHover: function(evt) { │ │ │ │ │ - this.request(evt.xy, { │ │ │ │ │ - hover: true │ │ │ │ │ - }); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoom.X, │ │ │ │ │ + OpenLayers.Control.PanZoom.Y); │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cancelHover │ │ │ │ │ - * Cancel callback for the hover handler │ │ │ │ │ - */ │ │ │ │ │ - cancelHover: function() { │ │ │ │ │ - if (this.hoverRequest) { │ │ │ │ │ - --this.pending; │ │ │ │ │ - if (this.pending <= 0) { │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - this.pending = 0; │ │ │ │ │ - } │ │ │ │ │ - this.hoverRequest.abort(); │ │ │ │ │ - this.hoverRequest = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: findLayers │ │ │ │ │ - * Internal method to get the layers, independent of whether we are │ │ │ │ │ - * inspecting the map or using a client-provided array │ │ │ │ │ - */ │ │ │ │ │ - findLayers: function() { │ │ │ │ │ - var candidates = this.layers || this.map.layers; │ │ │ │ │ - var layers = []; │ │ │ │ │ - var layer; │ │ │ │ │ - for (var i = candidates.length - 1; i >= 0; --i) { │ │ │ │ │ - layer = candidates[i]; │ │ │ │ │ - if (layer instanceof OpenLayers.Layer.WMTS && │ │ │ │ │ - layer.requestEncoding === this.requestEncoding && │ │ │ │ │ - (!this.queryVisible || layer.getVisibility())) { │ │ │ │ │ - layers.push(layer); │ │ │ │ │ - if (!this.drillDown || this.hover) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return layers; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: buildRequestOptions │ │ │ │ │ - * Build an object with the relevant options for the GetFeatureInfo request. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} A WMTS layer. │ │ │ │ │ - * xy - {} The position on the map where the │ │ │ │ │ - * mouse event occurred. │ │ │ │ │ - */ │ │ │ │ │ - buildRequestOptions: function(layer, xy) { │ │ │ │ │ - var loc = this.map.getLonLatFromPixel(xy); │ │ │ │ │ - var getTileUrl = layer.getURL( │ │ │ │ │ - new OpenLayers.Bounds(loc.lon, loc.lat, loc.lon, loc.lat) │ │ │ │ │ - ); │ │ │ │ │ - var params = OpenLayers.Util.getParameters(getTileUrl); │ │ │ │ │ - var tileInfo = layer.getTileInfo(loc); │ │ │ │ │ - OpenLayers.Util.extend(params, { │ │ │ │ │ - service: "WMTS", │ │ │ │ │ - version: layer.version, │ │ │ │ │ - request: "GetFeatureInfo", │ │ │ │ │ - infoFormat: this.infoFormat, │ │ │ │ │ - i: tileInfo.i, │ │ │ │ │ - j: tileInfo.j │ │ │ │ │ - }); │ │ │ │ │ - OpenLayers.Util.applyDefaults(params, this.vendorParams); │ │ │ │ │ - return { │ │ │ │ │ - url: OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url, │ │ │ │ │ - params: OpenLayers.Util.upperCaseObject(params), │ │ │ │ │ - callback: function(request) { │ │ │ │ │ - this.handleResponse(xy, request, layer); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: request │ │ │ │ │ - * Sends a GetFeatureInfo request to the WMTS │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * xy - {} The position on the map where the mouse event │ │ │ │ │ - * occurred. │ │ │ │ │ - * options - {Object} additional options for this method. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * - *hover* {Boolean} true if we do the request for the hover handler │ │ │ │ │ - */ │ │ │ │ │ - request: function(xy, options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - var layers = this.findLayers(); │ │ │ │ │ - if (layers.length > 0) { │ │ │ │ │ - var issue, layer; │ │ │ │ │ - for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ - layer = layers[i]; │ │ │ │ │ - issue = this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ - xy: xy, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - if (issue !== false) { │ │ │ │ │ - ++this.pending; │ │ │ │ │ - var requestOptions = this.buildRequestOptions(layer, xy); │ │ │ │ │ - var request = OpenLayers.Request.GET(requestOptions); │ │ │ │ │ - if (options.hover === true) { │ │ │ │ │ - this.hoverRequest = request; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.pending > 0) { │ │ │ │ │ - OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleResponse │ │ │ │ │ - * Handler for the GetFeatureInfo response. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * xy - {} The position on the map where the mouse event │ │ │ │ │ - * occurred. │ │ │ │ │ - * request - {XMLHttpRequest} The request object. │ │ │ │ │ - * layer - {} The queried layer. │ │ │ │ │ - */ │ │ │ │ │ - handleResponse: function(xy, request, layer) { │ │ │ │ │ - --this.pending; │ │ │ │ │ - if (this.pending <= 0) { │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - this.pending = 0; │ │ │ │ │ - } │ │ │ │ │ - if (request.status && (request.status < 200 || request.status >= 300)) { │ │ │ │ │ - this.events.triggerEvent("exception", { │ │ │ │ │ - xy: xy, │ │ │ │ │ - request: request, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - var doc = request.responseXML; │ │ │ │ │ - if (!doc || !doc.documentElement) { │ │ │ │ │ - doc = request.responseText; │ │ │ │ │ - } │ │ │ │ │ - var features, except; │ │ │ │ │ - try { │ │ │ │ │ - features = this.format.read(doc); │ │ │ │ │ - } catch (error) { │ │ │ │ │ - except = true; │ │ │ │ │ - this.events.triggerEvent("exception", { │ │ │ │ │ - xy: xy, │ │ │ │ │ - request: request, │ │ │ │ │ - error: error, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (!except) { │ │ │ │ │ - this.events.triggerEvent("getfeatureinfo", { │ │ │ │ │ - text: request.responseText, │ │ │ │ │ - features: features, │ │ │ │ │ - request: request, │ │ │ │ │ - xy: xy, │ │ │ │ │ - layer: layer │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.WMTSGetFeatureInfo" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/PanZoom.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.PanZoom │ │ │ │ │ - * The PanZoom is a visible control, composed of a │ │ │ │ │ - * and a . By │ │ │ │ │ - * default it is drawn in the upper left corner of the map. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.PanZoom = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: slideFactor │ │ │ │ │ - * {Integer} Number of pixels by which we'll pan the map in any direction │ │ │ │ │ - * on clicking the arrow buttons. If you want to pan by some ratio │ │ │ │ │ - * of the map dimensions, use instead. │ │ │ │ │ - */ │ │ │ │ │ - slideFactor: 50, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: slideRatio │ │ │ │ │ - * {Number} The fraction of map width/height by which we'll pan the map │ │ │ │ │ - * on clicking the arrow buttons. Default is null. If set, will │ │ │ │ │ - * override . E.g. if slideRatio is .5, then the Pan Up │ │ │ │ │ - * button will pan up half the map height. │ │ │ │ │ - */ │ │ │ │ │ - slideRatio: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: buttons │ │ │ │ │ - * {Array(DOMElement)} Array of Button Divs │ │ │ │ │ - */ │ │ │ │ │ - buttons: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: position │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - position: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.PanZoom │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoom.X, │ │ │ │ │ - OpenLayers.Control.PanZoom.Y); │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ if (this.map) { │ │ │ │ │ this.map.events.unregister("buttonclick", this, this.onButtonClick); │ │ │ │ │ } │ │ │ │ │ this.removeButtons(); │ │ │ │ │ this.buttons = null; │ │ │ │ │ @@ -45689,3621 +38480,4096 @@ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Constant: Y │ │ │ │ │ * {Integer} │ │ │ │ │ */ │ │ │ │ │ OpenLayers.Control.PanZoom.Y = 4; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/CacheRead.js │ │ │ │ │ + OpenLayers/Control/PanZoomBar.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Control/PanZoom.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.CacheRead │ │ │ │ │ - * A control for using image tiles cached with │ │ │ │ │ - * from the browser's local storage. │ │ │ │ │ + * Class: OpenLayers.Control.PanZoomBar │ │ │ │ │ + * The PanZoomBar is a visible control composed of a │ │ │ │ │ + * and a . │ │ │ │ │ + * By default it is displayed in the upper left corner of the map as 4 │ │ │ │ │ + * directional arrows above a vertical slider. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.CacheRead = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomStopWidth │ │ │ │ │ + */ │ │ │ │ │ + zoomStopWidth: 18, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomStopHeight │ │ │ │ │ + */ │ │ │ │ │ + zoomStopHeight: 11, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: slider │ │ │ │ │ + */ │ │ │ │ │ + slider: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: sliderEvents │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + sliderEvents: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoombarDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + zoombarDiv: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomWorldIcon │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + zoomWorldIcon: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: fetchEvent │ │ │ │ │ - * {String} The layer event to listen to for replacing remote resource tile │ │ │ │ │ - * URLs with cached data URIs. Supported values are "tileerror" (try │ │ │ │ │ - * remote first, fall back to cached) and "tileloadstart" (try cache │ │ │ │ │ - * first, fall back to remote). Default is "tileloadstart". │ │ │ │ │ - * │ │ │ │ │ - * Note that "tileerror" will not work for CORS enabled images (see │ │ │ │ │ - * https://developer.mozilla.org/en/CORS_Enabled_Image), i.e. layers │ │ │ │ │ - * configured with a in │ │ │ │ │ - * . │ │ │ │ │ + * APIProperty: panIcons │ │ │ │ │ + * {Boolean} Set this property to false not to display the pan icons. If │ │ │ │ │ + * false the zoom world icon is placed under the zoom bar. Defaults to │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - fetchEvent: "tileloadstart", │ │ │ │ │ + panIcons: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array()}. Optional. If provided, only these │ │ │ │ │ - * layers will receive tiles from the cache. │ │ │ │ │ + * APIProperty: forceFixedZoomLevel │ │ │ │ │ + * {Boolean} Force a fixed zoom level even though the map has │ │ │ │ │ + * fractionalZoom │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + forceFixedZoomLevel: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * Property: mouseDragStart │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + mouseDragStart: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.CacheRead │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Object with API properties for this control │ │ │ │ │ + * Property: deltaY │ │ │ │ │ + * {Number} The cumulative vertical pixel offset during a zoom bar drag. │ │ │ │ │ */ │ │ │ │ │ + deltaY: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoomStart │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + zoomStart: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.PanZoomBar │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + │ │ │ │ │ + this._removeZoomBar(); │ │ │ │ │ + │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + "changebaselayer": this.redraw, │ │ │ │ │ + "updatesize": this.redraw, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Control.PanZoom.prototype.destroy.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + delete this.mouseDragStart; │ │ │ │ │ + delete this.zoomStart; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ * Method: setMap │ │ │ │ │ - * Set the map property for the control. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ * map - {} │ │ │ │ │ */ │ │ │ │ │ setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - var i, layers = this.layers || map.layers; │ │ │ │ │ - for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ - this.addLayer({ │ │ │ │ │ - layer: layers[i] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (!this.layers) { │ │ │ │ │ - map.events.on({ │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - removeLayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ + OpenLayers.Control.PanZoom.prototype.setMap.apply(this, arguments); │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + "changebaselayer": this.redraw, │ │ │ │ │ + "updatesize": this.redraw, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: redraw │ │ │ │ │ + * clear the div and start over. │ │ │ │ │ + */ │ │ │ │ │ + redraw: function() { │ │ │ │ │ + if (this.div != null) { │ │ │ │ │ + this.removeButtons(); │ │ │ │ │ + this._removeZoomBar(); │ │ │ │ │ } │ │ │ │ │ + this.draw(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addLayer │ │ │ │ │ - * Adds a layer to the control. Once added, tiles requested for this layer │ │ │ │ │ - * will be cached. │ │ │ │ │ + * Method: draw │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Object with a layer property referencing an │ │ │ │ │ - * instance │ │ │ │ │ + * px - {} │ │ │ │ │ */ │ │ │ │ │ - addLayer: function(evt) { │ │ │ │ │ - evt.layer.events.register(this.fetchEvent, this, this.fetch); │ │ │ │ │ + draw: function(px) { │ │ │ │ │ + // initialize our internal div │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + px = this.position.clone(); │ │ │ │ │ + │ │ │ │ │ + // place the controls │ │ │ │ │ + this.buttons = []; │ │ │ │ │ + │ │ │ │ │ + var sz = { │ │ │ │ │ + w: 18, │ │ │ │ │ + h: 18 │ │ │ │ │ + }; │ │ │ │ │ + if (this.panIcons) { │ │ │ │ │ + var centered = new OpenLayers.Pixel(px.x + sz.w / 2, px.y); │ │ │ │ │ + var wposition = sz.w; │ │ │ │ │ + │ │ │ │ │ + if (this.zoomWorldIcon) { │ │ │ │ │ + centered = new OpenLayers.Pixel(px.x + sz.w, px.y); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this._addButton("panup", "north-mini.png", centered, sz); │ │ │ │ │ + px.y = centered.y + sz.h; │ │ │ │ │ + this._addButton("panleft", "west-mini.png", px, sz); │ │ │ │ │ + if (this.zoomWorldIcon) { │ │ │ │ │ + this._addButton("zoomworld", "zoom-world-mini.png", px.add(sz.w, 0), sz); │ │ │ │ │ + │ │ │ │ │ + wposition *= 2; │ │ │ │ │ + } │ │ │ │ │ + this._addButton("panright", "east-mini.png", px.add(wposition, 0), sz); │ │ │ │ │ + this._addButton("pandown", "south-mini.png", centered.add(0, sz.h * 2), sz); │ │ │ │ │ + this._addButton("zoomin", "zoom-plus-mini.png", centered.add(0, sz.h * 3 + 5), sz); │ │ │ │ │ + centered = this._addZoomBar(centered.add(0, sz.h * 4 + 5)); │ │ │ │ │ + this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); │ │ │ │ │ + } else { │ │ │ │ │ + this._addButton("zoomin", "zoom-plus-mini.png", px, sz); │ │ │ │ │ + centered = this._addZoomBar(px.add(0, sz.h)); │ │ │ │ │ + this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); │ │ │ │ │ + if (this.zoomWorldIcon) { │ │ │ │ │ + centered = centered.add(0, sz.h + 3); │ │ │ │ │ + this._addButton("zoomworld", "zoom-world-mini.png", centered, sz); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeLayer │ │ │ │ │ - * Removes a layer from the control. Once removed, tiles requested for this │ │ │ │ │ - * layer will no longer be cached. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: _addZoomBar │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Object with a layer property referencing an │ │ │ │ │ - * instance │ │ │ │ │ + * centered - {} where zoombar drawing is to start. │ │ │ │ │ */ │ │ │ │ │ - removeLayer: function(evt) { │ │ │ │ │ - evt.layer.events.unregister(this.fetchEvent, this, this.fetch); │ │ │ │ │ + _addZoomBar: function(centered) { │ │ │ │ │ + var imgLocation = OpenLayers.Util.getImageLocation("slider.png"); │ │ │ │ │ + var id = this.id + "_" + this.map.id; │ │ │ │ │ + var minZoom = this.map.getMinZoom(); │ │ │ │ │ + var zoomsToEnd = this.map.getNumZoomLevels() - 1 - this.map.getZoom(); │ │ │ │ │ + var slider = OpenLayers.Util.createAlphaImageDiv(id, │ │ │ │ │ + centered.add(-1, zoomsToEnd * this.zoomStopHeight), { │ │ │ │ │ + w: 20, │ │ │ │ │ + h: 9 │ │ │ │ │ + }, │ │ │ │ │ + imgLocation, │ │ │ │ │ + "absolute"); │ │ │ │ │ + slider.style.cursor = "move"; │ │ │ │ │ + this.slider = slider; │ │ │ │ │ + │ │ │ │ │ + this.sliderEvents = new OpenLayers.Events(this, slider, null, true, { │ │ │ │ │ + includeXY: true │ │ │ │ │ + }); │ │ │ │ │ + this.sliderEvents.on({ │ │ │ │ │ + "touchstart": this.zoomBarDown, │ │ │ │ │ + "touchmove": this.zoomBarDrag, │ │ │ │ │ + "touchend": this.zoomBarUp, │ │ │ │ │ + "mousedown": this.zoomBarDown, │ │ │ │ │ + "mousemove": this.zoomBarDrag, │ │ │ │ │ + "mouseup": this.zoomBarUp │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + var sz = { │ │ │ │ │ + w: this.zoomStopWidth, │ │ │ │ │ + h: this.zoomStopHeight * (this.map.getNumZoomLevels() - minZoom) │ │ │ │ │ + }; │ │ │ │ │ + var imgLocation = OpenLayers.Util.getImageLocation("zoombar.png"); │ │ │ │ │ + var div = null; │ │ │ │ │ + │ │ │ │ │ + if (OpenLayers.Util.alphaHack()) { │ │ │ │ │ + var id = this.id + "_" + this.map.id; │ │ │ │ │ + div = OpenLayers.Util.createAlphaImageDiv(id, centered, { │ │ │ │ │ + w: sz.w, │ │ │ │ │ + h: this.zoomStopHeight │ │ │ │ │ + }, │ │ │ │ │ + imgLocation, │ │ │ │ │ + "absolute", null, "crop"); │ │ │ │ │ + div.style.height = sz.h + "px"; │ │ │ │ │ + } else { │ │ │ │ │ + div = OpenLayers.Util.createDiv( │ │ │ │ │ + 'OpenLayers_Control_PanZoomBar_Zoombar' + this.map.id, │ │ │ │ │ + centered, │ │ │ │ │ + sz, │ │ │ │ │ + imgLocation); │ │ │ │ │ + } │ │ │ │ │ + div.style.cursor = "pointer"; │ │ │ │ │ + div.className = "olButton"; │ │ │ │ │ + this.zoombarDiv = div; │ │ │ │ │ + │ │ │ │ │ + this.div.appendChild(div); │ │ │ │ │ + │ │ │ │ │ + this.startTop = parseInt(div.style.top); │ │ │ │ │ + this.div.appendChild(slider); │ │ │ │ │ + │ │ │ │ │ + this.map.events.register("zoomend", this, this.moveZoomBar); │ │ │ │ │ + │ │ │ │ │ + centered = centered.add(0, │ │ │ │ │ + this.zoomStopHeight * (this.map.getNumZoomLevels() - minZoom)); │ │ │ │ │ + return centered; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: fetch │ │ │ │ │ - * Listener to the event. Replaces a tile's url with a data │ │ │ │ │ - * URI from the cache. │ │ │ │ │ + * Method: _removeZoomBar │ │ │ │ │ + */ │ │ │ │ │ + _removeZoomBar: function() { │ │ │ │ │ + this.sliderEvents.un({ │ │ │ │ │ + "touchstart": this.zoomBarDown, │ │ │ │ │ + "touchmove": this.zoomBarDrag, │ │ │ │ │ + "touchend": this.zoomBarUp, │ │ │ │ │ + "mousedown": this.zoomBarDown, │ │ │ │ │ + "mousemove": this.zoomBarDrag, │ │ │ │ │ + "mouseup": this.zoomBarUp │ │ │ │ │ + }); │ │ │ │ │ + this.sliderEvents.destroy(); │ │ │ │ │ + │ │ │ │ │ + this.div.removeChild(this.zoombarDiv); │ │ │ │ │ + this.zoombarDiv = null; │ │ │ │ │ + this.div.removeChild(this.slider); │ │ │ │ │ + this.slider = null; │ │ │ │ │ + │ │ │ │ │ + this.map.events.unregister("zoomend", this, this.moveZoomBar); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: onButtonClick │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Event object with a tile property. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - fetch: function(evt) { │ │ │ │ │ - if (this.active && window.localStorage && │ │ │ │ │ - evt.tile instanceof OpenLayers.Tile.Image) { │ │ │ │ │ - var tile = evt.tile, │ │ │ │ │ - url = tile.url; │ │ │ │ │ - // deal with modified tile urls when both CacheWrite and CacheRead │ │ │ │ │ - // are active │ │ │ │ │ - if (!tile.layer.crossOriginKeyword && OpenLayers.ProxyHost && │ │ │ │ │ - url.indexOf(OpenLayers.ProxyHost) === 0) { │ │ │ │ │ - url = OpenLayers.Control.CacheWrite.urlMap[url]; │ │ │ │ │ - } │ │ │ │ │ - var dataURI = window.localStorage.getItem("olCache_" + url); │ │ │ │ │ - if (dataURI) { │ │ │ │ │ - tile.url = dataURI; │ │ │ │ │ - if (evt.type === "tileerror") { │ │ │ │ │ - tile.setImgSrc(dataURI); │ │ │ │ │ - } │ │ │ │ │ + onButtonClick: function(evt) { │ │ │ │ │ + OpenLayers.Control.PanZoom.prototype.onButtonClick.apply(this, arguments); │ │ │ │ │ + if (evt.buttonElement === this.zoombarDiv) { │ │ │ │ │ + var levels = evt.buttonXY.y / this.zoomStopHeight; │ │ │ │ │ + if (this.forceFixedZoomLevel || !this.map.fractionalZoom) { │ │ │ │ │ + levels = Math.floor(levels); │ │ │ │ │ } │ │ │ │ │ + var zoom = (this.map.getNumZoomLevels() - 1) - levels; │ │ │ │ │ + zoom = Math.min(Math.max(zoom, 0), this.map.getNumZoomLevels() - 1); │ │ │ │ │ + this.map.zoomTo(zoom); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * The destroy method is used to perform any clean up before the control │ │ │ │ │ - * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ - * to prevent memory leaks. │ │ │ │ │ + * Method: passEventToSlider │ │ │ │ │ + * This function is used to pass events that happen on the div, or the map, │ │ │ │ │ + * through to the slider, which then does its moving thing. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.layers || this.map) { │ │ │ │ │ - var i, layers = this.layers || this.map.layers; │ │ │ │ │ - for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ - this.removeLayer({ │ │ │ │ │ - layer: layers[i] │ │ │ │ │ - }); │ │ │ │ │ + passEventToSlider: function(evt) { │ │ │ │ │ + this.sliderEvents.handleBrowserEvent(evt); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /* │ │ │ │ │ + * Method: zoomBarDown │ │ │ │ │ + * event listener for clicks on the slider │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ + */ │ │ │ │ │ + zoomBarDown: function(evt) { │ │ │ │ │ + if (!OpenLayers.Event.isLeftClick(evt) && !OpenLayers.Event.isSingleTouch(evt)) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + "touchmove": this.passEventToSlider, │ │ │ │ │ + "mousemove": this.passEventToSlider, │ │ │ │ │ + "mouseup": this.passEventToSlider, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + this.mouseDragStart = evt.xy.clone(); │ │ │ │ │ + this.zoomStart = evt.xy.clone(); │ │ │ │ │ + this.div.style.cursor = "move"; │ │ │ │ │ + // reset the div offsets just in case the div moved │ │ │ │ │ + this.zoombarDiv.offsets = null; │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /* │ │ │ │ │ + * Method: zoomBarDrag │ │ │ │ │ + * This is what happens when a click has occurred, and the client is │ │ │ │ │ + * dragging. Here we must ensure that the slider doesn't go beyond the │ │ │ │ │ + * bottom/top of the zoombar div, as well as moving the slider to its new │ │ │ │ │ + * visual location │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ + */ │ │ │ │ │ + zoomBarDrag: function(evt) { │ │ │ │ │ + if (this.mouseDragStart != null) { │ │ │ │ │ + var deltaY = this.mouseDragStart.y - evt.xy.y; │ │ │ │ │ + var offsets = OpenLayers.Util.pagePosition(this.zoombarDiv); │ │ │ │ │ + if ((evt.clientY - offsets[1]) > 0 && │ │ │ │ │ + (evt.clientY - offsets[1]) < parseInt(this.zoombarDiv.style.height) - 2) { │ │ │ │ │ + var newTop = parseInt(this.slider.style.top) - deltaY; │ │ │ │ │ + this.slider.style.top = newTop + "px"; │ │ │ │ │ + this.mouseDragStart = evt.xy.clone(); │ │ │ │ │ } │ │ │ │ │ + // set cumulative displacement │ │ │ │ │ + this.deltaY = this.zoomStart.y - evt.xy.y; │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ } │ │ │ │ │ - if (this.map) { │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /* │ │ │ │ │ + * Method: zoomBarUp │ │ │ │ │ + * Perform cleanup when a mouseup event is received -- discover new zoom │ │ │ │ │ + * level and switch to it. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ + */ │ │ │ │ │ + zoomBarUp: function(evt) { │ │ │ │ │ + if (!OpenLayers.Event.isLeftClick(evt) && evt.type !== "touchend") { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + if (this.mouseDragStart) { │ │ │ │ │ + this.div.style.cursor = ""; │ │ │ │ │ this.map.events.un({ │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - removeLayer: this.removeLayer, │ │ │ │ │ + "touchmove": this.passEventToSlider, │ │ │ │ │ + "mouseup": this.passEventToSlider, │ │ │ │ │ + "mousemove": this.passEventToSlider, │ │ │ │ │ scope: this │ │ │ │ │ }); │ │ │ │ │ + var zoomLevel = this.map.zoom; │ │ │ │ │ + if (!this.forceFixedZoomLevel && this.map.fractionalZoom) { │ │ │ │ │ + zoomLevel += this.deltaY / this.zoomStopHeight; │ │ │ │ │ + zoomLevel = Math.min(Math.max(zoomLevel, 0), │ │ │ │ │ + this.map.getNumZoomLevels() - 1); │ │ │ │ │ + } else { │ │ │ │ │ + zoomLevel += this.deltaY / this.zoomStopHeight; │ │ │ │ │ + zoomLevel = Math.max(Math.round(zoomLevel), 0); │ │ │ │ │ + } │ │ │ │ │ + this.map.zoomTo(zoomLevel); │ │ │ │ │ + this.mouseDragStart = null; │ │ │ │ │ + this.zoomStart = null; │ │ │ │ │ + this.deltaY = 0; │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.CacheRead" │ │ │ │ │ + /* │ │ │ │ │ + * Method: moveZoomBar │ │ │ │ │ + * Change the location of the slider to match the current zoom level. │ │ │ │ │ + */ │ │ │ │ │ + moveZoomBar: function() { │ │ │ │ │ + var newTop = │ │ │ │ │ + ((this.map.getNumZoomLevels() - 1) - this.map.getZoom()) * │ │ │ │ │ + this.zoomStopHeight + this.startTop + 1; │ │ │ │ │ + this.slider.style.top = newTop + "px"; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.PanZoomBar" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Pan.js │ │ │ │ │ + OpenLayers/Control/DragPan.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control/Button.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Pan │ │ │ │ │ - * The Pan control is a single button to pan the map in one direction. For │ │ │ │ │ - * a more complete control see . │ │ │ │ │ + * Class: OpenLayers.Control.DragPan │ │ │ │ │ + * The DragPan control pans the map with a drag of the mouse. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Pan = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ +OpenLayers.Control.DragPan = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: slideFactor │ │ │ │ │ - * {Integer} Number of pixels by which we'll pan the map in any direction │ │ │ │ │ - * on clicking the arrow buttons, defaults to 50. If you want to pan │ │ │ │ │ - * by some ratio of the map dimensions, use instead. │ │ │ │ │ + * Property: type │ │ │ │ │ + * {OpenLayers.Control.TYPES} │ │ │ │ │ */ │ │ │ │ │ - slideFactor: 50, │ │ │ │ │ + type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: slideRatio │ │ │ │ │ - * {Number} The fraction of map width/height by which we'll pan the map │ │ │ │ │ - * on clicking the arrow buttons. Default is null. If set, will │ │ │ │ │ - * override . E.g. if slideRatio is .5, then Pan Up will │ │ │ │ │ - * pan up half the map height. │ │ │ │ │ + /** │ │ │ │ │ + * Property: panned │ │ │ │ │ + * {Boolean} The map moved. │ │ │ │ │ */ │ │ │ │ │ - slideRatio: null, │ │ │ │ │ + panned: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: direction │ │ │ │ │ - * {String} in {'North', 'South', 'East', 'West'} │ │ │ │ │ + /** │ │ │ │ │ + * Property: interval │ │ │ │ │ + * {Integer} The number of milliseconds that should ellapse before │ │ │ │ │ + * panning the map again. Defaults to 0 milliseconds, which means that │ │ │ │ │ + * no separate cycle is used for panning. In most cases you won't want │ │ │ │ │ + * to change this value. For slow machines/devices larger values can be │ │ │ │ │ + * tried out. │ │ │ │ │ */ │ │ │ │ │ - direction: null, │ │ │ │ │ + interval: 0, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Pan │ │ │ │ │ - * Control which handles the panning (in any of the cardinal directions) │ │ │ │ │ - * of the map by a set px distance. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * direction - {String} The direction this button should pan. │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * APIProperty: documentDrag │ │ │ │ │ + * {Boolean} If set to true, mouse dragging will continue even if the │ │ │ │ │ + * mouse cursor leaves the map viewport. Default is false. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(direction, options) { │ │ │ │ │ + documentDrag: false, │ │ │ │ │ │ │ │ │ │ - this.direction = direction; │ │ │ │ │ - this.CLASS_NAME += this.direction; │ │ │ │ │ + /** │ │ │ │ │ + * Property: kinetic │ │ │ │ │ + * {} The OpenLayers.Kinetic object. │ │ │ │ │ + */ │ │ │ │ │ + kinetic: null, │ │ │ │ │ │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: enableKinetic │ │ │ │ │ + * {Boolean} Set this option to enable "kinetic dragging". Can be │ │ │ │ │ + * set to true or to an object. If set to an object this │ │ │ │ │ + * object will be passed to the {} │ │ │ │ │ + * constructor. Defaults to true. │ │ │ │ │ + * To get kinetic dragging, ensure that OpenLayers/Kinetic.js is │ │ │ │ │ + * included in your build config. │ │ │ │ │ + */ │ │ │ │ │ + enableKinetic: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: kineticInterval │ │ │ │ │ + * {Integer} Interval in milliseconds between 2 steps in the "kinetic │ │ │ │ │ + * scrolling". Applies only if enableKinetic is set. Defaults │ │ │ │ │ + * to 10 milliseconds. │ │ │ │ │ + */ │ │ │ │ │ + kineticInterval: 10, │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + * Creates a Drag handler, using and │ │ │ │ │ + * as callbacks. │ │ │ │ │ + */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + if (this.enableKinetic && OpenLayers.Kinetic) { │ │ │ │ │ + var config = { │ │ │ │ │ + interval: this.kineticInterval │ │ │ │ │ + }; │ │ │ │ │ + if (typeof this.enableKinetic === "object") { │ │ │ │ │ + config = OpenLayers.Util.extend(config, this.enableKinetic); │ │ │ │ │ + } │ │ │ │ │ + this.kinetic = new OpenLayers.Kinetic(config); │ │ │ │ │ + } │ │ │ │ │ + this.handler = new OpenLayers.Handler.Drag(this, { │ │ │ │ │ + "move": this.panMap, │ │ │ │ │ + "done": this.panMapDone, │ │ │ │ │ + "down": this.panMapStart │ │ │ │ │ + }, { │ │ │ │ │ + interval: this.interval, │ │ │ │ │ + documentDrag: this.documentDrag │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: trigger │ │ │ │ │ + * Method: panMapStart │ │ │ │ │ */ │ │ │ │ │ - trigger: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - var getSlideFactor = OpenLayers.Function.bind(function(dim) { │ │ │ │ │ - return this.slideRatio ? │ │ │ │ │ - this.map.getSize()[dim] * this.slideRatio : │ │ │ │ │ - this.slideFactor; │ │ │ │ │ - }, this); │ │ │ │ │ + panMapStart: function() { │ │ │ │ │ + if (this.kinetic) { │ │ │ │ │ + this.kinetic.begin(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - switch (this.direction) { │ │ │ │ │ - case OpenLayers.Control.Pan.NORTH: │ │ │ │ │ - this.map.pan(0, -getSlideFactor("h")); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Control.Pan.SOUTH: │ │ │ │ │ - this.map.pan(0, getSlideFactor("h")); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Control.Pan.WEST: │ │ │ │ │ - this.map.pan(-getSlideFactor("w"), 0); │ │ │ │ │ - break; │ │ │ │ │ - case OpenLayers.Control.Pan.EAST: │ │ │ │ │ - this.map.pan(getSlideFactor("w"), 0); │ │ │ │ │ - break; │ │ │ │ │ + /** │ │ │ │ │ + * Method: panMap │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * xy - {} Pixel of the mouse position │ │ │ │ │ + */ │ │ │ │ │ + panMap: function(xy) { │ │ │ │ │ + if (this.kinetic) { │ │ │ │ │ + this.kinetic.update(xy); │ │ │ │ │ + } │ │ │ │ │ + this.panned = true; │ │ │ │ │ + this.map.pan( │ │ │ │ │ + this.handler.last.x - xy.x, │ │ │ │ │ + this.handler.last.y - xy.y, { │ │ │ │ │ + dragging: true, │ │ │ │ │ + animate: false │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: panMapDone │ │ │ │ │ + * Finish the panning operation. Only call setCenter (through ) │ │ │ │ │ + * if the map has actually been moved. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * xy - {} Pixel of the mouse position │ │ │ │ │ + */ │ │ │ │ │ + panMapDone: function(xy) { │ │ │ │ │ + if (this.panned) { │ │ │ │ │ + var res = null; │ │ │ │ │ + if (this.kinetic) { │ │ │ │ │ + res = this.kinetic.end(xy); │ │ │ │ │ + } │ │ │ │ │ + this.map.pan( │ │ │ │ │ + this.handler.last.x - xy.x, │ │ │ │ │ + this.handler.last.y - xy.y, { │ │ │ │ │ + dragging: !!res, │ │ │ │ │ + animate: false │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + if (res) { │ │ │ │ │ + var self = this; │ │ │ │ │ + this.kinetic.move(res, function(x, y, end) { │ │ │ │ │ + self.map.pan(x, y, { │ │ │ │ │ + dragging: !end, │ │ │ │ │ + animate: false │ │ │ │ │ + }); │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ + this.panned = false; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Pan" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.DragPan" │ │ │ │ │ }); │ │ │ │ │ - │ │ │ │ │ -OpenLayers.Control.Pan.NORTH = "North"; │ │ │ │ │ -OpenLayers.Control.Pan.SOUTH = "South"; │ │ │ │ │ -OpenLayers.Control.Pan.EAST = "East"; │ │ │ │ │ -OpenLayers.Control.Pan.WEST = "West"; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Zoom.js │ │ │ │ │ + OpenLayers/Control/Panel.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/Control.js │ │ │ │ │ * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Zoom │ │ │ │ │ - * The Zoom control is a pair of +/- links for zooming in and out. │ │ │ │ │ + * Class: OpenLayers.Control.Panel │ │ │ │ │ + * The Panel control is a container for other controls. With it toolbars │ │ │ │ │ + * may be composed. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Zoom = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.Panel = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + /** │ │ │ │ │ + * Property: controls │ │ │ │ │ + * {Array()} │ │ │ │ │ + */ │ │ │ │ │ + controls: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomInText │ │ │ │ │ - * {String} │ │ │ │ │ - * Text for zoom-in link. Default is "+". │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ */ │ │ │ │ │ - zoomInText: "+", │ │ │ │ │ + autoActivate: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: defaultControl │ │ │ │ │ + * {} The control which is activated when the control is │ │ │ │ │ + * activated (turned on), which also happens at instantiation. │ │ │ │ │ + * If is true, will be nullified after the │ │ │ │ │ + * first activation of the panel. │ │ │ │ │ + */ │ │ │ │ │ + defaultControl: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomInId │ │ │ │ │ - * {String} │ │ │ │ │ - * Instead of having the control create a zoom in link, you can provide │ │ │ │ │ - * the identifier for an anchor element already added to the document. │ │ │ │ │ - * By default, an element with id "olZoomInLink" will be searched for │ │ │ │ │ - * and used if it exists. │ │ │ │ │ + * APIProperty: saveState │ │ │ │ │ + * {Boolean} If set to true, the active state of this panel's controls will │ │ │ │ │ + * be stored on panel deactivation, and restored on reactivation. Default │ │ │ │ │ + * is false. │ │ │ │ │ */ │ │ │ │ │ - zoomInId: "olZoomInLink", │ │ │ │ │ + saveState: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomOutText │ │ │ │ │ - * {String} │ │ │ │ │ - * Text for zoom-out link. Default is "\u2212". │ │ │ │ │ + * APIProperty: allowDepress │ │ │ │ │ + * {Boolean} If is true the controls can │ │ │ │ │ + * be deactivated by clicking the icon that represents them. Default │ │ │ │ │ + * is false. │ │ │ │ │ */ │ │ │ │ │ - zoomOutText: "\u2212", │ │ │ │ │ + allowDepress: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomOutId │ │ │ │ │ - * {String} │ │ │ │ │ - * Instead of having the control create a zoom out link, you can provide │ │ │ │ │ - * the identifier for an anchor element already added to the document. │ │ │ │ │ - * By default, an element with id "olZoomOutLink" will be searched for │ │ │ │ │ - * and used if it exists. │ │ │ │ │ + * Property: activeState │ │ │ │ │ + * {Object} stores the active state of this panel's controls. │ │ │ │ │ */ │ │ │ │ │ - zoomOutId: "olZoomOutLink", │ │ │ │ │ + activeState: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.Panel │ │ │ │ │ + * Create a new control panel. │ │ │ │ │ + * │ │ │ │ │ + * Each control in the panel is represented by an icon. When clicking │ │ │ │ │ + * on an icon, the method is called. │ │ │ │ │ + * │ │ │ │ │ + * Specific properties for controls on a panel: │ │ │ │ │ + * type - {Number} One of , │ │ │ │ │ + * , . │ │ │ │ │ + * If not provided, is assumed. │ │ │ │ │ + * title - {string} Text displayed when mouse is over the icon that │ │ │ │ │ + * represents the control. │ │ │ │ │ + * │ │ │ │ │ + * The of a control determines the behavior when │ │ │ │ │ + * clicking its icon: │ │ │ │ │ + * - The control is activated and other │ │ │ │ │ + * controls of this type in the same panel are deactivated. This is │ │ │ │ │ + * the default type. │ │ │ │ │ + * - The active state of the control is │ │ │ │ │ + * toggled. │ │ │ │ │ + * - The │ │ │ │ │ + * method of the control is called, │ │ │ │ │ + * but its active state is not changed. │ │ │ │ │ + * │ │ │ │ │ + * If a control is , it will be drawn with the │ │ │ │ │ + * olControl[Name]ItemActive class, otherwise with the │ │ │ │ │ + * olControl[Name]ItemInactive class. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.controls = []; │ │ │ │ │ + this.activeState = {}; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.events.unregister("buttonclick", this, this.onButtonClick); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + for (var ctl, i = this.controls.length - 1; i >= 0; i--) { │ │ │ │ │ + ctl = this.controls[i]; │ │ │ │ │ + if (ctl.events) { │ │ │ │ │ + ctl.events.un({ │ │ │ │ │ + activate: this.iconOn, │ │ │ │ │ + deactivate: this.iconOff │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + ctl.panel_div = null; │ │ │ │ │ + } │ │ │ │ │ + this.activeState = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + */ │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + var control; │ │ │ │ │ + for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ + control = this.controls[i]; │ │ │ │ │ + if (control === this.defaultControl || │ │ │ │ │ + (this.saveState && this.activeState[control.id])) { │ │ │ │ │ + control.activate(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.saveState === true) { │ │ │ │ │ + this.defaultControl = null; │ │ │ │ │ + } │ │ │ │ │ + this.redraw(); │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + var control; │ │ │ │ │ + for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ + control = this.controls[i]; │ │ │ │ │ + this.activeState[control.id] = control.deactivate(); │ │ │ │ │ + } │ │ │ │ │ + this.redraw(); │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * Method: draw │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {DOMElement} A reference to the DOMElement containing the zoom links. │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ draw: function() { │ │ │ │ │ - var div = OpenLayers.Control.prototype.draw.apply(this), │ │ │ │ │ - links = this.getOrCreateLinks(div), │ │ │ │ │ - zoomIn = links.zoomIn, │ │ │ │ │ - zoomOut = links.zoomOut, │ │ │ │ │ - eventsInstance = this.map.events; │ │ │ │ │ - │ │ │ │ │ - if (zoomOut.parentNode !== div) { │ │ │ │ │ - eventsInstance = this.events; │ │ │ │ │ - eventsInstance.attachToElement(zoomOut.parentNode); │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (this.outsideViewport) { │ │ │ │ │ + this.events.attachToElement(this.div); │ │ │ │ │ + this.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ + } else { │ │ │ │ │ + this.map.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ } │ │ │ │ │ - eventsInstance.register("buttonclick", this, this.onZoomClick); │ │ │ │ │ + this.addControlsToMap(this.controls); │ │ │ │ │ + return this.div; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.zoomInLink = zoomIn; │ │ │ │ │ - this.zoomOutLink = zoomOut; │ │ │ │ │ - return div; │ │ │ │ │ + /** │ │ │ │ │ + * Method: redraw │ │ │ │ │ + */ │ │ │ │ │ + redraw: function() { │ │ │ │ │ + for (var l = this.div.childNodes.length, i = l - 1; i >= 0; i--) { │ │ │ │ │ + this.div.removeChild(this.div.childNodes[i]); │ │ │ │ │ + } │ │ │ │ │ + this.div.innerHTML = ""; │ │ │ │ │ + if (this.active) { │ │ │ │ │ + for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ + this.div.appendChild(this.controls[i].panel_div); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getOrCreateLinks │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: activateControl │ │ │ │ │ + * This method is called when the user click on the icon representing a │ │ │ │ │ + * control in the panel. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * el - {DOMElement} │ │ │ │ │ + * control - {} │ │ │ │ │ + */ │ │ │ │ │ + activateControl: function(control) { │ │ │ │ │ + if (!this.active) { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + if (control.type == OpenLayers.Control.TYPE_BUTTON) { │ │ │ │ │ + control.trigger(); │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + if (control.type == OpenLayers.Control.TYPE_TOGGLE) { │ │ │ │ │ + if (control.active) { │ │ │ │ │ + control.deactivate(); │ │ │ │ │ + } else { │ │ │ │ │ + control.activate(); │ │ │ │ │ + } │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + if (this.allowDepress && control.active) { │ │ │ │ │ + control.deactivate(); │ │ │ │ │ + } else { │ │ │ │ │ + var c; │ │ │ │ │ + for (var i = 0, len = this.controls.length; i < len; i++) { │ │ │ │ │ + c = this.controls[i]; │ │ │ │ │ + if (c != control && │ │ │ │ │ + (c.type === OpenLayers.Control.TYPE_TOOL || c.type == null)) { │ │ │ │ │ + c.deactivate(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + control.activate(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: addControls │ │ │ │ │ + * To build a toolbar, you add a set of controls to it. addControls │ │ │ │ │ + * lets you add a single control or a list of controls to the │ │ │ │ │ + * Control Panel. │ │ │ │ │ * │ │ │ │ │ - * Return: │ │ │ │ │ - * {Object} Object with zoomIn and zoomOut properties referencing links. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * controls - {} Controls to add in the panel. │ │ │ │ │ */ │ │ │ │ │ - getOrCreateLinks: function(el) { │ │ │ │ │ - var zoomIn = document.getElementById(this.zoomInId), │ │ │ │ │ - zoomOut = document.getElementById(this.zoomOutId); │ │ │ │ │ - if (!zoomIn) { │ │ │ │ │ - zoomIn = document.createElement("a"); │ │ │ │ │ - zoomIn.href = "#zoomIn"; │ │ │ │ │ - zoomIn.appendChild(document.createTextNode(this.zoomInText)); │ │ │ │ │ - zoomIn.className = "olControlZoomIn"; │ │ │ │ │ - el.appendChild(zoomIn); │ │ │ │ │ + addControls: function(controls) { │ │ │ │ │ + if (!(OpenLayers.Util.isArray(controls))) { │ │ │ │ │ + controls = [controls]; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Element.addClass(zoomIn, "olButton"); │ │ │ │ │ - if (!zoomOut) { │ │ │ │ │ - zoomOut = document.createElement("a"); │ │ │ │ │ - zoomOut.href = "#zoomOut"; │ │ │ │ │ - zoomOut.appendChild(document.createTextNode(this.zoomOutText)); │ │ │ │ │ - zoomOut.className = "olControlZoomOut"; │ │ │ │ │ - el.appendChild(zoomOut); │ │ │ │ │ + this.controls = this.controls.concat(controls); │ │ │ │ │ + │ │ │ │ │ + for (var i = 0, len = controls.length; i < len; i++) { │ │ │ │ │ + var control = controls[i], │ │ │ │ │ + element = this.createControlMarkup(control); │ │ │ │ │ + OpenLayers.Element.addClass(element, │ │ │ │ │ + control.displayClass + "ItemInactive"); │ │ │ │ │ + OpenLayers.Element.addClass(element, "olButton"); │ │ │ │ │ + if (control.title != "" && !element.title) { │ │ │ │ │ + element.title = control.title; │ │ │ │ │ + } │ │ │ │ │ + control.panel_div = element; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.map) { // map.addControl() has already been called on the panel │ │ │ │ │ + this.addControlsToMap(controls); │ │ │ │ │ + this.redraw(); │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Element.addClass(zoomOut, "olButton"); │ │ │ │ │ - return { │ │ │ │ │ - zoomIn: zoomIn, │ │ │ │ │ - zoomOut: zoomOut │ │ │ │ │ - }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onZoomClick │ │ │ │ │ - * Called when zoomin/out link is clicked. │ │ │ │ │ + * APIMethod: createControlMarkup │ │ │ │ │ + * This function just creates a div for the control. If specific HTML │ │ │ │ │ + * markup is needed this function can be overridden in specific classes, │ │ │ │ │ + * or at panel instantiation time: │ │ │ │ │ + * │ │ │ │ │ + * Example: │ │ │ │ │ + * (code) │ │ │ │ │ + * var panel = new OpenLayers.Control.Panel({ │ │ │ │ │ + * defaultControl: control, │ │ │ │ │ + * // ovverride createControlMarkup to create actual buttons │ │ │ │ │ + * // including texts wrapped into span elements. │ │ │ │ │ + * createControlMarkup: function(control) { │ │ │ │ │ + * var button = document.createElement('button'), │ │ │ │ │ + * span = document.createElement('span'); │ │ │ │ │ + * if (control.text) { │ │ │ │ │ + * span.innerHTML = control.text; │ │ │ │ │ + * } │ │ │ │ │ + * return button; │ │ │ │ │ + * } │ │ │ │ │ + * }); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * control - {} The control to create the HTML │ │ │ │ │ + * markup for. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The markup. │ │ │ │ │ */ │ │ │ │ │ - onZoomClick: function(evt) { │ │ │ │ │ - var button = evt.buttonElement; │ │ │ │ │ - if (button === this.zoomInLink) { │ │ │ │ │ - this.map.zoomIn(); │ │ │ │ │ - } else if (button === this.zoomOutLink) { │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ + createControlMarkup: function(control) { │ │ │ │ │ + return document.createElement("div"); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: addControlsToMap │ │ │ │ │ + * Only for internal use in draw() and addControls() methods. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * controls - {Array()} Controls to add into map. │ │ │ │ │ + */ │ │ │ │ │ + addControlsToMap: function(controls) { │ │ │ │ │ + var control; │ │ │ │ │ + for (var i = 0, len = controls.length; i < len; i++) { │ │ │ │ │ + control = controls[i]; │ │ │ │ │ + if (control.autoActivate === true) { │ │ │ │ │ + control.autoActivate = false; │ │ │ │ │ + this.map.addControl(control); │ │ │ │ │ + control.autoActivate = true; │ │ │ │ │ + } else { │ │ │ │ │ + this.map.addControl(control); │ │ │ │ │ + control.deactivate(); │ │ │ │ │ + } │ │ │ │ │ + control.events.on({ │ │ │ │ │ + activate: this.iconOn, │ │ │ │ │ + deactivate: this.iconOff │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: iconOn │ │ │ │ │ + * Internal use, for use only with "controls[i].events.on/un". │ │ │ │ │ + */ │ │ │ │ │ + iconOn: function() { │ │ │ │ │ + var d = this.panel_div; // "this" refers to a control on panel! │ │ │ │ │ + var re = new RegExp("\\b(" + this.displayClass + "Item)Inactive\\b"); │ │ │ │ │ + d.className = d.className.replace(re, "$1Active"); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: iconOff │ │ │ │ │ + * Internal use, for use only with "controls[i].events.on/un". │ │ │ │ │ + */ │ │ │ │ │ + iconOff: function() { │ │ │ │ │ + var d = this.panel_div; // "this" refers to a control on panel! │ │ │ │ │ + var re = new RegExp("\\b(" + this.displayClass + "Item)Active\\b"); │ │ │ │ │ + d.className = d.className.replace(re, "$1Inactive"); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: onButtonClick │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + */ │ │ │ │ │ + onButtonClick: function(evt) { │ │ │ │ │ + var controls = this.controls, │ │ │ │ │ + button = evt.buttonElement; │ │ │ │ │ + for (var i = controls.length - 1; i >= 0; --i) { │ │ │ │ │ + if (controls[i].panel_div === button) { │ │ │ │ │ + this.activateControl(controls[i]); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * 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(control[property]) evaluates to true, the control will be │ │ │ │ │ + * included in the array returned. If no controls 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. │ │ │ │ │ + */ │ │ │ │ │ + getControlsBy: function(property, match) { │ │ │ │ │ + var test = (typeof match.test == "function"); │ │ │ │ │ + var found = OpenLayers.Array.filter(this.controls, function(item) { │ │ │ │ │ + return item[property] == match || (test && match.test(item[property])); │ │ │ │ │ + }); │ │ │ │ │ + return found; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getControlsByName │ │ │ │ │ + * Get a list of contorls with names matching the given name. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * match - {String | Object} A control 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(control.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 name. │ │ │ │ │ + * An empty array is returned if no matches are found. │ │ │ │ │ + */ │ │ │ │ │ + getControlsByName: function(match) { │ │ │ │ │ + return this.getControlsBy("name", match); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getControlsByClass │ │ │ │ │ + * Get a list of controls of a given type (CLASS_NAME). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * match - {String | Object} A control class name. The type 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 type. │ │ │ │ │ + * An empty array is returned if no matches are found. │ │ │ │ │ + */ │ │ │ │ │ + getControlsByClass: function(match) { │ │ │ │ │ + return this.getControlsBy("CLASS_NAME", match); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Panel" │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Handler/Box.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ + * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Handler.Box │ │ │ │ │ + * Handler for dragging a rectangle across the map. Box is displayed │ │ │ │ │ + * on mouse down, moves on mouse move, and is finished on mouse up. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ + * Property: dragHandler │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + dragHandler: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: boxDivClassName │ │ │ │ │ + * {String} The CSS class to use for drawing the box. Default is │ │ │ │ │ + * olHandlerBoxZoomBox │ │ │ │ │ + */ │ │ │ │ │ + boxDivClassName: 'olHandlerBoxZoomBox', │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: boxOffsets │ │ │ │ │ + * {Object} Caches box offsets from css. This is used by the getBoxOffsets │ │ │ │ │ + * method. │ │ │ │ │ + */ │ │ │ │ │ + boxOffsets: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Handler.Box │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * control - {} │ │ │ │ │ + * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ + * functions. Various callbacks described below. │ │ │ │ │ + * options - {Object} │ │ │ │ │ + * │ │ │ │ │ + * Named callbacks: │ │ │ │ │ + * start - Called when the box drag operation starts. │ │ │ │ │ + * done - Called when the box drag operation is finished. │ │ │ │ │ + * The callback should expect to receive a single argument, the box │ │ │ │ │ + * bounds or a pixel. If the box dragging didn't span more than a 5 │ │ │ │ │ + * pixel distance, a pixel will be returned instead of a bounds object. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(control, callbacks, options) { │ │ │ │ │ + OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ + this.dragHandler = new OpenLayers.Handler.Drag( │ │ │ │ │ + this, { │ │ │ │ │ + down: this.startBox, │ │ │ │ │ + move: this.moveBox, │ │ │ │ │ + out: this.removeBox, │ │ │ │ │ + up: this.endBox │ │ │ │ │ + }, { │ │ │ │ │ + keyMask: this.keyMask │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ * Method: destroy │ │ │ │ │ - * Clean up. │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.events.unregister("buttonclick", this, this.onZoomClick); │ │ │ │ │ + OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ + if (this.dragHandler) { │ │ │ │ │ + this.dragHandler.destroy(); │ │ │ │ │ + this.dragHandler = null; │ │ │ │ │ } │ │ │ │ │ - delete this.zoomInLink; │ │ │ │ │ - delete this.zoomOutLink; │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Zoom" │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + */ │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Handler.prototype.setMap.apply(this, arguments); │ │ │ │ │ + if (this.dragHandler) { │ │ │ │ │ + this.dragHandler.setMap(map); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: startBox │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * xy - {} │ │ │ │ │ + */ │ │ │ │ │ + startBox: function(xy) { │ │ │ │ │ + this.callback("start", []); │ │ │ │ │ + this.zoomBox = OpenLayers.Util.createDiv('zoomBox', { │ │ │ │ │ + x: -9999, │ │ │ │ │ + y: -9999 │ │ │ │ │ + }); │ │ │ │ │ + this.zoomBox.className = this.boxDivClassName; │ │ │ │ │ + this.zoomBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1; │ │ │ │ │ + │ │ │ │ │ + this.map.viewPortDiv.appendChild(this.zoomBox); │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Element.addClass( │ │ │ │ │ + this.map.viewPortDiv, "olDrawBox" │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveBox │ │ │ │ │ + */ │ │ │ │ │ + moveBox: function(xy) { │ │ │ │ │ + var startX = this.dragHandler.start.x; │ │ │ │ │ + var startY = this.dragHandler.start.y; │ │ │ │ │ + var deltaX = Math.abs(startX - xy.x); │ │ │ │ │ + var deltaY = Math.abs(startY - xy.y); │ │ │ │ │ + │ │ │ │ │ + var offset = this.getBoxOffsets(); │ │ │ │ │ + this.zoomBox.style.width = (deltaX + offset.width + 1) + "px"; │ │ │ │ │ + this.zoomBox.style.height = (deltaY + offset.height + 1) + "px"; │ │ │ │ │ + this.zoomBox.style.left = (xy.x < startX ? │ │ │ │ │ + startX - deltaX - offset.left : startX - offset.left) + "px"; │ │ │ │ │ + this.zoomBox.style.top = (xy.y < startY ? │ │ │ │ │ + startY - deltaY - offset.top : startY - offset.top) + "px"; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: endBox │ │ │ │ │ + */ │ │ │ │ │ + endBox: function(end) { │ │ │ │ │ + var result; │ │ │ │ │ + if (Math.abs(this.dragHandler.start.x - end.x) > 5 || │ │ │ │ │ + Math.abs(this.dragHandler.start.y - end.y) > 5) { │ │ │ │ │ + var start = this.dragHandler.start; │ │ │ │ │ + var top = Math.min(start.y, end.y); │ │ │ │ │ + var bottom = Math.max(start.y, end.y); │ │ │ │ │ + var left = Math.min(start.x, end.x); │ │ │ │ │ + var right = Math.max(start.x, end.x); │ │ │ │ │ + result = new OpenLayers.Bounds(left, bottom, right, top); │ │ │ │ │ + } else { │ │ │ │ │ + result = this.dragHandler.start.clone(); // i.e. OL.Pixel │ │ │ │ │ + } │ │ │ │ │ + this.removeBox(); │ │ │ │ │ + │ │ │ │ │ + this.callback("done", [result]); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeBox │ │ │ │ │ + * Remove the zoombox from the screen and nullify our reference to it. │ │ │ │ │ + */ │ │ │ │ │ + removeBox: function() { │ │ │ │ │ + this.map.viewPortDiv.removeChild(this.zoomBox); │ │ │ │ │ + this.zoomBox = null; │ │ │ │ │ + this.boxOffsets = null; │ │ │ │ │ + OpenLayers.Element.removeClass( │ │ │ │ │ + this.map.viewPortDiv, "olDrawBox" │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: activate │ │ │ │ │ + */ │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + this.dragHandler.activate(); │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + if (this.dragHandler.deactivate()) { │ │ │ │ │ + if (this.zoomBox) { │ │ │ │ │ + this.removeBox(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getBoxOffsets │ │ │ │ │ + * Determines border offsets for a box, according to the box model. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} an object with the following offsets: │ │ │ │ │ + * - left │ │ │ │ │ + * - right │ │ │ │ │ + * - top │ │ │ │ │ + * - bottom │ │ │ │ │ + * - width │ │ │ │ │ + * - height │ │ │ │ │ + */ │ │ │ │ │ + getBoxOffsets: function() { │ │ │ │ │ + if (!this.boxOffsets) { │ │ │ │ │ + // Determine the box model. If the testDiv's clientWidth is 3, then │ │ │ │ │ + // the borders are outside and we are dealing with the w3c box │ │ │ │ │ + // model. Otherwise, the browser uses the traditional box model and │ │ │ │ │ + // the borders are inside the box bounds, leaving us with a │ │ │ │ │ + // clientWidth of 1. │ │ │ │ │ + var testDiv = document.createElement("div"); │ │ │ │ │ + //testDiv.style.visibility = "hidden"; │ │ │ │ │ + testDiv.style.position = "absolute"; │ │ │ │ │ + testDiv.style.border = "1px solid black"; │ │ │ │ │ + testDiv.style.width = "3px"; │ │ │ │ │ + document.body.appendChild(testDiv); │ │ │ │ │ + var w3cBoxModel = testDiv.clientWidth == 3; │ │ │ │ │ + document.body.removeChild(testDiv); │ │ │ │ │ + │ │ │ │ │ + var left = parseInt(OpenLayers.Element.getStyle(this.zoomBox, │ │ │ │ │ + "border-left-width")); │ │ │ │ │ + var right = parseInt(OpenLayers.Element.getStyle( │ │ │ │ │ + this.zoomBox, "border-right-width")); │ │ │ │ │ + var top = parseInt(OpenLayers.Element.getStyle(this.zoomBox, │ │ │ │ │ + "border-top-width")); │ │ │ │ │ + var bottom = parseInt(OpenLayers.Element.getStyle( │ │ │ │ │ + this.zoomBox, "border-bottom-width")); │ │ │ │ │ + this.boxOffsets = { │ │ │ │ │ + left: left, │ │ │ │ │ + right: right, │ │ │ │ │ + top: top, │ │ │ │ │ + bottom: bottom, │ │ │ │ │ + width: w3cBoxModel === false ? left + right : 0, │ │ │ │ │ + height: w3cBoxModel === false ? top + bottom : 0 │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + return this.boxOffsets; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Box" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/WMS.js │ │ │ │ │ + OpenLayers/Control/ZoomBox.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler/Box.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.WMS │ │ │ │ │ - * Instances of OpenLayers.Layer.WMS are used to display data from OGC Web │ │ │ │ │ - * Mapping Services. Create a new WMS layer with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Control.ZoomBox │ │ │ │ │ + * The ZoomBox control enables zooming directly to a given extent, by drawing │ │ │ │ │ + * a box on the map. The box is drawn by holding down shift, whilst dragging │ │ │ │ │ + * the mouse. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ +OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + /** │ │ │ │ │ + * Property: type │ │ │ │ │ + * {OpenLayers.Control.TYPE} │ │ │ │ │ + */ │ │ │ │ │ + type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: DEFAULT_PARAMS │ │ │ │ │ - * {Object} Hashtable of default parameter key/value pairs │ │ │ │ │ + * Property: out │ │ │ │ │ + * {Boolean} Should the control be used for zooming out? │ │ │ │ │ */ │ │ │ │ │ - DEFAULT_PARAMS: { │ │ │ │ │ - service: "WMS", │ │ │ │ │ - version: "1.1.1", │ │ │ │ │ - request: "GetMap", │ │ │ │ │ - styles: "", │ │ │ │ │ - format: "image/jpeg" │ │ │ │ │ - }, │ │ │ │ │ + out: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} Default is true for WMS layer │ │ │ │ │ + * APIProperty: keyMask │ │ │ │ │ + * {Integer} Zoom only occurs if the keyMask matches the combination of │ │ │ │ │ + * keys down. Use bitwise operators and one or more of the │ │ │ │ │ + * constants to construct a keyMask. Leave null if │ │ │ │ │ + * not used mask. Default is null. │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + keyMask: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: encodeBBOX │ │ │ │ │ - * {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no', │ │ │ │ │ - * but some services want it that way. Default false. │ │ │ │ │ + * APIProperty: alwaysZoom │ │ │ │ │ + * {Boolean} Always zoom in/out when box drawn, even if the zoom level does │ │ │ │ │ + * not change. │ │ │ │ │ */ │ │ │ │ │ - encodeBBOX: false, │ │ │ │ │ + alwaysZoom: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: noMagic │ │ │ │ │ - * {Boolean} If true, the image format will not be automagicaly switched │ │ │ │ │ - * from image/jpeg to image/png or image/gif when using │ │ │ │ │ - * TRANSPARENT=TRUE. Also isBaseLayer will not changed by the │ │ │ │ │ - * constructor. Default false. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomOnClick │ │ │ │ │ + * {Boolean} Should we zoom when no box was dragged, i.e. the user only │ │ │ │ │ + * clicked? Default is true. │ │ │ │ │ */ │ │ │ │ │ - noMagic: false, │ │ │ │ │ + zoomOnClick: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: yx │ │ │ │ │ - * {Object} Keys in this object are EPSG codes for which the axis order │ │ │ │ │ - * is to be reversed (yx instead of xy, LatLon instead of LonLat), with │ │ │ │ │ - * true as value. This is only relevant for WMS versions >= 1.3.0, and │ │ │ │ │ - * only if yx is not set in for the │ │ │ │ │ - * used projection. │ │ │ │ │ + * Method: draw │ │ │ │ │ */ │ │ │ │ │ - yx: {}, │ │ │ │ │ + draw: function() { │ │ │ │ │ + this.handler = new OpenLayers.Handler.Box(this, { │ │ │ │ │ + done: this.zoomBox │ │ │ │ │ + }, { │ │ │ │ │ + keyMask: this.keyMask │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.WMS │ │ │ │ │ - * Create a new WMS layer object │ │ │ │ │ - * │ │ │ │ │ - * Examples: │ │ │ │ │ - * │ │ │ │ │ - * The code below creates a simple WMS layer using the image/jpeg format. │ │ │ │ │ - * (code) │ │ │ │ │ - * var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic", │ │ │ │ │ - * "http://wms.jpl.nasa.gov/wms.cgi", │ │ │ │ │ - * {layers: "modis,global_mosaic"}); │ │ │ │ │ - * (end) │ │ │ │ │ - * Note the 3rd argument (params). Properties added to this object will be │ │ │ │ │ - * added to the WMS GetMap requests used for this layer's tiles. The only │ │ │ │ │ - * mandatory parameter is "layers". Other common WMS params include │ │ │ │ │ - * "transparent", "styles" and "format". Note that the "srs" param will │ │ │ │ │ - * always be ignored. Instead, it will be derived from the baseLayer's or │ │ │ │ │ - * map's projection. │ │ │ │ │ - * │ │ │ │ │ - * The code below creates a transparent WMS layer with additional options. │ │ │ │ │ - * (code) │ │ │ │ │ - * var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic", │ │ │ │ │ - * "http://wms.jpl.nasa.gov/wms.cgi", │ │ │ │ │ - * { │ │ │ │ │ - * layers: "modis,global_mosaic", │ │ │ │ │ - * transparent: true │ │ │ │ │ - * }, { │ │ │ │ │ - * opacity: 0.5, │ │ │ │ │ - * singleTile: true │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ - * Note that by default, a WMS layer is configured as baseLayer. Setting │ │ │ │ │ - * the "transparent" param to true will apply some magic (see ). │ │ │ │ │ - * The default image format changes from image/jpeg to image/png, and the │ │ │ │ │ - * layer is not configured as baseLayer. │ │ │ │ │ + * Method: zoomBox │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} A name for the layer │ │ │ │ │ - * url - {String} Base url for the WMS │ │ │ │ │ - * (e.g. http://wms.jpl.nasa.gov/wms.cgi) │ │ │ │ │ - * params - {Object} An object with key/value pairs representing the │ │ │ │ │ - * GetMap query string parameters and parameter values. │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer. │ │ │ │ │ - * These options include all properties listed above, plus the ones │ │ │ │ │ - * inherited from superclasses. │ │ │ │ │ + * position - {} or {} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, params, options) { │ │ │ │ │ - var newArguments = []; │ │ │ │ │ - //uppercase params │ │ │ │ │ - params = OpenLayers.Util.upperCaseObject(params); │ │ │ │ │ - if (parseFloat(params.VERSION) >= 1.3 && !params.EXCEPTIONS) { │ │ │ │ │ - params.EXCEPTIONS = "INIMAGE"; │ │ │ │ │ + zoomBox: function(position) { │ │ │ │ │ + if (position instanceof OpenLayers.Bounds) { │ │ │ │ │ + var bounds, │ │ │ │ │ + targetCenterPx = position.getCenterPixel(); │ │ │ │ │ + if (!this.out) { │ │ │ │ │ + var minXY = this.map.getLonLatFromPixel({ │ │ │ │ │ + x: position.left, │ │ │ │ │ + y: position.bottom │ │ │ │ │ + }); │ │ │ │ │ + var maxXY = this.map.getLonLatFromPixel({ │ │ │ │ │ + x: position.right, │ │ │ │ │ + y: position.top │ │ │ │ │ + }); │ │ │ │ │ + bounds = new OpenLayers.Bounds(minXY.lon, minXY.lat, │ │ │ │ │ + maxXY.lon, maxXY.lat); │ │ │ │ │ + } else { │ │ │ │ │ + var pixWidth = position.right - position.left; │ │ │ │ │ + var pixHeight = position.bottom - position.top; │ │ │ │ │ + var zoomFactor = Math.min((this.map.size.h / pixHeight), │ │ │ │ │ + (this.map.size.w / pixWidth)); │ │ │ │ │ + var extent = this.map.getExtent(); │ │ │ │ │ + var center = this.map.getLonLatFromPixel(targetCenterPx); │ │ │ │ │ + var xmin = center.lon - (extent.getWidth() / 2) * zoomFactor; │ │ │ │ │ + var xmax = center.lon + (extent.getWidth() / 2) * zoomFactor; │ │ │ │ │ + var ymin = center.lat - (extent.getHeight() / 2) * zoomFactor; │ │ │ │ │ + var ymax = center.lat + (extent.getHeight() / 2) * zoomFactor; │ │ │ │ │ + bounds = new OpenLayers.Bounds(xmin, ymin, xmax, ymax); │ │ │ │ │ + } │ │ │ │ │ + // always zoom in/out │ │ │ │ │ + var lastZoom = this.map.getZoom(), │ │ │ │ │ + size = this.map.getSize(), │ │ │ │ │ + centerPx = { │ │ │ │ │ + x: size.w / 2, │ │ │ │ │ + y: size.h / 2 │ │ │ │ │ + }, │ │ │ │ │ + zoom = this.map.getZoomForExtent(bounds), │ │ │ │ │ + oldRes = this.map.getResolution(), │ │ │ │ │ + newRes = this.map.getResolutionForZoom(zoom); │ │ │ │ │ + if (oldRes == newRes) { │ │ │ │ │ + this.map.setCenter(this.map.getLonLatFromPixel(targetCenterPx)); │ │ │ │ │ + } else { │ │ │ │ │ + var zoomOriginPx = { │ │ │ │ │ + x: (oldRes * targetCenterPx.x - newRes * centerPx.x) / │ │ │ │ │ + (oldRes - newRes), │ │ │ │ │ + y: (oldRes * targetCenterPx.y - newRes * centerPx.y) / │ │ │ │ │ + (oldRes - newRes) │ │ │ │ │ + }; │ │ │ │ │ + this.map.zoomTo(zoom, zoomOriginPx); │ │ │ │ │ + } │ │ │ │ │ + if (lastZoom == this.map.getZoom() && this.alwaysZoom == true) { │ │ │ │ │ + this.map.zoomTo(lastZoom + (this.out ? -1 : 1)); │ │ │ │ │ + } │ │ │ │ │ + } else if (this.zoomOnClick) { // it's a pixel │ │ │ │ │ + if (!this.out) { │ │ │ │ │ + this.map.zoomTo(this.map.getZoom() + 1, position); │ │ │ │ │ + } else { │ │ │ │ │ + this.map.zoomTo(this.map.getZoom() - 1, position); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - newArguments.push(name, url, params, options); │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); │ │ │ │ │ - OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.params, │ │ │ │ │ - OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS) │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ZoomBox" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Handler/MouseWheel.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Handler.MouseWheel │ │ │ │ │ + * Handler for wheel up/down events. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ + /** │ │ │ │ │ + * Property: wheelListener │ │ │ │ │ + * {function} │ │ │ │ │ + */ │ │ │ │ │ + wheelListener: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: interval │ │ │ │ │ + * {Integer} In order to increase server performance, an interval (in │ │ │ │ │ + * milliseconds) can be set to reduce the number of up/down events │ │ │ │ │ + * called. If set, a new up/down event will not be set until the │ │ │ │ │ + * interval has passed. │ │ │ │ │ + * Defaults to 0, meaning no interval. │ │ │ │ │ + */ │ │ │ │ │ + interval: 0, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: maxDelta │ │ │ │ │ + * {Integer} Maximum delta to collect before breaking from the current │ │ │ │ │ + * interval. In cumulative mode, this also limits the maximum delta │ │ │ │ │ + * returned from the handler. Default is Number.POSITIVE_INFINITY. │ │ │ │ │ + */ │ │ │ │ │ + maxDelta: Number.POSITIVE_INFINITY, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: delta │ │ │ │ │ + * {Integer} When interval is set, delta collects the mousewheel z-deltas │ │ │ │ │ + * of the events that occur within the interval. │ │ │ │ │ + * See also the cumulative option │ │ │ │ │ + */ │ │ │ │ │ + delta: 0, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: cumulative │ │ │ │ │ + * {Boolean} When interval is set: true to collect all the mousewheel │ │ │ │ │ + * z-deltas, false to only record the delta direction (positive or │ │ │ │ │ + * negative) │ │ │ │ │ + */ │ │ │ │ │ + cumulative: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Handler.MouseWheel │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * control - {} │ │ │ │ │ + * callbacks - {Object} An object containing a single function to be │ │ │ │ │ + * called when the drag operation is finished. │ │ │ │ │ + * The callback should expect to recieve a single │ │ │ │ │ + * argument, the point geometry. │ │ │ │ │ + * options - {Object} │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(control, callbacks, options) { │ │ │ │ │ + OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ + this.wheelListener = OpenLayers.Function.bindAsEventListener( │ │ │ │ │ + this.onWheelEvent, this │ │ │ │ │ ); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + OpenLayers.Handler.prototype.destroy.apply(this, arguments); │ │ │ │ │ + this.wheelListener = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * Mouse ScrollWheel code thanks to http://adomas.org/javascript-mouse-wheel/ │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - //layer is transparent │ │ │ │ │ - if (!this.noMagic && this.params.TRANSPARENT && │ │ │ │ │ - this.params.TRANSPARENT.toString().toLowerCase() == "true") { │ │ │ │ │ + /** │ │ │ │ │ + * Method: onWheelEvent │ │ │ │ │ + * Catch the wheel event and handle it xbrowserly │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * e - {Event} │ │ │ │ │ + */ │ │ │ │ │ + onWheelEvent: function(e) { │ │ │ │ │ │ │ │ │ │ - // unless explicitly set in options, make layer an overlay │ │ │ │ │ - if ((options == null) || (!options.isBaseLayer)) { │ │ │ │ │ - this.isBaseLayer = false; │ │ │ │ │ + // make sure we have a map and check keyboard modifiers │ │ │ │ │ + if (!this.map || !this.checkModifiers(e)) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // Ride up the element's DOM hierarchy to determine if it or any of │ │ │ │ │ + // its ancestors was: │ │ │ │ │ + // * specifically marked as scrollable (CSS overflow property) │ │ │ │ │ + // * one of our layer divs or a div marked as scrollable │ │ │ │ │ + // ('olScrollable' CSS class) │ │ │ │ │ + // * the map div │ │ │ │ │ + // │ │ │ │ │ + var overScrollableDiv = false; │ │ │ │ │ + var allowScroll = false; │ │ │ │ │ + var overMapDiv = false; │ │ │ │ │ + │ │ │ │ │ + var elem = OpenLayers.Event.element(e); │ │ │ │ │ + while ((elem != null) && !overMapDiv && !overScrollableDiv) { │ │ │ │ │ + │ │ │ │ │ + if (!overScrollableDiv) { │ │ │ │ │ + try { │ │ │ │ │ + var overflow; │ │ │ │ │ + if (elem.currentStyle) { │ │ │ │ │ + overflow = elem.currentStyle["overflow"]; │ │ │ │ │ + } else { │ │ │ │ │ + var style = │ │ │ │ │ + document.defaultView.getComputedStyle(elem, null); │ │ │ │ │ + overflow = style.getPropertyValue("overflow"); │ │ │ │ │ + } │ │ │ │ │ + overScrollableDiv = (overflow && │ │ │ │ │ + (overflow == "auto") || (overflow == "scroll")); │ │ │ │ │ + } catch (err) { │ │ │ │ │ + //sometimes when scrolling in a popup, this causes │ │ │ │ │ + // obscure browser error │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // jpegs can never be transparent, so intelligently switch the │ │ │ │ │ - // format, depending on the browser's capabilities │ │ │ │ │ - if (this.params.FORMAT == "image/jpeg") { │ │ │ │ │ - this.params.FORMAT = OpenLayers.Util.alphaHack() ? "image/gif" : │ │ │ │ │ - "image/png"; │ │ │ │ │ + if (!allowScroll) { │ │ │ │ │ + allowScroll = OpenLayers.Element.hasClass(elem, 'olScrollable'); │ │ │ │ │ + if (!allowScroll) { │ │ │ │ │ + for (var i = 0, len = this.map.layers.length; i < len; i++) { │ │ │ │ │ + // Are we in the layer div? Note that we have two cases │ │ │ │ │ + // here: one is to catch EventPane layers, which have a │ │ │ │ │ + // pane above the layer (layer.pane) │ │ │ │ │ + var layer = this.map.layers[i]; │ │ │ │ │ + if (elem == layer.div || elem == layer.pane) { │ │ │ │ │ + allowScroll = true; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + overMapDiv = (elem == this.map.div); │ │ │ │ │ + │ │ │ │ │ + elem = elem.parentNode; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ + // Logic below is the following: │ │ │ │ │ + // │ │ │ │ │ + // If we are over a scrollable div or not over the map div: │ │ │ │ │ + // * do nothing (let the browser handle scrolling) │ │ │ │ │ + // │ │ │ │ │ + // otherwise │ │ │ │ │ + // │ │ │ │ │ + // If we are over the layer div or a 'olScrollable' div: │ │ │ │ │ + // * zoom/in out │ │ │ │ │ + // then │ │ │ │ │ + // * kill event (so as not to also scroll the page after zooming) │ │ │ │ │ + // │ │ │ │ │ + // otherwise │ │ │ │ │ + // │ │ │ │ │ + // Kill the event (dont scroll the page if we wheel over the │ │ │ │ │ + // layerswitcher or the pan/zoom control) │ │ │ │ │ + // │ │ │ │ │ + if (!overScrollableDiv && overMapDiv) { │ │ │ │ │ + if (allowScroll) { │ │ │ │ │ + var delta = 0; │ │ │ │ │ + │ │ │ │ │ + if (e.wheelDelta) { │ │ │ │ │ + delta = e.wheelDelta; │ │ │ │ │ + if (delta % 160 === 0) { │ │ │ │ │ + // opera have steps of 160 instead of 120 │ │ │ │ │ + delta = delta * 0.75; │ │ │ │ │ + } │ │ │ │ │ + delta = delta / 120; │ │ │ │ │ + } else if (e.detail) { │ │ │ │ │ + // detail in Firefox on OS X is 1/3 of Windows │ │ │ │ │ + // so force delta 1 / -1 │ │ │ │ │ + delta = -(e.detail / Math.abs(e.detail)); │ │ │ │ │ + } │ │ │ │ │ + this.delta += delta; │ │ │ │ │ + │ │ │ │ │ + window.clearTimeout(this._timeoutId); │ │ │ │ │ + if (this.interval && Math.abs(this.delta) < this.maxDelta) { │ │ │ │ │ + // store e because window.event might change during delay │ │ │ │ │ + var evt = OpenLayers.Util.extend({}, e); │ │ │ │ │ + this._timeoutId = window.setTimeout( │ │ │ │ │ + OpenLayers.Function.bind(function() { │ │ │ │ │ + this.wheelZoom(evt); │ │ │ │ │ + }, this), │ │ │ │ │ + this.interval │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + this.wheelZoom(e); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this layer │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this layer │ │ │ │ │ + * Method: wheelZoom │ │ │ │ │ + * Given the wheel event, we carry out the appropriate zooming in or out, │ │ │ │ │ + * based on the 'wheelDelta' or 'detail' property of the event. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * e - {Event} │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ + wheelZoom: function(e) { │ │ │ │ │ + var delta = this.delta; │ │ │ │ │ + this.delta = 0; │ │ │ │ │ │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.WMS(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.params, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + if (delta) { │ │ │ │ │ + e.xy = this.map.events.getMousePosition(e); │ │ │ │ │ + if (delta < 0) { │ │ │ │ │ + this.callback("down", │ │ │ │ │ + [e, this.cumulative ? Math.max(-this.maxDelta, delta) : -1]); │ │ │ │ │ + } else { │ │ │ │ │ + this.callback("up", │ │ │ │ │ + [e, this.cumulative ? Math.min(this.maxDelta, delta) : 1]); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ + /** │ │ │ │ │ + * Method: activate │ │ │ │ │ + */ │ │ │ │ │ + activate: function(evt) { │ │ │ │ │ + if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + //register mousewheel events specifically on the window and document │ │ │ │ │ + var wheelListener = this.wheelListener; │ │ │ │ │ + OpenLayers.Event.observe(window, "DOMMouseScroll", wheelListener); │ │ │ │ │ + OpenLayers.Event.observe(window, "mousewheel", wheelListener); │ │ │ │ │ + OpenLayers.Event.observe(document, "mousewheel", wheelListener); │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - return obj; │ │ │ │ │ + /** │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function(evt) { │ │ │ │ │ + if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + // unregister mousewheel events specifically on the window and document │ │ │ │ │ + var wheelListener = this.wheelListener; │ │ │ │ │ + OpenLayers.Event.stopObserving(window, "DOMMouseScroll", wheelListener); │ │ │ │ │ + OpenLayers.Event.stopObserving(window, "mousewheel", wheelListener); │ │ │ │ │ + OpenLayers.Event.stopObserving(document, "mousewheel", wheelListener); │ │ │ │ │ + return true; │ │ │ │ │ + } else { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.MouseWheel" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/Navigation.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control/ZoomBox.js │ │ │ │ │ + * @requires OpenLayers/Control/DragPan.js │ │ │ │ │ + * @requires OpenLayers/Handler/MouseWheel.js │ │ │ │ │ + * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.Navigation │ │ │ │ │ + * The navigation control handles map browsing with mouse events (dragging, │ │ │ │ │ + * double-clicking, and scrolling the wheel). Create a new navigation │ │ │ │ │ + * control with the control. │ │ │ │ │ + * │ │ │ │ │ + * Note that this control is added to the map by default (if no controls │ │ │ │ │ + * array is sent in the options object to the │ │ │ │ │ + * constructor). │ │ │ │ │ + * │ │ │ │ │ + * Inherits: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: dragPan │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + dragPan: null, │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: reverseAxisOrder │ │ │ │ │ - * Returns true if the axis order is reversed for the WMS version and │ │ │ │ │ - * projection of the layer. │ │ │ │ │ + * APIProperty: dragPanOptions │ │ │ │ │ + * {Object} Options passed to the DragPan control. │ │ │ │ │ + */ │ │ │ │ │ + dragPanOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: pinchZoom │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + pinchZoom: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: pinchZoomOptions │ │ │ │ │ + * {Object} Options passed to the PinchZoom control. │ │ │ │ │ + */ │ │ │ │ │ + pinchZoomOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: documentDrag │ │ │ │ │ + * {Boolean} Allow panning of the map by dragging outside map viewport. │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + documentDrag: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: zoomBox │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + zoomBox: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomBoxEnabled │ │ │ │ │ + * {Boolean} Whether the user can draw a box to zoom │ │ │ │ │ + */ │ │ │ │ │ + zoomBoxEnabled: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomWheelEnabled │ │ │ │ │ + * {Boolean} Whether the mousewheel should zoom the map │ │ │ │ │ + */ │ │ │ │ │ + zoomWheelEnabled: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: mouseWheelOptions │ │ │ │ │ + * {Object} Options passed to the MouseWheel control (only useful if │ │ │ │ │ + * is set to true). Default is no options for maps │ │ │ │ │ + * with fractionalZoom set to true, otherwise │ │ │ │ │ + * {cumulative: false, interval: 50, maxDelta: 6} │ │ │ │ │ + */ │ │ │ │ │ + mouseWheelOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: handleRightClicks │ │ │ │ │ + * {Boolean} Whether or not to handle right clicks. Default is false. │ │ │ │ │ + */ │ │ │ │ │ + handleRightClicks: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: zoomBoxKeyMask │ │ │ │ │ + * {Integer} key code of the key, which has to be │ │ │ │ │ + * pressed, while drawing the zoom box with the mouse on the screen. │ │ │ │ │ + * You should probably set handleRightClicks to true if you use this │ │ │ │ │ + * with MOD_CTRL, to disable the context menu for machines which use │ │ │ │ │ + * CTRL-Click as a right click. │ │ │ │ │ + * Default: │ │ │ │ │ + */ │ │ │ │ │ + zoomBoxKeyMask: OpenLayers.Handler.MOD_SHIFT, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: autoActivate │ │ │ │ │ + * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ + * true. │ │ │ │ │ + */ │ │ │ │ │ + autoActivate: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.Navigation │ │ │ │ │ + * Create a new navigation control │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} true if the axis order is reversed, false otherwise. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * the control │ │ │ │ │ */ │ │ │ │ │ - reverseAxisOrder: function() { │ │ │ │ │ - var projCode = this.projection.getCode(); │ │ │ │ │ - return parseFloat(this.params.VERSION) >= 1.3 && │ │ │ │ │ - !!(this.yx[projCode] || (OpenLayers.Projection.defaults[projCode] && │ │ │ │ │ - OpenLayers.Projection.defaults[projCode].yx)); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + this.handlers = {}; │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ - * Return a GetMap query string for this layer │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * The destroy method is used to perform any clean up before the control │ │ │ │ │ + * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ + * to prevent memory leaks. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + │ │ │ │ │ + if (this.dragPan) { │ │ │ │ │ + this.dragPan.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.dragPan = null; │ │ │ │ │ + │ │ │ │ │ + if (this.zoomBox) { │ │ │ │ │ + this.zoomBox.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.zoomBox = null; │ │ │ │ │ + │ │ │ │ │ + if (this.pinchZoom) { │ │ │ │ │ + this.pinchZoom.destroy(); │ │ │ │ │ + } │ │ │ │ │ + this.pinchZoom = null; │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: activate │ │ │ │ │ + */ │ │ │ │ │ + activate: function() { │ │ │ │ │ + this.dragPan.activate(); │ │ │ │ │ + if (this.zoomWheelEnabled) { │ │ │ │ │ + this.handlers.wheel.activate(); │ │ │ │ │ + } │ │ │ │ │ + this.handlers.click.activate(); │ │ │ │ │ + if (this.zoomBoxEnabled) { │ │ │ │ │ + this.zoomBox.activate(); │ │ │ │ │ + } │ │ │ │ │ + if (this.pinchZoom) { │ │ │ │ │ + this.pinchZoom.activate(); │ │ │ │ │ + } │ │ │ │ │ + return OpenLayers.Control.prototype.activate.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (this.pinchZoom) { │ │ │ │ │ + this.pinchZoom.deactivate(); │ │ │ │ │ + } │ │ │ │ │ + this.zoomBox.deactivate(); │ │ │ │ │ + this.dragPan.deactivate(); │ │ │ │ │ + this.handlers.click.deactivate(); │ │ │ │ │ + this.handlers.wheel.deactivate(); │ │ │ │ │ + return OpenLayers.Control.prototype.deactivate.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ + */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + // disable right mouse context menu for support of right click events │ │ │ │ │ + if (this.handleRightClicks) { │ │ │ │ │ + this.map.viewPortDiv.oncontextmenu = OpenLayers.Function.False; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var clickCallbacks = { │ │ │ │ │ + 'click': this.defaultClick, │ │ │ │ │ + 'dblclick': this.defaultDblClick, │ │ │ │ │ + 'dblrightclick': this.defaultDblRightClick │ │ │ │ │ + }; │ │ │ │ │ + var clickOptions = { │ │ │ │ │ + 'double': true, │ │ │ │ │ + 'stopDouble': true │ │ │ │ │ + }; │ │ │ │ │ + this.handlers.click = new OpenLayers.Handler.Click( │ │ │ │ │ + this, clickCallbacks, clickOptions │ │ │ │ │ + ); │ │ │ │ │ + this.dragPan = new OpenLayers.Control.DragPan( │ │ │ │ │ + OpenLayers.Util.extend({ │ │ │ │ │ + map: this.map, │ │ │ │ │ + documentDrag: this.documentDrag │ │ │ │ │ + }, this.dragPanOptions) │ │ │ │ │ + ); │ │ │ │ │ + this.zoomBox = new OpenLayers.Control.ZoomBox({ │ │ │ │ │ + map: this.map, │ │ │ │ │ + keyMask: this.zoomBoxKeyMask │ │ │ │ │ + }); │ │ │ │ │ + this.dragPan.draw(); │ │ │ │ │ + this.zoomBox.draw(); │ │ │ │ │ + var wheelOptions = this.map.fractionalZoom ? {} : { │ │ │ │ │ + cumulative: false, │ │ │ │ │ + interval: 50, │ │ │ │ │ + maxDelta: 6 │ │ │ │ │ + }; │ │ │ │ │ + this.handlers.wheel = new OpenLayers.Handler.MouseWheel( │ │ │ │ │ + this, { │ │ │ │ │ + up: this.wheelUp, │ │ │ │ │ + down: this.wheelDown │ │ │ │ │ + }, │ │ │ │ │ + OpenLayers.Util.extend(wheelOptions, this.mouseWheelOptions) │ │ │ │ │ + ); │ │ │ │ │ + if (OpenLayers.Control.PinchZoom) { │ │ │ │ │ + this.pinchZoom = new OpenLayers.Control.PinchZoom( │ │ │ │ │ + OpenLayers.Util.extend({ │ │ │ │ │ + map: this.map │ │ │ │ │ + }, this.pinchZoomOptions)); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: defaultClick │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} A bounds representing the bbox for the │ │ │ │ │ - * request. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string with the layer's url and parameters and also the │ │ │ │ │ - * passed-in bounds and appropriate tile size specified as │ │ │ │ │ - * parameters. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - bounds = this.adjustBounds(bounds); │ │ │ │ │ - │ │ │ │ │ - var imageSize = this.getImageSize(); │ │ │ │ │ - var newParams = {}; │ │ │ │ │ - // WMS 1.3 introduced axis order │ │ │ │ │ - var reverseAxisOrder = this.reverseAxisOrder(); │ │ │ │ │ - newParams.BBOX = this.encodeBBOX ? │ │ │ │ │ - bounds.toBBOX(null, reverseAxisOrder) : │ │ │ │ │ - bounds.toArray(reverseAxisOrder); │ │ │ │ │ - newParams.WIDTH = imageSize.w; │ │ │ │ │ - newParams.HEIGHT = imageSize.h; │ │ │ │ │ - var requestString = this.getFullRequestString(newParams); │ │ │ │ │ - return requestString; │ │ │ │ │ + defaultClick: function(evt) { │ │ │ │ │ + if (evt.lastTouches && evt.lastTouches.length == 2) { │ │ │ │ │ + this.map.zoomOut(); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: mergeNewParams │ │ │ │ │ - * Catch changeParams and uppercase the new params to be merged in │ │ │ │ │ - * before calling changeParams on the super class. │ │ │ │ │ + * Method: defaultDblClick │ │ │ │ │ * │ │ │ │ │ - * Once params have been changed, the tiles will be reloaded with │ │ │ │ │ - * the new parameters. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + */ │ │ │ │ │ + defaultDblClick: function(evt) { │ │ │ │ │ + this.map.zoomTo(this.map.zoom + 1, evt.xy); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: defaultDblRightClick │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * newParams - {Object} Hashtable of new params to use │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - mergeNewParams: function(newParams) { │ │ │ │ │ - var upperParams = OpenLayers.Util.upperCaseObject(newParams); │ │ │ │ │ - var newArguments = [upperParams]; │ │ │ │ │ - return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, │ │ │ │ │ - newArguments); │ │ │ │ │ + defaultDblRightClick: function(evt) { │ │ │ │ │ + this.map.zoomTo(this.map.zoom - 1, evt.xy); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getFullRequestString │ │ │ │ │ - * Combine the layer's url with its params and these newParams. │ │ │ │ │ - * │ │ │ │ │ - * Add the SRS parameter from projection -- this is probably │ │ │ │ │ - * more eloquently done via a setProjection() method, but this │ │ │ │ │ - * works for now and always. │ │ │ │ │ + /** │ │ │ │ │ + * Method: wheelChange │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * newParams - {Object} │ │ │ │ │ - * altUrl - {String} Use this as the url instead of the layer's url │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * deltaZ - {Integer} │ │ │ │ │ */ │ │ │ │ │ - getFullRequestString: function(newParams, altUrl) { │ │ │ │ │ - var mapProjection = this.map.getProjectionObject(); │ │ │ │ │ - var projectionCode = this.projection && this.projection.equals(mapProjection) ? │ │ │ │ │ - this.projection.getCode() : │ │ │ │ │ - mapProjection.getCode(); │ │ │ │ │ - var value = (projectionCode == "none") ? null : projectionCode; │ │ │ │ │ - if (parseFloat(this.params.VERSION) >= 1.3) { │ │ │ │ │ - this.params.CRS = value; │ │ │ │ │ - } else { │ │ │ │ │ - this.params.SRS = value; │ │ │ │ │ + wheelChange: function(evt, deltaZ) { │ │ │ │ │ + if (!this.map.fractionalZoom) { │ │ │ │ │ + deltaZ = Math.round(deltaZ); │ │ │ │ │ + } │ │ │ │ │ + var currentZoom = this.map.getZoom(), │ │ │ │ │ + newZoom = currentZoom + deltaZ; │ │ │ │ │ + newZoom = Math.max(newZoom, 0); │ │ │ │ │ + newZoom = Math.min(newZoom, this.map.getNumZoomLevels()); │ │ │ │ │ + if (newZoom === currentZoom) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ + this.map.zoomTo(newZoom, evt.xy); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (typeof this.params.TRANSPARENT == "boolean") { │ │ │ │ │ - newParams.TRANSPARENT = this.params.TRANSPARENT ? "TRUE" : "FALSE"; │ │ │ │ │ + /** │ │ │ │ │ + * Method: wheelUp │ │ │ │ │ + * User spun scroll wheel up │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * delta - {Integer} │ │ │ │ │ + */ │ │ │ │ │ + wheelUp: function(evt, delta) { │ │ │ │ │ + this.wheelChange(evt, delta || 1); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: wheelDown │ │ │ │ │ + * User spun scroll wheel down │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ + * delta - {Integer} │ │ │ │ │ + */ │ │ │ │ │ + wheelDown: function(evt, delta) { │ │ │ │ │ + this.wheelChange(evt, delta || -1); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: disableZoomBox │ │ │ │ │ + */ │ │ │ │ │ + disableZoomBox: function() { │ │ │ │ │ + this.zoomBoxEnabled = false; │ │ │ │ │ + this.zoomBox.deactivate(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: enableZoomBox │ │ │ │ │ + */ │ │ │ │ │ + enableZoomBox: function() { │ │ │ │ │ + this.zoomBoxEnabled = true; │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.zoomBox.activate(); │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply( │ │ │ │ │ - this, arguments); │ │ │ │ │ + /** │ │ │ │ │ + * Method: disableZoomWheel │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + disableZoomWheel: function() { │ │ │ │ │ + this.zoomWheelEnabled = false; │ │ │ │ │ + this.handlers.wheel.deactivate(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.WMS" │ │ │ │ │ + /** │ │ │ │ │ + * Method: enableZoomWheel │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + enableZoomWheel: function() { │ │ │ │ │ + this.zoomWheelEnabled = true; │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.handlers.wheel.activate(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Navigation" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/RegularPolygon.js │ │ │ │ │ + OpenLayers/Handler/Point.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ + * @requires OpenLayers/Handler.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Handler.RegularPolygon │ │ │ │ │ - * Handler to draw a regular polygon on the map. Polygon is displayed on mouse │ │ │ │ │ - * down, moves or is modified on mouse move, and is finished on mouse up. │ │ │ │ │ - * The handler triggers callbacks for 'done' and 'cancel'. Create a new │ │ │ │ │ - * instance with the constructor. │ │ │ │ │ + * Class: OpenLayers.Handler.Point │ │ │ │ │ + * Handler to draw a point on the map. Point is displayed on activation, │ │ │ │ │ + * moves on mouse move, and is finished on mouse up. The handler triggers │ │ │ │ │ + * callbacks for 'done', 'cancel', and 'modify'. The modify callback is │ │ │ │ │ + * called with each change in the sketch and will receive the latest point │ │ │ │ │ + * drawn. Create a new instance with the │ │ │ │ │ + * constructor. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, { │ │ │ │ │ +OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: sides │ │ │ │ │ - * {Integer} Number of sides for the regular polygon. Needs to be greater │ │ │ │ │ - * than 2. Defaults to 4. │ │ │ │ │ + * Property: point │ │ │ │ │ + * {} The currently drawn point │ │ │ │ │ */ │ │ │ │ │ - sides: 4, │ │ │ │ │ + point: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: radius │ │ │ │ │ - * {Float} Optional radius in map units of the regular polygon. If this is │ │ │ │ │ - * set to some non-zero value, a polygon with a fixed radius will be │ │ │ │ │ - * drawn and dragged with mose movements. If this property is not │ │ │ │ │ - * set, dragging changes the radius of the polygon. Set to null by │ │ │ │ │ - * default. │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} The temporary drawing layer │ │ │ │ │ */ │ │ │ │ │ - radius: null, │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: snapAngle │ │ │ │ │ - * {Float} If set to a non-zero value, the handler will snap the polygon │ │ │ │ │ - * rotation to multiples of the snapAngle. Value is an angle measured │ │ │ │ │ - * in degrees counterclockwise from the positive x-axis. │ │ │ │ │ + * APIProperty: multi │ │ │ │ │ + * {Boolean} Cast features to multi-part geometries before passing to the │ │ │ │ │ + * layer. Default is false. │ │ │ │ │ */ │ │ │ │ │ - snapAngle: null, │ │ │ │ │ + multi: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: snapToggle │ │ │ │ │ - * {String} If set, snapToggle is checked on mouse events and will set │ │ │ │ │ - * the snap mode to the opposite of what it currently is. To disallow │ │ │ │ │ - * toggling between snap and non-snap mode, set freehandToggle to │ │ │ │ │ - * null. Acceptable toggle values are 'shiftKey', 'ctrlKey', and │ │ │ │ │ - * 'altKey'. Snap mode is only possible if this.snapAngle is set to a │ │ │ │ │ - * non-zero value. │ │ │ │ │ + * APIProperty: citeCompliant │ │ │ │ │ + * {Boolean} If set to true, coordinates of features drawn in a map extent │ │ │ │ │ + * crossing the date line won't exceed the world bounds. Default is false. │ │ │ │ │ */ │ │ │ │ │ - snapToggle: 'shiftKey', │ │ │ │ │ + citeCompliant: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layerOptions │ │ │ │ │ - * {Object} Any optional properties to be set on the sketch layer. │ │ │ │ │ + * Property: mouseDown │ │ │ │ │ + * {Boolean} The mouse is down │ │ │ │ │ */ │ │ │ │ │ - layerOptions: null, │ │ │ │ │ + mouseDown: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: persist │ │ │ │ │ - * {Boolean} Leave the feature rendered until clear is called. Default │ │ │ │ │ - * is false. If set to true, the feature remains rendered until │ │ │ │ │ - * clear is called, typically by deactivating the handler or starting │ │ │ │ │ - * another drawing. │ │ │ │ │ + * Property: stoppedDown │ │ │ │ │ + * {Boolean} Indicate whether the last mousedown stopped the event │ │ │ │ │ + * propagation. │ │ │ │ │ */ │ │ │ │ │ - persist: false, │ │ │ │ │ + stoppedDown: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: irregular │ │ │ │ │ - * {Boolean} Draw an irregular polygon instead of a regular polygon. │ │ │ │ │ - * Default is false. If true, the initial mouse down will represent │ │ │ │ │ - * one corner of the polygon bounds and with each mouse movement, the │ │ │ │ │ - * polygon will be stretched so the opposite corner of its bounds │ │ │ │ │ - * follows the mouse position. This property takes precedence over │ │ │ │ │ - * the radius property. If set to true, the radius property will │ │ │ │ │ - * be ignored. │ │ │ │ │ + * Property: lastDown │ │ │ │ │ + * {} Location of the last mouse down │ │ │ │ │ */ │ │ │ │ │ - irregular: false, │ │ │ │ │ + lastDown: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: citeCompliant │ │ │ │ │ - * {Boolean} If set to true, coordinates of features drawn in a map extent │ │ │ │ │ - * crossing the date line won't exceed the world bounds. Default is false. │ │ │ │ │ + * Property: lastUp │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - citeCompliant: false, │ │ │ │ │ + lastUp: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: angle │ │ │ │ │ - * {Float} The angle from the origin (mouse down) to the current mouse │ │ │ │ │ - * position, in radians. This is measured counterclockwise from the │ │ │ │ │ - * positive x-axis. │ │ │ │ │ + * APIProperty: persist │ │ │ │ │ + * {Boolean} Leave the feature rendered until destroyFeature is called. │ │ │ │ │ + * Default is false. If set to true, the feature remains rendered until │ │ │ │ │ + * destroyFeature is called, typically by deactivating the handler or │ │ │ │ │ + * starting another drawing. │ │ │ │ │ */ │ │ │ │ │ - angle: null, │ │ │ │ │ + persist: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: fixedRadius │ │ │ │ │ - * {Boolean} The polygon has a fixed radius. True if a radius is set before │ │ │ │ │ - * drawing begins. False otherwise. │ │ │ │ │ + * APIProperty: stopDown │ │ │ │ │ + * {Boolean} Stop event propagation on mousedown. Must be false to │ │ │ │ │ + * allow "pan while drawing". Defaults to false. │ │ │ │ │ */ │ │ │ │ │ - fixedRadius: false, │ │ │ │ │ + stopDown: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: feature │ │ │ │ │ - * {} The currently drawn polygon feature │ │ │ │ │ + * APIPropery: stopUp │ │ │ │ │ + * {Boolean} Stop event propagation on mouse. Must be false to │ │ │ │ │ + * allow "pan while dragging". Defaults to fase. │ │ │ │ │ */ │ │ │ │ │ - feature: null, │ │ │ │ │ + stopUp: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} The temporary drawing layer │ │ │ │ │ + * Property: layerOptions │ │ │ │ │ + * {Object} Any optional properties to be set on the sketch layer. │ │ │ │ │ */ │ │ │ │ │ - layer: null, │ │ │ │ │ + layerOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: origin │ │ │ │ │ - * {} Location of the first mouse down │ │ │ │ │ + * APIProperty: pixelTolerance │ │ │ │ │ + * {Number} Maximum number of pixels between down and up (mousedown │ │ │ │ │ + * and mouseup, or touchstart and touchend) for the handler to │ │ │ │ │ + * add a new point. If set to an integer value, if the │ │ │ │ │ + * displacement between down and up is great to this value │ │ │ │ │ + * no point will be added. Default value is 5. │ │ │ │ │ */ │ │ │ │ │ - origin: null, │ │ │ │ │ + pixelTolerance: 5, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.RegularPolygon │ │ │ │ │ - * Create a new regular polygon handler. │ │ │ │ │ + * Property: lastTouchPx │ │ │ │ │ + * {} The last pixel used to know the distance between │ │ │ │ │ + * two touches (for double touch). │ │ │ │ │ + */ │ │ │ │ │ + lastTouchPx: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Handler.Point │ │ │ │ │ + * Create a new point handler. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ * control - {} The control that owns this handler │ │ │ │ │ * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ * functions. Various callbacks described below. │ │ │ │ │ - * options - {Object} An object with properties to be set on the handler. │ │ │ │ │ - * If the options.sides property is not specified, the number of sides │ │ │ │ │ - * will default to 4. │ │ │ │ │ + * options - {Object} An optional object with properties to be set on the │ │ │ │ │ + * handler │ │ │ │ │ * │ │ │ │ │ * Named callbacks: │ │ │ │ │ * create - Called when a sketch is first created. Callback called with │ │ │ │ │ * the creation point geometry and sketch feature. │ │ │ │ │ - * done - Called when the sketch drawing is finished. The callback will │ │ │ │ │ - * recieve a single argument, the sketch geometry. │ │ │ │ │ + * modify - Called with each move of a vertex with the vertex (point) │ │ │ │ │ + * geometry and the sketch feature. │ │ │ │ │ + * done - Called when the point drawing is finished. The callback will │ │ │ │ │ + * recieve a single argument, the point geometry. │ │ │ │ │ * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ * cancel callback will receive a geometry. │ │ │ │ │ */ │ │ │ │ │ initialize: function(control, callbacks, options) { │ │ │ │ │ if (!(options && options.layerOptions && options.layerOptions.styleMap)) { │ │ │ │ │ this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {}); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - OpenLayers.Handler.Drag.prototype.initialize.apply(this, │ │ │ │ │ - [control, callbacks, options]); │ │ │ │ │ - this.options = (options) ? options : {}; │ │ │ │ │ + OpenLayers.Handler.prototype.initialize.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setOptions │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * newOptions - {Object} │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * turn on the handler │ │ │ │ │ */ │ │ │ │ │ - setOptions: function(newOptions) { │ │ │ │ │ - OpenLayers.Util.extend(this.options, newOptions); │ │ │ │ │ - OpenLayers.Util.extend(this, newOptions); │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (!OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + // create temporary vector layer for rendering geometry sketch │ │ │ │ │ + // TBD: this could be moved to initialize/destroy - setting visibility here │ │ │ │ │ + var options = OpenLayers.Util.extend({ │ │ │ │ │ + displayInLayerSwitcher: false, │ │ │ │ │ + // indicate that the temp vector layer will never be out of range │ │ │ │ │ + // without this, resolution properties must be specified at the │ │ │ │ │ + // map-level for this temporary layer to init its resolutions │ │ │ │ │ + // correctly │ │ │ │ │ + calculateInRange: OpenLayers.Function.True, │ │ │ │ │ + wrapDateLine: this.citeCompliant │ │ │ │ │ + }, this.layerOptions); │ │ │ │ │ + this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); │ │ │ │ │ + this.map.addLayer(this.layer); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Turn on the handler. │ │ │ │ │ + * Method: createFeature │ │ │ │ │ + * Add temporary features │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully activated │ │ │ │ │ + * Parameters: │ │ │ │ │ + * pixel - {} A pixel location on the map. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Handler.Drag.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - // create temporary vector layer for rendering geometry sketch │ │ │ │ │ - var options = OpenLayers.Util.extend({ │ │ │ │ │ - displayInLayerSwitcher: false, │ │ │ │ │ - // indicate that the temp vector layer will never be out of range │ │ │ │ │ - // without this, resolution properties must be specified at the │ │ │ │ │ - // map-level for this temporary layer to init its resolutions │ │ │ │ │ - // correctly │ │ │ │ │ - calculateInRange: OpenLayers.Function.True, │ │ │ │ │ - wrapDateLine: this.citeCompliant │ │ │ │ │ - }, this.layerOptions); │ │ │ │ │ - this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); │ │ │ │ │ - this.map.addLayer(this.layer); │ │ │ │ │ - activated = true; │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ + createFeature: function(pixel) { │ │ │ │ │ + var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ + var geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ + lonlat.lon, lonlat.lat │ │ │ │ │ + ); │ │ │ │ │ + this.point = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ + this.callback("create", [this.point.geometry, this.point]); │ │ │ │ │ + this.point.geometry.clearBounds(); │ │ │ │ │ + this.layer.addFeatures([this.point], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIMethod: deactivate │ │ │ │ │ - * Turn off the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated │ │ │ │ │ + * turn off the handler │ │ │ │ │ */ │ │ │ │ │ deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.Drag.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - // call the cancel callback if mid-drawing │ │ │ │ │ - if (this.dragging) { │ │ │ │ │ - this.cancel(); │ │ │ │ │ - } │ │ │ │ │ - // If a layer's map property is set to null, it means that that │ │ │ │ │ - // layer isn't added to the map. Since we ourself added the layer │ │ │ │ │ - // to the map in activate(), we can assume that if this.layer.map │ │ │ │ │ - // is null it means that the layer has been destroyed (as a result │ │ │ │ │ - // of map.destroy() for example. │ │ │ │ │ - if (this.layer.map != null) { │ │ │ │ │ - this.layer.destroy(false); │ │ │ │ │ - if (this.feature) { │ │ │ │ │ - this.feature.destroy(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.layer = null; │ │ │ │ │ - this.feature = null; │ │ │ │ │ - deactivated = true; │ │ │ │ │ + if (!OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + this.cancel(); │ │ │ │ │ + // If a layer's map property is set to null, it means that that layer │ │ │ │ │ + // isn't added to the map. Since we ourself added the layer to the map │ │ │ │ │ + // in activate(), we can assume that if this.layer.map is null it means │ │ │ │ │ + // that the layer has been destroyed (as a result of map.destroy() for │ │ │ │ │ + // example. │ │ │ │ │ + if (this.layer.map != null) { │ │ │ │ │ + this.destroyFeature(true); │ │ │ │ │ + this.layer.destroy(false); │ │ │ │ │ + } │ │ │ │ │ + this.layer = null; │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: down │ │ │ │ │ - * Start drawing a new feature │ │ │ │ │ + * Method: destroyFeature │ │ │ │ │ + * Destroy the temporary geometries │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The drag start event │ │ │ │ │ + * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ */ │ │ │ │ │ - down: function(evt) { │ │ │ │ │ - this.fixedRadius = !!(this.radius); │ │ │ │ │ - var maploc = this.layer.getLonLatFromViewPortPx(evt.xy); │ │ │ │ │ - this.origin = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat); │ │ │ │ │ - // create the new polygon │ │ │ │ │ - if (!this.fixedRadius || this.irregular) { │ │ │ │ │ - // smallest radius should not be less one pixel in map units │ │ │ │ │ - // VML doesn't behave well with smaller │ │ │ │ │ - this.radius = this.map.getResolution(); │ │ │ │ │ + destroyFeature: function(force) { │ │ │ │ │ + if (this.layer && (force || !this.persist)) { │ │ │ │ │ + this.layer.destroyFeatures(); │ │ │ │ │ } │ │ │ │ │ - if (this.persist) { │ │ │ │ │ - this.clear(); │ │ │ │ │ + this.point = null; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroyPersistedFeature │ │ │ │ │ + * Destroy the persisted feature. │ │ │ │ │ + */ │ │ │ │ │ + destroyPersistedFeature: function() { │ │ │ │ │ + var layer = this.layer; │ │ │ │ │ + if (layer && layer.features.length > 1) { │ │ │ │ │ + this.layer.features[0].destroy(); │ │ │ │ │ } │ │ │ │ │ - this.feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ - this.createGeometry(); │ │ │ │ │ - this.callback("create", [this.origin, this.feature]); │ │ │ │ │ - this.layer.addFeatures([this.feature], { │ │ │ │ │ - silent: true │ │ │ │ │ - }); │ │ │ │ │ - this.layer.drawFeature(this.feature, this.style); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: move │ │ │ │ │ - * Respond to drag move events │ │ │ │ │ + * Method: finalize │ │ │ │ │ + * Finish the geometry and call the "done" callback. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Evt} The move event │ │ │ │ │ + * cancel - {Boolean} Call cancel instead of done callback. Default │ │ │ │ │ + * is false. │ │ │ │ │ */ │ │ │ │ │ - move: function(evt) { │ │ │ │ │ - var maploc = this.layer.getLonLatFromViewPortPx(evt.xy); │ │ │ │ │ - var point = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat); │ │ │ │ │ - if (this.irregular) { │ │ │ │ │ - var ry = Math.sqrt(2) * Math.abs(point.y - this.origin.y) / 2; │ │ │ │ │ - this.radius = Math.max(this.map.getResolution() / 2, ry); │ │ │ │ │ - } else if (this.fixedRadius) { │ │ │ │ │ - this.origin = point; │ │ │ │ │ - } else { │ │ │ │ │ - this.calculateAngle(point, evt); │ │ │ │ │ - this.radius = Math.max(this.map.getResolution() / 2, │ │ │ │ │ - point.distanceTo(this.origin)); │ │ │ │ │ - } │ │ │ │ │ - this.modifyGeometry(); │ │ │ │ │ - if (this.irregular) { │ │ │ │ │ - var dx = point.x - this.origin.x; │ │ │ │ │ - var dy = point.y - this.origin.y; │ │ │ │ │ - var ratio; │ │ │ │ │ - if (dy == 0) { │ │ │ │ │ - ratio = dx / (this.radius * Math.sqrt(2)); │ │ │ │ │ - } else { │ │ │ │ │ - ratio = dx / dy; │ │ │ │ │ - } │ │ │ │ │ - this.feature.geometry.resize(1, this.origin, ratio); │ │ │ │ │ - this.feature.geometry.move(dx / 2, dy / 2); │ │ │ │ │ - } │ │ │ │ │ - this.layer.drawFeature(this.feature, this.style); │ │ │ │ │ + finalize: function(cancel) { │ │ │ │ │ + var key = cancel ? "cancel" : "done"; │ │ │ │ │ + this.mouseDown = false; │ │ │ │ │ + this.lastDown = null; │ │ │ │ │ + this.lastUp = null; │ │ │ │ │ + this.lastTouchPx = null; │ │ │ │ │ + this.callback(key, [this.geometryClone()]); │ │ │ │ │ + this.destroyFeature(cancel); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: up │ │ │ │ │ - * Finish drawing the feature │ │ │ │ │ + * APIMethod: cancel │ │ │ │ │ + * Finish the geometry and call the "cancel" callback. │ │ │ │ │ + */ │ │ │ │ │ + cancel: function() { │ │ │ │ │ + this.finalize(true); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: click │ │ │ │ │ + * Handle clicks. Clicks are stopped from propagating to other listeners │ │ │ │ │ + * on map.events or other dom elements. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ + */ │ │ │ │ │ + click: function(evt) { │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: dblclick │ │ │ │ │ + * Handle double-clicks. Double-clicks are stopped from propagating to other │ │ │ │ │ + * listeners on map.events or other dom elements. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ + */ │ │ │ │ │ + dblclick: function(evt) { │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: modifyFeature │ │ │ │ │ + * Modify the existing geometry given a pixel location. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The mouse up event │ │ │ │ │ + * pixel - {} A pixel location on the map. │ │ │ │ │ */ │ │ │ │ │ - up: function(evt) { │ │ │ │ │ - this.finalize(); │ │ │ │ │ - // the mouseup method of superclass doesn't call the │ │ │ │ │ - // "done" callback if there's been no move between │ │ │ │ │ - // down and up │ │ │ │ │ - if (this.start == this.last) { │ │ │ │ │ - this.callback("done", [evt.xy]); │ │ │ │ │ + modifyFeature: function(pixel) { │ │ │ │ │ + if (!this.point) { │ │ │ │ │ + this.createFeature(pixel); │ │ │ │ │ } │ │ │ │ │ + var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ + this.point.geometry.x = lonlat.lon; │ │ │ │ │ + this.point.geometry.y = lonlat.lat; │ │ │ │ │ + this.callback("modify", [this.point.geometry, this.point, false]); │ │ │ │ │ + this.point.geometry.clearBounds(); │ │ │ │ │ + this.drawFeature(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: out │ │ │ │ │ - * Finish drawing the feature. │ │ │ │ │ + * Method: drawFeature │ │ │ │ │ + * Render features on the temporary layer. │ │ │ │ │ + */ │ │ │ │ │ + drawFeature: function() { │ │ │ │ │ + this.layer.drawFeature(this.point, this.style); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getGeometry │ │ │ │ │ + * Return the sketch geometry. If is true, this will return │ │ │ │ │ + * a multi-part geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getGeometry: function() { │ │ │ │ │ + var geometry = this.point && this.point.geometry; │ │ │ │ │ + if (geometry && this.multi) { │ │ │ │ │ + geometry = new OpenLayers.Geometry.MultiPoint([geometry]); │ │ │ │ │ + } │ │ │ │ │ + return geometry; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: geometryClone │ │ │ │ │ + * Return a clone of the relevant geometry. │ │ │ │ │ * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + geometryClone: function() { │ │ │ │ │ + var geom = this.getGeometry(); │ │ │ │ │ + return geom && geom.clone(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: mousedown │ │ │ │ │ + * Handle mousedown. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} The mouse out event │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ */ │ │ │ │ │ - out: function(evt) { │ │ │ │ │ - this.finalize(); │ │ │ │ │ + mousedown: function(evt) { │ │ │ │ │ + return this.down(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createGeometry │ │ │ │ │ - * Create the new polygon geometry. This is called at the start of the │ │ │ │ │ - * drag and at any point during the drag if the number of sides │ │ │ │ │ - * changes. │ │ │ │ │ + * Method: touchstart │ │ │ │ │ + * Handle touchstart. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ */ │ │ │ │ │ - createGeometry: function() { │ │ │ │ │ - this.angle = Math.PI * ((1 / this.sides) - (1 / 2)); │ │ │ │ │ - if (this.snapAngle) { │ │ │ │ │ - this.angle += this.snapAngle * (Math.PI / 180); │ │ │ │ │ - } │ │ │ │ │ - this.feature.geometry = OpenLayers.Geometry.Polygon.createRegularPolygon( │ │ │ │ │ - this.origin, this.radius, this.sides, this.snapAngle │ │ │ │ │ - ); │ │ │ │ │ + touchstart: function(evt) { │ │ │ │ │ + this.startTouch(); │ │ │ │ │ + this.lastTouchPx = evt.xy; │ │ │ │ │ + return this.down(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: modifyGeometry │ │ │ │ │ - * Modify the polygon geometry in place. │ │ │ │ │ + * Method: mousemove │ │ │ │ │ + * Handle mousemove. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ */ │ │ │ │ │ - modifyGeometry: function() { │ │ │ │ │ - var angle, point; │ │ │ │ │ - var ring = this.feature.geometry.components[0]; │ │ │ │ │ - // if the number of sides ever changes, create a new geometry │ │ │ │ │ - if (ring.components.length != (this.sides + 1)) { │ │ │ │ │ - this.createGeometry(); │ │ │ │ │ - ring = this.feature.geometry.components[0]; │ │ │ │ │ - } │ │ │ │ │ - for (var i = 0; i < this.sides; ++i) { │ │ │ │ │ - point = ring.components[i]; │ │ │ │ │ - angle = this.angle + (i * 2 * Math.PI / this.sides); │ │ │ │ │ - point.x = this.origin.x + (this.radius * Math.cos(angle)); │ │ │ │ │ - point.y = this.origin.y + (this.radius * Math.sin(angle)); │ │ │ │ │ - point.clearBounds(); │ │ │ │ │ - } │ │ │ │ │ + mousemove: function(evt) { │ │ │ │ │ + return this.move(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: calculateAngle │ │ │ │ │ - * Calculate the angle based on settings. │ │ │ │ │ + * Method: touchmove │ │ │ │ │ + * Handle touchmove. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ + */ │ │ │ │ │ + touchmove: function(evt) { │ │ │ │ │ + this.lastTouchPx = evt.xy; │ │ │ │ │ + return this.move(evt); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: mouseup │ │ │ │ │ + * Handle mouseup. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * point - {} │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ */ │ │ │ │ │ - calculateAngle: function(point, evt) { │ │ │ │ │ - var alpha = Math.atan2(point.y - this.origin.y, │ │ │ │ │ - point.x - this.origin.x); │ │ │ │ │ - if (this.snapAngle && (this.snapToggle && !evt[this.snapToggle])) { │ │ │ │ │ - var snapAngleRad = (Math.PI / 180) * this.snapAngle; │ │ │ │ │ - this.angle = Math.round(alpha / snapAngleRad) * snapAngleRad; │ │ │ │ │ - } else { │ │ │ │ │ - this.angle = alpha; │ │ │ │ │ - } │ │ │ │ │ + mouseup: function(evt) { │ │ │ │ │ + return this.up(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Finish the geometry and call the "cancel" callback. │ │ │ │ │ + * Method: touchend │ │ │ │ │ + * Handle touchend. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - // the polygon geometry gets cloned in the callback method │ │ │ │ │ - this.callback("cancel", null); │ │ │ │ │ - this.finalize(); │ │ │ │ │ + touchend: function(evt) { │ │ │ │ │ + evt.xy = this.lastTouchPx; │ │ │ │ │ + return this.up(evt); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: finalize │ │ │ │ │ - * Finish the geometry and call the "done" callback. │ │ │ │ │ + * Method: down │ │ │ │ │ + * Handle mousedown and touchstart. Adjust the geometry and redraw. │ │ │ │ │ + * Return determines whether to propagate the event on the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ */ │ │ │ │ │ - finalize: function() { │ │ │ │ │ - this.origin = null; │ │ │ │ │ - this.radius = this.options.radius; │ │ │ │ │ + down: function(evt) { │ │ │ │ │ + this.mouseDown = true; │ │ │ │ │ + this.lastDown = evt.xy; │ │ │ │ │ + if (!this.touch) { // no point displayed until up on touch devices │ │ │ │ │ + this.modifyFeature(evt.xy); │ │ │ │ │ + } │ │ │ │ │ + this.stoppedDown = this.stopDown; │ │ │ │ │ + return !this.stopDown; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clear │ │ │ │ │ - * Clear any rendered features on the temporary layer. This is called │ │ │ │ │ - * when the handler is deactivated, canceled, or done (unless persist │ │ │ │ │ - * is true). │ │ │ │ │ + * Method: move │ │ │ │ │ + * Handle mousemove and touchmove. Adjust the geometry and redraw. │ │ │ │ │ + * Return determines whether to propagate the event on the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ */ │ │ │ │ │ - clear: function() { │ │ │ │ │ - if (this.layer) { │ │ │ │ │ - this.layer.renderer.clear(); │ │ │ │ │ - this.layer.destroyFeatures(); │ │ │ │ │ + move: function(evt) { │ │ │ │ │ + if (!this.touch // no point displayed until up on touch devices │ │ │ │ │ + && │ │ │ │ │ + (!this.mouseDown || this.stoppedDown)) { │ │ │ │ │ + this.modifyFeature(evt.xy); │ │ │ │ │ } │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: callback │ │ │ │ │ - * Trigger the control's named callback with the given arguments │ │ │ │ │ + * Method: up │ │ │ │ │ + * Handle mouseup and touchend. Send the latest point in the geometry to the control. │ │ │ │ │ + * Return determines whether to propagate the event on the map. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} The key for the callback that is one of the properties │ │ │ │ │ - * of the handler's callbacks object. │ │ │ │ │ - * args - {Array} An array of arguments with which to call the callback │ │ │ │ │ - * (defined by the control). │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ */ │ │ │ │ │ - callback: function(name, args) { │ │ │ │ │ - // override the callback method to always send the polygon geometry │ │ │ │ │ - if (this.callbacks[name]) { │ │ │ │ │ - this.callbacks[name].apply(this.control, │ │ │ │ │ - [this.feature.geometry.clone()]); │ │ │ │ │ + up: function(evt) { │ │ │ │ │ + this.mouseDown = false; │ │ │ │ │ + this.stoppedDown = this.stopDown; │ │ │ │ │ + │ │ │ │ │ + // check keyboard modifiers │ │ │ │ │ + if (!this.checkModifiers(evt)) { │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ - // since sketch features are added to the temporary layer │ │ │ │ │ - // they must be cleared here if done or cancel │ │ │ │ │ - if (!this.persist && (name == "done" || name == "cancel")) { │ │ │ │ │ - this.clear(); │ │ │ │ │ + // ignore double-clicks │ │ │ │ │ + if (this.lastUp && this.lastUp.equals(evt.xy)) { │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + if (this.lastDown && this.passesTolerance(this.lastDown, evt.xy, │ │ │ │ │ + this.pixelTolerance)) { │ │ │ │ │ + if (this.touch) { │ │ │ │ │ + this.modifyFeature(evt.xy); │ │ │ │ │ + } │ │ │ │ │ + if (this.persist) { │ │ │ │ │ + this.destroyPersistedFeature(); │ │ │ │ │ + } │ │ │ │ │ + this.lastUp = evt.xy; │ │ │ │ │ + this.finalize(); │ │ │ │ │ + return !this.stopUp; │ │ │ │ │ + } else { │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.RegularPolygon" │ │ │ │ │ + /** │ │ │ │ │ + * Method: mouseout │ │ │ │ │ + * Handle mouse out. For better user experience reset mouseDown │ │ │ │ │ + * and stoppedDown when the mouse leaves the map viewport. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + */ │ │ │ │ │ + mouseout: function(evt) { │ │ │ │ │ + if (OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { │ │ │ │ │ + this.stoppedDown = this.stopDown; │ │ │ │ │ + this.mouseDown = false; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: passesTolerance │ │ │ │ │ + * Determine whether the event is within the optional pixel tolerance. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The event is within the pixel tolerance (if specified). │ │ │ │ │ + */ │ │ │ │ │ + passesTolerance: function(pixel1, pixel2, tolerance) { │ │ │ │ │ + var passes = true; │ │ │ │ │ + │ │ │ │ │ + if (tolerance != null && pixel1 && pixel2) { │ │ │ │ │ + var dist = pixel1.distanceTo(pixel2); │ │ │ │ │ + if (dist > tolerance) { │ │ │ │ │ + passes = false; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return passes; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Point" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/SLD.js │ │ │ │ │ + OpenLayers/Handler/Path.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Format/XML/VersionedOGC.js │ │ │ │ │ - * @requires OpenLayers/Style.js │ │ │ │ │ - * @requires OpenLayers/Rule.js │ │ │ │ │ - * @requires OpenLayers/Filter/FeatureId.js │ │ │ │ │ - * @requires OpenLayers/Filter/Logical.js │ │ │ │ │ - * @requires OpenLayers/Filter/Comparison.js │ │ │ │ │ - * @requires OpenLayers/Filter/Spatial.js │ │ │ │ │ + * @requires OpenLayers/Handler/Point.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + * @requires OpenLayers/Geometry/LineString.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.SLD │ │ │ │ │ - * Read/Write SLD. Create a new instance with the │ │ │ │ │ - * constructor. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Handler.Path │ │ │ │ │ + * Handler to draw a path on the map. Path is displayed on mouse down, │ │ │ │ │ + * moves on mouse move, and is finished on mouse up. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, { │ │ │ │ │ +OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: profile │ │ │ │ │ - * {String} If provided, use a custom profile. │ │ │ │ │ - * │ │ │ │ │ - * Currently supported profiles: │ │ │ │ │ - * - GeoServer - parses GeoServer vendor specific capabilities for SLD. │ │ │ │ │ + * Property: line │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - profile: null, │ │ │ │ │ + line: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: defaultVersion │ │ │ │ │ - * {String} Version number to assume if none found. Default is "1.0.0". │ │ │ │ │ + * APIProperty: maxVertices │ │ │ │ │ + * {Number} The maximum number of vertices which can be drawn by this │ │ │ │ │ + * handler. When the number of vertices reaches maxVertices, the │ │ │ │ │ + * geometry is automatically finalized. Default is null. │ │ │ │ │ */ │ │ │ │ │ - defaultVersion: "1.0.0", │ │ │ │ │ + maxVertices: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: stringifyOutput │ │ │ │ │ - * {Boolean} If true, write will return a string otherwise a DOMElement. │ │ │ │ │ - * Default is true. │ │ │ │ │ + * Property: doubleTouchTolerance │ │ │ │ │ + * {Number} Maximum number of pixels between two touches for │ │ │ │ │ + * the gesture to be considered a "finalize feature" action. │ │ │ │ │ + * Default is 20. │ │ │ │ │ */ │ │ │ │ │ - stringifyOutput: true, │ │ │ │ │ + doubleTouchTolerance: 20, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: namedLayersAsArray │ │ │ │ │ - * {Boolean} Generate a namedLayers array. If false, the namedLayers │ │ │ │ │ - * property value will be an object keyed by layer name. Default is │ │ │ │ │ - * false. │ │ │ │ │ + * Property: freehand │ │ │ │ │ + * {Boolean} In freehand mode, the handler starts the path on mouse down, │ │ │ │ │ + * adds a point for every mouse move, and finishes the path on mouse up. │ │ │ │ │ + * Outside of freehand mode, a point is added to the path on every mouse │ │ │ │ │ + * click and double-click finishes the path. │ │ │ │ │ */ │ │ │ │ │ - namedLayersAsArray: false, │ │ │ │ │ + freehand: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: write │ │ │ │ │ - * Write a SLD document given a list of styles. │ │ │ │ │ + * Property: freehandToggle │ │ │ │ │ + * {String} If set, freehandToggle is checked on mouse events and will set │ │ │ │ │ + * the freehand mode to the opposite of this.freehand. To disallow │ │ │ │ │ + * toggling between freehand and non-freehand mode, set freehandToggle to │ │ │ │ │ + * null. Acceptable toggle values are 'shiftKey', 'ctrlKey', and 'altKey'. │ │ │ │ │ + */ │ │ │ │ │ + freehandToggle: 'shiftKey', │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: timerId │ │ │ │ │ + * {Integer} The timer used to test the double touch. │ │ │ │ │ + */ │ │ │ │ │ + timerId: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: redoStack │ │ │ │ │ + * {Array} Stack containing points removed with . │ │ │ │ │ + */ │ │ │ │ │ + redoStack: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Handler.Path │ │ │ │ │ + * Create a new path hander │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * sld - {Object} An object representing the SLD. │ │ │ │ │ - * options - {Object} Optional configuration object. │ │ │ │ │ + * control - {} The control that owns this handler │ │ │ │ │ + * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ + * functions. Various callbacks described below. │ │ │ │ │ + * options - {Object} An optional object with properties to be set on the │ │ │ │ │ + * handler │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} An SLD document string. │ │ │ │ │ + * Named callbacks: │ │ │ │ │ + * create - Called when a sketch is first created. Callback called with │ │ │ │ │ + * the creation point geometry and sketch feature. │ │ │ │ │ + * modify - Called with each move of a vertex with the vertex (point) │ │ │ │ │ + * geometry and the sketch feature. │ │ │ │ │ + * point - Called as each point is added. Receives the new point geometry. │ │ │ │ │ + * done - Called when the point drawing is finished. The callback will │ │ │ │ │ + * recieve a single argument, the linestring geometry. │ │ │ │ │ + * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ + * cancel callback will receive a geometry. │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Read and SLD doc and return an object representing the SLD. │ │ │ │ │ + * Method: createFeature │ │ │ │ │ + * Add temporary geometries │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {String | DOMElement} Data to read. │ │ │ │ │ - * options - {Object} Options for the reader. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object representing the SLD. │ │ │ │ │ + * pixel - {} The initial pixel location for the new │ │ │ │ │ + * feature. │ │ │ │ │ */ │ │ │ │ │ + createFeature: function(pixel) { │ │ │ │ │ + var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ + var geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ + lonlat.lon, lonlat.lat │ │ │ │ │ + ); │ │ │ │ │ + this.point = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ + this.line = new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.LineString([this.point.geometry]) │ │ │ │ │ + ); │ │ │ │ │ + this.callback("create", [this.point.geometry, this.getSketch()]); │ │ │ │ │ + this.point.geometry.clearBounds(); │ │ │ │ │ + this.layer.addFeatures([this.line, this.point], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.SLD" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/GML/v2.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Format/GML/Base.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroyFeature │ │ │ │ │ + * Destroy temporary geometries │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ + */ │ │ │ │ │ + destroyFeature: function(force) { │ │ │ │ │ + OpenLayers.Handler.Point.prototype.destroyFeature.call( │ │ │ │ │ + this, force); │ │ │ │ │ + this.line = null; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.GML.v2 │ │ │ │ │ - * Parses GML version 2. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.GML.v2 = OpenLayers.Class(OpenLayers.Format.GML.Base, { │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroyPersistedFeature │ │ │ │ │ + * Destroy the persisted feature. │ │ │ │ │ + */ │ │ │ │ │ + destroyPersistedFeature: function() { │ │ │ │ │ + var layer = this.layer; │ │ │ │ │ + if (layer && layer.features.length > 2) { │ │ │ │ │ + this.layer.features[0].destroy(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} Schema location for a particular minor version. │ │ │ │ │ + * Method: removePoint │ │ │ │ │ + * Destroy the temporary point. │ │ │ │ │ */ │ │ │ │ │ - schemaLocation: "http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/feature.xsd", │ │ │ │ │ + removePoint: function() { │ │ │ │ │ + if (this.point) { │ │ │ │ │ + this.layer.removeFeatures([this.point]); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.GML.v2 │ │ │ │ │ - * Create a parser for GML v2. │ │ │ │ │ + * Method: addPoint │ │ │ │ │ + * Add point to geometry. Send the point index to override │ │ │ │ │ + * the behavior of LinearRing that disregards adding duplicate points. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * pixel - {} The pixel location for the new point. │ │ │ │ │ + */ │ │ │ │ │ + addPoint: function(pixel) { │ │ │ │ │ + this.layer.removeFeatures([this.point]); │ │ │ │ │ + var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ + this.point = new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat) │ │ │ │ │ + ); │ │ │ │ │ + this.line.geometry.addComponent( │ │ │ │ │ + this.point.geometry, this.line.geometry.components.length │ │ │ │ │ + ); │ │ │ │ │ + this.layer.addFeatures([this.point]); │ │ │ │ │ + this.callback("point", [this.point.geometry, this.getGeometry()]); │ │ │ │ │ + this.callback("modify", [this.point.geometry, this.getSketch()]); │ │ │ │ │ + this.drawFeature(); │ │ │ │ │ + delete this.redoStack; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: insertXY │ │ │ │ │ + * Insert a point in the current sketch given x & y coordinates. The new │ │ │ │ │ + * point is inserted immediately before the most recently drawn point. │ │ │ │ │ * │ │ │ │ │ - * Valid options properties: │ │ │ │ │ - * featureType - {String} Local (without prefix) feature typeName (required). │ │ │ │ │ - * featureNS - {String} Feature namespace (required). │ │ │ │ │ - * geometryName - {String} Geometry element name. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * x - {Number} The x-coordinate of the point. │ │ │ │ │ + * y - {Number} The y-coordinate of the point. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Format.GML.Base.prototype.initialize.apply(this, [options]); │ │ │ │ │ + insertXY: function(x, y) { │ │ │ │ │ + this.line.geometry.addComponent( │ │ │ │ │ + new OpenLayers.Geometry.Point(x, y), │ │ │ │ │ + this.getCurrentPointIndex() │ │ │ │ │ + ); │ │ │ │ │ + this.drawFeature(); │ │ │ │ │ + delete this.redoStack; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: readers │ │ │ │ │ - * Contains public functions, grouped by namespace prefix, that will │ │ │ │ │ - * be applied when a namespaced node is found matching the function │ │ │ │ │ - * name. The function will be applied in the scope of this parser │ │ │ │ │ - * with two arguments: the node being read and a context object passed │ │ │ │ │ - * from the parent. │ │ │ │ │ + * Method: 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. │ │ │ │ │ */ │ │ │ │ │ - readers: { │ │ │ │ │ - "gml": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "outerBoundaryIs": function(node, container) { │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - container.outer = obj.components[0]; │ │ │ │ │ - }, │ │ │ │ │ - "innerBoundaryIs": function(node, container) { │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - container.inner.push(obj.components[0]); │ │ │ │ │ - }, │ │ │ │ │ - "Box": function(node, container) { │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - if (!container.components) { │ │ │ │ │ - container.components = []; │ │ │ │ │ - } │ │ │ │ │ - var min = obj.points[0]; │ │ │ │ │ - var max = obj.points[1]; │ │ │ │ │ - container.components.push( │ │ │ │ │ - new OpenLayers.Bounds(min.x, min.y, max.x, max.y) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, OpenLayers.Format.GML.Base.prototype.readers["gml"]), │ │ │ │ │ - "feature": OpenLayers.Format.GML.Base.prototype.readers["feature"], │ │ │ │ │ - "wfs": OpenLayers.Format.GML.Base.prototype.readers["wfs"] │ │ │ │ │ + insertDeltaXY: function(dx, dy) { │ │ │ │ │ + var previousIndex = this.getCurrentPointIndex() - 1; │ │ │ │ │ + var p0 = this.line.geometry.components[previousIndex]; │ │ │ │ │ + if (p0 && !isNaN(p0.x) && !isNaN(p0.y)) { │ │ │ │ │ + this.insertXY(p0.x + dx, p0.y + dy); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: write │ │ │ │ │ + * Method: insertDirectionLength │ │ │ │ │ + * Insert a point in the current sketch given a direction and a length. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array() | OpenLayers.Feature.Vector} │ │ │ │ │ - * An array of features or a single feature. │ │ │ │ │ + * direction - {Number} Degrees clockwise from the positive x-axis. │ │ │ │ │ + * length - {Number} Distance from the previously drawn point. │ │ │ │ │ + */ │ │ │ │ │ + insertDirectionLength: function(direction, length) { │ │ │ │ │ + direction *= Math.PI / 180; │ │ │ │ │ + var dx = length * Math.cos(direction); │ │ │ │ │ + var dy = length * Math.sin(direction); │ │ │ │ │ + this.insertDeltaXY(dx, dy); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: insertDeflectionLength │ │ │ │ │ + * Insert a point in the current sketch given a deflection and a length. │ │ │ │ │ + * The deflection should be degrees clockwise from the previously │ │ │ │ │ + * digitized segment. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} Given an array of features, a doc with a gml:featureMembers │ │ │ │ │ - * element will be returned. Given a single feature, a doc with a │ │ │ │ │ - * gml:featureMember element will be returned. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * deflection - {Number} Degrees clockwise from the previous segment. │ │ │ │ │ + * length - {Number} Distance from the previously drawn point. │ │ │ │ │ */ │ │ │ │ │ - write: function(features) { │ │ │ │ │ - var name; │ │ │ │ │ - if (OpenLayers.Util.isArray(features)) { │ │ │ │ │ - // GML2 only has abstract feature collections │ │ │ │ │ - // wfs provides a feature collection from a well-known schema │ │ │ │ │ - name = "wfs:FeatureCollection"; │ │ │ │ │ - } else { │ │ │ │ │ - name = "gml:featureMember"; │ │ │ │ │ + insertDeflectionLength: function(deflection, length) { │ │ │ │ │ + var previousIndex = this.getCurrentPointIndex() - 1; │ │ │ │ │ + if (previousIndex > 0) { │ │ │ │ │ + var p1 = this.line.geometry.components[previousIndex]; │ │ │ │ │ + var p0 = this.line.geometry.components[previousIndex - 1]; │ │ │ │ │ + var theta = Math.atan2(p1.y - p0.y, p1.x - p0.x); │ │ │ │ │ + this.insertDirectionLength( │ │ │ │ │ + (theta * 180 / Math.PI) + deflection, length │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - var root = this.writeNode(name, features); │ │ │ │ │ - this.setAttributeNS( │ │ │ │ │ - root, this.namespaces["xsi"], │ │ │ │ │ - "xsi:schemaLocation", this.schemaLocation │ │ │ │ │ - ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - return OpenLayers.Format.XML.prototype.write.apply(this, [root]); │ │ │ │ │ + /** │ │ │ │ │ + * Method: getCurrentPointIndex │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} The index of the most recently drawn point. │ │ │ │ │ + */ │ │ │ │ │ + getCurrentPointIndex: function() { │ │ │ │ │ + return this.line.geometry.components.length - 1; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ + * Method: undo │ │ │ │ │ + * Remove the most recently added point in the sketch geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} A point was removed. │ │ │ │ │ */ │ │ │ │ │ - writers: { │ │ │ │ │ - "gml": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "Point": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:Point"); │ │ │ │ │ - this.writeNode("coordinates", [geometry], node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "coordinates": function(points) { │ │ │ │ │ - var numPoints = points.length; │ │ │ │ │ - var parts = new Array(numPoints); │ │ │ │ │ - var point; │ │ │ │ │ - for (var i = 0; i < numPoints; ++i) { │ │ │ │ │ - point = points[i]; │ │ │ │ │ - if (this.xy) { │ │ │ │ │ - parts[i] = point.x + "," + point.y; │ │ │ │ │ - } else { │ │ │ │ │ - parts[i] = point.y + "," + point.x; │ │ │ │ │ - } │ │ │ │ │ - if (point.z != undefined) { // allow null or undefined │ │ │ │ │ - parts[i] += "," + point.z; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return this.createElementNSPlus("gml:coordinates", { │ │ │ │ │ - attributes: { │ │ │ │ │ - decimal: ".", │ │ │ │ │ - cs: ",", │ │ │ │ │ - ts: " " │ │ │ │ │ - }, │ │ │ │ │ - value: (numPoints == 1) ? parts[0] : parts.join(" ") │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "LineString": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:LineString"); │ │ │ │ │ - this.writeNode("coordinates", geometry.components, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Polygon": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:Polygon"); │ │ │ │ │ - this.writeNode("outerBoundaryIs", geometry.components[0], node); │ │ │ │ │ - for (var i = 1; i < geometry.components.length; ++i) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "innerBoundaryIs", geometry.components[i], node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "outerBoundaryIs": function(ring) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:outerBoundaryIs"); │ │ │ │ │ - this.writeNode("LinearRing", ring, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "innerBoundaryIs": function(ring) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:innerBoundaryIs"); │ │ │ │ │ - this.writeNode("LinearRing", ring, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "LinearRing": function(ring) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:LinearRing"); │ │ │ │ │ - this.writeNode("coordinates", ring.components, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Box": function(bounds) { │ │ │ │ │ - var node = this.createElementNSPlus("gml:Box"); │ │ │ │ │ - this.writeNode("coordinates", [{ │ │ │ │ │ - x: bounds.left, │ │ │ │ │ - y: bounds.bottom │ │ │ │ │ - }, { │ │ │ │ │ - x: bounds.right, │ │ │ │ │ - y: bounds.top │ │ │ │ │ - }], node); │ │ │ │ │ - // srsName attribute is optional for gml:Box │ │ │ │ │ - if (this.srsName) { │ │ │ │ │ - node.setAttribute("srsName", this.srsName); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ + undo: function() { │ │ │ │ │ + var geometry = this.line.geometry; │ │ │ │ │ + var components = geometry.components; │ │ │ │ │ + var index = this.getCurrentPointIndex() - 1; │ │ │ │ │ + var target = components[index]; │ │ │ │ │ + var undone = geometry.removeComponent(target); │ │ │ │ │ + if (undone) { │ │ │ │ │ + // On touch devices, set the current ("mouse location") point to │ │ │ │ │ + // match the last digitized point. │ │ │ │ │ + if (this.touch && index > 0) { │ │ │ │ │ + components = geometry.components; // safety │ │ │ │ │ + var lastpt = components[index - 1]; │ │ │ │ │ + var curptidx = this.getCurrentPointIndex(); │ │ │ │ │ + var curpt = components[curptidx]; │ │ │ │ │ + curpt.x = lastpt.x; │ │ │ │ │ + curpt.y = lastpt.y; │ │ │ │ │ } │ │ │ │ │ - }, OpenLayers.Format.GML.Base.prototype.writers["gml"]), │ │ │ │ │ - "feature": OpenLayers.Format.GML.Base.prototype.writers["feature"], │ │ │ │ │ - "wfs": OpenLayers.Format.GML.Base.prototype.writers["wfs"] │ │ │ │ │ + if (!this.redoStack) { │ │ │ │ │ + this.redoStack = []; │ │ │ │ │ + } │ │ │ │ │ + this.redoStack.push(target); │ │ │ │ │ + this.drawFeature(); │ │ │ │ │ + } │ │ │ │ │ + return undone; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.GML.v2" │ │ │ │ │ + /** │ │ │ │ │ + * Method: redo │ │ │ │ │ + * Reinsert the most recently removed point resulting from an call. │ │ │ │ │ + * The undo stack is deleted whenever a point is added by other means. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} A point was added. │ │ │ │ │ + */ │ │ │ │ │ + redo: function() { │ │ │ │ │ + var target = this.redoStack && this.redoStack.pop(); │ │ │ │ │ + if (target) { │ │ │ │ │ + this.line.geometry.addComponent(target, this.getCurrentPointIndex()); │ │ │ │ │ + this.drawFeature(); │ │ │ │ │ + } │ │ │ │ │ + return !!target; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Format/Filter/v1_0_0.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: freehandMode │ │ │ │ │ + * Determine whether to behave in freehand mode or not. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} │ │ │ │ │ + */ │ │ │ │ │ + freehandMode: function(evt) { │ │ │ │ │ + return (this.freehandToggle && evt[this.freehandToggle]) ? │ │ │ │ │ + !this.freehand : this.freehand; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of 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: modifyFeature │ │ │ │ │ + * Modify the existing geometry given the new point │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * pixel - {} The updated pixel location for the latest │ │ │ │ │ + * point. │ │ │ │ │ + * drawing - {Boolean} Indicate if we're currently drawing. │ │ │ │ │ + */ │ │ │ │ │ + modifyFeature: function(pixel, drawing) { │ │ │ │ │ + if (!this.line) { │ │ │ │ │ + this.createFeature(pixel); │ │ │ │ │ + } │ │ │ │ │ + var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ + this.point.geometry.x = lonlat.lon; │ │ │ │ │ + this.point.geometry.y = lonlat.lat; │ │ │ │ │ + this.callback("modify", [this.point.geometry, this.getSketch(), drawing]); │ │ │ │ │ + this.point.geometry.clearBounds(); │ │ │ │ │ + this.drawFeature(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Format/GML/v2.js │ │ │ │ │ - * @requires OpenLayers/Format/Filter/v1.js │ │ │ │ │ - */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: drawFeature │ │ │ │ │ + * Render geometries on the temporary layer. │ │ │ │ │ + */ │ │ │ │ │ + drawFeature: function() { │ │ │ │ │ + this.layer.drawFeature(this.line, this.style); │ │ │ │ │ + this.layer.drawFeature(this.point, this.style); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Format.Filter.v1_0_0 │ │ │ │ │ - * Write ogc:Filter version 1.0.0. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Format.Filter.v1_0_0 = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Format.GML.v2, OpenLayers.Format.Filter.v1, { │ │ │ │ │ + /** │ │ │ │ │ + * Method: getSketch │ │ │ │ │ + * Return the sketch feature. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getSketch: function() { │ │ │ │ │ + return this.line; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: VERSION │ │ │ │ │ - * {String} 1.0.0 │ │ │ │ │ - */ │ │ │ │ │ - VERSION: "1.0.0", │ │ │ │ │ + /** │ │ │ │ │ + * Method: getGeometry │ │ │ │ │ + * Return the sketch geometry. If is true, this will return │ │ │ │ │ + * a multi-part geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getGeometry: function() { │ │ │ │ │ + var geometry = this.line && this.line.geometry; │ │ │ │ │ + if (geometry && this.multi) { │ │ │ │ │ + geometry = new OpenLayers.Geometry.MultiLineString([geometry]); │ │ │ │ │ + } │ │ │ │ │ + return geometry; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} http://www.opengis.net/ogc/filter/1.0.0/filter.xsd │ │ │ │ │ - */ │ │ │ │ │ - schemaLocation: "http://www.opengis.net/ogc/filter/1.0.0/filter.xsd", │ │ │ │ │ + /** │ │ │ │ │ + * method: touchstart │ │ │ │ │ + * handle touchstart. │ │ │ │ │ + * │ │ │ │ │ + * parameters: │ │ │ │ │ + * evt - {event} the browser event │ │ │ │ │ + * │ │ │ │ │ + * returns: │ │ │ │ │ + * {boolean} allow event propagation │ │ │ │ │ + */ │ │ │ │ │ + touchstart: function(evt) { │ │ │ │ │ + if (this.timerId && │ │ │ │ │ + this.passesTolerance(this.lastTouchPx, evt.xy, │ │ │ │ │ + this.doubleTouchTolerance)) { │ │ │ │ │ + // double-tap, finalize the geometry │ │ │ │ │ + this.finishGeometry(); │ │ │ │ │ + window.clearTimeout(this.timerId); │ │ │ │ │ + this.timerId = null; │ │ │ │ │ + return false; │ │ │ │ │ + } else { │ │ │ │ │ + if (this.timerId) { │ │ │ │ │ + window.clearTimeout(this.timerId); │ │ │ │ │ + this.timerId = null; │ │ │ │ │ + } │ │ │ │ │ + this.timerId = window.setTimeout( │ │ │ │ │ + OpenLayers.Function.bind(function() { │ │ │ │ │ + this.timerId = null; │ │ │ │ │ + }, this), 300); │ │ │ │ │ + return OpenLayers.Handler.Point.prototype.touchstart.call(this, evt); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Format.Filter.v1_0_0 │ │ │ │ │ - * Instances of this class are not created directly. Use the │ │ │ │ │ - * constructor instead. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Format.GML.v2.prototype.initialize.apply( │ │ │ │ │ - this, [options] │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Method: down │ │ │ │ │ + * Handle mousedown and touchstart. Add a new point to the geometry and │ │ │ │ │ + * render it. Return determines whether to propagate the event on the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ + */ │ │ │ │ │ + down: function(evt) { │ │ │ │ │ + var stopDown = this.stopDown; │ │ │ │ │ + if (this.freehandMode(evt)) { │ │ │ │ │ + stopDown = true; │ │ │ │ │ + if (this.touch) { │ │ │ │ │ + this.modifyFeature(evt.xy, !!this.lastUp); │ │ │ │ │ + OpenLayers.Event.stop(evt); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (!this.touch && (!this.lastDown || │ │ │ │ │ + !this.passesTolerance(this.lastDown, evt.xy, │ │ │ │ │ + this.pixelTolerance))) { │ │ │ │ │ + this.modifyFeature(evt.xy, !!this.lastUp); │ │ │ │ │ + } │ │ │ │ │ + this.mouseDown = true; │ │ │ │ │ + this.lastDown = evt.xy; │ │ │ │ │ + this.stoppedDown = stopDown; │ │ │ │ │ + return !stopDown; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: readers │ │ │ │ │ - * Contains public functions, grouped by namespace prefix, that will │ │ │ │ │ - * be applied when a namespaced node is found matching the function │ │ │ │ │ - * name. The function will be applied in the scope of this parser │ │ │ │ │ - * with two arguments: the node being read and a context object passed │ │ │ │ │ - * from the parent. │ │ │ │ │ - */ │ │ │ │ │ - readers: { │ │ │ │ │ - "ogc": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "PropertyIsEqualTo": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.EQUAL_TO │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsNotEqualTo": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsLike": function(node, obj) { │ │ │ │ │ - var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ - type: OpenLayers.Filter.Comparison.LIKE │ │ │ │ │ - }); │ │ │ │ │ - this.readChildNodes(node, filter); │ │ │ │ │ - var wildCard = node.getAttribute("wildCard"); │ │ │ │ │ - var singleChar = node.getAttribute("singleChar"); │ │ │ │ │ - var esc = node.getAttribute("escape"); │ │ │ │ │ - filter.value2regex(wildCard, singleChar, esc); │ │ │ │ │ - obj.filters.push(filter); │ │ │ │ │ - } │ │ │ │ │ - }, OpenLayers.Format.Filter.v1.prototype.readers["ogc"]), │ │ │ │ │ - "gml": OpenLayers.Format.GML.v2.prototype.readers["gml"], │ │ │ │ │ - "feature": OpenLayers.Format.GML.v2.prototype.readers["feature"] │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Method: move │ │ │ │ │ + * Handle mousemove and touchmove. Adjust the geometry and redraw. │ │ │ │ │ + * Return determines whether to propagate the event on the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ + */ │ │ │ │ │ + move: function(evt) { │ │ │ │ │ + if (this.stoppedDown && this.freehandMode(evt)) { │ │ │ │ │ + if (this.persist) { │ │ │ │ │ + this.destroyPersistedFeature(); │ │ │ │ │ + } │ │ │ │ │ + if (this.maxVertices && this.line && │ │ │ │ │ + this.line.geometry.components.length === this.maxVertices) { │ │ │ │ │ + this.removePoint(); │ │ │ │ │ + this.finalize(); │ │ │ │ │ + } else { │ │ │ │ │ + this.addPoint(evt.xy); │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + if (!this.touch && (!this.mouseDown || this.stoppedDown)) { │ │ │ │ │ + this.modifyFeature(evt.xy, !!this.lastUp); │ │ │ │ │ + } │ │ │ │ │ + return true; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ - */ │ │ │ │ │ - writers: { │ │ │ │ │ - "ogc": OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "PropertyIsEqualTo": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsEqualTo"); │ │ │ │ │ - // no ogc:expression handling for PropertyName for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - // handle Literals or Functions for now │ │ │ │ │ - this.writeOgcExpression(filter.value, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsNotEqualTo": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo"); │ │ │ │ │ - // no ogc:expression handling for PropertyName for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - // handle Literals or Functions for now │ │ │ │ │ - this.writeOgcExpression(filter.value, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PropertyIsLike": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:PropertyIsLike", { │ │ │ │ │ - attributes: { │ │ │ │ │ - wildCard: "*", │ │ │ │ │ - singleChar: ".", │ │ │ │ │ - escape: "!" │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - // no ogc:expression handling for now │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - // convert regex string to ogc string │ │ │ │ │ - this.writeNode("Literal", filter.regex2value(), node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "BBOX": function(filter) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:BBOX"); │ │ │ │ │ - // PropertyName is mandatory in 1.0.0, but e.g. GeoServer also │ │ │ │ │ - // accepts filters without it. When this is used with │ │ │ │ │ - // OpenLayers.Protocol.WFS, OpenLayers.Format.WFST will set a │ │ │ │ │ - // missing filter.property to the geometryName that is │ │ │ │ │ - // configured with the protocol, which defaults to "the_geom". │ │ │ │ │ - // So the only way to omit this mandatory property is to not │ │ │ │ │ - // set the property on the filter and to set the geometryName │ │ │ │ │ - // on the WFS protocol to null. The latter also happens when │ │ │ │ │ - // the protocol is configured without a geometryName and a │ │ │ │ │ - // featureNS. │ │ │ │ │ - filter.property && this.writeNode("PropertyName", filter, node); │ │ │ │ │ - var box = this.writeNode("gml:Box", filter.value, node); │ │ │ │ │ - if (filter.projection) { │ │ │ │ │ - box.setAttribute("srsName", filter.projection); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ + /** │ │ │ │ │ + * Method: up │ │ │ │ │ + * Handle mouseup and touchend. Send the latest point in the geometry to │ │ │ │ │ + * the control. Return determines whether to propagate the event on the map. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ + */ │ │ │ │ │ + up: function(evt) { │ │ │ │ │ + if (this.mouseDown && (!this.lastUp || !this.lastUp.equals(evt.xy))) { │ │ │ │ │ + if (this.stoppedDown && this.freehandMode(evt)) { │ │ │ │ │ + if (this.persist) { │ │ │ │ │ + this.destroyPersistedFeature(); │ │ │ │ │ } │ │ │ │ │ - }, OpenLayers.Format.Filter.v1.prototype.writers["ogc"]), │ │ │ │ │ - "gml": OpenLayers.Format.GML.v2.prototype.writers["gml"], │ │ │ │ │ - "feature": OpenLayers.Format.GML.v2.prototype.writers["feature"] │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: writeSpatial │ │ │ │ │ - * │ │ │ │ │ - * Read a {} filter and converts it into XML. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * filter - {} The filter. │ │ │ │ │ - * name - {String} Name of the generated XML element. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The created XML element. │ │ │ │ │ - */ │ │ │ │ │ - writeSpatial: function(filter, name) { │ │ │ │ │ - var node = this.createElementNSPlus("ogc:" + name); │ │ │ │ │ - this.writeNode("PropertyName", filter, node); │ │ │ │ │ - if (filter.value instanceof OpenLayers.Filter.Function) { │ │ │ │ │ - this.writeNode("Function", filter.value, node); │ │ │ │ │ + this.removePoint(); │ │ │ │ │ + this.finalize(); │ │ │ │ │ } else { │ │ │ │ │ - var child; │ │ │ │ │ - if (filter.value instanceof OpenLayers.Geometry) { │ │ │ │ │ - child = this.writeNode("feature:_geometry", filter.value).firstChild; │ │ │ │ │ - } else { │ │ │ │ │ - child = this.writeNode("gml:Box", filter.value); │ │ │ │ │ - } │ │ │ │ │ - if (filter.projection) { │ │ │ │ │ - child.setAttribute("srsName", filter.projection); │ │ │ │ │ + if (this.passesTolerance(this.lastDown, evt.xy, │ │ │ │ │ + this.pixelTolerance)) { │ │ │ │ │ + if (this.touch) { │ │ │ │ │ + this.modifyFeature(evt.xy); │ │ │ │ │ + } │ │ │ │ │ + if (this.lastUp == null && this.persist) { │ │ │ │ │ + this.destroyPersistedFeature(); │ │ │ │ │ + } │ │ │ │ │ + this.addPoint(evt.xy); │ │ │ │ │ + this.lastUp = evt.xy; │ │ │ │ │ + if (this.line.geometry.components.length === this.maxVertices + 1) { │ │ │ │ │ + this.finishGeometry(); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - node.appendChild(child); │ │ │ │ │ } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ + } │ │ │ │ │ + this.stoppedDown = this.stopDown; │ │ │ │ │ + this.mouseDown = false; │ │ │ │ │ + return !this.stopUp; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: finishGeometry │ │ │ │ │ + * Finish the geometry and send it back to the control. │ │ │ │ │ + */ │ │ │ │ │ + finishGeometry: function() { │ │ │ │ │ + var index = this.line.geometry.components.length - 1; │ │ │ │ │ + this.line.geometry.removeComponent(this.line.geometry.components[index]); │ │ │ │ │ + this.removePoint(); │ │ │ │ │ + this.finalize(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.Filter.v1_0_0" │ │ │ │ │ + /** │ │ │ │ │ + * Method: dblclick │ │ │ │ │ + * Handle double-clicks. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The browser event │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Allow event propagation │ │ │ │ │ + */ │ │ │ │ │ + dblclick: function(evt) { │ │ │ │ │ + if (!this.freehandMode(evt)) { │ │ │ │ │ + this.finishGeometry(); │ │ │ │ │ + } │ │ │ │ │ + return false; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - }); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Path" │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/SLD/v1.js │ │ │ │ │ + OpenLayers/Handler/Polygon.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Rule.js │ │ │ │ │ - * @requires OpenLayers/Format/SLD.js │ │ │ │ │ - * @requires OpenLayers/Format/Filter/v1_0_0.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 │ │ │ │ │ + * @requires OpenLayers/Handler/Path.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.SLD.v1 │ │ │ │ │ - * Superclass for SLD version 1 parsers. │ │ │ │ │ + * Class: OpenLayers.Handler.Polygon │ │ │ │ │ + * Handler to draw a polygon on the map. Polygon is displayed on mouse down, │ │ │ │ │ + * moves on mouse move, and is finished on mouse up. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: namespaces │ │ │ │ │ - * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ - */ │ │ │ │ │ - namespaces: { │ │ │ │ │ - sld: "http://www.opengis.net/sld", │ │ │ │ │ - ogc: "http://www.opengis.net/ogc", │ │ │ │ │ - gml: "http://www.opengis.net/gml", │ │ │ │ │ - xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ - xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: defaultPrefix │ │ │ │ │ - */ │ │ │ │ │ - defaultPrefix: "sld", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} Schema location for a particular minor version. │ │ │ │ │ - */ │ │ │ │ │ - schemaLocation: null, │ │ │ │ │ +OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: multipleSymbolizers │ │ │ │ │ - * {Boolean} Support multiple symbolizers per rule. Default is false. if │ │ │ │ │ - * true, an OpenLayers.Style2 instance will be created to represent │ │ │ │ │ - * user styles instead of an OpenLayers.Style instace. The │ │ │ │ │ - * OpenLayers.Style2 class allows collections of rules with multiple │ │ │ │ │ - * symbolizers, but is not currently useful for client side rendering. │ │ │ │ │ - * If multiple symbolizers is true, multiple FeatureTypeStyle elements │ │ │ │ │ - * are preserved in reading/writing by setting symbolizer zIndex values. │ │ │ │ │ - * In addition, the property is ignored if │ │ │ │ │ - * multiple symbolizers are supported (defaults should be applied │ │ │ │ │ - * when rendering). │ │ │ │ │ - */ │ │ │ │ │ - multipleSymbolizers: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: featureTypeCounter │ │ │ │ │ - * {Number} Private counter for multiple feature type styles. │ │ │ │ │ + * APIProperty: holeModifier │ │ │ │ │ + * {String} Key modifier to trigger hole digitizing. Acceptable values are │ │ │ │ │ + * "altKey", "shiftKey", or "ctrlKey". If not set, no hole digitizing │ │ │ │ │ + * will take place. Default is null. │ │ │ │ │ */ │ │ │ │ │ - featureTypeCounter: null, │ │ │ │ │ + holeModifier: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: defaultSymbolizer. │ │ │ │ │ - * {Object} A symbolizer with the SLD defaults. │ │ │ │ │ + * Property: drawingHole │ │ │ │ │ + * {Boolean} Currently drawing an interior ring. │ │ │ │ │ */ │ │ │ │ │ - defaultSymbolizer: { │ │ │ │ │ - fillColor: "#808080", │ │ │ │ │ - fillOpacity: 1, │ │ │ │ │ - strokeColor: "#000000", │ │ │ │ │ - strokeOpacity: 1, │ │ │ │ │ - strokeWidth: 1, │ │ │ │ │ - strokeDashstyle: "solid", │ │ │ │ │ - pointRadius: 3, │ │ │ │ │ - graphicName: "square" │ │ │ │ │ - }, │ │ │ │ │ + drawingHole: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.SLD.v1 │ │ │ │ │ - * Instances of this class are not created directly. Use the │ │ │ │ │ - * constructor instead. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * Property: polygon │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ + polygon: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: read │ │ │ │ │ + * Constructor: OpenLayers.Handler.Polygon │ │ │ │ │ + * Create a Polygon Handler. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {DOMElement} An SLD document element. │ │ │ │ │ - * options - {Object} Options for the reader. │ │ │ │ │ + * control - {} The control that owns this handler │ │ │ │ │ + * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ + * functions. Various callbacks described below. │ │ │ │ │ + * options - {Object} An optional object with properties to be set on the │ │ │ │ │ + * handler │ │ │ │ │ * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * namedLayersAsArray - {Boolean} Generate a namedLayers array. If false, │ │ │ │ │ - * the namedLayers property value will be an object keyed by layer name. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * Named callbacks: │ │ │ │ │ + * create - Called when a sketch is first created. Callback called with │ │ │ │ │ + * the creation point geometry and sketch feature. │ │ │ │ │ + * modify - Called with each move of a vertex with the vertex (point) │ │ │ │ │ + * geometry and the sketch feature. │ │ │ │ │ + * point - Called as each point is added. Receives the new point geometry. │ │ │ │ │ + * done - Called when the point drawing is finished. The callback will │ │ │ │ │ + * recieve a single argument, the polygon geometry. │ │ │ │ │ + * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ + * cancel callback will receive a geometry. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createFeature │ │ │ │ │ + * Add temporary geometries │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object representing the SLD. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * pixel - {} The initial pixel location for the new │ │ │ │ │ + * feature. │ │ │ │ │ */ │ │ │ │ │ - read: function(data, options) { │ │ │ │ │ - options = OpenLayers.Util.applyDefaults(options, this.options); │ │ │ │ │ - var sld = { │ │ │ │ │ - namedLayers: options.namedLayersAsArray === true ? [] : {} │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(data, sld); │ │ │ │ │ - return sld; │ │ │ │ │ + createFeature: function(pixel) { │ │ │ │ │ + var lonlat = this.layer.getLonLatFromViewPortPx(pixel); │ │ │ │ │ + var geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ + lonlat.lon, lonlat.lat │ │ │ │ │ + ); │ │ │ │ │ + this.point = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ + this.line = new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.LinearRing([this.point.geometry]) │ │ │ │ │ + ); │ │ │ │ │ + this.polygon = new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.Polygon([this.line.geometry]) │ │ │ │ │ + ); │ │ │ │ │ + this.callback("create", [this.point.geometry, this.getSketch()]); │ │ │ │ │ + this.point.geometry.clearBounds(); │ │ │ │ │ + this.layer.addFeatures([this.polygon, this.point], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: readers │ │ │ │ │ - * Contains public functions, grouped by namespace prefix, that will │ │ │ │ │ - * be applied when a namespaced node is found matching the function │ │ │ │ │ - * name. The function will be applied in the scope of this parser │ │ │ │ │ - * with two arguments: the node being read and a context object passed │ │ │ │ │ - * from the parent. │ │ │ │ │ + * Method: addPoint │ │ │ │ │ + * Add point to geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * pixel - {} The pixel location for the new point. │ │ │ │ │ */ │ │ │ │ │ - readers: OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "sld": { │ │ │ │ │ - "StyledLayerDescriptor": function(node, sld) { │ │ │ │ │ - sld.version = node.getAttribute("version"); │ │ │ │ │ - this.readChildNodes(node, sld); │ │ │ │ │ - }, │ │ │ │ │ - "Name": function(node, obj) { │ │ │ │ │ - obj.name = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Title": function(node, obj) { │ │ │ │ │ - obj.title = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Abstract": function(node, obj) { │ │ │ │ │ - obj.description = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "NamedLayer": function(node, sld) { │ │ │ │ │ - var layer = { │ │ │ │ │ - userStyles: [], │ │ │ │ │ - namedStyles: [] │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, layer); │ │ │ │ │ - // give each of the user styles this layer name │ │ │ │ │ - for (var i = 0, len = layer.userStyles.length; i < len; ++i) { │ │ │ │ │ - layer.userStyles[i].layerName = layer.name; │ │ │ │ │ - } │ │ │ │ │ - if (OpenLayers.Util.isArray(sld.namedLayers)) { │ │ │ │ │ - sld.namedLayers.push(layer); │ │ │ │ │ - } else { │ │ │ │ │ - sld.namedLayers[layer.name] = layer; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "NamedStyle": function(node, layer) { │ │ │ │ │ - layer.namedStyles.push( │ │ │ │ │ - this.getChildName(node.firstChild) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "UserStyle": function(node, layer) { │ │ │ │ │ - var obj = { │ │ │ │ │ - defaultsPerSymbolizer: true, │ │ │ │ │ - rules: [] │ │ │ │ │ - }; │ │ │ │ │ - this.featureTypeCounter = -1; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - var style; │ │ │ │ │ - if (this.multipleSymbolizers) { │ │ │ │ │ - delete obj.defaultsPerSymbolizer; │ │ │ │ │ - style = new OpenLayers.Style2(obj); │ │ │ │ │ - } else { │ │ │ │ │ - style = new OpenLayers.Style(this.defaultSymbolizer, obj); │ │ │ │ │ - } │ │ │ │ │ - layer.userStyles.push(style); │ │ │ │ │ - }, │ │ │ │ │ - "IsDefault": function(node, style) { │ │ │ │ │ - if (this.getChildValue(node) == "1") { │ │ │ │ │ - style.isDefault = true; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "FeatureTypeStyle": function(node, style) { │ │ │ │ │ - ++this.featureTypeCounter; │ │ │ │ │ - var obj = { │ │ │ │ │ - rules: this.multipleSymbolizers ? style.rules : [] │ │ │ │ │ - }; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - if (!this.multipleSymbolizers) { │ │ │ │ │ - style.rules = obj.rules; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "Rule": function(node, obj) { │ │ │ │ │ - var config; │ │ │ │ │ - if (this.multipleSymbolizers) { │ │ │ │ │ - config = { │ │ │ │ │ - symbolizers: [] │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - var rule = new OpenLayers.Rule(config); │ │ │ │ │ - this.readChildNodes(node, rule); │ │ │ │ │ - obj.rules.push(rule); │ │ │ │ │ - }, │ │ │ │ │ - "ElseFilter": function(node, rule) { │ │ │ │ │ - rule.elseFilter = true; │ │ │ │ │ - }, │ │ │ │ │ - "MinScaleDenominator": function(node, rule) { │ │ │ │ │ - rule.minScaleDenominator = parseFloat(this.getChildValue(node)); │ │ │ │ │ - }, │ │ │ │ │ - "MaxScaleDenominator": function(node, rule) { │ │ │ │ │ - rule.maxScaleDenominator = parseFloat(this.getChildValue(node)); │ │ │ │ │ - }, │ │ │ │ │ - "TextSymbolizer": function(node, rule) { │ │ │ │ │ - var config = {}; │ │ │ │ │ - this.readChildNodes(node, config); │ │ │ │ │ - if (this.multipleSymbolizers) { │ │ │ │ │ - config.zIndex = this.featureTypeCounter; │ │ │ │ │ - rule.symbolizers.push( │ │ │ │ │ - new OpenLayers.Symbolizer.Text(config) │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - rule.symbolizer["Text"] = OpenLayers.Util.applyDefaults( │ │ │ │ │ - config, rule.symbolizer["Text"] │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "LabelPlacement": function(node, symbolizer) { │ │ │ │ │ - this.readChildNodes(node, symbolizer); │ │ │ │ │ - }, │ │ │ │ │ - "PointPlacement": function(node, symbolizer) { │ │ │ │ │ - var config = {}; │ │ │ │ │ - this.readChildNodes(node, config); │ │ │ │ │ - config.labelRotation = config.rotation; │ │ │ │ │ - delete config.rotation; │ │ │ │ │ - var labelAlign, │ │ │ │ │ - x = symbolizer.labelAnchorPointX, │ │ │ │ │ - y = symbolizer.labelAnchorPointY; │ │ │ │ │ - if (x <= 1 / 3) { │ │ │ │ │ - labelAlign = 'l'; │ │ │ │ │ - } else if (x > 1 / 3 && x < 2 / 3) { │ │ │ │ │ - labelAlign = 'c'; │ │ │ │ │ - } else if (x >= 2 / 3) { │ │ │ │ │ - labelAlign = 'r'; │ │ │ │ │ - } │ │ │ │ │ - if (y <= 1 / 3) { │ │ │ │ │ - labelAlign += 'b'; │ │ │ │ │ - } else if (y > 1 / 3 && y < 2 / 3) { │ │ │ │ │ - labelAlign += 'm'; │ │ │ │ │ - } else if (y >= 2 / 3) { │ │ │ │ │ - labelAlign += 't'; │ │ │ │ │ - } │ │ │ │ │ - config.labelAlign = labelAlign; │ │ │ │ │ - OpenLayers.Util.applyDefaults(symbolizer, config); │ │ │ │ │ - }, │ │ │ │ │ - "AnchorPoint": function(node, symbolizer) { │ │ │ │ │ - this.readChildNodes(node, symbolizer); │ │ │ │ │ - }, │ │ │ │ │ - "AnchorPointX": function(node, symbolizer) { │ │ │ │ │ - var labelAnchorPointX = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - // always string, could be empty string │ │ │ │ │ - if (labelAnchorPointX) { │ │ │ │ │ - symbolizer.labelAnchorPointX = labelAnchorPointX; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "AnchorPointY": function(node, symbolizer) { │ │ │ │ │ - var labelAnchorPointY = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - // always string, could be empty string │ │ │ │ │ - if (labelAnchorPointY) { │ │ │ │ │ - symbolizer.labelAnchorPointY = labelAnchorPointY; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "Displacement": function(node, symbolizer) { │ │ │ │ │ - this.readChildNodes(node, symbolizer); │ │ │ │ │ - }, │ │ │ │ │ - "DisplacementX": function(node, symbolizer) { │ │ │ │ │ - var labelXOffset = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - // always string, could be empty string │ │ │ │ │ - if (labelXOffset) { │ │ │ │ │ - symbolizer.labelXOffset = labelXOffset; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "DisplacementY": function(node, symbolizer) { │ │ │ │ │ - var labelYOffset = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - // always string, could be empty string │ │ │ │ │ - if (labelYOffset) { │ │ │ │ │ - symbolizer.labelYOffset = labelYOffset; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "LinePlacement": function(node, symbolizer) { │ │ │ │ │ - this.readChildNodes(node, symbolizer); │ │ │ │ │ - }, │ │ │ │ │ - "PerpendicularOffset": function(node, symbolizer) { │ │ │ │ │ - var labelPerpendicularOffset = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - // always string, could be empty string │ │ │ │ │ - if (labelPerpendicularOffset) { │ │ │ │ │ - symbolizer.labelPerpendicularOffset = labelPerpendicularOffset; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "Label": function(node, symbolizer) { │ │ │ │ │ - var value = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - if (value) { │ │ │ │ │ - symbolizer.label = value; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "Font": function(node, symbolizer) { │ │ │ │ │ - this.readChildNodes(node, symbolizer); │ │ │ │ │ - }, │ │ │ │ │ - "Halo": function(node, symbolizer) { │ │ │ │ │ - // halo has a fill, so send fresh object │ │ │ │ │ - var obj = {}; │ │ │ │ │ - this.readChildNodes(node, obj); │ │ │ │ │ - symbolizer.haloRadius = obj.haloRadius; │ │ │ │ │ - symbolizer.haloColor = obj.fillColor; │ │ │ │ │ - symbolizer.haloOpacity = obj.fillOpacity; │ │ │ │ │ - }, │ │ │ │ │ - "Radius": function(node, symbolizer) { │ │ │ │ │ - var radius = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - if (radius != null) { │ │ │ │ │ - // radius is only used for halo │ │ │ │ │ - symbolizer.haloRadius = radius; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "RasterSymbolizer": function(node, rule) { │ │ │ │ │ - var config = {}; │ │ │ │ │ - this.readChildNodes(node, config); │ │ │ │ │ - if (this.multipleSymbolizers) { │ │ │ │ │ - config.zIndex = this.featureTypeCounter; │ │ │ │ │ - rule.symbolizers.push( │ │ │ │ │ - new OpenLayers.Symbolizer.Raster(config) │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - rule.symbolizer["Raster"] = OpenLayers.Util.applyDefaults( │ │ │ │ │ - config, rule.symbolizer["Raster"] │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "Geometry": function(node, obj) { │ │ │ │ │ - obj.geometry = {}; │ │ │ │ │ - this.readChildNodes(node, obj.geometry); │ │ │ │ │ - }, │ │ │ │ │ - "ColorMap": function(node, symbolizer) { │ │ │ │ │ - symbolizer.colorMap = []; │ │ │ │ │ - this.readChildNodes(node, symbolizer.colorMap); │ │ │ │ │ - }, │ │ │ │ │ - "ColorMapEntry": function(node, colorMap) { │ │ │ │ │ - var q = node.getAttribute("quantity"); │ │ │ │ │ - var o = node.getAttribute("opacity"); │ │ │ │ │ - colorMap.push({ │ │ │ │ │ - color: node.getAttribute("color"), │ │ │ │ │ - quantity: q !== null ? parseFloat(q) : undefined, │ │ │ │ │ - label: node.getAttribute("label") || undefined, │ │ │ │ │ - opacity: o !== null ? parseFloat(o) : undefined │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "LineSymbolizer": function(node, rule) { │ │ │ │ │ - var config = {}; │ │ │ │ │ - this.readChildNodes(node, config); │ │ │ │ │ - if (this.multipleSymbolizers) { │ │ │ │ │ - config.zIndex = this.featureTypeCounter; │ │ │ │ │ - rule.symbolizers.push( │ │ │ │ │ - new OpenLayers.Symbolizer.Line(config) │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - rule.symbolizer["Line"] = OpenLayers.Util.applyDefaults( │ │ │ │ │ - config, rule.symbolizer["Line"] │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "PolygonSymbolizer": function(node, rule) { │ │ │ │ │ - var config = { │ │ │ │ │ - fill: false, │ │ │ │ │ - stroke: false │ │ │ │ │ - }; │ │ │ │ │ - if (!this.multipleSymbolizers) { │ │ │ │ │ - config = rule.symbolizer["Polygon"] || config; │ │ │ │ │ - } │ │ │ │ │ - this.readChildNodes(node, config); │ │ │ │ │ - if (this.multipleSymbolizers) { │ │ │ │ │ - config.zIndex = this.featureTypeCounter; │ │ │ │ │ - rule.symbolizers.push( │ │ │ │ │ - new OpenLayers.Symbolizer.Polygon(config) │ │ │ │ │ + addPoint: function(pixel) { │ │ │ │ │ + if (!this.drawingHole && this.holeModifier && │ │ │ │ │ + this.evt && this.evt[this.holeModifier]) { │ │ │ │ │ + var geometry = this.point.geometry; │ │ │ │ │ + var features = this.control.layer.features; │ │ │ │ │ + var candidate, polygon; │ │ │ │ │ + // look for intersections, last drawn gets priority │ │ │ │ │ + for (var i = features.length - 1; i >= 0; --i) { │ │ │ │ │ + candidate = features[i].geometry; │ │ │ │ │ + if ((candidate instanceof OpenLayers.Geometry.Polygon || │ │ │ │ │ + candidate instanceof OpenLayers.Geometry.MultiPolygon) && │ │ │ │ │ + candidate.intersects(geometry)) { │ │ │ │ │ + polygon = features[i]; │ │ │ │ │ + this.control.layer.removeFeatures([polygon], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.control.layer.events.registerPriority( │ │ │ │ │ + "sketchcomplete", this, this.finalizeInteriorRing │ │ │ │ │ ); │ │ │ │ │ - } else { │ │ │ │ │ - rule.symbolizer["Polygon"] = config; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "PointSymbolizer": function(node, rule) { │ │ │ │ │ - var config = { │ │ │ │ │ - fill: false, │ │ │ │ │ - stroke: false, │ │ │ │ │ - graphic: false │ │ │ │ │ - }; │ │ │ │ │ - if (!this.multipleSymbolizers) { │ │ │ │ │ - config = rule.symbolizer["Point"] || config; │ │ │ │ │ - } │ │ │ │ │ - this.readChildNodes(node, config); │ │ │ │ │ - if (this.multipleSymbolizers) { │ │ │ │ │ - config.zIndex = this.featureTypeCounter; │ │ │ │ │ - rule.symbolizers.push( │ │ │ │ │ - new OpenLayers.Symbolizer.Point(config) │ │ │ │ │ + this.control.layer.events.registerPriority( │ │ │ │ │ + "sketchmodified", this, this.enforceTopology │ │ │ │ │ ); │ │ │ │ │ - } else { │ │ │ │ │ - rule.symbolizer["Point"] = config; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "Stroke": function(node, symbolizer) { │ │ │ │ │ - symbolizer.stroke = true; │ │ │ │ │ - this.readChildNodes(node, symbolizer); │ │ │ │ │ - }, │ │ │ │ │ - "Fill": function(node, symbolizer) { │ │ │ │ │ - symbolizer.fill = true; │ │ │ │ │ - this.readChildNodes(node, symbolizer); │ │ │ │ │ - }, │ │ │ │ │ - "CssParameter": function(node, symbolizer) { │ │ │ │ │ - var cssProperty = node.getAttribute("name"); │ │ │ │ │ - var symProperty = this.cssMap[cssProperty]; │ │ │ │ │ - // for labels, fill should map to fontColor and fill-opacity │ │ │ │ │ - // to fontOpacity │ │ │ │ │ - if (symbolizer.label) { │ │ │ │ │ - if (cssProperty === 'fill') { │ │ │ │ │ - symProperty = "fontColor"; │ │ │ │ │ - } else if (cssProperty === 'fill-opacity') { │ │ │ │ │ - symProperty = "fontOpacity"; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (symProperty) { │ │ │ │ │ - // Limited support for parsing of OGC expressions │ │ │ │ │ - var value = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - // always string, could be an empty string │ │ │ │ │ - if (value) { │ │ │ │ │ - symbolizer[symProperty] = value; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "Graphic": function(node, symbolizer) { │ │ │ │ │ - symbolizer.graphic = true; │ │ │ │ │ - var graphic = {}; │ │ │ │ │ - // painter's order not respected here, clobber previous with next │ │ │ │ │ - this.readChildNodes(node, graphic); │ │ │ │ │ - // directly properties with names that match symbolizer properties │ │ │ │ │ - var properties = [ │ │ │ │ │ - "stroke", "strokeColor", "strokeWidth", "strokeOpacity", │ │ │ │ │ - "strokeLinecap", "fill", "fillColor", "fillOpacity", │ │ │ │ │ - "graphicName", "rotation", "graphicFormat" │ │ │ │ │ - ]; │ │ │ │ │ - var prop, value; │ │ │ │ │ - for (var i = 0, len = properties.length; i < len; ++i) { │ │ │ │ │ - prop = properties[i]; │ │ │ │ │ - value = graphic[prop]; │ │ │ │ │ - if (value != undefined) { │ │ │ │ │ - symbolizer[prop] = value; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // set other generic properties with specific graphic property names │ │ │ │ │ - if (graphic.opacity != undefined) { │ │ │ │ │ - symbolizer.graphicOpacity = graphic.opacity; │ │ │ │ │ - } │ │ │ │ │ - if (graphic.size != undefined) { │ │ │ │ │ - var pointRadius = graphic.size / 2; │ │ │ │ │ - if (isNaN(pointRadius)) { │ │ │ │ │ - // likely a property name │ │ │ │ │ - symbolizer.graphicWidth = graphic.size; │ │ │ │ │ - } else { │ │ │ │ │ - symbolizer.pointRadius = graphic.size / 2; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (graphic.href != undefined) { │ │ │ │ │ - symbolizer.externalGraphic = graphic.href; │ │ │ │ │ - } │ │ │ │ │ - if (graphic.rotation != undefined) { │ │ │ │ │ - symbolizer.rotation = graphic.rotation; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "ExternalGraphic": function(node, graphic) { │ │ │ │ │ - this.readChildNodes(node, graphic); │ │ │ │ │ - }, │ │ │ │ │ - "Mark": function(node, graphic) { │ │ │ │ │ - this.readChildNodes(node, graphic); │ │ │ │ │ - }, │ │ │ │ │ - "WellKnownName": function(node, graphic) { │ │ │ │ │ - graphic.graphicName = this.getChildValue(node); │ │ │ │ │ - }, │ │ │ │ │ - "Opacity": function(node, obj) { │ │ │ │ │ - var opacity = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - // always string, could be empty string │ │ │ │ │ - if (opacity) { │ │ │ │ │ - obj.opacity = opacity; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "Size": function(node, obj) { │ │ │ │ │ - var size = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - // always string, could be empty string │ │ │ │ │ - if (size) { │ │ │ │ │ - obj.size = size; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - "Rotation": function(node, obj) { │ │ │ │ │ - var rotation = this.readers.ogc._expression.call(this, node); │ │ │ │ │ - // always string, could be empty string │ │ │ │ │ - if (rotation) { │ │ │ │ │ - obj.rotation = rotation; │ │ │ │ │ + polygon.geometry.addComponent(this.line.geometry); │ │ │ │ │ + this.polygon = polygon; │ │ │ │ │ + this.drawingHole = true; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - "OnlineResource": function(node, obj) { │ │ │ │ │ - obj.href = this.getAttributeNS( │ │ │ │ │ - node, this.namespaces.xlink, "href" │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "Format": function(node, graphic) { │ │ │ │ │ - graphic.graphicFormat = this.getChildValue(node); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }, OpenLayers.Format.Filter.v1_0_0.prototype.readers), │ │ │ │ │ + OpenLayers.Handler.Path.prototype.addPoint.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: cssMap │ │ │ │ │ - * {Object} Object mapping supported css property names to OpenLayers │ │ │ │ │ - * symbolizer property names. │ │ │ │ │ + * Method: getCurrentPointIndex │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} The index of the most recently drawn point. │ │ │ │ │ */ │ │ │ │ │ - cssMap: { │ │ │ │ │ - "stroke": "strokeColor", │ │ │ │ │ - "stroke-opacity": "strokeOpacity", │ │ │ │ │ - "stroke-width": "strokeWidth", │ │ │ │ │ - "stroke-linecap": "strokeLinecap", │ │ │ │ │ - "stroke-dasharray": "strokeDashstyle", │ │ │ │ │ - "fill": "fillColor", │ │ │ │ │ - "fill-opacity": "fillOpacity", │ │ │ │ │ - "font-family": "fontFamily", │ │ │ │ │ - "font-size": "fontSize", │ │ │ │ │ - "font-weight": "fontWeight", │ │ │ │ │ - "font-style": "fontStyle" │ │ │ │ │ + getCurrentPointIndex: function() { │ │ │ │ │ + return this.line.geometry.components.length - 2; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getCssProperty │ │ │ │ │ - * Given a symbolizer property, get the corresponding CSS property │ │ │ │ │ - * from the . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * sym - {String} A symbolizer property name. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A CSS property name or null if none found. │ │ │ │ │ + * Method: enforceTopology │ │ │ │ │ + * Simple topology enforcement for drawing interior rings. Ensures vertices │ │ │ │ │ + * of interior rings are contained by exterior ring. Other topology │ │ │ │ │ + * rules are enforced in to allow drawing of │ │ │ │ │ + * rings that intersect only during the sketch (e.g. a "C" shaped ring │ │ │ │ │ + * that nearly encloses another ring). │ │ │ │ │ */ │ │ │ │ │ - getCssProperty: function(sym) { │ │ │ │ │ - var css = null; │ │ │ │ │ - for (var prop in this.cssMap) { │ │ │ │ │ - if (this.cssMap[prop] == sym) { │ │ │ │ │ - css = prop; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + enforceTopology: function(event) { │ │ │ │ │ + var point = event.vertex; │ │ │ │ │ + var components = this.line.geometry.components; │ │ │ │ │ + // ensure that vertices of interior ring are contained by exterior ring │ │ │ │ │ + if (!this.polygon.geometry.intersects(point)) { │ │ │ │ │ + var last = components[components.length - 3]; │ │ │ │ │ + point.x = last.x; │ │ │ │ │ + point.y = last.y; │ │ │ │ │ } │ │ │ │ │ - return css; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getGraphicFormat │ │ │ │ │ - * Given a href for an external graphic, try to determine the mime-type. │ │ │ │ │ - * This method doesn't try too hard, and will fall back to │ │ │ │ │ - * if one of the known is not │ │ │ │ │ - * the file extension of the provided href. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * href - {String} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The graphic format. │ │ │ │ │ + * Method: finishGeometry │ │ │ │ │ + * Finish the geometry and send it back to the control. │ │ │ │ │ */ │ │ │ │ │ - getGraphicFormat: function(href) { │ │ │ │ │ - var format, regex; │ │ │ │ │ - for (var key in this.graphicFormats) { │ │ │ │ │ - if (this.graphicFormats[key].test(href)) { │ │ │ │ │ - format = key; │ │ │ │ │ - break; │ │ │ │ │ + finishGeometry: function() { │ │ │ │ │ + var index = this.line.geometry.components.length - 2; │ │ │ │ │ + this.line.geometry.removeComponent(this.line.geometry.components[index]); │ │ │ │ │ + this.removePoint(); │ │ │ │ │ + this.finalize(); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: finalizeInteriorRing │ │ │ │ │ + * Enforces that new ring has some area and doesn't contain vertices of any │ │ │ │ │ + * other rings. │ │ │ │ │ + */ │ │ │ │ │ + finalizeInteriorRing: function() { │ │ │ │ │ + var ring = this.line.geometry; │ │ │ │ │ + // ensure that ring has some area │ │ │ │ │ + var modified = (ring.getArea() !== 0); │ │ │ │ │ + if (modified) { │ │ │ │ │ + // ensure that new ring doesn't intersect any other rings │ │ │ │ │ + var rings = this.polygon.geometry.components; │ │ │ │ │ + for (var i = rings.length - 2; i >= 0; --i) { │ │ │ │ │ + if (ring.intersects(rings[i])) { │ │ │ │ │ + modified = false; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (modified) { │ │ │ │ │ + // ensure that new ring doesn't contain any other rings │ │ │ │ │ + var target; │ │ │ │ │ + outer: for (var i = rings.length - 2; i > 0; --i) { │ │ │ │ │ + var points = rings[i].components; │ │ │ │ │ + for (var j = 0, jj = points.length; j < jj; ++j) { │ │ │ │ │ + if (ring.containsPoint(points[j])) { │ │ │ │ │ + modified = false; │ │ │ │ │ + break outer; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return format || this.defaultGraphicFormat; │ │ │ │ │ + if (modified) { │ │ │ │ │ + if (this.polygon.state !== OpenLayers.State.INSERT) { │ │ │ │ │ + this.polygon.state = OpenLayers.State.UPDATE; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + this.polygon.geometry.removeComponent(ring); │ │ │ │ │ + } │ │ │ │ │ + this.restoreFeature(); │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: defaultGraphicFormat │ │ │ │ │ - * {String} If none other can be determined from , this │ │ │ │ │ - * default will be returned. │ │ │ │ │ + * APIMethod: cancel │ │ │ │ │ + * Finish the geometry and call the "cancel" callback. │ │ │ │ │ */ │ │ │ │ │ - defaultGraphicFormat: "image/png", │ │ │ │ │ + cancel: function() { │ │ │ │ │ + if (this.drawingHole) { │ │ │ │ │ + this.polygon.geometry.removeComponent(this.line.geometry); │ │ │ │ │ + this.restoreFeature(true); │ │ │ │ │ + } │ │ │ │ │ + return OpenLayers.Handler.Path.prototype.cancel.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: graphicFormats │ │ │ │ │ - * {Object} Mapping of image mime-types to regular extensions matching │ │ │ │ │ - * well-known file extensions. │ │ │ │ │ + * Method: restoreFeature │ │ │ │ │ + * Move the feature from the sketch layer to the target layer. │ │ │ │ │ + * │ │ │ │ │ + * Properties: │ │ │ │ │ + * cancel - {Boolean} Cancel drawing. If falsey, the "sketchcomplete" event │ │ │ │ │ + * will be fired. │ │ │ │ │ */ │ │ │ │ │ - graphicFormats: { │ │ │ │ │ - "image/jpeg": /\.jpe?g$/i, │ │ │ │ │ - "image/gif": /\.gif$/i, │ │ │ │ │ - "image/png": /\.png$/i │ │ │ │ │ + restoreFeature: function(cancel) { │ │ │ │ │ + this.control.layer.events.unregister( │ │ │ │ │ + "sketchcomplete", this, this.finalizeInteriorRing │ │ │ │ │ + ); │ │ │ │ │ + this.control.layer.events.unregister( │ │ │ │ │ + "sketchmodified", this, this.enforceTopology │ │ │ │ │ + ); │ │ │ │ │ + this.layer.removeFeatures([this.polygon], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.control.layer.addFeatures([this.polygon], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.drawingHole = false; │ │ │ │ │ + if (!cancel) { │ │ │ │ │ + // Re-trigger "sketchcomplete" so other listeners can do their │ │ │ │ │ + // business. While this is somewhat sloppy (if a listener is │ │ │ │ │ + // registered with registerPriority - not common - between the start │ │ │ │ │ + // and end of a single ring drawing - very uncommon - it will be │ │ │ │ │ + // called twice). │ │ │ │ │ + // TODO: In 3.0, collapse sketch handlers into geometry specific │ │ │ │ │ + // drawing controls. │ │ │ │ │ + this.control.layer.events.triggerEvent( │ │ │ │ │ + "sketchcomplete", { │ │ │ │ │ + feature: this.polygon │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: write │ │ │ │ │ + * Method: destroyFeature │ │ │ │ │ + * Destroy temporary geometries │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * sld - {Object} An object representing the SLD. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} The root of an SLD document. │ │ │ │ │ + * force - {Boolean} Destroy even if persist is true. │ │ │ │ │ */ │ │ │ │ │ - write: function(sld) { │ │ │ │ │ - return this.writers.sld.StyledLayerDescriptor.apply(this, [sld]); │ │ │ │ │ + destroyFeature: function(force) { │ │ │ │ │ + OpenLayers.Handler.Path.prototype.destroyFeature.call( │ │ │ │ │ + this, force); │ │ │ │ │ + this.polygon = null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: writers │ │ │ │ │ - * As a compliment to the readers property, this structure contains public │ │ │ │ │ - * writing functions grouped by namespace alias and named like the │ │ │ │ │ - * node names they produce. │ │ │ │ │ + * Method: drawFeature │ │ │ │ │ + * Render geometries on the temporary layer. │ │ │ │ │ */ │ │ │ │ │ - writers: OpenLayers.Util.applyDefaults({ │ │ │ │ │ - "sld": { │ │ │ │ │ - "_OGCExpression": function(nodeName, value) { │ │ │ │ │ - // only the simplest of ogc:expression handled │ │ │ │ │ - // {label: "some text and a ${propertyName}"} │ │ │ │ │ - var node = this.createElementNSPlus(nodeName); │ │ │ │ │ - var tokens = typeof value == "string" ? │ │ │ │ │ - value.split("${") : [value]; │ │ │ │ │ - node.appendChild(this.createTextNode(tokens[0])); │ │ │ │ │ - var item, last; │ │ │ │ │ - for (var i = 1, len = tokens.length; i < len; i++) { │ │ │ │ │ - item = tokens[i]; │ │ │ │ │ - last = item.indexOf("}"); │ │ │ │ │ - if (last > 0) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "ogc:PropertyName", { │ │ │ │ │ - property: item.substring(0, last) │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - node.appendChild( │ │ │ │ │ - this.createTextNode(item.substring(++last)) │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - // no ending }, so this is a literal ${ │ │ │ │ │ - node.appendChild( │ │ │ │ │ - this.createTextNode("${" + item) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "StyledLayerDescriptor": function(sld) { │ │ │ │ │ - var root = this.createElementNSPlus( │ │ │ │ │ - "sld:StyledLayerDescriptor", { │ │ │ │ │ - attributes: { │ │ │ │ │ - "version": this.VERSION, │ │ │ │ │ - "xsi:schemaLocation": this.schemaLocation │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - // For ArcGIS Server it is necessary to define this │ │ │ │ │ - // at the root level (see ticket:2166). │ │ │ │ │ - root.setAttribute("xmlns:ogc", this.namespaces.ogc); │ │ │ │ │ - root.setAttribute("xmlns:gml", this.namespaces.gml); │ │ │ │ │ - │ │ │ │ │ - // add in optional name │ │ │ │ │ - if (sld.name) { │ │ │ │ │ - this.writeNode("Name", sld.name, root); │ │ │ │ │ - } │ │ │ │ │ - // add in optional title │ │ │ │ │ - if (sld.title) { │ │ │ │ │ - this.writeNode("Title", sld.title, root); │ │ │ │ │ - } │ │ │ │ │ - // add in optional description │ │ │ │ │ - if (sld.description) { │ │ │ │ │ - this.writeNode("Abstract", sld.description, root); │ │ │ │ │ - } │ │ │ │ │ - // add in named layers │ │ │ │ │ - // allow namedLayers to be an array │ │ │ │ │ - if (OpenLayers.Util.isArray(sld.namedLayers)) { │ │ │ │ │ - for (var i = 0, len = sld.namedLayers.length; i < len; ++i) { │ │ │ │ │ - this.writeNode("NamedLayer", sld.namedLayers[i], root); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - for (var name in sld.namedLayers) { │ │ │ │ │ - this.writeNode("NamedLayer", sld.namedLayers[name], root); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return root; │ │ │ │ │ - }, │ │ │ │ │ - "Name": function(name) { │ │ │ │ │ - return this.createElementNSPlus("sld:Name", { │ │ │ │ │ - value: name │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Title": function(title) { │ │ │ │ │ - return this.createElementNSPlus("sld:Title", { │ │ │ │ │ - value: title │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Abstract": function(description) { │ │ │ │ │ - return this.createElementNSPlus( │ │ │ │ │ - "sld:Abstract", { │ │ │ │ │ - value: description │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "NamedLayer": function(layer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:NamedLayer"); │ │ │ │ │ - │ │ │ │ │ - // add in required name │ │ │ │ │ - this.writeNode("Name", layer.name, node); │ │ │ │ │ - │ │ │ │ │ - // optional sld:LayerFeatureConstraints here │ │ │ │ │ - │ │ │ │ │ - // add in named styles │ │ │ │ │ - if (layer.namedStyles) { │ │ │ │ │ - for (var i = 0, len = layer.namedStyles.length; i < len; ++i) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "NamedStyle", layer.namedStyles[i], node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // add in user styles │ │ │ │ │ - if (layer.userStyles) { │ │ │ │ │ - for (var i = 0, len = layer.userStyles.length; i < len; ++i) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "UserStyle", layer.userStyles[i], node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "NamedStyle": function(name) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:NamedStyle"); │ │ │ │ │ - this.writeNode("Name", name, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "UserStyle": function(style) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:UserStyle"); │ │ │ │ │ - │ │ │ │ │ - // add in optional name │ │ │ │ │ - if (style.name) { │ │ │ │ │ - this.writeNode("Name", style.name, node); │ │ │ │ │ - } │ │ │ │ │ - // add in optional title │ │ │ │ │ - if (style.title) { │ │ │ │ │ - this.writeNode("Title", style.title, node); │ │ │ │ │ - } │ │ │ │ │ - // add in optional description │ │ │ │ │ - if (style.description) { │ │ │ │ │ - this.writeNode("Abstract", style.description, node); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // add isdefault │ │ │ │ │ - if (style.isDefault) { │ │ │ │ │ - this.writeNode("IsDefault", style.isDefault, node); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // add FeatureTypeStyles │ │ │ │ │ - if (this.multipleSymbolizers && style.rules) { │ │ │ │ │ - // group style objects by symbolizer zIndex │ │ │ │ │ - var rulesByZ = { │ │ │ │ │ - 0: [] │ │ │ │ │ - }; │ │ │ │ │ - var zValues = [0]; │ │ │ │ │ - var rule, ruleMap, symbolizer, zIndex, clone; │ │ │ │ │ - for (var i = 0, ii = style.rules.length; i < ii; ++i) { │ │ │ │ │ - rule = style.rules[i]; │ │ │ │ │ - if (rule.symbolizers) { │ │ │ │ │ - ruleMap = {}; │ │ │ │ │ - for (var j = 0, jj = rule.symbolizers.length; j < jj; ++j) { │ │ │ │ │ - symbolizer = rule.symbolizers[j]; │ │ │ │ │ - zIndex = symbolizer.zIndex; │ │ │ │ │ - if (!(zIndex in ruleMap)) { │ │ │ │ │ - clone = rule.clone(); │ │ │ │ │ - clone.symbolizers = []; │ │ │ │ │ - ruleMap[zIndex] = clone; │ │ │ │ │ - } │ │ │ │ │ - ruleMap[zIndex].symbolizers.push(symbolizer.clone()); │ │ │ │ │ - } │ │ │ │ │ - for (zIndex in ruleMap) { │ │ │ │ │ - if (!(zIndex in rulesByZ)) { │ │ │ │ │ - zValues.push(zIndex); │ │ │ │ │ - rulesByZ[zIndex] = []; │ │ │ │ │ - } │ │ │ │ │ - rulesByZ[zIndex].push(ruleMap[zIndex]); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // no symbolizers in rule │ │ │ │ │ - rulesByZ[0].push(rule.clone()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // write one FeatureTypeStyle per zIndex │ │ │ │ │ - zValues.sort(); │ │ │ │ │ - var rules; │ │ │ │ │ - for (var i = 0, ii = zValues.length; i < ii; ++i) { │ │ │ │ │ - rules = rulesByZ[zValues[i]]; │ │ │ │ │ - if (rules.length > 0) { │ │ │ │ │ - clone = style.clone(); │ │ │ │ │ - clone.rules = rulesByZ[zValues[i]]; │ │ │ │ │ - this.writeNode("FeatureTypeStyle", clone, node); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - this.writeNode("FeatureTypeStyle", style, node); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "IsDefault": function(bool) { │ │ │ │ │ - return this.createElementNSPlus( │ │ │ │ │ - "sld:IsDefault", { │ │ │ │ │ - value: (bool) ? "1" : "0" │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "FeatureTypeStyle": function(style) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:FeatureTypeStyle"); │ │ │ │ │ - │ │ │ │ │ - // OpenLayers currently stores no Name, Title, Abstract, │ │ │ │ │ - // FeatureTypeName, or SemanticTypeIdentifier information │ │ │ │ │ - // related to FeatureTypeStyle │ │ │ │ │ - │ │ │ │ │ - // add in rules │ │ │ │ │ - for (var i = 0, len = style.rules.length; i < len; ++i) { │ │ │ │ │ - this.writeNode("Rule", style.rules[i], node); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Rule": function(rule) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:Rule"); │ │ │ │ │ - │ │ │ │ │ - // add in optional name │ │ │ │ │ - if (rule.name) { │ │ │ │ │ - this.writeNode("Name", rule.name, node); │ │ │ │ │ - } │ │ │ │ │ - // add in optional title │ │ │ │ │ - if (rule.title) { │ │ │ │ │ - this.writeNode("Title", rule.title, node); │ │ │ │ │ - } │ │ │ │ │ - // add in optional description │ │ │ │ │ - if (rule.description) { │ │ │ │ │ - this.writeNode("Abstract", rule.description, node); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // add in LegendGraphic here │ │ │ │ │ - │ │ │ │ │ - // add in optional filters │ │ │ │ │ - if (rule.elseFilter) { │ │ │ │ │ - this.writeNode("ElseFilter", null, node); │ │ │ │ │ - } else if (rule.filter) { │ │ │ │ │ - this.writeNode("ogc:Filter", rule.filter, node); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // add in scale limits │ │ │ │ │ - if (rule.minScaleDenominator != undefined) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "MinScaleDenominator", rule.minScaleDenominator, node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (rule.maxScaleDenominator != undefined) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "MaxScaleDenominator", rule.maxScaleDenominator, node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var type, symbolizer; │ │ │ │ │ - if (this.multipleSymbolizers && rule.symbolizers) { │ │ │ │ │ - var symbolizer; │ │ │ │ │ - for (var i = 0, ii = rule.symbolizers.length; i < ii; ++i) { │ │ │ │ │ - symbolizer = rule.symbolizers[i]; │ │ │ │ │ - type = symbolizer.CLASS_NAME.split(".").pop(); │ │ │ │ │ - this.writeNode( │ │ │ │ │ - type + "Symbolizer", symbolizer, node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - // add in symbolizers (relies on geometry type keys) │ │ │ │ │ - var types = OpenLayers.Style.SYMBOLIZER_PREFIXES; │ │ │ │ │ - for (var i = 0, len = types.length; i < len; ++i) { │ │ │ │ │ - type = types[i]; │ │ │ │ │ - symbolizer = rule.symbolizer[type]; │ │ │ │ │ - if (symbolizer) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - type + "Symbolizer", symbolizer, node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - │ │ │ │ │ - }, │ │ │ │ │ - "ElseFilter": function() { │ │ │ │ │ - return this.createElementNSPlus("sld:ElseFilter"); │ │ │ │ │ - }, │ │ │ │ │ - "MinScaleDenominator": function(scale) { │ │ │ │ │ - return this.createElementNSPlus( │ │ │ │ │ - "sld:MinScaleDenominator", { │ │ │ │ │ - value: scale │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "MaxScaleDenominator": function(scale) { │ │ │ │ │ - return this.createElementNSPlus( │ │ │ │ │ - "sld:MaxScaleDenominator", { │ │ │ │ │ - value: scale │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "LineSymbolizer": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:LineSymbolizer"); │ │ │ │ │ - this.writeNode("Stroke", symbolizer, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Stroke": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:Stroke"); │ │ │ │ │ - │ │ │ │ │ - // GraphicFill here │ │ │ │ │ - // GraphicStroke here │ │ │ │ │ - │ │ │ │ │ - // add in CssParameters │ │ │ │ │ - if (symbolizer.strokeColor != undefined) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "strokeColor" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.strokeOpacity != undefined) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "strokeOpacity" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.strokeWidth != undefined) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "strokeWidth" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.strokeDashstyle != undefined && symbolizer.strokeDashstyle !== "solid") { │ │ │ │ │ - // assumes valid stroke-dasharray value │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "strokeDashstyle" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.strokeLinecap != undefined) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "strokeLinecap" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "CssParameter": function(obj) { │ │ │ │ │ - // not handling ogc:expressions for now │ │ │ │ │ - return this.createElementNSPlus("sld:CssParameter", { │ │ │ │ │ - attributes: { │ │ │ │ │ - name: this.getCssProperty(obj.key) │ │ │ │ │ - }, │ │ │ │ │ - value: obj.symbolizer[obj.key] │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "TextSymbolizer": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:TextSymbolizer"); │ │ │ │ │ - // add in optional Label │ │ │ │ │ - if (symbolizer.label != null) { │ │ │ │ │ - this.writeNode("Label", symbolizer.label, node); │ │ │ │ │ - } │ │ │ │ │ - // add in optional Font │ │ │ │ │ - if (symbolizer.fontFamily != null || │ │ │ │ │ - symbolizer.fontSize != null || │ │ │ │ │ - symbolizer.fontWeight != null || │ │ │ │ │ - symbolizer.fontStyle != null) { │ │ │ │ │ - this.writeNode("Font", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - // add in optional LabelPlacement │ │ │ │ │ - if (symbolizer.labelAnchorPointX != null || │ │ │ │ │ - symbolizer.labelAnchorPointY != null || │ │ │ │ │ - symbolizer.labelAlign != null || │ │ │ │ │ - symbolizer.labelXOffset != null || │ │ │ │ │ - symbolizer.labelYOffset != null || │ │ │ │ │ - symbolizer.labelRotation != null || │ │ │ │ │ - symbolizer.labelPerpendicularOffset != null) { │ │ │ │ │ - this.writeNode("LabelPlacement", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - // add in optional Halo │ │ │ │ │ - if (symbolizer.haloRadius != null || │ │ │ │ │ - symbolizer.haloColor != null || │ │ │ │ │ - symbolizer.haloOpacity != null) { │ │ │ │ │ - this.writeNode("Halo", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - // add in optional Fill │ │ │ │ │ - if (symbolizer.fontColor != null || │ │ │ │ │ - symbolizer.fontOpacity != null) { │ │ │ │ │ - this.writeNode("Fill", { │ │ │ │ │ - fillColor: symbolizer.fontColor, │ │ │ │ │ - fillOpacity: symbolizer.fontOpacity │ │ │ │ │ - }, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "LabelPlacement": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:LabelPlacement"); │ │ │ │ │ - // PointPlacement and LinePlacement are choices, so don't output both │ │ │ │ │ - if ((symbolizer.labelAnchorPointX != null || │ │ │ │ │ - symbolizer.labelAnchorPointY != null || │ │ │ │ │ - symbolizer.labelAlign != null || │ │ │ │ │ - symbolizer.labelXOffset != null || │ │ │ │ │ - symbolizer.labelYOffset != null || │ │ │ │ │ - symbolizer.labelRotation != null) && │ │ │ │ │ - symbolizer.labelPerpendicularOffset == null) { │ │ │ │ │ - this.writeNode("PointPlacement", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.labelPerpendicularOffset != null) { │ │ │ │ │ - this.writeNode("LinePlacement", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "LinePlacement": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:LinePlacement"); │ │ │ │ │ - this.writeNode("PerpendicularOffset", symbolizer.labelPerpendicularOffset, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PerpendicularOffset": function(value) { │ │ │ │ │ - return this.createElementNSPlus("sld:PerpendicularOffset", { │ │ │ │ │ - value: value │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "PointPlacement": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:PointPlacement"); │ │ │ │ │ - if (symbolizer.labelAnchorPointX != null || │ │ │ │ │ - symbolizer.labelAnchorPointY != null || │ │ │ │ │ - symbolizer.labelAlign != null) { │ │ │ │ │ - this.writeNode("AnchorPoint", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.labelXOffset != null || │ │ │ │ │ - symbolizer.labelYOffset != null) { │ │ │ │ │ - this.writeNode("Displacement", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.labelRotation != null) { │ │ │ │ │ - this.writeNode("Rotation", symbolizer.labelRotation, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "AnchorPoint": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:AnchorPoint"); │ │ │ │ │ - var x = symbolizer.labelAnchorPointX, │ │ │ │ │ - y = symbolizer.labelAnchorPointY; │ │ │ │ │ - if (x != null) { │ │ │ │ │ - this.writeNode("AnchorPointX", x, node); │ │ │ │ │ - } │ │ │ │ │ - if (y != null) { │ │ │ │ │ - this.writeNode("AnchorPointY", y, node); │ │ │ │ │ - } │ │ │ │ │ - if (x == null && y == null) { │ │ │ │ │ - var xAlign = symbolizer.labelAlign.substr(0, 1), │ │ │ │ │ - yAlign = symbolizer.labelAlign.substr(1, 1); │ │ │ │ │ - if (xAlign === "l") { │ │ │ │ │ - x = 0; │ │ │ │ │ - } else if (xAlign === "c") { │ │ │ │ │ - x = 0.5; │ │ │ │ │ - } else if (xAlign === "r") { │ │ │ │ │ - x = 1; │ │ │ │ │ - } │ │ │ │ │ - if (yAlign === "b") { │ │ │ │ │ - y = 0; │ │ │ │ │ - } else if (yAlign === "m") { │ │ │ │ │ - y = 0.5; │ │ │ │ │ - } else if (yAlign === "t") { │ │ │ │ │ - y = 1; │ │ │ │ │ - } │ │ │ │ │ - this.writeNode("AnchorPointX", x, node); │ │ │ │ │ - this.writeNode("AnchorPointY", y, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "AnchorPointX": function(value) { │ │ │ │ │ - return this.createElementNSPlus("sld:AnchorPointX", { │ │ │ │ │ - value: value │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "AnchorPointY": function(value) { │ │ │ │ │ - return this.createElementNSPlus("sld:AnchorPointY", { │ │ │ │ │ - value: value │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Displacement": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:Displacement"); │ │ │ │ │ - if (symbolizer.labelXOffset != null) { │ │ │ │ │ - this.writeNode("DisplacementX", symbolizer.labelXOffset, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.labelYOffset != null) { │ │ │ │ │ - this.writeNode("DisplacementY", symbolizer.labelYOffset, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "DisplacementX": function(value) { │ │ │ │ │ - return this.createElementNSPlus("sld:DisplacementX", { │ │ │ │ │ - value: value │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "DisplacementY": function(value) { │ │ │ │ │ - return this.createElementNSPlus("sld:DisplacementY", { │ │ │ │ │ - value: value │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Font": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:Font"); │ │ │ │ │ - // add in CssParameters │ │ │ │ │ - if (symbolizer.fontFamily) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "fontFamily" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.fontSize) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "fontSize" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.fontWeight) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "fontWeight" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.fontStyle) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "fontStyle" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Label": function(label) { │ │ │ │ │ - return this.writers.sld._OGCExpression.call( │ │ │ │ │ - this, "sld:Label", label │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "Halo": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:Halo"); │ │ │ │ │ - if (symbolizer.haloRadius) { │ │ │ │ │ - this.writeNode("Radius", symbolizer.haloRadius, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.haloColor || symbolizer.haloOpacity) { │ │ │ │ │ - this.writeNode("Fill", { │ │ │ │ │ - fillColor: symbolizer.haloColor, │ │ │ │ │ - fillOpacity: symbolizer.haloOpacity │ │ │ │ │ - }, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Radius": function(value) { │ │ │ │ │ - return this.createElementNSPlus("sld:Radius", { │ │ │ │ │ - value: value │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "RasterSymbolizer": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:RasterSymbolizer"); │ │ │ │ │ - if (symbolizer.geometry) { │ │ │ │ │ - this.writeNode("Geometry", symbolizer.geometry, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.opacity) { │ │ │ │ │ - this.writeNode("Opacity", symbolizer.opacity, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.colorMap) { │ │ │ │ │ - this.writeNode("ColorMap", symbolizer.colorMap, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Geometry": function(geometry) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:Geometry"); │ │ │ │ │ - if (geometry.property) { │ │ │ │ │ - this.writeNode("ogc:PropertyName", geometry, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "ColorMap": function(colorMap) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:ColorMap"); │ │ │ │ │ - for (var i = 0, len = colorMap.length; i < len; ++i) { │ │ │ │ │ - this.writeNode("ColorMapEntry", colorMap[i], node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "ColorMapEntry": function(colorMapEntry) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:ColorMapEntry"); │ │ │ │ │ - var a = colorMapEntry; │ │ │ │ │ - node.setAttribute("color", a.color); │ │ │ │ │ - a.opacity !== undefined && node.setAttribute("opacity", │ │ │ │ │ - parseFloat(a.opacity)); │ │ │ │ │ - a.quantity !== undefined && node.setAttribute("quantity", │ │ │ │ │ - parseFloat(a.quantity)); │ │ │ │ │ - a.label !== undefined && node.setAttribute("label", a.label); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PolygonSymbolizer": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:PolygonSymbolizer"); │ │ │ │ │ - if (symbolizer.fill !== false) { │ │ │ │ │ - this.writeNode("Fill", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.stroke !== false) { │ │ │ │ │ - this.writeNode("Stroke", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Fill": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:Fill"); │ │ │ │ │ - │ │ │ │ │ - // GraphicFill here │ │ │ │ │ + drawFeature: function() { │ │ │ │ │ + this.layer.drawFeature(this.polygon, this.style); │ │ │ │ │ + this.layer.drawFeature(this.point, this.style); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // add in CssParameters │ │ │ │ │ - if (symbolizer.fillColor) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "fillColor" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.fillOpacity != null) { │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "CssParameter", { │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - key: "fillOpacity" │ │ │ │ │ - }, │ │ │ │ │ - node │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "PointSymbolizer": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:PointSymbolizer"); │ │ │ │ │ - this.writeNode("Graphic", symbolizer, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Graphic": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:Graphic"); │ │ │ │ │ - if (symbolizer.externalGraphic != undefined) { │ │ │ │ │ - this.writeNode("ExternalGraphic", symbolizer, node); │ │ │ │ │ - } else { │ │ │ │ │ - this.writeNode("Mark", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: getSketch │ │ │ │ │ + * Return the sketch feature. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getSketch: function() { │ │ │ │ │ + return this.polygon; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (symbolizer.graphicOpacity != undefined) { │ │ │ │ │ - this.writeNode("Opacity", symbolizer.graphicOpacity, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.pointRadius != undefined) { │ │ │ │ │ - this.writeNode("Size", symbolizer.pointRadius * 2, node); │ │ │ │ │ - } else if (symbolizer.graphicWidth != undefined) { │ │ │ │ │ - this.writeNode("Size", symbolizer.graphicWidth, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.rotation != undefined) { │ │ │ │ │ - this.writeNode("Rotation", symbolizer.rotation, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "ExternalGraphic": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:ExternalGraphic"); │ │ │ │ │ - this.writeNode( │ │ │ │ │ - "OnlineResource", symbolizer.externalGraphic, node │ │ │ │ │ - ); │ │ │ │ │ - var format = symbolizer.graphicFormat || │ │ │ │ │ - this.getGraphicFormat(symbolizer.externalGraphic); │ │ │ │ │ - this.writeNode("Format", format, node); │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "Mark": function(symbolizer) { │ │ │ │ │ - var node = this.createElementNSPlus("sld:Mark"); │ │ │ │ │ - if (symbolizer.graphicName) { │ │ │ │ │ - this.writeNode("WellKnownName", symbolizer.graphicName, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.fill !== false) { │ │ │ │ │ - this.writeNode("Fill", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - if (symbolizer.stroke !== false) { │ │ │ │ │ - this.writeNode("Stroke", symbolizer, node); │ │ │ │ │ - } │ │ │ │ │ - return node; │ │ │ │ │ - }, │ │ │ │ │ - "WellKnownName": function(name) { │ │ │ │ │ - return this.createElementNSPlus("sld:WellKnownName", { │ │ │ │ │ - value: name │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Opacity": function(value) { │ │ │ │ │ - return this.createElementNSPlus("sld:Opacity", { │ │ │ │ │ - value: value │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Size": function(value) { │ │ │ │ │ - return this.writers.sld._OGCExpression.call( │ │ │ │ │ - this, "sld:Size", value │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - "Rotation": function(value) { │ │ │ │ │ - return this.createElementNSPlus("sld:Rotation", { │ │ │ │ │ - value: value │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "OnlineResource": function(href) { │ │ │ │ │ - return this.createElementNSPlus("sld:OnlineResource", { │ │ │ │ │ - attributes: { │ │ │ │ │ - "xlink:type": "simple", │ │ │ │ │ - "xlink:href": href │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - "Format": function(format) { │ │ │ │ │ - return this.createElementNSPlus("sld:Format", { │ │ │ │ │ - value: format │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: getGeometry │ │ │ │ │ + * Return the sketch geometry. If is true, this will return │ │ │ │ │ + * a multi-part geometry. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} │ │ │ │ │ + */ │ │ │ │ │ + getGeometry: function() { │ │ │ │ │ + var geometry = this.polygon && this.polygon.geometry; │ │ │ │ │ + if (geometry && this.multi) { │ │ │ │ │ + geometry = new OpenLayers.Geometry.MultiPolygon([geometry]); │ │ │ │ │ } │ │ │ │ │ - }, OpenLayers.Format.Filter.v1_0_0.prototype.writers), │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.SLD.v1" │ │ │ │ │ + return geometry; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.Polygon" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/SLD/v1_0_0.js │ │ │ │ │ + OpenLayers/Control/EditingToolbar.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Format/SLD/v1.js │ │ │ │ │ - * @requires OpenLayers/Format/Filter/v1_0_0.js │ │ │ │ │ + * @requires OpenLayers/Control/Panel.js │ │ │ │ │ + * @requires OpenLayers/Control/Navigation.js │ │ │ │ │ + * @requires OpenLayers/Control/DrawFeature.js │ │ │ │ │ + * @requires OpenLayers/Handler/Point.js │ │ │ │ │ + * @requires OpenLayers/Handler/Path.js │ │ │ │ │ + * @requires OpenLayers/Handler/Polygon.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.SLD.v1_0_0 │ │ │ │ │ - * Write SLD version 1.0.0. │ │ │ │ │ + * Class: OpenLayers.Control.EditingToolbar │ │ │ │ │ + * The EditingToolbar is a panel of 4 controls to draw polygons, lines, │ │ │ │ │ + * points, or to navigate the map by panning. By default it appears in the │ │ │ │ │ + * upper right corner of the map. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.SLD.v1_0_0 = OpenLayers.Class( │ │ │ │ │ - OpenLayers.Format.SLD.v1, { │ │ │ │ │ +OpenLayers.Control.EditingToolbar = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Control.Panel, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: VERSION │ │ │ │ │ - * {String} 1.0.0 │ │ │ │ │ + * APIProperty: citeCompliant │ │ │ │ │ + * {Boolean} If set to true, coordinates of features drawn in a map extent │ │ │ │ │ + * crossing the date line won't exceed the world bounds. Default is false. │ │ │ │ │ */ │ │ │ │ │ - VERSION: "1.0.0", │ │ │ │ │ + citeCompliant: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: schemaLocation │ │ │ │ │ - * {String} http://www.opengis.net/sld │ │ │ │ │ - * http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd │ │ │ │ │ + * Constructor: OpenLayers.Control.EditingToolbar │ │ │ │ │ + * Create an editing toolbar for a given layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - schemaLocation: "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd", │ │ │ │ │ + initialize: function(layer, options) { │ │ │ │ │ + OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ + │ │ │ │ │ + this.addControls( │ │ │ │ │ + [new OpenLayers.Control.Navigation()] │ │ │ │ │ + ); │ │ │ │ │ + var controls = [ │ │ │ │ │ + new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, { │ │ │ │ │ + displayClass: 'olControlDrawFeaturePoint', │ │ │ │ │ + handlerOptions: { │ │ │ │ │ + citeCompliant: this.citeCompliant │ │ │ │ │ + } │ │ │ │ │ + }), │ │ │ │ │ + new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, { │ │ │ │ │ + displayClass: 'olControlDrawFeaturePath', │ │ │ │ │ + handlerOptions: { │ │ │ │ │ + citeCompliant: this.citeCompliant │ │ │ │ │ + } │ │ │ │ │ + }), │ │ │ │ │ + new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, { │ │ │ │ │ + displayClass: 'olControlDrawFeaturePolygon', │ │ │ │ │ + handlerOptions: { │ │ │ │ │ + citeCompliant: this.citeCompliant │ │ │ │ │ + } │ │ │ │ │ + }) │ │ │ │ │ + ]; │ │ │ │ │ + this.addControls(controls); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.SLD.v1_0_0 │ │ │ │ │ - * Instances of this class are not created directly. Use the │ │ │ │ │ - * constructor instead. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * calls the default draw, and then activates mouse defaults. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (this.defaultControl === null) { │ │ │ │ │ + this.defaultControl = this.controls[0]; │ │ │ │ │ + } │ │ │ │ │ + return div; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.SLD.v1_0_0" │ │ │ │ │ - │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.EditingToolbar" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/SLDSelect.js │ │ │ │ │ + OpenLayers/Control/LayerSwitcher.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Layer/WMS.js │ │ │ │ │ - * @requires OpenLayers/Handler/RegularPolygon.js │ │ │ │ │ - * @requires OpenLayers/Handler/Polygon.js │ │ │ │ │ - * @requires OpenLayers/Handler/Path.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ - * @requires OpenLayers/Filter/Spatial.js │ │ │ │ │ - * @requires OpenLayers/Format/SLD/v1_0_0.js │ │ │ │ │ + * @requires OpenLayers/Lang.js │ │ │ │ │ + * @requires OpenLayers/Util.js │ │ │ │ │ + * @requires OpenLayers/Events/buttonclick.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.SLDSelect │ │ │ │ │ - * Perform selections on WMS layers using Styled Layer Descriptor (SLD) │ │ │ │ │ + * Class: OpenLayers.Control.LayerSwitcher │ │ │ │ │ + * The LayerSwitcher control displays a table of contents for the map. This │ │ │ │ │ + * allows the user interface to switch between BaseLasyers and to show or hide │ │ │ │ │ + * Overlays. By default the switcher is shown minimized on the right edge of │ │ │ │ │ + * the map, the user may expand it by clicking on the handle. │ │ │ │ │ + * │ │ │ │ │ + * To create the LayerSwitcher outside of the map, pass the Id of a html div │ │ │ │ │ + * as the first argument to the constructor. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.SLDSelect = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.LayerSwitcher = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * selected - Triggered when a selection occurs. Listeners receive an │ │ │ │ │ - * event with *filters* and *layer* properties. Filters will be an │ │ │ │ │ - * array of OpenLayers.Filter objects created in order to perform │ │ │ │ │ - * the particular selection. │ │ │ │ │ + /** │ │ │ │ │ + * Property: layerStates │ │ │ │ │ + * {Array(Object)} Basically a copy of the "state" of the map's layers │ │ │ │ │ + * the last time the control was drawn. We have this in order to avoid │ │ │ │ │ + * unnecessarily redrawing the control. │ │ │ │ │ */ │ │ │ │ │ + layerStates: null, │ │ │ │ │ + │ │ │ │ │ + // DOM Elements │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: clearOnDeactivate │ │ │ │ │ - * {Boolean} Should the selection be cleared when the control is │ │ │ │ │ - * deactivated. Default value is false. │ │ │ │ │ + * Property: layersDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - clearOnDeactivate: false, │ │ │ │ │ + layersDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array()} The WMS layers this control will work │ │ │ │ │ - * on. │ │ │ │ │ + * Property: baseLayersDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + baseLayersDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: callbacks │ │ │ │ │ - * {Object} The functions that are sent to the handler for callback │ │ │ │ │ + * Property: baseLayers │ │ │ │ │ + * {Array(Object)} │ │ │ │ │ */ │ │ │ │ │ - callbacks: null, │ │ │ │ │ + baseLayers: null, │ │ │ │ │ + │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: selectionSymbolizer │ │ │ │ │ - * {Object} Determines the styling of the selected objects. Default is │ │ │ │ │ - * a selection in red. │ │ │ │ │ + * Property: dataLbl │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - selectionSymbolizer: { │ │ │ │ │ - 'Polygon': { │ │ │ │ │ - fillColor: '#FF0000', │ │ │ │ │ - stroke: false │ │ │ │ │ - }, │ │ │ │ │ - 'Line': { │ │ │ │ │ - strokeColor: '#FF0000', │ │ │ │ │ - strokeWidth: 2 │ │ │ │ │ - }, │ │ │ │ │ - 'Point': { │ │ │ │ │ - graphicName: 'square', │ │ │ │ │ - fillColor: '#FF0000', │ │ │ │ │ - pointRadius: 5 │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + dataLbl: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layerOptions │ │ │ │ │ - * {Object} The options to apply to the selection layer, by default the │ │ │ │ │ - * selection layer will be kept out of the layer switcher. │ │ │ │ │ + * Property: dataLayersDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - layerOptions: null, │ │ │ │ │ + dataLayersDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ + * Property: dataLayers │ │ │ │ │ + * {Array(Object)} │ │ │ │ │ */ │ │ │ │ │ + dataLayers: null, │ │ │ │ │ + │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: sketchStyle │ │ │ │ │ - * {|Object} Style or symbolizer to use for the sketch │ │ │ │ │ - * handler. The recommended way of styling the sketch layer, however, is │ │ │ │ │ - * to configure an in the layerOptions of the │ │ │ │ │ - * : │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * new OpenLayers.Control.SLDSelect(OpenLayers.Handler.Path, { │ │ │ │ │ - * handlerOptions: { │ │ │ │ │ - * layerOptions: { │ │ │ │ │ - * styleMap: new OpenLayers.StyleMap({ │ │ │ │ │ - * "default": {strokeColor: "yellow"} │ │ │ │ │ - * }) │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ + * Property: minimizeDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - sketchStyle: null, │ │ │ │ │ + minimizeDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: wfsCache │ │ │ │ │ - * {Object} Cache to use for storing parsed results from │ │ │ │ │ - * . If not provided, │ │ │ │ │ - * these will be cached on the prototype. │ │ │ │ │ + * Property: maximizeDiv │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - wfsCache: {}, │ │ │ │ │ + maximizeDiv: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layerCache │ │ │ │ │ - * {Object} Cache to use for storing references to the selection layers. │ │ │ │ │ - * Normally each source layer will have exactly 1 selection layer of │ │ │ │ │ - * type OpenLayers.Layer.WMS. If not provided, layers will │ │ │ │ │ - * be cached on the prototype. Note that if is │ │ │ │ │ - * true, the layer will no longer be cached after deactivating the │ │ │ │ │ - * control. │ │ │ │ │ + * APIProperty: ascending │ │ │ │ │ + * {Boolean} │ │ │ │ │ */ │ │ │ │ │ - layerCache: {}, │ │ │ │ │ + ascending: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.SLDSelect │ │ │ │ │ - * Create a new control for selecting features in WMS layers using │ │ │ │ │ - * Styled Layer Descriptor (SLD). │ │ │ │ │ + * Constructor: OpenLayers.Control.LayerSwitcher │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * handler - {} A sketch handler class. This determines │ │ │ │ │ - * the type of selection, e.g. box (), point │ │ │ │ │ - * (), path () or │ │ │ │ │ - * polygon () selection. To use circle │ │ │ │ │ - * type selection, use and pass │ │ │ │ │ - * the number of desired sides (e.g. 40) as "sides" property to the │ │ │ │ │ - * . │ │ │ │ │ - * options - {Object} An object containing all configuration properties for │ │ │ │ │ - * the control. │ │ │ │ │ - * │ │ │ │ │ - * Valid options: │ │ │ │ │ - * layers - Array({}) The layers to perform the │ │ │ │ │ - * selection on. │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(handler, options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - │ │ │ │ │ - this.callbacks = OpenLayers.Util.extend({ │ │ │ │ │ - done: this.select, │ │ │ │ │ - click: this.select │ │ │ │ │ - }, this.callbacks); │ │ │ │ │ - this.handlerOptions = this.handlerOptions || {}; │ │ │ │ │ - this.layerOptions = OpenLayers.Util.applyDefaults(this.layerOptions, { │ │ │ │ │ - displayInLayerSwitcher: false, │ │ │ │ │ - tileOptions: { │ │ │ │ │ - maxGetUrlLength: 2048 │ │ │ │ │ - } │ │ │ │ │ - }); │ │ │ │ │ - if (this.sketchStyle) { │ │ │ │ │ - this.handlerOptions.layerOptions = OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.handlerOptions.layerOptions, { │ │ │ │ │ - styleMap: new OpenLayers.StyleMap({ │ │ │ │ │ - "default": this.sketchStyle │ │ │ │ │ - }) │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - this.handler = new handler(this, this.callbacks, this.handlerOptions); │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ + this.layerStates = []; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIMethod: destroy │ │ │ │ │ - * Take care of things that are not handled in superclass. │ │ │ │ │ */ │ │ │ │ │ destroy: function() { │ │ │ │ │ - for (var key in this.layerCache) { │ │ │ │ │ - delete this.layerCache[key]; │ │ │ │ │ - } │ │ │ │ │ - for (var key in this.wfsCache) { │ │ │ │ │ - delete this.wfsCache[key]; │ │ │ │ │ - } │ │ │ │ │ + │ │ │ │ │ + //clear out layers info and unregister their events │ │ │ │ │ + this.clearLayersArray("base"); │ │ │ │ │ + this.clearLayersArray("data"); │ │ │ │ │ + │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + buttonclick: this.onButtonClick, │ │ │ │ │ + addlayer: this.redraw, │ │ │ │ │ + changelayer: this.redraw, │ │ │ │ │ + removelayer: this.redraw, │ │ │ │ │ + changebaselayer: this.redraw, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + this.events.unregister("buttonclick", this, this.onButtonClick); │ │ │ │ │ + │ │ │ │ │ OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: coupleLayerVisiblity │ │ │ │ │ - * Couple the selection layer and the source layer with respect to │ │ │ │ │ - * layer visibility. So if the source layer is turned off, the │ │ │ │ │ - * selection layer is also turned off. │ │ │ │ │ - * │ │ │ │ │ - * Context: │ │ │ │ │ - * - {} │ │ │ │ │ + * Method: setMap │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ + * Properties: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - coupleLayerVisiblity: function(evt) { │ │ │ │ │ - this.setVisibility(evt.object.getVisibility()); │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + addlayer: this.redraw, │ │ │ │ │ + changelayer: this.redraw, │ │ │ │ │ + removelayer: this.redraw, │ │ │ │ │ + changebaselayer: this.redraw, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + if (this.outsideViewport) { │ │ │ │ │ + this.events.attachToElement(this.div); │ │ │ │ │ + this.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ + } else { │ │ │ │ │ + this.map.events.register("buttonclick", this, this.onButtonClick); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createSelectionLayer │ │ │ │ │ - * Creates a "clone" from the source layer in which the selection can │ │ │ │ │ - * be drawn. This ensures both the source layer and the selection are │ │ │ │ │ - * visible and not only the selection. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * source - {} The source layer on which the selection │ │ │ │ │ - * is performed. │ │ │ │ │ + * Method: draw │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} A WMS layer with maxGetUrlLength configured to 2048 │ │ │ │ │ - * since SLD selections can easily get quite long. │ │ │ │ │ + * {DOMElement} A reference to the DIV DOMElement containing the │ │ │ │ │ + * switcher tabs. │ │ │ │ │ */ │ │ │ │ │ - createSelectionLayer: function(source) { │ │ │ │ │ - // check if we already have a selection layer for the source layer │ │ │ │ │ - var selectionLayer; │ │ │ │ │ - if (!this.layerCache[source.id]) { │ │ │ │ │ - selectionLayer = new OpenLayers.Layer.WMS(source.name, │ │ │ │ │ - source.url, source.params, │ │ │ │ │ - OpenLayers.Util.applyDefaults( │ │ │ │ │ - this.layerOptions, │ │ │ │ │ - source.getOptions()) │ │ │ │ │ - ); │ │ │ │ │ - this.layerCache[source.id] = selectionLayer; │ │ │ │ │ - // make sure the layers are coupled wrt visibility, but only │ │ │ │ │ - // if they are not displayed in the layer switcher, because in │ │ │ │ │ - // that case the user cannot control visibility. │ │ │ │ │ - if (this.layerOptions.displayInLayerSwitcher === false) { │ │ │ │ │ - source.events.on({ │ │ │ │ │ - "visibilitychanged": this.coupleLayerVisiblity, │ │ │ │ │ - scope: selectionLayer │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - this.map.addLayer(selectionLayer); │ │ │ │ │ - } else { │ │ │ │ │ - selectionLayer = this.layerCache[source.id]; │ │ │ │ │ + draw: function() { │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this); │ │ │ │ │ + │ │ │ │ │ + // create layout divs │ │ │ │ │ + this.loadContents(); │ │ │ │ │ + │ │ │ │ │ + // set mode to minimize │ │ │ │ │ + if (!this.outsideViewport) { │ │ │ │ │ + this.minimizeControl(); │ │ │ │ │ } │ │ │ │ │ - return selectionLayer; │ │ │ │ │ + │ │ │ │ │ + // populate div with current info │ │ │ │ │ + this.redraw(); │ │ │ │ │ + │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: createSLD │ │ │ │ │ - * Create the SLD document for the layer using the supplied filters. │ │ │ │ │ + * Method: onButtonClick │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layer - {} │ │ │ │ │ - * filters - Array({}) The filters to be applied. │ │ │ │ │ - * geometryAttributes - Array({Object}) The geometry attributes of the │ │ │ │ │ - * layer. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} The SLD document generated as a string. │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - createSLD: function(layer, filters, geometryAttributes) { │ │ │ │ │ - var sld = { │ │ │ │ │ - version: "1.0.0", │ │ │ │ │ - namedLayers: {} │ │ │ │ │ - }; │ │ │ │ │ - var layerNames = [layer.params.LAYERS].join(",").split(","); │ │ │ │ │ - for (var i = 0, len = layerNames.length; i < len; i++) { │ │ │ │ │ - var name = layerNames[i]; │ │ │ │ │ - sld.namedLayers[name] = { │ │ │ │ │ - name: name, │ │ │ │ │ - userStyles: [] │ │ │ │ │ - }; │ │ │ │ │ - var symbolizer = this.selectionSymbolizer; │ │ │ │ │ - var geometryAttribute = geometryAttributes[i]; │ │ │ │ │ - if (geometryAttribute.type.indexOf('Polygon') >= 0) { │ │ │ │ │ - symbolizer = { │ │ │ │ │ - Polygon: this.selectionSymbolizer['Polygon'] │ │ │ │ │ - }; │ │ │ │ │ - } else if (geometryAttribute.type.indexOf('LineString') >= 0) { │ │ │ │ │ - symbolizer = { │ │ │ │ │ - Line: this.selectionSymbolizer['Line'] │ │ │ │ │ - }; │ │ │ │ │ - } else if (geometryAttribute.type.indexOf('Point') >= 0) { │ │ │ │ │ - symbolizer = { │ │ │ │ │ - Point: this.selectionSymbolizer['Point'] │ │ │ │ │ - }; │ │ │ │ │ + onButtonClick: function(evt) { │ │ │ │ │ + var button = evt.buttonElement; │ │ │ │ │ + if (button === this.minimizeDiv) { │ │ │ │ │ + this.minimizeControl(); │ │ │ │ │ + } else if (button === this.maximizeDiv) { │ │ │ │ │ + this.maximizeControl(); │ │ │ │ │ + } else if (button._layerSwitcher === this.id) { │ │ │ │ │ + if (button["for"]) { │ │ │ │ │ + button = document.getElementById(button["for"]); │ │ │ │ │ + } │ │ │ │ │ + if (!button.disabled) { │ │ │ │ │ + if (button.type == "radio") { │ │ │ │ │ + button.checked = true; │ │ │ │ │ + this.map.setBaseLayer(this.map.getLayer(button._layer)); │ │ │ │ │ + } else { │ │ │ │ │ + button.checked = !button.checked; │ │ │ │ │ + this.updateMap(); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - var filter = filters[i]; │ │ │ │ │ - sld.namedLayers[name].userStyles.push({ │ │ │ │ │ - name: 'default', │ │ │ │ │ - rules: [ │ │ │ │ │ - new OpenLayers.Rule({ │ │ │ │ │ - symbolizer: symbolizer, │ │ │ │ │ - filter: filter, │ │ │ │ │ - maxScaleDenominator: layer.options.minScale │ │ │ │ │ - }) │ │ │ │ │ - ] │ │ │ │ │ - }); │ │ │ │ │ } │ │ │ │ │ - return new OpenLayers.Format.SLD({ │ │ │ │ │ - srsName: this.map.getProjection() │ │ │ │ │ - }).write(sld); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseDescribeLayer │ │ │ │ │ - * Parse the SLD WMS DescribeLayer response and issue the corresponding │ │ │ │ │ - * WFS DescribeFeatureType request │ │ │ │ │ + * Method: clearLayersArray │ │ │ │ │ + * User specifies either "base" or "data". we then clear all the │ │ │ │ │ + * corresponding listeners, the div, and reinitialize a new array. │ │ │ │ │ * │ │ │ │ │ - * request - {XMLHttpRequest} The request object. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layersType - {String} │ │ │ │ │ */ │ │ │ │ │ - parseDescribeLayer: function(request) { │ │ │ │ │ - var format = new OpenLayers.Format.WMSDescribeLayer(); │ │ │ │ │ - var doc = request.responseXML; │ │ │ │ │ - if (!doc || !doc.documentElement) { │ │ │ │ │ - doc = request.responseText; │ │ │ │ │ - } │ │ │ │ │ - var describeLayer = format.read(doc); │ │ │ │ │ - var typeNames = []; │ │ │ │ │ - var url = null; │ │ │ │ │ - for (var i = 0, len = describeLayer.length; i < len; i++) { │ │ │ │ │ - // perform a WFS DescribeFeatureType request │ │ │ │ │ - if (describeLayer[i].owsType == "WFS") { │ │ │ │ │ - typeNames.push(describeLayer[i].typeName); │ │ │ │ │ - url = describeLayer[i].owsURL; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - var options = { │ │ │ │ │ - url: url, │ │ │ │ │ - params: { │ │ │ │ │ - SERVICE: "WFS", │ │ │ │ │ - TYPENAME: typeNames.toString(), │ │ │ │ │ - REQUEST: "DescribeFeatureType", │ │ │ │ │ - VERSION: "1.0.0" │ │ │ │ │ - }, │ │ │ │ │ - callback: function(request) { │ │ │ │ │ - var format = new OpenLayers.Format.WFSDescribeFeatureType(); │ │ │ │ │ - var doc = request.responseXML; │ │ │ │ │ - if (!doc || !doc.documentElement) { │ │ │ │ │ - doc = request.responseText; │ │ │ │ │ - } │ │ │ │ │ - var describeFeatureType = format.read(doc); │ │ │ │ │ - this.control.wfsCache[this.layer.id] = describeFeatureType; │ │ │ │ │ - this.control._queue && this.control.applySelection(); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Request.GET(options); │ │ │ │ │ + clearLayersArray: function(layersType) { │ │ │ │ │ + this[layersType + "LayersDiv"].innerHTML = ""; │ │ │ │ │ + this[layersType + "Layers"] = []; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: getGeometryAttributes │ │ │ │ │ - * Look up the geometry attributes from the WFS DescribeFeatureType response │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} The layer for which to look up the │ │ │ │ │ - * geometry attributes. │ │ │ │ │ + * Method: checkRedraw │ │ │ │ │ + * Checks if the layer state has changed since the last redraw() call. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * Array({Object}) Array of geometry attributes │ │ │ │ │ + * {Boolean} The layer state changed since the last redraw() call. │ │ │ │ │ */ │ │ │ │ │ - getGeometryAttributes: function(layer) { │ │ │ │ │ - var result = []; │ │ │ │ │ - var cache = this.wfsCache[layer.id]; │ │ │ │ │ - for (var i = 0, len = cache.featureTypes.length; i < len; i++) { │ │ │ │ │ - var typeName = cache.featureTypes[i]; │ │ │ │ │ - var properties = typeName.properties; │ │ │ │ │ - for (var j = 0, lenj = properties.length; j < lenj; j++) { │ │ │ │ │ - var property = properties[j]; │ │ │ │ │ - var type = property.type; │ │ │ │ │ - if ((type.indexOf('LineString') >= 0) || │ │ │ │ │ - (type.indexOf('GeometryAssociationType') >= 0) || │ │ │ │ │ - (type.indexOf('GeometryPropertyType') >= 0) || │ │ │ │ │ - (type.indexOf('Point') >= 0) || │ │ │ │ │ - (type.indexOf('Polygon') >= 0)) { │ │ │ │ │ - result.push(property); │ │ │ │ │ - } │ │ │ │ │ + checkRedraw: function() { │ │ │ │ │ + if (!this.layerStates.length || │ │ │ │ │ + (this.map.layers.length != this.layerStates.length)) { │ │ │ │ │ + return true; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + for (var i = 0, len = this.layerStates.length; i < len; i++) { │ │ │ │ │ + var layerState = this.layerStates[i]; │ │ │ │ │ + var layer = this.map.layers[i]; │ │ │ │ │ + if ((layerState.name != layer.name) || │ │ │ │ │ + (layerState.inRange != layer.inRange) || │ │ │ │ │ + (layerState.id != layer.id) || │ │ │ │ │ + (layerState.visibility != layer.visibility)) { │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return result; │ │ │ │ │ + │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the control. Activating the control will perform a SLD WMS │ │ │ │ │ - * DescribeLayer request followed by a WFS DescribeFeatureType request │ │ │ │ │ - * so that the proper symbolizers can be chosen based on the geometry │ │ │ │ │ - * type. │ │ │ │ │ + * Method: redraw │ │ │ │ │ + * Goes through and takes the current state of the Map and rebuilds the │ │ │ │ │ + * control to display that state. Groups base layers into a │ │ │ │ │ + * radio-button group and lists each data layer with a checkbox. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} A reference to the DIV DOMElement containing the control │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = OpenLayers.Control.prototype.activate.call(this); │ │ │ │ │ - if (activated) { │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - var layer = this.layers[i]; │ │ │ │ │ - if (layer && !this.wfsCache[layer.id]) { │ │ │ │ │ - var options = { │ │ │ │ │ - url: layer.url, │ │ │ │ │ - params: { │ │ │ │ │ - SERVICE: "WMS", │ │ │ │ │ - VERSION: layer.params.VERSION, │ │ │ │ │ - LAYERS: layer.params.LAYERS, │ │ │ │ │ - REQUEST: "DescribeLayer" │ │ │ │ │ - }, │ │ │ │ │ - callback: this.parseDescribeLayer, │ │ │ │ │ - scope: { │ │ │ │ │ - layer: layer, │ │ │ │ │ - control: this │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Request.GET(options); │ │ │ │ │ + redraw: function() { │ │ │ │ │ + //if the state hasn't changed since last redraw, no need │ │ │ │ │ + // to do anything. Just return the existing div. │ │ │ │ │ + if (!this.checkRedraw()) { │ │ │ │ │ + return this.div; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + //clear out previous layers │ │ │ │ │ + this.clearLayersArray("base"); │ │ │ │ │ + this.clearLayersArray("data"); │ │ │ │ │ + │ │ │ │ │ + var containsOverlays = false; │ │ │ │ │ + var containsBaseLayers = false; │ │ │ │ │ + │ │ │ │ │ + // Save state -- for checking layer if the map state changed. │ │ │ │ │ + // We save this before redrawing, because in the process of redrawing │ │ │ │ │ + // we will trigger more visibility changes, and we want to not redraw │ │ │ │ │ + // and enter an infinite loop. │ │ │ │ │ + var len = this.map.layers.length; │ │ │ │ │ + this.layerStates = new Array(len); │ │ │ │ │ + for (var i = 0; i < len; i++) { │ │ │ │ │ + var layer = this.map.layers[i]; │ │ │ │ │ + this.layerStates[i] = { │ │ │ │ │ + 'name': layer.name, │ │ │ │ │ + 'visibility': layer.visibility, │ │ │ │ │ + 'inRange': layer.inRange, │ │ │ │ │ + 'id': layer.id │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var layers = this.map.layers.slice(); │ │ │ │ │ + if (!this.ascending) { │ │ │ │ │ + layers.reverse(); │ │ │ │ │ + } │ │ │ │ │ + for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ + var layer = layers[i]; │ │ │ │ │ + var baseLayer = layer.isBaseLayer; │ │ │ │ │ + │ │ │ │ │ + if (layer.displayInLayerSwitcher) { │ │ │ │ │ + │ │ │ │ │ + if (baseLayer) { │ │ │ │ │ + containsBaseLayers = true; │ │ │ │ │ + } else { │ │ │ │ │ + containsOverlays = true; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // only check a baselayer if it is *the* baselayer, check data │ │ │ │ │ + // layers if they are visible │ │ │ │ │ + var checked = (baseLayer) ? (layer == this.map.baseLayer) : │ │ │ │ │ + layer.getVisibility(); │ │ │ │ │ + │ │ │ │ │ + // create input element │ │ │ │ │ + var inputElem = document.createElement("input"), │ │ │ │ │ + // The input shall have an id attribute so we can use │ │ │ │ │ + // labels to interact with them. │ │ │ │ │ + inputId = OpenLayers.Util.createUniqueID( │ │ │ │ │ + this.id + "_input_" │ │ │ │ │ + ); │ │ │ │ │ + │ │ │ │ │ + inputElem.id = inputId; │ │ │ │ │ + inputElem.name = (baseLayer) ? this.id + "_baseLayers" : layer.name; │ │ │ │ │ + inputElem.type = (baseLayer) ? "radio" : "checkbox"; │ │ │ │ │ + inputElem.value = layer.name; │ │ │ │ │ + inputElem.checked = checked; │ │ │ │ │ + inputElem.defaultChecked = checked; │ │ │ │ │ + inputElem.className = "olButton"; │ │ │ │ │ + inputElem._layer = layer.id; │ │ │ │ │ + inputElem._layerSwitcher = this.id; │ │ │ │ │ + │ │ │ │ │ + if (!baseLayer && !layer.inRange) { │ │ │ │ │ + inputElem.disabled = true; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // create span │ │ │ │ │ + var labelSpan = document.createElement("label"); │ │ │ │ │ + // this isn't the DOM attribute 'for', but an arbitrary name we │ │ │ │ │ + // use to find the appropriate input element in │ │ │ │ │ + labelSpan["for"] = inputElem.id; │ │ │ │ │ + OpenLayers.Element.addClass(labelSpan, "labelSpan olButton"); │ │ │ │ │ + labelSpan._layer = layer.id; │ │ │ │ │ + labelSpan._layerSwitcher = this.id; │ │ │ │ │ + if (!baseLayer && !layer.inRange) { │ │ │ │ │ + labelSpan.style.color = "gray"; │ │ │ │ │ } │ │ │ │ │ + labelSpan.innerHTML = layer.name; │ │ │ │ │ + labelSpan.style.verticalAlign = (baseLayer) ? "bottom" : │ │ │ │ │ + "baseline"; │ │ │ │ │ + // create line break │ │ │ │ │ + var br = document.createElement("br"); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + var groupArray = (baseLayer) ? this.baseLayers : │ │ │ │ │ + this.dataLayers; │ │ │ │ │ + groupArray.push({ │ │ │ │ │ + 'layer': layer, │ │ │ │ │ + 'inputElem': inputElem, │ │ │ │ │ + 'labelSpan': labelSpan │ │ │ │ │ + }); │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ + var groupDiv = (baseLayer) ? this.baseLayersDiv : │ │ │ │ │ + this.dataLayersDiv; │ │ │ │ │ + groupDiv.appendChild(inputElem); │ │ │ │ │ + groupDiv.appendChild(labelSpan); │ │ │ │ │ + groupDiv.appendChild(br); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return activated; │ │ │ │ │ + │ │ │ │ │ + // if no overlays, dont display the overlay label │ │ │ │ │ + this.dataLbl.style.display = (containsOverlays) ? "" : "none"; │ │ │ │ │ + │ │ │ │ │ + // if no baselayers, dont display the baselayer label │ │ │ │ │ + this.baseLbl.style.display = (containsBaseLayers) ? "" : "none"; │ │ │ │ │ + │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the control. If clearOnDeactivate is true, remove the │ │ │ │ │ - * selection layer(s). │ │ │ │ │ + * Method: updateMap │ │ │ │ │ + * Cycles through the loaded data and base layer input arrays and makes │ │ │ │ │ + * the necessary calls to the Map object such that that the map's │ │ │ │ │ + * visual state corresponds to what the user has selected in │ │ │ │ │ + * the control. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = OpenLayers.Control.prototype.deactivate.call(this); │ │ │ │ │ - if (deactivated) { │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - var layer = this.layers[i]; │ │ │ │ │ - if (layer && this.clearOnDeactivate === true) { │ │ │ │ │ - var layerCache = this.layerCache; │ │ │ │ │ - var selectionLayer = layerCache[layer.id]; │ │ │ │ │ - if (selectionLayer) { │ │ │ │ │ - layer.events.un({ │ │ │ │ │ - "visibilitychanged": this.coupleLayerVisiblity, │ │ │ │ │ - scope: selectionLayer │ │ │ │ │ - }); │ │ │ │ │ - selectionLayer.destroy(); │ │ │ │ │ - delete layerCache[layer.id]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + updateMap: function() { │ │ │ │ │ + │ │ │ │ │ + // set the newly selected base layer │ │ │ │ │ + for (var i = 0, len = this.baseLayers.length; i < len; i++) { │ │ │ │ │ + var layerEntry = this.baseLayers[i]; │ │ │ │ │ + if (layerEntry.inputElem.checked) { │ │ │ │ │ + this.map.setBaseLayer(layerEntry.layer, false); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + │ │ │ │ │ + // set the correct visibilities for the overlays │ │ │ │ │ + for (var i = 0, len = this.dataLayers.length; i < len; i++) { │ │ │ │ │ + var layerEntry = this.dataLayers[i]; │ │ │ │ │ + layerEntry.layer.setVisibility(layerEntry.inputElem.checked); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setLayers │ │ │ │ │ - * Set the layers on which the selection should be performed. Call the │ │ │ │ │ - * setLayers method if the layer(s) to be used change and the same │ │ │ │ │ - * control should be used on a new set of layers. │ │ │ │ │ - * If the control is already active, it will be active after the new │ │ │ │ │ - * set of layers is set. │ │ │ │ │ + * Method: maximizeControl │ │ │ │ │ + * Set up the labels and divs for the control │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * layers - {Array()} The new set of layers on which │ │ │ │ │ - * the selection should be performed. │ │ │ │ │ + * e - {Event} │ │ │ │ │ */ │ │ │ │ │ - setLayers: function(layers) { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - this.layers = layers; │ │ │ │ │ - this.activate(); │ │ │ │ │ - } else { │ │ │ │ │ - this.layers = layers; │ │ │ │ │ + maximizeControl: function(e) { │ │ │ │ │ + │ │ │ │ │ + // set the div's width and height to empty values, so │ │ │ │ │ + // the div dimensions can be controlled by CSS │ │ │ │ │ + this.div.style.width = ""; │ │ │ │ │ + this.div.style.height = ""; │ │ │ │ │ + │ │ │ │ │ + this.showControls(false); │ │ │ │ │ + │ │ │ │ │ + if (e != null) { │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Function: createFilter │ │ │ │ │ - * Create the filter to be used in the SLD. │ │ │ │ │ + * Method: minimizeControl │ │ │ │ │ + * Hide all the contents of the control, shrink the size, │ │ │ │ │ + * add the maximize icon │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometryAttribute - {Object} Used to get the name of the geometry │ │ │ │ │ - * attribute which is needed for constructing the spatial filter. │ │ │ │ │ - * geometry - {} The geometry to use. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} The spatial filter created. │ │ │ │ │ + * e - {Event} │ │ │ │ │ */ │ │ │ │ │ - createFilter: function(geometryAttribute, geometry) { │ │ │ │ │ - var filter = null; │ │ │ │ │ - if (this.handler instanceof OpenLayers.Handler.RegularPolygon) { │ │ │ │ │ - // box │ │ │ │ │ - if (this.handler.irregular === true) { │ │ │ │ │ - filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: OpenLayers.Filter.Spatial.BBOX, │ │ │ │ │ - property: geometryAttribute.name, │ │ │ │ │ - value: geometry.getBounds() │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: OpenLayers.Filter.Spatial.INTERSECTS, │ │ │ │ │ - property: geometryAttribute.name, │ │ │ │ │ - value: geometry │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } else if (this.handler instanceof OpenLayers.Handler.Polygon) { │ │ │ │ │ - filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: OpenLayers.Filter.Spatial.INTERSECTS, │ │ │ │ │ - property: geometryAttribute.name, │ │ │ │ │ - value: geometry │ │ │ │ │ - }); │ │ │ │ │ - } else if (this.handler instanceof OpenLayers.Handler.Path) { │ │ │ │ │ - // if source layer is point based, use DWITHIN instead │ │ │ │ │ - if (geometryAttribute.type.indexOf('Point') >= 0) { │ │ │ │ │ - filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: OpenLayers.Filter.Spatial.DWITHIN, │ │ │ │ │ - property: geometryAttribute.name, │ │ │ │ │ - distance: this.map.getExtent().getWidth() * 0.01, │ │ │ │ │ - distanceUnits: this.map.getUnits(), │ │ │ │ │ - value: geometry │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: OpenLayers.Filter.Spatial.INTERSECTS, │ │ │ │ │ - property: geometryAttribute.name, │ │ │ │ │ - value: geometry │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } else if (this.handler instanceof OpenLayers.Handler.Click) { │ │ │ │ │ - if (geometryAttribute.type.indexOf('Polygon') >= 0) { │ │ │ │ │ - filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: OpenLayers.Filter.Spatial.INTERSECTS, │ │ │ │ │ - property: geometryAttribute.name, │ │ │ │ │ - value: geometry │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: OpenLayers.Filter.Spatial.DWITHIN, │ │ │ │ │ - property: geometryAttribute.name, │ │ │ │ │ - distance: this.map.getExtent().getWidth() * 0.01, │ │ │ │ │ - distanceUnits: this.map.getUnits(), │ │ │ │ │ - value: geometry │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + minimizeControl: function(e) { │ │ │ │ │ + │ │ │ │ │ + // to minimize the control we set its div's width │ │ │ │ │ + // and height to 0px, we cannot just set "display" │ │ │ │ │ + // to "none" because it would hide the maximize │ │ │ │ │ + // div │ │ │ │ │ + this.div.style.width = "0px"; │ │ │ │ │ + this.div.style.height = "0px"; │ │ │ │ │ + │ │ │ │ │ + this.showControls(true); │ │ │ │ │ + │ │ │ │ │ + if (e != null) { │ │ │ │ │ + OpenLayers.Event.stop(e); │ │ │ │ │ } │ │ │ │ │ - return filter; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: select │ │ │ │ │ - * When the handler is done, use SLD_BODY on the selection layer to │ │ │ │ │ - * display the selection in the map. │ │ │ │ │ + * Method: showControls │ │ │ │ │ + * Hide/Show all LayerSwitcher controls depending on whether we are │ │ │ │ │ + * minimized or not │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {Object} or {} │ │ │ │ │ + * minimize - {Boolean} │ │ │ │ │ */ │ │ │ │ │ - select: function(geometry) { │ │ │ │ │ - this._queue = function() { │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - var layer = this.layers[i]; │ │ │ │ │ - var geometryAttributes = this.getGeometryAttributes(layer); │ │ │ │ │ - var filters = []; │ │ │ │ │ - for (var j = 0, lenj = geometryAttributes.length; j < lenj; j++) { │ │ │ │ │ - var geometryAttribute = geometryAttributes[j]; │ │ │ │ │ - if (geometryAttribute !== null) { │ │ │ │ │ - // from the click handler we will not get an actual │ │ │ │ │ - // geometry so transform │ │ │ │ │ - if (!(geometry instanceof OpenLayers.Geometry)) { │ │ │ │ │ - var point = this.map.getLonLatFromPixel( │ │ │ │ │ - geometry.xy); │ │ │ │ │ - geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ - point.lon, point.lat); │ │ │ │ │ - } │ │ │ │ │ - var filter = this.createFilter(geometryAttribute, │ │ │ │ │ - geometry); │ │ │ │ │ - if (filter !== null) { │ │ │ │ │ - filters.push(filter); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var selectionLayer = this.createSelectionLayer(layer); │ │ │ │ │ - │ │ │ │ │ - this.events.triggerEvent("selected", { │ │ │ │ │ - layer: layer, │ │ │ │ │ - filters: filters │ │ │ │ │ - }); │ │ │ │ │ + showControls: function(minimize) { │ │ │ │ │ │ │ │ │ │ - var sld = this.createSLD(layer, filters, geometryAttributes); │ │ │ │ │ + this.maximizeDiv.style.display = minimize ? "" : "none"; │ │ │ │ │ + this.minimizeDiv.style.display = minimize ? "none" : ""; │ │ │ │ │ │ │ │ │ │ - selectionLayer.mergeNewParams({ │ │ │ │ │ - SLD_BODY: sld │ │ │ │ │ - }); │ │ │ │ │ - delete this._queue; │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - this.applySelection(); │ │ │ │ │ + this.layersDiv.style.display = minimize ? "none" : ""; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: applySelection │ │ │ │ │ - * Checks if all required wfs data is cached, and applies the selection │ │ │ │ │ + * Method: loadContents │ │ │ │ │ + * Set up the labels and divs for the control │ │ │ │ │ */ │ │ │ │ │ - applySelection: function() { │ │ │ │ │ - var canApply = true; │ │ │ │ │ - for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ - if (!this.wfsCache[this.layers[i].id]) { │ │ │ │ │ - canApply = false; │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + loadContents: function() { │ │ │ │ │ + │ │ │ │ │ + // layers list div │ │ │ │ │ + this.layersDiv = document.createElement("div"); │ │ │ │ │ + this.layersDiv.id = this.id + "_layersDiv"; │ │ │ │ │ + OpenLayers.Element.addClass(this.layersDiv, "layersDiv"); │ │ │ │ │ + │ │ │ │ │ + this.baseLbl = document.createElement("div"); │ │ │ │ │ + this.baseLbl.innerHTML = OpenLayers.i18n("Base Layer"); │ │ │ │ │ + OpenLayers.Element.addClass(this.baseLbl, "baseLbl"); │ │ │ │ │ + │ │ │ │ │ + this.baseLayersDiv = document.createElement("div"); │ │ │ │ │ + OpenLayers.Element.addClass(this.baseLayersDiv, "baseLayersDiv"); │ │ │ │ │ + │ │ │ │ │ + this.dataLbl = document.createElement("div"); │ │ │ │ │ + this.dataLbl.innerHTML = OpenLayers.i18n("Overlays"); │ │ │ │ │ + OpenLayers.Element.addClass(this.dataLbl, "dataLbl"); │ │ │ │ │ + │ │ │ │ │ + this.dataLayersDiv = document.createElement("div"); │ │ │ │ │ + OpenLayers.Element.addClass(this.dataLayersDiv, "dataLayersDiv"); │ │ │ │ │ + │ │ │ │ │ + if (this.ascending) { │ │ │ │ │ + this.layersDiv.appendChild(this.baseLbl); │ │ │ │ │ + this.layersDiv.appendChild(this.baseLayersDiv); │ │ │ │ │ + this.layersDiv.appendChild(this.dataLbl); │ │ │ │ │ + this.layersDiv.appendChild(this.dataLayersDiv); │ │ │ │ │ + } else { │ │ │ │ │ + this.layersDiv.appendChild(this.dataLbl); │ │ │ │ │ + this.layersDiv.appendChild(this.dataLayersDiv); │ │ │ │ │ + this.layersDiv.appendChild(this.baseLbl); │ │ │ │ │ + this.layersDiv.appendChild(this.baseLayersDiv); │ │ │ │ │ } │ │ │ │ │ - canApply && this._queue.call(this); │ │ │ │ │ + │ │ │ │ │ + this.div.appendChild(this.layersDiv); │ │ │ │ │ + │ │ │ │ │ + // maximize button div │ │ │ │ │ + var img = OpenLayers.Util.getImageLocation('layer-switcher-maximize.png'); │ │ │ │ │ + this.maximizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ + "OpenLayers_Control_MaximizeDiv", │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + img, │ │ │ │ │ + "absolute"); │ │ │ │ │ + OpenLayers.Element.addClass(this.maximizeDiv, "maximizeDiv olButton"); │ │ │ │ │ + this.maximizeDiv.style.display = "none"; │ │ │ │ │ + │ │ │ │ │ + this.div.appendChild(this.maximizeDiv); │ │ │ │ │ + │ │ │ │ │ + // minimize button div │ │ │ │ │ + var img = OpenLayers.Util.getImageLocation('layer-switcher-minimize.png'); │ │ │ │ │ + this.minimizeDiv = OpenLayers.Util.createAlphaImageDiv( │ │ │ │ │ + "OpenLayers_Control_MinimizeDiv", │ │ │ │ │ + null, │ │ │ │ │ + null, │ │ │ │ │ + img, │ │ │ │ │ + "absolute"); │ │ │ │ │ + OpenLayers.Element.addClass(this.minimizeDiv, "minimizeDiv olButton"); │ │ │ │ │ + this.minimizeDiv.style.display = "none"; │ │ │ │ │ + │ │ │ │ │ + this.div.appendChild(this.minimizeDiv); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.SLDSelect" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.LayerSwitcher" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ OpenLayers/Control/ArgParser.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ @@ -49484,418 +42750,14 @@ │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Control.ArgParser" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Handler/Pinch.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Handler.Pinch │ │ │ │ │ - * The pinch handler is used to deal with sequences of browser events related │ │ │ │ │ - * to pinch gestures. The handler is used by controls that want to know │ │ │ │ │ - * when a pinch sequence begins, when a pinch is happening, and when it has │ │ │ │ │ - * finished. │ │ │ │ │ - * │ │ │ │ │ - * Controls that use the pinch handler typically construct it with callbacks │ │ │ │ │ - * for 'start', 'move', and 'done'. Callbacks for these keys are │ │ │ │ │ - * called when the pinch begins, with each change, and when the pinch is │ │ │ │ │ - * done. │ │ │ │ │ - * │ │ │ │ │ - * Create a new pinch handler with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Handler.Pinch = OpenLayers.Class(OpenLayers.Handler, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: started │ │ │ │ │ - * {Boolean} When a touchstart event is received, we want to record it, │ │ │ │ │ - * but not set 'pinching' until the touchmove get started after │ │ │ │ │ - * starting. │ │ │ │ │ - */ │ │ │ │ │ - started: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: stopDown │ │ │ │ │ - * {Boolean} Stop propagation of touchstart events from getting to │ │ │ │ │ - * listeners on the same element. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - stopDown: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: pinching │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - pinching: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: last │ │ │ │ │ - * {Object} Object that store informations related to pinch last touch. │ │ │ │ │ - */ │ │ │ │ │ - last: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: start │ │ │ │ │ - * {Object} Object that store informations related to pinch touchstart. │ │ │ │ │ - */ │ │ │ │ │ - start: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Handler.Pinch │ │ │ │ │ - * Returns OpenLayers.Handler.Pinch │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * control - {} The control that is making use of │ │ │ │ │ - * this handler. If a handler is being used without a control, the │ │ │ │ │ - * handlers setMap method must be overridden to deal properly with │ │ │ │ │ - * the map. │ │ │ │ │ - * callbacks - {Object} An object containing functions to be called when │ │ │ │ │ - * the pinch operation start, change, or is finished. The callbacks │ │ │ │ │ - * should expect to receive an object argument, which contains │ │ │ │ │ - * information about scale, distance, and position of touch points. │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchstart │ │ │ │ │ - * Handle touchstart events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - touchstart: function(evt) { │ │ │ │ │ - var propagate = true; │ │ │ │ │ - this.pinching = false; │ │ │ │ │ - if (OpenLayers.Event.isMultiTouch(evt)) { │ │ │ │ │ - this.started = true; │ │ │ │ │ - this.last = this.start = { │ │ │ │ │ - distance: this.getDistance(evt.touches), │ │ │ │ │ - delta: 0, │ │ │ │ │ - scale: 1 │ │ │ │ │ - }; │ │ │ │ │ - this.callback("start", [evt, this.start]); │ │ │ │ │ - propagate = !this.stopDown; │ │ │ │ │ - } else if (this.started) { │ │ │ │ │ - // Some webkit versions send fake single-touch events during │ │ │ │ │ - // multitouch, which cause the drag handler to trigger │ │ │ │ │ - return false; │ │ │ │ │ - } else { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ - } │ │ │ │ │ - // prevent document dragging │ │ │ │ │ - OpenLayers.Event.preventDefault(evt); │ │ │ │ │ - return propagate; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchmove │ │ │ │ │ - * Handle touchmove events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - touchmove: function(evt) { │ │ │ │ │ - if (this.started && OpenLayers.Event.isMultiTouch(evt)) { │ │ │ │ │ - this.pinching = true; │ │ │ │ │ - var current = this.getPinchData(evt); │ │ │ │ │ - this.callback("move", [evt, current]); │ │ │ │ │ - this.last = current; │ │ │ │ │ - // prevent document dragging │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - } else if (this.started) { │ │ │ │ │ - // Some webkit versions send fake single-touch events during │ │ │ │ │ - // multitouch, which cause the drag handler to trigger │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: touchend │ │ │ │ │ - * Handle touchend events │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Let the event propagate. │ │ │ │ │ - */ │ │ │ │ │ - touchend: function(evt) { │ │ │ │ │ - if (this.started && !OpenLayers.Event.isMultiTouch(evt)) { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.pinching = false; │ │ │ │ │ - this.callback("done", [evt, this.start, this.last]); │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully activated. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.pinching = false; │ │ │ │ │ - activated = true; │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivate the handler. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The handler was successfully deactivated. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.started = false; │ │ │ │ │ - this.pinching = false; │ │ │ │ │ - this.start = null; │ │ │ │ │ - this.last = null; │ │ │ │ │ - deactivated = true; │ │ │ │ │ - } │ │ │ │ │ - return deactivated; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getDistance │ │ │ │ │ - * Get the distance in pixels between two touches. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * touches - {Array(Object)} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Number} The distance in pixels. │ │ │ │ │ - */ │ │ │ │ │ - getDistance: function(touches) { │ │ │ │ │ - var t0 = touches[0]; │ │ │ │ │ - var t1 = touches[1]; │ │ │ │ │ - return Math.sqrt( │ │ │ │ │ - Math.pow(t0.olClientX - t1.olClientX, 2) + │ │ │ │ │ - Math.pow(t0.olClientY - t1.olClientY, 2) │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getPinchData │ │ │ │ │ - * Get informations about the pinch event. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Object that contains data about the current pinch. │ │ │ │ │ - */ │ │ │ │ │ - getPinchData: function(evt) { │ │ │ │ │ - var distance = this.getDistance(evt.touches); │ │ │ │ │ - var scale = distance / this.start.distance; │ │ │ │ │ - return { │ │ │ │ │ - distance: distance, │ │ │ │ │ - delta: this.last.distance - distance, │ │ │ │ │ - scale: scale │ │ │ │ │ - }; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Handler.Pinch" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/PinchZoom.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Handler/Pinch.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.PinchZoom │ │ │ │ │ - * │ │ │ │ │ - * Inherits: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.PinchZoom = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: type │ │ │ │ │ - * {OpenLayers.Control.TYPES} │ │ │ │ │ - */ │ │ │ │ │ - type: OpenLayers.Control.TYPE_TOOL, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: pinchOrigin │ │ │ │ │ - * {Object} Cached object representing the pinch start (in pixels). │ │ │ │ │ - */ │ │ │ │ │ - pinchOrigin: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: currentCenter │ │ │ │ │ - * {Object} Cached object representing the latest pinch center (in pixels). │ │ │ │ │ - */ │ │ │ │ │ - currentCenter: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: preserveCenter │ │ │ │ │ - * {Boolean} Set this to true if you don't want the map center to change │ │ │ │ │ - * while pinching. For example you may want to set preserveCenter to │ │ │ │ │ - * true when the user location is being watched and you want to preserve │ │ │ │ │ - * the user location at the center of the map even if he zooms in or │ │ │ │ │ - * out using pinch. This property's value can be changed any time on an │ │ │ │ │ - * existing instance. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - preserveCenter: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the pinch handler │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.PinchZoom │ │ │ │ │ - * Create a control for zooming with pinch gestures. This works on devices │ │ │ │ │ - * with multi-touch support. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * the control │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ - this.handler = new OpenLayers.Handler.Pinch(this, { │ │ │ │ │ - start: this.pinchStart, │ │ │ │ │ - move: this.pinchMove, │ │ │ │ │ - done: this.pinchDone │ │ │ │ │ - }, this.handlerOptions); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: pinchStart │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * pinchData - {Object} pinch data object related to the current touchmove │ │ │ │ │ - * of the pinch gesture. This give us the current scale of the pinch. │ │ │ │ │ - */ │ │ │ │ │ - pinchStart: function(evt, pinchData) { │ │ │ │ │ - var xy = (this.preserveCenter) ? │ │ │ │ │ - this.map.getPixelFromLonLat(this.map.getCenter()) : evt.xy; │ │ │ │ │ - this.pinchOrigin = xy; │ │ │ │ │ - this.currentCenter = xy; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: pinchMove │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * pinchData - {Object} pinch data object related to the current touchmove │ │ │ │ │ - * of the pinch gesture. This give us the current scale of the pinch. │ │ │ │ │ - */ │ │ │ │ │ - pinchMove: function(evt, pinchData) { │ │ │ │ │ - var scale = pinchData.scale; │ │ │ │ │ - var containerOrigin = this.map.layerContainerOriginPx; │ │ │ │ │ - var pinchOrigin = this.pinchOrigin; │ │ │ │ │ - var current = (this.preserveCenter) ? │ │ │ │ │ - this.map.getPixelFromLonLat(this.map.getCenter()) : evt.xy; │ │ │ │ │ - │ │ │ │ │ - var dx = Math.round((containerOrigin.x + current.x - pinchOrigin.x) + (scale - 1) * (containerOrigin.x - pinchOrigin.x)); │ │ │ │ │ - var dy = Math.round((containerOrigin.y + current.y - pinchOrigin.y) + (scale - 1) * (containerOrigin.y - pinchOrigin.y)); │ │ │ │ │ - │ │ │ │ │ - this.map.applyTransform(dx, dy, scale); │ │ │ │ │ - this.currentCenter = current; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: pinchDone │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - * start - {Object} pinch data object related to the touchstart event that │ │ │ │ │ - * started the pinch gesture. │ │ │ │ │ - * last - {Object} pinch data object related to the last touchmove event │ │ │ │ │ - * of the pinch gesture. This give us the final scale of the pinch. │ │ │ │ │ - */ │ │ │ │ │ - pinchDone: function(evt, start, last) { │ │ │ │ │ - this.map.applyTransform(); │ │ │ │ │ - var zoom = this.map.getZoomForResolution(this.map.getResolution() / last.scale, true); │ │ │ │ │ - if (zoom !== this.map.getZoom() || !this.currentCenter.equals(this.pinchOrigin)) { │ │ │ │ │ - var resolution = this.map.getResolutionForZoom(zoom); │ │ │ │ │ - │ │ │ │ │ - var location = this.map.getLonLatFromPixel(this.pinchOrigin); │ │ │ │ │ - var zoomPixel = this.currentCenter; │ │ │ │ │ - var size = this.map.getSize(); │ │ │ │ │ - │ │ │ │ │ - location.lon += resolution * ((size.w / 2) - zoomPixel.x); │ │ │ │ │ - location.lat -= resolution * ((size.h / 2) - zoomPixel.y); │ │ │ │ │ - │ │ │ │ │ - // Force a reflow before calling setCenter. This is to work │ │ │ │ │ - // around an issue occuring in iOS. │ │ │ │ │ - // │ │ │ │ │ - // See https://github.com/openlayers/openlayers/pull/351. │ │ │ │ │ - // │ │ │ │ │ - // Without a reflow setting the layer container div's top left │ │ │ │ │ - // style properties to "0px" - as done in Map.moveTo when zoom │ │ │ │ │ - // is changed - won't actually correctly reposition the layer │ │ │ │ │ - // container div. │ │ │ │ │ - // │ │ │ │ │ - // Also, we need to use a statement that the Google Closure │ │ │ │ │ - // compiler won't optimize away. │ │ │ │ │ - this.map.div.clientWidth = this.map.div.clientWidth; │ │ │ │ │ - │ │ │ │ │ - this.map.setCenter(location, zoom); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.PinchZoom" │ │ │ │ │ - │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ OpenLayers/Control/Permalink.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ @@ -50150,1073 +43012,2374 @@ │ │ │ │ │ │ │ │ │ │ return params; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Control.Permalink" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/CacheWrite.js │ │ │ │ │ + OpenLayers/Control/ModifyFeature.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ - * @requires OpenLayers/Console.js │ │ │ │ │ + * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ + * @requires OpenLayers/Handler/Keyboard.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.CacheWrite │ │ │ │ │ - * A control for caching image tiles in the browser's local storage. The │ │ │ │ │ - * control is used to fetch and use the cached │ │ │ │ │ - * tile images. │ │ │ │ │ - * │ │ │ │ │ - * Note: Before using this control on any layer that is not your own, make sure │ │ │ │ │ - * that the terms of service of the tile provider allow local storage of tiles. │ │ │ │ │ + * Class: OpenLayers.Control.ModifyFeature │ │ │ │ │ + * Control to modify features. When activated, a click renders the vertices │ │ │ │ │ + * of a feature - these vertices can then be dragged. By default, the │ │ │ │ │ + * delete key will delete the vertex under the mouse. New features are │ │ │ │ │ + * added by dragging "virtual vertices" between vertices. Create a new │ │ │ │ │ + * control with the constructor. │ │ │ │ │ * │ │ │ │ │ - * Inherits from: │ │ │ │ │ + * Inherits From: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.CacheWrite = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * To register events in the constructor, configure . │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * cachefull - Triggered when the cache is full. Listeners receive an │ │ │ │ │ - * object with a tile property as first argument. The tile references │ │ │ │ │ - * the tile that couldn't be cached. │ │ │ │ │ - */ │ │ │ │ │ +OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: eventListeners │ │ │ │ │ - * {Object} Object with event listeners, keyed by event name. An optional │ │ │ │ │ - * scope property defines the scope that listeners will be executed in. │ │ │ │ │ + * APIProperty: documentDrag │ │ │ │ │ + * {Boolean} If set to true, dragging vertices will continue even if the │ │ │ │ │ + * mouse cursor leaves the map viewport. Default is false. │ │ │ │ │ */ │ │ │ │ │ + documentDrag: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * {Array()}. Optional. If provided, caching │ │ │ │ │ - * will be enabled for these layers only, otherwise for all cacheable │ │ │ │ │ - * layers. │ │ │ │ │ + * APIProperty: geometryTypes │ │ │ │ │ + * {Array(String)} To restrict modification to a limited set of geometry │ │ │ │ │ + * types, send a list of strings corresponding to the geometry class │ │ │ │ │ + * names. │ │ │ │ │ */ │ │ │ │ │ - layers: null, │ │ │ │ │ + geometryTypes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: imageFormat │ │ │ │ │ - * {String} The image format used for caching. The default is "image/png". │ │ │ │ │ - * Supported formats depend on the user agent. If an unsupported │ │ │ │ │ - * is provided, "image/png" will be used. For aerial │ │ │ │ │ - * imagery, "image/jpeg" is recommended. │ │ │ │ │ + * APIProperty: clickout │ │ │ │ │ + * {Boolean} Unselect features when clicking outside any feature. │ │ │ │ │ + * Default is true. │ │ │ │ │ */ │ │ │ │ │ - imageFormat: "image/png", │ │ │ │ │ + clickout: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: quotaRegEx │ │ │ │ │ - * {RegExp} │ │ │ │ │ + * APIProperty: toggle │ │ │ │ │ + * {Boolean} Unselect a selected feature on click. │ │ │ │ │ + * Default is true. │ │ │ │ │ */ │ │ │ │ │ - quotaRegEx: (/quota/i), │ │ │ │ │ + toggle: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.CacheWrite │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Object with API properties for this control. │ │ │ │ │ + * APIProperty: standalone │ │ │ │ │ + * {Boolean} Set to true to create a control without SelectFeature │ │ │ │ │ + * capabilities. Default is false. If standalone is true, to modify │ │ │ │ │ + * a feature, call the method with the target feature. │ │ │ │ │ + * Note that you must call the method to finish │ │ │ │ │ + * feature modification in standalone mode (before starting to modify │ │ │ │ │ + * another feature). │ │ │ │ │ */ │ │ │ │ │ + standalone: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + /** │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - var i, layers = this.layers || map.layers; │ │ │ │ │ - for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ - this.addLayer({ │ │ │ │ │ - layer: layers[i] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - if (!this.layers) { │ │ │ │ │ - map.events.on({ │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - removeLayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addLayer │ │ │ │ │ - * Adds a layer to the control. Once added, tiles requested for this layer │ │ │ │ │ - * will be cached. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Object with a layer property referencing an │ │ │ │ │ - * instance │ │ │ │ │ + * Property: feature │ │ │ │ │ + * {} Feature currently available for modification. │ │ │ │ │ */ │ │ │ │ │ - addLayer: function(evt) { │ │ │ │ │ - evt.layer.events.on({ │ │ │ │ │ - tileloadstart: this.makeSameOrigin, │ │ │ │ │ - tileloaded: this.onTileLoaded, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + feature: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: removeLayer │ │ │ │ │ - * Removes a layer from the control. Once removed, tiles requested for this │ │ │ │ │ - * layer will no longer be cached. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} Object with a layer property referencing an │ │ │ │ │ - * instance │ │ │ │ │ + * Property: vertex │ │ │ │ │ + * {} Vertex currently being modified. │ │ │ │ │ */ │ │ │ │ │ - removeLayer: function(evt) { │ │ │ │ │ - evt.layer.events.un({ │ │ │ │ │ - tileloadstart: this.makeSameOrigin, │ │ │ │ │ - tileloaded: this.onTileLoaded, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ + vertex: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: makeSameOrigin │ │ │ │ │ - * If the tile does not have CORS image loading enabled and is from a │ │ │ │ │ - * different origin, use OpenLayers.ProxyHost to make it a same origin url. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * Property: vertices │ │ │ │ │ + * {Array()} Verticies currently available │ │ │ │ │ + * for dragging. │ │ │ │ │ */ │ │ │ │ │ - makeSameOrigin: function(evt) { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - var tile = evt.tile; │ │ │ │ │ - if (tile instanceof OpenLayers.Tile.Image && │ │ │ │ │ - !tile.crossOriginKeyword && │ │ │ │ │ - tile.url.substr(0, 5) !== "data:") { │ │ │ │ │ - var sameOriginUrl = OpenLayers.Request.makeSameOrigin( │ │ │ │ │ - tile.url, OpenLayers.ProxyHost │ │ │ │ │ - ); │ │ │ │ │ - OpenLayers.Control.CacheWrite.urlMap[sameOriginUrl] = tile.url; │ │ │ │ │ - tile.url = sameOriginUrl; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + vertices: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onTileLoaded │ │ │ │ │ - * Decides whether a tile can be cached and calls the cache method. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * Property: virtualVertices │ │ │ │ │ + * {Array()} Virtual vertices in the middle │ │ │ │ │ + * of each edge. │ │ │ │ │ */ │ │ │ │ │ - onTileLoaded: function(evt) { │ │ │ │ │ - if (this.active && !evt.aborted && │ │ │ │ │ - evt.tile instanceof OpenLayers.Tile.Image && │ │ │ │ │ - evt.tile.url.substr(0, 5) !== 'data:') { │ │ │ │ │ - this.cache({ │ │ │ │ │ - tile: evt.tile │ │ │ │ │ - }); │ │ │ │ │ - delete OpenLayers.Control.CacheWrite.urlMap[evt.tile.url]; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + virtualVertices: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cache │ │ │ │ │ - * Adds a tile to the cache. When the cache is full, the "cachefull" event │ │ │ │ │ - * is triggered. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} Object with a tile property, tile being the │ │ │ │ │ - * with the data to add to the cache │ │ │ │ │ + * Property: handlers │ │ │ │ │ + * {Object} │ │ │ │ │ */ │ │ │ │ │ - cache: function(obj) { │ │ │ │ │ - if (window.localStorage) { │ │ │ │ │ - var tile = obj.tile; │ │ │ │ │ - try { │ │ │ │ │ - var canvasContext = tile.getCanvasContext(); │ │ │ │ │ - if (canvasContext) { │ │ │ │ │ - var urlMap = OpenLayers.Control.CacheWrite.urlMap; │ │ │ │ │ - var url = urlMap[tile.url] || tile.url; │ │ │ │ │ - window.localStorage.setItem( │ │ │ │ │ - "olCache_" + url, │ │ │ │ │ - canvasContext.canvas.toDataURL(this.imageFormat) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - } catch (e) { │ │ │ │ │ - // local storage full or CORS violation │ │ │ │ │ - var reason = e.name || e.message; │ │ │ │ │ - if (reason && this.quotaRegEx.test(reason)) { │ │ │ │ │ - this.events.triggerEvent("cachefull", { │ │ │ │ │ - tile: tile │ │ │ │ │ - }); │ │ │ │ │ - } else { │ │ │ │ │ - OpenLayers.Console.error(e.toString()); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + handlers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * The destroy method is used to perform any clean up before the control │ │ │ │ │ - * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ - * to prevent memory leaks. │ │ │ │ │ + * APIProperty: deleteCodes │ │ │ │ │ + * {Array(Integer)} Keycodes for deleting verticies. Set to null to disable │ │ │ │ │ + * vertex deltion by keypress. If non-null, keypresses with codes │ │ │ │ │ + * in this array will delete vertices under the mouse. Default │ │ │ │ │ + * is 46 and 68, the 'delete' and lowercase 'd' keys. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.layers || this.map) { │ │ │ │ │ - var i, layers = this.layers || this.map.layers; │ │ │ │ │ - for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ - this.removeLayer({ │ │ │ │ │ - layer: layers[i] │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - if (this.map) { │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - addlayer: this.addLayer, │ │ │ │ │ - removeLayer: this.removeLayer, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.CacheWrite" │ │ │ │ │ -}); │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * APIFunction: OpenLayers.Control.CacheWrite.clearCache │ │ │ │ │ - * Clears all tiles cached with from the cache. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.CacheWrite.clearCache = function() { │ │ │ │ │ - if (!window.localStorage) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var i, key; │ │ │ │ │ - for (i = window.localStorage.length - 1; i >= 0; --i) { │ │ │ │ │ - key = window.localStorage.key(i); │ │ │ │ │ - if (key.substr(0, 8) === "olCache_") { │ │ │ │ │ - window.localStorage.removeItem(key); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ -}; │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Property: OpenLayers.Control.CacheWrite.urlMap │ │ │ │ │ - * {Object} Mapping of same origin urls to cache url keys. Entries will be │ │ │ │ │ - * deleted as soon as a tile was cached. │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.CacheWrite.urlMap = {}; │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Measure.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.Measure │ │ │ │ │ - * Allows for drawing of features for measurements. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + deleteCodes: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * measure - Triggered when a measurement sketch is complete. Listeners │ │ │ │ │ - * will receive an event with measure, units, order, and geometry │ │ │ │ │ - * properties. │ │ │ │ │ - * measurepartial - Triggered when a new point is added to the │ │ │ │ │ - * measurement sketch or if the property is true and the │ │ │ │ │ - * measurement sketch is modified. Listeners receive an event with measure, │ │ │ │ │ - * units, order, and geometry. │ │ │ │ │ + * APIProperty: virtualStyle │ │ │ │ │ + * {Object} A symbolizer to be used for virtual vertices. │ │ │ │ │ */ │ │ │ │ │ + virtualStyle: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ + * APIProperty: vertexRenderIntent │ │ │ │ │ + * {String} The renderIntent to use for vertices. If no is │ │ │ │ │ + * provided, this renderIntent will also be used for virtual vertices, with │ │ │ │ │ + * a fillOpacity and strokeOpacity of 0.3. Default is null, which means │ │ │ │ │ + * that the layer's default style will be used for vertices. │ │ │ │ │ */ │ │ │ │ │ + vertexRenderIntent: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: callbacks │ │ │ │ │ - * {Object} The functions that are sent to the handler for callback │ │ │ │ │ + * APIProperty: mode │ │ │ │ │ + * {Integer} Bitfields specifying the modification mode. Defaults to │ │ │ │ │ + * OpenLayers.Control.ModifyFeature.RESHAPE. To set the mode to a │ │ │ │ │ + * combination of options, use the | operator. For example, to allow │ │ │ │ │ + * the control to both resize and rotate features, use the following │ │ │ │ │ + * syntax │ │ │ │ │ + * (code) │ │ │ │ │ + * control.mode = OpenLayers.Control.ModifyFeature.RESIZE | │ │ │ │ │ + * OpenLayers.Control.ModifyFeature.ROTATE; │ │ │ │ │ + * (end) │ │ │ │ │ */ │ │ │ │ │ - callbacks: null, │ │ │ │ │ + mode: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displaySystem │ │ │ │ │ - * {String} Display system for output measurements. Supported values │ │ │ │ │ - * are 'english', 'metric', and 'geographic'. Default is 'metric'. │ │ │ │ │ + * APIProperty: createVertices │ │ │ │ │ + * {Boolean} Create new vertices by dragging the virtual vertices │ │ │ │ │ + * in the middle of each edge. Default is true. │ │ │ │ │ */ │ │ │ │ │ - displaySystem: 'metric', │ │ │ │ │ + createVertices: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: geodesic │ │ │ │ │ - * {Boolean} Calculate geodesic metrics instead of planar metrics. This │ │ │ │ │ - * requires that geometries can be transformed into Geographic/WGS84 │ │ │ │ │ - * (if that is not already the map projection). Default is false. │ │ │ │ │ + * Property: modified │ │ │ │ │ + * {Boolean} The currently selected feature has been modified. │ │ │ │ │ */ │ │ │ │ │ - geodesic: false, │ │ │ │ │ + modified: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: displaySystemUnits │ │ │ │ │ - * {Object} Units for various measurement systems. Values are arrays │ │ │ │ │ - * of unit abbreviations (from OpenLayers.INCHES_PER_UNIT) in decreasing │ │ │ │ │ - * order of length. │ │ │ │ │ + * Property: radiusHandle │ │ │ │ │ + * {} A handle for rotating/resizing a feature. │ │ │ │ │ */ │ │ │ │ │ - displaySystemUnits: { │ │ │ │ │ - geographic: ['dd'], │ │ │ │ │ - english: ['mi', 'ft', 'in'], │ │ │ │ │ - metric: ['km', 'm'] │ │ │ │ │ - }, │ │ │ │ │ + radiusHandle: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: delay │ │ │ │ │ - * {Number} Number of milliseconds between clicks before the event is │ │ │ │ │ - * considered a double-click. The "measurepartial" event will not │ │ │ │ │ - * be triggered if the sketch is completed within this time. This │ │ │ │ │ - * is required for IE where creating a browser reflow (if a listener │ │ │ │ │ - * is modifying the DOM by displaying the measurement values) messes │ │ │ │ │ - * with the dblclick listener in the sketch handler. │ │ │ │ │ + * Property: dragHandle │ │ │ │ │ + * {} A handle for dragging a feature. │ │ │ │ │ */ │ │ │ │ │ - partialDelay: 300, │ │ │ │ │ + dragHandle: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: delayedTrigger │ │ │ │ │ - * {Number} Timeout id of trigger for measurepartial. │ │ │ │ │ + * APIProperty: onModificationStart │ │ │ │ │ + * {Function} *Deprecated*. Register for "beforefeaturemodified" instead. │ │ │ │ │ + * The "beforefeaturemodified" event is triggered on the layer before │ │ │ │ │ + * any modification begins. │ │ │ │ │ + * │ │ │ │ │ + * Optional function to be called when a feature is selected │ │ │ │ │ + * to be modified. The function should expect to be called with a │ │ │ │ │ + * feature. This could be used for example to allow to lock the │ │ │ │ │ + * feature on server-side. │ │ │ │ │ */ │ │ │ │ │ - delayedTrigger: null, │ │ │ │ │ + onModificationStart: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: persist │ │ │ │ │ - * {Boolean} Keep the temporary measurement sketch drawn after the │ │ │ │ │ - * measurement is complete. The geometry will persist until a new │ │ │ │ │ - * measurement is started, the control is deactivated, or is │ │ │ │ │ - * called. │ │ │ │ │ + * APIProperty: onModification │ │ │ │ │ + * {Function} *Deprecated*. Register for "featuremodified" instead. │ │ │ │ │ + * The "featuremodified" event is triggered on the layer with each │ │ │ │ │ + * feature modification. │ │ │ │ │ + * │ │ │ │ │ + * Optional function to be called when a feature has been │ │ │ │ │ + * modified. The function should expect to be called with a feature. │ │ │ │ │ */ │ │ │ │ │ - persist: false, │ │ │ │ │ + onModification: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: immediate │ │ │ │ │ - * {Boolean} Activates the immediate measurement so that the "measurepartial" │ │ │ │ │ - * event is also fired once the measurement sketch is modified. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * APIProperty: onModificationEnd │ │ │ │ │ + * {Function} *Deprecated*. Register for "afterfeaturemodified" instead. │ │ │ │ │ + * The "afterfeaturemodified" event is triggered on the layer after │ │ │ │ │ + * a feature has been modified. │ │ │ │ │ + * │ │ │ │ │ + * Optional function to be called when a feature is finished │ │ │ │ │ + * being modified. The function should expect to be called with a │ │ │ │ │ + * feature. │ │ │ │ │ */ │ │ │ │ │ - immediate: false, │ │ │ │ │ + onModificationEnd: function() {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Measure │ │ │ │ │ + * Constructor: OpenLayers.Control.ModifyFeature │ │ │ │ │ + * Create a new modify feature control. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * handler - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + * layer - {} Layer that contains features that │ │ │ │ │ + * will be modified. │ │ │ │ │ + * options - {Object} Optional object whose properties will be set on the │ │ │ │ │ + * control. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(handler, options) { │ │ │ │ │ + initialize: function(layer, options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + this.virtualVertices = []; │ │ │ │ │ + this.virtualStyle = OpenLayers.Util.extend({}, │ │ │ │ │ + this.layer.style || │ │ │ │ │ + this.layer.styleMap.createSymbolizer(null, options.vertexRenderIntent) │ │ │ │ │ + ); │ │ │ │ │ + this.virtualStyle.fillOpacity = 0.3; │ │ │ │ │ + this.virtualStyle.strokeOpacity = 0.3; │ │ │ │ │ + this.deleteCodes = [46, 68]; │ │ │ │ │ + this.mode = OpenLayers.Control.ModifyFeature.RESHAPE; │ │ │ │ │ OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - var callbacks = { │ │ │ │ │ - done: this.measureComplete, │ │ │ │ │ - point: this.measurePartial │ │ │ │ │ + if (!(OpenLayers.Util.isArray(this.deleteCodes))) { │ │ │ │ │ + this.deleteCodes = [this.deleteCodes]; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // configure the drag handler │ │ │ │ │ + var dragCallbacks = { │ │ │ │ │ + down: function(pixel) { │ │ │ │ │ + this.vertex = null; │ │ │ │ │ + var feature = this.layer.getFeatureFromEvent( │ │ │ │ │ + this.handlers.drag.evt); │ │ │ │ │ + if (feature) { │ │ │ │ │ + this.dragStart(feature); │ │ │ │ │ + } else if (this.clickout) { │ │ │ │ │ + this._unselect = this.feature; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + move: function(pixel) { │ │ │ │ │ + delete this._unselect; │ │ │ │ │ + if (this.vertex) { │ │ │ │ │ + this.dragVertex(this.vertex, pixel); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + up: function() { │ │ │ │ │ + this.handlers.drag.stopDown = false; │ │ │ │ │ + if (this._unselect) { │ │ │ │ │ + this.unselectFeature(this._unselect); │ │ │ │ │ + delete this._unselect; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + done: function(pixel) { │ │ │ │ │ + if (this.vertex) { │ │ │ │ │ + this.dragComplete(this.vertex); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }; │ │ │ │ │ - if (this.immediate) { │ │ │ │ │ - callbacks.modify = this.measureImmediate; │ │ │ │ │ + var dragOptions = { │ │ │ │ │ + documentDrag: this.documentDrag, │ │ │ │ │ + stopDown: false │ │ │ │ │ + }; │ │ │ │ │ + │ │ │ │ │ + // configure the keyboard handler │ │ │ │ │ + var keyboardOptions = { │ │ │ │ │ + keydown: this.handleKeypress │ │ │ │ │ + }; │ │ │ │ │ + this.handlers = { │ │ │ │ │ + keyboard: new OpenLayers.Handler.Keyboard(this, keyboardOptions), │ │ │ │ │ + drag: new OpenLayers.Handler.Drag(this, dragCallbacks, dragOptions) │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Take care of things that are not handled in superclass. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + "removelayer": this.handleMapEvents, │ │ │ │ │ + "changelayer": this.handleMapEvents, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - this.callbacks = OpenLayers.Util.extend(callbacks, this.callbacks); │ │ │ │ │ + this.layer = null; │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, []); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // let the handler options override, so old code that passes 'persist' │ │ │ │ │ - // directly to the handler does not need an update │ │ │ │ │ - this.handlerOptions = OpenLayers.Util.extend({ │ │ │ │ │ - persist: this.persist │ │ │ │ │ - }, this.handlerOptions); │ │ │ │ │ - this.handler = new handler(this, this.callbacks, this.handlerOptions); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Activate the control. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Successfully activated the control. │ │ │ │ │ + */ │ │ │ │ │ + activate: function() { │ │ │ │ │ + this.moveLayerToTop(); │ │ │ │ │ + this.map.events.on({ │ │ │ │ │ + "removelayer": this.handleMapEvents, │ │ │ │ │ + "changelayer": this.handleMapEvents, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + return (this.handlers.keyboard.activate() && │ │ │ │ │ + this.handlers.drag.activate() && │ │ │ │ │ + OpenLayers.Control.prototype.activate.apply(this, arguments)); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIMethod: deactivate │ │ │ │ │ + * Deactivate the control. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Successfully deactivated the control. │ │ │ │ │ */ │ │ │ │ │ deactivate: function() { │ │ │ │ │ - this.cancelDelay(); │ │ │ │ │ - return OpenLayers.Control.prototype.deactivate.apply(this, arguments); │ │ │ │ │ + var deactivated = false; │ │ │ │ │ + // the return from the controls is unimportant in this case │ │ │ │ │ + if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + this.moveLayerBack(); │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + "removelayer": this.handleMapEvents, │ │ │ │ │ + "changelayer": this.handleMapEvents, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + this.layer.removeFeatures(this.vertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.layer.removeFeatures(this.virtualVertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + this.handlers.drag.deactivate(); │ │ │ │ │ + this.handlers.keyboard.deactivate(); │ │ │ │ │ + var feature = this.feature; │ │ │ │ │ + if (feature && feature.geometry && feature.layer) { │ │ │ │ │ + this.unselectFeature(feature); │ │ │ │ │ + } │ │ │ │ │ + deactivated = true; │ │ │ │ │ + } │ │ │ │ │ + return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: cancel │ │ │ │ │ - * Stop the control from measuring. If is true, the temporary │ │ │ │ │ - * sketch will be erased. │ │ │ │ │ + * Method: beforeSelectFeature │ │ │ │ │ + * Called before a feature is selected. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The feature about to be selected. │ │ │ │ │ */ │ │ │ │ │ - cancel: function() { │ │ │ │ │ - this.cancelDelay(); │ │ │ │ │ - this.handler.cancel(); │ │ │ │ │ + beforeSelectFeature: function(feature) { │ │ │ │ │ + return this.layer.events.triggerEvent( │ │ │ │ │ + "beforefeaturemodified", { │ │ │ │ │ + feature: feature │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: setImmediate │ │ │ │ │ - * Sets the property. Changes the activity of immediate │ │ │ │ │ - * measurement. │ │ │ │ │ + * APIMethod: selectFeature │ │ │ │ │ + * Select a feature for modification in standalone mode. In non-standalone │ │ │ │ │ + * mode, this method is called when a feature is selected by clicking. │ │ │ │ │ + * Register a listener to the beforefeaturemodified event and return false │ │ │ │ │ + * to prevent feature modification. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} the selected feature. │ │ │ │ │ */ │ │ │ │ │ - setImmediate: function(immediate) { │ │ │ │ │ - this.immediate = immediate; │ │ │ │ │ - if (this.immediate) { │ │ │ │ │ - this.callbacks.modify = this.measureImmediate; │ │ │ │ │ - } else { │ │ │ │ │ - delete this.callbacks.modify; │ │ │ │ │ + selectFeature: function(feature) { │ │ │ │ │ + if (this.feature === feature || │ │ │ │ │ + (this.geometryTypes && OpenLayers.Util.indexOf(this.geometryTypes, │ │ │ │ │ + feature.geometry.CLASS_NAME) == -1)) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + if (this.beforeSelectFeature(feature) !== false) { │ │ │ │ │ + if (this.feature) { │ │ │ │ │ + this.unselectFeature(this.feature); │ │ │ │ │ + } │ │ │ │ │ + this.feature = feature; │ │ │ │ │ + this.layer.selectedFeatures.push(feature); │ │ │ │ │ + this.layer.drawFeature(feature, 'select'); │ │ │ │ │ + this.modified = false; │ │ │ │ │ + this.resetVertices(); │ │ │ │ │ + this.onModificationStart(this.feature); │ │ │ │ │ + } │ │ │ │ │ + // keep track of geometry modifications │ │ │ │ │ + var modified = feature.modified; │ │ │ │ │ + if (feature.geometry && !(modified && modified.geometry)) { │ │ │ │ │ + this._originalGeometry = feature.geometry.clone(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: updateHandler │ │ │ │ │ + * APIMethod: unselectFeature │ │ │ │ │ + * Called when the select feature control unselects a feature. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * handler - {Function} One of the sketch handler constructors. │ │ │ │ │ - * options - {Object} Options for the handler. │ │ │ │ │ + * feature - {} The unselected feature. │ │ │ │ │ */ │ │ │ │ │ - updateHandler: function(handler, options) { │ │ │ │ │ - var active = this.active; │ │ │ │ │ - if (active) { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ + unselectFeature: function(feature) { │ │ │ │ │ + this.layer.removeFeatures(this.vertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + this.layer.destroyFeatures(this.virtualVertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.virtualVertices = []; │ │ │ │ │ + if (this.dragHandle) { │ │ │ │ │ + this.layer.destroyFeatures([this.dragHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + delete this.dragHandle; │ │ │ │ │ } │ │ │ │ │ - this.handler = new handler(this, this.callbacks, options); │ │ │ │ │ - if (active) { │ │ │ │ │ - this.activate(); │ │ │ │ │ + if (this.radiusHandle) { │ │ │ │ │ + this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + delete this.radiusHandle; │ │ │ │ │ } │ │ │ │ │ + this.layer.drawFeature(this.feature, 'default'); │ │ │ │ │ + this.feature = null; │ │ │ │ │ + OpenLayers.Util.removeItem(this.layer.selectedFeatures, feature); │ │ │ │ │ + this.onModificationEnd(feature); │ │ │ │ │ + this.layer.events.triggerEvent("afterfeaturemodified", { │ │ │ │ │ + feature: feature, │ │ │ │ │ + modified: this.modified │ │ │ │ │ + }); │ │ │ │ │ + this.modified = false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: measureComplete │ │ │ │ │ - * Called when the measurement sketch is done. │ │ │ │ │ + * Method: dragStart │ │ │ │ │ + * Called by the drag handler before a feature is dragged. This method is │ │ │ │ │ + * used to differentiate between points and vertices │ │ │ │ │ + * of higher order geometries. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ + * feature - {} The point or vertex about to be │ │ │ │ │ + * dragged. │ │ │ │ │ */ │ │ │ │ │ - measureComplete: function(geometry) { │ │ │ │ │ - this.cancelDelay(); │ │ │ │ │ - this.measure(geometry, "measure"); │ │ │ │ │ + dragStart: function(feature) { │ │ │ │ │ + var isPoint = feature.geometry.CLASS_NAME == │ │ │ │ │ + 'OpenLayers.Geometry.Point'; │ │ │ │ │ + if (!this.standalone && │ │ │ │ │ + ((!feature._sketch && isPoint) || !feature._sketch)) { │ │ │ │ │ + if (this.toggle && this.feature === feature) { │ │ │ │ │ + // mark feature for unselection │ │ │ │ │ + this._unselect = feature; │ │ │ │ │ + } │ │ │ │ │ + this.selectFeature(feature); │ │ │ │ │ + } │ │ │ │ │ + if (feature._sketch || isPoint) { │ │ │ │ │ + // feature is a drag or virtual handle or point │ │ │ │ │ + this.vertex = feature; │ │ │ │ │ + this.handlers.drag.stopDown = true; │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: measurePartial │ │ │ │ │ - * Called each time a new point is added to the measurement sketch. │ │ │ │ │ + * Method: dragVertex │ │ │ │ │ + * Called by the drag handler with each drag move of a vertex. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * point - {} The last point added. │ │ │ │ │ - * geometry - {} The sketch geometry. │ │ │ │ │ + * vertex - {} The vertex being dragged. │ │ │ │ │ + * pixel - {} Pixel location of the mouse event. │ │ │ │ │ */ │ │ │ │ │ - measurePartial: function(point, geometry) { │ │ │ │ │ - this.cancelDelay(); │ │ │ │ │ - geometry = geometry.clone(); │ │ │ │ │ - // when we're wating for a dblclick, we have to trigger measurepartial │ │ │ │ │ - // after some delay to deal with reflow issues in IE │ │ │ │ │ - if (this.handler.freehandMode(this.handler.evt)) { │ │ │ │ │ - // no dblclick in freehand mode │ │ │ │ │ - this.measure(geometry, "measurepartial"); │ │ │ │ │ + dragVertex: function(vertex, pixel) { │ │ │ │ │ + var pos = this.map.getLonLatFromViewPortPx(pixel); │ │ │ │ │ + var geom = vertex.geometry; │ │ │ │ │ + geom.move(pos.lon - geom.x, pos.lat - geom.y); │ │ │ │ │ + this.modified = true; │ │ │ │ │ + /** │ │ │ │ │ + * Five cases: │ │ │ │ │ + * 1) dragging a simple point │ │ │ │ │ + * 2) dragging a virtual vertex │ │ │ │ │ + * 3) dragging a drag handle │ │ │ │ │ + * 4) dragging a real vertex │ │ │ │ │ + * 5) dragging a radius handle │ │ │ │ │ + */ │ │ │ │ │ + if (this.feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + // dragging a simple point │ │ │ │ │ + this.layer.events.triggerEvent("vertexmodified", { │ │ │ │ │ + vertex: vertex.geometry, │ │ │ │ │ + feature: this.feature, │ │ │ │ │ + pixel: pixel │ │ │ │ │ + }); │ │ │ │ │ } else { │ │ │ │ │ - this.delayedTrigger = window.setTimeout( │ │ │ │ │ - OpenLayers.Function.bind(function() { │ │ │ │ │ - this.delayedTrigger = null; │ │ │ │ │ - this.measure(geometry, "measurepartial"); │ │ │ │ │ - }, this), │ │ │ │ │ - this.partialDelay │ │ │ │ │ - ); │ │ │ │ │ + if (vertex._index) { │ │ │ │ │ + // dragging a virtual vertex │ │ │ │ │ + vertex.geometry.parent.addComponent(vertex.geometry, │ │ │ │ │ + vertex._index); │ │ │ │ │ + // move from virtual to real vertex │ │ │ │ │ + delete vertex._index; │ │ │ │ │ + OpenLayers.Util.removeItem(this.virtualVertices, vertex); │ │ │ │ │ + this.vertices.push(vertex); │ │ │ │ │ + } else if (vertex == this.dragHandle) { │ │ │ │ │ + // dragging a drag handle │ │ │ │ │ + this.layer.removeFeatures(this.vertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + if (this.radiusHandle) { │ │ │ │ │ + this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.radiusHandle = null; │ │ │ │ │ + } │ │ │ │ │ + } else if (vertex !== this.radiusHandle) { │ │ │ │ │ + // dragging a real vertex │ │ │ │ │ + this.layer.events.triggerEvent("vertexmodified", { │ │ │ │ │ + vertex: vertex.geometry, │ │ │ │ │ + feature: this.feature, │ │ │ │ │ + pixel: pixel │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + // dragging a radius handle - no special treatment │ │ │ │ │ + if (this.virtualVertices.length > 0) { │ │ │ │ │ + this.layer.destroyFeatures(this.virtualVertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.virtualVertices = []; │ │ │ │ │ + } │ │ │ │ │ + this.layer.drawFeature(this.feature, this.standalone ? undefined : │ │ │ │ │ + 'select'); │ │ │ │ │ } │ │ │ │ │ + // keep the vertex on top so it gets the mouseout after dragging │ │ │ │ │ + // this should be removed in favor of an option to draw under or │ │ │ │ │ + // maintain node z-index │ │ │ │ │ + this.layer.drawFeature(vertex); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: measureImmediate │ │ │ │ │ - * Called each time the measurement sketch is modified. │ │ │ │ │ + * Method: dragComplete │ │ │ │ │ + * Called by the drag handler when the feature dragging is complete. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * point - {} The point at the mouse position. │ │ │ │ │ - * feature - {} The sketch feature. │ │ │ │ │ - * drawing - {Boolean} Indicates whether we're currently drawing. │ │ │ │ │ + * vertex - {} The vertex being dragged. │ │ │ │ │ */ │ │ │ │ │ - measureImmediate: function(point, feature, drawing) { │ │ │ │ │ - if (drawing && !this.handler.freehandMode(this.handler.evt)) { │ │ │ │ │ - this.cancelDelay(); │ │ │ │ │ - this.measure(feature.geometry, "measurepartial"); │ │ │ │ │ + dragComplete: function(vertex) { │ │ │ │ │ + this.resetVertices(); │ │ │ │ │ + this.setFeatureState(); │ │ │ │ │ + this.onModification(this.feature); │ │ │ │ │ + this.layer.events.triggerEvent("featuremodified", { │ │ │ │ │ + feature: this.feature │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setFeatureState │ │ │ │ │ + * Called when the feature is modified. If the current state is not │ │ │ │ │ + * INSERT or DELETE, the state is set to UPDATE. │ │ │ │ │ + */ │ │ │ │ │ + setFeatureState: function() { │ │ │ │ │ + if (this.feature.state != OpenLayers.State.INSERT && │ │ │ │ │ + this.feature.state != OpenLayers.State.DELETE) { │ │ │ │ │ + this.feature.state = OpenLayers.State.UPDATE; │ │ │ │ │ + if (this.modified && this._originalGeometry) { │ │ │ │ │ + var feature = this.feature; │ │ │ │ │ + feature.modified = OpenLayers.Util.extend(feature.modified, { │ │ │ │ │ + geometry: this._originalGeometry │ │ │ │ │ + }); │ │ │ │ │ + delete this._originalGeometry; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cancelDelay │ │ │ │ │ - * Cancels the delay measurement that measurePartial began. │ │ │ │ │ + * Method: resetVertices │ │ │ │ │ */ │ │ │ │ │ - cancelDelay: function() { │ │ │ │ │ - if (this.delayedTrigger !== null) { │ │ │ │ │ - window.clearTimeout(this.delayedTrigger); │ │ │ │ │ - this.delayedTrigger = null; │ │ │ │ │ + resetVertices: function() { │ │ │ │ │ + if (this.vertices.length > 0) { │ │ │ │ │ + this.layer.removeFeatures(this.vertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + } │ │ │ │ │ + if (this.virtualVertices.length > 0) { │ │ │ │ │ + this.layer.removeFeatures(this.virtualVertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.virtualVertices = []; │ │ │ │ │ + } │ │ │ │ │ + if (this.dragHandle) { │ │ │ │ │ + this.layer.destroyFeatures([this.dragHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.dragHandle = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.radiusHandle) { │ │ │ │ │ + this.layer.destroyFeatures([this.radiusHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.radiusHandle = null; │ │ │ │ │ + } │ │ │ │ │ + if (this.feature && │ │ │ │ │ + this.feature.geometry.CLASS_NAME != "OpenLayers.Geometry.Point") { │ │ │ │ │ + if ((this.mode & OpenLayers.Control.ModifyFeature.DRAG)) { │ │ │ │ │ + this.collectDragHandle(); │ │ │ │ │ + } │ │ │ │ │ + if ((this.mode & (OpenLayers.Control.ModifyFeature.ROTATE | │ │ │ │ │ + OpenLayers.Control.ModifyFeature.RESIZE))) { │ │ │ │ │ + this.collectRadiusHandle(); │ │ │ │ │ + } │ │ │ │ │ + if (this.mode & OpenLayers.Control.ModifyFeature.RESHAPE) { │ │ │ │ │ + // Don't collect vertices when we're resizing │ │ │ │ │ + if (!(this.mode & OpenLayers.Control.ModifyFeature.RESIZE)) { │ │ │ │ │ + this.collectVertices(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: measure │ │ │ │ │ + * Method: handleKeypress │ │ │ │ │ + * Called by the feature handler on keypress. This is used to delete │ │ │ │ │ + * vertices. If the property is set, vertices will │ │ │ │ │ + * be deleted when a feature is selected for modification and │ │ │ │ │ + * the mouse is over a vertex. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * eventType - {String} │ │ │ │ │ + * evt - {Event} Keypress event. │ │ │ │ │ */ │ │ │ │ │ - measure: function(geometry, eventType) { │ │ │ │ │ - var stat, order; │ │ │ │ │ - if (geometry.CLASS_NAME.indexOf('LineString') > -1) { │ │ │ │ │ - stat = this.getBestLength(geometry); │ │ │ │ │ - order = 1; │ │ │ │ │ - } else { │ │ │ │ │ - stat = this.getBestArea(geometry); │ │ │ │ │ - order = 2; │ │ │ │ │ + handleKeypress: function(evt) { │ │ │ │ │ + var code = evt.keyCode; │ │ │ │ │ + │ │ │ │ │ + // check for delete key │ │ │ │ │ + if (this.feature && │ │ │ │ │ + OpenLayers.Util.indexOf(this.deleteCodes, code) != -1) { │ │ │ │ │ + var vertex = this.layer.getFeatureFromEvent(this.handlers.drag.evt); │ │ │ │ │ + if (vertex && │ │ │ │ │ + OpenLayers.Util.indexOf(this.vertices, vertex) != -1 && │ │ │ │ │ + !this.handlers.drag.dragging && vertex.geometry.parent) { │ │ │ │ │ + // remove the vertex │ │ │ │ │ + vertex.geometry.parent.removeComponent(vertex.geometry); │ │ │ │ │ + this.layer.events.triggerEvent("vertexremoved", { │ │ │ │ │ + vertex: vertex.geometry, │ │ │ │ │ + feature: this.feature, │ │ │ │ │ + pixel: evt.xy │ │ │ │ │ + }); │ │ │ │ │ + this.layer.drawFeature(this.feature, this.standalone ? │ │ │ │ │ + undefined : 'select'); │ │ │ │ │ + this.modified = true; │ │ │ │ │ + this.resetVertices(); │ │ │ │ │ + this.setFeatureState(); │ │ │ │ │ + this.onModification(this.feature); │ │ │ │ │ + this.layer.events.triggerEvent("featuremodified", { │ │ │ │ │ + feature: this.feature │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - this.events.triggerEvent(eventType, { │ │ │ │ │ - measure: stat[0], │ │ │ │ │ - units: stat[1], │ │ │ │ │ - order: order, │ │ │ │ │ - geometry: geometry │ │ │ │ │ - }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getBestArea │ │ │ │ │ - * Based on the returns the area of a geometry. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array([Float, String])} Returns a two item array containing the │ │ │ │ │ - * area and the units abbreviation. │ │ │ │ │ + * Method: collectVertices │ │ │ │ │ + * Collect the vertices from the modifiable feature's geometry and push │ │ │ │ │ + * them on to the control's vertices array. │ │ │ │ │ */ │ │ │ │ │ - getBestArea: function(geometry) { │ │ │ │ │ - var units = this.displaySystemUnits[this.displaySystem]; │ │ │ │ │ - var unit, area; │ │ │ │ │ - for (var i = 0, len = units.length; i < len; ++i) { │ │ │ │ │ - unit = units[i]; │ │ │ │ │ - area = this.getArea(geometry, unit); │ │ │ │ │ - if (area > 1) { │ │ │ │ │ - break; │ │ │ │ │ + collectVertices: function() { │ │ │ │ │ + this.vertices = []; │ │ │ │ │ + this.virtualVertices = []; │ │ │ │ │ + var control = this; │ │ │ │ │ + │ │ │ │ │ + function collectComponentVertices(geometry) { │ │ │ │ │ + var i, vertex, component, len; │ │ │ │ │ + if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + vertex = new OpenLayers.Feature.Vector(geometry); │ │ │ │ │ + vertex._sketch = true; │ │ │ │ │ + vertex.renderIntent = control.vertexRenderIntent; │ │ │ │ │ + control.vertices.push(vertex); │ │ │ │ │ + } else { │ │ │ │ │ + var numVert = geometry.components.length; │ │ │ │ │ + if (geometry.CLASS_NAME == "OpenLayers.Geometry.LinearRing") { │ │ │ │ │ + numVert -= 1; │ │ │ │ │ + } │ │ │ │ │ + for (i = 0; i < numVert; ++i) { │ │ │ │ │ + component = geometry.components[i]; │ │ │ │ │ + if (component.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + vertex = new OpenLayers.Feature.Vector(component); │ │ │ │ │ + vertex._sketch = true; │ │ │ │ │ + vertex.renderIntent = control.vertexRenderIntent; │ │ │ │ │ + control.vertices.push(vertex); │ │ │ │ │ + } else { │ │ │ │ │ + collectComponentVertices(component); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // add virtual vertices in the middle of each edge │ │ │ │ │ + if (control.createVertices && geometry.CLASS_NAME != "OpenLayers.Geometry.MultiPoint") { │ │ │ │ │ + for (i = 0, len = geometry.components.length; i < len - 1; ++i) { │ │ │ │ │ + var prevVertex = geometry.components[i]; │ │ │ │ │ + var nextVertex = geometry.components[i + 1]; │ │ │ │ │ + if (prevVertex.CLASS_NAME == "OpenLayers.Geometry.Point" && │ │ │ │ │ + nextVertex.CLASS_NAME == "OpenLayers.Geometry.Point") { │ │ │ │ │ + var x = (prevVertex.x + nextVertex.x) / 2; │ │ │ │ │ + var y = (prevVertex.y + nextVertex.y) / 2; │ │ │ │ │ + var point = new OpenLayers.Feature.Vector( │ │ │ │ │ + new OpenLayers.Geometry.Point(x, y), │ │ │ │ │ + null, control.virtualStyle │ │ │ │ │ + ); │ │ │ │ │ + // set the virtual parent and intended index │ │ │ │ │ + point.geometry.parent = geometry; │ │ │ │ │ + point._index = i + 1; │ │ │ │ │ + point._sketch = true; │ │ │ │ │ + control.virtualVertices.push(point); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return [area, unit]; │ │ │ │ │ + collectComponentVertices.call(this, this.feature.geometry); │ │ │ │ │ + this.layer.addFeatures(this.virtualVertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.layer.addFeatures(this.vertices, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getArea │ │ │ │ │ + * Method: collectDragHandle │ │ │ │ │ + * Collect the drag handle for the selected geometry. │ │ │ │ │ + */ │ │ │ │ │ + collectDragHandle: function() { │ │ │ │ │ + var geometry = this.feature.geometry; │ │ │ │ │ + var center = geometry.getBounds().getCenterLonLat(); │ │ │ │ │ + var originGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ + center.lon, center.lat │ │ │ │ │ + ); │ │ │ │ │ + var origin = new OpenLayers.Feature.Vector(originGeometry); │ │ │ │ │ + originGeometry.move = function(x, y) { │ │ │ │ │ + OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ + geometry.move(x, y); │ │ │ │ │ + }; │ │ │ │ │ + origin._sketch = true; │ │ │ │ │ + this.dragHandle = origin; │ │ │ │ │ + this.dragHandle.renderIntent = this.vertexRenderIntent; │ │ │ │ │ + this.layer.addFeatures([this.dragHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: collectRadiusHandle │ │ │ │ │ + * Collect the radius handle for the selected geometry. │ │ │ │ │ + */ │ │ │ │ │ + collectRadiusHandle: function() { │ │ │ │ │ + var geometry = this.feature.geometry; │ │ │ │ │ + var bounds = geometry.getBounds(); │ │ │ │ │ + var center = bounds.getCenterLonLat(); │ │ │ │ │ + var originGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ + center.lon, center.lat │ │ │ │ │ + ); │ │ │ │ │ + var radiusGeometry = new OpenLayers.Geometry.Point( │ │ │ │ │ + bounds.right, bounds.bottom │ │ │ │ │ + ); │ │ │ │ │ + var radius = new OpenLayers.Feature.Vector(radiusGeometry); │ │ │ │ │ + var resize = (this.mode & OpenLayers.Control.ModifyFeature.RESIZE); │ │ │ │ │ + var reshape = (this.mode & OpenLayers.Control.ModifyFeature.RESHAPE); │ │ │ │ │ + var rotate = (this.mode & OpenLayers.Control.ModifyFeature.ROTATE); │ │ │ │ │ + │ │ │ │ │ + radiusGeometry.move = function(x, y) { │ │ │ │ │ + OpenLayers.Geometry.Point.prototype.move.call(this, x, y); │ │ │ │ │ + var dx1 = this.x - originGeometry.x; │ │ │ │ │ + var dy1 = this.y - originGeometry.y; │ │ │ │ │ + var dx0 = dx1 - x; │ │ │ │ │ + var dy0 = dy1 - y; │ │ │ │ │ + if (rotate) { │ │ │ │ │ + var a0 = Math.atan2(dy0, dx0); │ │ │ │ │ + var a1 = Math.atan2(dy1, dx1); │ │ │ │ │ + var angle = a1 - a0; │ │ │ │ │ + angle *= 180 / Math.PI; │ │ │ │ │ + geometry.rotate(angle, originGeometry); │ │ │ │ │ + } │ │ │ │ │ + if (resize) { │ │ │ │ │ + var scale, ratio; │ │ │ │ │ + // 'resize' together with 'reshape' implies that the aspect │ │ │ │ │ + // ratio of the geometry will not be preserved whilst resizing │ │ │ │ │ + if (reshape) { │ │ │ │ │ + scale = dy1 / dy0; │ │ │ │ │ + ratio = (dx1 / dx0) / scale; │ │ │ │ │ + } else { │ │ │ │ │ + var l0 = Math.sqrt((dx0 * dx0) + (dy0 * dy0)); │ │ │ │ │ + var l1 = Math.sqrt((dx1 * dx1) + (dy1 * dy1)); │ │ │ │ │ + scale = l1 / l0; │ │ │ │ │ + } │ │ │ │ │ + geometry.resize(scale, originGeometry, ratio); │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + radius._sketch = true; │ │ │ │ │ + this.radiusHandle = radius; │ │ │ │ │ + this.radiusHandle.renderIntent = this.vertexRenderIntent; │ │ │ │ │ + this.layer.addFeatures([this.radiusHandle], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control and all handlers. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * units - {String} Unit abbreviation │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The geometry area in the given units. │ │ │ │ │ + * map - {} The control's map. │ │ │ │ │ */ │ │ │ │ │ - getArea: function(geometry, units) { │ │ │ │ │ - var area, geomUnits; │ │ │ │ │ - if (this.geodesic) { │ │ │ │ │ - area = geometry.getGeodesicArea(this.map.getProjectionObject()); │ │ │ │ │ - geomUnits = "m"; │ │ │ │ │ - } else { │ │ │ │ │ - area = geometry.getArea(); │ │ │ │ │ - geomUnits = this.map.getUnits(); │ │ │ │ │ - } │ │ │ │ │ - var inPerDisplayUnit = OpenLayers.INCHES_PER_UNIT[units]; │ │ │ │ │ - if (inPerDisplayUnit) { │ │ │ │ │ - var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[geomUnits]; │ │ │ │ │ - area *= Math.pow((inPerMapUnit / inPerDisplayUnit), 2); │ │ │ │ │ - } │ │ │ │ │ - return area; │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + this.handlers.drag.setMap(map); │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getBestLength │ │ │ │ │ - * Based on the returns the length of a geometry. │ │ │ │ │ - * │ │ │ │ │ + * Method: handleMapEvents │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array([Float, String])} Returns a two item array containing the │ │ │ │ │ - * length and the units abbreviation. │ │ │ │ │ + * evt - {Object} │ │ │ │ │ */ │ │ │ │ │ - getBestLength: function(geometry) { │ │ │ │ │ - var units = this.displaySystemUnits[this.displaySystem]; │ │ │ │ │ - var unit, length; │ │ │ │ │ - for (var i = 0, len = units.length; i < len; ++i) { │ │ │ │ │ - unit = units[i]; │ │ │ │ │ - length = this.getLength(geometry, unit); │ │ │ │ │ - if (length > 1) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + handleMapEvents: function(evt) { │ │ │ │ │ + if (evt.type == "removelayer" || evt.property == "order") { │ │ │ │ │ + this.moveLayerToTop(); │ │ │ │ │ } │ │ │ │ │ - return [length, unit]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getLength │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * geometry - {} │ │ │ │ │ - * units - {String} Unit abbreviation │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Float} The geometry length in the given units. │ │ │ │ │ + * Method: moveLayerToTop │ │ │ │ │ + * Moves the layer for this handler to the top, so mouse events can reach │ │ │ │ │ + * it. │ │ │ │ │ */ │ │ │ │ │ - getLength: function(geometry, units) { │ │ │ │ │ - var length, geomUnits; │ │ │ │ │ - if (this.geodesic) { │ │ │ │ │ - length = geometry.getGeodesicLength(this.map.getProjectionObject()); │ │ │ │ │ - geomUnits = "m"; │ │ │ │ │ + moveLayerToTop: function() { │ │ │ │ │ + var index = Math.max(this.map.Z_INDEX_BASE['Feature'] - 1, │ │ │ │ │ + this.layer.getZIndex()) + 1; │ │ │ │ │ + this.layer.setZIndex(index); │ │ │ │ │ + │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: moveLayerBack │ │ │ │ │ + * Moves the layer back to the position determined by the map's layers │ │ │ │ │ + * array. │ │ │ │ │ + */ │ │ │ │ │ + moveLayerBack: function() { │ │ │ │ │ + var index = this.layer.getZIndex() - 1; │ │ │ │ │ + if (index >= this.map.Z_INDEX_BASE['Feature']) { │ │ │ │ │ + this.layer.setZIndex(index); │ │ │ │ │ } else { │ │ │ │ │ - length = geometry.getLength(); │ │ │ │ │ - geomUnits = this.map.getUnits(); │ │ │ │ │ - } │ │ │ │ │ - var inPerDisplayUnit = OpenLayers.INCHES_PER_UNIT[units]; │ │ │ │ │ - if (inPerDisplayUnit) { │ │ │ │ │ - var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[geomUnits]; │ │ │ │ │ - length *= (inPerMapUnit / inPerDisplayUnit); │ │ │ │ │ + this.map.setLayerZIndex(this.layer, │ │ │ │ │ + this.map.getLayerIndex(this.layer)); │ │ │ │ │ } │ │ │ │ │ - return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Measure" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ModifyFeature" │ │ │ │ │ }); │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Constant: RESHAPE │ │ │ │ │ + * {Integer} Constant used to make the control work in reshape mode │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ModifyFeature.RESHAPE = 1; │ │ │ │ │ +/** │ │ │ │ │ + * Constant: RESIZE │ │ │ │ │ + * {Integer} Constant used to make the control work in resize mode │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ModifyFeature.RESIZE = 2; │ │ │ │ │ +/** │ │ │ │ │ + * Constant: ROTATE │ │ │ │ │ + * {Integer} Constant used to make the control work in rotate mode │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ModifyFeature.ROTATE = 4; │ │ │ │ │ +/** │ │ │ │ │ + * Constant: DRAG │ │ │ │ │ + * {Integer} Constant used to make the control work in drag mode │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ModifyFeature.DRAG = 8; │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Graticule.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/Control.js │ │ │ │ │ - * @requires OpenLayers/Lang.js │ │ │ │ │ - * @requires OpenLayers/Rule.js │ │ │ │ │ - * @requires OpenLayers/StyleMap.js │ │ │ │ │ - * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ + * @requires OpenLayers/Format/XML.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.Graticule │ │ │ │ │ - * The Graticule displays a grid of latitude/longitude lines reprojected on │ │ │ │ │ - * the map. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Format.WMSGetFeatureInfo │ │ │ │ │ + * Class to read GetFeatureInfo responses from Web Mapping Services │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - * │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.Graticule = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ +OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: intervals │ │ │ │ │ - * {Array(Float)} A list of possible graticule widths in degrees. │ │ │ │ │ + * APIProperty: layerIdentifier │ │ │ │ │ + * {String} All xml nodes containing this search criteria will populate an │ │ │ │ │ + * internal array of layer nodes. │ │ │ │ │ */ │ │ │ │ │ - intervals: [45, 30, 20, 10, 5, 2, 1, │ │ │ │ │ - 0.5, 0.2, 0.1, 0.05, 0.01, │ │ │ │ │ - 0.005, 0.002, 0.001 │ │ │ │ │ - ], │ │ │ │ │ + layerIdentifier: '_layer', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: displayInLayerSwitcher │ │ │ │ │ - * {Boolean} Allows the Graticule control to be switched on and off by │ │ │ │ │ - * LayerSwitcher control. Defaults is true. │ │ │ │ │ + * APIProperty: featureIdentifier │ │ │ │ │ + * {String} All xml nodes containing this search criteria will populate an │ │ │ │ │ + * internal array of feature nodes for each layer node found. │ │ │ │ │ */ │ │ │ │ │ - displayInLayerSwitcher: true, │ │ │ │ │ + featureIdentifier: '_feature', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: visible │ │ │ │ │ - * {Boolean} should the graticule be initially visible (default=true) │ │ │ │ │ + * Property: regExes │ │ │ │ │ + * Compiled regular expressions for manipulating strings. │ │ │ │ │ */ │ │ │ │ │ - visible: true, │ │ │ │ │ + regExes: { │ │ │ │ │ + trimSpace: (/^\s*|\s*$/g), │ │ │ │ │ + removeSpace: (/\s*/g), │ │ │ │ │ + splitSpace: (/\s+/), │ │ │ │ │ + trimComma: (/\s*,\s*/g) │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: numPoints │ │ │ │ │ - * {Integer} The number of points to use in each graticule line. Higher │ │ │ │ │ - * numbers result in a smoother curve for projected maps │ │ │ │ │ + * Property: gmlFormat │ │ │ │ │ + * {} internal GML format for parsing geometries │ │ │ │ │ + * in msGMLOutput │ │ │ │ │ */ │ │ │ │ │ - numPoints: 50, │ │ │ │ │ + gmlFormat: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: targetSize │ │ │ │ │ - * {Integer} The maximum size of the grid in pixels on the map │ │ │ │ │ + * Constructor: OpenLayers.Format.WMSGetFeatureInfo │ │ │ │ │ + * Create a new parser for WMS GetFeatureInfo responses │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ */ │ │ │ │ │ - targetSize: 200, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layerName │ │ │ │ │ - * {String} The name to be displayed in the layer switcher, default is set │ │ │ │ │ - * by {}. │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read WMS GetFeatureInfo data from a string, and return an array of features │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array()} An array of features. │ │ │ │ │ */ │ │ │ │ │ - layerName: null, │ │ │ │ │ + read: function(data) { │ │ │ │ │ + var result; │ │ │ │ │ + if (typeof data == "string") { │ │ │ │ │ + data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ + } │ │ │ │ │ + var root = data.documentElement; │ │ │ │ │ + if (root) { │ │ │ │ │ + var scope = this; │ │ │ │ │ + var read = this["read_" + root.nodeName]; │ │ │ │ │ + if (read) { │ │ │ │ │ + result = read.call(this, root); │ │ │ │ │ + } else { │ │ │ │ │ + // fall-back to GML since this is a common output format for WMS │ │ │ │ │ + // GetFeatureInfo responses │ │ │ │ │ + result = new OpenLayers.Format.GML((this.options ? this.options : {})).read(data); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + result = data; │ │ │ │ │ + } │ │ │ │ │ + return result; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * 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. │ │ │ │ │ + * Method: read_msGMLOutput │ │ │ │ │ + * Parse msGMLOutput nodes. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {DOMElement} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} │ │ │ │ │ */ │ │ │ │ │ - labelFormat: 'dm', │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: lineSymbolizer │ │ │ │ │ - * {symbolizer} the symbolizer used to render lines │ │ │ │ │ - */ │ │ │ │ │ - lineSymbolizer: { │ │ │ │ │ - strokeColor: "#333", │ │ │ │ │ - strokeWidth: 1, │ │ │ │ │ - strokeOpacity: 0.5 │ │ │ │ │ + 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 response; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: labelSymbolizer │ │ │ │ │ - * {symbolizer} the symbolizer used to render labels │ │ │ │ │ + * Method: read_FeatureInfoResponse │ │ │ │ │ + * Parse FeatureInfoResponse nodes. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {DOMElement} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} │ │ │ │ │ */ │ │ │ │ │ - labelSymbolizer: {}, │ │ │ │ │ + read_FeatureInfoResponse: function(data) { │ │ │ │ │ + var response = []; │ │ │ │ │ + var featureNodes = this.getElementsByTagNameNS(data, '*', │ │ │ │ │ + 'FIELDS'); │ │ │ │ │ + │ │ │ │ │ + for (var i = 0, len = featureNodes.length; i < len; i++) { │ │ │ │ │ + var featureNode = featureNodes[i]; │ │ │ │ │ + var geom = null; │ │ │ │ │ + │ │ │ │ │ + // attributes can be actual attributes on the FIELDS tag, │ │ │ │ │ + // or FIELD children │ │ │ │ │ + var attributes = {}; │ │ │ │ │ + var j; │ │ │ │ │ + var jlen = featureNode.attributes.length; │ │ │ │ │ + if (jlen > 0) { │ │ │ │ │ + for (j = 0; j < jlen; j++) { │ │ │ │ │ + var attribute = featureNode.attributes[j]; │ │ │ │ │ + attributes[attribute.nodeName] = attribute.nodeValue; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + var nodes = featureNode.childNodes; │ │ │ │ │ + for (j = 0, jlen = nodes.length; j < jlen; ++j) { │ │ │ │ │ + var node = nodes[j]; │ │ │ │ │ + if (node.nodeType != 3) { │ │ │ │ │ + attributes[node.getAttribute("name")] = │ │ │ │ │ + node.getAttribute("value"); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + response.push( │ │ │ │ │ + new OpenLayers.Feature.Vector(geom, attributes, null) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return response; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: gratLayer │ │ │ │ │ - * {} vector layer used to draw the graticule on │ │ │ │ │ + * 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 │ │ │ │ │ */ │ │ │ │ │ - gratLayer: 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; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Graticule │ │ │ │ │ - * Create a new graticule control to display a grid of latitude longitude │ │ │ │ │ - * lines. │ │ │ │ │ + * Method: parseAttributes │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * node - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An attributes object. │ │ │ │ │ * │ │ │ │ │ + * Notes: │ │ │ │ │ + * Assumes that attributes are direct child xml nodes of the passed node │ │ │ │ │ + * and contain only a single text node. │ │ │ │ │ + */ │ │ │ │ │ + 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; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseGeometry │ │ │ │ │ + * Parse the geometry and the feature bounds out of the node using │ │ │ │ │ + * Format.GML │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * node - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object containing the geometry and the feature bounds │ │ │ │ │ + */ │ │ │ │ │ + parseGeometry: function(node) { │ │ │ │ │ + // we need to use the old Format.GML parser since we do not know the │ │ │ │ │ + // geometry name │ │ │ │ │ + if (!this.gmlFormat) { │ │ │ │ │ + this.gmlFormat = new OpenLayers.Format.GML(); │ │ │ │ │ + } │ │ │ │ │ + var feature = this.gmlFormat.parseFeature(node); │ │ │ │ │ + var geometry, bounds = null; │ │ │ │ │ + if (feature) { │ │ │ │ │ + geometry = feature.geometry && feature.geometry.clone(); │ │ │ │ │ + bounds = feature.bounds && feature.bounds.clone(); │ │ │ │ │ + feature.destroy(); │ │ │ │ │ + } │ │ │ │ │ + return { │ │ │ │ │ + geometry: geometry, │ │ │ │ │ + bounds: bounds │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.WMSGetFeatureInfo" │ │ │ │ │ + │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/WMTSGetFeatureInfo.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ + * @requires OpenLayers/Request.js │ │ │ │ │ + * @requires OpenLayers/Format/WMSGetFeatureInfo.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.WMTSGetFeatureInfo │ │ │ │ │ + * The WMTSGetFeatureInfo control uses a WMTS query to get information about a │ │ │ │ │ + * point on the map. The information may be in a display-friendly format │ │ │ │ │ + * such as HTML, or a machine-friendly format such as GML, depending on the │ │ │ │ │ + * server's capabilities and the client's configuration. This control │ │ │ │ │ + * handles click or hover events, attempts to parse the results using an │ │ │ │ │ + * OpenLayers.Format, and fires a 'getfeatureinfo' event for each layer │ │ │ │ │ + * queried. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.WMTSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: hover │ │ │ │ │ + * {Boolean} Send GetFeatureInfo requests when mouse stops moving. │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + hover: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: requestEncoding │ │ │ │ │ + * {String} One of "KVP" or "REST". Only KVP encoding is supported at this │ │ │ │ │ + * time. │ │ │ │ │ + */ │ │ │ │ │ + requestEncoding: "KVP", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: drillDown │ │ │ │ │ + * {Boolean} Drill down over all WMTS layers in the map. When │ │ │ │ │ + * using drillDown mode, hover is not possible. A getfeatureinfo event │ │ │ │ │ + * will be fired for each layer queried. │ │ │ │ │ + */ │ │ │ │ │ + drillDown: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: maxFeatures │ │ │ │ │ + * {Integer} Maximum number of features to return from a WMTS query. This │ │ │ │ │ + * sets the feature_count parameter on WMTS GetFeatureInfo │ │ │ │ │ + * requests. │ │ │ │ │ + */ │ │ │ │ │ + maxFeatures: 10, │ │ │ │ │ + │ │ │ │ │ + /** APIProperty: clickCallback │ │ │ │ │ + * {String} The click callback to register in the │ │ │ │ │ + * {} object created when the hover │ │ │ │ │ + * option is set to false. Default is "click". │ │ │ │ │ + */ │ │ │ │ │ + clickCallback: "click", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: layers │ │ │ │ │ + * {Array()} The layers to query for feature info. │ │ │ │ │ + * If omitted, all map WMTS layers will be considered. │ │ │ │ │ + */ │ │ │ │ │ + layers: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: queryVisible │ │ │ │ │ + * {Boolean} Filter out hidden layers when searching the map for layers to │ │ │ │ │ + * query. Default is true. │ │ │ │ │ + */ │ │ │ │ │ + queryVisible: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: infoFormat │ │ │ │ │ + * {String} The mimetype to request from the server │ │ │ │ │ + */ │ │ │ │ │ + infoFormat: 'text/html', │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: vendorParams │ │ │ │ │ + * {Object} Additional parameters that will be added to the request, for │ │ │ │ │ + * WMTS implementations that support them. This could e.g. look like │ │ │ │ │ + * (start code) │ │ │ │ │ + * { │ │ │ │ │ + * radius: 5 │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + */ │ │ │ │ │ + vendorParams: {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: format │ │ │ │ │ + * {} A format for parsing GetFeatureInfo responses. │ │ │ │ │ + * Default is . │ │ │ │ │ + */ │ │ │ │ │ + format: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: formatOptions │ │ │ │ │ + * {Object} Optional properties to set on the format (if one is not provided │ │ │ │ │ + * in the property. │ │ │ │ │ + */ │ │ │ │ │ + formatOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: handlerOptions │ │ │ │ │ + * {Object} Additional options for the handlers used by this control, e.g. │ │ │ │ │ + * (start code) │ │ │ │ │ + * { │ │ │ │ │ + * "click": {delay: 100}, │ │ │ │ │ + * "hover": {delay: 300} │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: handler │ │ │ │ │ + * {Object} Reference to the for this control │ │ │ │ │ + */ │ │ │ │ │ + handler: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: hoverRequest │ │ │ │ │ + * {} contains the currently running hover request │ │ │ │ │ + * (if any). │ │ │ │ │ + */ │ │ │ │ │ + hoverRequest: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * beforegetfeatureinfo - Triggered before each request is sent. │ │ │ │ │ + * The event object has an *xy* property with the position of the │ │ │ │ │ + * mouse click or hover event that triggers the request and a *layer* │ │ │ │ │ + * property referencing the layer about to be queried. If a listener │ │ │ │ │ + * returns false, the request will not be issued. │ │ │ │ │ + * getfeatureinfo - Triggered when a GetFeatureInfo response is received. │ │ │ │ │ + * The event object has a *text* property with the body of the │ │ │ │ │ + * response (String), a *features* property with an array of the │ │ │ │ │ + * parsed features, an *xy* property with the position of the mouse │ │ │ │ │ + * click or hover event that triggered the request, a *layer* property │ │ │ │ │ + * referencing the layer queried and a *request* property with the │ │ │ │ │ + * request itself. If drillDown is set to true, one event will be fired │ │ │ │ │ + * for each layer queried. │ │ │ │ │ + * exception - Triggered when a GetFeatureInfo request fails (with a │ │ │ │ │ + * status other than 200) or whenparsing fails. Listeners will receive │ │ │ │ │ + * an event with *request*, *xy*, and *layer* properties. In the case │ │ │ │ │ + * of a parsing error, the event will also contain an *error* property. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: pending │ │ │ │ │ + * {Number} The number of pending requests. │ │ │ │ │ + */ │ │ │ │ │ + pending: 0, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ options = options || {}; │ │ │ │ │ - options.layerName = options.layerName || OpenLayers.i18n("Graticule"); │ │ │ │ │ + options.handlerOptions = options.handlerOptions || {}; │ │ │ │ │ + │ │ │ │ │ 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}"; │ │ │ │ │ + if (!this.format) { │ │ │ │ │ + this.format = new OpenLayers.Format.WMSGetFeatureInfo( │ │ │ │ │ + options.formatOptions │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.drillDown === true) { │ │ │ │ │ + this.hover = false; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.hover) { │ │ │ │ │ + this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ + this, { │ │ │ │ │ + move: this.cancelHover, │ │ │ │ │ + pause: this.getInfoForHover │ │ │ │ │ + }, │ │ │ │ │ + OpenLayers.Util.extend( │ │ │ │ │ + this.handlerOptions.hover || {}, { │ │ │ │ │ + delay: 250 │ │ │ │ │ + } │ │ │ │ │ + ) │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + var callbacks = {}; │ │ │ │ │ + callbacks[this.clickCallback] = this.getInfoForClick; │ │ │ │ │ + this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ + this, callbacks, this.handlerOptions.click || {} │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ + * Method: getInfoForClick │ │ │ │ │ + * Called on click │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - if (this.gratLayer) { │ │ │ │ │ - this.gratLayer.destroy(); │ │ │ │ │ - this.gratLayer = null; │ │ │ │ │ + getInfoForClick: function(evt) { │ │ │ │ │ + this.request(evt.xy, {}); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getInfoForHover │ │ │ │ │ + * Pause callback for the hover handler │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} │ │ │ │ │ + */ │ │ │ │ │ + getInfoForHover: function(evt) { │ │ │ │ │ + this.request(evt.xy, { │ │ │ │ │ + hover: true │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: cancelHover │ │ │ │ │ + * Cancel callback for the hover handler │ │ │ │ │ + */ │ │ │ │ │ + cancelHover: function() { │ │ │ │ │ + if (this.hoverRequest) { │ │ │ │ │ + --this.pending; │ │ │ │ │ + if (this.pending <= 0) { │ │ │ │ │ + OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + this.pending = 0; │ │ │ │ │ + } │ │ │ │ │ + this.hoverRequest.abort(); │ │ │ │ │ + this.hoverRequest = null; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * Method: findLayers │ │ │ │ │ + * Internal method to get the layers, independent of whether we are │ │ │ │ │ + * inspecting the map or using a client-provided array │ │ │ │ │ + */ │ │ │ │ │ + findLayers: function() { │ │ │ │ │ + var candidates = this.layers || this.map.layers; │ │ │ │ │ + var layers = []; │ │ │ │ │ + var layer; │ │ │ │ │ + for (var i = candidates.length - 1; i >= 0; --i) { │ │ │ │ │ + layer = candidates[i]; │ │ │ │ │ + if (layer instanceof OpenLayers.Layer.WMTS && │ │ │ │ │ + layer.requestEncoding === this.requestEncoding && │ │ │ │ │ + (!this.queryVisible || layer.getVisibility())) { │ │ │ │ │ + layers.push(layer); │ │ │ │ │ + if (!this.drillDown || this.hover) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return layers; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: buildRequestOptions │ │ │ │ │ + * Build an object with the relevant options for the GetFeatureInfo request. │ │ │ │ │ * │ │ │ │ │ - * initializes the graticule layer and does the initial update │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} A WMTS layer. │ │ │ │ │ + * xy - {} The position on the map where the │ │ │ │ │ + * mouse event occurred. │ │ │ │ │ + */ │ │ │ │ │ + buildRequestOptions: function(layer, xy) { │ │ │ │ │ + var loc = this.map.getLonLatFromPixel(xy); │ │ │ │ │ + var getTileUrl = layer.getURL( │ │ │ │ │ + new OpenLayers.Bounds(loc.lon, loc.lat, loc.lon, loc.lat) │ │ │ │ │ + ); │ │ │ │ │ + var params = OpenLayers.Util.getParameters(getTileUrl); │ │ │ │ │ + var tileInfo = layer.getTileInfo(loc); │ │ │ │ │ + OpenLayers.Util.extend(params, { │ │ │ │ │ + service: "WMTS", │ │ │ │ │ + version: layer.version, │ │ │ │ │ + request: "GetFeatureInfo", │ │ │ │ │ + infoFormat: this.infoFormat, │ │ │ │ │ + i: tileInfo.i, │ │ │ │ │ + j: tileInfo.j │ │ │ │ │ + }); │ │ │ │ │ + OpenLayers.Util.applyDefaults(params, this.vendorParams); │ │ │ │ │ + return { │ │ │ │ │ + url: OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url, │ │ │ │ │ + params: OpenLayers.Util.upperCaseObject(params), │ │ │ │ │ + callback: function(request) { │ │ │ │ │ + this.handleResponse(xy, request, layer); │ │ │ │ │ + }, │ │ │ │ │ + scope: this │ │ │ │ │ + }; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: request │ │ │ │ │ + * Sends a GetFeatureInfo request to the WMTS │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {DOMElement} │ │ │ │ │ + * Parameters: │ │ │ │ │ + * xy - {} The position on the map where the mouse event │ │ │ │ │ + * occurred. │ │ │ │ │ + * options - {Object} additional options for this method. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * - *hover* {Boolean} true if we do the request for the hover handler │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ + request: function(xy, options) { │ │ │ │ │ + options = options || {}; │ │ │ │ │ + var layers = this.findLayers(); │ │ │ │ │ + if (layers.length > 0) { │ │ │ │ │ + var issue, layer; │ │ │ │ │ + for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ + layer = layers[i]; │ │ │ │ │ + issue = this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ + xy: xy, │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ + if (issue !== false) { │ │ │ │ │ + ++this.pending; │ │ │ │ │ + var requestOptions = this.buildRequestOptions(layer, xy); │ │ │ │ │ + var request = OpenLayers.Request.GET(requestOptions); │ │ │ │ │ + if (options.hover === true) { │ │ │ │ │ + this.hoverRequest = request; │ │ │ │ │ } │ │ │ │ │ - })] │ │ │ │ │ - }); │ │ │ │ │ - this.gratLayer = new OpenLayers.Layer.Vector(this.layerName, { │ │ │ │ │ - styleMap: new OpenLayers.StyleMap({ │ │ │ │ │ - 'default': gratStyle │ │ │ │ │ - }), │ │ │ │ │ - visibility: this.visible, │ │ │ │ │ - displayInLayerSwitcher: this.displayInLayerSwitcher │ │ │ │ │ - }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.pending > 0) { │ │ │ │ │ + OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ + * Method: handleResponse │ │ │ │ │ + * Handler for the GetFeatureInfo response. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * xy - {} The position on the map where the mouse event │ │ │ │ │ + * occurred. │ │ │ │ │ + * request - {XMLHttpRequest} The request object. │ │ │ │ │ + * layer - {} The queried layer. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + handleResponse: function(xy, request, layer) { │ │ │ │ │ + --this.pending; │ │ │ │ │ + if (this.pending <= 0) { │ │ │ │ │ + OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + this.pending = 0; │ │ │ │ │ + } │ │ │ │ │ + if (request.status && (request.status < 200 || request.status >= 300)) { │ │ │ │ │ + this.events.triggerEvent("exception", { │ │ │ │ │ + xy: xy, │ │ │ │ │ + request: request, │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ } else { │ │ │ │ │ - return false; │ │ │ │ │ + var doc = request.responseXML; │ │ │ │ │ + if (!doc || !doc.documentElement) { │ │ │ │ │ + doc = request.responseText; │ │ │ │ │ + } │ │ │ │ │ + var features, except; │ │ │ │ │ + try { │ │ │ │ │ + features = this.format.read(doc); │ │ │ │ │ + } catch (error) { │ │ │ │ │ + except = true; │ │ │ │ │ + this.events.triggerEvent("exception", { │ │ │ │ │ + xy: xy, │ │ │ │ │ + request: request, │ │ │ │ │ + error: error, │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (!except) { │ │ │ │ │ + this.events.triggerEvent("getfeatureinfo", { │ │ │ │ │ + text: request.responseText, │ │ │ │ │ + features: features, │ │ │ │ │ + request: request, │ │ │ │ │ + xy: xy, │ │ │ │ │ + layer: layer │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.WMTSGetFeatureInfo" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/ZoomToMaxExtent.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control/Button.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.ZoomToMaxExtent │ │ │ │ │ + * The ZoomToMaxExtent control is a button that zooms out to the maximum │ │ │ │ │ + * extent of the map. It is designed to be used with a │ │ │ │ │ + * . │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ZoomToMaxExtent = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ + * Method: trigger │ │ │ │ │ + * │ │ │ │ │ + * Called whenever this control is being rendered inside of a panel and a │ │ │ │ │ + * click occurs on this controls element. Actually zooms to the maximum │ │ │ │ │ + * extent of this controls map. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ + trigger: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.zoomToMaxExtent(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ZoomToMaxExtent" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/ScaleLine.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.ScaleLine │ │ │ │ │ + * The ScaleLine displays a small line indicator representing the current │ │ │ │ │ + * map scale on the map. By default it is drawn in the lower left corner of │ │ │ │ │ + * the map. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + * │ │ │ │ │ + * Is a very close copy of: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ScaleLine = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: update │ │ │ │ │ - * │ │ │ │ │ - * calculates the grid to be displayed and actually draws it │ │ │ │ │ + * Property: maxWidth │ │ │ │ │ + * {Integer} Maximum width of the scale line in pixels. Default is 100. │ │ │ │ │ + */ │ │ │ │ │ + maxWidth: 100, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: topOutUnits │ │ │ │ │ + * {String} Units for zoomed out on top bar. Default is km. │ │ │ │ │ + */ │ │ │ │ │ + topOutUnits: "km", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: topInUnits │ │ │ │ │ + * {String} Units for zoomed in on top bar. Default is m. │ │ │ │ │ + */ │ │ │ │ │ + topInUnits: "m", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: bottomOutUnits │ │ │ │ │ + * {String} Units for zoomed out on bottom bar. Default is mi. │ │ │ │ │ + */ │ │ │ │ │ + bottomOutUnits: "mi", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: bottomInUnits │ │ │ │ │ + * {String} Units for zoomed in on bottom bar. Default is ft. │ │ │ │ │ + */ │ │ │ │ │ + bottomInUnits: "ft", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: eTop │ │ │ │ │ + * {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + eTop: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: eBottom │ │ │ │ │ + * {DOMElement} │ │ │ │ │ + */ │ │ │ │ │ + eBottom: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: geodesic │ │ │ │ │ + * {Boolean} Use geodesic measurement. Default is false. The recommended │ │ │ │ │ + * setting for maps in EPSG:4326 is false, and true EPSG:900913. If set to │ │ │ │ │ + * true, the scale will be calculated based on the horizontal size of the │ │ │ │ │ + * pixel in the center of the map viewport. │ │ │ │ │ + */ │ │ │ │ │ + geodesic: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.ScaleLine │ │ │ │ │ + * Create a new scale line control. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: draw │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ + draw: function() { │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (!this.eTop) { │ │ │ │ │ + // stick in the top bar │ │ │ │ │ + this.eTop = document.createElement("div"); │ │ │ │ │ + this.eTop.className = this.displayClass + "Top"; │ │ │ │ │ + var theLen = this.topInUnits.length; │ │ │ │ │ + this.div.appendChild(this.eTop); │ │ │ │ │ + if ((this.topOutUnits == "") || (this.topInUnits == "")) { │ │ │ │ │ + this.eTop.style.visibility = "hidden"; │ │ │ │ │ + } else { │ │ │ │ │ + this.eTop.style.visibility = "visible"; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // and the bottom bar │ │ │ │ │ + this.eBottom = document.createElement("div"); │ │ │ │ │ + this.eBottom.className = this.displayClass + "Bottom"; │ │ │ │ │ + this.div.appendChild(this.eBottom); │ │ │ │ │ + if ((this.bottomOutUnits == "") || (this.bottomInUnits == "")) { │ │ │ │ │ + this.eBottom.style.visibility = "hidden"; │ │ │ │ │ + } else { │ │ │ │ │ + this.eBottom.style.visibility = "visible"; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.map.events.register('moveend', this, this.update); │ │ │ │ │ + this.update(); │ │ │ │ │ + return this.div; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getBarLen │ │ │ │ │ + * Given a number, round it down to the nearest 1,2,5 times a power of 10. │ │ │ │ │ + * That seems a fairly useful set of number groups to use. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * maxLen - {float} the number we're rounding down from │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} the rounded number (less than or equal to maxLen) │ │ │ │ │ + */ │ │ │ │ │ + getBarLen: function(maxLen) { │ │ │ │ │ + // nearest power of 10 lower than maxLen │ │ │ │ │ + var digits = parseInt(Math.log(maxLen) / Math.log(10)); │ │ │ │ │ + var pow10 = Math.pow(10, digits); │ │ │ │ │ + │ │ │ │ │ + // ok, find first character │ │ │ │ │ + var firstChar = parseInt(maxLen / pow10); │ │ │ │ │ + │ │ │ │ │ + // right, put it into the correct bracket │ │ │ │ │ + var barLen; │ │ │ │ │ + if (firstChar > 5) { │ │ │ │ │ + barLen = 5; │ │ │ │ │ + } else if (firstChar > 2) { │ │ │ │ │ + barLen = 2; │ │ │ │ │ + } else { │ │ │ │ │ + barLen = 1; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // scale it up the correct power of 10 │ │ │ │ │ + return barLen * pow10; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: update │ │ │ │ │ + * Update the size of the bars, and the labels they contain. │ │ │ │ │ + */ │ │ │ │ │ update: function() { │ │ │ │ │ - //wait for the map to be initialized before proceeding │ │ │ │ │ - var mapBounds = this.map.getExtent(); │ │ │ │ │ - if (!mapBounds) { │ │ │ │ │ + var res = this.map.getResolution(); │ │ │ │ │ + if (!res) { │ │ │ │ │ return; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - //clear out the old grid │ │ │ │ │ - this.gratLayer.destroyFeatures(); │ │ │ │ │ + var curMapUnits = this.map.getUnits(); │ │ │ │ │ + var inches = OpenLayers.INCHES_PER_UNIT; │ │ │ │ │ │ │ │ │ │ - //get the projection objects required │ │ │ │ │ - var llProj = new OpenLayers.Projection("EPSG:4326"); │ │ │ │ │ - var mapProj = this.map.getProjectionObject(); │ │ │ │ │ - var mapRes = this.map.getResolution(); │ │ │ │ │ + // convert maxWidth to map units │ │ │ │ │ + var maxSizeData = this.maxWidth * res * inches[curMapUnits]; │ │ │ │ │ + var geodesicRatio = 1; │ │ │ │ │ + if (this.geodesic === true) { │ │ │ │ │ + var maxSizeGeodesic = (this.map.getGeodesicPixelSize().w || │ │ │ │ │ + 0.000001) * this.maxWidth; │ │ │ │ │ + var maxSizeKilometers = maxSizeData / inches["km"]; │ │ │ │ │ + geodesicRatio = maxSizeGeodesic / maxSizeKilometers; │ │ │ │ │ + maxSizeData *= geodesicRatio; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - //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; │ │ │ │ │ + // decide whether to use large or small scale units │ │ │ │ │ + var topUnits; │ │ │ │ │ + var bottomUnits; │ │ │ │ │ + if (maxSizeData > 100000) { │ │ │ │ │ + topUnits = this.topOutUnits; │ │ │ │ │ + bottomUnits = this.bottomOutUnits; │ │ │ │ │ + } else { │ │ │ │ │ + topUnits = this.topInUnits; │ │ │ │ │ + bottomUnits = this.bottomInUnits; │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - //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); │ │ │ │ │ + // and to map units units │ │ │ │ │ + var topMax = maxSizeData / inches[topUnits]; │ │ │ │ │ + var bottomMax = maxSizeData / inches[bottomUnits]; │ │ │ │ │ │ │ │ │ │ - /* 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; │ │ │ │ │ - } │ │ │ │ │ + // now trim this down to useful block length │ │ │ │ │ + var topRounded = this.getBarLen(topMax); │ │ │ │ │ + var bottomRounded = this.getBarLen(bottomMax); │ │ │ │ │ + │ │ │ │ │ + // and back to display units │ │ │ │ │ + topMax = topRounded / inches[curMapUnits] * inches[topUnits]; │ │ │ │ │ + bottomMax = bottomRounded / inches[curMapUnits] * inches[bottomUnits]; │ │ │ │ │ + │ │ │ │ │ + // and to pixel units │ │ │ │ │ + var topPx = topMax / res / geodesicRatio; │ │ │ │ │ + var bottomPx = bottomMax / res / geodesicRatio; │ │ │ │ │ + │ │ │ │ │ + // now set the pixel widths │ │ │ │ │ + // and the values inside them │ │ │ │ │ + │ │ │ │ │ + if (this.eBottom.style.visibility == "visible") { │ │ │ │ │ + this.eBottom.style.width = Math.round(bottomPx) + "px"; │ │ │ │ │ + this.eBottom.innerHTML = bottomRounded + " " + bottomUnits; │ │ │ │ │ } │ │ │ │ │ - //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? │ │ │ │ │ + if (this.eTop.style.visibility == "visible") { │ │ │ │ │ + this.eTop.style.width = Math.round(topPx) + "px"; │ │ │ │ │ + this.eTop.innerHTML = topRounded + " " + topUnits; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /* 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); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ScaleLine" │ │ │ │ │ +}); │ │ │ │ │ │ │ │ │ │ - //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; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/Split.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published 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/Path.js │ │ │ │ │ + * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.Split │ │ │ │ │ + * Acts as a split feature agent while editing vector features. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.Split = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * beforesplit - Triggered before a split occurs. Listeners receive an │ │ │ │ │ + * event object with *source* and *target* properties. │ │ │ │ │ + * split - Triggered when a split occurs. Listeners receive an event with │ │ │ │ │ + * an *original* property and a *features* property. The original │ │ │ │ │ + * is a reference to the target feature that the sketch or modified │ │ │ │ │ + * feature intersects. The features property is a list of all features │ │ │ │ │ + * that result from this single split. This event is triggered before │ │ │ │ │ + * the resulting features are added to the layer (while the layer still │ │ │ │ │ + * has a reference to the original). │ │ │ │ │ + * aftersplit - Triggered after all splits resulting from a single sketch │ │ │ │ │ + * or feature modification have occurred. The original features │ │ │ │ │ + * have been destroyed and features that result from the split │ │ │ │ │ + * have already been added to the layer. Listeners receive an event │ │ │ │ │ + * with a *source* and *features* property. The source references the │ │ │ │ │ + * sketch or modified feature used as a splitter. The features │ │ │ │ │ + * property is a list of all resulting features. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: layer │ │ │ │ │ + * {} The target layer with features to be split. │ │ │ │ │ + * Set at construction or after construction with . │ │ │ │ │ + */ │ │ │ │ │ + layer: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: source │ │ │ │ │ + * {} Optional source layer. Any newly created │ │ │ │ │ + * or modified features from this layer will be used to split features │ │ │ │ │ + * on the target layer. If not provided, a temporary sketch layer will │ │ │ │ │ + * be created. │ │ │ │ │ + */ │ │ │ │ │ + source: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: sourceOptions │ │ │ │ │ + * {Options} If a temporary sketch layer is created, these layer options │ │ │ │ │ + * will be applied. │ │ │ │ │ + */ │ │ │ │ │ + sourceOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: tolerance │ │ │ │ │ + * {Number} Distance between the calculated intersection and a vertex on │ │ │ │ │ + * the source geometry below which the existing vertex will be used │ │ │ │ │ + * for the split. Default is null. │ │ │ │ │ + */ │ │ │ │ │ + tolerance: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: edge │ │ │ │ │ + * {Boolean} Allow splits given intersection of edges only. Default is │ │ │ │ │ + * true. If false, a vertex on the source must be within the │ │ │ │ │ + * distance of the calculated intersection for a split │ │ │ │ │ + * to occur. │ │ │ │ │ + */ │ │ │ │ │ + edge: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: deferDelete │ │ │ │ │ + * {Boolean} Instead of removing features from the layer, set feature │ │ │ │ │ + * states of split features to DELETE. This assumes a save strategy │ │ │ │ │ + * or other component is in charge of removing features from the │ │ │ │ │ + * layer. Default is false. If false, split features will be │ │ │ │ │ + * immediately deleted from the layer. │ │ │ │ │ + */ │ │ │ │ │ + deferDelete: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: mutual │ │ │ │ │ + * {Boolean} If source and target layers are the same, split source │ │ │ │ │ + * features and target features where they intersect. Default is │ │ │ │ │ + * true. If false, only target features will be split. │ │ │ │ │ + */ │ │ │ │ │ + mutual: true, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: targetFilter │ │ │ │ │ + * {} Optional filter that will be evaluated │ │ │ │ │ + * to determine if a feature from the target layer is eligible for │ │ │ │ │ + * splitting. │ │ │ │ │ + */ │ │ │ │ │ + targetFilter: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: sourceFilter │ │ │ │ │ + * {} Optional filter that will be evaluated │ │ │ │ │ + * to determine if a feature from the source layer is eligible for │ │ │ │ │ + * splitting. │ │ │ │ │ + */ │ │ │ │ │ + sourceFilter: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: handler │ │ │ │ │ + * {} The temporary sketch handler created if │ │ │ │ │ + * no source layer is provided. │ │ │ │ │ + */ │ │ │ │ │ + handler: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.Split │ │ │ │ │ + * Creates a new split control. A control is constructed with a target │ │ │ │ │ + * layer and an optional source layer. While the control is active, │ │ │ │ │ + * creating new features or modifying existing features on the source │ │ │ │ │ + * layer will result in splitting any eligible features on the target │ │ │ │ │ + * layer. If no source layer is provided, a temporary sketch layer will │ │ │ │ │ + * be created to create lines for splitting features on the target. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An object containing all configuration properties for │ │ │ │ │ + * the control. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * layer - {} The target layer. Features from this │ │ │ │ │ + * layer will be split by new or modified features on the source layer │ │ │ │ │ + * or temporary sketch layer. │ │ │ │ │ + * source - {} Optional source layer. If provided │ │ │ │ │ + * newly created features or modified features will be used to split │ │ │ │ │ + * features on the target layer. If not provided, a temporary sketch │ │ │ │ │ + * layer will be created for drawing lines. │ │ │ │ │ + * tolerance - {Number} Optional value for the distance between a source │ │ │ │ │ + * vertex and the calculated intersection below which the split will │ │ │ │ │ + * occur at the vertex. │ │ │ │ │ + * edge - {Boolean} Allow splits given intersection of edges only. Default │ │ │ │ │ + * is true. If false, a vertex on the source must be within the │ │ │ │ │ + * distance of the calculated intersection for a split │ │ │ │ │ + * to occur. │ │ │ │ │ + * mutual - {Boolean} If source and target are the same, split source │ │ │ │ │ + * features and target features where they intersect. Default is │ │ │ │ │ + * true. If false, only target features will be split. │ │ │ │ │ + * targetFilter - {} Optional filter that will be evaluated │ │ │ │ │ + * to determine if a feature from the target layer is eligible for │ │ │ │ │ + * splitting. │ │ │ │ │ + * sourceFilter - {} Optional filter that will be evaluated │ │ │ │ │ + * to determine if a feature from the target layer is eligible for │ │ │ │ │ + * splitting. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.options = options || {}; // TODO: this could be done by the super │ │ │ │ │ + │ │ │ │ │ + // set the source layer if provided │ │ │ │ │ + if (this.options.source) { │ │ │ │ │ + this.setSource(this.options.source); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: setSource │ │ │ │ │ + * Set the source layer for edits layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} The new source layer layer. If │ │ │ │ │ + * null, a temporary sketch layer will be created. │ │ │ │ │ + */ │ │ │ │ │ + setSource: function(layer) { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + if (this.handler) { │ │ │ │ │ + this.handler.destroy(); │ │ │ │ │ + delete this.handler; │ │ │ │ │ + } │ │ │ │ │ + this.source = layer; │ │ │ │ │ + this.activate(); │ │ │ │ │ + } else { │ │ │ │ │ + this.source = layer; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Activate the control. Activating the control registers listeners for │ │ │ │ │ + * editing related events so that during feature creation and │ │ │ │ │ + * modification, features in the target will be considered for │ │ │ │ │ + * splitting. │ │ │ │ │ + */ │ │ │ │ │ + activate: function() { │ │ │ │ │ + var activated = OpenLayers.Control.prototype.activate.call(this); │ │ │ │ │ + if (activated) { │ │ │ │ │ + if (!this.source) { │ │ │ │ │ + if (!this.handler) { │ │ │ │ │ + this.handler = new OpenLayers.Handler.Path(this, { │ │ │ │ │ + done: function(geometry) { │ │ │ │ │ + this.onSketchComplete({ │ │ │ │ │ + feature: new OpenLayers.Feature.Vector(geometry) │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, { │ │ │ │ │ + layerOptions: this.sourceOptions │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ + this.handler.activate(); │ │ │ │ │ + } else if (this.source.events) { │ │ │ │ │ + this.source.events.on({ │ │ │ │ │ + sketchcomplete: this.onSketchComplete, │ │ │ │ │ + afterfeaturemodified: this.afterFeatureModified, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - 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)); │ │ │ │ │ + } │ │ │ │ │ + return activated; │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the control. Deactivating the control unregisters listeners │ │ │ │ │ + * so feature editing may proceed without engaging the split agent. │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = OpenLayers.Control.prototype.deactivate.call(this); │ │ │ │ │ + if (deactivated) { │ │ │ │ │ + if (this.source && this.source.events) { │ │ │ │ │ + this.source.events.un({ │ │ │ │ │ + sketchcomplete: this.onSketchComplete, │ │ │ │ │ + afterfeaturemodified: this.afterFeatureModified, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - var geom = new OpenLayers.Geometry.LineString(pointList); │ │ │ │ │ - lines.push(new OpenLayers.Feature.Vector(geom)); │ │ │ │ │ } │ │ │ │ │ + return deactivated; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - //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; │ │ │ │ │ + /** │ │ │ │ │ + * Method: onSketchComplete │ │ │ │ │ + * Registered as a listener for the sketchcomplete event on the editable │ │ │ │ │ + * layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Object} The sketch complete event. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} Stop the sketch from being added to the layer (it has been │ │ │ │ │ + * split). │ │ │ │ │ + */ │ │ │ │ │ + onSketchComplete: function(event) { │ │ │ │ │ + this.feature = null; │ │ │ │ │ + return !this.considerSplit(event.feature); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: afterFeatureModified │ │ │ │ │ + * Registered as a listener for the afterfeaturemodified event on the │ │ │ │ │ + * editable layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * event - {Object} The after feature modified event. │ │ │ │ │ + */ │ │ │ │ │ + afterFeatureModified: function(event) { │ │ │ │ │ + if (event.modified) { │ │ │ │ │ + var feature = event.feature; │ │ │ │ │ + if (typeof feature.geometry.split === "function") { │ │ │ │ │ + this.feature = event.feature; │ │ │ │ │ + this.considerSplit(event.feature); │ │ │ │ │ } │ │ │ │ │ - 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; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeByGeometry │ │ │ │ │ + * Remove a feature from a list based on the given geometry. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * features - {Array()} A list of features. │ │ │ │ │ + * geometry - {} A geometry. │ │ │ │ │ + */ │ │ │ │ │ + removeByGeometry: function(features, geometry) { │ │ │ │ │ + for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + if (features[i].geometry === geometry) { │ │ │ │ │ + features.splice(i, 1); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: isEligible │ │ │ │ │ + * Test if a target feature is eligible for splitting. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * target - {} The target feature. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The target is eligible for splitting. │ │ │ │ │ + */ │ │ │ │ │ + isEligible: function(target) { │ │ │ │ │ + if (!target.geometry) { │ │ │ │ │ + return false; │ │ │ │ │ + } else { │ │ │ │ │ + return ( │ │ │ │ │ + target.state !== OpenLayers.State.DELETE │ │ │ │ │ + ) && ( │ │ │ │ │ + typeof target.geometry.split === "function" │ │ │ │ │ + ) && ( │ │ │ │ │ + this.feature !== target │ │ │ │ │ + ) && ( │ │ │ │ │ + !this.targetFilter || │ │ │ │ │ + this.targetFilter.evaluate(target.attributes) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: considerSplit │ │ │ │ │ + * Decide whether or not to split target features with the supplied │ │ │ │ │ + * feature. If is true, both the source and target features │ │ │ │ │ + * will be split if eligible. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The newly created or modified │ │ │ │ │ + * feature. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The supplied feature was split (and destroyed). │ │ │ │ │ + */ │ │ │ │ │ + considerSplit: function(feature) { │ │ │ │ │ + var sourceSplit = false; │ │ │ │ │ + var targetSplit = false; │ │ │ │ │ + if (!this.sourceFilter || │ │ │ │ │ + this.sourceFilter.evaluate(feature.attributes)) { │ │ │ │ │ + var features = this.layer && this.layer.features || []; │ │ │ │ │ + var target, results, proceed; │ │ │ │ │ + var additions = [], │ │ │ │ │ + removals = []; │ │ │ │ │ + var mutual = (this.layer === this.source) && this.mutual; │ │ │ │ │ + var options = { │ │ │ │ │ + edge: this.edge, │ │ │ │ │ + tolerance: this.tolerance, │ │ │ │ │ + mutual: mutual │ │ │ │ │ + }; │ │ │ │ │ + var sourceParts = [feature.geometry]; │ │ │ │ │ + var targetFeature, targetParts; │ │ │ │ │ + var source, parts; │ │ │ │ │ + for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + targetFeature = features[i]; │ │ │ │ │ + if (this.isEligible(targetFeature)) { │ │ │ │ │ + targetParts = [targetFeature.geometry]; │ │ │ │ │ + // work through source geoms - this array may change │ │ │ │ │ + for (var j = 0; j < sourceParts.length; ++j) { │ │ │ │ │ + source = sourceParts[j]; │ │ │ │ │ + // work through target parts - this array may change │ │ │ │ │ + for (var k = 0; k < targetParts.length; ++k) { │ │ │ │ │ + target = targetParts[k]; │ │ │ │ │ + if (source.getBounds().intersectsBounds(target.getBounds())) { │ │ │ │ │ + results = source.split(target, options); │ │ │ │ │ + if (results) { │ │ │ │ │ + proceed = this.events.triggerEvent( │ │ │ │ │ + "beforesplit", { │ │ │ │ │ + source: feature, │ │ │ │ │ + target: targetFeature │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + if (proceed !== false) { │ │ │ │ │ + if (mutual) { │ │ │ │ │ + parts = results[0]; │ │ │ │ │ + // handle parts that result from source splitting │ │ │ │ │ + if (parts.length > 1) { │ │ │ │ │ + // splice in new source parts │ │ │ │ │ + parts.unshift(j, 1); // add args for splice below │ │ │ │ │ + Array.prototype.splice.apply(sourceParts, parts); │ │ │ │ │ + j += parts.length - 3; │ │ │ │ │ + } │ │ │ │ │ + results = results[1]; │ │ │ │ │ + } │ │ │ │ │ + // handle parts that result from target splitting │ │ │ │ │ + if (results.length > 1) { │ │ │ │ │ + // splice in new target parts │ │ │ │ │ + results.unshift(k, 1); // add args for splice below │ │ │ │ │ + Array.prototype.splice.apply(targetParts, results); │ │ │ │ │ + k += results.length - 3; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (targetParts && targetParts.length > 1) { │ │ │ │ │ + this.geomsToFeatures(targetFeature, targetParts); │ │ │ │ │ + this.events.triggerEvent("split", { │ │ │ │ │ + original: targetFeature, │ │ │ │ │ + features: targetParts │ │ │ │ │ + }); │ │ │ │ │ + Array.prototype.push.apply(additions, targetParts); │ │ │ │ │ + removals.push(targetFeature); │ │ │ │ │ + targetSplit = true; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - 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)); │ │ │ │ │ + if (sourceParts && sourceParts.length > 1) { │ │ │ │ │ + this.geomsToFeatures(feature, sourceParts); │ │ │ │ │ + this.events.triggerEvent("split", { │ │ │ │ │ + original: feature, │ │ │ │ │ + features: sourceParts │ │ │ │ │ + }); │ │ │ │ │ + Array.prototype.push.apply(additions, sourceParts); │ │ │ │ │ + removals.push(feature); │ │ │ │ │ + sourceSplit = true; │ │ │ │ │ + } │ │ │ │ │ + if (sourceSplit || targetSplit) { │ │ │ │ │ + // remove and add feature events are suppressed │ │ │ │ │ + // listen for split event on this control instead │ │ │ │ │ + if (this.deferDelete) { │ │ │ │ │ + // Set state instead of removing. Take care to avoid │ │ │ │ │ + // setting delete for features that have not yet been │ │ │ │ │ + // inserted - those should be destroyed immediately. │ │ │ │ │ + var feat, destroys = []; │ │ │ │ │ + for (var i = 0, len = removals.length; i < len; ++i) { │ │ │ │ │ + feat = removals[i]; │ │ │ │ │ + if (feat.state === OpenLayers.State.INSERT) { │ │ │ │ │ + destroys.push(feat); │ │ │ │ │ + } else { │ │ │ │ │ + feat.state = OpenLayers.State.DELETE; │ │ │ │ │ + this.layer.drawFeature(feat); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.layer.destroyFeatures(destroys, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + for (var i = 0, len = additions.length; i < len; ++i) { │ │ │ │ │ + additions[i].state = OpenLayers.State.INSERT; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + this.layer.destroyFeatures(removals, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + this.layer.addFeatures(additions, { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.events.triggerEvent("aftersplit", { │ │ │ │ │ + source: feature, │ │ │ │ │ + features: additions │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - var geom = new OpenLayers.Geometry.LineString(pointList); │ │ │ │ │ - lines.push(new OpenLayers.Feature.Vector(geom)); │ │ │ │ │ } │ │ │ │ │ - this.gratLayer.addFeatures(lines); │ │ │ │ │ + return sourceSplit; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Graticule" │ │ │ │ │ -}); │ │ │ │ │ + /** │ │ │ │ │ + * Method: geomsToFeatures │ │ │ │ │ + * Create new features given a template feature and a list of geometries. │ │ │ │ │ + * The list of geometries is modified in place. The result will be │ │ │ │ │ + * a list of new features. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * feature - {} The feature to be cloned. │ │ │ │ │ + * geoms - {Array()} List of goemetries. This will │ │ │ │ │ + * become a list of new features. │ │ │ │ │ + */ │ │ │ │ │ + geomsToFeatures: function(feature, geoms) { │ │ │ │ │ + var clone = feature.clone(); │ │ │ │ │ + delete clone.geometry; │ │ │ │ │ + var newFeature; │ │ │ │ │ + for (var i = 0, len = geoms.length; i < len; ++i) { │ │ │ │ │ + // turn results list from geoms to features │ │ │ │ │ + newFeature = clone.clone(); │ │ │ │ │ + newFeature.geometry = geoms[i]; │ │ │ │ │ + newFeature.state = OpenLayers.State.INSERT; │ │ │ │ │ + geoms[i] = newFeature; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Clean up the control. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.deactivate(); // TODO: this should be handled by the super │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Control.prototype.destroy.call(this); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Split" │ │ │ │ │ +}); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ OpenLayers/Handler/Feature.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ @@ -51666,1456 +45829,14 @@ │ │ │ │ │ this.map.getLayerIndex(this.layer)); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Handler.Feature" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/Vector/RootContainer.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Layer.Vector.RootContainer │ │ │ │ │ - * A special layer type to combine multiple vector layers inside a single │ │ │ │ │ - * renderer root container. This class is not supposed to be instantiated │ │ │ │ │ - * from user space, it is a helper class for controls that require event │ │ │ │ │ - * processing for multiple vector layers. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer.Vector.RootContainer = OpenLayers.Class(OpenLayers.Layer.Vector, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: displayInLayerSwitcher │ │ │ │ │ - * Set to false for this layer type │ │ │ │ │ - */ │ │ │ │ │ - displayInLayerSwitcher: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: layers │ │ │ │ │ - * Layers that are attached to this container. Required config option. │ │ │ │ │ - */ │ │ │ │ │ - layers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.Vector.RootContainer │ │ │ │ │ - * Create a new root container for multiple vector layer. This constructor │ │ │ │ │ - * is not supposed to be used from user space, it is only to be used by │ │ │ │ │ - * controls that need feature selection across multiple vector layers. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} A name for the layer │ │ │ │ │ - * options - {Object} Optional object with non-default properties to set on │ │ │ │ │ - * the layer. │ │ │ │ │ - * │ │ │ │ │ - * Required options properties: │ │ │ │ │ - * layers - {Array()} The layers managed by this │ │ │ │ │ - * container │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A new vector layer root │ │ │ │ │ - * container │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: display │ │ │ │ │ - */ │ │ │ │ │ - display: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: getFeatureFromEvent │ │ │ │ │ - * walk through the layers to find the feature returned by the event │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} event object with a feature property │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - getFeatureFromEvent: function(evt) { │ │ │ │ │ - var layers = this.layers; │ │ │ │ │ - var feature; │ │ │ │ │ - for (var i = 0; i < layers.length; i++) { │ │ │ │ │ - feature = layers[i].getFeatureFromEvent(evt); │ │ │ │ │ - if (feature) { │ │ │ │ │ - return feature; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.Vector.prototype.setMap.apply(this, arguments); │ │ │ │ │ - this.collectRoots(); │ │ │ │ │ - map.events.register("changelayer", this, this.handleChangeLayer); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: removeMap │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - map.events.unregister("changelayer", this, this.handleChangeLayer); │ │ │ │ │ - this.resetRoots(); │ │ │ │ │ - OpenLayers.Layer.Vector.prototype.removeMap.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: collectRoots │ │ │ │ │ - * Collects the root nodes of all layers this control is configured with │ │ │ │ │ - * and moveswien the nodes to this control's layer │ │ │ │ │ - */ │ │ │ │ │ - collectRoots: function() { │ │ │ │ │ - var layer; │ │ │ │ │ - // walk through all map layers, because we want to keep the order │ │ │ │ │ - for (var i = 0; i < this.map.layers.length; ++i) { │ │ │ │ │ - layer = this.map.layers[i]; │ │ │ │ │ - if (OpenLayers.Util.indexOf(this.layers, layer) != -1) { │ │ │ │ │ - layer.renderer.moveRoot(this.renderer); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: resetRoots │ │ │ │ │ - * Resets the root nodes back into the layers they belong to. │ │ │ │ │ - */ │ │ │ │ │ - resetRoots: function() { │ │ │ │ │ - var layer; │ │ │ │ │ - for (var i = 0; i < this.layers.length; ++i) { │ │ │ │ │ - layer = this.layers[i]; │ │ │ │ │ - if (this.renderer && layer.renderer.getRenderLayerId() == this.id) { │ │ │ │ │ - this.renderer.moveRoot(layer.renderer); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: handleChangeLayer │ │ │ │ │ - * Event handler for the map's changelayer event. We need to rebuild │ │ │ │ │ - * this container's layer dom if order of one of its layers changes. │ │ │ │ │ - * This handler is added with the setMap method, and removed with the │ │ │ │ │ - * removeMap method. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Object} │ │ │ │ │ - */ │ │ │ │ │ - handleChangeLayer: function(evt) { │ │ │ │ │ - var layer = evt.layer; │ │ │ │ │ - if (evt.property == "order" && │ │ │ │ │ - OpenLayers.Util.indexOf(this.layers, layer) != -1) { │ │ │ │ │ - this.resetRoots(); │ │ │ │ │ - this.collectRoots(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.Vector.RootContainer" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/SelectFeature.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ - * @requires OpenLayers/Handler/Feature.js │ │ │ │ │ - * @requires OpenLayers/Layer/Vector/RootContainer.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.SelectFeature │ │ │ │ │ - * The SelectFeature control selects vector features from a given layer on │ │ │ │ │ - * click or hover. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * beforefeaturehighlighted - Triggered before a feature is highlighted │ │ │ │ │ - * featurehighlighted - Triggered when a feature is highlighted │ │ │ │ │ - * featureunhighlighted - Triggered when a feature is unhighlighted │ │ │ │ │ - * boxselectionstart - Triggered before box selection starts │ │ │ │ │ - * boxselectionend - Triggered after box selection ends │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: multipleKey │ │ │ │ │ - * {String} An event modifier ('altKey' or 'shiftKey') that temporarily sets │ │ │ │ │ - * the property to true. Default is null. │ │ │ │ │ - */ │ │ │ │ │ - multipleKey: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: toggleKey │ │ │ │ │ - * {String} An event modifier ('altKey' or 'shiftKey') that temporarily sets │ │ │ │ │ - * the property to true. Default is null. │ │ │ │ │ - */ │ │ │ │ │ - toggleKey: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: multiple │ │ │ │ │ - * {Boolean} Allow selection of multiple geometries. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - multiple: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: clickout │ │ │ │ │ - * {Boolean} Unselect features when clicking outside any feature. │ │ │ │ │ - * Default is true. │ │ │ │ │ - */ │ │ │ │ │ - clickout: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: toggle │ │ │ │ │ - * {Boolean} Unselect a selected feature on click. Default is false. Only │ │ │ │ │ - * has meaning if hover is false. │ │ │ │ │ - */ │ │ │ │ │ - toggle: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: hover │ │ │ │ │ - * {Boolean} Select on mouse over and deselect on mouse out. If true, this │ │ │ │ │ - * ignores clicks and only listens to mouse moves. │ │ │ │ │ - */ │ │ │ │ │ - hover: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: highlightOnly │ │ │ │ │ - * {Boolean} If true do not actually select features (that is place them in │ │ │ │ │ - * the layer's selected features array), just highlight them. This property │ │ │ │ │ - * has no effect if hover is false. Defaults to false. │ │ │ │ │ - */ │ │ │ │ │ - highlightOnly: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: box │ │ │ │ │ - * {Boolean} Allow feature selection by drawing a box. │ │ │ │ │ - */ │ │ │ │ │ - box: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: onBeforeSelect │ │ │ │ │ - * {Function} Optional function to be called before a feature is selected. │ │ │ │ │ - * The function should expect to be called with a feature. │ │ │ │ │ - */ │ │ │ │ │ - onBeforeSelect: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onSelect │ │ │ │ │ - * {Function} Optional function to be called when a feature is selected. │ │ │ │ │ - * The function should expect to be called with a feature. │ │ │ │ │ - */ │ │ │ │ │ - onSelect: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: onUnselect │ │ │ │ │ - * {Function} Optional function to be called when a feature is unselected. │ │ │ │ │ - * The function should expect to be called with a feature. │ │ │ │ │ - */ │ │ │ │ │ - onUnselect: function() {}, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: scope │ │ │ │ │ - * {Object} The scope to use with the onBeforeSelect, onSelect, onUnselect │ │ │ │ │ - * callbacks. If null the scope will be this control. │ │ │ │ │ - */ │ │ │ │ │ - scope: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geometryTypes │ │ │ │ │ - * {Array(String)} To restrict selecting to a limited set of geometry types, │ │ │ │ │ - * send a list of strings corresponding to the geometry class names. │ │ │ │ │ - */ │ │ │ │ │ - geometryTypes: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layer │ │ │ │ │ - * {} The vector layer with a common renderer │ │ │ │ │ - * root for all layers this control is configured with (if an array of │ │ │ │ │ - * layers was passed to the constructor), or the vector layer the control │ │ │ │ │ - * was configured with (if a single layer was passed to the constructor). │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: layers │ │ │ │ │ - * {Array()} The layers this control will work on, │ │ │ │ │ - * or null if the control was configured with a single layer │ │ │ │ │ - */ │ │ │ │ │ - layers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: callbacks │ │ │ │ │ - * {Object} The functions that are sent to the handlers.feature for callback │ │ │ │ │ - */ │ │ │ │ │ - callbacks: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: selectStyle │ │ │ │ │ - * {Object} Hash of styles │ │ │ │ │ - */ │ │ │ │ │ - selectStyle: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: renderIntent │ │ │ │ │ - * {String} key used to retrieve the select style from the layer's │ │ │ │ │ - * style map. │ │ │ │ │ - */ │ │ │ │ │ - renderIntent: "select", │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: handlers │ │ │ │ │ - * {Object} Object with references to multiple │ │ │ │ │ - * instances. │ │ │ │ │ - */ │ │ │ │ │ - handlers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.SelectFeature │ │ │ │ │ - * Create a new control for selecting features. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layers - {}, or an array of vector layers. The │ │ │ │ │ - * layer(s) this control will select features from. │ │ │ │ │ - * options - {Object} │ │ │ │ │ - */ │ │ │ │ │ - initialize: function(layers, options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ - │ │ │ │ │ - if (this.scope === null) { │ │ │ │ │ - this.scope = this; │ │ │ │ │ - } │ │ │ │ │ - this.initLayer(layers); │ │ │ │ │ - var callbacks = { │ │ │ │ │ - click: this.clickFeature, │ │ │ │ │ - clickout: this.clickoutFeature │ │ │ │ │ - }; │ │ │ │ │ - if (this.hover) { │ │ │ │ │ - callbacks.over = this.overFeature; │ │ │ │ │ - callbacks.out = this.outFeature; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.callbacks = OpenLayers.Util.extend(callbacks, this.callbacks); │ │ │ │ │ - this.handlers = { │ │ │ │ │ - feature: new OpenLayers.Handler.Feature( │ │ │ │ │ - this, this.layer, this.callbacks, { │ │ │ │ │ - geometryTypes: this.geometryTypes │ │ │ │ │ - } │ │ │ │ │ - ) │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - if (this.box) { │ │ │ │ │ - this.handlers.box = new OpenLayers.Handler.Box( │ │ │ │ │ - this, { │ │ │ │ │ - done: this.selectBox │ │ │ │ │ - }, { │ │ │ │ │ - boxDivClassName: "olHandlerBoxSelectFeature" │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: initLayer │ │ │ │ │ - * Assign the layer property. If layers is an array, we need to use │ │ │ │ │ - * a RootContainer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layers - {}, or an array of vector layers. │ │ │ │ │ - */ │ │ │ │ │ - initLayer: function(layers) { │ │ │ │ │ - if (OpenLayers.Util.isArray(layers)) { │ │ │ │ │ - this.layers = layers; │ │ │ │ │ - this.layer = new OpenLayers.Layer.Vector.RootContainer( │ │ │ │ │ - this.id + "_container", { │ │ │ │ │ - layers: layers │ │ │ │ │ - } │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - this.layer = layers; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - if (this.active && this.layers) { │ │ │ │ │ - this.map.removeLayer(this.layer); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - if (this.layers) { │ │ │ │ │ - this.layer.destroy(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activates the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The control was effectively activated. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (!this.active) { │ │ │ │ │ - if (this.layers) { │ │ │ │ │ - this.map.addLayer(this.layer); │ │ │ │ │ - } │ │ │ │ │ - this.handlers.feature.activate(); │ │ │ │ │ - if (this.box && this.handlers.box) { │ │ │ │ │ - this.handlers.box.activate(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Control.prototype.activate.apply( │ │ │ │ │ - this, arguments │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivates the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The control was effectively deactivated. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - this.handlers.feature.deactivate(); │ │ │ │ │ - if (this.handlers.box) { │ │ │ │ │ - this.handlers.box.deactivate(); │ │ │ │ │ - } │ │ │ │ │ - if (this.layers) { │ │ │ │ │ - this.map.removeLayer(this.layer); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Control.prototype.deactivate.apply( │ │ │ │ │ - this, arguments │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: unselectAll │ │ │ │ │ - * Unselect all selected features. To unselect all except for a single │ │ │ │ │ - * feature, set the options.except property to the feature. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} Optional configuration object. │ │ │ │ │ - */ │ │ │ │ │ - unselectAll: function(options) { │ │ │ │ │ - // we'll want an option to supress notification here │ │ │ │ │ - var layers = this.layers || [this.layer], │ │ │ │ │ - layer, feature, l, numExcept; │ │ │ │ │ - for (l = 0; l < layers.length; ++l) { │ │ │ │ │ - layer = layers[l]; │ │ │ │ │ - numExcept = 0; │ │ │ │ │ - //layer.selectedFeatures is null when layer is destroyed and │ │ │ │ │ - //one of it's preremovelayer listener calls setLayer │ │ │ │ │ - //with another layer on this control │ │ │ │ │ - if (layer.selectedFeatures != null) { │ │ │ │ │ - while (layer.selectedFeatures.length > numExcept) { │ │ │ │ │ - feature = layer.selectedFeatures[numExcept]; │ │ │ │ │ - if (!options || options.except != feature) { │ │ │ │ │ - this.unselect(feature); │ │ │ │ │ - } else { │ │ │ │ │ - ++numExcept; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clickFeature │ │ │ │ │ - * Called on click in a feature │ │ │ │ │ - * Only responds if this.hover is false. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - clickFeature: function(feature) { │ │ │ │ │ - if (!this.hover) { │ │ │ │ │ - var selected = (OpenLayers.Util.indexOf( │ │ │ │ │ - feature.layer.selectedFeatures, feature) > -1); │ │ │ │ │ - if (selected) { │ │ │ │ │ - if (this.toggleSelect()) { │ │ │ │ │ - this.unselect(feature); │ │ │ │ │ - } else if (!this.multipleSelect()) { │ │ │ │ │ - this.unselectAll({ │ │ │ │ │ - except: feature │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - if (!this.multipleSelect()) { │ │ │ │ │ - this.unselectAll({ │ │ │ │ │ - except: feature │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - this.select(feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: multipleSelect │ │ │ │ │ - * Allow for multiple selected features based on property and │ │ │ │ │ - * event modifier. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Allow for multiple selected features. │ │ │ │ │ - */ │ │ │ │ │ - multipleSelect: function() { │ │ │ │ │ - return this.multiple || (this.handlers.feature.evt && │ │ │ │ │ - this.handlers.feature.evt[this.multipleKey]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: toggleSelect │ │ │ │ │ - * Event should toggle the selected state of a feature based on │ │ │ │ │ - * property and event modifier. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Toggle the selected state of a feature. │ │ │ │ │ - */ │ │ │ │ │ - toggleSelect: function() { │ │ │ │ │ - return this.toggle || (this.handlers.feature.evt && │ │ │ │ │ - this.handlers.feature.evt[this.toggleKey]); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: clickoutFeature │ │ │ │ │ - * Called on click outside a previously clicked (selected) feature. │ │ │ │ │ - * Only responds if this.hover is false. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - clickoutFeature: function(feature) { │ │ │ │ │ - if (!this.hover && this.clickout) { │ │ │ │ │ - this.unselectAll(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: overFeature │ │ │ │ │ - * Called on over a feature. │ │ │ │ │ - * Only responds if this.hover is true. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - overFeature: function(feature) { │ │ │ │ │ - var layer = feature.layer; │ │ │ │ │ - if (this.hover) { │ │ │ │ │ - if (this.highlightOnly) { │ │ │ │ │ - this.highlight(feature); │ │ │ │ │ - } else if (OpenLayers.Util.indexOf( │ │ │ │ │ - layer.selectedFeatures, feature) == -1) { │ │ │ │ │ - this.select(feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: outFeature │ │ │ │ │ - * Called on out of a selected feature. │ │ │ │ │ - * Only responds if this.hover is true. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - outFeature: function(feature) { │ │ │ │ │ - if (this.hover) { │ │ │ │ │ - if (this.highlightOnly) { │ │ │ │ │ - // we do nothing if we're not the last highlighter of the │ │ │ │ │ - // feature │ │ │ │ │ - if (feature._lastHighlighter == this.id) { │ │ │ │ │ - // if another select control had highlighted the feature before │ │ │ │ │ - // we did it ourself then we use that control to highlight the │ │ │ │ │ - // feature as it was before we highlighted it, else we just │ │ │ │ │ - // unhighlight it │ │ │ │ │ - if (feature._prevHighlighter && │ │ │ │ │ - feature._prevHighlighter != this.id) { │ │ │ │ │ - delete feature._lastHighlighter; │ │ │ │ │ - var control = this.map.getControl( │ │ │ │ │ - feature._prevHighlighter); │ │ │ │ │ - if (control) { │ │ │ │ │ - control.highlight(feature); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - this.unhighlight(feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - this.unselect(feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: highlight │ │ │ │ │ - * Redraw feature with the select style. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - highlight: function(feature) { │ │ │ │ │ - var layer = feature.layer; │ │ │ │ │ - var cont = this.events.triggerEvent("beforefeaturehighlighted", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - if (cont !== false) { │ │ │ │ │ - feature._prevHighlighter = feature._lastHighlighter; │ │ │ │ │ - feature._lastHighlighter = this.id; │ │ │ │ │ - var style = this.selectStyle || this.renderIntent; │ │ │ │ │ - layer.drawFeature(feature, style); │ │ │ │ │ - this.events.triggerEvent("featurehighlighted", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: unhighlight │ │ │ │ │ - * Redraw feature with the "default" style │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - unhighlight: function(feature) { │ │ │ │ │ - var layer = feature.layer; │ │ │ │ │ - // three cases: │ │ │ │ │ - // 1. there's no other highlighter, in that case _prev is undefined, │ │ │ │ │ - // and we just need to undef _last │ │ │ │ │ - // 2. another control highlighted the feature after we did it, in │ │ │ │ │ - // that case _last references this other control, and we just │ │ │ │ │ - // need to undef _prev │ │ │ │ │ - // 3. another control highlighted the feature before we did it, in │ │ │ │ │ - // that case _prev references this other control, and we need to │ │ │ │ │ - // set _last to _prev and undef _prev │ │ │ │ │ - if (feature._prevHighlighter == undefined) { │ │ │ │ │ - delete feature._lastHighlighter; │ │ │ │ │ - } else if (feature._prevHighlighter == this.id) { │ │ │ │ │ - delete feature._prevHighlighter; │ │ │ │ │ - } else { │ │ │ │ │ - feature._lastHighlighter = feature._prevHighlighter; │ │ │ │ │ - delete feature._prevHighlighter; │ │ │ │ │ - } │ │ │ │ │ - layer.drawFeature(feature, feature.style || feature.layer.style || │ │ │ │ │ - "default"); │ │ │ │ │ - this.events.triggerEvent("featureunhighlighted", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: select │ │ │ │ │ - * Add feature to the layer's selectedFeature array, render the feature as │ │ │ │ │ - * selected, and call the onSelect function. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - select: function(feature) { │ │ │ │ │ - var cont = this.onBeforeSelect.call(this.scope, feature); │ │ │ │ │ - var layer = feature.layer; │ │ │ │ │ - if (cont !== false) { │ │ │ │ │ - cont = layer.events.triggerEvent("beforefeatureselected", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - if (cont !== false) { │ │ │ │ │ - layer.selectedFeatures.push(feature); │ │ │ │ │ - this.highlight(feature); │ │ │ │ │ - // if the feature handler isn't involved in the feature │ │ │ │ │ - // selection (because the box handler is used or the │ │ │ │ │ - // feature is selected programatically) we fake the │ │ │ │ │ - // feature handler to allow unselecting on click │ │ │ │ │ - if (!this.handlers.feature.lastFeature) { │ │ │ │ │ - this.handlers.feature.lastFeature = layer.selectedFeatures[0]; │ │ │ │ │ - } │ │ │ │ │ - layer.events.triggerEvent("featureselected", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - this.onSelect.call(this.scope, feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: unselect │ │ │ │ │ - * Remove feature from the layer's selectedFeature array, render the feature as │ │ │ │ │ - * normal, and call the onUnselect function. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - unselect: function(feature) { │ │ │ │ │ - var layer = feature.layer; │ │ │ │ │ - // Store feature style for restoration later │ │ │ │ │ - this.unhighlight(feature); │ │ │ │ │ - OpenLayers.Util.removeItem(layer.selectedFeatures, feature); │ │ │ │ │ - layer.events.triggerEvent("featureunselected", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - this.onUnselect.call(this.scope, feature); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: selectBox │ │ │ │ │ - * Callback from the handlers.box set up when selection is true │ │ │ │ │ - * on. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * position - { || } │ │ │ │ │ - */ │ │ │ │ │ - selectBox: function(position) { │ │ │ │ │ - if (position instanceof OpenLayers.Bounds) { │ │ │ │ │ - var minXY = this.map.getLonLatFromPixel({ │ │ │ │ │ - x: position.left, │ │ │ │ │ - y: position.bottom │ │ │ │ │ - }); │ │ │ │ │ - var maxXY = this.map.getLonLatFromPixel({ │ │ │ │ │ - x: position.right, │ │ │ │ │ - y: position.top │ │ │ │ │ - }); │ │ │ │ │ - var bounds = new OpenLayers.Bounds( │ │ │ │ │ - minXY.lon, minXY.lat, maxXY.lon, maxXY.lat │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - // if multiple is false, first deselect currently selected features │ │ │ │ │ - if (!this.multipleSelect()) { │ │ │ │ │ - this.unselectAll(); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // because we're using a box, we consider we want multiple selection │ │ │ │ │ - var prevMultiple = this.multiple; │ │ │ │ │ - this.multiple = true; │ │ │ │ │ - var layers = this.layers || [this.layer]; │ │ │ │ │ - this.events.triggerEvent("boxselectionstart", { │ │ │ │ │ - layers: layers │ │ │ │ │ - }); │ │ │ │ │ - var layer; │ │ │ │ │ - for (var l = 0; l < layers.length; ++l) { │ │ │ │ │ - layer = layers[l]; │ │ │ │ │ - for (var i = 0, len = layer.features.length; i < len; ++i) { │ │ │ │ │ - var feature = layer.features[i]; │ │ │ │ │ - // check if the feature is displayed │ │ │ │ │ - if (!feature.getVisibility()) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (this.geometryTypes == null || OpenLayers.Util.indexOf( │ │ │ │ │ - this.geometryTypes, feature.geometry.CLASS_NAME) > -1) { │ │ │ │ │ - if (bounds.toGeometry().intersects(feature.geometry)) { │ │ │ │ │ - if (OpenLayers.Util.indexOf(layer.selectedFeatures, feature) == -1) { │ │ │ │ │ - this.select(feature); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - this.multiple = prevMultiple; │ │ │ │ │ - this.events.triggerEvent("boxselectionend", { │ │ │ │ │ - layers: layers │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.handlers.feature.setMap(map); │ │ │ │ │ - if (this.box) { │ │ │ │ │ - this.handlers.box.setMap(map); │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: setLayer │ │ │ │ │ - * Attach a new layer to the control, overriding any existing layers. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layers - Array of {} or a single │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - setLayer: function(layers) { │ │ │ │ │ - var isActive = this.active; │ │ │ │ │ - this.unselectAll(); │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - if (this.layers) { │ │ │ │ │ - this.layer.destroy(); │ │ │ │ │ - this.layers = null; │ │ │ │ │ - } │ │ │ │ │ - this.initLayer(layers); │ │ │ │ │ - this.handlers.feature.layer = this.layer; │ │ │ │ │ - if (isActive) { │ │ │ │ │ - this.activate(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.SelectFeature" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/Geolocate.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - * @requires OpenLayers/Projection.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.Geolocate │ │ │ │ │ - * The Geolocate control wraps w3c geolocation API into control that can be │ │ │ │ │ - * bound to a map, and generate events on location update │ │ │ │ │ - * │ │ │ │ │ - * To use this control requires to load the proj4js library if the projection │ │ │ │ │ - * of the map is not EPSG:4326 or EPSG:900913. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.Geolocate = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ - * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * locationupdated - Triggered when browser return a new position. Listeners will │ │ │ │ │ - * receive an object with a 'position' property which is the browser.geolocation.position │ │ │ │ │ - * native object, as well as a 'point' property which is the location transformed in the │ │ │ │ │ - * current map projection. │ │ │ │ │ - * locationfailed - Triggered when geolocation has failed │ │ │ │ │ - * locationuncapable - Triggered when control is activated on a browser │ │ │ │ │ - * which doesn't support geolocation │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: geolocation │ │ │ │ │ - * {Object} The geolocation engine, as a property to be possibly mocked. │ │ │ │ │ - * This is set lazily to avoid a memory leak in IE9. │ │ │ │ │ - */ │ │ │ │ │ - geolocation: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: available │ │ │ │ │ - * {Boolean} The navigator.geolocation object is available. │ │ │ │ │ - */ │ │ │ │ │ - available: ('geolocation' in navigator), │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: bind │ │ │ │ │ - * {Boolean} If true, map center will be set on location update. │ │ │ │ │ - */ │ │ │ │ │ - bind: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: watch │ │ │ │ │ - * {Boolean} If true, position will be update regularly. │ │ │ │ │ - */ │ │ │ │ │ - watch: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: geolocationOptions │ │ │ │ │ - * {Object} Options to pass to the navigator's geolocation API. See │ │ │ │ │ - * . No specific │ │ │ │ │ - * option is passed to the geolocation API by default. │ │ │ │ │ - */ │ │ │ │ │ - geolocationOptions: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.Geolocate │ │ │ │ │ - * Create a new control to deal with browser geolocation API │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activates the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The control was effectively activated. │ │ │ │ │ - */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (this.available && !this.geolocation) { │ │ │ │ │ - // set lazily to avoid IE9 memory leak │ │ │ │ │ - this.geolocation = navigator.geolocation; │ │ │ │ │ - } │ │ │ │ │ - if (!this.geolocation) { │ │ │ │ │ - this.events.triggerEvent("locationuncapable"); │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - if (this.watch) { │ │ │ │ │ - this.watchId = this.geolocation.watchPosition( │ │ │ │ │ - OpenLayers.Function.bind(this.geolocate, this), │ │ │ │ │ - OpenLayers.Function.bind(this.failure, this), │ │ │ │ │ - this.geolocationOptions │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - this.getCurrentLocation(); │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivates the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The control was effectively deactivated. │ │ │ │ │ - */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.active && this.watchId !== null) { │ │ │ │ │ - this.geolocation.clearWatch(this.watchId); │ │ │ │ │ - } │ │ │ │ │ - return OpenLayers.Control.prototype.deactivate.apply( │ │ │ │ │ - this, arguments │ │ │ │ │ - ); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: geolocate │ │ │ │ │ - * Activates the control. │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - geolocate: function(position) { │ │ │ │ │ - var center = new OpenLayers.LonLat( │ │ │ │ │ - position.coords.longitude, │ │ │ │ │ - position.coords.latitude │ │ │ │ │ - ).transform( │ │ │ │ │ - new OpenLayers.Projection("EPSG:4326"), │ │ │ │ │ - this.map.getProjectionObject() │ │ │ │ │ - ); │ │ │ │ │ - if (this.bind) { │ │ │ │ │ - this.map.setCenter(center); │ │ │ │ │ - } │ │ │ │ │ - this.events.triggerEvent("locationupdated", { │ │ │ │ │ - position: position, │ │ │ │ │ - point: new OpenLayers.Geometry.Point( │ │ │ │ │ - center.lon, center.lat │ │ │ │ │ - ) │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: getCurrentLocation │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Returns true if a event will be fired (successfull │ │ │ │ │ - * registration) │ │ │ │ │ - */ │ │ │ │ │ - getCurrentLocation: function() { │ │ │ │ │ - if (!this.active || this.watch) { │ │ │ │ │ - return false; │ │ │ │ │ - } │ │ │ │ │ - this.geolocation.getCurrentPosition( │ │ │ │ │ - OpenLayers.Function.bind(this.geolocate, this), │ │ │ │ │ - OpenLayers.Function.bind(this.failure, this), │ │ │ │ │ - this.geolocationOptions │ │ │ │ │ - ); │ │ │ │ │ - return true; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: failure │ │ │ │ │ - * method called on browser's geolocation failure │ │ │ │ │ - * │ │ │ │ │ - */ │ │ │ │ │ - failure: function(error) { │ │ │ │ │ - this.events.triggerEvent("locationfailed", { │ │ │ │ │ - error: error │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.Geolocate" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/PanZoomBar.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control/PanZoom.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.PanZoomBar │ │ │ │ │ - * The PanZoomBar is a visible control composed of a │ │ │ │ │ - * and a . │ │ │ │ │ - * By default it is displayed in the upper left corner of the map as 4 │ │ │ │ │ - * directional arrows above a vertical slider. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomStopWidth │ │ │ │ │ - */ │ │ │ │ │ - zoomStopWidth: 18, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomStopHeight │ │ │ │ │ - */ │ │ │ │ │ - zoomStopHeight: 11, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: slider │ │ │ │ │ - */ │ │ │ │ │ - slider: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: sliderEvents │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - sliderEvents: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoombarDiv │ │ │ │ │ - * {DOMElement} │ │ │ │ │ - */ │ │ │ │ │ - zoombarDiv: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomWorldIcon │ │ │ │ │ - * {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - zoomWorldIcon: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: panIcons │ │ │ │ │ - * {Boolean} Set this property to false not to display the pan icons. If │ │ │ │ │ - * false the zoom world icon is placed under the zoom bar. Defaults to │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - panIcons: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: forceFixedZoomLevel │ │ │ │ │ - * {Boolean} Force a fixed zoom level even though the map has │ │ │ │ │ - * fractionalZoom │ │ │ │ │ - */ │ │ │ │ │ - forceFixedZoomLevel: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: mouseDragStart │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - mouseDragStart: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: deltaY │ │ │ │ │ - * {Number} The cumulative vertical pixel offset during a zoom bar drag. │ │ │ │ │ - */ │ │ │ │ │ - deltaY: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: zoomStart │ │ │ │ │ - * {} │ │ │ │ │ - */ │ │ │ │ │ - zoomStart: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.PanZoomBar │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - │ │ │ │ │ - this._removeZoomBar(); │ │ │ │ │ - │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - "changebaselayer": this.redraw, │ │ │ │ │ - "updatesize": this.redraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Control.PanZoom.prototype.destroy.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - delete this.mouseDragStart; │ │ │ │ │ - delete this.zoomStart; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ - */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Control.PanZoom.prototype.setMap.apply(this, arguments); │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - "changebaselayer": this.redraw, │ │ │ │ │ - "updatesize": this.redraw, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: redraw │ │ │ │ │ - * clear the div and start over. │ │ │ │ │ - */ │ │ │ │ │ - redraw: function() { │ │ │ │ │ - if (this.div != null) { │ │ │ │ │ - this.removeButtons(); │ │ │ │ │ - this._removeZoomBar(); │ │ │ │ │ - } │ │ │ │ │ - this.draw(); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * px - {} │ │ │ │ │ - */ │ │ │ │ │ - draw: function(px) { │ │ │ │ │ - // initialize our internal div │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - px = this.position.clone(); │ │ │ │ │ - │ │ │ │ │ - // place the controls │ │ │ │ │ - this.buttons = []; │ │ │ │ │ - │ │ │ │ │ - var sz = { │ │ │ │ │ - w: 18, │ │ │ │ │ - h: 18 │ │ │ │ │ - }; │ │ │ │ │ - if (this.panIcons) { │ │ │ │ │ - var centered = new OpenLayers.Pixel(px.x + sz.w / 2, px.y); │ │ │ │ │ - var wposition = sz.w; │ │ │ │ │ - │ │ │ │ │ - if (this.zoomWorldIcon) { │ │ │ │ │ - centered = new OpenLayers.Pixel(px.x + sz.w, px.y); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this._addButton("panup", "north-mini.png", centered, sz); │ │ │ │ │ - px.y = centered.y + sz.h; │ │ │ │ │ - this._addButton("panleft", "west-mini.png", px, sz); │ │ │ │ │ - if (this.zoomWorldIcon) { │ │ │ │ │ - this._addButton("zoomworld", "zoom-world-mini.png", px.add(sz.w, 0), sz); │ │ │ │ │ - │ │ │ │ │ - wposition *= 2; │ │ │ │ │ - } │ │ │ │ │ - this._addButton("panright", "east-mini.png", px.add(wposition, 0), sz); │ │ │ │ │ - this._addButton("pandown", "south-mini.png", centered.add(0, sz.h * 2), sz); │ │ │ │ │ - this._addButton("zoomin", "zoom-plus-mini.png", centered.add(0, sz.h * 3 + 5), sz); │ │ │ │ │ - centered = this._addZoomBar(centered.add(0, sz.h * 4 + 5)); │ │ │ │ │ - this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); │ │ │ │ │ - } else { │ │ │ │ │ - this._addButton("zoomin", "zoom-plus-mini.png", px, sz); │ │ │ │ │ - centered = this._addZoomBar(px.add(0, sz.h)); │ │ │ │ │ - this._addButton("zoomout", "zoom-minus-mini.png", centered, sz); │ │ │ │ │ - if (this.zoomWorldIcon) { │ │ │ │ │ - centered = centered.add(0, sz.h + 3); │ │ │ │ │ - this._addButton("zoomworld", "zoom-world-mini.png", centered, sz); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return this.div; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: _addZoomBar │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * centered - {} where zoombar drawing is to start. │ │ │ │ │ - */ │ │ │ │ │ - _addZoomBar: function(centered) { │ │ │ │ │ - var imgLocation = OpenLayers.Util.getImageLocation("slider.png"); │ │ │ │ │ - var id = this.id + "_" + this.map.id; │ │ │ │ │ - var minZoom = this.map.getMinZoom(); │ │ │ │ │ - var zoomsToEnd = this.map.getNumZoomLevels() - 1 - this.map.getZoom(); │ │ │ │ │ - var slider = OpenLayers.Util.createAlphaImageDiv(id, │ │ │ │ │ - centered.add(-1, zoomsToEnd * this.zoomStopHeight), { │ │ │ │ │ - w: 20, │ │ │ │ │ - h: 9 │ │ │ │ │ - }, │ │ │ │ │ - imgLocation, │ │ │ │ │ - "absolute"); │ │ │ │ │ - slider.style.cursor = "move"; │ │ │ │ │ - this.slider = slider; │ │ │ │ │ - │ │ │ │ │ - this.sliderEvents = new OpenLayers.Events(this, slider, null, true, { │ │ │ │ │ - includeXY: true │ │ │ │ │ - }); │ │ │ │ │ - this.sliderEvents.on({ │ │ │ │ │ - "touchstart": this.zoomBarDown, │ │ │ │ │ - "touchmove": this.zoomBarDrag, │ │ │ │ │ - "touchend": this.zoomBarUp, │ │ │ │ │ - "mousedown": this.zoomBarDown, │ │ │ │ │ - "mousemove": this.zoomBarDrag, │ │ │ │ │ - "mouseup": this.zoomBarUp │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - var sz = { │ │ │ │ │ - w: this.zoomStopWidth, │ │ │ │ │ - h: this.zoomStopHeight * (this.map.getNumZoomLevels() - minZoom) │ │ │ │ │ - }; │ │ │ │ │ - var imgLocation = OpenLayers.Util.getImageLocation("zoombar.png"); │ │ │ │ │ - var div = null; │ │ │ │ │ - │ │ │ │ │ - if (OpenLayers.Util.alphaHack()) { │ │ │ │ │ - var id = this.id + "_" + this.map.id; │ │ │ │ │ - div = OpenLayers.Util.createAlphaImageDiv(id, centered, { │ │ │ │ │ - w: sz.w, │ │ │ │ │ - h: this.zoomStopHeight │ │ │ │ │ - }, │ │ │ │ │ - imgLocation, │ │ │ │ │ - "absolute", null, "crop"); │ │ │ │ │ - div.style.height = sz.h + "px"; │ │ │ │ │ - } else { │ │ │ │ │ - div = OpenLayers.Util.createDiv( │ │ │ │ │ - 'OpenLayers_Control_PanZoomBar_Zoombar' + this.map.id, │ │ │ │ │ - centered, │ │ │ │ │ - sz, │ │ │ │ │ - imgLocation); │ │ │ │ │ - } │ │ │ │ │ - div.style.cursor = "pointer"; │ │ │ │ │ - div.className = "olButton"; │ │ │ │ │ - this.zoombarDiv = div; │ │ │ │ │ - │ │ │ │ │ - this.div.appendChild(div); │ │ │ │ │ - │ │ │ │ │ - this.startTop = parseInt(div.style.top); │ │ │ │ │ - this.div.appendChild(slider); │ │ │ │ │ - │ │ │ │ │ - this.map.events.register("zoomend", this, this.moveZoomBar); │ │ │ │ │ - │ │ │ │ │ - centered = centered.add(0, │ │ │ │ │ - this.zoomStopHeight * (this.map.getNumZoomLevels() - minZoom)); │ │ │ │ │ - return centered; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: _removeZoomBar │ │ │ │ │ - */ │ │ │ │ │ - _removeZoomBar: function() { │ │ │ │ │ - this.sliderEvents.un({ │ │ │ │ │ - "touchstart": this.zoomBarDown, │ │ │ │ │ - "touchmove": this.zoomBarDrag, │ │ │ │ │ - "touchend": this.zoomBarUp, │ │ │ │ │ - "mousedown": this.zoomBarDown, │ │ │ │ │ - "mousemove": this.zoomBarDrag, │ │ │ │ │ - "mouseup": this.zoomBarUp │ │ │ │ │ - }); │ │ │ │ │ - this.sliderEvents.destroy(); │ │ │ │ │ - │ │ │ │ │ - this.div.removeChild(this.zoombarDiv); │ │ │ │ │ - this.zoombarDiv = null; │ │ │ │ │ - this.div.removeChild(this.slider); │ │ │ │ │ - this.slider = null; │ │ │ │ │ - │ │ │ │ │ - this.map.events.unregister("zoomend", this, this.moveZoomBar); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: onButtonClick │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ - */ │ │ │ │ │ - onButtonClick: function(evt) { │ │ │ │ │ - OpenLayers.Control.PanZoom.prototype.onButtonClick.apply(this, arguments); │ │ │ │ │ - if (evt.buttonElement === this.zoombarDiv) { │ │ │ │ │ - var levels = evt.buttonXY.y / this.zoomStopHeight; │ │ │ │ │ - if (this.forceFixedZoomLevel || !this.map.fractionalZoom) { │ │ │ │ │ - levels = Math.floor(levels); │ │ │ │ │ - } │ │ │ │ │ - var zoom = (this.map.getNumZoomLevels() - 1) - levels; │ │ │ │ │ - zoom = Math.min(Math.max(zoom, 0), this.map.getNumZoomLevels() - 1); │ │ │ │ │ - this.map.zoomTo(zoom); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: passEventToSlider │ │ │ │ │ - * This function is used to pass events that happen on the div, or the map, │ │ │ │ │ - * through to the slider, which then does its moving thing. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - */ │ │ │ │ │ - passEventToSlider: function(evt) { │ │ │ │ │ - this.sliderEvents.handleBrowserEvent(evt); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /* │ │ │ │ │ - * Method: zoomBarDown │ │ │ │ │ - * event listener for clicks on the slider │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - */ │ │ │ │ │ - zoomBarDown: function(evt) { │ │ │ │ │ - if (!OpenLayers.Event.isLeftClick(evt) && !OpenLayers.Event.isSingleTouch(evt)) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - this.map.events.on({ │ │ │ │ │ - "touchmove": this.passEventToSlider, │ │ │ │ │ - "mousemove": this.passEventToSlider, │ │ │ │ │ - "mouseup": this.passEventToSlider, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - this.mouseDragStart = evt.xy.clone(); │ │ │ │ │ - this.zoomStart = evt.xy.clone(); │ │ │ │ │ - this.div.style.cursor = "move"; │ │ │ │ │ - // reset the div offsets just in case the div moved │ │ │ │ │ - this.zoombarDiv.offsets = null; │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /* │ │ │ │ │ - * Method: zoomBarDrag │ │ │ │ │ - * This is what happens when a click has occurred, and the client is │ │ │ │ │ - * dragging. Here we must ensure that the slider doesn't go beyond the │ │ │ │ │ - * bottom/top of the zoombar div, as well as moving the slider to its new │ │ │ │ │ - * visual location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - */ │ │ │ │ │ - zoomBarDrag: function(evt) { │ │ │ │ │ - if (this.mouseDragStart != null) { │ │ │ │ │ - var deltaY = this.mouseDragStart.y - evt.xy.y; │ │ │ │ │ - var offsets = OpenLayers.Util.pagePosition(this.zoombarDiv); │ │ │ │ │ - if ((evt.clientY - offsets[1]) > 0 && │ │ │ │ │ - (evt.clientY - offsets[1]) < parseInt(this.zoombarDiv.style.height) - 2) { │ │ │ │ │ - var newTop = parseInt(this.slider.style.top) - deltaY; │ │ │ │ │ - this.slider.style.top = newTop + "px"; │ │ │ │ │ - this.mouseDragStart = evt.xy.clone(); │ │ │ │ │ - } │ │ │ │ │ - // set cumulative displacement │ │ │ │ │ - this.deltaY = this.zoomStart.y - evt.xy.y; │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /* │ │ │ │ │ - * Method: zoomBarUp │ │ │ │ │ - * Perform cleanup when a mouseup event is received -- discover new zoom │ │ │ │ │ - * level and switch to it. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ - */ │ │ │ │ │ - zoomBarUp: function(evt) { │ │ │ │ │ - if (!OpenLayers.Event.isLeftClick(evt) && evt.type !== "touchend") { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - if (this.mouseDragStart) { │ │ │ │ │ - this.div.style.cursor = ""; │ │ │ │ │ - this.map.events.un({ │ │ │ │ │ - "touchmove": this.passEventToSlider, │ │ │ │ │ - "mouseup": this.passEventToSlider, │ │ │ │ │ - "mousemove": this.passEventToSlider, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - var zoomLevel = this.map.zoom; │ │ │ │ │ - if (!this.forceFixedZoomLevel && this.map.fractionalZoom) { │ │ │ │ │ - zoomLevel += this.deltaY / this.zoomStopHeight; │ │ │ │ │ - zoomLevel = Math.min(Math.max(zoomLevel, 0), │ │ │ │ │ - this.map.getNumZoomLevels() - 1); │ │ │ │ │ - } else { │ │ │ │ │ - zoomLevel += this.deltaY / this.zoomStopHeight; │ │ │ │ │ - zoomLevel = Math.max(Math.round(zoomLevel), 0); │ │ │ │ │ - } │ │ │ │ │ - this.map.zoomTo(zoomLevel); │ │ │ │ │ - this.mouseDragStart = null; │ │ │ │ │ - this.zoomStart = null; │ │ │ │ │ - this.deltaY = 0; │ │ │ │ │ - OpenLayers.Event.stop(evt); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /* │ │ │ │ │ - * Method: moveZoomBar │ │ │ │ │ - * Change the location of the slider to match the current zoom level. │ │ │ │ │ - */ │ │ │ │ │ - moveZoomBar: function() { │ │ │ │ │ - var newTop = │ │ │ │ │ - ((this.map.getNumZoomLevels() - 1) - this.map.getZoom()) * │ │ │ │ │ - this.zoomStopHeight + this.startTop + 1; │ │ │ │ │ - this.slider.style.top = newTop + "px"; │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.PanZoomBar" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ OpenLayers/Control/DragFeature.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ @@ -53479,277 +46200,554 @@ │ │ │ │ │ this.handlers.feature.setMap(map); │ │ │ │ │ OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Control.DragFeature" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/TouchNavigation.js │ │ │ │ │ + OpenLayers/Control/WMSGetFeatureInfo.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control/DragPan.js │ │ │ │ │ - * @requires OpenLayers/Control/PinchZoom.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ + * @requires OpenLayers/Request.js │ │ │ │ │ + * @requires OpenLayers/Format/WMSGetFeatureInfo.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.TouchNavigation │ │ │ │ │ - * The navigation control handles map browsing with touch events (dragging, │ │ │ │ │ - * double-tapping, tap with two fingers, and pinch zoom). Create a new │ │ │ │ │ - * control with the constructor. │ │ │ │ │ - * │ │ │ │ │ - * If you’re only targeting touch enabled devices with your mapping application, │ │ │ │ │ - * you can create a map with only a TouchNavigation control. The │ │ │ │ │ - * control is mobile ready by default, but │ │ │ │ │ - * you can generate a smaller build of the library by only including this │ │ │ │ │ - * touch navigation control if you aren't concerned about mouse interaction. │ │ │ │ │ + * Class: OpenLayers.Control.WMSGetFeatureInfo │ │ │ │ │ + * The WMSGetFeatureInfo control uses a WMS query to get information about a point on the map. The │ │ │ │ │ + * information may be in a display-friendly format such as HTML, or a machine-friendly format such │ │ │ │ │ + * as GML, depending on the server's capabilities and the client's configuration. This control │ │ │ │ │ + * handles click or hover events, attempts to parse the results using an OpenLayers.Format, and │ │ │ │ │ + * fires a 'getfeatureinfo' event with the click position, the raw body of the response, and an │ │ │ │ │ + * array of features if it successfully read the response. │ │ │ │ │ * │ │ │ │ │ - * Inherits: │ │ │ │ │ + * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.TouchNavigation = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ +OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: dragPan │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: hover │ │ │ │ │ + * {Boolean} Send GetFeatureInfo requests when mouse stops moving. │ │ │ │ │ + * Default is false. │ │ │ │ │ */ │ │ │ │ │ - dragPan: null, │ │ │ │ │ + hover: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: dragPanOptions │ │ │ │ │ - * {Object} Options passed to the DragPan control. │ │ │ │ │ + * APIProperty: drillDown │ │ │ │ │ + * {Boolean} Drill down over all WMS layers in the map. When │ │ │ │ │ + * using drillDown mode, hover is not possible, and an infoFormat that │ │ │ │ │ + * returns parseable features is required. Default is false. │ │ │ │ │ */ │ │ │ │ │ - dragPanOptions: null, │ │ │ │ │ + drillDown: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: pinchZoom │ │ │ │ │ - * {} │ │ │ │ │ + * APIProperty: maxFeatures │ │ │ │ │ + * {Integer} Maximum number of features to return from a WMS query. This │ │ │ │ │ + * sets the feature_count parameter on WMS GetFeatureInfo │ │ │ │ │ + * requests. │ │ │ │ │ */ │ │ │ │ │ - pinchZoom: null, │ │ │ │ │ + maxFeatures: 10, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: pinchZoomOptions │ │ │ │ │ - * {Object} Options passed to the PinchZoom control. │ │ │ │ │ + * APIProperty: clickCallback │ │ │ │ │ + * {String} The click callback to register in the │ │ │ │ │ + * {} object created when the hover │ │ │ │ │ + * option is set to false. Default is "click". │ │ │ │ │ */ │ │ │ │ │ - pinchZoomOptions: null, │ │ │ │ │ + clickCallback: "click", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: clickHandlerOptions │ │ │ │ │ - * {Object} Options passed to the Click handler. │ │ │ │ │ + * APIProperty: output │ │ │ │ │ + * {String} Either "features" or "object". When triggering a getfeatureinfo │ │ │ │ │ + * request should we pass on an array of features or an object with with │ │ │ │ │ + * a "features" property and other properties (such as the url of the │ │ │ │ │ + * WMS). Default is "features". │ │ │ │ │ */ │ │ │ │ │ - clickHandlerOptions: null, │ │ │ │ │ + output: "features", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: documentDrag │ │ │ │ │ - * {Boolean} Allow panning of the map by dragging outside map viewport. │ │ │ │ │ - * Default is false. │ │ │ │ │ + * APIProperty: layers │ │ │ │ │ + * {Array()} The layers to query for feature info. │ │ │ │ │ + * If omitted, all map WMS layers with a url that matches this or │ │ │ │ │ + * will be considered. │ │ │ │ │ */ │ │ │ │ │ - documentDrag: false, │ │ │ │ │ + layers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ + * APIProperty: queryVisible │ │ │ │ │ + * {Boolean} If true, filter out hidden layers when searching the map for │ │ │ │ │ + * layers to query. Default is false. │ │ │ │ │ */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ + queryVisible: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.TouchNavigation │ │ │ │ │ - * Create a new navigation control │ │ │ │ │ + * APIProperty: url │ │ │ │ │ + * {String} The URL of the WMS service to use. If not provided, the url │ │ │ │ │ + * of the first eligible layer will be used. │ │ │ │ │ + */ │ │ │ │ │ + url: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: layerUrls │ │ │ │ │ + * {Array(String)} Optional list of urls for layers that should be queried. │ │ │ │ │ + * This can be used when the layer url differs from the url used for │ │ │ │ │ + * making GetFeatureInfo requests (in the case of a layer using cached │ │ │ │ │ + * tiles). │ │ │ │ │ + */ │ │ │ │ │ + layerUrls: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: infoFormat │ │ │ │ │ + * {String} The mimetype to request from the server. If you are using │ │ │ │ │ + * drillDown mode and have multiple servers that do not share a common │ │ │ │ │ + * infoFormat, you can override the control's infoFormat by providing an │ │ │ │ │ + * INFO_FORMAT parameter in your instance(s). │ │ │ │ │ + */ │ │ │ │ │ + infoFormat: 'text/html', │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: vendorParams │ │ │ │ │ + * {Object} Additional parameters that will be added to the request, for │ │ │ │ │ + * WMS implementations that support them. This could e.g. look like │ │ │ │ │ + * (start code) │ │ │ │ │ + * { │ │ │ │ │ + * radius: 5 │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + */ │ │ │ │ │ + vendorParams: {}, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: format │ │ │ │ │ + * {} A format for parsing GetFeatureInfo responses. │ │ │ │ │ + * Default is . │ │ │ │ │ + */ │ │ │ │ │ + format: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: formatOptions │ │ │ │ │ + * {Object} Optional properties to set on the format (if one is not provided │ │ │ │ │ + * in the property. │ │ │ │ │ + */ │ │ │ │ │ + formatOptions: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: handlerOptions │ │ │ │ │ + * {Object} Additional options for the handlers used by this control, e.g. │ │ │ │ │ + * (start code) │ │ │ │ │ + * { │ │ │ │ │ + * "click": {delay: 100}, │ │ │ │ │ + * "hover": {delay: 300} │ │ │ │ │ + * } │ │ │ │ │ + * (end) │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: handler │ │ │ │ │ + * {Object} Reference to the for this control │ │ │ │ │ + */ │ │ │ │ │ + handler: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: hoverRequest │ │ │ │ │ + * {} contains the currently running hover request │ │ │ │ │ + * (if any). │ │ │ │ │ + */ │ │ │ │ │ + hoverRequest: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * beforegetfeatureinfo - Triggered before the request is sent. │ │ │ │ │ + * The event object has an *xy* property with the position of the │ │ │ │ │ + * mouse click or hover event that triggers the request. │ │ │ │ │ + * nogetfeatureinfo - no queryable layers were found. │ │ │ │ │ + * getfeatureinfo - Triggered when a GetFeatureInfo response is received. │ │ │ │ │ + * The event object has a *text* property with the body of the │ │ │ │ │ + * response (String), a *features* property with an array of the │ │ │ │ │ + * parsed features, an *xy* property with the position of the mouse │ │ │ │ │ + * click or hover event that triggered the request, and a *request* │ │ │ │ │ + * property with the request itself. If drillDown is set to true and │ │ │ │ │ + * multiple requests were issued to collect feature info from all │ │ │ │ │ + * layers, *text* and *request* will only contain the response body │ │ │ │ │ + * and request object of the last request. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * the control │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ - this.handlers = {}; │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, arguments); │ │ │ │ │ + options = options || {}; │ │ │ │ │ + options.handlerOptions = options.handlerOptions || {}; │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + │ │ │ │ │ + if (!this.format) { │ │ │ │ │ + this.format = new OpenLayers.Format.WMSGetFeatureInfo( │ │ │ │ │ + options.formatOptions │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.drillDown === true) { │ │ │ │ │ + this.hover = false; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (this.hover) { │ │ │ │ │ + this.handler = new OpenLayers.Handler.Hover( │ │ │ │ │ + this, { │ │ │ │ │ + 'move': this.cancelHover, │ │ │ │ │ + 'pause': this.getInfoForHover │ │ │ │ │ + }, │ │ │ │ │ + OpenLayers.Util.extend(this.handlerOptions.hover || {}, { │ │ │ │ │ + 'delay': 250 │ │ │ │ │ + })); │ │ │ │ │ + } else { │ │ │ │ │ + var callbacks = {}; │ │ │ │ │ + callbacks[this.clickCallback] = this.getInfoForClick; │ │ │ │ │ + this.handler = new OpenLayers.Handler.Click( │ │ │ │ │ + this, callbacks, this.handlerOptions.click || {}); │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: destroy │ │ │ │ │ - * The destroy method is used to perform any clean up before the control │ │ │ │ │ - * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ - * to prevent memory leaks. │ │ │ │ │ + * Method: getInfoForClick │ │ │ │ │ + * Called on click │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - if (this.dragPan) { │ │ │ │ │ - this.dragPan.destroy(); │ │ │ │ │ - } │ │ │ │ │ - this.dragPan = null; │ │ │ │ │ - if (this.pinchZoom) { │ │ │ │ │ - this.pinchZoom.destroy(); │ │ │ │ │ - delete this.pinchZoom; │ │ │ │ │ - } │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + getInfoForClick: function(evt) { │ │ │ │ │ + this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ + xy: evt.xy │ │ │ │ │ + }); │ │ │ │ │ + // Set the cursor to "wait" to tell the user we're working on their │ │ │ │ │ + // click. │ │ │ │ │ + OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + this.request(evt.xy, {}); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ + * Method: getInfoForHover │ │ │ │ │ + * Pause callback for the hover handler │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ - this.dragPan.activate(); │ │ │ │ │ - this.handlers.click.activate(); │ │ │ │ │ - this.pinchZoom.activate(); │ │ │ │ │ - return true; │ │ │ │ │ - } │ │ │ │ │ - return false; │ │ │ │ │ + getInfoForHover: function(evt) { │ │ │ │ │ + this.events.triggerEvent("beforegetfeatureinfo", { │ │ │ │ │ + xy: evt.xy │ │ │ │ │ + }); │ │ │ │ │ + this.request(evt.xy, { │ │ │ │ │ + hover: true │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ + * Method: cancelHover │ │ │ │ │ + * Cancel callback for the hover handler │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ - this.dragPan.deactivate(); │ │ │ │ │ - this.handlers.click.deactivate(); │ │ │ │ │ - this.pinchZoom.deactivate(); │ │ │ │ │ - return true; │ │ │ │ │ + cancelHover: function() { │ │ │ │ │ + if (this.hoverRequest) { │ │ │ │ │ + this.hoverRequest.abort(); │ │ │ │ │ + this.hoverRequest = null; │ │ │ │ │ } │ │ │ │ │ - return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ + * Method: findLayers │ │ │ │ │ + * Internal method to get the layers, independent of whether we are │ │ │ │ │ + * inspecting the map or using a client-provided array │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var clickCallbacks = { │ │ │ │ │ - click: this.defaultClick, │ │ │ │ │ - dblclick: this.defaultDblClick │ │ │ │ │ - }; │ │ │ │ │ - var clickOptions = OpenLayers.Util.extend({ │ │ │ │ │ - "double": true, │ │ │ │ │ - stopDouble: true, │ │ │ │ │ - pixelTolerance: 2 │ │ │ │ │ - }, this.clickHandlerOptions); │ │ │ │ │ - this.handlers.click = new OpenLayers.Handler.Click( │ │ │ │ │ - this, clickCallbacks, clickOptions │ │ │ │ │ - ); │ │ │ │ │ - this.dragPan = new OpenLayers.Control.DragPan( │ │ │ │ │ - OpenLayers.Util.extend({ │ │ │ │ │ - map: this.map, │ │ │ │ │ - documentDrag: this.documentDrag │ │ │ │ │ - }, this.dragPanOptions) │ │ │ │ │ - ); │ │ │ │ │ - this.dragPan.draw(); │ │ │ │ │ - this.pinchZoom = new OpenLayers.Control.PinchZoom( │ │ │ │ │ - OpenLayers.Util.extend({ │ │ │ │ │ - map: this.map │ │ │ │ │ - }, this.pinchZoomOptions) │ │ │ │ │ - ); │ │ │ │ │ + findLayers: function() { │ │ │ │ │ + │ │ │ │ │ + var candidates = this.layers || this.map.layers; │ │ │ │ │ + var layers = []; │ │ │ │ │ + var layer, url; │ │ │ │ │ + for (var i = candidates.length - 1; i >= 0; --i) { │ │ │ │ │ + layer = candidates[i]; │ │ │ │ │ + if (layer instanceof OpenLayers.Layer.WMS && │ │ │ │ │ + (!this.queryVisible || layer.getVisibility())) { │ │ │ │ │ + url = OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url; │ │ │ │ │ + // if the control was not configured with a url, set it │ │ │ │ │ + // to the first layer url │ │ │ │ │ + if (this.drillDown === false && !this.url) { │ │ │ │ │ + this.url = url; │ │ │ │ │ + } │ │ │ │ │ + if (this.drillDown === true || this.urlMatches(url)) { │ │ │ │ │ + layers.push(layer); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return layers; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultClick │ │ │ │ │ + * Method: urlMatches │ │ │ │ │ + * Test to see if the provided url matches either the control or one │ │ │ │ │ + * of the . │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * url - {String} The url to test. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The provided url matches the control or one of the │ │ │ │ │ + * . │ │ │ │ │ */ │ │ │ │ │ - defaultClick: function(evt) { │ │ │ │ │ - if (evt.lastTouches && evt.lastTouches.length == 2) { │ │ │ │ │ - this.map.zoomOut(); │ │ │ │ │ + urlMatches: function(url) { │ │ │ │ │ + var matches = OpenLayers.Util.isEquivalentUrl(this.url, url); │ │ │ │ │ + if (!matches && this.layerUrls) { │ │ │ │ │ + for (var i = 0, len = this.layerUrls.length; i < len; ++i) { │ │ │ │ │ + if (OpenLayers.Util.isEquivalentUrl(this.layerUrls[i], url)) { │ │ │ │ │ + matches = true; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return matches; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: defaultDblClick │ │ │ │ │ + * Method: buildWMSOptions │ │ │ │ │ + * Build an object with the relevant WMS options for the GetFeatureInfo request │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Event} │ │ │ │ │ + * url - {String} The url to be used for sending the request │ │ │ │ │ + * layers - {Array(} The position on the map where the mouse │ │ │ │ │ + * event occurred. │ │ │ │ │ + * format - {String} The format from the corresponding GetMap request │ │ │ │ │ */ │ │ │ │ │ - defaultDblClick: function(evt) { │ │ │ │ │ - this.map.zoomTo(this.map.zoom + 1, evt.xy); │ │ │ │ │ + buildWMSOptions: function(url, layers, clickPosition, format) { │ │ │ │ │ + var layerNames = [], │ │ │ │ │ + styleNames = []; │ │ │ │ │ + for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ + if (layers[i].params.LAYERS != null) { │ │ │ │ │ + layerNames = layerNames.concat(layers[i].params.LAYERS); │ │ │ │ │ + styleNames = styleNames.concat(this.getStyleNames(layers[i])); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var firstLayer = layers[0]; │ │ │ │ │ + // use the firstLayer's projection if it matches the map projection - │ │ │ │ │ + // this assumes that all layers will be available in this projection │ │ │ │ │ + var projection = this.map.getProjection(); │ │ │ │ │ + var layerProj = firstLayer.projection; │ │ │ │ │ + if (layerProj && layerProj.equals(this.map.getProjectionObject())) { │ │ │ │ │ + projection = layerProj.getCode(); │ │ │ │ │ + } │ │ │ │ │ + var params = OpenLayers.Util.extend({ │ │ │ │ │ + service: "WMS", │ │ │ │ │ + version: firstLayer.params.VERSION, │ │ │ │ │ + request: "GetFeatureInfo", │ │ │ │ │ + exceptions: firstLayer.params.EXCEPTIONS, │ │ │ │ │ + bbox: this.map.getExtent().toBBOX(null, │ │ │ │ │ + firstLayer.reverseAxisOrder()), │ │ │ │ │ + feature_count: this.maxFeatures, │ │ │ │ │ + height: this.map.getSize().h, │ │ │ │ │ + width: this.map.getSize().w, │ │ │ │ │ + format: format, │ │ │ │ │ + info_format: firstLayer.params.INFO_FORMAT || this.infoFormat │ │ │ │ │ + }, (parseFloat(firstLayer.params.VERSION) >= 1.3) ? { │ │ │ │ │ + crs: projection, │ │ │ │ │ + i: parseInt(clickPosition.x), │ │ │ │ │ + j: parseInt(clickPosition.y) │ │ │ │ │ + } : { │ │ │ │ │ + srs: projection, │ │ │ │ │ + x: parseInt(clickPosition.x), │ │ │ │ │ + y: parseInt(clickPosition.y) │ │ │ │ │ + }); │ │ │ │ │ + if (layerNames.length != 0) { │ │ │ │ │ + params = OpenLayers.Util.extend({ │ │ │ │ │ + layers: layerNames, │ │ │ │ │ + query_layers: layerNames, │ │ │ │ │ + styles: styleNames │ │ │ │ │ + }, params); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Util.applyDefaults(params, this.vendorParams); │ │ │ │ │ + return { │ │ │ │ │ + url: url, │ │ │ │ │ + params: OpenLayers.Util.upperCaseObject(params), │ │ │ │ │ + callback: function(request) { │ │ │ │ │ + this.handleResponse(clickPosition, request, url); │ │ │ │ │ + }, │ │ │ │ │ + scope: this │ │ │ │ │ + }; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.TouchNavigation" │ │ │ │ │ -}); │ │ │ │ │ -/* ====================================================================== │ │ │ │ │ - OpenLayers/Control/PanPanel.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ + /** │ │ │ │ │ + * Method: getStyleNames │ │ │ │ │ + * Gets the STYLES parameter for the layer. Make sure the STYLES parameter │ │ │ │ │ + * matches the LAYERS parameter │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array(String)} The STYLES parameter │ │ │ │ │ + */ │ │ │ │ │ + getStyleNames: function(layer) { │ │ │ │ │ + // in the event of a WMS layer bundling multiple layers but not │ │ │ │ │ + // specifying styles,we need the same number of commas to specify │ │ │ │ │ + // the default style for each of the layers. We can't just leave it │ │ │ │ │ + // blank as we may be including other layers that do specify styles. │ │ │ │ │ + var styleNames; │ │ │ │ │ + if (layer.params.STYLES) { │ │ │ │ │ + styleNames = layer.params.STYLES; │ │ │ │ │ + } else { │ │ │ │ │ + if (OpenLayers.Util.isArray(layer.params.LAYERS)) { │ │ │ │ │ + styleNames = new Array(layer.params.LAYERS.length); │ │ │ │ │ + } else { // Assume it's a String │ │ │ │ │ + styleNames = layer.params.LAYERS.replace(/[^,]/g, ""); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return styleNames; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of 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: request │ │ │ │ │ + * Sends a GetFeatureInfo request to the WMS │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * clickPosition - {} The position on the map where the │ │ │ │ │ + * mouse event occurred. │ │ │ │ │ + * options - {Object} additional options for this method. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * - *hover* {Boolean} true if we do the request for the hover handler │ │ │ │ │ + */ │ │ │ │ │ + request: function(clickPosition, options) { │ │ │ │ │ + var layers = this.findLayers(); │ │ │ │ │ + if (layers.length == 0) { │ │ │ │ │ + this.events.triggerEvent("nogetfeatureinfo"); │ │ │ │ │ + // Reset the cursor. │ │ │ │ │ + OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Control/Panel.js │ │ │ │ │ - * @requires OpenLayers/Control/Pan.js │ │ │ │ │ - */ │ │ │ │ │ + options = options || {}; │ │ │ │ │ + if (this.drillDown === false) { │ │ │ │ │ + var wmsOptions = this.buildWMSOptions(this.url, layers, │ │ │ │ │ + clickPosition, layers[0].params.FORMAT); │ │ │ │ │ + var request = OpenLayers.Request.GET(wmsOptions); │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Control.PanPanel │ │ │ │ │ - * The PanPanel is visible control for panning the map North, South, East or │ │ │ │ │ - * West in small steps. By default it is drawn in the top left corner of the │ │ │ │ │ - * map. │ │ │ │ │ - * │ │ │ │ │ - * Note: │ │ │ │ │ - * If you wish to use this class with the default images and you want │ │ │ │ │ - * it to look nice in ie6, you should add the following, conditionally │ │ │ │ │ - * added css stylesheet to your HTML file: │ │ │ │ │ - * │ │ │ │ │ - * (code) │ │ │ │ │ - * │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Control.PanPanel = OpenLayers.Class(OpenLayers.Control.Panel, { │ │ │ │ │ + if (options.hover === true) { │ │ │ │ │ + this.hoverRequest = request; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + this._requestCount = 0; │ │ │ │ │ + this._numRequests = 0; │ │ │ │ │ + this.features = []; │ │ │ │ │ + // group according to service url to combine requests │ │ │ │ │ + var services = {}, │ │ │ │ │ + url; │ │ │ │ │ + for (var i = 0, len = layers.length; i < len; i++) { │ │ │ │ │ + var layer = layers[i]; │ │ │ │ │ + var service, found = false; │ │ │ │ │ + url = OpenLayers.Util.isArray(layer.url) ? layer.url[0] : layer.url; │ │ │ │ │ + if (url in services) { │ │ │ │ │ + services[url].push(layer); │ │ │ │ │ + } else { │ │ │ │ │ + this._numRequests++; │ │ │ │ │ + services[url] = [layer]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var layers; │ │ │ │ │ + for (var url in services) { │ │ │ │ │ + layers = services[url]; │ │ │ │ │ + var wmsOptions = this.buildWMSOptions(url, layers, │ │ │ │ │ + clickPosition, layers[0].params.FORMAT); │ │ │ │ │ + OpenLayers.Request.GET(wmsOptions); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: slideFactor │ │ │ │ │ - * {Integer} Number of pixels by which we'll pan the map in any direction │ │ │ │ │ - * on clicking the arrow buttons, defaults to 50. If you want to pan │ │ │ │ │ - * by some ratio of the map dimensions, use instead. │ │ │ │ │ + /** │ │ │ │ │ + * Method: triggerGetFeatureInfo │ │ │ │ │ + * Trigger the getfeatureinfo event when all is done │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * request - {XMLHttpRequest} The request object │ │ │ │ │ + * xy - {} The position on the map where the │ │ │ │ │ + * mouse event occurred. │ │ │ │ │ + * features - {Array()} or │ │ │ │ │ + * {Array({Object}) when output is "object". The object has a url and a │ │ │ │ │ + * features property which contains an array of features. │ │ │ │ │ */ │ │ │ │ │ - slideFactor: 50, │ │ │ │ │ + triggerGetFeatureInfo: function(request, xy, features) { │ │ │ │ │ + this.events.triggerEvent("getfeatureinfo", { │ │ │ │ │ + text: request.responseText, │ │ │ │ │ + features: features, │ │ │ │ │ + request: request, │ │ │ │ │ + xy: xy │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: slideRatio │ │ │ │ │ - * {Number} The fraction of map width/height by which we'll pan the map │ │ │ │ │ - * on clicking the arrow buttons. Default is null. If set, will │ │ │ │ │ - * override . E.g. if slideRatio is .5, then Pan Up will │ │ │ │ │ - * pan up half the map height. │ │ │ │ │ - */ │ │ │ │ │ - slideRatio: null, │ │ │ │ │ + // Reset the cursor. │ │ │ │ │ + OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.PanPanel │ │ │ │ │ - * Add the four directional pan buttons. │ │ │ │ │ + * Method: handleResponse │ │ │ │ │ + * Handler for the GetFeatureInfo response. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be used │ │ │ │ │ - * to extend the control. │ │ │ │ │ + * xy - {} The position on the map where the │ │ │ │ │ + * mouse event occurred. │ │ │ │ │ + * request - {XMLHttpRequest} The request object. │ │ │ │ │ + * url - {String} The url which was used for this request. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ - var options = { │ │ │ │ │ - slideFactor: this.slideFactor, │ │ │ │ │ - slideRatio: this.slideRatio │ │ │ │ │ - }; │ │ │ │ │ - this.addControls([ │ │ │ │ │ - new OpenLayers.Control.Pan(OpenLayers.Control.Pan.NORTH, options), │ │ │ │ │ - new OpenLayers.Control.Pan(OpenLayers.Control.Pan.SOUTH, options), │ │ │ │ │ - new OpenLayers.Control.Pan(OpenLayers.Control.Pan.EAST, options), │ │ │ │ │ - new OpenLayers.Control.Pan(OpenLayers.Control.Pan.WEST, options) │ │ │ │ │ - ]); │ │ │ │ │ + handleResponse: function(xy, request, url) { │ │ │ │ │ + │ │ │ │ │ + var doc = request.responseXML; │ │ │ │ │ + if (!doc || !doc.documentElement) { │ │ │ │ │ + doc = request.responseText; │ │ │ │ │ + } │ │ │ │ │ + var features = this.format.read(doc); │ │ │ │ │ + if (this.drillDown === false) { │ │ │ │ │ + this.triggerGetFeatureInfo(request, xy, features); │ │ │ │ │ + } else { │ │ │ │ │ + this._requestCount++; │ │ │ │ │ + if (this.output === "object") { │ │ │ │ │ + this._features = (this._features || []).concat({ │ │ │ │ │ + url: url, │ │ │ │ │ + features: features │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + this._features = (this._features || []).concat(features); │ │ │ │ │ + } │ │ │ │ │ + if (this._requestCount === this._numRequests) { │ │ │ │ │ + this.triggerGetFeatureInfo(request, xy, this._features.concat()); │ │ │ │ │ + delete this._features; │ │ │ │ │ + delete this._requestCount; │ │ │ │ │ + delete this._numRequests; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.PanPanel" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.WMSGetFeatureInfo" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ OpenLayers/Control/TransformFeature.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ @@ -54386,6770 +47384,8372 @@ │ │ │ │ │ this.dragControl = null; │ │ │ │ │ OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ CLASS_NAME: "OpenLayers.Control.TransformFeature" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/GetFeature.js │ │ │ │ │ + OpenLayers/Control/Snapping.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * @requires OpenLayers/Control.js │ │ │ │ │ - * @requires OpenLayers/Handler/Click.js │ │ │ │ │ - * @requires OpenLayers/Handler/Box.js │ │ │ │ │ - * @requires OpenLayers/Handler/Hover.js │ │ │ │ │ - * @requires OpenLayers/Filter/Spatial.js │ │ │ │ │ + * @requires OpenLayers/Layer/Vector.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.GetFeature │ │ │ │ │ - * Gets vector features for locations underneath the mouse cursor. Can be │ │ │ │ │ - * configured to act on click, hover or dragged boxes. Uses an │ │ │ │ │ - * that supports spatial filters to retrieve │ │ │ │ │ - * features from a server and fires events that notify applications of the │ │ │ │ │ - * selected features. │ │ │ │ │ + * Class: OpenLayers.Control.Snapping │ │ │ │ │ + * Acts as a snapping agent while editing vector features. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: protocol │ │ │ │ │ - * {} Required. The protocol used for fetching │ │ │ │ │ - * features. │ │ │ │ │ - */ │ │ │ │ │ - protocol: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: multipleKey │ │ │ │ │ - * {String} An event modifier ('altKey' or 'shiftKey') that temporarily sets │ │ │ │ │ - * the property to true. Default is null. │ │ │ │ │ - */ │ │ │ │ │ - multipleKey: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: toggleKey │ │ │ │ │ - * {String} An event modifier ('altKey' or 'shiftKey') that temporarily sets │ │ │ │ │ - * the property to true. Default is null. │ │ │ │ │ - */ │ │ │ │ │ - toggleKey: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: modifiers │ │ │ │ │ - * {Object} The event modifiers to use, according to the current event │ │ │ │ │ - * being handled by this control's handlers │ │ │ │ │ - */ │ │ │ │ │ - modifiers: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: multiple │ │ │ │ │ - * {Boolean} Allow selection of multiple geometries. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - multiple: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: click │ │ │ │ │ - * {Boolean} Use a click handler for selecting/unselecting features. If │ │ │ │ │ - * both and are set to true, the click handler takes │ │ │ │ │ - * precedence over the box handler if a box with zero extent was │ │ │ │ │ - * selected. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - click: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: single │ │ │ │ │ - * {Boolean} Tells whether select by click should select a single │ │ │ │ │ - * feature. If set to false, all matching features are selected. │ │ │ │ │ - * If set to true, only the best matching feature is selected. │ │ │ │ │ - * This option has an effect only of the option is set │ │ │ │ │ - * to true. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - single: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: clickout │ │ │ │ │ - * {Boolean} Unselect features when clicking outside any feature. │ │ │ │ │ - * Applies only if is true. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - clickout: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: toggle │ │ │ │ │ - * {Boolean} Unselect a selected feature on click. Applies only if │ │ │ │ │ - * is true. Default is false. │ │ │ │ │ - */ │ │ │ │ │ - toggle: false, │ │ │ │ │ +OpenLayers.Control.Snapping = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: clickTolerance │ │ │ │ │ - * {Integer} Tolerance for the filter query in pixels. This has the │ │ │ │ │ - * same effect as the tolerance parameter on WMS GetFeatureInfo │ │ │ │ │ - * requests. Will be ignored for box selections. Applies only if │ │ │ │ │ - * or is true. Default is 5. Note that this not │ │ │ │ │ - * only affects requests on click, but also on hover. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * beforesnap - Triggered before a snap occurs. Listeners receive an │ │ │ │ │ + * event object with *point*, *x*, *y*, *distance*, *layer*, and │ │ │ │ │ + * *snapType* properties. The point property will be original point │ │ │ │ │ + * geometry considered for snapping. The x and y properties represent │ │ │ │ │ + * coordinates the point will receive. The distance is the distance │ │ │ │ │ + * of the snap. The layer is the target layer. The snapType property │ │ │ │ │ + * will be one of "node", "vertex", or "edge". Return false to stop │ │ │ │ │ + * snapping from occurring. │ │ │ │ │ + * snap - Triggered when a snap occurs. Listeners receive an event with │ │ │ │ │ + * *point*, *snapType*, *layer*, and *distance* properties. The point │ │ │ │ │ + * will be the location snapped to. The snapType will be one of "node", │ │ │ │ │ + * "vertex", or "edge". The layer will be the target layer. The │ │ │ │ │ + * distance will be the distance of the snap in map units. │ │ │ │ │ + * unsnap - Triggered when a vertex is unsnapped. Listeners receive an │ │ │ │ │ + * event with a *point* property. │ │ │ │ │ */ │ │ │ │ │ - clickTolerance: 5, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: hover │ │ │ │ │ - * {Boolean} Send feature requests on mouse moves. Default is false. │ │ │ │ │ + * CONSTANT: DEFAULTS │ │ │ │ │ + * Default target properties. │ │ │ │ │ */ │ │ │ │ │ - hover: false, │ │ │ │ │ + DEFAULTS: { │ │ │ │ │ + tolerance: 10, │ │ │ │ │ + node: true, │ │ │ │ │ + edge: true, │ │ │ │ │ + vertex: true │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: box │ │ │ │ │ - * {Boolean} Allow feature selection by drawing a box. If set to │ │ │ │ │ - * true set to false to disable the click handler and │ │ │ │ │ - * rely on the box handler only, even for "zero extent" boxes. │ │ │ │ │ - * See the description of the option for additional │ │ │ │ │ - * information. Default is false. │ │ │ │ │ + * Property: greedy │ │ │ │ │ + * {Boolean} Snap to closest feature in first layer with an eligible │ │ │ │ │ + * feature. Default is true. │ │ │ │ │ */ │ │ │ │ │ - box: false, │ │ │ │ │ + greedy: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: maxFeatures │ │ │ │ │ - * {Integer} Maximum number of features to return from a query in single mode │ │ │ │ │ - * if supported by the . This set of features is then used to │ │ │ │ │ - * determine the best match client-side. Default is 10. │ │ │ │ │ + * Property: precedence │ │ │ │ │ + * {Array} List representing precedence of different snapping types. │ │ │ │ │ + * Default is "node", "vertex", "edge". │ │ │ │ │ */ │ │ │ │ │ - maxFeatures: 10, │ │ │ │ │ + precedence: ["node", "vertex", "edge"], │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: features │ │ │ │ │ - * {Object} Hash of {}, keyed by fid, holding │ │ │ │ │ - * the currently selected features │ │ │ │ │ + * Property: resolution │ │ │ │ │ + * {Float} The map resolution for the previously considered snap. │ │ │ │ │ */ │ │ │ │ │ - features: null, │ │ │ │ │ + resolution: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Proeprty: hoverFeature │ │ │ │ │ - * {} The feature currently selected by the │ │ │ │ │ - * hover handler │ │ │ │ │ + * Property: geoToleranceCache │ │ │ │ │ + * {Object} A cache of geo-tolerances. Tolerance values (in map units) are │ │ │ │ │ + * calculated when the map resolution changes. │ │ │ │ │ */ │ │ │ │ │ - hoverFeature: null, │ │ │ │ │ + geoToleranceCache: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: handlerOptions │ │ │ │ │ - * {Object} Additional options for the handlers used by this control. This │ │ │ │ │ - * is a hash with the keys "click", "box" and "hover". │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} The current editable layer. Set at │ │ │ │ │ + * construction or after construction with . │ │ │ │ │ */ │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: handlers │ │ │ │ │ - * {Object} Object with references to multiple │ │ │ │ │ - * instances. │ │ │ │ │ + * Property: feature │ │ │ │ │ + * {} The current editable feature. │ │ │ │ │ */ │ │ │ │ │ - handlers: null, │ │ │ │ │ + feature: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: hoverResponse │ │ │ │ │ - * {} The response object associated with │ │ │ │ │ - * the currently running hover request (if any). │ │ │ │ │ + * Property: point │ │ │ │ │ + * {} The currently snapped vertex. │ │ │ │ │ */ │ │ │ │ │ - hoverResponse: null, │ │ │ │ │ + point: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: filterType │ │ │ │ │ - * {} The type of filter to use when sending off a request. │ │ │ │ │ - * Possible values: │ │ │ │ │ - * OpenLayers.Filter.Spatial. │ │ │ │ │ - * Defaults to: OpenLayers.Filter.Spatial.BBOX │ │ │ │ │ - */ │ │ │ │ │ - filterType: OpenLayers.Filter.Spatial.BBOX, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: events │ │ │ │ │ - * {} Events instance for listeners and triggering │ │ │ │ │ - * control specific events. │ │ │ │ │ + * Constructor: OpenLayers.Control.Snapping │ │ │ │ │ + * Creates a new snapping control. A control is constructed with an editable │ │ │ │ │ + * layer and a set of configuration objects for target layers. While the │ │ │ │ │ + * control is active, dragging vertices while drawing new features or │ │ │ │ │ + * modifying existing features on the editable layer will engage │ │ │ │ │ + * snapping to features on the target layers. Whether a vertex snaps to │ │ │ │ │ + * a feature on a target layer depends on the target layer configuration. │ │ │ │ │ * │ │ │ │ │ - * Register a listener for a particular event with the following syntax: │ │ │ │ │ - * (code) │ │ │ │ │ - * control.events.register(type, obj, listener); │ │ │ │ │ - * (end) │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An object containing all configuration properties for │ │ │ │ │ + * the control. │ │ │ │ │ * │ │ │ │ │ - * Supported event types (in addition to those from ): │ │ │ │ │ - * beforefeatureselected - Triggered when is true before a │ │ │ │ │ - * feature is selected. The event object has a feature property with │ │ │ │ │ - * the feature about to select │ │ │ │ │ - * featureselected - Triggered when is true and a feature is │ │ │ │ │ - * selected. The event object has a feature property with the │ │ │ │ │ - * selected feature │ │ │ │ │ - * beforefeaturesselected - Triggered when is true before a │ │ │ │ │ - * set of features is selected. The event object is an array of │ │ │ │ │ - * feature properties with the features about to be selected. │ │ │ │ │ - * Return false after receiving this event to discontinue processing │ │ │ │ │ - * of all featureselected events and the featuresselected event. │ │ │ │ │ - * featuresselected - Triggered when is true and a set of │ │ │ │ │ - * features is selected. The event object is an array of feature │ │ │ │ │ - * properties of the selected features │ │ │ │ │ - * featureunselected - Triggered when is true and a feature is │ │ │ │ │ - * unselected. The event object has a feature property with the │ │ │ │ │ - * unselected feature │ │ │ │ │ - * clickout - Triggered when when is true and no feature was │ │ │ │ │ - * selected. │ │ │ │ │ - * hoverfeature - Triggered when is true and the mouse has │ │ │ │ │ - * stopped over a feature │ │ │ │ │ - * outfeature - Triggered when is true and the mouse moves │ │ │ │ │ - * moved away from a hover-selected feature │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Control.GetFeature │ │ │ │ │ - * Create a new control for fetching remote features. │ │ │ │ │ + * Valid options: │ │ │ │ │ + * layer - {} The editable layer. Features from this │ │ │ │ │ + * layer that are digitized or modified may have vertices snapped to │ │ │ │ │ + * features from any of the target layers. │ │ │ │ │ + * targets - {Array(Object | OpenLayers.Layer.Vector)} A list of objects for │ │ │ │ │ + * configuring target layers. See valid properties of the target │ │ │ │ │ + * objects below. If the items in the targets list are vector layers │ │ │ │ │ + * (instead of configuration objects), the defaults from the │ │ │ │ │ + * property will apply. The editable layer itself may be a target │ │ │ │ │ + * layer, allowing newly created or edited features to be snapped to │ │ │ │ │ + * existing features from the same layer. If no targets are provided │ │ │ │ │ + * the layer given in the constructor (as ) will become the │ │ │ │ │ + * initial target. │ │ │ │ │ + * defaults - {Object} An object with default properties to be applied │ │ │ │ │ + * to all target objects. │ │ │ │ │ + * greedy - {Boolean} Snap to closest feature in first target layer that │ │ │ │ │ + * applies. Default is true. If false, all features in all target │ │ │ │ │ + * layers will be checked and the closest feature in all target layers │ │ │ │ │ + * will be chosen. The greedy property determines if the order of the │ │ │ │ │ + * target layers is significant. By default, the order of the target │ │ │ │ │ + * layers is significant where layers earlier in the target layer list │ │ │ │ │ + * have precedence over layers later in the list. Within a single │ │ │ │ │ + * layer, the closest feature is always chosen for snapping. This │ │ │ │ │ + * property only determines whether the search for a closer feature │ │ │ │ │ + * continues after an eligible feature is found in a target layer. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} A configuration object which at least has to contain │ │ │ │ │ - * a property (if not, it has to be set before a request is │ │ │ │ │ - * made) │ │ │ │ │ + * Valid target properties: │ │ │ │ │ + * layer - {} A target layer. Features from this │ │ │ │ │ + * layer will be eligible to act as snapping target for the editable │ │ │ │ │ + * layer. │ │ │ │ │ + * tolerance - {Float} The distance (in pixels) at which snapping may occur. │ │ │ │ │ + * Default is 10. │ │ │ │ │ + * node - {Boolean} Snap to nodes (first or last point in a geometry) in │ │ │ │ │ + * target layer. Default is true. │ │ │ │ │ + * nodeTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ + * for nodes specifically. If none is provided, will be │ │ │ │ │ + * used. │ │ │ │ │ + * vertex - {Boolean} Snap to vertices in target layer. Default is true. │ │ │ │ │ + * vertexTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ + * for vertices specifically. If none is provided, will be │ │ │ │ │ + * used. │ │ │ │ │ + * edge - {Boolean} Snap to edges in target layer. Default is true. │ │ │ │ │ + * edgeTolerance - {Float} Optional distance at which snapping may occur │ │ │ │ │ + * for edges specifically. If none is provided, will be │ │ │ │ │ + * used. │ │ │ │ │ + * filter - {} Optional filter to evaluate to determine if │ │ │ │ │ + * feature is eligible for snapping. If filter evaluates to true for a │ │ │ │ │ + * target feature a vertex may be snapped to the feature. │ │ │ │ │ + * minResolution - {Number} If a minResolution is provided, snapping to this │ │ │ │ │ + * target will only be considered if the map resolution is greater than │ │ │ │ │ + * or equal to this value (the minResolution is inclusive). Default is │ │ │ │ │ + * no minimum resolution limit. │ │ │ │ │ + * maxResolution - {Number} If a maxResolution is provided, snapping to this │ │ │ │ │ + * target will only be considered if the map resolution is strictly │ │ │ │ │ + * less than this value (the maxResolution is exclusive). Default is │ │ │ │ │ + * no maximum resolution limit. │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ - options.handlerOptions = options.handlerOptions || {}; │ │ │ │ │ - │ │ │ │ │ OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.options = options || {}; // TODO: this could be done by the super │ │ │ │ │ │ │ │ │ │ - this.features = {}; │ │ │ │ │ - │ │ │ │ │ - this.handlers = {}; │ │ │ │ │ - │ │ │ │ │ - if (this.click) { │ │ │ │ │ - this.handlers.click = new OpenLayers.Handler.Click(this, { │ │ │ │ │ - click: this.selectClick │ │ │ │ │ - }, this.handlerOptions.click || {}); │ │ │ │ │ + // set the editable layer if provided │ │ │ │ │ + if (this.options.layer) { │ │ │ │ │ + this.setLayer(this.options.layer); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - if (this.box) { │ │ │ │ │ - this.handlers.box = new OpenLayers.Handler.Box( │ │ │ │ │ - this, { │ │ │ │ │ - done: this.selectBox │ │ │ │ │ - }, │ │ │ │ │ - OpenLayers.Util.extend(this.handlerOptions.box, { │ │ │ │ │ - boxDivClassName: "olHandlerBoxSelectFeature" │ │ │ │ │ - }) │ │ │ │ │ - ); │ │ │ │ │ + // configure target layers │ │ │ │ │ + var defaults = OpenLayers.Util.extend({}, this.options.defaults); │ │ │ │ │ + this.defaults = OpenLayers.Util.applyDefaults(defaults, this.DEFAULTS); │ │ │ │ │ + this.setTargets(this.options.targets); │ │ │ │ │ + if (this.targets.length === 0 && this.layer) { │ │ │ │ │ + this.addTargetLayer(this.layer); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - if (this.hover) { │ │ │ │ │ - this.handlers.hover = new OpenLayers.Handler.Hover( │ │ │ │ │ - this, { │ │ │ │ │ - 'move': this.cancelHover, │ │ │ │ │ - 'pause': this.selectHover │ │ │ │ │ - }, │ │ │ │ │ - OpenLayers.Util.extend(this.handlerOptions.hover, { │ │ │ │ │ - 'delay': 250, │ │ │ │ │ - 'pixelTolerance': 2 │ │ │ │ │ - }) │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ + this.geoToleranceCache = {}; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: activate │ │ │ │ │ - * Activates the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The control was effectively activated. │ │ │ │ │ + * APIMethod: setLayer │ │ │ │ │ + * Set the editable layer. Call the setLayer method if the editable layer │ │ │ │ │ + * changes and the same control should be used on a new editable layer. │ │ │ │ │ + * If the control is already active, it will be active after the new │ │ │ │ │ + * layer is set. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} The new editable layer. │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - if (!this.active) { │ │ │ │ │ - for (var i in this.handlers) { │ │ │ │ │ - this.handlers[i].activate(); │ │ │ │ │ - } │ │ │ │ │ + setLayer: function(layer) { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + this.layer = layer; │ │ │ │ │ + this.activate(); │ │ │ │ │ + } else { │ │ │ │ │ + this.layer = layer; │ │ │ │ │ } │ │ │ │ │ - return OpenLayers.Control.prototype.activate.apply( │ │ │ │ │ - this, arguments │ │ │ │ │ - ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: deactivate │ │ │ │ │ - * Deactivates the control. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The control was effectively deactivated. │ │ │ │ │ + * Method: setTargets │ │ │ │ │ + * Set the targets for the snapping agent. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * targets - {Array} An array of target configs or target layers. │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - if (this.active) { │ │ │ │ │ - for (var i in this.handlers) { │ │ │ │ │ - this.handlers[i].deactivate(); │ │ │ │ │ + setTargets: function(targets) { │ │ │ │ │ + this.targets = []; │ │ │ │ │ + if (targets && targets.length) { │ │ │ │ │ + var target; │ │ │ │ │ + for (var i = 0, len = targets.length; i < len; ++i) { │ │ │ │ │ + target = targets[i]; │ │ │ │ │ + if (target instanceof OpenLayers.Layer.Vector) { │ │ │ │ │ + this.addTargetLayer(target); │ │ │ │ │ + } else { │ │ │ │ │ + this.addTarget(target); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - return OpenLayers.Control.prototype.deactivate.apply( │ │ │ │ │ - this, arguments │ │ │ │ │ - ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: selectClick │ │ │ │ │ - * Called on click │ │ │ │ │ + * Method: addTargetLayer │ │ │ │ │ + * Add a target layer with the default target config. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * layer - {} A target layer. │ │ │ │ │ */ │ │ │ │ │ - selectClick: function(evt) { │ │ │ │ │ - var bounds = this.pixelToBounds(evt.xy); │ │ │ │ │ - │ │ │ │ │ - this.setModifiers(evt); │ │ │ │ │ - this.request(bounds, { │ │ │ │ │ - single: this.single │ │ │ │ │ + addTargetLayer: function(layer) { │ │ │ │ │ + this.addTarget({ │ │ │ │ │ + layer: layer │ │ │ │ │ }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: selectBox │ │ │ │ │ - * Callback from the handlers.box set up when selection is on │ │ │ │ │ + * Method: addTarget │ │ │ │ │ + * Add a configured target layer. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * position - {|Object} An OpenLayers.Bounds or │ │ │ │ │ - * an object with a 'left', 'bottom', 'right' and 'top' properties. │ │ │ │ │ + * target - {Object} A target config. │ │ │ │ │ */ │ │ │ │ │ - selectBox: function(position) { │ │ │ │ │ - var bounds; │ │ │ │ │ - if (position instanceof OpenLayers.Bounds) { │ │ │ │ │ - var minXY = this.map.getLonLatFromPixel({ │ │ │ │ │ - x: position.left, │ │ │ │ │ - y: position.bottom │ │ │ │ │ - }); │ │ │ │ │ - var maxXY = this.map.getLonLatFromPixel({ │ │ │ │ │ - x: position.right, │ │ │ │ │ - y: position.top │ │ │ │ │ - }); │ │ │ │ │ - bounds = new OpenLayers.Bounds( │ │ │ │ │ - minXY.lon, minXY.lat, maxXY.lon, maxXY.lat │ │ │ │ │ - ); │ │ │ │ │ + addTarget: function(target) { │ │ │ │ │ + target = OpenLayers.Util.applyDefaults(target, this.defaults); │ │ │ │ │ + target.nodeTolerance = target.nodeTolerance || target.tolerance; │ │ │ │ │ + target.vertexTolerance = target.vertexTolerance || target.tolerance; │ │ │ │ │ + target.edgeTolerance = target.edgeTolerance || target.tolerance; │ │ │ │ │ + this.targets.push(target); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - } else { │ │ │ │ │ - if (this.click) { │ │ │ │ │ - // box without extent - let the click handler take care of it │ │ │ │ │ - return; │ │ │ │ │ + /** │ │ │ │ │ + * Method: removeTargetLayer │ │ │ │ │ + * Remove a target layer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * layer - {} The target layer to remove. │ │ │ │ │ + */ │ │ │ │ │ + removeTargetLayer: function(layer) { │ │ │ │ │ + var target; │ │ │ │ │ + for (var i = this.targets.length - 1; i >= 0; --i) { │ │ │ │ │ + target = this.targets[i]; │ │ │ │ │ + if (target.layer === layer) { │ │ │ │ │ + this.removeTarget(target); │ │ │ │ │ } │ │ │ │ │ - bounds = this.pixelToBounds(position); │ │ │ │ │ } │ │ │ │ │ - this.setModifiers(this.handlers.box.dragHandler.evt); │ │ │ │ │ - this.request(bounds); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: selectHover │ │ │ │ │ - * Callback from the handlers.hover set up when selection is on │ │ │ │ │ + * Method: removeTarget │ │ │ │ │ + * Remove a target. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} event object with an xy property │ │ │ │ │ + * target - {Object} A target config. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Array} The targets array. │ │ │ │ │ */ │ │ │ │ │ - selectHover: function(evt) { │ │ │ │ │ - var bounds = this.pixelToBounds(evt.xy); │ │ │ │ │ - this.request(bounds, { │ │ │ │ │ - single: true, │ │ │ │ │ - hover: true │ │ │ │ │ - }); │ │ │ │ │ + removeTarget: function(target) { │ │ │ │ │ + return OpenLayers.Util.removeItem(this.targets, target); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cancelHover │ │ │ │ │ - * Callback from the handlers.hover set up when selection is on │ │ │ │ │ - */ │ │ │ │ │ - cancelHover: function() { │ │ │ │ │ - if (this.hoverResponse) { │ │ │ │ │ - this.protocol.abort(this.hoverResponse); │ │ │ │ │ - this.hoverResponse = null; │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Activate the control. Activating the control registers listeners for │ │ │ │ │ + * editing related events so that during feature creation and │ │ │ │ │ + * modification, moving vertices will trigger snapping. │ │ │ │ │ + */ │ │ │ │ │ + activate: function() { │ │ │ │ │ + var activated = OpenLayers.Control.prototype.activate.call(this); │ │ │ │ │ + if (activated) { │ │ │ │ │ + if (this.layer && this.layer.events) { │ │ │ │ │ + this.layer.events.on({ │ │ │ │ │ + sketchstarted: this.onSketchModified, │ │ │ │ │ + sketchmodified: this.onSketchModified, │ │ │ │ │ + vertexmodified: this.onVertexModified, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: request │ │ │ │ │ - * Sends a GetFeature request to the WFS │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} bounds for the request's BBOX filter │ │ │ │ │ - * options - {Object} additional options for this method. │ │ │ │ │ - * │ │ │ │ │ - * Supported options include: │ │ │ │ │ - * single - {Boolean} A single feature should be returned. │ │ │ │ │ - * Note that this will be ignored if the protocol does not │ │ │ │ │ - * return the geometries of the features. │ │ │ │ │ - * hover - {Boolean} Do the request for the hover handler. │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the control. Deactivating the control unregisters listeners │ │ │ │ │ + * so feature editing may proceed without engaging the snapping agent. │ │ │ │ │ */ │ │ │ │ │ - request: function(bounds, options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - var filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ - type: this.filterType, │ │ │ │ │ - value: bounds │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - // Set the cursor to "wait" to tell the user we're working. │ │ │ │ │ - OpenLayers.Element.addClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - │ │ │ │ │ - var response = this.protocol.read({ │ │ │ │ │ - maxFeatures: options.single == true ? this.maxFeatures : undefined, │ │ │ │ │ - filter: filter, │ │ │ │ │ - callback: function(result) { │ │ │ │ │ - if (result.success()) { │ │ │ │ │ - if (result.features.length) { │ │ │ │ │ - if (options.single == true) { │ │ │ │ │ - this.selectBestFeature(result.features, │ │ │ │ │ - bounds.getCenterLonLat(), options); │ │ │ │ │ - } else { │ │ │ │ │ - this.select(result.features); │ │ │ │ │ - } │ │ │ │ │ - } else if (options.hover) { │ │ │ │ │ - this.hoverSelect(); │ │ │ │ │ - } else { │ │ │ │ │ - this.events.triggerEvent("clickout"); │ │ │ │ │ - if (this.clickout) { │ │ │ │ │ - this.unselectAll(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // Reset the cursor. │ │ │ │ │ - OpenLayers.Element.removeClass(this.map.viewPortDiv, "olCursorWait"); │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - if (options.hover == true) { │ │ │ │ │ - this.hoverResponse = response; │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = OpenLayers.Control.prototype.deactivate.call(this); │ │ │ │ │ + if (deactivated) { │ │ │ │ │ + if (this.layer && this.layer.events) { │ │ │ │ │ + this.layer.events.un({ │ │ │ │ │ + sketchstarted: this.onSketchModified, │ │ │ │ │ + sketchmodified: this.onSketchModified, │ │ │ │ │ + vertexmodified: this.onVertexModified, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + this.feature = null; │ │ │ │ │ + this.point = null; │ │ │ │ │ + return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: selectBestFeature │ │ │ │ │ - * Selects the feature from an array of features that is the best match │ │ │ │ │ - * for the click position. │ │ │ │ │ - * │ │ │ │ │ + * Method: onSketchModified │ │ │ │ │ + * Registered as a listener for the sketchmodified event on the editable │ │ │ │ │ + * layer. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {Array()} │ │ │ │ │ - * clickPosition - {} │ │ │ │ │ - * options - {Object} additional options for this method │ │ │ │ │ - * │ │ │ │ │ - * Supported options include: │ │ │ │ │ - * hover - {Boolean} Do the selection for the hover handler. │ │ │ │ │ + * event - {Object} The sketch modified event. │ │ │ │ │ */ │ │ │ │ │ - selectBestFeature: function(features, clickPosition, options) { │ │ │ │ │ - options = options || {}; │ │ │ │ │ - if (features.length) { │ │ │ │ │ - var point = new OpenLayers.Geometry.Point(clickPosition.lon, │ │ │ │ │ - clickPosition.lat); │ │ │ │ │ - var feature, resultFeature, dist; │ │ │ │ │ - var minDist = Number.MAX_VALUE; │ │ │ │ │ - for (var i = 0; i < features.length; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - if (feature.geometry) { │ │ │ │ │ - dist = point.distanceTo(feature.geometry, { │ │ │ │ │ - edge: false │ │ │ │ │ - }); │ │ │ │ │ - if (dist < minDist) { │ │ │ │ │ - minDist = dist; │ │ │ │ │ - resultFeature = feature; │ │ │ │ │ - if (minDist == 0) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (options.hover == true) { │ │ │ │ │ - this.hoverSelect(resultFeature); │ │ │ │ │ - } else { │ │ │ │ │ - this.select(resultFeature || features); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + onSketchModified: function(event) { │ │ │ │ │ + this.feature = event.feature; │ │ │ │ │ + this.considerSnapping(event.vertex, event.vertex); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setModifiers │ │ │ │ │ - * Sets the multiple and toggle modifiers according to the current event │ │ │ │ │ - * │ │ │ │ │ + * Method: onVertexModified │ │ │ │ │ + * Registered as a listener for the vertexmodified event on the editable │ │ │ │ │ + * layer. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * event - {Object} The vertex modified event. │ │ │ │ │ */ │ │ │ │ │ - setModifiers: function(evt) { │ │ │ │ │ - this.modifiers = { │ │ │ │ │ - multiple: this.multiple || (this.multipleKey && evt[this.multipleKey]), │ │ │ │ │ - toggle: this.toggle || (this.toggleKey && evt[this.toggleKey]) │ │ │ │ │ - }; │ │ │ │ │ + onVertexModified: function(event) { │ │ │ │ │ + this.feature = event.feature; │ │ │ │ │ + var loc = this.layer.map.getLonLatFromViewPortPx(event.pixel); │ │ │ │ │ + this.considerSnapping( │ │ │ │ │ + event.vertex, new OpenLayers.Geometry.Point(loc.lon, loc.lat) │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: select │ │ │ │ │ - * Add feature to the hash of selected features and trigger the │ │ │ │ │ - * featureselected and featuresselected events. │ │ │ │ │ - * │ │ │ │ │ + * Method: considerSnapping │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * features - {} or an array of features │ │ │ │ │ + * point - {} The vertex to be snapped (or │ │ │ │ │ + * unsnapped). │ │ │ │ │ + * loc - {} The location of the mouse in map │ │ │ │ │ + * coords. │ │ │ │ │ */ │ │ │ │ │ - select: function(features) { │ │ │ │ │ - if (!this.modifiers.multiple && !this.modifiers.toggle) { │ │ │ │ │ - this.unselectAll(); │ │ │ │ │ - } │ │ │ │ │ - if (!(OpenLayers.Util.isArray(features))) { │ │ │ │ │ - features = [features]; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var cont = this.events.triggerEvent("beforefeaturesselected", { │ │ │ │ │ - features: features │ │ │ │ │ - }); │ │ │ │ │ - if (cont !== false) { │ │ │ │ │ - var selectedFeatures = []; │ │ │ │ │ - var feature; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - if (this.features[feature.fid || feature.id]) { │ │ │ │ │ - if (this.modifiers.toggle) { │ │ │ │ │ - this.unselect(this.features[feature.fid || feature.id]); │ │ │ │ │ - } │ │ │ │ │ + considerSnapping: function(point, loc) { │ │ │ │ │ + var best = { │ │ │ │ │ + rank: Number.POSITIVE_INFINITY, │ │ │ │ │ + dist: Number.POSITIVE_INFINITY, │ │ │ │ │ + x: null, │ │ │ │ │ + y: null │ │ │ │ │ + }; │ │ │ │ │ + var snapped = false; │ │ │ │ │ + var result, target; │ │ │ │ │ + for (var i = 0, len = this.targets.length; i < len; ++i) { │ │ │ │ │ + target = this.targets[i]; │ │ │ │ │ + result = this.testTarget(target, loc); │ │ │ │ │ + if (result) { │ │ │ │ │ + if (this.greedy) { │ │ │ │ │ + best = result; │ │ │ │ │ + best.target = target; │ │ │ │ │ + snapped = true; │ │ │ │ │ + break; │ │ │ │ │ } else { │ │ │ │ │ - cont = this.events.triggerEvent("beforefeatureselected", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - if (cont !== false) { │ │ │ │ │ - this.features[feature.fid || feature.id] = feature; │ │ │ │ │ - selectedFeatures.push(feature); │ │ │ │ │ - │ │ │ │ │ - this.events.triggerEvent("featureselected", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ + if ((result.rank < best.rank) || │ │ │ │ │ + (result.rank === best.rank && result.dist < best.dist)) { │ │ │ │ │ + best = result; │ │ │ │ │ + best.target = target; │ │ │ │ │ + snapped = true; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - this.events.triggerEvent("featuresselected", { │ │ │ │ │ - features: selectedFeatures │ │ │ │ │ - }); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: hoverSelect │ │ │ │ │ - * Sets/unsets the │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * feature - {} the feature to hover-select. │ │ │ │ │ - * If none is provided, the current will be nulled and │ │ │ │ │ - * the outfeature event will be triggered. │ │ │ │ │ - */ │ │ │ │ │ - hoverSelect: function(feature) { │ │ │ │ │ - var fid = feature ? feature.fid || feature.id : null; │ │ │ │ │ - var hfid = this.hoverFeature ? │ │ │ │ │ - this.hoverFeature.fid || this.hoverFeature.id : null; │ │ │ │ │ - │ │ │ │ │ - if (hfid && hfid != fid) { │ │ │ │ │ - this.events.triggerEvent("outfeature", { │ │ │ │ │ - feature: this.hoverFeature │ │ │ │ │ + if (snapped) { │ │ │ │ │ + var proceed = this.events.triggerEvent("beforesnap", { │ │ │ │ │ + point: point, │ │ │ │ │ + x: best.x, │ │ │ │ │ + y: best.y, │ │ │ │ │ + distance: best.dist, │ │ │ │ │ + layer: best.target.layer, │ │ │ │ │ + snapType: this.precedence[best.rank] │ │ │ │ │ }); │ │ │ │ │ - this.hoverFeature = null; │ │ │ │ │ + if (proceed !== false) { │ │ │ │ │ + point.x = best.x; │ │ │ │ │ + point.y = best.y; │ │ │ │ │ + this.point = point; │ │ │ │ │ + this.events.triggerEvent("snap", { │ │ │ │ │ + point: point, │ │ │ │ │ + snapType: this.precedence[best.rank], │ │ │ │ │ + layer: best.target.layer, │ │ │ │ │ + distance: best.dist │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + snapped = false; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - if (fid && fid != hfid) { │ │ │ │ │ - this.events.triggerEvent("hoverfeature", { │ │ │ │ │ - feature: feature │ │ │ │ │ + if (this.point && !snapped) { │ │ │ │ │ + point.x = loc.x; │ │ │ │ │ + point.y = loc.y; │ │ │ │ │ + this.point = null; │ │ │ │ │ + this.events.triggerEvent("unsnap", { │ │ │ │ │ + point: point │ │ │ │ │ }); │ │ │ │ │ - this.hoverFeature = feature; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: unselect │ │ │ │ │ - * Remove feature from the hash of selected features and trigger the │ │ │ │ │ - * featureunselected event. │ │ │ │ │ + * Method: testTarget │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * feature - {} │ │ │ │ │ - */ │ │ │ │ │ - unselect: function(feature) { │ │ │ │ │ - delete this.features[feature.fid || feature.id]; │ │ │ │ │ - this.events.triggerEvent("featureunselected", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: unselectAll │ │ │ │ │ - * Unselect all selected features. │ │ │ │ │ + * target - {Object} Object with target layer configuration. │ │ │ │ │ + * loc - {} The location of the mouse in map │ │ │ │ │ + * coords. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} A result object with rank, dist, x, and y properties. │ │ │ │ │ + * Returns null if candidate is not eligible for snapping. │ │ │ │ │ */ │ │ │ │ │ - unselectAll: function() { │ │ │ │ │ - // we'll want an option to supress notification here │ │ │ │ │ - for (var fid in this.features) { │ │ │ │ │ - this.unselect(this.features[fid]); │ │ │ │ │ + testTarget: function(target, loc) { │ │ │ │ │ + var resolution = this.layer.map.getResolution(); │ │ │ │ │ + if ("minResolution" in target) { │ │ │ │ │ + if (resolution < target.minResolution) { │ │ │ │ │ + return null; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if ("maxResolution" in target) { │ │ │ │ │ + if (resolution >= target.maxResolution) { │ │ │ │ │ + return null; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var tolerance = { │ │ │ │ │ + node: this.getGeoTolerance(target.nodeTolerance, resolution), │ │ │ │ │ + vertex: this.getGeoTolerance(target.vertexTolerance, resolution), │ │ │ │ │ + edge: this.getGeoTolerance(target.edgeTolerance, resolution) │ │ │ │ │ + }; │ │ │ │ │ + // this could be cached if we don't support setting tolerance values directly │ │ │ │ │ + var maxTolerance = Math.max( │ │ │ │ │ + tolerance.node, tolerance.vertex, tolerance.edge │ │ │ │ │ + ); │ │ │ │ │ + var result = { │ │ │ │ │ + rank: Number.POSITIVE_INFINITY, │ │ │ │ │ + dist: Number.POSITIVE_INFINITY │ │ │ │ │ + }; │ │ │ │ │ + var eligible = false; │ │ │ │ │ + var features = target.layer.features; │ │ │ │ │ + var feature, type, vertices, vertex, closest, dist, found; │ │ │ │ │ + var numTypes = this.precedence.length; │ │ │ │ │ + var ll = new OpenLayers.LonLat(loc.x, loc.y); │ │ │ │ │ + for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ + feature = features[i]; │ │ │ │ │ + if (feature !== this.feature && !feature._sketch && │ │ │ │ │ + feature.state !== OpenLayers.State.DELETE && │ │ │ │ │ + (!target.filter || target.filter.evaluate(feature))) { │ │ │ │ │ + if (feature.atPoint(ll, maxTolerance, maxTolerance)) { │ │ │ │ │ + for (var j = 0, stop = Math.min(result.rank + 1, numTypes); j < stop; ++j) { │ │ │ │ │ + type = this.precedence[j]; │ │ │ │ │ + if (target[type]) { │ │ │ │ │ + if (type === "edge") { │ │ │ │ │ + closest = feature.geometry.distanceTo(loc, { │ │ │ │ │ + details: true │ │ │ │ │ + }); │ │ │ │ │ + dist = closest.distance; │ │ │ │ │ + if (dist <= tolerance[type] && dist < result.dist) { │ │ │ │ │ + result = { │ │ │ │ │ + rank: j, │ │ │ │ │ + dist: dist, │ │ │ │ │ + x: closest.x0, │ │ │ │ │ + y: closest.y0 // closest coords on feature │ │ │ │ │ + }; │ │ │ │ │ + eligible = true; │ │ │ │ │ + // don't look for lower precedence types for this feature │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // look for nodes or vertices │ │ │ │ │ + vertices = feature.geometry.getVertices(type === "node"); │ │ │ │ │ + found = false; │ │ │ │ │ + for (var k = 0, klen = vertices.length; k < klen; ++k) { │ │ │ │ │ + vertex = vertices[k]; │ │ │ │ │ + dist = vertex.distanceTo(loc); │ │ │ │ │ + if (dist <= tolerance[type] && │ │ │ │ │ + (j < result.rank || (j === result.rank && dist < result.dist))) { │ │ │ │ │ + result = { │ │ │ │ │ + rank: j, │ │ │ │ │ + dist: dist, │ │ │ │ │ + x: vertex.x, │ │ │ │ │ + y: vertex.y │ │ │ │ │ + }; │ │ │ │ │ + eligible = true; │ │ │ │ │ + found = true; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (found) { │ │ │ │ │ + // don't look for lower precedence types for this feature │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ + return eligible ? result : null; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: getGeoTolerance │ │ │ │ │ + * Calculate a tolerance in map units given a tolerance in pixels. This │ │ │ │ │ + * takes advantage of the when the map resolution │ │ │ │ │ + * has not changed. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * tolerance - {Number} A tolerance value in pixels. │ │ │ │ │ + * resolution - {Number} Map resolution. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Number} A tolerance value in map units. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - for (var i in this.handlers) { │ │ │ │ │ - this.handlers[i].setMap(map); │ │ │ │ │ + getGeoTolerance: function(tolerance, resolution) { │ │ │ │ │ + if (resolution !== this.resolution) { │ │ │ │ │ + this.resolution = resolution; │ │ │ │ │ + this.geoToleranceCache = {}; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + var geoTolerance = this.geoToleranceCache[tolerance]; │ │ │ │ │ + if (geoTolerance === undefined) { │ │ │ │ │ + geoTolerance = tolerance * resolution; │ │ │ │ │ + this.geoToleranceCache[tolerance] = geoTolerance; │ │ │ │ │ + } │ │ │ │ │ + return geoTolerance; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: pixelToBounds │ │ │ │ │ - * Takes a pixel as argument and creates bounds after adding the │ │ │ │ │ - * . │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * pixel - {} │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * Clean up the control. │ │ │ │ │ */ │ │ │ │ │ - pixelToBounds: function(pixel) { │ │ │ │ │ - var llPx = pixel.add(-this.clickTolerance / 2, this.clickTolerance / 2); │ │ │ │ │ - var urPx = pixel.add(this.clickTolerance / 2, -this.clickTolerance / 2); │ │ │ │ │ - var ll = this.map.getLonLatFromPixel(llPx); │ │ │ │ │ - var ur = this.map.getLonLatFromPixel(urPx); │ │ │ │ │ - return new OpenLayers.Bounds(ll.lon, ll.lat, ur.lon, ur.lat); │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.deactivate(); // TODO: this should be handled by the super │ │ │ │ │ + } │ │ │ │ │ + delete this.layer; │ │ │ │ │ + delete this.targets; │ │ │ │ │ + OpenLayers.Control.prototype.destroy.call(this); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.GetFeature" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Snapping" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Control/NavigationHistory.js │ │ │ │ │ + OpenLayers/Control/ZoomIn.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Control.js │ │ │ │ │ * @requires OpenLayers/Control/Button.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Control.NavigationHistory │ │ │ │ │ - * A navigation history control. This is a meta-control, that creates two │ │ │ │ │ - * dependent controls: and . Call the trigger method │ │ │ │ │ - * on the and controls to restore previous and next │ │ │ │ │ - * history states. The previous and next controls will become active │ │ │ │ │ - * when there are available states to restore and will become deactive │ │ │ │ │ - * when there are no states to restore. │ │ │ │ │ + * Class: OpenLayers.Control.ZoomIn │ │ │ │ │ + * The ZoomIn control is a button to increase the zoom level of a map. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: type │ │ │ │ │ - * {String} Note that this control is not intended to be added directly │ │ │ │ │ - * to a control panel. Instead, add the sub-controls previous and │ │ │ │ │ - * next. These sub-controls are button type controls that activate │ │ │ │ │ - * and deactivate themselves. If this parent control is added to │ │ │ │ │ - * a panel, it will act as a toggle. │ │ │ │ │ - */ │ │ │ │ │ - type: OpenLayers.Control.TYPE_TOGGLE, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: previous │ │ │ │ │ - * {} A button type control whose trigger method restores │ │ │ │ │ - * the previous state managed by this control. │ │ │ │ │ - */ │ │ │ │ │ - previous: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: previousOptions │ │ │ │ │ - * {Object} Set this property on the options argument of the constructor │ │ │ │ │ - * to set optional properties on the control. │ │ │ │ │ - */ │ │ │ │ │ - previousOptions: null, │ │ │ │ │ +OpenLayers.Control.ZoomIn = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: next │ │ │ │ │ - * {} A button type control whose trigger method restores │ │ │ │ │ - * the next state managed by this control. │ │ │ │ │ + * Method: trigger │ │ │ │ │ */ │ │ │ │ │ - next: null, │ │ │ │ │ + trigger: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.zoomIn(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: nextOptions │ │ │ │ │ - * {Object} Set this property on the options argument of the constructor │ │ │ │ │ - * to set optional properties on the control. │ │ │ │ │ - */ │ │ │ │ │ - nextOptions: null, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ZoomIn" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/ZoomOut.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: limit │ │ │ │ │ - * {Integer} Optional limit on the number of history items to retain. If │ │ │ │ │ - * null, there is no limit. Default is 50. │ │ │ │ │ - */ │ │ │ │ │ - limit: 50, │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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: autoActivate │ │ │ │ │ - * {Boolean} Activate the control when it is added to a map. Default is │ │ │ │ │ - * true. │ │ │ │ │ - */ │ │ │ │ │ - autoActivate: true, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control/Button.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: clearOnDeactivate │ │ │ │ │ - * {Boolean} Clear the history when the control is deactivated. Default │ │ │ │ │ - * is false. │ │ │ │ │ - */ │ │ │ │ │ - clearOnDeactivate: false, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.ZoomOut │ │ │ │ │ + * The ZoomOut control is a button to decrease the zoom level of a map. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ZoomOut = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: registry │ │ │ │ │ - * {Object} An object with keys corresponding to event types. Values │ │ │ │ │ - * are functions that return an object representing the current state. │ │ │ │ │ + * Method: trigger │ │ │ │ │ */ │ │ │ │ │ - registry: null, │ │ │ │ │ + trigger: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.zoomOut(); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: nextStack │ │ │ │ │ - * {Array} Array of items in the history. │ │ │ │ │ - */ │ │ │ │ │ - nextStack: null, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ZoomOut" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/ZoomPanel.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: previousStack │ │ │ │ │ - * {Array} List of items in the history. First item represents the current │ │ │ │ │ - * state. │ │ │ │ │ - */ │ │ │ │ │ - previousStack: null, │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: listeners │ │ │ │ │ - * {Object} An object containing properties corresponding to event types. │ │ │ │ │ - * This object is used to configure the control and is modified on │ │ │ │ │ - * construction. │ │ │ │ │ - */ │ │ │ │ │ - listeners: null, │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control/Panel.js │ │ │ │ │ + * @requires OpenLayers/Control/ZoomIn.js │ │ │ │ │ + * @requires OpenLayers/Control/ZoomOut.js │ │ │ │ │ + * @requires OpenLayers/Control/ZoomToMaxExtent.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: restoring │ │ │ │ │ - * {Boolean} Currently restoring a history state. This is set to true │ │ │ │ │ - * before calling restore and set to false after restore returns. │ │ │ │ │ - */ │ │ │ │ │ - restoring: false, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.ZoomPanel │ │ │ │ │ + * The ZoomPanel control is a compact collecton of 3 zoom controls: a │ │ │ │ │ + * , a , and a │ │ │ │ │ + * . By default it is drawn in the upper left │ │ │ │ │ + * corner of the map. │ │ │ │ │ + * │ │ │ │ │ + * Note: │ │ │ │ │ + * If you wish to use this class with the default images and you want │ │ │ │ │ + * it to look nice in ie6, you should add the following, conditionally │ │ │ │ │ + * added css stylesheet to your HTML file: │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.ZoomPanel = OpenLayers.Class(OpenLayers.Control.Panel, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Control.NavigationHistory │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Control.ZoomPanel │ │ │ │ │ + * Add the three zooming controls. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ * options - {Object} An optional object whose properties will be used │ │ │ │ │ * to extend the control. │ │ │ │ │ */ │ │ │ │ │ initialize: function(options) { │ │ │ │ │ - OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.addControls([ │ │ │ │ │ + new OpenLayers.Control.ZoomIn(), │ │ │ │ │ + new OpenLayers.Control.ZoomToMaxExtent(), │ │ │ │ │ + new OpenLayers.Control.ZoomOut() │ │ │ │ │ + ]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - this.registry = OpenLayers.Util.extend({ │ │ │ │ │ - "moveend": this.getState │ │ │ │ │ - }, this.registry); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.ZoomPanel" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/NavToolbar.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - var previousOptions = { │ │ │ │ │ - trigger: OpenLayers.Function.bind(this.previousTrigger, this), │ │ │ │ │ - displayClass: this.displayClass + " " + this.displayClass + "Previous" │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Util.extend(previousOptions, this.previousOptions); │ │ │ │ │ - this.previous = new OpenLayers.Control.Button(previousOptions); │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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 nextOptions = { │ │ │ │ │ - trigger: OpenLayers.Function.bind(this.nextTrigger, this), │ │ │ │ │ - displayClass: this.displayClass + " " + this.displayClass + "Next" │ │ │ │ │ - }; │ │ │ │ │ - OpenLayers.Util.extend(nextOptions, this.nextOptions); │ │ │ │ │ - this.next = new OpenLayers.Control.Button(nextOptions); │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control/Panel.js │ │ │ │ │ + * @requires OpenLayers/Control/Navigation.js │ │ │ │ │ + * @requires OpenLayers/Control/ZoomBox.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - this.clear(); │ │ │ │ │ - }, │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.NavToolbar │ │ │ │ │ + * This Toolbar is an alternative to the Navigation control that displays │ │ │ │ │ + * the state of the control, and provides a UI for changing state to │ │ │ │ │ + * use the zoomBox via a Panel control. │ │ │ │ │ + * │ │ │ │ │ + * If you wish to change the properties of the Navigation control used │ │ │ │ │ + * in the NavToolbar, see: │ │ │ │ │ + * http://trac.openlayers.org/wiki/Toolbars#SubclassingNavToolbar │ │ │ │ │ + * │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.NavToolbar = OpenLayers.Class(OpenLayers.Control.Panel, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onPreviousChange │ │ │ │ │ - * Called when the previous history stack changes. │ │ │ │ │ + * Constructor: OpenLayers.Control.NavToolbar │ │ │ │ │ + * Add our two mousedefaults controls. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * state - {Object} An object representing the state to be restored │ │ │ │ │ - * if previous is triggered again or null if no previous states remain. │ │ │ │ │ - * length - {Integer} The number of remaining previous states that can │ │ │ │ │ - * be restored. │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ */ │ │ │ │ │ - onPreviousChange: function(state, length) { │ │ │ │ │ - if (state && !this.previous.active) { │ │ │ │ │ - this.previous.activate(); │ │ │ │ │ - } else if (!state && this.previous.active) { │ │ │ │ │ - this.previous.deactivate(); │ │ │ │ │ - } │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.addControls([ │ │ │ │ │ + new OpenLayers.Control.Navigation(), │ │ │ │ │ + new OpenLayers.Control.ZoomBox() │ │ │ │ │ + ]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onNextChange │ │ │ │ │ - * Called when the next history stack changes. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * state - {Object} An object representing the state to be restored │ │ │ │ │ - * if next is triggered again or null if no next states remain. │ │ │ │ │ - * length - {Integer} The number of remaining next states that can │ │ │ │ │ - * be restored. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * calls the default draw, and then activates mouse defaults. │ │ │ │ │ */ │ │ │ │ │ - onNextChange: function(state, length) { │ │ │ │ │ - if (state && !this.next.active) { │ │ │ │ │ - this.next.activate(); │ │ │ │ │ - } else if (!state && this.next.active) { │ │ │ │ │ - this.next.deactivate(); │ │ │ │ │ + draw: function() { │ │ │ │ │ + var div = OpenLayers.Control.Panel.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (this.defaultControl === null) { │ │ │ │ │ + this.defaultControl = this.controls[0]; │ │ │ │ │ } │ │ │ │ │ + return div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Destroy the control. │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.NavToolbar" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/Pan.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control/Button.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.Pan │ │ │ │ │ + * The Pan control is a single button to pan the map in one direction. For │ │ │ │ │ + * a more complete control see . │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.Pan = OpenLayers.Class(OpenLayers.Control.Button, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: slideFactor │ │ │ │ │ + * {Integer} Number of pixels by which we'll pan the map in any direction │ │ │ │ │ + * on clicking the arrow buttons, defaults to 50. If you want to pan │ │ │ │ │ + * by some ratio of the map dimensions, use instead. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - OpenLayers.Control.prototype.destroy.apply(this); │ │ │ │ │ - this.previous.destroy(); │ │ │ │ │ - this.next.destroy(); │ │ │ │ │ - this.deactivate(); │ │ │ │ │ - for (var prop in this) { │ │ │ │ │ - this[prop] = null; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + slideFactor: 50, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the control and and child │ │ │ │ │ - * controls. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * APIProperty: slideRatio │ │ │ │ │ + * {Number} The fraction of map width/height by which we'll pan the map │ │ │ │ │ + * on clicking the arrow buttons. Default is null. If set, will │ │ │ │ │ + * override . E.g. if slideRatio is .5, then Pan Up will │ │ │ │ │ + * pan up half the map height. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - this.map = map; │ │ │ │ │ - this.next.setMap(map); │ │ │ │ │ - this.previous.setMap(map); │ │ │ │ │ - }, │ │ │ │ │ + slideRatio: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Called when the control is added to the map. │ │ │ │ │ + /** │ │ │ │ │ + * Property: direction │ │ │ │ │ + * {String} in {'North', 'South', 'East', 'West'} │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ - this.next.draw(); │ │ │ │ │ - this.previous.draw(); │ │ │ │ │ - }, │ │ │ │ │ + direction: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: previousTrigger │ │ │ │ │ - * Restore the previous state. If no items are in the previous history │ │ │ │ │ - * stack, this has no effect. │ │ │ │ │ + * Constructor: OpenLayers.Control.Pan │ │ │ │ │ + * Control which handles the panning (in any of the cardinal directions) │ │ │ │ │ + * of the map by a set px distance. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Item representing state that was restored. Undefined if no │ │ │ │ │ - * items are in the previous history stack. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * direction - {String} The direction this button should pan. │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ */ │ │ │ │ │ - previousTrigger: function() { │ │ │ │ │ - var current = this.previousStack.shift(); │ │ │ │ │ - var state = this.previousStack.shift(); │ │ │ │ │ - if (state != undefined) { │ │ │ │ │ - this.nextStack.unshift(current); │ │ │ │ │ - this.previousStack.unshift(state); │ │ │ │ │ - this.restoring = true; │ │ │ │ │ - this.restore(state); │ │ │ │ │ - this.restoring = false; │ │ │ │ │ - this.onNextChange(this.nextStack[0], this.nextStack.length); │ │ │ │ │ - this.onPreviousChange( │ │ │ │ │ - this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ - ); │ │ │ │ │ - } else { │ │ │ │ │ - this.previousStack.unshift(current); │ │ │ │ │ - } │ │ │ │ │ - return state; │ │ │ │ │ + initialize: function(direction, options) { │ │ │ │ │ + │ │ │ │ │ + this.direction = direction; │ │ │ │ │ + this.CLASS_NAME += this.direction; │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: nextTrigger │ │ │ │ │ - * Restore the next state. If no items are in the next history │ │ │ │ │ - * stack, this has no effect. The next history stack is populated │ │ │ │ │ - * as states are restored from the previous history stack. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} Item representing state that was restored. Undefined if no │ │ │ │ │ - * items are in the next history stack. │ │ │ │ │ + * Method: trigger │ │ │ │ │ */ │ │ │ │ │ - nextTrigger: function() { │ │ │ │ │ - var state = this.nextStack.shift(); │ │ │ │ │ - if (state != undefined) { │ │ │ │ │ - this.previousStack.unshift(state); │ │ │ │ │ - this.restoring = true; │ │ │ │ │ - this.restore(state); │ │ │ │ │ - this.restoring = false; │ │ │ │ │ - this.onNextChange(this.nextStack[0], this.nextStack.length); │ │ │ │ │ - this.onPreviousChange( │ │ │ │ │ - this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ - ); │ │ │ │ │ + trigger: function() { │ │ │ │ │ + if (this.map) { │ │ │ │ │ + var getSlideFactor = OpenLayers.Function.bind(function(dim) { │ │ │ │ │ + return this.slideRatio ? │ │ │ │ │ + this.map.getSize()[dim] * this.slideRatio : │ │ │ │ │ + this.slideFactor; │ │ │ │ │ + }, this); │ │ │ │ │ + │ │ │ │ │ + switch (this.direction) { │ │ │ │ │ + case OpenLayers.Control.Pan.NORTH: │ │ │ │ │ + this.map.pan(0, -getSlideFactor("h")); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Control.Pan.SOUTH: │ │ │ │ │ + this.map.pan(0, getSlideFactor("h")); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Control.Pan.WEST: │ │ │ │ │ + this.map.pan(-getSlideFactor("w"), 0); │ │ │ │ │ + break; │ │ │ │ │ + case OpenLayers.Control.Pan.EAST: │ │ │ │ │ + this.map.pan(getSlideFactor("w"), 0); │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return state; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: clear │ │ │ │ │ - * Clear history. │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Pan" │ │ │ │ │ +}); │ │ │ │ │ + │ │ │ │ │ +OpenLayers.Control.Pan.NORTH = "North"; │ │ │ │ │ +OpenLayers.Control.Pan.SOUTH = "South"; │ │ │ │ │ +OpenLayers.Control.Pan.EAST = "East"; │ │ │ │ │ +OpenLayers.Control.Pan.WEST = "West"; │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/PanPanel.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control/Panel.js │ │ │ │ │ + * @requires OpenLayers/Control/Pan.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.PanPanel │ │ │ │ │ + * The PanPanel is visible control for panning the map North, South, East or │ │ │ │ │ + * West in small steps. By default it is drawn in the top left corner of the │ │ │ │ │ + * map. │ │ │ │ │ + * │ │ │ │ │ + * Note: │ │ │ │ │ + * If you wish to use this class with the default images and you want │ │ │ │ │ + * it to look nice in ie6, you should add the following, conditionally │ │ │ │ │ + * added css stylesheet to your HTML file: │ │ │ │ │ + * │ │ │ │ │ + * (code) │ │ │ │ │ + * │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.PanPanel = OpenLayers.Class(OpenLayers.Control.Panel, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: slideFactor │ │ │ │ │ + * {Integer} Number of pixels by which we'll pan the map in any direction │ │ │ │ │ + * on clicking the arrow buttons, defaults to 50. If you want to pan │ │ │ │ │ + * by some ratio of the map dimensions, use instead. │ │ │ │ │ */ │ │ │ │ │ - clear: function() { │ │ │ │ │ - this.previousStack = []; │ │ │ │ │ - this.previous.deactivate(); │ │ │ │ │ - this.nextStack = []; │ │ │ │ │ - this.next.deactivate(); │ │ │ │ │ - }, │ │ │ │ │ + slideFactor: 50, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: slideRatio │ │ │ │ │ + * {Number} The fraction of map width/height by which we'll pan the map │ │ │ │ │ + * on clicking the arrow buttons. Default is null. If set, will │ │ │ │ │ + * override . E.g. if slideRatio is .5, then Pan Up will │ │ │ │ │ + * pan up half the map height. │ │ │ │ │ + */ │ │ │ │ │ + slideRatio: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getState │ │ │ │ │ - * Get the current state and return it. │ │ │ │ │ + * Constructor: OpenLayers.Control.PanPanel │ │ │ │ │ + * Add the four directional pan buttons. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An object representing the current state. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be used │ │ │ │ │ + * to extend the control. │ │ │ │ │ */ │ │ │ │ │ - getState: function() { │ │ │ │ │ - return { │ │ │ │ │ - center: this.map.getCenter(), │ │ │ │ │ - resolution: this.map.getResolution(), │ │ │ │ │ - projection: this.map.getProjectionObject(), │ │ │ │ │ - units: this.map.getProjectionObject().getUnits() || │ │ │ │ │ - this.map.units || this.map.baseLayer.units │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); │ │ │ │ │ + var options = { │ │ │ │ │ + slideFactor: this.slideFactor, │ │ │ │ │ + slideRatio: this.slideRatio │ │ │ │ │ }; │ │ │ │ │ + this.addControls([ │ │ │ │ │ + new OpenLayers.Control.Pan(OpenLayers.Control.Pan.NORTH, options), │ │ │ │ │ + new OpenLayers.Control.Pan(OpenLayers.Control.Pan.SOUTH, options), │ │ │ │ │ + new OpenLayers.Control.Pan(OpenLayers.Control.Pan.EAST, options), │ │ │ │ │ + new OpenLayers.Control.Pan(OpenLayers.Control.Pan.WEST, options) │ │ │ │ │ + ]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.PanPanel" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/Scale.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Lang.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.Scale │ │ │ │ │ + * The Scale control displays the current map scale as a ratio (e.g. Scale = │ │ │ │ │ + * 1:1M). By default it is displayed in the lower right corner of the map. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.Scale = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * Method: restore │ │ │ │ │ - * Update the state with the given object. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * state - {Object} An object representing the state to restore. │ │ │ │ │ + * Property: element │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - restore: function(state) { │ │ │ │ │ - var center, zoom; │ │ │ │ │ - if (this.map.getProjectionObject() == state.projection) { │ │ │ │ │ - zoom = this.map.getZoomForResolution(state.resolution); │ │ │ │ │ - center = state.center; │ │ │ │ │ - } else { │ │ │ │ │ - center = state.center.clone(); │ │ │ │ │ - center.transform(state.projection, this.map.getProjectionObject()); │ │ │ │ │ - var sourceUnits = state.units; │ │ │ │ │ - var targetUnits = this.map.getProjectionObject().getUnits() || │ │ │ │ │ - this.map.units || this.map.baseLayer.units; │ │ │ │ │ - var resolutionFactor = sourceUnits && targetUnits ? │ │ │ │ │ - OpenLayers.INCHES_PER_UNIT[sourceUnits] / OpenLayers.INCHES_PER_UNIT[targetUnits] : 1; │ │ │ │ │ - zoom = this.map.getZoomForResolution(resolutionFactor * state.resolution); │ │ │ │ │ - } │ │ │ │ │ - this.map.setCenter(center, zoom); │ │ │ │ │ - }, │ │ │ │ │ + element: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setListeners │ │ │ │ │ - * Sets functions to be registered in the listeners object. │ │ │ │ │ + * APIProperty: geodesic │ │ │ │ │ + * {Boolean} Use geodesic measurement. Default is false. The recommended │ │ │ │ │ + * setting for maps in EPSG:4326 is false, and true EPSG:900913. If set to │ │ │ │ │ + * true, the scale will be calculated based on the horizontal size of the │ │ │ │ │ + * pixel in the center of the map viewport. │ │ │ │ │ */ │ │ │ │ │ - setListeners: function() { │ │ │ │ │ - this.listeners = {}; │ │ │ │ │ - for (var type in this.registry) { │ │ │ │ │ - this.listeners[type] = OpenLayers.Function.bind(function() { │ │ │ │ │ - if (!this.restoring) { │ │ │ │ │ - var state = this.registry[type].apply(this, arguments); │ │ │ │ │ - this.previousStack.unshift(state); │ │ │ │ │ - if (this.previousStack.length > 1) { │ │ │ │ │ - this.onPreviousChange( │ │ │ │ │ - this.previousStack[1], this.previousStack.length - 1 │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (this.previousStack.length > (this.limit + 1)) { │ │ │ │ │ - this.previousStack.pop(); │ │ │ │ │ - } │ │ │ │ │ - if (this.nextStack.length > 0) { │ │ │ │ │ - this.nextStack = []; │ │ │ │ │ - this.onNextChange(null, 0); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return true; │ │ │ │ │ - }, this); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + geodesic: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: activate │ │ │ │ │ - * Activate the control. This registers any listeners. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Control successfully activated. │ │ │ │ │ + * Constructor: OpenLayers.Control.Scale │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * element - {DOMElement} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - activate: function() { │ │ │ │ │ - var activated = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - if (OpenLayers.Control.prototype.activate.apply(this)) { │ │ │ │ │ - if (this.listeners == null) { │ │ │ │ │ - this.setListeners(); │ │ │ │ │ - } │ │ │ │ │ - for (var type in this.listeners) { │ │ │ │ │ - this.map.events.register(type, this, this.listeners[type]); │ │ │ │ │ - } │ │ │ │ │ - activated = true; │ │ │ │ │ - if (this.previousStack.length == 0) { │ │ │ │ │ - this.initStack(); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return activated; │ │ │ │ │ + initialize: function(element, options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + this.element = OpenLayers.Util.getElement(element); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: initStack │ │ │ │ │ - * Called after the control is activated if the previous history stack is │ │ │ │ │ - * empty. │ │ │ │ │ + * Method: draw │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} │ │ │ │ │ */ │ │ │ │ │ - initStack: function() { │ │ │ │ │ - if (this.map.getCenter()) { │ │ │ │ │ - this.listeners.moveend(); │ │ │ │ │ + draw: function() { │ │ │ │ │ + OpenLayers.Control.prototype.draw.apply(this, arguments); │ │ │ │ │ + if (!this.element) { │ │ │ │ │ + this.element = document.createElement("div"); │ │ │ │ │ + this.div.appendChild(this.element); │ │ │ │ │ } │ │ │ │ │ + this.map.events.register('moveend', this, this.updateScale); │ │ │ │ │ + this.updateScale(); │ │ │ │ │ + return this.div; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: deactivate │ │ │ │ │ - * Deactivate the control. This unregisters any listeners. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Control successfully deactivated. │ │ │ │ │ + * Method: updateScale │ │ │ │ │ */ │ │ │ │ │ - deactivate: function() { │ │ │ │ │ - var deactivated = false; │ │ │ │ │ - if (this.map) { │ │ │ │ │ - if (OpenLayers.Control.prototype.deactivate.apply(this)) { │ │ │ │ │ - for (var type in this.listeners) { │ │ │ │ │ - this.map.events.unregister( │ │ │ │ │ - type, this, this.listeners[type] │ │ │ │ │ - ); │ │ │ │ │ - } │ │ │ │ │ - if (this.clearOnDeactivate) { │ │ │ │ │ - this.clear(); │ │ │ │ │ - } │ │ │ │ │ - deactivated = true; │ │ │ │ │ + updateScale: function() { │ │ │ │ │ + var scale; │ │ │ │ │ + if (this.geodesic === true) { │ │ │ │ │ + var units = this.map.getUnits(); │ │ │ │ │ + if (!units) { │ │ │ │ │ + return; │ │ │ │ │ } │ │ │ │ │ + var inches = OpenLayers.INCHES_PER_UNIT; │ │ │ │ │ + scale = (this.map.getGeodesicPixelSize().w || 0.000001) * │ │ │ │ │ + inches["km"] * OpenLayers.DOTS_PER_INCH; │ │ │ │ │ + } else { │ │ │ │ │ + scale = this.map.getScale(); │ │ │ │ │ } │ │ │ │ │ - return deactivated; │ │ │ │ │ + │ │ │ │ │ + if (!scale) { │ │ │ │ │ + return; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + if (scale >= 9500 && scale <= 950000) { │ │ │ │ │ + scale = Math.round(scale / 1000) + "K"; │ │ │ │ │ + } else if (scale >= 950000) { │ │ │ │ │ + scale = Math.round(scale / 1000000) + "M"; │ │ │ │ │ + } else { │ │ │ │ │ + scale = Math.round(scale); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + this.element.innerHTML = OpenLayers.i18n("Scale = 1 : ${scaleDenom}", { │ │ │ │ │ + 'scaleDenom': scale │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Control.NavigationHistory" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Scale" │ │ │ │ │ }); │ │ │ │ │ │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Events/featureclick.js │ │ │ │ │ + OpenLayers/Control/Measure.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Events.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Feature/Vector.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Events.featureclick │ │ │ │ │ + * Class: OpenLayers.Control.Measure │ │ │ │ │ + * Allows for drawing of features for measurements. │ │ │ │ │ * │ │ │ │ │ - * Extension event type for handling feature click events, including overlapping │ │ │ │ │ - * features. │ │ │ │ │ - * │ │ │ │ │ - * Event types provided by this extension: │ │ │ │ │ - * - featureclick │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Events.featureclick = OpenLayers.Class({ │ │ │ │ │ +OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: cache │ │ │ │ │ - * {Object} A cache of features under the mouse. │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * measure - Triggered when a measurement sketch is complete. Listeners │ │ │ │ │ + * will receive an event with measure, units, order, and geometry │ │ │ │ │ + * properties. │ │ │ │ │ + * measurepartial - Triggered when a new point is added to the │ │ │ │ │ + * measurement sketch or if the property is true and the │ │ │ │ │ + * measurement sketch is modified. Listeners receive an event with measure, │ │ │ │ │ + * units, order, and geometry. │ │ │ │ │ */ │ │ │ │ │ - cache: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: map │ │ │ │ │ - * {} The map to register browser events on. │ │ │ │ │ + * APIProperty: handlerOptions │ │ │ │ │ + * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ */ │ │ │ │ │ - map: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: provides │ │ │ │ │ - * {Array(String)} The event types provided by this extension. │ │ │ │ │ + * Property: callbacks │ │ │ │ │ + * {Object} The functions that are sent to the handler for callback │ │ │ │ │ */ │ │ │ │ │ - provides: ["featureclick", "nofeatureclick", "featureover", "featureout"], │ │ │ │ │ + callbacks: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Events.featureclick │ │ │ │ │ - * Create a new featureclick event type. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * target - {} The events instance to create the events │ │ │ │ │ - * for. │ │ │ │ │ + * APIProperty: displaySystem │ │ │ │ │ + * {String} Display system for output measurements. Supported values │ │ │ │ │ + * are 'english', 'metric', and 'geographic'. Default is 'metric'. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(target) { │ │ │ │ │ - this.target = target; │ │ │ │ │ - if (target.object instanceof OpenLayers.Map) { │ │ │ │ │ - this.setMap(target.object); │ │ │ │ │ - } else if (target.object instanceof OpenLayers.Layer.Vector) { │ │ │ │ │ - if (target.object.map) { │ │ │ │ │ - this.setMap(target.object.map); │ │ │ │ │ - } else { │ │ │ │ │ - target.object.events.register("added", this, function(evt) { │ │ │ │ │ - this.setMap(target.object.map); │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - throw ("Listeners for '" + this.provides.join("', '") + │ │ │ │ │ - "' events can only be registered for OpenLayers.Layer.Vector " + │ │ │ │ │ - "or OpenLayers.Map instances"); │ │ │ │ │ - } │ │ │ │ │ - for (var i = this.provides.length - 1; i >= 0; --i) { │ │ │ │ │ - target.extensions[this.provides[i]] = true; │ │ │ │ │ - } │ │ │ │ │ + displaySystem: 'metric', │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: geodesic │ │ │ │ │ + * {Boolean} Calculate geodesic metrics instead of planar metrics. This │ │ │ │ │ + * requires that geometries can be transformed into Geographic/WGS84 │ │ │ │ │ + * (if that is not already the map projection). Default is false. │ │ │ │ │ + */ │ │ │ │ │ + geodesic: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: displaySystemUnits │ │ │ │ │ + * {Object} Units for various measurement systems. Values are arrays │ │ │ │ │ + * of unit abbreviations (from OpenLayers.INCHES_PER_UNIT) in decreasing │ │ │ │ │ + * order of length. │ │ │ │ │ + */ │ │ │ │ │ + displaySystemUnits: { │ │ │ │ │ + geographic: ['dd'], │ │ │ │ │ + english: ['mi', 'ft', 'in'], │ │ │ │ │ + metric: ['km', 'm'] │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ + * Property: delay │ │ │ │ │ + * {Number} Number of milliseconds between clicks before the event is │ │ │ │ │ + * considered a double-click. The "measurepartial" event will not │ │ │ │ │ + * be triggered if the sketch is completed within this time. This │ │ │ │ │ + * is required for IE where creating a browser reflow (if a listener │ │ │ │ │ + * is modifying the DOM by displaying the measurement values) messes │ │ │ │ │ + * with the dblclick listener in the sketch handler. │ │ │ │ │ + */ │ │ │ │ │ + partialDelay: 300, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Property: delayedTrigger │ │ │ │ │ + * {Number} Timeout id of trigger for measurepartial. │ │ │ │ │ + */ │ │ │ │ │ + delayedTrigger: null, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: persist │ │ │ │ │ + * {Boolean} Keep the temporary measurement sketch drawn after the │ │ │ │ │ + * measurement is complete. The geometry will persist until a new │ │ │ │ │ + * measurement is started, the control is deactivated, or is │ │ │ │ │ + * called. │ │ │ │ │ + */ │ │ │ │ │ + persist: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: immediate │ │ │ │ │ + * {Boolean} Activates the immediate measurement so that the "measurepartial" │ │ │ │ │ + * event is also fired once the measurement sketch is modified. │ │ │ │ │ + * Default is false. │ │ │ │ │ + */ │ │ │ │ │ + immediate: false, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.Measure │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} The map to register browser events on. │ │ │ │ │ + * handler - {} │ │ │ │ │ + * options - {Object} │ │ │ │ │ */ │ │ │ │ │ - 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 │ │ │ │ │ - }); │ │ │ │ │ + initialize: function(handler, options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ + var callbacks = { │ │ │ │ │ + done: this.measureComplete, │ │ │ │ │ + point: this.measurePartial │ │ │ │ │ + }; │ │ │ │ │ + if (this.immediate) { │ │ │ │ │ + callbacks.modify = this.measureImmediate; │ │ │ │ │ + } │ │ │ │ │ + this.callbacks = OpenLayers.Util.extend(callbacks, this.callbacks); │ │ │ │ │ + │ │ │ │ │ + // let the handler options override, so old code that passes 'persist' │ │ │ │ │ + // directly to the handler does not need an update │ │ │ │ │ + this.handlerOptions = OpenLayers.Util.extend({ │ │ │ │ │ + persist: this.persist │ │ │ │ │ + }, this.handlerOptions); │ │ │ │ │ + this.handler = new handler(this, this.callbacks, this.handlerOptions); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: start │ │ │ │ │ - * Sets startEvt = evt. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ */ │ │ │ │ │ - start: function(evt) { │ │ │ │ │ - this.startEvt = evt; │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + this.cancelDelay(); │ │ │ │ │ + return OpenLayers.Control.prototype.deactivate.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: cancel │ │ │ │ │ - * Deletes the start event. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * APIMethod: cancel │ │ │ │ │ + * Stop the control from measuring. If is true, the temporary │ │ │ │ │ + * sketch will be erased. │ │ │ │ │ */ │ │ │ │ │ - cancel: function(evt) { │ │ │ │ │ - delete this.startEvt; │ │ │ │ │ + cancel: function() { │ │ │ │ │ + this.cancelDelay(); │ │ │ │ │ + this.handler.cancel(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onClick │ │ │ │ │ - * Listener for the click event. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * APIMethod: setImmediate │ │ │ │ │ + * Sets the property. Changes the activity of immediate │ │ │ │ │ + * measurement. │ │ │ │ │ */ │ │ │ │ │ - onClick: function(evt) { │ │ │ │ │ - if (!this.startEvt || evt.type !== "touchend" && │ │ │ │ │ - !OpenLayers.Event.isLeftClick(evt)) { │ │ │ │ │ - return; │ │ │ │ │ - } │ │ │ │ │ - var features = this.getFeatures(this.startEvt); │ │ │ │ │ - delete this.startEvt; │ │ │ │ │ - // fire featureclick events │ │ │ │ │ - var feature, layer, more, clicked = {}; │ │ │ │ │ - for (var i = 0, len = features.length; i < len; ++i) { │ │ │ │ │ - feature = features[i]; │ │ │ │ │ - layer = feature.layer; │ │ │ │ │ - clicked[layer.id] = true; │ │ │ │ │ - more = this.triggerEvent("featureclick", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - if (more === false) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // 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 │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ + setImmediate: function(immediate) { │ │ │ │ │ + this.immediate = immediate; │ │ │ │ │ + if (this.immediate) { │ │ │ │ │ + this.callbacks.modify = this.measureImmediate; │ │ │ │ │ + } else { │ │ │ │ │ + delete this.callbacks.modify; │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: onMousemove │ │ │ │ │ - * Listener for the mousemove event. │ │ │ │ │ + * Method: updateHandler │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {} │ │ │ │ │ + * handler - {Function} One of the sketch handler constructors. │ │ │ │ │ + * options - {Object} Options for the handler. │ │ │ │ │ */ │ │ │ │ │ - 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; │ │ │ │ │ - } │ │ │ │ │ + updateHandler: function(handler, options) { │ │ │ │ │ + var active = this.active; │ │ │ │ │ + if (active) { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ } │ │ │ │ │ - // fire featureout events │ │ │ │ │ - for (i = 0, len = out.length; i < len; ++i) { │ │ │ │ │ - feature = out[i]; │ │ │ │ │ - delete this.cache[feature.id]; │ │ │ │ │ - more = this.triggerEvent("featureout", { │ │ │ │ │ - feature: feature │ │ │ │ │ - }); │ │ │ │ │ - if (more === false) { │ │ │ │ │ - break; │ │ │ │ │ - } │ │ │ │ │ + this.handler = new handler(this, this.callbacks, options); │ │ │ │ │ + if (active) { │ │ │ │ │ + this.activate(); │ │ │ │ │ } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: triggerEvent │ │ │ │ │ - * Determines where to trigger the event and triggers it. │ │ │ │ │ + * Method: measureComplete │ │ │ │ │ + * Called when the measurement sketch is done. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * type - {String} The event type to trigger │ │ │ │ │ - * evt - {Object} The listener argument │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} The last listener return. │ │ │ │ │ + * geometry - {} │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ + measureComplete: function(geometry) { │ │ │ │ │ + this.cancelDelay(); │ │ │ │ │ + this.measure(geometry, "measure"); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getFeatures │ │ │ │ │ - * Get all features at the given screen location. │ │ │ │ │ + * Method: measurePartial │ │ │ │ │ + * Called each time a new point is added to the measurement sketch. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * evt - {Object} Event object. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Array()} List of features at the given point. │ │ │ │ │ + * point - {} The last point added. │ │ │ │ │ + * geometry - {} The sketch geometry. │ │ │ │ │ */ │ │ │ │ │ - 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); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - // restore feature visibility │ │ │ │ │ - for (i = 0, len = targets.length; i < len; ++i) { │ │ │ │ │ - targets[i].style.display = ""; │ │ │ │ │ - } │ │ │ │ │ - // restore layer visibility │ │ │ │ │ - for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ - layers[i].div.style.display = "block"; │ │ │ │ │ + measurePartial: function(point, geometry) { │ │ │ │ │ + this.cancelDelay(); │ │ │ │ │ + geometry = geometry.clone(); │ │ │ │ │ + // when we're wating for a dblclick, we have to trigger measurepartial │ │ │ │ │ + // after some delay to deal with reflow issues in IE │ │ │ │ │ + if (this.handler.freehandMode(this.handler.evt)) { │ │ │ │ │ + // no dblclick in freehand mode │ │ │ │ │ + this.measure(geometry, "measurepartial"); │ │ │ │ │ + } else { │ │ │ │ │ + this.delayedTrigger = window.setTimeout( │ │ │ │ │ + OpenLayers.Function.bind(function() { │ │ │ │ │ + this.delayedTrigger = null; │ │ │ │ │ + this.measure(geometry, "measurepartial"); │ │ │ │ │ + }, this), │ │ │ │ │ + this.partialDelay │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - return features; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Clean up. │ │ │ │ │ + * Method: measureImmediate │ │ │ │ │ + * Called each time the measurement sketch is modified. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * point - {} The point at the mouse position. │ │ │ │ │ + * feature - {} The sketch feature. │ │ │ │ │ + * drawing - {Boolean} Indicates whether we're currently drawing. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - for (var i = this.provides.length - 1; i >= 0; --i) { │ │ │ │ │ - delete this.target.extensions[this.provides[i]]; │ │ │ │ │ + measureImmediate: function(point, feature, drawing) { │ │ │ │ │ + if (drawing && !this.handler.freehandMode(this.handler.evt)) { │ │ │ │ │ + this.cancelDelay(); │ │ │ │ │ + this.measure(feature.geometry, "measurepartial"); │ │ │ │ │ } │ │ │ │ │ - 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: 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/Layer/XYZ.js │ │ │ │ │ - ====================================================================== */ │ │ │ │ │ - │ │ │ │ │ -/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ - * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ - * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ - * full text of the license. */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ - */ │ │ │ │ │ - │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Layer.XYZ │ │ │ │ │ - * The XYZ class is designed to make it easier for people who have tiles │ │ │ │ │ - * arranged by a standard XYZ grid. │ │ │ │ │ - * │ │ │ │ │ - * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ - */ │ │ │ │ │ -OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * Default is true, as this is designed to be a base tile source. │ │ │ │ │ - */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: sphericalMercator │ │ │ │ │ - * Whether the tile extents should be set to the defaults for │ │ │ │ │ - * spherical mercator. Useful for things like OpenStreetMap. │ │ │ │ │ - * Default is false, except for the OSM subclass. │ │ │ │ │ - */ │ │ │ │ │ - sphericalMercator: false, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: zoomOffset │ │ │ │ │ - * {Number} If your cache has more zoom levels than you want to provide │ │ │ │ │ - * access to with this layer, supply a zoomOffset. This zoom offset │ │ │ │ │ - * is added to the current map zoom level to determine the level │ │ │ │ │ - * for a requested tile. For example, if you supply a zoomOffset │ │ │ │ │ - * of 3, when the map is at the zoom 0, tiles will be requested from │ │ │ │ │ - * level 3 of your cache. Default is 0 (assumes cache level and map │ │ │ │ │ - * zoom are equivalent). Using is an alternative to │ │ │ │ │ - * setting if you only want to expose a subset │ │ │ │ │ - * of the server resolutions. │ │ │ │ │ - */ │ │ │ │ │ - zoomOffset: 0, │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: serverResolutions │ │ │ │ │ - * {Array} A list of all resolutions available on the server. Only set this │ │ │ │ │ - * property if the map resolutions differ from the server. This │ │ │ │ │ - * property serves two purposes. (a) can include │ │ │ │ │ - * resolutions that the server supports and that you don't want to │ │ │ │ │ - * provide with this layer; you can also look at , which is │ │ │ │ │ - * an alternative to for that specific purpose. │ │ │ │ │ - * (b) The map can work with resolutions that aren't supported by │ │ │ │ │ - * the server, i.e. that aren't in . When the │ │ │ │ │ - * map is displayed in such a resolution data for the closest │ │ │ │ │ - * server-supported resolution is loaded and the layer div is │ │ │ │ │ - * stretched as necessary. │ │ │ │ │ + * Method: cancelDelay │ │ │ │ │ + * Cancels the delay measurement that measurePartial began. │ │ │ │ │ */ │ │ │ │ │ - serverResolutions: null, │ │ │ │ │ + cancelDelay: function() { │ │ │ │ │ + if (this.delayedTrigger !== null) { │ │ │ │ │ + window.clearTimeout(this.delayedTrigger); │ │ │ │ │ + this.delayedTrigger = null; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.XYZ │ │ │ │ │ + * Method: measure │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - * url - {String} │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * eventType - {String} │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, options) { │ │ │ │ │ - if (options && options.sphericalMercator || this.sphericalMercator) { │ │ │ │ │ - options = OpenLayers.Util.extend({ │ │ │ │ │ - projection: "EPSG:900913", │ │ │ │ │ - numZoomLevels: 19 │ │ │ │ │ - }, options); │ │ │ │ │ + measure: function(geometry, eventType) { │ │ │ │ │ + var stat, order; │ │ │ │ │ + if (geometry.CLASS_NAME.indexOf('LineString') > -1) { │ │ │ │ │ + stat = this.getBestLength(geometry); │ │ │ │ │ + order = 1; │ │ │ │ │ + } else { │ │ │ │ │ + stat = this.getBestArea(geometry); │ │ │ │ │ + order = 2; │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply(this, [ │ │ │ │ │ - name || this.name, url || this.url, {}, │ │ │ │ │ - options │ │ │ │ │ - ]); │ │ │ │ │ + this.events.triggerEvent(eventType, { │ │ │ │ │ + measure: stat[0], │ │ │ │ │ + units: stat[1], │ │ │ │ │ + order: order, │ │ │ │ │ + geometry: geometry │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ - * Create a clone of this layer │ │ │ │ │ + * Method: getBestArea │ │ │ │ │ + * Based on the returns the area of a geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * obj - {Object} Is this ever used? │ │ │ │ │ - * │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An exact clone of this OpenLayers.Layer.XYZ │ │ │ │ │ + * {Array([Float, String])} Returns a two item array containing the │ │ │ │ │ + * area and the units abbreviation. │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ - │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.XYZ(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ + getBestArea: function(geometry) { │ │ │ │ │ + var units = this.displaySystemUnits[this.displaySystem]; │ │ │ │ │ + var unit, area; │ │ │ │ │ + for (var i = 0, len = units.length; i < len; ++i) { │ │ │ │ │ + unit = units[i]; │ │ │ │ │ + area = this.getArea(geometry, unit); │ │ │ │ │ + if (area > 1) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ - │ │ │ │ │ - return obj; │ │ │ │ │ + return [area, unit]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ + * Method: getArea │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * units - {String} Unit abbreviation │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A string with the layer's url and parameters and also the │ │ │ │ │ - * passed-in bounds and appropriate tile size specified as │ │ │ │ │ - * parameters │ │ │ │ │ + * {Float} The geometry area in the given units. │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - var xyz = this.getXYZ(bounds); │ │ │ │ │ - var url = this.url; │ │ │ │ │ - if (OpenLayers.Util.isArray(url)) { │ │ │ │ │ - var s = '' + xyz.x + xyz.y + xyz.z; │ │ │ │ │ - url = this.selectUrl(s, url); │ │ │ │ │ + getArea: function(geometry, units) { │ │ │ │ │ + var area, geomUnits; │ │ │ │ │ + if (this.geodesic) { │ │ │ │ │ + area = geometry.getGeodesicArea(this.map.getProjectionObject()); │ │ │ │ │ + geomUnits = "m"; │ │ │ │ │ + } else { │ │ │ │ │ + area = geometry.getArea(); │ │ │ │ │ + geomUnits = this.map.getUnits(); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return OpenLayers.String.format(url, xyz); │ │ │ │ │ + var inPerDisplayUnit = OpenLayers.INCHES_PER_UNIT[units]; │ │ │ │ │ + if (inPerDisplayUnit) { │ │ │ │ │ + var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[geomUnits]; │ │ │ │ │ + area *= Math.pow((inPerMapUnit / inPerDisplayUnit), 2); │ │ │ │ │ + } │ │ │ │ │ + return area; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getXYZ │ │ │ │ │ - * Calculates x, y and z for the given bounds. │ │ │ │ │ + * Method: getBestLength │ │ │ │ │ + * Based on the returns the length of a geometry. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ + * geometry - {} │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} - an object with x, y and z properties. │ │ │ │ │ + * {Array([Float, String])} Returns a two item array containing the │ │ │ │ │ + * length and the units abbreviation. │ │ │ │ │ */ │ │ │ │ │ - getXYZ: function(bounds) { │ │ │ │ │ - var res = this.getServerResolution(); │ │ │ │ │ - var x = Math.round((bounds.left - this.maxExtent.left) / │ │ │ │ │ - (res * this.tileSize.w)); │ │ │ │ │ - var y = Math.round((this.maxExtent.top - bounds.top) / │ │ │ │ │ - (res * this.tileSize.h)); │ │ │ │ │ - var z = this.getServerZoom(); │ │ │ │ │ - │ │ │ │ │ - if (this.wrapDateLine) { │ │ │ │ │ - var limit = Math.pow(2, z); │ │ │ │ │ - x = ((x % limit) + limit) % limit; │ │ │ │ │ + getBestLength: function(geometry) { │ │ │ │ │ + var units = this.displaySystemUnits[this.displaySystem]; │ │ │ │ │ + var unit, length; │ │ │ │ │ + for (var i = 0, len = units.length; i < len; ++i) { │ │ │ │ │ + unit = units[i]; │ │ │ │ │ + length = this.getLength(geometry, unit); │ │ │ │ │ + if (length > 1) { │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return { │ │ │ │ │ - 'x': x, │ │ │ │ │ - 'y': y, │ │ │ │ │ - 'z': z │ │ │ │ │ - }; │ │ │ │ │ + return [length, unit]; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /* APIMethod: setMap │ │ │ │ │ - * When the layer is added to a map, then we can fetch our origin │ │ │ │ │ - * (if we don't have one.) │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * Method: getLength │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * geometry - {} │ │ │ │ │ + * units - {String} Unit abbreviation │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Float} The geometry length in the given units. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments); │ │ │ │ │ - if (!this.tileOrigin) { │ │ │ │ │ - this.tileOrigin = new OpenLayers.LonLat(this.maxExtent.left, │ │ │ │ │ - this.maxExtent.bottom); │ │ │ │ │ + getLength: function(geometry, units) { │ │ │ │ │ + var length, geomUnits; │ │ │ │ │ + if (this.geodesic) { │ │ │ │ │ + length = geometry.getGeodesicLength(this.map.getProjectionObject()); │ │ │ │ │ + geomUnits = "m"; │ │ │ │ │ + } else { │ │ │ │ │ + length = geometry.getLength(); │ │ │ │ │ + geomUnits = this.map.getUnits(); │ │ │ │ │ } │ │ │ │ │ + var inPerDisplayUnit = OpenLayers.INCHES_PER_UNIT[units]; │ │ │ │ │ + if (inPerDisplayUnit) { │ │ │ │ │ + var inPerMapUnit = OpenLayers.INCHES_PER_UNIT[geomUnits]; │ │ │ │ │ + length *= (inPerMapUnit / inPerDisplayUnit); │ │ │ │ │ + } │ │ │ │ │ + return length; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.XYZ" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Measure" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Tile/UTFGrid.js │ │ │ │ │ + OpenLayers/Control/Geolocate.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Tile.js │ │ │ │ │ - * @requires OpenLayers/Format/JSON.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ + * @requires OpenLayers/Projection.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Tile.UTFGrid │ │ │ │ │ - * Instances of OpenLayers.Tile.UTFGrid are used to manage │ │ │ │ │ - * UTFGrids. This is an unusual tile type in that it doesn't have a │ │ │ │ │ - * rendered image; only a 'hit grid' that can be used to │ │ │ │ │ - * look up feature attributes. │ │ │ │ │ + * Class: OpenLayers.Control.Geolocate │ │ │ │ │ + * The Geolocate control wraps w3c geolocation API into control that can be │ │ │ │ │ + * bound to a map, and generate events on location update │ │ │ │ │ * │ │ │ │ │ - * See the constructor for details on constructing a │ │ │ │ │ - * new instance. │ │ │ │ │ + * To use this control requires to load the proj4js library if the projection │ │ │ │ │ + * of the map is not EPSG:4326 or EPSG:900913. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, { │ │ │ │ │ +OpenLayers.Control.Geolocate = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: url │ │ │ │ │ - * {String} │ │ │ │ │ - * The URL of the UTFGrid file being requested. Provided by the │ │ │ │ │ - * method. │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * locationupdated - Triggered when browser return a new position. Listeners will │ │ │ │ │ + * receive an object with a 'position' property which is the browser.geolocation.position │ │ │ │ │ + * native object, as well as a 'point' property which is the location transformed in the │ │ │ │ │ + * current map projection. │ │ │ │ │ + * locationfailed - Triggered when geolocation has failed │ │ │ │ │ + * locationuncapable - Triggered when control is activated on a browser │ │ │ │ │ + * which doesn't support geolocation │ │ │ │ │ */ │ │ │ │ │ - url: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: utfgridResolution │ │ │ │ │ - * {Number} │ │ │ │ │ - * Ratio of the pixel width to the width of a UTFGrid data point. If an │ │ │ │ │ - * entry in the grid represents a 4x4 block of pixels, the │ │ │ │ │ - * utfgridResolution would be 4. Default is 2. │ │ │ │ │ + * Property: geolocation │ │ │ │ │ + * {Object} The geolocation engine, as a property to be possibly mocked. │ │ │ │ │ + * This is set lazily to avoid a memory leak in IE9. │ │ │ │ │ */ │ │ │ │ │ - utfgridResolution: 2, │ │ │ │ │ + geolocation: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: json │ │ │ │ │ - * {Object} │ │ │ │ │ - * Stores the parsed JSON tile data structure. │ │ │ │ │ + /** │ │ │ │ │ + * Property: available │ │ │ │ │ + * {Boolean} The navigator.geolocation object is available. │ │ │ │ │ */ │ │ │ │ │ - json: null, │ │ │ │ │ + available: ('geolocation' in navigator), │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Property: format │ │ │ │ │ - * {OpenLayers.Format.JSON} │ │ │ │ │ - * Parser instance used to parse JSON for cross browser support. The native │ │ │ │ │ - * JSON.parse method will be used where available (all except IE<8). │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: bind │ │ │ │ │ + * {Boolean} If true, map center will be set on location update. │ │ │ │ │ */ │ │ │ │ │ - format: null, │ │ │ │ │ + bind: true, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Tile.UTFGrid │ │ │ │ │ - * Constructor for a new instance. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * layer - {} layer that the tile will go in. │ │ │ │ │ - * position - {} │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * url - {} Deprecated. Remove me in 3.0. │ │ │ │ │ - * size - {} │ │ │ │ │ - * options - {Object} │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: watch │ │ │ │ │ + * {Boolean} If true, position will be update regularly. │ │ │ │ │ */ │ │ │ │ │ + watch: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Clean up. │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: geolocationOptions │ │ │ │ │ + * {Object} Options to pass to the navigator's geolocation API. See │ │ │ │ │ + * . No specific │ │ │ │ │ + * option is passed to the geolocation API by default. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.clear(); │ │ │ │ │ - OpenLayers.Tile.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + geolocationOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: draw │ │ │ │ │ - * Check that a tile should be drawn, and draw it. │ │ │ │ │ - * In the case of UTFGrids, "drawing" it means fetching and │ │ │ │ │ - * parsing the json. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} Was a tile drawn? │ │ │ │ │ + * Constructor: OpenLayers.Control.Geolocate │ │ │ │ │ + * Create a new control to deal with browser geolocation API │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - draw: function() { │ │ │ │ │ - var drawn = OpenLayers.Tile.prototype.draw.apply(this, arguments); │ │ │ │ │ - if (drawn) { │ │ │ │ │ - if (this.isLoading) { │ │ │ │ │ - this.abortLoading(); │ │ │ │ │ - //if we're already loading, send 'reload' instead of 'loadstart'. │ │ │ │ │ - this.events.triggerEvent("reload"); │ │ │ │ │ - } else { │ │ │ │ │ - this.isLoading = true; │ │ │ │ │ - this.events.triggerEvent("loadstart"); │ │ │ │ │ - } │ │ │ │ │ - this.url = this.layer.getURL(this.bounds); │ │ │ │ │ - │ │ │ │ │ - if (this.layer.useJSONP) { │ │ │ │ │ - // Use JSONP method to avoid xbrowser policy │ │ │ │ │ - var ols = new OpenLayers.Protocol.Script({ │ │ │ │ │ - url: this.url, │ │ │ │ │ - callback: function(response) { │ │ │ │ │ - this.isLoading = false; │ │ │ │ │ - this.events.triggerEvent("loadend"); │ │ │ │ │ - this.json = response.data; │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - ols.read(); │ │ │ │ │ - this.request = ols; │ │ │ │ │ - } else { │ │ │ │ │ - // Use standard XHR │ │ │ │ │ - this.request = OpenLayers.Request.GET({ │ │ │ │ │ - url: this.url, │ │ │ │ │ - callback: function(response) { │ │ │ │ │ - this.isLoading = false; │ │ │ │ │ - this.events.triggerEvent("loadend"); │ │ │ │ │ - if (response.status === 200) { │ │ │ │ │ - this.parseData(response.responseText); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - scope: this │ │ │ │ │ - }); │ │ │ │ │ - } │ │ │ │ │ - } else { │ │ │ │ │ - this.unload(); │ │ │ │ │ - } │ │ │ │ │ - return drawn; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: abortLoading │ │ │ │ │ - * Cancel a pending request. │ │ │ │ │ + * Method: destroy │ │ │ │ │ */ │ │ │ │ │ - abortLoading: function() { │ │ │ │ │ - if (this.request) { │ │ │ │ │ - this.request.abort(); │ │ │ │ │ - delete this.request; │ │ │ │ │ - } │ │ │ │ │ - this.isLoading = false; │ │ │ │ │ + destroy: function() { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getFeatureInfo │ │ │ │ │ - * Get feature information associated with a pixel offset. If the pixel │ │ │ │ │ - * offset corresponds to a feature, the returned object will have id │ │ │ │ │ - * and data properties. Otherwise, null will be returned. │ │ │ │ │ - * │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * i - {Number} X-axis pixel offset (from top left of tile) │ │ │ │ │ - * j - {Number} Y-axis pixel offset (from top left of tile) │ │ │ │ │ + * Method: activate │ │ │ │ │ + * Activates the control. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} Object with feature id and data properties corresponding to the │ │ │ │ │ - * given pixel offset. │ │ │ │ │ + * {Boolean} The control was effectively activated. │ │ │ │ │ */ │ │ │ │ │ - getFeatureInfo: function(i, j) { │ │ │ │ │ - var info = null; │ │ │ │ │ - if (this.json) { │ │ │ │ │ - var id = this.getFeatureId(i, j); │ │ │ │ │ - if (id !== null) { │ │ │ │ │ - info = { │ │ │ │ │ - id: id, │ │ │ │ │ - data: this.json.data[id] │ │ │ │ │ - }; │ │ │ │ │ + activate: function() { │ │ │ │ │ + if (this.available && !this.geolocation) { │ │ │ │ │ + // set lazily to avoid IE9 memory leak │ │ │ │ │ + this.geolocation = navigator.geolocation; │ │ │ │ │ + } │ │ │ │ │ + if (!this.geolocation) { │ │ │ │ │ + this.events.triggerEvent("locationuncapable"); │ │ │ │ │ + return false; │ │ │ │ │ + } │ │ │ │ │ + if (OpenLayers.Control.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + if (this.watch) { │ │ │ │ │ + this.watchId = this.geolocation.watchPosition( │ │ │ │ │ + OpenLayers.Function.bind(this.geolocate, this), │ │ │ │ │ + OpenLayers.Function.bind(this.failure, this), │ │ │ │ │ + this.geolocationOptions │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + this.getCurrentLocation(); │ │ │ │ │ } │ │ │ │ │ + return true; │ │ │ │ │ } │ │ │ │ │ - return info; │ │ │ │ │ + return false; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getFeatureId │ │ │ │ │ - * Get the identifier for the feature associated with a pixel offset. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * i - {Number} X-axis pixel offset (from top left of tile) │ │ │ │ │ - * j - {Number} Y-axis pixel offset (from top left of tile) │ │ │ │ │ + * Method: deactivate │ │ │ │ │ + * Deactivates the control. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} The feature identifier corresponding to the given pixel offset. │ │ │ │ │ - * Returns null if pixel doesn't correspond to a feature. │ │ │ │ │ + * {Boolean} The control was effectively deactivated. │ │ │ │ │ */ │ │ │ │ │ - getFeatureId: function(i, j) { │ │ │ │ │ - var id = null; │ │ │ │ │ - if (this.json) { │ │ │ │ │ - var resolution = this.utfgridResolution; │ │ │ │ │ - var row = Math.floor(j / resolution); │ │ │ │ │ - var col = Math.floor(i / resolution); │ │ │ │ │ - var charCode = this.json.grid[row].charCodeAt(col); │ │ │ │ │ - var index = this.indexFromCharCode(charCode); │ │ │ │ │ - var keys = this.json.keys; │ │ │ │ │ - if (!isNaN(index) && (index in keys)) { │ │ │ │ │ - id = keys[index]; │ │ │ │ │ - } │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + if (this.active && this.watchId !== null) { │ │ │ │ │ + this.geolocation.clearWatch(this.watchId); │ │ │ │ │ } │ │ │ │ │ - return id; │ │ │ │ │ + return OpenLayers.Control.prototype.deactivate.apply( │ │ │ │ │ + this, arguments │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: indexFromCharCode │ │ │ │ │ - * Given a character code for one of the UTFGrid "grid" characters, │ │ │ │ │ - * resolve the integer index for the feature id in the UTFGrid "keys" │ │ │ │ │ - * array. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * charCode - {Integer} │ │ │ │ │ + * Method: geolocate │ │ │ │ │ + * Activates the control. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Integer} Index for the feature id from the keys array. │ │ │ │ │ */ │ │ │ │ │ - indexFromCharCode: function(charCode) { │ │ │ │ │ - if (charCode >= 93) { │ │ │ │ │ - charCode--; │ │ │ │ │ - } │ │ │ │ │ - if (charCode >= 35) { │ │ │ │ │ - charCode--; │ │ │ │ │ + geolocate: function(position) { │ │ │ │ │ + var center = new OpenLayers.LonLat( │ │ │ │ │ + position.coords.longitude, │ │ │ │ │ + position.coords.latitude │ │ │ │ │ + ).transform( │ │ │ │ │ + new OpenLayers.Projection("EPSG:4326"), │ │ │ │ │ + this.map.getProjectionObject() │ │ │ │ │ + ); │ │ │ │ │ + if (this.bind) { │ │ │ │ │ + this.map.setCenter(center); │ │ │ │ │ } │ │ │ │ │ - return charCode - 32; │ │ │ │ │ + this.events.triggerEvent("locationupdated", { │ │ │ │ │ + position: position, │ │ │ │ │ + point: new OpenLayers.Geometry.Point( │ │ │ │ │ + center.lon, center.lat │ │ │ │ │ + ) │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseData │ │ │ │ │ - * Parse the JSON from a request │ │ │ │ │ + * APIMethod: getCurrentLocation │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * str - {String} UTFGrid as a JSON string. │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} parsed javascript data │ │ │ │ │ + * {Boolean} Returns true if a event will be fired (successfull │ │ │ │ │ + * registration) │ │ │ │ │ */ │ │ │ │ │ - parseData: function(str) { │ │ │ │ │ - if (!this.format) { │ │ │ │ │ - this.format = new OpenLayers.Format.JSON(); │ │ │ │ │ + getCurrentLocation: function() { │ │ │ │ │ + if (!this.active || this.watch) { │ │ │ │ │ + return false; │ │ │ │ │ } │ │ │ │ │ - this.json = this.format.read(str); │ │ │ │ │ + this.geolocation.getCurrentPosition( │ │ │ │ │ + OpenLayers.Function.bind(this.geolocate, this), │ │ │ │ │ + OpenLayers.Function.bind(this.failure, this), │ │ │ │ │ + this.geolocationOptions │ │ │ │ │ + ); │ │ │ │ │ + return true; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: clear │ │ │ │ │ - * Delete data stored with this tile. │ │ │ │ │ + /** │ │ │ │ │ + * Method: failure │ │ │ │ │ + * method called on browser's geolocation failure │ │ │ │ │ + * │ │ │ │ │ */ │ │ │ │ │ - clear: function() { │ │ │ │ │ - this.json = null; │ │ │ │ │ + failure: function(error) { │ │ │ │ │ + this.events.triggerEvent("locationfailed", { │ │ │ │ │ + error: error │ │ │ │ │ + }); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Tile.UTFGrid" │ │ │ │ │ - │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.Geolocate" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/UTFGrid.js │ │ │ │ │ + OpenLayers/Layer/WMS.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ + │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Layer/XYZ.js │ │ │ │ │ - * @requires OpenLayers/Tile/UTFGrid.js │ │ │ │ │ + * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ -/** │ │ │ │ │ - * Class: OpenLayers.Layer.UTFGrid │ │ │ │ │ - * This Layer reads from UTFGrid tiled data sources. Since UTFGrids are │ │ │ │ │ - * essentially JSON-based ASCII art with attached attributes, they are not │ │ │ │ │ - * visibly rendered. In order to use them in the map, you must add a │ │ │ │ │ - * control as well. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * │ │ │ │ │ - * (start code) │ │ │ │ │ - * var world_utfgrid = new OpenLayers.Layer.UTFGrid({ │ │ │ │ │ - * url: "/tiles/world_utfgrid/${z}/${x}/${y}.json", │ │ │ │ │ - * utfgridResolution: 4, │ │ │ │ │ - * displayInLayerSwitcher: false │ │ │ │ │ - * ); │ │ │ │ │ - * map.addLayer(world_utfgrid); │ │ │ │ │ - * │ │ │ │ │ - * var control = new OpenLayers.Control.UTFGrid({ │ │ │ │ │ - * layers: [world_utfgrid], │ │ │ │ │ - * handlerMode: 'move', │ │ │ │ │ - * callback: function(dataLookup) { │ │ │ │ │ - * // do something with returned data │ │ │ │ │ - * } │ │ │ │ │ - * }) │ │ │ │ │ - * (end code) │ │ │ │ │ - * │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Layer.WMS │ │ │ │ │ + * Instances of OpenLayers.Layer.WMS are used to display data from OGC Web │ │ │ │ │ + * Mapping Services. Create a new WMS layer with the │ │ │ │ │ + * constructor. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.XYZ, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * Default is false, as UTFGrids are designed to be a transparent overlay layer. │ │ │ │ │ - */ │ │ │ │ │ - isBaseLayer: false, │ │ │ │ │ +OpenLayers.Layer.WMS = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: projection │ │ │ │ │ - * {} │ │ │ │ │ - * Source projection for the UTFGrids. Default is "EPSG:900913". │ │ │ │ │ + * Constant: DEFAULT_PARAMS │ │ │ │ │ + * {Object} Hashtable of default parameter key/value pairs │ │ │ │ │ */ │ │ │ │ │ - projection: new OpenLayers.Projection("EPSG:900913"), │ │ │ │ │ + DEFAULT_PARAMS: { │ │ │ │ │ + service: "WMS", │ │ │ │ │ + version: "1.1.1", │ │ │ │ │ + request: "GetMap", │ │ │ │ │ + styles: "", │ │ │ │ │ + format: "image/jpeg" │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: useJSONP │ │ │ │ │ - * {Boolean} │ │ │ │ │ - * Should we use a JSONP script approach instead of a standard AJAX call? │ │ │ │ │ - * │ │ │ │ │ - * Set to true for using utfgrids from another server. │ │ │ │ │ - * Avoids same-domain policy restrictions. │ │ │ │ │ - * Note that this only works if the server accepts │ │ │ │ │ - * the callback GET parameter and dynamically │ │ │ │ │ - * wraps the returned json in a function call. │ │ │ │ │ - * │ │ │ │ │ - * Default is false │ │ │ │ │ + * APIProperty: isBaseLayer │ │ │ │ │ + * {Boolean} Default is true for WMS layer │ │ │ │ │ */ │ │ │ │ │ - useJSONP: false, │ │ │ │ │ + isBaseLayer: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: url │ │ │ │ │ - * {String} │ │ │ │ │ - * URL tempate for UTFGrid tiles. Include x, y, and z parameters. │ │ │ │ │ - * E.g. "/tiles/${z}/${x}/${y}.json" │ │ │ │ │ + * APIProperty: encodeBBOX │ │ │ │ │ + * {Boolean} Should the BBOX commas be encoded? The WMS spec says 'no', │ │ │ │ │ + * but some services want it that way. Default false. │ │ │ │ │ */ │ │ │ │ │ + encodeBBOX: false, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: utfgridResolution │ │ │ │ │ - * {Number} │ │ │ │ │ - * Ratio of the pixel width to the width of a UTFGrid data point. If an │ │ │ │ │ - * entry in the grid represents a 4x4 block of pixels, the │ │ │ │ │ - * utfgridResolution would be 4. Default is 2 (specified in │ │ │ │ │ - * ). │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: noMagic │ │ │ │ │ + * {Boolean} If true, the image format will not be automagicaly switched │ │ │ │ │ + * from image/jpeg to image/png or image/gif when using │ │ │ │ │ + * TRANSPARENT=TRUE. Also isBaseLayer will not changed by the │ │ │ │ │ + * constructor. Default false. │ │ │ │ │ */ │ │ │ │ │ + noMagic: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: tileClass │ │ │ │ │ - * {} The tile class to use for this layer. │ │ │ │ │ - * Defaults is . │ │ │ │ │ + * Property: yx │ │ │ │ │ + * {Object} Keys in this object are EPSG codes for which the axis order │ │ │ │ │ + * is to be reversed (yx instead of xy, LatLon instead of LonLat), with │ │ │ │ │ + * true as value. This is only relevant for WMS versions >= 1.3.0, and │ │ │ │ │ + * only if yx is not set in for the │ │ │ │ │ + * used projection. │ │ │ │ │ */ │ │ │ │ │ - tileClass: OpenLayers.Tile.UTFGrid, │ │ │ │ │ + yx: {}, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.UTFGrid │ │ │ │ │ - * Create a new UTFGrid layer. │ │ │ │ │ + * Constructor: OpenLayers.Layer.WMS │ │ │ │ │ + * Create a new WMS layer object │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * config - {Object} Configuration properties for the layer. │ │ │ │ │ + * Examples: │ │ │ │ │ * │ │ │ │ │ - * Required configuration properties: │ │ │ │ │ - * url - {String} The url template for UTFGrid tiles. See the property. │ │ │ │ │ + * The code below creates a simple WMS layer using the image/jpeg format. │ │ │ │ │ + * (code) │ │ │ │ │ + * var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic", │ │ │ │ │ + * "http://wms.jpl.nasa.gov/wms.cgi", │ │ │ │ │ + * {layers: "modis,global_mosaic"}); │ │ │ │ │ + * (end) │ │ │ │ │ + * Note the 3rd argument (params). Properties added to this object will be │ │ │ │ │ + * added to the WMS GetMap requests used for this layer's tiles. The only │ │ │ │ │ + * mandatory parameter is "layers". Other common WMS params include │ │ │ │ │ + * "transparent", "styles" and "format". Note that the "srs" param will │ │ │ │ │ + * always be ignored. Instead, it will be derived from the baseLayer's or │ │ │ │ │ + * map's projection. │ │ │ │ │ + * │ │ │ │ │ + * The code below creates a transparent WMS layer with additional options. │ │ │ │ │ + * (code) │ │ │ │ │ + * var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic", │ │ │ │ │ + * "http://wms.jpl.nasa.gov/wms.cgi", │ │ │ │ │ + * { │ │ │ │ │ + * layers: "modis,global_mosaic", │ │ │ │ │ + * transparent: true │ │ │ │ │ + * }, { │ │ │ │ │ + * opacity: 0.5, │ │ │ │ │ + * singleTile: true │ │ │ │ │ + * }); │ │ │ │ │ + * (end) │ │ │ │ │ + * Note that by default, a WMS layer is configured as baseLayer. Setting │ │ │ │ │ + * the "transparent" param to true will apply some magic (see ). │ │ │ │ │ + * The default image format changes from image/jpeg to image/png, and the │ │ │ │ │ + * layer is not configured as baseLayer. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * name - {String} A name for the layer │ │ │ │ │ + * url - {String} Base url for the WMS │ │ │ │ │ + * (e.g. http://wms.jpl.nasa.gov/wms.cgi) │ │ │ │ │ + * params - {Object} An object with key/value pairs representing the │ │ │ │ │ + * GetMap query string parameters and parameter values. │ │ │ │ │ + * options - {Object} Hashtable of extra options to tag onto the layer. │ │ │ │ │ + * These options include all properties listed above, plus the ones │ │ │ │ │ + * inherited from superclasses. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply( │ │ │ │ │ - this, [options.name, options.url, {}, options] │ │ │ │ │ + initialize: function(name, url, params, options) { │ │ │ │ │ + var newArguments = []; │ │ │ │ │ + //uppercase params │ │ │ │ │ + params = OpenLayers.Util.upperCaseObject(params); │ │ │ │ │ + if (parseFloat(params.VERSION) >= 1.3 && !params.EXCEPTIONS) { │ │ │ │ │ + params.EXCEPTIONS = "INIMAGE"; │ │ │ │ │ + } │ │ │ │ │ + newArguments.push(name, url, params, options); │ │ │ │ │ + OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); │ │ │ │ │ + OpenLayers.Util.applyDefaults( │ │ │ │ │ + this.params, │ │ │ │ │ + OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS) │ │ │ │ │ ); │ │ │ │ │ - this.tileOptions = OpenLayers.Util.extend({ │ │ │ │ │ - utfgridResolution: this.utfgridResolution │ │ │ │ │ - }, this.tileOptions); │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: createBackBuffer │ │ │ │ │ - * The UTFGrid cannot create a back buffer, so this method is overriden. │ │ │ │ │ - */ │ │ │ │ │ - createBackBuffer: function() {}, │ │ │ │ │ + │ │ │ │ │ + //layer is transparent │ │ │ │ │ + if (!this.noMagic && this.params.TRANSPARENT && │ │ │ │ │ + this.params.TRANSPARENT.toString().toLowerCase() == "true") { │ │ │ │ │ + │ │ │ │ │ + // unless explicitly set in options, make layer an overlay │ │ │ │ │ + if ((options == null) || (!options.isBaseLayer)) { │ │ │ │ │ + this.isBaseLayer = false; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + // jpegs can never be transparent, so intelligently switch the │ │ │ │ │ + // format, depending on the browser's capabilities │ │ │ │ │ + if (this.params.FORMAT == "image/jpeg") { │ │ │ │ │ + this.params.FORMAT = OpenLayers.Util.alphaHack() ? "image/gif" : │ │ │ │ │ + "image/png"; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: clone │ │ │ │ │ + * Method: clone │ │ │ │ │ * Create a clone of this layer │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * obj - {Object} Only used by a subclass of this layer. │ │ │ │ │ - * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An exact clone of this OpenLayers.Layer.UTFGrid │ │ │ │ │ + * {} An exact clone of this layer │ │ │ │ │ */ │ │ │ │ │ clone: function(obj) { │ │ │ │ │ + │ │ │ │ │ if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.UTFGrid(this.getOptions()); │ │ │ │ │ + obj = new OpenLayers.Layer.WMS(this.name, │ │ │ │ │ + this.url, │ │ │ │ │ + this.params, │ │ │ │ │ + this.getOptions()); │ │ │ │ │ } │ │ │ │ │ │ │ │ │ │ - // get all additions from superclasses │ │ │ │ │ + //get all additions from superclasses │ │ │ │ │ obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ │ │ │ │ │ + // copy/set any non-init, non-simple values here │ │ │ │ │ + │ │ │ │ │ return obj; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: getFeatureInfo │ │ │ │ │ - * Get details about a feature associated with a map location. The object │ │ │ │ │ - * returned will have id and data properties. If the given location │ │ │ │ │ - * doesn't correspond to a feature, null will be returned. │ │ │ │ │ + * APIMethod: reverseAxisOrder │ │ │ │ │ + * Returns true if the axis order is reversed for the WMS version and │ │ │ │ │ + * projection of the layer. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} true if the axis order is reversed, false otherwise. │ │ │ │ │ + */ │ │ │ │ │ + reverseAxisOrder: function() { │ │ │ │ │ + var projCode = this.projection.getCode(); │ │ │ │ │ + return parseFloat(this.params.VERSION) >= 1.3 && │ │ │ │ │ + !!(this.yx[projCode] || (OpenLayers.Projection.defaults[projCode] && │ │ │ │ │ + OpenLayers.Projection.defaults[projCode].yx)); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: getURL │ │ │ │ │ + * Return a GetMap query string for this layer │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * location - {} map location │ │ │ │ │ + * bounds - {} A bounds representing the bbox for the │ │ │ │ │ + * request. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {Object} Object representing the feature id and UTFGrid data │ │ │ │ │ - * corresponding to the given map location. Returns null if the given │ │ │ │ │ - * location doesn't hit a feature. │ │ │ │ │ + * {String} A string with the layer's url and parameters and also the │ │ │ │ │ + * passed-in bounds and appropriate tile size specified as │ │ │ │ │ + * parameters. │ │ │ │ │ */ │ │ │ │ │ - getFeatureInfo: function(location) { │ │ │ │ │ - var info = null; │ │ │ │ │ - var tileInfo = this.getTileData(location); │ │ │ │ │ - if (tileInfo && tileInfo.tile) { │ │ │ │ │ - info = tileInfo.tile.getFeatureInfo(tileInfo.i, tileInfo.j); │ │ │ │ │ - } │ │ │ │ │ - return info; │ │ │ │ │ + getURL: function(bounds) { │ │ │ │ │ + bounds = this.adjustBounds(bounds); │ │ │ │ │ + │ │ │ │ │ + var imageSize = this.getImageSize(); │ │ │ │ │ + var newParams = {}; │ │ │ │ │ + // WMS 1.3 introduced axis order │ │ │ │ │ + var reverseAxisOrder = this.reverseAxisOrder(); │ │ │ │ │ + newParams.BBOX = this.encodeBBOX ? │ │ │ │ │ + bounds.toBBOX(null, reverseAxisOrder) : │ │ │ │ │ + bounds.toArray(reverseAxisOrder); │ │ │ │ │ + newParams.WIDTH = imageSize.w; │ │ │ │ │ + newParams.HEIGHT = imageSize.h; │ │ │ │ │ + var requestString = this.getFullRequestString(newParams); │ │ │ │ │ + return requestString; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: getFeatureId │ │ │ │ │ - * Get the identifier for the feature associated with a map location. │ │ │ │ │ - * │ │ │ │ │ + * APIMethod: mergeNewParams │ │ │ │ │ + * Catch changeParams and uppercase the new params to be merged in │ │ │ │ │ + * before calling changeParams on the super class. │ │ │ │ │ + * │ │ │ │ │ + * Once params have been changed, the tiles will be reloaded with │ │ │ │ │ + * the new parameters. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * location - {} map location │ │ │ │ │ + * newParams - {Object} Hashtable of new params to use │ │ │ │ │ + */ │ │ │ │ │ + mergeNewParams: function(newParams) { │ │ │ │ │ + var upperParams = OpenLayers.Util.upperCaseObject(newParams); │ │ │ │ │ + var newArguments = [upperParams]; │ │ │ │ │ + return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(this, │ │ │ │ │ + newArguments); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: getFullRequestString │ │ │ │ │ + * Combine the layer's url with its params and these newParams. │ │ │ │ │ + * │ │ │ │ │ + * Add the SRS parameter from projection -- this is probably │ │ │ │ │ + * more eloquently done via a setProjection() method, but this │ │ │ │ │ + * works for now and always. │ │ │ │ │ * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newParams - {Object} │ │ │ │ │ + * altUrl - {String} Use this as the url instead of the layer's url │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} The feature identifier corresponding to the given map location. │ │ │ │ │ - * Returns null if the location doesn't hit a feature. │ │ │ │ │ + * {String} │ │ │ │ │ */ │ │ │ │ │ - getFeatureId: function(location) { │ │ │ │ │ - var id = null; │ │ │ │ │ - var info = this.getTileData(location); │ │ │ │ │ - if (info.tile) { │ │ │ │ │ - id = info.tile.getFeatureId(info.i, info.j); │ │ │ │ │ + getFullRequestString: function(newParams, altUrl) { │ │ │ │ │ + var mapProjection = this.map.getProjectionObject(); │ │ │ │ │ + var projectionCode = this.projection && this.projection.equals(mapProjection) ? │ │ │ │ │ + this.projection.getCode() : │ │ │ │ │ + mapProjection.getCode(); │ │ │ │ │ + var value = (projectionCode == "none") ? null : projectionCode; │ │ │ │ │ + if (parseFloat(this.params.VERSION) >= 1.3) { │ │ │ │ │ + this.params.CRS = value; │ │ │ │ │ + } else { │ │ │ │ │ + this.params.SRS = value; │ │ │ │ │ } │ │ │ │ │ - return id; │ │ │ │ │ + │ │ │ │ │ + if (typeof this.params.TRANSPARENT == "boolean") { │ │ │ │ │ + newParams.TRANSPARENT = this.params.TRANSPARENT ? "TRUE" : "FALSE"; │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + return OpenLayers.Layer.Grid.prototype.getFullRequestString.apply( │ │ │ │ │ + this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.UTFGrid" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Layer.WMS" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/EventPane.js │ │ │ │ │ + OpenLayers/Handler/RegularPolygon.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published 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/Util.js │ │ │ │ │ + * @requires OpenLayers/Handler/Drag.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.EventPane │ │ │ │ │ - * Base class for 3rd party layers, providing a DOM element which isolates │ │ │ │ │ - * the 3rd-party layer from mouse events. │ │ │ │ │ - * Only used by Google layers. │ │ │ │ │ - * │ │ │ │ │ - * Automatically instantiated by the Google constructor, and not usually instantiated directly. │ │ │ │ │ - * │ │ │ │ │ - * Create a new event pane layer with the │ │ │ │ │ - * constructor. │ │ │ │ │ + * Class: OpenLayers.Handler.RegularPolygon │ │ │ │ │ + * Handler to draw a regular polygon on the map. Polygon is displayed on mouse │ │ │ │ │ + * down, moves or is modified on mouse move, and is finished on mouse up. │ │ │ │ │ + * The handler triggers callbacks for 'done' and 'cancel'. Create a new │ │ │ │ │ + * instance with the constructor. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.EventPane = OpenLayers.Class(OpenLayers.Layer, { │ │ │ │ │ +OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: smoothDragPan │ │ │ │ │ - * {Boolean} smoothDragPan determines whether non-public/internal API │ │ │ │ │ - * methods are used for better performance while dragging EventPane │ │ │ │ │ - * layers. When not in sphericalMercator mode, the smoother dragging │ │ │ │ │ - * doesn't actually move north/south directly with the number of │ │ │ │ │ - * pixels moved, resulting in a slight offset when you drag your mouse │ │ │ │ │ - * north south with this option on. If this visual disparity bothers │ │ │ │ │ - * you, you should turn this option off, or use spherical mercator. │ │ │ │ │ - * Default is on. │ │ │ │ │ + * APIProperty: sides │ │ │ │ │ + * {Integer} Number of sides for the regular polygon. Needs to be greater │ │ │ │ │ + * than 2. Defaults to 4. │ │ │ │ │ */ │ │ │ │ │ - smoothDragPan: true, │ │ │ │ │ + sides: 4, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: isBaseLayer │ │ │ │ │ - * {Boolean} EventPaned layers are always base layers, by necessity. │ │ │ │ │ + * APIProperty: radius │ │ │ │ │ + * {Float} Optional radius in map units of the regular polygon. If this is │ │ │ │ │ + * set to some non-zero value, a polygon with a fixed radius will be │ │ │ │ │ + * drawn and dragged with mose movements. If this property is not │ │ │ │ │ + * set, dragging changes the radius of the polygon. Set to null by │ │ │ │ │ + * default. │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + radius: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isFixed │ │ │ │ │ - * {Boolean} EventPaned layers are fixed by default. │ │ │ │ │ + * APIProperty: snapAngle │ │ │ │ │ + * {Float} If set to a non-zero value, the handler will snap the polygon │ │ │ │ │ + * rotation to multiples of the snapAngle. Value is an angle measured │ │ │ │ │ + * in degrees counterclockwise from the positive x-axis. │ │ │ │ │ */ │ │ │ │ │ - isFixed: true, │ │ │ │ │ + snapAngle: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: pane │ │ │ │ │ - * {DOMElement} A reference to the element that controls the events. │ │ │ │ │ + * APIProperty: snapToggle │ │ │ │ │ + * {String} If set, snapToggle is checked on mouse events and will set │ │ │ │ │ + * the snap mode to the opposite of what it currently is. To disallow │ │ │ │ │ + * toggling between snap and non-snap mode, set freehandToggle to │ │ │ │ │ + * null. Acceptable toggle values are 'shiftKey', 'ctrlKey', and │ │ │ │ │ + * 'altKey'. Snap mode is only possible if this.snapAngle is set to a │ │ │ │ │ + * non-zero value. │ │ │ │ │ */ │ │ │ │ │ - pane: null, │ │ │ │ │ - │ │ │ │ │ + snapToggle: 'shiftKey', │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: mapObject │ │ │ │ │ - * {Object} This is the object which will be used to load the 3rd party library │ │ │ │ │ - * in the case of the google layer, this will be of type GMap, │ │ │ │ │ - * in the case of the ve layer, this will be of type VEMap │ │ │ │ │ + * Property: layerOptions │ │ │ │ │ + * {Object} Any optional properties to be set on the sketch layer. │ │ │ │ │ */ │ │ │ │ │ - mapObject: null, │ │ │ │ │ - │ │ │ │ │ + layerOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.EventPane │ │ │ │ │ - * Create a new event pane layer │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} │ │ │ │ │ - * options - {Object} Hashtable of extra options to tag onto the layer │ │ │ │ │ + * APIProperty: persist │ │ │ │ │ + * {Boolean} Leave the feature rendered until clear is called. Default │ │ │ │ │ + * is false. If set to true, the feature remains rendered until │ │ │ │ │ + * clear is called, typically by deactivating the handler or starting │ │ │ │ │ + * another drawing. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, options) { │ │ │ │ │ - OpenLayers.Layer.prototype.initialize.apply(this, arguments); │ │ │ │ │ - if (this.pane == null) { │ │ │ │ │ - this.pane = OpenLayers.Util.createDiv(this.div.id + "_EventPane"); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + persist: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: destroy │ │ │ │ │ - * Deconstruct this layer. │ │ │ │ │ + * APIProperty: irregular │ │ │ │ │ + * {Boolean} Draw an irregular polygon instead of a regular polygon. │ │ │ │ │ + * Default is false. If true, the initial mouse down will represent │ │ │ │ │ + * one corner of the polygon bounds and with each mouse movement, the │ │ │ │ │ + * polygon will be stretched so the opposite corner of its bounds │ │ │ │ │ + * follows the mouse position. This property takes precedence over │ │ │ │ │ + * the radius property. If set to true, the radius property will │ │ │ │ │ + * be ignored. │ │ │ │ │ */ │ │ │ │ │ - destroy: function() { │ │ │ │ │ - this.mapObject = null; │ │ │ │ │ - this.pane = null; │ │ │ │ │ - OpenLayers.Layer.prototype.destroy.apply(this, arguments); │ │ │ │ │ - }, │ │ │ │ │ + irregular: false, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: citeCompliant │ │ │ │ │ + * {Boolean} If set to true, coordinates of features drawn in a map extent │ │ │ │ │ + * crossing the date line won't exceed the world bounds. Default is false. │ │ │ │ │ + */ │ │ │ │ │ + citeCompliant: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setMap │ │ │ │ │ - * Set the map property for the layer. This is done through an accessor │ │ │ │ │ - * so that subclasses can override this and take special action once │ │ │ │ │ - * they have their map variable set. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * Property: angle │ │ │ │ │ + * {Float} The angle from the origin (mouse down) to the current mouse │ │ │ │ │ + * position, in radians. This is measured counterclockwise from the │ │ │ │ │ + * positive x-axis. │ │ │ │ │ */ │ │ │ │ │ - setMap: function(map) { │ │ │ │ │ - OpenLayers.Layer.prototype.setMap.apply(this, arguments); │ │ │ │ │ + angle: null, │ │ │ │ │ │ │ │ │ │ - this.pane.style.zIndex = parseInt(this.div.style.zIndex) + 1; │ │ │ │ │ - this.pane.style.display = this.div.style.display; │ │ │ │ │ - this.pane.style.width = "100%"; │ │ │ │ │ - this.pane.style.height = "100%"; │ │ │ │ │ - if (OpenLayers.BROWSER_NAME == "msie") { │ │ │ │ │ - this.pane.style.background = │ │ │ │ │ - "url(" + OpenLayers.Util.getImageLocation("blank.gif") + ")"; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: fixedRadius │ │ │ │ │ + * {Boolean} The polygon has a fixed radius. True if a radius is set before │ │ │ │ │ + * drawing begins. False otherwise. │ │ │ │ │ + */ │ │ │ │ │ + fixedRadius: false, │ │ │ │ │ │ │ │ │ │ - if (this.isFixed) { │ │ │ │ │ - this.map.viewPortDiv.appendChild(this.pane); │ │ │ │ │ - } else { │ │ │ │ │ - this.map.layerContainerDiv.appendChild(this.pane); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: feature │ │ │ │ │ + * {} The currently drawn polygon feature │ │ │ │ │ + */ │ │ │ │ │ + feature: null, │ │ │ │ │ │ │ │ │ │ - // once our layer has been added to the map, we can load it │ │ │ │ │ - this.loadMapObject(); │ │ │ │ │ + /** │ │ │ │ │ + * Property: layer │ │ │ │ │ + * {} The temporary drawing layer │ │ │ │ │ + */ │ │ │ │ │ + layer: null, │ │ │ │ │ │ │ │ │ │ - // if map didn't load, display warning │ │ │ │ │ - if (this.mapObject == null) { │ │ │ │ │ - this.loadWarningMessage(); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: origin │ │ │ │ │ + * {} Location of the first mouse down │ │ │ │ │ + */ │ │ │ │ │ + origin: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: removeMap │ │ │ │ │ - * On being removed from the map, we'll like to remove the invisible 'pane' │ │ │ │ │ - * div that we added to it on creation. │ │ │ │ │ - * │ │ │ │ │ + * Constructor: OpenLayers.Handler.RegularPolygon │ │ │ │ │ + * Create a new regular polygon handler. │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * map - {} │ │ │ │ │ + * control - {} The control that owns this handler │ │ │ │ │ + * callbacks - {Object} An object with a properties whose values are │ │ │ │ │ + * functions. Various callbacks described below. │ │ │ │ │ + * options - {Object} An object with properties to be set on the handler. │ │ │ │ │ + * If the options.sides property is not specified, the number of sides │ │ │ │ │ + * will default to 4. │ │ │ │ │ + * │ │ │ │ │ + * Named callbacks: │ │ │ │ │ + * create - Called when a sketch is first created. Callback called with │ │ │ │ │ + * the creation point geometry and sketch feature. │ │ │ │ │ + * done - Called when the sketch drawing is finished. The callback will │ │ │ │ │ + * recieve a single argument, the sketch geometry. │ │ │ │ │ + * cancel - Called when the handler is deactivated while drawing. The │ │ │ │ │ + * cancel callback will receive a geometry. │ │ │ │ │ */ │ │ │ │ │ - removeMap: function(map) { │ │ │ │ │ - if (this.pane && this.pane.parentNode) { │ │ │ │ │ - this.pane.parentNode.removeChild(this.pane); │ │ │ │ │ + initialize: function(control, callbacks, options) { │ │ │ │ │ + if (!(options && options.layerOptions && options.layerOptions.styleMap)) { │ │ │ │ │ + this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {}); │ │ │ │ │ } │ │ │ │ │ - OpenLayers.Layer.prototype.removeMap.apply(this, arguments); │ │ │ │ │ + │ │ │ │ │ + OpenLayers.Handler.Drag.prototype.initialize.apply(this, │ │ │ │ │ + [control, callbacks, options]); │ │ │ │ │ + this.options = (options) ? options : {}; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: loadWarningMessage │ │ │ │ │ - * If we can't load the map lib, then display an error message to the │ │ │ │ │ - * user and tell them where to go for help. │ │ │ │ │ + * APIMethod: setOptions │ │ │ │ │ * │ │ │ │ │ - * This function sets up the layout for the warning message. Each 3rd │ │ │ │ │ - * party layer must implement its own getWarningHTML() function to │ │ │ │ │ - * provide the actual warning message. │ │ │ │ │ + * Parameters: │ │ │ │ │ + * newOptions - {Object} │ │ │ │ │ */ │ │ │ │ │ - loadWarningMessage: function() { │ │ │ │ │ - │ │ │ │ │ - this.div.style.backgroundColor = "darkblue"; │ │ │ │ │ - │ │ │ │ │ - var viewSize = this.map.getSize(); │ │ │ │ │ - │ │ │ │ │ - var msgW = Math.min(viewSize.w, 300); │ │ │ │ │ - var msgH = Math.min(viewSize.h, 200); │ │ │ │ │ - var size = new OpenLayers.Size(msgW, msgH); │ │ │ │ │ - │ │ │ │ │ - var centerPx = new OpenLayers.Pixel(viewSize.w / 2, viewSize.h / 2); │ │ │ │ │ - │ │ │ │ │ - var topLeft = centerPx.add(-size.w / 2, -size.h / 2); │ │ │ │ │ - │ │ │ │ │ - var div = OpenLayers.Util.createDiv(this.name + "_warning", │ │ │ │ │ - topLeft, │ │ │ │ │ - size, │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - null, │ │ │ │ │ - "auto"); │ │ │ │ │ - │ │ │ │ │ - div.style.padding = "7px"; │ │ │ │ │ - div.style.backgroundColor = "yellow"; │ │ │ │ │ - │ │ │ │ │ - div.innerHTML = this.getWarningHTML(); │ │ │ │ │ - this.div.appendChild(div); │ │ │ │ │ + setOptions: function(newOptions) { │ │ │ │ │ + OpenLayers.Util.extend(this.options, newOptions); │ │ │ │ │ + OpenLayers.Util.extend(this, newOptions); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: getWarningHTML │ │ │ │ │ - * To be implemented by subclasses. │ │ │ │ │ - * │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Turn on the handler. │ │ │ │ │ + * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} String with information on why layer is broken, how to get │ │ │ │ │ - * it working. │ │ │ │ │ + * {Boolean} The handler was successfully activated │ │ │ │ │ */ │ │ │ │ │ - getWarningHTML: function() { │ │ │ │ │ - //should be implemented by subclasses │ │ │ │ │ - return ""; │ │ │ │ │ + activate: function() { │ │ │ │ │ + var activated = false; │ │ │ │ │ + if (OpenLayers.Handler.Drag.prototype.activate.apply(this, arguments)) { │ │ │ │ │ + // create temporary vector layer for rendering geometry sketch │ │ │ │ │ + var options = OpenLayers.Util.extend({ │ │ │ │ │ + displayInLayerSwitcher: false, │ │ │ │ │ + // indicate that the temp vector layer will never be out of range │ │ │ │ │ + // without this, resolution properties must be specified at the │ │ │ │ │ + // map-level for this temporary layer to init its resolutions │ │ │ │ │ + // correctly │ │ │ │ │ + calculateInRange: OpenLayers.Function.True, │ │ │ │ │ + wrapDateLine: this.citeCompliant │ │ │ │ │ + }, this.layerOptions); │ │ │ │ │ + this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options); │ │ │ │ │ + this.map.addLayer(this.layer); │ │ │ │ │ + activated = true; │ │ │ │ │ + } │ │ │ │ │ + return activated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: display │ │ │ │ │ - * Set the display on the pane │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Turn off the handler. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * display - {Boolean} │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Boolean} The handler was successfully deactivated │ │ │ │ │ */ │ │ │ │ │ - display: function(display) { │ │ │ │ │ - OpenLayers.Layer.prototype.display.apply(this, arguments); │ │ │ │ │ - this.pane.style.display = this.div.style.display; │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = false; │ │ │ │ │ + if (OpenLayers.Handler.Drag.prototype.deactivate.apply(this, arguments)) { │ │ │ │ │ + // call the cancel callback if mid-drawing │ │ │ │ │ + if (this.dragging) { │ │ │ │ │ + this.cancel(); │ │ │ │ │ + } │ │ │ │ │ + // If a layer's map property is set to null, it means that that │ │ │ │ │ + // layer isn't added to the map. Since we ourself added the layer │ │ │ │ │ + // to the map in activate(), we can assume that if this.layer.map │ │ │ │ │ + // is null it means that the layer has been destroyed (as a result │ │ │ │ │ + // of map.destroy() for example. │ │ │ │ │ + if (this.layer.map != null) { │ │ │ │ │ + this.layer.destroy(false); │ │ │ │ │ + if (this.feature) { │ │ │ │ │ + this.feature.destroy(); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + this.layer = null; │ │ │ │ │ + this.feature = null; │ │ │ │ │ + deactivated = true; │ │ │ │ │ + } │ │ │ │ │ + return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setZIndex │ │ │ │ │ - * Set the z-index order for the pane. │ │ │ │ │ - * │ │ │ │ │ + * Method: down │ │ │ │ │ + * Start drawing a new feature │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * zIndex - {int} │ │ │ │ │ + * evt - {Event} The drag start event │ │ │ │ │ */ │ │ │ │ │ - setZIndex: function(zIndex) { │ │ │ │ │ - OpenLayers.Layer.prototype.setZIndex.apply(this, arguments); │ │ │ │ │ - this.pane.style.zIndex = parseInt(this.div.style.zIndex) + 1; │ │ │ │ │ + down: function(evt) { │ │ │ │ │ + this.fixedRadius = !!(this.radius); │ │ │ │ │ + var maploc = this.layer.getLonLatFromViewPortPx(evt.xy); │ │ │ │ │ + this.origin = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat); │ │ │ │ │ + // create the new polygon │ │ │ │ │ + if (!this.fixedRadius || this.irregular) { │ │ │ │ │ + // smallest radius should not be less one pixel in map units │ │ │ │ │ + // VML doesn't behave well with smaller │ │ │ │ │ + this.radius = this.map.getResolution(); │ │ │ │ │ + } │ │ │ │ │ + if (this.persist) { │ │ │ │ │ + this.clear(); │ │ │ │ │ + } │ │ │ │ │ + this.feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ + this.createGeometry(); │ │ │ │ │ + this.callback("create", [this.origin, this.feature]); │ │ │ │ │ + this.layer.addFeatures([this.feature], { │ │ │ │ │ + silent: true │ │ │ │ │ + }); │ │ │ │ │ + this.layer.drawFeature(this.feature, this.style); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: moveByPx │ │ │ │ │ - * Move the layer based on pixel vector. To be implemented by subclasses. │ │ │ │ │ + * Method: move │ │ │ │ │ + * Respond to drag move events │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * dx - {Number} The x coord of the displacement vector. │ │ │ │ │ - * dy - {Number} The y coord of the displacement vector. │ │ │ │ │ + * evt - {Evt} The move event │ │ │ │ │ */ │ │ │ │ │ - moveByPx: function(dx, dy) { │ │ │ │ │ - OpenLayers.Layer.prototype.moveByPx.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - if (this.dragPanMapObject) { │ │ │ │ │ - this.dragPanMapObject(dx, -dy); │ │ │ │ │ + move: function(evt) { │ │ │ │ │ + var maploc = this.layer.getLonLatFromViewPortPx(evt.xy); │ │ │ │ │ + var point = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat); │ │ │ │ │ + if (this.irregular) { │ │ │ │ │ + var ry = Math.sqrt(2) * Math.abs(point.y - this.origin.y) / 2; │ │ │ │ │ + this.radius = Math.max(this.map.getResolution() / 2, ry); │ │ │ │ │ + } else if (this.fixedRadius) { │ │ │ │ │ + this.origin = point; │ │ │ │ │ } else { │ │ │ │ │ - this.moveTo(this.map.getCachedCenter()); │ │ │ │ │ + this.calculateAngle(point, evt); │ │ │ │ │ + this.radius = Math.max(this.map.getResolution() / 2, │ │ │ │ │ + point.distanceTo(this.origin)); │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: moveTo │ │ │ │ │ - * Handle calls to move the layer. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * bounds - {} │ │ │ │ │ - * zoomChanged - {Boolean} │ │ │ │ │ - * dragging - {Boolean} │ │ │ │ │ - */ │ │ │ │ │ - moveTo: function(bounds, zoomChanged, dragging) { │ │ │ │ │ - OpenLayers.Layer.prototype.moveTo.apply(this, arguments); │ │ │ │ │ - │ │ │ │ │ - if (this.mapObject != null) { │ │ │ │ │ - │ │ │ │ │ - var newCenter = this.map.getCenter(); │ │ │ │ │ - var newZoom = this.map.getZoom(); │ │ │ │ │ - │ │ │ │ │ - if (newCenter != null) { │ │ │ │ │ - │ │ │ │ │ - var moOldCenter = this.getMapObjectCenter(); │ │ │ │ │ - var oldCenter = this.getOLLonLatFromMapObjectLonLat(moOldCenter); │ │ │ │ │ - │ │ │ │ │ - var moOldZoom = this.getMapObjectZoom(); │ │ │ │ │ - var oldZoom = this.getOLZoomFromMapObjectZoom(moOldZoom); │ │ │ │ │ - │ │ │ │ │ - if (!(newCenter.equals(oldCenter)) || newZoom != oldZoom) { │ │ │ │ │ - │ │ │ │ │ - if (!zoomChanged && oldCenter && this.dragPanMapObject && │ │ │ │ │ - this.smoothDragPan) { │ │ │ │ │ - var oldPx = this.map.getViewPortPxFromLonLat(oldCenter); │ │ │ │ │ - var newPx = this.map.getViewPortPxFromLonLat(newCenter); │ │ │ │ │ - this.dragPanMapObject(newPx.x - oldPx.x, oldPx.y - newPx.y); │ │ │ │ │ - } else { │ │ │ │ │ - var center = this.getMapObjectLonLatFromOLLonLat(newCenter); │ │ │ │ │ - var zoom = this.getMapObjectZoomFromOLZoom(newZoom); │ │ │ │ │ - this.setMapObjectCenter(center, zoom, dragging); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + this.modifyGeometry(); │ │ │ │ │ + if (this.irregular) { │ │ │ │ │ + var dx = point.x - this.origin.x; │ │ │ │ │ + var dy = point.y - this.origin.y; │ │ │ │ │ + var ratio; │ │ │ │ │ + if (dy == 0) { │ │ │ │ │ + ratio = dx / (this.radius * Math.sqrt(2)); │ │ │ │ │ + } else { │ │ │ │ │ + ratio = dx / dy; │ │ │ │ │ } │ │ │ │ │ + this.feature.geometry.resize(1, this.origin, ratio); │ │ │ │ │ + this.feature.geometry.move(dx / 2, dy / 2); │ │ │ │ │ } │ │ │ │ │ + this.layer.drawFeature(this.feature, this.style); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Baselayer Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: getLonLatFromViewPortPx │ │ │ │ │ - * Get a map location from a pixel location │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * viewPortPx - {} │ │ │ │ │ + * Method: up │ │ │ │ │ + * Finish drawing the feature │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.LonLat which is the passed-in view │ │ │ │ │ - * port OpenLayers.Pixel, translated into lon/lat by map lib │ │ │ │ │ - * If the map lib is not loaded or not centered, returns null │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} The mouse up event │ │ │ │ │ */ │ │ │ │ │ - getLonLatFromViewPortPx: function(viewPortPx) { │ │ │ │ │ - var lonlat = null; │ │ │ │ │ - if ((this.mapObject != null) && │ │ │ │ │ - (this.getMapObjectCenter() != null)) { │ │ │ │ │ - var moPixel = this.getMapObjectPixelFromOLPixel(viewPortPx); │ │ │ │ │ - var moLonLat = this.getMapObjectLonLatFromMapObjectPixel(moPixel); │ │ │ │ │ - lonlat = this.getOLLonLatFromMapObjectLonLat(moLonLat); │ │ │ │ │ + up: function(evt) { │ │ │ │ │ + this.finalize(); │ │ │ │ │ + // the mouseup method of superclass doesn't call the │ │ │ │ │ + // "done" callback if there's been no move between │ │ │ │ │ + // down and up │ │ │ │ │ + if (this.start == this.last) { │ │ │ │ │ + this.callback("done", [evt.xy]); │ │ │ │ │ } │ │ │ │ │ - return lonlat; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: getViewPortPxFromLonLat │ │ │ │ │ - * Get a pixel location from a map location │ │ │ │ │ + * Method: out │ │ │ │ │ + * Finish drawing the feature. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * lonlat - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.Pixel which is the passed-in │ │ │ │ │ - * OpenLayers.LonLat, translated into view port pixels by map lib │ │ │ │ │ - * If map lib is not loaded or not centered, returns null │ │ │ │ │ + * evt - {Event} The mouse out event │ │ │ │ │ */ │ │ │ │ │ - getViewPortPxFromLonLat: function(lonlat) { │ │ │ │ │ - var viewPortPx = null; │ │ │ │ │ - if ((this.mapObject != null) && │ │ │ │ │ - (this.getMapObjectCenter() != null)) { │ │ │ │ │ - │ │ │ │ │ - var moLonLat = this.getMapObjectLonLatFromOLLonLat(lonlat); │ │ │ │ │ - var moPixel = this.getMapObjectPixelFromMapObjectLonLat(moLonLat); │ │ │ │ │ + out: function(evt) { │ │ │ │ │ + this.finalize(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - viewPortPx = this.getOLPixelFromMapObjectPixel(moPixel); │ │ │ │ │ + /** │ │ │ │ │ + * Method: createGeometry │ │ │ │ │ + * Create the new polygon geometry. This is called at the start of the │ │ │ │ │ + * drag and at any point during the drag if the number of sides │ │ │ │ │ + * changes. │ │ │ │ │ + */ │ │ │ │ │ + createGeometry: function() { │ │ │ │ │ + this.angle = Math.PI * ((1 / this.sides) - (1 / 2)); │ │ │ │ │ + if (this.snapAngle) { │ │ │ │ │ + this.angle += this.snapAngle * (Math.PI / 180); │ │ │ │ │ } │ │ │ │ │ - return viewPortPx; │ │ │ │ │ + this.feature.geometry = OpenLayers.Geometry.Polygon.createRegularPolygon( │ │ │ │ │ + this.origin, this.radius, this.sides, this.snapAngle │ │ │ │ │ + ); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - /* */ │ │ │ │ │ - /* Translation Functions */ │ │ │ │ │ - /* */ │ │ │ │ │ - /* The following functions translate Map Object and */ │ │ │ │ │ - /* OL formats for Pixel, LonLat */ │ │ │ │ │ - /* */ │ │ │ │ │ - /********************************************************/ │ │ │ │ │ - │ │ │ │ │ - // │ │ │ │ │ - // TRANSLATION: MapObject LatLng <-> OpenLayers.LonLat │ │ │ │ │ - // │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: getOLLonLatFromMapObjectLonLat │ │ │ │ │ - * Get an OL style map location from a 3rd party style map location │ │ │ │ │ - * │ │ │ │ │ - * Parameters │ │ │ │ │ - * moLonLat - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.LonLat, translated from the passed in │ │ │ │ │ - * MapObject LonLat │ │ │ │ │ - * Returns null if null value is passed in │ │ │ │ │ + * Method: modifyGeometry │ │ │ │ │ + * Modify the polygon geometry in place. │ │ │ │ │ */ │ │ │ │ │ - getOLLonLatFromMapObjectLonLat: function(moLonLat) { │ │ │ │ │ - var olLonLat = null; │ │ │ │ │ - if (moLonLat != null) { │ │ │ │ │ - var lon = this.getLongitudeFromMapObjectLonLat(moLonLat); │ │ │ │ │ - var lat = this.getLatitudeFromMapObjectLonLat(moLonLat); │ │ │ │ │ - olLonLat = new OpenLayers.LonLat(lon, lat); │ │ │ │ │ + modifyGeometry: function() { │ │ │ │ │ + var angle, point; │ │ │ │ │ + var ring = this.feature.geometry.components[0]; │ │ │ │ │ + // if the number of sides ever changes, create a new geometry │ │ │ │ │ + if (ring.components.length != (this.sides + 1)) { │ │ │ │ │ + this.createGeometry(); │ │ │ │ │ + ring = this.feature.geometry.components[0]; │ │ │ │ │ + } │ │ │ │ │ + for (var i = 0; i < this.sides; ++i) { │ │ │ │ │ + point = ring.components[i]; │ │ │ │ │ + angle = this.angle + (i * 2 * Math.PI / this.sides); │ │ │ │ │ + point.x = this.origin.x + (this.radius * Math.cos(angle)); │ │ │ │ │ + point.y = this.origin.y + (this.radius * Math.sin(angle)); │ │ │ │ │ + point.clearBounds(); │ │ │ │ │ } │ │ │ │ │ - return olLonLat; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getMapObjectLonLatFromOLLonLat │ │ │ │ │ - * Get a 3rd party map location from an OL map location. │ │ │ │ │ + * Method: calculateAngle │ │ │ │ │ + * Calculate the angle based on settings. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * olLonLat - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} A MapObject LonLat, translated from the passed in │ │ │ │ │ - * OpenLayers.LonLat │ │ │ │ │ - * Returns null if null value is passed in │ │ │ │ │ + * point - {} │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - getMapObjectLonLatFromOLLonLat: function(olLonLat) { │ │ │ │ │ - var moLatLng = null; │ │ │ │ │ - if (olLonLat != null) { │ │ │ │ │ - moLatLng = this.getMapObjectLonLatFromLonLat(olLonLat.lon, │ │ │ │ │ - olLonLat.lat); │ │ │ │ │ + calculateAngle: function(point, evt) { │ │ │ │ │ + var alpha = Math.atan2(point.y - this.origin.y, │ │ │ │ │ + point.x - this.origin.x); │ │ │ │ │ + if (this.snapAngle && (this.snapToggle && !evt[this.snapToggle])) { │ │ │ │ │ + var snapAngleRad = (Math.PI / 180) * this.snapAngle; │ │ │ │ │ + this.angle = Math.round(alpha / snapAngleRad) * snapAngleRad; │ │ │ │ │ + } else { │ │ │ │ │ + this.angle = alpha; │ │ │ │ │ } │ │ │ │ │ - return moLatLng; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: cancel │ │ │ │ │ + * Finish the geometry and call the "cancel" callback. │ │ │ │ │ + */ │ │ │ │ │ + cancel: function() { │ │ │ │ │ + // the polygon geometry gets cloned in the callback method │ │ │ │ │ + this.callback("cancel", null); │ │ │ │ │ + this.finalize(); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // │ │ │ │ │ - // TRANSLATION: MapObject Pixel <-> OpenLayers.Pixel │ │ │ │ │ - // │ │ │ │ │ + /** │ │ │ │ │ + * Method: finalize │ │ │ │ │ + * Finish the geometry and call the "done" callback. │ │ │ │ │ + */ │ │ │ │ │ + finalize: function() { │ │ │ │ │ + this.origin = null; │ │ │ │ │ + this.radius = this.options.radius; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getOLPixelFromMapObjectPixel │ │ │ │ │ - * Get an OL pixel location from a 3rd party pixel location. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * moPixel - {Object} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An OpenLayers.Pixel, translated from the passed in │ │ │ │ │ - * MapObject Pixel │ │ │ │ │ - * Returns null if null value is passed in │ │ │ │ │ + * APIMethod: clear │ │ │ │ │ + * Clear any rendered features on the temporary layer. This is called │ │ │ │ │ + * when the handler is deactivated, canceled, or done (unless persist │ │ │ │ │ + * is true). │ │ │ │ │ */ │ │ │ │ │ - getOLPixelFromMapObjectPixel: function(moPixel) { │ │ │ │ │ - var olPixel = null; │ │ │ │ │ - if (moPixel != null) { │ │ │ │ │ - var x = this.getXFromMapObjectPixel(moPixel); │ │ │ │ │ - var y = this.getYFromMapObjectPixel(moPixel); │ │ │ │ │ - olPixel = new OpenLayers.Pixel(x, y); │ │ │ │ │ + clear: function() { │ │ │ │ │ + if (this.layer) { │ │ │ │ │ + this.layer.renderer.clear(); │ │ │ │ │ + this.layer.destroyFeatures(); │ │ │ │ │ } │ │ │ │ │ - return olPixel; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getMapObjectPixelFromOLPixel │ │ │ │ │ - * Get a 3rd party pixel location from an OL pixel location │ │ │ │ │ + * Method: callback │ │ │ │ │ + * Trigger the control's named callback with the given arguments │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * olPixel - {} │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} A MapObject Pixel, translated from the passed in │ │ │ │ │ - * OpenLayers.Pixel │ │ │ │ │ - * Returns null if null value is passed in │ │ │ │ │ + * name - {String} The key for the callback that is one of the properties │ │ │ │ │ + * of the handler's callbacks object. │ │ │ │ │ + * args - {Array} An array of arguments with which to call the callback │ │ │ │ │ + * (defined by the control). │ │ │ │ │ */ │ │ │ │ │ - getMapObjectPixelFromOLPixel: function(olPixel) { │ │ │ │ │ - var moPixel = null; │ │ │ │ │ - if (olPixel != null) { │ │ │ │ │ - moPixel = this.getMapObjectPixelFromXY(olPixel.x, olPixel.y); │ │ │ │ │ + callback: function(name, args) { │ │ │ │ │ + // override the callback method to always send the polygon geometry │ │ │ │ │ + if (this.callbacks[name]) { │ │ │ │ │ + this.callbacks[name].apply(this.control, │ │ │ │ │ + [this.feature.geometry.clone()]); │ │ │ │ │ + } │ │ │ │ │ + // since sketch features are added to the temporary layer │ │ │ │ │ + // they must be cleared here if done or cancel │ │ │ │ │ + if (!this.persist && (name == "done" || name == "cancel")) { │ │ │ │ │ + this.clear(); │ │ │ │ │ } │ │ │ │ │ - return moPixel; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.EventPane" │ │ │ │ │ + CLASS_NAME: "OpenLayers.Handler.RegularPolygon" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Format/ArcXML.js │ │ │ │ │ + OpenLayers/Format/SLD.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Format/XML.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Polygon.js │ │ │ │ │ - * @requires OpenLayers/Geometry/Point.js │ │ │ │ │ - * @requires OpenLayers/Geometry/MultiPolygon.js │ │ │ │ │ - * @requires OpenLayers/Geometry/LinearRing.js │ │ │ │ │ + * @requires OpenLayers/Format/XML/VersionedOGC.js │ │ │ │ │ + * @requires OpenLayers/Style.js │ │ │ │ │ + * @requires OpenLayers/Rule.js │ │ │ │ │ + * @requires OpenLayers/Filter/FeatureId.js │ │ │ │ │ + * @requires OpenLayers/Filter/Logical.js │ │ │ │ │ + * @requires OpenLayers/Filter/Comparison.js │ │ │ │ │ + * @requires OpenLayers/Filter/Spatial.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Format.ArcXML │ │ │ │ │ - * Read/Write ArcXML. Create a new instance with the │ │ │ │ │ + * Class: OpenLayers.Format.SLD │ │ │ │ │ + * Read/Write SLD. Create a new instance with the │ │ │ │ │ * constructor. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Format.ArcXML = OpenLayers.Class(OpenLayers.Format.XML, { │ │ │ │ │ +OpenLayers.Format.SLD = OpenLayers.Class(OpenLayers.Format.XML.VersionedOGC, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: fontStyleKeys │ │ │ │ │ - * {Array} List of keys used in font styling. │ │ │ │ │ + * APIProperty: profile │ │ │ │ │ + * {String} If provided, use a custom profile. │ │ │ │ │ + * │ │ │ │ │ + * Currently supported profiles: │ │ │ │ │ + * - GeoServer - parses GeoServer vendor specific capabilities for SLD. │ │ │ │ │ */ │ │ │ │ │ - fontStyleKeys: [ │ │ │ │ │ - 'antialiasing', 'blockout', 'font', 'fontcolor', 'fontsize', 'fontstyle', │ │ │ │ │ - 'glowing', 'interval', 'outline', 'printmode', 'shadow', 'transparency' │ │ │ │ │ - ], │ │ │ │ │ + profile: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: request │ │ │ │ │ - * A get_image request destined for an ArcIMS server. │ │ │ │ │ + * APIProperty: defaultVersion │ │ │ │ │ + * {String} Version number to assume if none found. Default is "1.0.0". │ │ │ │ │ */ │ │ │ │ │ - request: null, │ │ │ │ │ + defaultVersion: "1.0.0", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: response │ │ │ │ │ - * A parsed response from an ArcIMS server. │ │ │ │ │ + * APIProperty: stringifyOutput │ │ │ │ │ + * {Boolean} If true, write will return a string otherwise a DOMElement. │ │ │ │ │ + * Default is true. │ │ │ │ │ */ │ │ │ │ │ - response: null, │ │ │ │ │ + stringifyOutput: true, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Format.ArcXML │ │ │ │ │ - * Create a new parser/writer for ArcXML. Create an instance of this class │ │ │ │ │ - * to begin authoring a request to an ArcIMS service. This is used │ │ │ │ │ - * primarily by the ArcIMS layer, but could be used to do other wild │ │ │ │ │ - * stuff, like geocoding. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * options - {Object} An optional object whose properties will be set on │ │ │ │ │ - * this instance. │ │ │ │ │ + * APIProperty: namedLayersAsArray │ │ │ │ │ + * {Boolean} Generate a namedLayers array. If false, the namedLayers │ │ │ │ │ + * property value will be an object keyed by layer name. Default is │ │ │ │ │ + * false. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(options) { │ │ │ │ │ - this.request = new OpenLayers.Format.ArcXML.Request(); │ │ │ │ │ - this.response = new OpenLayers.Format.ArcXML.Response(); │ │ │ │ │ - │ │ │ │ │ - if (options) { │ │ │ │ │ - if (options.requesttype == "feature") { │ │ │ │ │ - this.request.get_image = null; │ │ │ │ │ - │ │ │ │ │ - var qry = this.request.get_feature.query; │ │ │ │ │ - this.addCoordSys(qry.featurecoordsys, options.featureCoordSys); │ │ │ │ │ - this.addCoordSys(qry.filtercoordsys, options.filterCoordSys); │ │ │ │ │ - │ │ │ │ │ - if (options.polygon) { │ │ │ │ │ - qry.isspatial = true; │ │ │ │ │ - qry.spatialfilter.polygon = options.polygon; │ │ │ │ │ - } else if (options.envelope) { │ │ │ │ │ - qry.isspatial = true; │ │ │ │ │ - qry.spatialfilter.envelope = { │ │ │ │ │ - minx: 0, │ │ │ │ │ - miny: 0, │ │ │ │ │ - maxx: 0, │ │ │ │ │ - maxy: 0 │ │ │ │ │ - }; │ │ │ │ │ - this.parseEnvelope(qry.spatialfilter.envelope, options.envelope); │ │ │ │ │ - } │ │ │ │ │ - } else if (options.requesttype == "image") { │ │ │ │ │ - this.request.get_feature = null; │ │ │ │ │ - │ │ │ │ │ - var props = this.request.get_image.properties; │ │ │ │ │ - this.parseEnvelope(props.envelope, options.envelope); │ │ │ │ │ - │ │ │ │ │ - this.addLayers(props.layerlist, options.layers); │ │ │ │ │ - this.addImageSize(props.imagesize, options.tileSize); │ │ │ │ │ - this.addCoordSys(props.featurecoordsys, options.featureCoordSys); │ │ │ │ │ - this.addCoordSys(props.filtercoordsys, options.filterCoordSys); │ │ │ │ │ - } else { │ │ │ │ │ - // if an arcxml object is being created with no request type, it is │ │ │ │ │ - // probably going to consume a response, so do not throw an error if │ │ │ │ │ - // the requesttype is not defined │ │ │ │ │ - this.request = null; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - OpenLayers.Format.XML.prototype.initialize.apply(this, [options]); │ │ │ │ │ - }, │ │ │ │ │ + namedLayersAsArray: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseEnvelope │ │ │ │ │ - * Parse an array of coordinates into an ArcXML envelope structure. │ │ │ │ │ + * APIMethod: write │ │ │ │ │ + * Write a SLD document given a list of styles. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * env - {Object} An envelope object that will contain the parsed coordinates. │ │ │ │ │ - * arr - {Array(double)} An array of coordinates in the order: [ minx, miny, maxx, maxy ] │ │ │ │ │ - */ │ │ │ │ │ - parseEnvelope: function(env, arr) { │ │ │ │ │ - if (arr && arr.length == 4) { │ │ │ │ │ - env.minx = arr[0]; │ │ │ │ │ - env.miny = arr[1]; │ │ │ │ │ - env.maxx = arr[2]; │ │ │ │ │ - env.maxy = arr[3]; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Method: addLayers │ │ │ │ │ - * Add a collection of layers to another collection of layers. Each layer in the list is tuple of │ │ │ │ │ - * { id, visible }. These layer collections represent the │ │ │ │ │ - * /ARCXML/REQUEST/get_image/PROPERTIES/LAYERLIST/LAYERDEF items in ArcXML │ │ │ │ │ - * │ │ │ │ │ - * TODO: Add support for dynamic layer rendering. │ │ │ │ │ + * sld - {Object} An object representing the SLD. │ │ │ │ │ + * options - {Object} Optional configuration object. │ │ │ │ │ * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * ll - {Array({id,visible})} A list of layer definitions. │ │ │ │ │ - * lyrs - {Array({id,visible})} A list of layer definitions. │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} An SLD document string. │ │ │ │ │ */ │ │ │ │ │ - addLayers: function(ll, lyrs) { │ │ │ │ │ - for (var lind = 0, len = lyrs.length; lind < len; lind++) { │ │ │ │ │ - ll.push(lyrs[lind]); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addImageSize │ │ │ │ │ - * Set the size of the requested image. │ │ │ │ │ + * APIMethod: read │ │ │ │ │ + * Read and SLD doc and return an object representing the SLD. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * imsize - {Object} An ArcXML imagesize object. │ │ │ │ │ - * olsize - {} The image size to set. │ │ │ │ │ + * data - {String | DOMElement} Data to read. │ │ │ │ │ + * options - {Object} Options for the reader. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object representing the SLD. │ │ │ │ │ */ │ │ │ │ │ - addImageSize: function(imsize, olsize) { │ │ │ │ │ - if (olsize !== null) { │ │ │ │ │ - imsize.width = olsize.w; │ │ │ │ │ - imsize.height = olsize.h; │ │ │ │ │ - imsize.printwidth = olsize.w; │ │ │ │ │ - imsize.printheight = olsize.h; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.SLD" │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/GML/v2.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format/GML/Base.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.GML.v2 │ │ │ │ │ + * Parses GML version 2. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.GML.v2 = OpenLayers.Class(OpenLayers.Format.GML.Base, { │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: addCoordSys │ │ │ │ │ - * Add the coordinate system information to an object. The object may be │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * featOrFilt - {Object} A featurecoordsys or filtercoordsys ArcXML structure. │ │ │ │ │ - * fsys - {String} or {} or {filtercoordsys} or │ │ │ │ │ - * {featurecoordsys} A projection representation. If it's a {String}, │ │ │ │ │ - * the value is assumed to be the SRID. If it's a {OpenLayers.Projection} │ │ │ │ │ - * AND Proj4js is available, the projection number and name are extracted │ │ │ │ │ - * from there. If it's a filter or feature ArcXML structure, it is copied. │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} Schema location for a particular minor version. │ │ │ │ │ */ │ │ │ │ │ - addCoordSys: function(featOrFilt, fsys) { │ │ │ │ │ - if (typeof fsys == "string") { │ │ │ │ │ - featOrFilt.id = parseInt(fsys); │ │ │ │ │ - featOrFilt.string = fsys; │ │ │ │ │ - } │ │ │ │ │ - // is this a proj4js instance? │ │ │ │ │ - else if (typeof fsys == "object" && fsys.proj !== null) { │ │ │ │ │ - featOrFilt.id = fsys.proj.srsProjNumber; │ │ │ │ │ - featOrFilt.string = fsys.proj.srsCode; │ │ │ │ │ - } else { │ │ │ │ │ - featOrFilt = fsys; │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + schemaLocation: "http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/feature.xsd", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: iserror │ │ │ │ │ - * Check to see if the response from the server was an error. │ │ │ │ │ + * Constructor: OpenLayers.Format.GML.v2 │ │ │ │ │ + * Create a parser for GML v2. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. If nothing is supplied, │ │ │ │ │ - * the current response is examined. │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Boolean} true if the response was an error. │ │ │ │ │ + * Valid options properties: │ │ │ │ │ + * featureType - {String} Local (without prefix) feature typeName (required). │ │ │ │ │ + * featureNS - {String} Feature namespace (required). │ │ │ │ │ + * geometryName - {String} Geometry element name. │ │ │ │ │ */ │ │ │ │ │ - iserror: function(data) { │ │ │ │ │ - var ret = null; │ │ │ │ │ - │ │ │ │ │ - if (!data) { │ │ │ │ │ - ret = (this.response.error !== ''); │ │ │ │ │ - } else { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ - var errorNodes = data.documentElement.getElementsByTagName("ERROR"); │ │ │ │ │ - ret = (errorNodes !== null && errorNodes.length > 0); │ │ │ │ │ - } │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Format.GML.Base.prototype.initialize.apply(this, [options]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - return ret; │ │ │ │ │ + /** │ │ │ │ │ + * 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: { │ │ │ │ │ + "gml": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "outerBoundaryIs": function(node, container) { │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + container.outer = obj.components[0]; │ │ │ │ │ + }, │ │ │ │ │ + "innerBoundaryIs": function(node, container) { │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + container.inner.push(obj.components[0]); │ │ │ │ │ + }, │ │ │ │ │ + "Box": function(node, container) { │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + if (!container.components) { │ │ │ │ │ + container.components = []; │ │ │ │ │ + } │ │ │ │ │ + var min = obj.points[0]; │ │ │ │ │ + var max = obj.points[1]; │ │ │ │ │ + container.components.push( │ │ │ │ │ + new OpenLayers.Bounds(min.x, min.y, max.x, max.y) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.GML.Base.prototype.readers["gml"]), │ │ │ │ │ + "feature": OpenLayers.Format.GML.Base.prototype.readers["feature"], │ │ │ │ │ + "wfs": OpenLayers.Format.GML.Base.prototype.readers["wfs"] │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: read │ │ │ │ │ - * Read data from a string, and return an response. │ │ │ │ │ - * │ │ │ │ │ + * Method: write │ │ │ │ │ + * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} data to read/parse. │ │ │ │ │ + * features - {Array() | OpenLayers.Feature.Vector} │ │ │ │ │ + * An array of features or a single feature. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {} An ArcXML response. Note that this response │ │ │ │ │ - * data may change in the future. │ │ │ │ │ + * {String} Given an array of features, a doc with a gml:featureMembers │ │ │ │ │ + * element will be returned. Given a single feature, a doc with a │ │ │ │ │ + * gml:featureMember element will be returned. │ │ │ │ │ */ │ │ │ │ │ - read: function(data) { │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - data = OpenLayers.Format.XML.prototype.read.apply(this, [data]); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var arcNode = null; │ │ │ │ │ - if (data && data.documentElement) { │ │ │ │ │ - if (data.documentElement.nodeName == "ARCXML") { │ │ │ │ │ - arcNode = data.documentElement; │ │ │ │ │ - } else { │ │ │ │ │ - arcNode = data.documentElement.getElementsByTagName("ARCXML")[0]; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // in Safari, arcNode will be there but will have a child named │ │ │ │ │ - // parsererror │ │ │ │ │ - if (!arcNode || arcNode.firstChild.nodeName === 'parsererror') { │ │ │ │ │ - var error, source; │ │ │ │ │ - try { │ │ │ │ │ - error = data.firstChild.nodeValue; │ │ │ │ │ - source = data.firstChild.childNodes[1].firstChild.nodeValue; │ │ │ │ │ - } catch (err) { │ │ │ │ │ - // pass │ │ │ │ │ - } │ │ │ │ │ - throw { │ │ │ │ │ - message: "Error parsing the ArcXML request", │ │ │ │ │ - error: error, │ │ │ │ │ - source: source │ │ │ │ │ - }; │ │ │ │ │ + write: function(features) { │ │ │ │ │ + var name; │ │ │ │ │ + if (OpenLayers.Util.isArray(features)) { │ │ │ │ │ + // GML2 only has abstract feature collections │ │ │ │ │ + // wfs provides a feature collection from a well-known schema │ │ │ │ │ + name = "wfs:FeatureCollection"; │ │ │ │ │ + } else { │ │ │ │ │ + name = "gml:featureMember"; │ │ │ │ │ } │ │ │ │ │ + var root = this.writeNode(name, features); │ │ │ │ │ + this.setAttributeNS( │ │ │ │ │ + root, this.namespaces["xsi"], │ │ │ │ │ + "xsi:schemaLocation", this.schemaLocation │ │ │ │ │ + ); │ │ │ │ │ │ │ │ │ │ - var response = this.parseResponse(arcNode); │ │ │ │ │ - return response; │ │ │ │ │ + return OpenLayers.Format.XML.prototype.write.apply(this, [root]); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIMethod: write │ │ │ │ │ - * Generate an ArcXml document string for sending to an ArcIMS server. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {String} A string representing the ArcXML document request. │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ */ │ │ │ │ │ - write: function(request) { │ │ │ │ │ - if (!request) { │ │ │ │ │ - request = this.request; │ │ │ │ │ - } │ │ │ │ │ - var root = this.createElementNS("", "ARCXML"); │ │ │ │ │ - root.setAttribute("version", "1.1"); │ │ │ │ │ - │ │ │ │ │ - var reqElem = this.createElementNS("", "REQUEST"); │ │ │ │ │ - │ │ │ │ │ - if (request.get_image != null) { │ │ │ │ │ - var getElem = this.createElementNS("", "GET_IMAGE"); │ │ │ │ │ - reqElem.appendChild(getElem); │ │ │ │ │ - │ │ │ │ │ - var propElem = this.createElementNS("", "PROPERTIES"); │ │ │ │ │ - getElem.appendChild(propElem); │ │ │ │ │ - │ │ │ │ │ - var props = request.get_image.properties; │ │ │ │ │ - if (props.featurecoordsys != null) { │ │ │ │ │ - var feat = this.createElementNS("", "FEATURECOORDSYS"); │ │ │ │ │ - propElem.appendChild(feat); │ │ │ │ │ - │ │ │ │ │ - if (props.featurecoordsys.id === 0) { │ │ │ │ │ - feat.setAttribute("string", props.featurecoordsys['string']); │ │ │ │ │ - } else { │ │ │ │ │ - feat.setAttribute("id", props.featurecoordsys.id); │ │ │ │ │ + writers: { │ │ │ │ │ + "gml": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "Point": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:Point"); │ │ │ │ │ + this.writeNode("coordinates", [geometry], node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "coordinates": function(points) { │ │ │ │ │ + var numPoints = points.length; │ │ │ │ │ + var parts = new Array(numPoints); │ │ │ │ │ + var point; │ │ │ │ │ + for (var i = 0; i < numPoints; ++i) { │ │ │ │ │ + point = points[i]; │ │ │ │ │ + if (this.xy) { │ │ │ │ │ + parts[i] = point.x + "," + point.y; │ │ │ │ │ + } else { │ │ │ │ │ + parts[i] = point.y + "," + point.x; │ │ │ │ │ + } │ │ │ │ │ + if (point.z != undefined) { // allow null or undefined │ │ │ │ │ + parts[i] += "," + point.z; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (props.filtercoordsys != null) { │ │ │ │ │ - var filt = this.createElementNS("", "FILTERCOORDSYS"); │ │ │ │ │ - propElem.appendChild(filt); │ │ │ │ │ - │ │ │ │ │ - if (props.filtercoordsys.id === 0) { │ │ │ │ │ - filt.setAttribute("string", props.filtercoordsys.string); │ │ │ │ │ - } else { │ │ │ │ │ - filt.setAttribute("id", props.filtercoordsys.id); │ │ │ │ │ + return this.createElementNSPlus("gml:coordinates", { │ │ │ │ │ + attributes: { │ │ │ │ │ + decimal: ".", │ │ │ │ │ + cs: ",", │ │ │ │ │ + ts: " " │ │ │ │ │ + }, │ │ │ │ │ + value: (numPoints == 1) ? parts[0] : parts.join(" ") │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "LineString": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:LineString"); │ │ │ │ │ + this.writeNode("coordinates", geometry.components, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Polygon": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:Polygon"); │ │ │ │ │ + this.writeNode("outerBoundaryIs", geometry.components[0], node); │ │ │ │ │ + for (var i = 1; i < geometry.components.length; ++i) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "innerBoundaryIs", geometry.components[i], node │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (props.envelope != null) { │ │ │ │ │ - var env = this.createElementNS("", "ENVELOPE"); │ │ │ │ │ - propElem.appendChild(env); │ │ │ │ │ - │ │ │ │ │ - env.setAttribute("minx", props.envelope.minx); │ │ │ │ │ - env.setAttribute("miny", props.envelope.miny); │ │ │ │ │ - env.setAttribute("maxx", props.envelope.maxx); │ │ │ │ │ - env.setAttribute("maxy", props.envelope.maxy); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var imagesz = this.createElementNS("", "IMAGESIZE"); │ │ │ │ │ - propElem.appendChild(imagesz); │ │ │ │ │ - │ │ │ │ │ - imagesz.setAttribute("height", props.imagesize.height); │ │ │ │ │ - imagesz.setAttribute("width", props.imagesize.width); │ │ │ │ │ - │ │ │ │ │ - if (props.imagesize.height != props.imagesize.printheight || │ │ │ │ │ - props.imagesize.width != props.imagesize.printwidth) { │ │ │ │ │ - imagesz.setAttribute("printheight", props.imagesize.printheight); │ │ │ │ │ - imagesz.setArrtibute("printwidth", props.imagesize.printwidth); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (props.background != null) { │ │ │ │ │ - var backgrnd = this.createElementNS("", "BACKGROUND"); │ │ │ │ │ - propElem.appendChild(backgrnd); │ │ │ │ │ - │ │ │ │ │ - backgrnd.setAttribute("color", │ │ │ │ │ - props.background.color.r + "," + │ │ │ │ │ - props.background.color.g + "," + │ │ │ │ │ - props.background.color.b); │ │ │ │ │ - │ │ │ │ │ - if (props.background.transcolor !== null) { │ │ │ │ │ - backgrnd.setAttribute("transcolor", │ │ │ │ │ - props.background.transcolor.r + "," + │ │ │ │ │ - props.background.transcolor.g + "," + │ │ │ │ │ - props.background.transcolor.b); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "outerBoundaryIs": function(ring) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:outerBoundaryIs"); │ │ │ │ │ + this.writeNode("LinearRing", ring, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "innerBoundaryIs": function(ring) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:innerBoundaryIs"); │ │ │ │ │ + this.writeNode("LinearRing", ring, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "LinearRing": function(ring) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:LinearRing"); │ │ │ │ │ + this.writeNode("coordinates", ring.components, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Box": function(bounds) { │ │ │ │ │ + var node = this.createElementNSPlus("gml:Box"); │ │ │ │ │ + this.writeNode("coordinates", [{ │ │ │ │ │ + x: bounds.left, │ │ │ │ │ + y: bounds.bottom │ │ │ │ │ + }, { │ │ │ │ │ + x: bounds.right, │ │ │ │ │ + y: bounds.top │ │ │ │ │ + }], node); │ │ │ │ │ + // srsName attribute is optional for gml:Box │ │ │ │ │ + if (this.srsName) { │ │ │ │ │ + node.setAttribute("srsName", this.srsName); │ │ │ │ │ } │ │ │ │ │ + return node; │ │ │ │ │ } │ │ │ │ │ + }, OpenLayers.Format.GML.Base.prototype.writers["gml"]), │ │ │ │ │ + "feature": OpenLayers.Format.GML.Base.prototype.writers["feature"], │ │ │ │ │ + "wfs": OpenLayers.Format.GML.Base.prototype.writers["wfs"] │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (props.layerlist != null && props.layerlist.length > 0) { │ │ │ │ │ - var layerlst = this.createElementNS("", "LAYERLIST"); │ │ │ │ │ - propElem.appendChild(layerlst); │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.GML.v2" │ │ │ │ │ │ │ │ │ │ - for (var ld = 0; ld < props.layerlist.length; ld++) { │ │ │ │ │ - var ldef = this.createElementNS("", "LAYERDEF"); │ │ │ │ │ - layerlst.appendChild(ldef); │ │ │ │ │ +}); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/Filter/v1_0_0.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - ldef.setAttribute("id", props.layerlist[ld].id); │ │ │ │ │ - ldef.setAttribute("visible", props.layerlist[ld].visible); │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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 (typeof props.layerlist[ld].query == "object") { │ │ │ │ │ - var query = props.layerlist[ld].query; │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Format/GML/v2.js │ │ │ │ │ + * @requires OpenLayers/Format/Filter/v1.js │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - if (query.where.length < 0) { │ │ │ │ │ - continue; │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.Filter.v1_0_0 │ │ │ │ │ + * Write ogc:Filter version 1.0.0. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.Filter.v1_0_0 = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Format.GML.v2, OpenLayers.Format.Filter.v1, { │ │ │ │ │ │ │ │ │ │ - var queryElem = null; │ │ │ │ │ - if (typeof query.spatialfilter == "boolean" && query.spatialfilter) { │ │ │ │ │ - // handle spatial filter madness │ │ │ │ │ - queryElem = this.createElementNS("", "SPATIALQUERY"); │ │ │ │ │ - } else { │ │ │ │ │ - queryElem = this.createElementNS("", "QUERY"); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Constant: VERSION │ │ │ │ │ + * {String} 1.0.0 │ │ │ │ │ + */ │ │ │ │ │ + VERSION: "1.0.0", │ │ │ │ │ │ │ │ │ │ - queryElem.setAttribute("where", query.where); │ │ │ │ │ + /** │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} http://www.opengis.net/ogc/filter/1.0.0/filter.xsd │ │ │ │ │ + */ │ │ │ │ │ + schemaLocation: "http://www.opengis.net/ogc/filter/1.0.0/filter.xsd", │ │ │ │ │ │ │ │ │ │ - if (typeof query.accuracy == "number" && query.accuracy > 0) { │ │ │ │ │ - queryElem.setAttribute("accuracy", query.accuracy); │ │ │ │ │ - } │ │ │ │ │ - if (typeof query.featurelimit == "number" && query.featurelimit < 2000) { │ │ │ │ │ - queryElem.setAttribute("featurelimit", query.featurelimit); │ │ │ │ │ - } │ │ │ │ │ - if (typeof query.subfields == "string" && query.subfields != "#ALL#") { │ │ │ │ │ - queryElem.setAttribute("subfields", query.subfields); │ │ │ │ │ - } │ │ │ │ │ - if (typeof query.joinexpression == "string" && query.joinexpression.length > 0) { │ │ │ │ │ - queryElem.setAttribute("joinexpression", query.joinexpression); │ │ │ │ │ - } │ │ │ │ │ - if (typeof query.jointables == "string" && query.jointables.length > 0) { │ │ │ │ │ - queryElem.setAttribute("jointables", query.jointables); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.Filter.v1_0_0 │ │ │ │ │ + * Instances of this class are not created directly. Use the │ │ │ │ │ + * constructor instead. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(options) { │ │ │ │ │ + OpenLayers.Format.GML.v2.prototype.initialize.apply( │ │ │ │ │ + this, [options] │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - ldef.appendChild(queryElem); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: readers │ │ │ │ │ + * Contains public functions, grouped by namespace prefix, that will │ │ │ │ │ + * be applied when a namespaced node is found matching the function │ │ │ │ │ + * name. The function will be applied in the scope of this parser │ │ │ │ │ + * with two arguments: the node being read and a context object passed │ │ │ │ │ + * from the parent. │ │ │ │ │ + */ │ │ │ │ │ + readers: { │ │ │ │ │ + "ogc": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "PropertyIsEqualTo": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.EQUAL_TO │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsNotEqualTo": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsLike": function(node, obj) { │ │ │ │ │ + var filter = new OpenLayers.Filter.Comparison({ │ │ │ │ │ + type: OpenLayers.Filter.Comparison.LIKE │ │ │ │ │ + }); │ │ │ │ │ + this.readChildNodes(node, filter); │ │ │ │ │ + var wildCard = node.getAttribute("wildCard"); │ │ │ │ │ + var singleChar = node.getAttribute("singleChar"); │ │ │ │ │ + var esc = node.getAttribute("escape"); │ │ │ │ │ + filter.value2regex(wildCard, singleChar, esc); │ │ │ │ │ + obj.filters.push(filter); │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.Filter.v1.prototype.readers["ogc"]), │ │ │ │ │ + "gml": OpenLayers.Format.GML.v2.prototype.readers["gml"], │ │ │ │ │ + "feature": OpenLayers.Format.GML.v2.prototype.readers["feature"] │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (typeof props.layerlist[ld].renderer == "object") { │ │ │ │ │ - this.addRenderer(ldef, props.layerlist[ld].renderer); │ │ │ │ │ + /** │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ + */ │ │ │ │ │ + writers: { │ │ │ │ │ + "ogc": OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "PropertyIsEqualTo": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsEqualTo"); │ │ │ │ │ + // no ogc:expression handling for PropertyName for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + // handle Literals or Functions for now │ │ │ │ │ + this.writeOgcExpression(filter.value, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsNotEqualTo": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsNotEqualTo"); │ │ │ │ │ + // no ogc:expression handling for PropertyName for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + // handle Literals or Functions for now │ │ │ │ │ + this.writeOgcExpression(filter.value, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PropertyIsLike": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:PropertyIsLike", { │ │ │ │ │ + attributes: { │ │ │ │ │ + wildCard: "*", │ │ │ │ │ + singleChar: ".", │ │ │ │ │ + escape: "!" │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + // no ogc:expression handling for now │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + // convert regex string to ogc string │ │ │ │ │ + this.writeNode("Literal", filter.regex2value(), node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "BBOX": function(filter) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:BBOX"); │ │ │ │ │ + // PropertyName is mandatory in 1.0.0, but e.g. GeoServer also │ │ │ │ │ + // accepts filters without it. When this is used with │ │ │ │ │ + // OpenLayers.Protocol.WFS, OpenLayers.Format.WFST will set a │ │ │ │ │ + // missing filter.property to the geometryName that is │ │ │ │ │ + // configured with the protocol, which defaults to "the_geom". │ │ │ │ │ + // So the only way to omit this mandatory property is to not │ │ │ │ │ + // set the property on the filter and to set the geometryName │ │ │ │ │ + // on the WFS protocol to null. The latter also happens when │ │ │ │ │ + // the protocol is configured without a geometryName and a │ │ │ │ │ + // featureNS. │ │ │ │ │ + filter.property && this.writeNode("PropertyName", filter, node); │ │ │ │ │ + var box = this.writeNode("gml:Box", filter.value, node); │ │ │ │ │ + if (filter.projection) { │ │ │ │ │ + box.setAttribute("srsName", filter.projection); │ │ │ │ │ } │ │ │ │ │ + return node; │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - } else if (request.get_feature != null) { │ │ │ │ │ - var getElem = this.createElementNS("", "GET_FEATURES"); │ │ │ │ │ - getElem.setAttribute("outputmode", "newxml"); │ │ │ │ │ - getElem.setAttribute("checkesc", "true"); │ │ │ │ │ + }, OpenLayers.Format.Filter.v1.prototype.writers["ogc"]), │ │ │ │ │ + "gml": OpenLayers.Format.GML.v2.prototype.writers["gml"], │ │ │ │ │ + "feature": OpenLayers.Format.GML.v2.prototype.writers["feature"] │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (request.get_feature.geometry) { │ │ │ │ │ - getElem.setAttribute("geometry", request.get_feature.geometry); │ │ │ │ │ + /** │ │ │ │ │ + * Method: writeSpatial │ │ │ │ │ + * │ │ │ │ │ + * Read a {} filter and converts it into XML. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * filter - {} The filter. │ │ │ │ │ + * name - {String} Name of the generated XML element. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The created XML element. │ │ │ │ │ + */ │ │ │ │ │ + writeSpatial: function(filter, name) { │ │ │ │ │ + var node = this.createElementNSPlus("ogc:" + name); │ │ │ │ │ + this.writeNode("PropertyName", filter, node); │ │ │ │ │ + if (filter.value instanceof OpenLayers.Filter.Function) { │ │ │ │ │ + this.writeNode("Function", filter.value, node); │ │ │ │ │ } else { │ │ │ │ │ - getElem.setAttribute("geometry", "false"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (request.get_feature.compact) { │ │ │ │ │ - getElem.setAttribute("compact", request.get_feature.compact); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (request.get_feature.featurelimit == "number") { │ │ │ │ │ - getElem.setAttribute("featurelimit", request.get_feature.featurelimit); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - getElem.setAttribute("globalenvelope", "true"); │ │ │ │ │ - reqElem.appendChild(getElem); │ │ │ │ │ - │ │ │ │ │ - if (request.get_feature.layer != null && request.get_feature.layer.length > 0) { │ │ │ │ │ - var lyrElem = this.createElementNS("", "LAYER"); │ │ │ │ │ - lyrElem.setAttribute("id", request.get_feature.layer); │ │ │ │ │ - getElem.appendChild(lyrElem); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var fquery = request.get_feature.query; │ │ │ │ │ - if (fquery != null) { │ │ │ │ │ - var qElem = null; │ │ │ │ │ - if (fquery.isspatial) { │ │ │ │ │ - qElem = this.createElementNS("", "SPATIALQUERY"); │ │ │ │ │ + var child; │ │ │ │ │ + if (filter.value instanceof OpenLayers.Geometry) { │ │ │ │ │ + child = this.writeNode("feature:_geometry", filter.value).firstChild; │ │ │ │ │ } else { │ │ │ │ │ - qElem = this.createElementNS("", "QUERY"); │ │ │ │ │ - } │ │ │ │ │ - getElem.appendChild(qElem); │ │ │ │ │ - │ │ │ │ │ - if (typeof fquery.accuracy == "number") { │ │ │ │ │ - qElem.setAttribute("accuracy", fquery.accuracy); │ │ │ │ │ + child = this.writeNode("gml:Box", filter.value); │ │ │ │ │ } │ │ │ │ │ - //qElem.setAttribute("featurelimit", "5"); │ │ │ │ │ - │ │ │ │ │ - if (fquery.featurecoordsys != null) { │ │ │ │ │ - var fcsElem1 = this.createElementNS("", "FEATURECOORDSYS"); │ │ │ │ │ - │ │ │ │ │ - if (fquery.featurecoordsys.id == 0) { │ │ │ │ │ - fcsElem1.setAttribute("string", fquery.featurecoordsys.string); │ │ │ │ │ - } else { │ │ │ │ │ - fcsElem1.setAttribute("id", fquery.featurecoordsys.id); │ │ │ │ │ - } │ │ │ │ │ - qElem.appendChild(fcsElem1); │ │ │ │ │ + if (filter.projection) { │ │ │ │ │ + child.setAttribute("srsName", filter.projection); │ │ │ │ │ } │ │ │ │ │ + node.appendChild(child); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (fquery.filtercoordsys != null) { │ │ │ │ │ - var fcsElem2 = this.createElementNS("", "FILTERCOORDSYS"); │ │ │ │ │ - │ │ │ │ │ - if (fquery.filtercoordsys.id === 0) { │ │ │ │ │ - fcsElem2.setAttribute("string", fquery.filtercoordsys.string); │ │ │ │ │ - } else { │ │ │ │ │ - fcsElem2.setAttribute("id", fquery.filtercoordsys.id); │ │ │ │ │ - } │ │ │ │ │ - qElem.appendChild(fcsElem2); │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - if (fquery.buffer > 0) { │ │ │ │ │ - var bufElem = this.createElementNS("", "BUFFER"); │ │ │ │ │ - bufElem.setAttribute("distance", fquery.buffer); │ │ │ │ │ - qElem.appendChild(bufElem); │ │ │ │ │ - } │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.Filter.v1_0_0" │ │ │ │ │ │ │ │ │ │ - if (fquery.isspatial) { │ │ │ │ │ - var spfElem = this.createElementNS("", "SPATIALFILTER"); │ │ │ │ │ - spfElem.setAttribute("relation", fquery.spatialfilter.relation); │ │ │ │ │ - qElem.appendChild(spfElem); │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Format/SLD/v1.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ │ │ │ │ │ - if (fquery.spatialfilter.envelope) { │ │ │ │ │ - var envElem = this.createElementNS("", "ENVELOPE"); │ │ │ │ │ - envElem.setAttribute("minx", fquery.spatialfilter.envelope.minx); │ │ │ │ │ - envElem.setAttribute("miny", fquery.spatialfilter.envelope.miny); │ │ │ │ │ - envElem.setAttribute("maxx", fquery.spatialfilter.envelope.maxx); │ │ │ │ │ - envElem.setAttribute("maxy", fquery.spatialfilter.envelope.maxy); │ │ │ │ │ - spfElem.appendChild(envElem); │ │ │ │ │ - } else if (typeof fquery.spatialfilter.polygon == "object") { │ │ │ │ │ - spfElem.appendChild(this.writePolygonGeometry(fquery.spatialfilter.polygon)); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of 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 (fquery.where != null && fquery.where.length > 0) { │ │ │ │ │ - qElem.setAttribute("where", fquery.where); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Rule.js │ │ │ │ │ + * @requires OpenLayers/Format/SLD.js │ │ │ │ │ + * @requires OpenLayers/Format/Filter/v1_0_0.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 │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - root.appendChild(reqElem); │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Format.SLD.v1 │ │ │ │ │ + * Superclass for SLD version 1 parsers. │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, { │ │ │ │ │ │ │ │ │ │ - return OpenLayers.Format.XML.prototype.write.apply(this, [root]); │ │ │ │ │ + /** │ │ │ │ │ + * Property: namespaces │ │ │ │ │ + * {Object} Mapping of namespace aliases to namespace URIs. │ │ │ │ │ + */ │ │ │ │ │ + namespaces: { │ │ │ │ │ + sld: "http://www.opengis.net/sld", │ │ │ │ │ + ogc: "http://www.opengis.net/ogc", │ │ │ │ │ + gml: "http://www.opengis.net/gml", │ │ │ │ │ + xlink: "http://www.w3.org/1999/xlink", │ │ │ │ │ + xsi: "http://www.w3.org/2001/XMLSchema-instance" │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * Property: defaultPrefix │ │ │ │ │ + */ │ │ │ │ │ + defaultPrefix: "sld", │ │ │ │ │ │ │ │ │ │ - addGroupRenderer: function(ldef, toprenderer) { │ │ │ │ │ - var topRelem = this.createElementNS("", "GROUPRENDERER"); │ │ │ │ │ - ldef.appendChild(topRelem); │ │ │ │ │ - │ │ │ │ │ - for (var rind = 0; rind < toprenderer.length; rind++) { │ │ │ │ │ - var renderer = toprenderer[rind]; │ │ │ │ │ - this.addRenderer(topRelem, renderer); │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} Schema location for a particular minor version. │ │ │ │ │ + */ │ │ │ │ │ + schemaLocation: null, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: multipleSymbolizers │ │ │ │ │ + * {Boolean} Support multiple symbolizers per rule. Default is false. if │ │ │ │ │ + * true, an OpenLayers.Style2 instance will be created to represent │ │ │ │ │ + * user styles instead of an OpenLayers.Style instace. The │ │ │ │ │ + * OpenLayers.Style2 class allows collections of rules with multiple │ │ │ │ │ + * symbolizers, but is not currently useful for client side rendering. │ │ │ │ │ + * If multiple symbolizers is true, multiple FeatureTypeStyle elements │ │ │ │ │ + * are preserved in reading/writing by setting symbolizer zIndex values. │ │ │ │ │ + * In addition, the property is ignored if │ │ │ │ │ + * multiple symbolizers are supported (defaults should be applied │ │ │ │ │ + * when rendering). │ │ │ │ │ + */ │ │ │ │ │ + multipleSymbolizers: false, │ │ │ │ │ │ │ │ │ │ - addRenderer: function(topRelem, renderer) { │ │ │ │ │ - if (OpenLayers.Util.isArray(renderer)) { │ │ │ │ │ - this.addGroupRenderer(topRelem, renderer); │ │ │ │ │ - } else { │ │ │ │ │ - var renderElem = this.createElementNS("", renderer.type.toUpperCase() + "RENDERER"); │ │ │ │ │ - topRelem.appendChild(renderElem); │ │ │ │ │ + /** │ │ │ │ │ + * Property: featureTypeCounter │ │ │ │ │ + * {Number} Private counter for multiple feature type styles. │ │ │ │ │ + */ │ │ │ │ │ + featureTypeCounter: null, │ │ │ │ │ │ │ │ │ │ - if (renderElem.tagName == "VALUEMAPRENDERER") { │ │ │ │ │ - this.addValueMapRenderer(renderElem, renderer); │ │ │ │ │ - } else if (renderElem.tagName == "VALUEMAPLABELRENDERER") { │ │ │ │ │ - this.addValueMapLabelRenderer(renderElem, renderer); │ │ │ │ │ - } else if (renderElem.tagName == "SIMPLELABELRENDERER") { │ │ │ │ │ - this.addSimpleLabelRenderer(renderElem, renderer); │ │ │ │ │ - } else if (renderElem.tagName == "SCALEDEPENDENTRENDERER") { │ │ │ │ │ - this.addScaleDependentRenderer(renderElem, renderer); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: defaultSymbolizer. │ │ │ │ │ + * {Object} A symbolizer with the SLD defaults. │ │ │ │ │ + */ │ │ │ │ │ + defaultSymbolizer: { │ │ │ │ │ + fillColor: "#808080", │ │ │ │ │ + fillOpacity: 1, │ │ │ │ │ + strokeColor: "#000000", │ │ │ │ │ + strokeOpacity: 1, │ │ │ │ │ + strokeWidth: 1, │ │ │ │ │ + strokeDashstyle: "solid", │ │ │ │ │ + pointRadius: 3, │ │ │ │ │ + graphicName: "square" │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.SLD.v1 │ │ │ │ │ + * Instances of this class are not created directly. Use the │ │ │ │ │ + * constructor instead. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ + */ │ │ │ │ │ │ │ │ │ │ - addScaleDependentRenderer: function(renderElem, renderer) { │ │ │ │ │ - if (typeof renderer.lower == "string" || typeof renderer.lower == "number") { │ │ │ │ │ - renderElem.setAttribute("lower", renderer.lower); │ │ │ │ │ - } │ │ │ │ │ - if (typeof renderer.upper == "string" || typeof renderer.upper == "number") { │ │ │ │ │ - renderElem.setAttribute("upper", renderer.upper); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - this.addRenderer(renderElem, renderer.renderer); │ │ │ │ │ + /** │ │ │ │ │ + * Method: read │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * data - {DOMElement} An SLD document element. │ │ │ │ │ + * options - {Object} Options for the reader. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * namedLayersAsArray - {Boolean} Generate a namedLayers array. If false, │ │ │ │ │ + * the namedLayers property value will be an object keyed by layer name. │ │ │ │ │ + * Default is false. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {Object} An object representing the SLD. │ │ │ │ │ + */ │ │ │ │ │ + read: function(data, options) { │ │ │ │ │ + options = OpenLayers.Util.applyDefaults(options, this.options); │ │ │ │ │ + var sld = { │ │ │ │ │ + namedLayers: options.namedLayersAsArray === true ? [] : {} │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(data, sld); │ │ │ │ │ + return sld; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ - addValueMapLabelRenderer: function(renderElem, renderer) { │ │ │ │ │ - renderElem.setAttribute("lookupfield", renderer.lookupfield); │ │ │ │ │ - renderElem.setAttribute("labelfield", renderer.labelfield); │ │ │ │ │ - │ │ │ │ │ - if (typeof renderer.exacts == "object") { │ │ │ │ │ - for (var ext = 0, extlen = renderer.exacts.length; ext < extlen; ext++) { │ │ │ │ │ - var exact = renderer.exacts[ext]; │ │ │ │ │ - │ │ │ │ │ - var eelem = this.createElementNS("", "EXACT"); │ │ │ │ │ - │ │ │ │ │ - if (typeof exact.value == "string") { │ │ │ │ │ - eelem.setAttribute("value", exact.value); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.label == "string") { │ │ │ │ │ - eelem.setAttribute("label", exact.label); │ │ │ │ │ + /** │ │ │ │ │ + * 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: OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "sld": { │ │ │ │ │ + "StyledLayerDescriptor": function(node, sld) { │ │ │ │ │ + sld.version = node.getAttribute("version"); │ │ │ │ │ + this.readChildNodes(node, sld); │ │ │ │ │ + }, │ │ │ │ │ + "Name": function(node, obj) { │ │ │ │ │ + obj.name = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Title": function(node, obj) { │ │ │ │ │ + obj.title = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Abstract": function(node, obj) { │ │ │ │ │ + obj.description = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "NamedLayer": function(node, sld) { │ │ │ │ │ + var layer = { │ │ │ │ │ + userStyles: [], │ │ │ │ │ + namedStyles: [] │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, layer); │ │ │ │ │ + // give each of the user styles this layer name │ │ │ │ │ + for (var i = 0, len = layer.userStyles.length; i < len; ++i) { │ │ │ │ │ + layer.userStyles[i].layerName = layer.name; │ │ │ │ │ } │ │ │ │ │ - if (typeof exact.method == "string") { │ │ │ │ │ - eelem.setAttribute("method", exact.method); │ │ │ │ │ + if (OpenLayers.Util.isArray(sld.namedLayers)) { │ │ │ │ │ + sld.namedLayers.push(layer); │ │ │ │ │ + } else { │ │ │ │ │ + sld.namedLayers[layer.name] = layer; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - renderElem.appendChild(eelem); │ │ │ │ │ - │ │ │ │ │ - if (typeof exact.symbol == "object") { │ │ │ │ │ - var selem = null; │ │ │ │ │ - │ │ │ │ │ - if (exact.symbol.type == "text") { │ │ │ │ │ - selem = this.createElementNS("", "TEXTSYMBOL"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (selem != null) { │ │ │ │ │ - var keys = this.fontStyleKeys; │ │ │ │ │ - for (var i = 0, len = keys.length; i < len; i++) { │ │ │ │ │ - var key = keys[i]; │ │ │ │ │ - if (exact.symbol[key]) { │ │ │ │ │ - selem.setAttribute(key, exact.symbol[key]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - eelem.appendChild(selem); │ │ │ │ │ + }, │ │ │ │ │ + "NamedStyle": function(node, layer) { │ │ │ │ │ + layer.namedStyles.push( │ │ │ │ │ + this.getChildName(node.firstChild) │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "UserStyle": function(node, layer) { │ │ │ │ │ + var obj = { │ │ │ │ │ + defaultsPerSymbolizer: true, │ │ │ │ │ + rules: [] │ │ │ │ │ + }; │ │ │ │ │ + this.featureTypeCounter = -1; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + var style; │ │ │ │ │ + if (this.multipleSymbolizers) { │ │ │ │ │ + delete obj.defaultsPerSymbolizer; │ │ │ │ │ + style = new OpenLayers.Style2(obj); │ │ │ │ │ + } else { │ │ │ │ │ + style = new OpenLayers.Style(this.defaultSymbolizer, obj); │ │ │ │ │ + } │ │ │ │ │ + layer.userStyles.push(style); │ │ │ │ │ + }, │ │ │ │ │ + "IsDefault": function(node, style) { │ │ │ │ │ + if (this.getChildValue(node) == "1") { │ │ │ │ │ + style.isDefault = true; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "FeatureTypeStyle": function(node, style) { │ │ │ │ │ + ++this.featureTypeCounter; │ │ │ │ │ + var obj = { │ │ │ │ │ + rules: this.multipleSymbolizers ? style.rules : [] │ │ │ │ │ + }; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + if (!this.multipleSymbolizers) { │ │ │ │ │ + style.rules = obj.rules; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "Rule": function(node, obj) { │ │ │ │ │ + var config; │ │ │ │ │ + if (this.multipleSymbolizers) { │ │ │ │ │ + config = { │ │ │ │ │ + symbolizers: [] │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + var rule = new OpenLayers.Rule(config); │ │ │ │ │ + this.readChildNodes(node, rule); │ │ │ │ │ + obj.rules.push(rule); │ │ │ │ │ + }, │ │ │ │ │ + "ElseFilter": function(node, rule) { │ │ │ │ │ + rule.elseFilter = true; │ │ │ │ │ + }, │ │ │ │ │ + "MinScaleDenominator": function(node, rule) { │ │ │ │ │ + rule.minScaleDenominator = parseFloat(this.getChildValue(node)); │ │ │ │ │ + }, │ │ │ │ │ + "MaxScaleDenominator": function(node, rule) { │ │ │ │ │ + rule.maxScaleDenominator = parseFloat(this.getChildValue(node)); │ │ │ │ │ + }, │ │ │ │ │ + "TextSymbolizer": function(node, rule) { │ │ │ │ │ + var config = {}; │ │ │ │ │ + this.readChildNodes(node, config); │ │ │ │ │ + if (this.multipleSymbolizers) { │ │ │ │ │ + config.zIndex = this.featureTypeCounter; │ │ │ │ │ + rule.symbolizers.push( │ │ │ │ │ + new OpenLayers.Symbolizer.Text(config) │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + rule.symbolizer["Text"] = OpenLayers.Util.applyDefaults( │ │ │ │ │ + config, rule.symbolizer["Text"] │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "LabelPlacement": function(node, symbolizer) { │ │ │ │ │ + this.readChildNodes(node, symbolizer); │ │ │ │ │ + }, │ │ │ │ │ + "PointPlacement": function(node, symbolizer) { │ │ │ │ │ + var config = {}; │ │ │ │ │ + this.readChildNodes(node, config); │ │ │ │ │ + config.labelRotation = config.rotation; │ │ │ │ │ + delete config.rotation; │ │ │ │ │ + var labelAlign, │ │ │ │ │ + x = symbolizer.labelAnchorPointX, │ │ │ │ │ + y = symbolizer.labelAnchorPointY; │ │ │ │ │ + if (x <= 1 / 3) { │ │ │ │ │ + labelAlign = 'l'; │ │ │ │ │ + } else if (x > 1 / 3 && x < 2 / 3) { │ │ │ │ │ + labelAlign = 'c'; │ │ │ │ │ + } else if (x >= 2 / 3) { │ │ │ │ │ + labelAlign = 'r'; │ │ │ │ │ + } │ │ │ │ │ + if (y <= 1 / 3) { │ │ │ │ │ + labelAlign += 'b'; │ │ │ │ │ + } else if (y > 1 / 3 && y < 2 / 3) { │ │ │ │ │ + labelAlign += 'm'; │ │ │ │ │ + } else if (y >= 2 / 3) { │ │ │ │ │ + labelAlign += 't'; │ │ │ │ │ + } │ │ │ │ │ + config.labelAlign = labelAlign; │ │ │ │ │ + OpenLayers.Util.applyDefaults(symbolizer, config); │ │ │ │ │ + }, │ │ │ │ │ + "AnchorPoint": function(node, symbolizer) { │ │ │ │ │ + this.readChildNodes(node, symbolizer); │ │ │ │ │ + }, │ │ │ │ │ + "AnchorPointX": function(node, symbolizer) { │ │ │ │ │ + var labelAnchorPointX = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + // always string, could be empty string │ │ │ │ │ + if (labelAnchorPointX) { │ │ │ │ │ + symbolizer.labelAnchorPointX = labelAnchorPointX; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "AnchorPointY": function(node, symbolizer) { │ │ │ │ │ + var labelAnchorPointY = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + // always string, could be empty string │ │ │ │ │ + if (labelAnchorPointY) { │ │ │ │ │ + symbolizer.labelAnchorPointY = labelAnchorPointY; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "Displacement": function(node, symbolizer) { │ │ │ │ │ + this.readChildNodes(node, symbolizer); │ │ │ │ │ + }, │ │ │ │ │ + "DisplacementX": function(node, symbolizer) { │ │ │ │ │ + var labelXOffset = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + // always string, could be empty string │ │ │ │ │ + if (labelXOffset) { │ │ │ │ │ + symbolizer.labelXOffset = labelXOffset; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "DisplacementY": function(node, symbolizer) { │ │ │ │ │ + var labelYOffset = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + // always string, could be empty string │ │ │ │ │ + if (labelYOffset) { │ │ │ │ │ + symbolizer.labelYOffset = labelYOffset; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "LinePlacement": function(node, symbolizer) { │ │ │ │ │ + this.readChildNodes(node, symbolizer); │ │ │ │ │ + }, │ │ │ │ │ + "PerpendicularOffset": function(node, symbolizer) { │ │ │ │ │ + var labelPerpendicularOffset = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + // always string, could be empty string │ │ │ │ │ + if (labelPerpendicularOffset) { │ │ │ │ │ + symbolizer.labelPerpendicularOffset = labelPerpendicularOffset; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "Label": function(node, symbolizer) { │ │ │ │ │ + var value = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + if (value) { │ │ │ │ │ + symbolizer.label = value; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "Font": function(node, symbolizer) { │ │ │ │ │ + this.readChildNodes(node, symbolizer); │ │ │ │ │ + }, │ │ │ │ │ + "Halo": function(node, symbolizer) { │ │ │ │ │ + // halo has a fill, so send fresh object │ │ │ │ │ + var obj = {}; │ │ │ │ │ + this.readChildNodes(node, obj); │ │ │ │ │ + symbolizer.haloRadius = obj.haloRadius; │ │ │ │ │ + symbolizer.haloColor = obj.fillColor; │ │ │ │ │ + symbolizer.haloOpacity = obj.fillOpacity; │ │ │ │ │ + }, │ │ │ │ │ + "Radius": function(node, symbolizer) { │ │ │ │ │ + var radius = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + if (radius != null) { │ │ │ │ │ + // radius is only used for halo │ │ │ │ │ + symbolizer.haloRadius = radius; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "RasterSymbolizer": function(node, rule) { │ │ │ │ │ + var config = {}; │ │ │ │ │ + this.readChildNodes(node, config); │ │ │ │ │ + if (this.multipleSymbolizers) { │ │ │ │ │ + config.zIndex = this.featureTypeCounter; │ │ │ │ │ + rule.symbolizers.push( │ │ │ │ │ + new OpenLayers.Symbolizer.Raster(config) │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + rule.symbolizer["Raster"] = OpenLayers.Util.applyDefaults( │ │ │ │ │ + config, rule.symbolizer["Raster"] │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "Geometry": function(node, obj) { │ │ │ │ │ + obj.geometry = {}; │ │ │ │ │ + this.readChildNodes(node, obj.geometry); │ │ │ │ │ + }, │ │ │ │ │ + "ColorMap": function(node, symbolizer) { │ │ │ │ │ + symbolizer.colorMap = []; │ │ │ │ │ + this.readChildNodes(node, symbolizer.colorMap); │ │ │ │ │ + }, │ │ │ │ │ + "ColorMapEntry": function(node, colorMap) { │ │ │ │ │ + var q = node.getAttribute("quantity"); │ │ │ │ │ + var o = node.getAttribute("opacity"); │ │ │ │ │ + colorMap.push({ │ │ │ │ │ + color: node.getAttribute("color"), │ │ │ │ │ + quantity: q !== null ? parseFloat(q) : undefined, │ │ │ │ │ + label: node.getAttribute("label") || undefined, │ │ │ │ │ + opacity: o !== null ? parseFloat(o) : undefined │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "LineSymbolizer": function(node, rule) { │ │ │ │ │ + var config = {}; │ │ │ │ │ + this.readChildNodes(node, config); │ │ │ │ │ + if (this.multipleSymbolizers) { │ │ │ │ │ + config.zIndex = this.featureTypeCounter; │ │ │ │ │ + rule.symbolizers.push( │ │ │ │ │ + new OpenLayers.Symbolizer.Line(config) │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + rule.symbolizer["Line"] = OpenLayers.Util.applyDefaults( │ │ │ │ │ + config, rule.symbolizer["Line"] │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "PolygonSymbolizer": function(node, rule) { │ │ │ │ │ + var config = { │ │ │ │ │ + fill: false, │ │ │ │ │ + stroke: false │ │ │ │ │ + }; │ │ │ │ │ + if (!this.multipleSymbolizers) { │ │ │ │ │ + config = rule.symbolizer["Polygon"] || config; │ │ │ │ │ + } │ │ │ │ │ + this.readChildNodes(node, config); │ │ │ │ │ + if (this.multipleSymbolizers) { │ │ │ │ │ + config.zIndex = this.featureTypeCounter; │ │ │ │ │ + rule.symbolizers.push( │ │ │ │ │ + new OpenLayers.Symbolizer.Polygon(config) │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + rule.symbolizer["Polygon"] = config; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "PointSymbolizer": function(node, rule) { │ │ │ │ │ + var config = { │ │ │ │ │ + fill: false, │ │ │ │ │ + stroke: false, │ │ │ │ │ + graphic: false │ │ │ │ │ + }; │ │ │ │ │ + if (!this.multipleSymbolizers) { │ │ │ │ │ + config = rule.symbolizer["Point"] || config; │ │ │ │ │ + } │ │ │ │ │ + this.readChildNodes(node, config); │ │ │ │ │ + if (this.multipleSymbolizers) { │ │ │ │ │ + config.zIndex = this.featureTypeCounter; │ │ │ │ │ + rule.symbolizers.push( │ │ │ │ │ + new OpenLayers.Symbolizer.Point(config) │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + rule.symbolizer["Point"] = config; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "Stroke": function(node, symbolizer) { │ │ │ │ │ + symbolizer.stroke = true; │ │ │ │ │ + this.readChildNodes(node, symbolizer); │ │ │ │ │ + }, │ │ │ │ │ + "Fill": function(node, symbolizer) { │ │ │ │ │ + symbolizer.fill = true; │ │ │ │ │ + this.readChildNodes(node, symbolizer); │ │ │ │ │ + }, │ │ │ │ │ + "CssParameter": function(node, symbolizer) { │ │ │ │ │ + var cssProperty = node.getAttribute("name"); │ │ │ │ │ + var symProperty = this.cssMap[cssProperty]; │ │ │ │ │ + // for labels, fill should map to fontColor and fill-opacity │ │ │ │ │ + // to fontOpacity │ │ │ │ │ + if (symbolizer.label) { │ │ │ │ │ + if (cssProperty === 'fill') { │ │ │ │ │ + symProperty = "fontColor"; │ │ │ │ │ + } else if (cssProperty === 'fill-opacity') { │ │ │ │ │ + symProperty = "fontOpacity"; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - } // for each exact │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - addValueMapRenderer: function(renderElem, renderer) { │ │ │ │ │ - renderElem.setAttribute("lookupfield", renderer.lookupfield); │ │ │ │ │ - │ │ │ │ │ - if (typeof renderer.ranges == "object") { │ │ │ │ │ - for (var rng = 0, rnglen = renderer.ranges.length; rng < rnglen; rng++) { │ │ │ │ │ - var range = renderer.ranges[rng]; │ │ │ │ │ - │ │ │ │ │ - var relem = this.createElementNS("", "RANGE"); │ │ │ │ │ - relem.setAttribute("lower", range.lower); │ │ │ │ │ - relem.setAttribute("upper", range.upper); │ │ │ │ │ - │ │ │ │ │ - renderElem.appendChild(relem); │ │ │ │ │ - │ │ │ │ │ - if (typeof range.symbol == "object") { │ │ │ │ │ - var selem = null; │ │ │ │ │ - │ │ │ │ │ - if (range.symbol.type == "simplepolygon") { │ │ │ │ │ - selem = this.createElementNS("", "SIMPLEPOLYGONSYMBOL"); │ │ │ │ │ + if (symProperty) { │ │ │ │ │ + // Limited support for parsing of OGC expressions │ │ │ │ │ + var value = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + // always string, could be an empty string │ │ │ │ │ + if (value) { │ │ │ │ │ + symbolizer[symProperty] = value; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - if (selem != null) { │ │ │ │ │ - if (typeof range.symbol.boundarycolor == "string") { │ │ │ │ │ - selem.setAttribute("boundarycolor", range.symbol.boundarycolor); │ │ │ │ │ - } │ │ │ │ │ - if (typeof range.symbol.fillcolor == "string") { │ │ │ │ │ - selem.setAttribute("fillcolor", range.symbol.fillcolor); │ │ │ │ │ - } │ │ │ │ │ - if (typeof range.symbol.filltransparency == "number") { │ │ │ │ │ - selem.setAttribute("filltransparency", range.symbol.filltransparency); │ │ │ │ │ - } │ │ │ │ │ - relem.appendChild(selem); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "Graphic": function(node, symbolizer) { │ │ │ │ │ + symbolizer.graphic = true; │ │ │ │ │ + var graphic = {}; │ │ │ │ │ + // painter's order not respected here, clobber previous with next │ │ │ │ │ + this.readChildNodes(node, graphic); │ │ │ │ │ + // directly properties with names that match symbolizer properties │ │ │ │ │ + var properties = [ │ │ │ │ │ + "stroke", "strokeColor", "strokeWidth", "strokeOpacity", │ │ │ │ │ + "strokeLinecap", "fill", "fillColor", "fillOpacity", │ │ │ │ │ + "graphicName", "rotation", "graphicFormat" │ │ │ │ │ + ]; │ │ │ │ │ + var prop, value; │ │ │ │ │ + for (var i = 0, len = properties.length; i < len; ++i) { │ │ │ │ │ + prop = properties[i]; │ │ │ │ │ + value = graphic[prop]; │ │ │ │ │ + if (value != undefined) { │ │ │ │ │ + symbolizer[prop] = value; │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - } // for each range │ │ │ │ │ - } else if (typeof renderer.exacts == "object") { │ │ │ │ │ - for (var ext = 0, extlen = renderer.exacts.length; ext < extlen; ext++) { │ │ │ │ │ - var exact = renderer.exacts[ext]; │ │ │ │ │ - │ │ │ │ │ - var eelem = this.createElementNS("", "EXACT"); │ │ │ │ │ - if (typeof exact.value == "string") { │ │ │ │ │ - eelem.setAttribute("value", exact.value); │ │ │ │ │ + // set other generic properties with specific graphic property names │ │ │ │ │ + if (graphic.opacity != undefined) { │ │ │ │ │ + symbolizer.graphicOpacity = graphic.opacity; │ │ │ │ │ } │ │ │ │ │ - if (typeof exact.label == "string") { │ │ │ │ │ - eelem.setAttribute("label", exact.label); │ │ │ │ │ + if (graphic.size != undefined) { │ │ │ │ │ + var pointRadius = graphic.size / 2; │ │ │ │ │ + if (isNaN(pointRadius)) { │ │ │ │ │ + // likely a property name │ │ │ │ │ + symbolizer.graphicWidth = graphic.size; │ │ │ │ │ + } else { │ │ │ │ │ + symbolizer.pointRadius = graphic.size / 2; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - if (typeof exact.method == "string") { │ │ │ │ │ - eelem.setAttribute("method", exact.method); │ │ │ │ │ + if (graphic.href != undefined) { │ │ │ │ │ + symbolizer.externalGraphic = graphic.href; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - renderElem.appendChild(eelem); │ │ │ │ │ - │ │ │ │ │ - if (typeof exact.symbol == "object") { │ │ │ │ │ - var selem = null; │ │ │ │ │ - │ │ │ │ │ - if (exact.symbol.type == "simplemarker") { │ │ │ │ │ - selem = this.createElementNS("", "SIMPLEMARKERSYMBOL"); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (selem != null) { │ │ │ │ │ - if (typeof exact.symbol.antialiasing == "string") { │ │ │ │ │ - selem.setAttribute("antialiasing", exact.symbol.antialiasing); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.color == "string") { │ │ │ │ │ - selem.setAttribute("color", exact.symbol.color); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.outline == "string") { │ │ │ │ │ - selem.setAttribute("outline", exact.symbol.outline); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.overlap == "string") { │ │ │ │ │ - selem.setAttribute("overlap", exact.symbol.overlap); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.shadow == "string") { │ │ │ │ │ - selem.setAttribute("shadow", exact.symbol.shadow); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.transparency == "number") { │ │ │ │ │ - selem.setAttribute("transparency", exact.symbol.transparency); │ │ │ │ │ - } │ │ │ │ │ - //if (typeof exact.symbol.type == "string") │ │ │ │ │ - // selem.setAttribute("type", exact.symbol.type); │ │ │ │ │ - if (typeof exact.symbol.usecentroid == "string") { │ │ │ │ │ - selem.setAttribute("usecentroid", exact.symbol.usecentroid); │ │ │ │ │ - } │ │ │ │ │ - if (typeof exact.symbol.width == "number") { │ │ │ │ │ - selem.setAttribute("width", exact.symbol.width); │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - eelem.appendChild(selem); │ │ │ │ │ - } │ │ │ │ │ + if (graphic.rotation != undefined) { │ │ │ │ │ + symbolizer.rotation = graphic.rotation; │ │ │ │ │ } │ │ │ │ │ - } // for each exact │ │ │ │ │ - } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - │ │ │ │ │ - addSimpleLabelRenderer: function(renderElem, renderer) { │ │ │ │ │ - renderElem.setAttribute("field", renderer.field); │ │ │ │ │ - var keys = ['featureweight', 'howmanylabels', 'labelbufferratio', │ │ │ │ │ - 'labelpriorities', 'labelweight', 'linelabelposition', │ │ │ │ │ - 'rotationalangles' │ │ │ │ │ - ]; │ │ │ │ │ - for (var i = 0, len = keys.length; i < len; i++) { │ │ │ │ │ - var key = keys[i]; │ │ │ │ │ - if (renderer[key]) { │ │ │ │ │ - renderElem.setAttribute(key, renderer[key]); │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - if (renderer.symbol.type == "text") { │ │ │ │ │ - var symbol = renderer.symbol; │ │ │ │ │ - var selem = this.createElementNS("", "TEXTSYMBOL"); │ │ │ │ │ - renderElem.appendChild(selem); │ │ │ │ │ - │ │ │ │ │ - var keys = this.fontStyleKeys; │ │ │ │ │ - for (var i = 0, len = keys.length; i < len; i++) { │ │ │ │ │ - var key = keys[i]; │ │ │ │ │ - if (symbol[key]) { │ │ │ │ │ - selem.setAttribute(key, renderer[key]); │ │ │ │ │ + }, │ │ │ │ │ + "ExternalGraphic": function(node, graphic) { │ │ │ │ │ + this.readChildNodes(node, graphic); │ │ │ │ │ + }, │ │ │ │ │ + "Mark": function(node, graphic) { │ │ │ │ │ + this.readChildNodes(node, graphic); │ │ │ │ │ + }, │ │ │ │ │ + "WellKnownName": function(node, graphic) { │ │ │ │ │ + graphic.graphicName = this.getChildValue(node); │ │ │ │ │ + }, │ │ │ │ │ + "Opacity": function(node, obj) { │ │ │ │ │ + var opacity = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + // always string, could be empty string │ │ │ │ │ + if (opacity) { │ │ │ │ │ + obj.opacity = opacity; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "Size": function(node, obj) { │ │ │ │ │ + var size = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + // always string, could be empty string │ │ │ │ │ + if (size) { │ │ │ │ │ + obj.size = size; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ + "Rotation": function(node, obj) { │ │ │ │ │ + var rotation = this.readers.ogc._expression.call(this, node); │ │ │ │ │ + // always string, could be empty string │ │ │ │ │ + if (rotation) { │ │ │ │ │ + obj.rotation = rotation; │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ + "OnlineResource": function(node, obj) { │ │ │ │ │ + obj.href = this.getAttributeNS( │ │ │ │ │ + node, this.namespaces.xlink, "href" │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "Format": function(node, graphic) { │ │ │ │ │ + graphic.graphicFormat = this.getChildValue(node); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - writePolygonGeometry: function(polygon) { │ │ │ │ │ - if (!(polygon instanceof OpenLayers.Geometry.Polygon)) { │ │ │ │ │ - throw { │ │ │ │ │ - message: 'Cannot write polygon geometry to ArcXML with an ' + │ │ │ │ │ - polygon.CLASS_NAME + ' object.', │ │ │ │ │ - geometry: polygon │ │ │ │ │ - }; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - var polyElem = this.createElementNS("", "POLYGON"); │ │ │ │ │ - │ │ │ │ │ - for (var ln = 0, lnlen = polygon.components.length; ln < lnlen; ln++) { │ │ │ │ │ - var ring = polygon.components[ln]; │ │ │ │ │ - var ringElem = this.createElementNS("", "RING"); │ │ │ │ │ - │ │ │ │ │ - for (var rn = 0, rnlen = ring.components.length; rn < rnlen; rn++) { │ │ │ │ │ - var point = ring.components[rn]; │ │ │ │ │ - var pointElem = this.createElementNS("", "POINT"); │ │ │ │ │ + }, OpenLayers.Format.Filter.v1_0_0.prototype.readers), │ │ │ │ │ │ │ │ │ │ - pointElem.setAttribute("x", point.x); │ │ │ │ │ - pointElem.setAttribute("y", point.y); │ │ │ │ │ + /** │ │ │ │ │ + * Property: cssMap │ │ │ │ │ + * {Object} Object mapping supported css property names to OpenLayers │ │ │ │ │ + * symbolizer property names. │ │ │ │ │ + */ │ │ │ │ │ + cssMap: { │ │ │ │ │ + "stroke": "strokeColor", │ │ │ │ │ + "stroke-opacity": "strokeOpacity", │ │ │ │ │ + "stroke-width": "strokeWidth", │ │ │ │ │ + "stroke-linecap": "strokeLinecap", │ │ │ │ │ + "stroke-dasharray": "strokeDashstyle", │ │ │ │ │ + "fill": "fillColor", │ │ │ │ │ + "fill-opacity": "fillOpacity", │ │ │ │ │ + "font-family": "fontFamily", │ │ │ │ │ + "font-size": "fontSize", │ │ │ │ │ + "font-weight": "fontWeight", │ │ │ │ │ + "font-style": "fontStyle" │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - ringElem.appendChild(pointElem); │ │ │ │ │ + /** │ │ │ │ │ + * Method: getCssProperty │ │ │ │ │ + * Given a symbolizer property, get the corresponding CSS property │ │ │ │ │ + * from the . │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * sym - {String} A symbolizer property name. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} A CSS property name or null if none found. │ │ │ │ │ + */ │ │ │ │ │ + getCssProperty: function(sym) { │ │ │ │ │ + var css = null; │ │ │ │ │ + for (var prop in this.cssMap) { │ │ │ │ │ + if (this.cssMap[prop] == sym) { │ │ │ │ │ + css = prop; │ │ │ │ │ + break; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - polyElem.appendChild(ringElem); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return polyElem; │ │ │ │ │ + return css; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: parseResponse │ │ │ │ │ - * Take an ArcXML response, and parse in into this object's internal properties. │ │ │ │ │ + * Method: getGraphicFormat │ │ │ │ │ + * Given a href for an external graphic, try to determine the mime-type. │ │ │ │ │ + * This method doesn't try too hard, and will fall back to │ │ │ │ │ + * if one of the known is not │ │ │ │ │ + * the file extension of the provided href. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * data - {String} or {DOMElement} The ArcXML response, as either a string or the │ │ │ │ │ - * top level DOMElement of the response. │ │ │ │ │ + * href - {String} │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The graphic format. │ │ │ │ │ */ │ │ │ │ │ - parseResponse: function(data) { │ │ │ │ │ - if (typeof data == "string") { │ │ │ │ │ - var newData = new OpenLayers.Format.XML(); │ │ │ │ │ - data = newData.read(data); │ │ │ │ │ + getGraphicFormat: function(href) { │ │ │ │ │ + var format, regex; │ │ │ │ │ + for (var key in this.graphicFormats) { │ │ │ │ │ + if (this.graphicFormats[key].test(href)) { │ │ │ │ │ + format = key; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - var response = new OpenLayers.Format.ArcXML.Response(); │ │ │ │ │ + return format || this.defaultGraphicFormat; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var errorNode = data.getElementsByTagName("ERROR"); │ │ │ │ │ + /** │ │ │ │ │ + * Property: defaultGraphicFormat │ │ │ │ │ + * {String} If none other can be determined from , this │ │ │ │ │ + * default will be returned. │ │ │ │ │ + */ │ │ │ │ │ + defaultGraphicFormat: "image/png", │ │ │ │ │ │ │ │ │ │ - if (errorNode != null && errorNode.length > 0) { │ │ │ │ │ - response.error = this.getChildValue(errorNode, "Unknown error."); │ │ │ │ │ - } else { │ │ │ │ │ - var responseNode = data.getElementsByTagName("RESPONSE"); │ │ │ │ │ + /** │ │ │ │ │ + * Property: graphicFormats │ │ │ │ │ + * {Object} Mapping of image mime-types to regular extensions matching │ │ │ │ │ + * well-known file extensions. │ │ │ │ │ + */ │ │ │ │ │ + graphicFormats: { │ │ │ │ │ + "image/jpeg": /\.jpe?g$/i, │ │ │ │ │ + "image/gif": /\.gif$/i, │ │ │ │ │ + "image/png": /\.png$/i │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - if (responseNode == null || responseNode.length == 0) { │ │ │ │ │ - response.error = "No RESPONSE tag found in ArcXML response."; │ │ │ │ │ - return response; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Method: write │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * sld - {Object} An object representing the SLD. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {DOMElement} The root of an SLD document. │ │ │ │ │ + */ │ │ │ │ │ + write: function(sld) { │ │ │ │ │ + return this.writers.sld.StyledLayerDescriptor.apply(this, [sld]); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - var rtype = responseNode[0].firstChild.nodeName; │ │ │ │ │ - if (rtype == "#text") { │ │ │ │ │ - rtype = responseNode[0].firstChild.nextSibling.nodeName; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Property: writers │ │ │ │ │ + * As a compliment to the readers property, this structure contains public │ │ │ │ │ + * writing functions grouped by namespace alias and named like the │ │ │ │ │ + * node names they produce. │ │ │ │ │ + */ │ │ │ │ │ + writers: OpenLayers.Util.applyDefaults({ │ │ │ │ │ + "sld": { │ │ │ │ │ + "_OGCExpression": function(nodeName, value) { │ │ │ │ │ + // only the simplest of ogc:expression handled │ │ │ │ │ + // {label: "some text and a ${propertyName}"} │ │ │ │ │ + var node = this.createElementNSPlus(nodeName); │ │ │ │ │ + var tokens = typeof value == "string" ? │ │ │ │ │ + value.split("${") : [value]; │ │ │ │ │ + node.appendChild(this.createTextNode(tokens[0])); │ │ │ │ │ + var item, last; │ │ │ │ │ + for (var i = 1, len = tokens.length; i < len; i++) { │ │ │ │ │ + item = tokens[i]; │ │ │ │ │ + last = item.indexOf("}"); │ │ │ │ │ + if (last > 0) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "ogc:PropertyName", { │ │ │ │ │ + property: item.substring(0, last) │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + node.appendChild( │ │ │ │ │ + this.createTextNode(item.substring(++last)) │ │ │ │ │ + ); │ │ │ │ │ + } else { │ │ │ │ │ + // no ending }, so this is a literal ${ │ │ │ │ │ + node.appendChild( │ │ │ │ │ + this.createTextNode("${" + item) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "StyledLayerDescriptor": function(sld) { │ │ │ │ │ + var root = this.createElementNSPlus( │ │ │ │ │ + "sld:StyledLayerDescriptor", { │ │ │ │ │ + attributes: { │ │ │ │ │ + "version": this.VERSION, │ │ │ │ │ + "xsi:schemaLocation": this.schemaLocation │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ │ │ │ │ │ - if (rtype == "IMAGE") { │ │ │ │ │ - var envelopeNode = data.getElementsByTagName("ENVELOPE"); │ │ │ │ │ - var outputNode = data.getElementsByTagName("OUTPUT"); │ │ │ │ │ + // For ArcGIS Server it is necessary to define this │ │ │ │ │ + // at the root level (see ticket:2166). │ │ │ │ │ + root.setAttribute("xmlns:ogc", this.namespaces.ogc); │ │ │ │ │ + root.setAttribute("xmlns:gml", this.namespaces.gml); │ │ │ │ │ │ │ │ │ │ - if (envelopeNode == null || envelopeNode.length == 0) { │ │ │ │ │ - response.error = "No ENVELOPE tag found in ArcXML response."; │ │ │ │ │ - } else if (outputNode == null || outputNode.length == 0) { │ │ │ │ │ - response.error = "No OUTPUT tag found in ArcXML response."; │ │ │ │ │ + // add in optional name │ │ │ │ │ + if (sld.name) { │ │ │ │ │ + this.writeNode("Name", sld.name, root); │ │ │ │ │ + } │ │ │ │ │ + // add in optional title │ │ │ │ │ + if (sld.title) { │ │ │ │ │ + this.writeNode("Title", sld.title, root); │ │ │ │ │ + } │ │ │ │ │ + // add in optional description │ │ │ │ │ + if (sld.description) { │ │ │ │ │ + this.writeNode("Abstract", sld.description, root); │ │ │ │ │ + } │ │ │ │ │ + // add in named layers │ │ │ │ │ + // allow namedLayers to be an array │ │ │ │ │ + if (OpenLayers.Util.isArray(sld.namedLayers)) { │ │ │ │ │ + for (var i = 0, len = sld.namedLayers.length; i < len; ++i) { │ │ │ │ │ + this.writeNode("NamedLayer", sld.namedLayers[i], root); │ │ │ │ │ + } │ │ │ │ │ } else { │ │ │ │ │ - var envAttr = this.parseAttributes(envelopeNode[0]); │ │ │ │ │ - var outputAttr = this.parseAttributes(outputNode[0]); │ │ │ │ │ - │ │ │ │ │ - if (typeof outputAttr.type == "string") { │ │ │ │ │ - response.image = { │ │ │ │ │ - envelope: envAttr, │ │ │ │ │ - output: { │ │ │ │ │ - type: outputAttr.type, │ │ │ │ │ - data: this.getChildValue(outputNode[0]) │ │ │ │ │ - } │ │ │ │ │ - }; │ │ │ │ │ - } else { │ │ │ │ │ - response.image = { │ │ │ │ │ - envelope: envAttr, │ │ │ │ │ - output: outputAttr │ │ │ │ │ - }; │ │ │ │ │ + for (var name in sld.namedLayers) { │ │ │ │ │ + this.writeNode("NamedLayer", sld.namedLayers[name], root); │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ - } else if (rtype == "FEATURES") { │ │ │ │ │ - var features = responseNode[0].getElementsByTagName("FEATURES"); │ │ │ │ │ + return root; │ │ │ │ │ + }, │ │ │ │ │ + "Name": function(name) { │ │ │ │ │ + return this.createElementNSPlus("sld:Name", { │ │ │ │ │ + value: name │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Title": function(title) { │ │ │ │ │ + return this.createElementNSPlus("sld:Title", { │ │ │ │ │ + value: title │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Abstract": function(description) { │ │ │ │ │ + return this.createElementNSPlus( │ │ │ │ │ + "sld:Abstract", { │ │ │ │ │ + value: description │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "NamedLayer": function(layer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:NamedLayer"); │ │ │ │ │ │ │ │ │ │ - // get the feature count │ │ │ │ │ - var featureCount = features[0].getElementsByTagName("FEATURECOUNT"); │ │ │ │ │ - response.features.featurecount = featureCount[0].getAttribute("count"); │ │ │ │ │ + // add in required name │ │ │ │ │ + this.writeNode("Name", layer.name, node); │ │ │ │ │ │ │ │ │ │ - if (response.features.featurecount > 0) { │ │ │ │ │ - // get the feature envelope │ │ │ │ │ - var envelope = features[0].getElementsByTagName("ENVELOPE"); │ │ │ │ │ - response.features.envelope = this.parseAttributes(envelope[0], typeof(0)); │ │ │ │ │ + // optional sld:LayerFeatureConstraints here │ │ │ │ │ │ │ │ │ │ - // get the field values per feature │ │ │ │ │ - var featureList = features[0].getElementsByTagName("FEATURE"); │ │ │ │ │ - for (var fn = 0; fn < featureList.length; fn++) { │ │ │ │ │ - var feature = new OpenLayers.Feature.Vector(); │ │ │ │ │ - var fields = featureList[fn].getElementsByTagName("FIELD"); │ │ │ │ │ + // add in named styles │ │ │ │ │ + if (layer.namedStyles) { │ │ │ │ │ + for (var i = 0, len = layer.namedStyles.length; i < len; ++i) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "NamedStyle", layer.namedStyles[i], node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - for (var fdn = 0; fdn < fields.length; fdn++) { │ │ │ │ │ - var fieldName = fields[fdn].getAttribute("name"); │ │ │ │ │ - var fieldValue = fields[fdn].getAttribute("value"); │ │ │ │ │ - feature.attributes[fieldName] = fieldValue; │ │ │ │ │ - } │ │ │ │ │ + // add in user styles │ │ │ │ │ + if (layer.userStyles) { │ │ │ │ │ + for (var i = 0, len = layer.userStyles.length; i < len; ++i) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "UserStyle", layer.userStyles[i], node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var geom = featureList[fn].getElementsByTagName("POLYGON"); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "NamedStyle": function(name) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:NamedStyle"); │ │ │ │ │ + this.writeNode("Name", name, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "UserStyle": function(style) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:UserStyle"); │ │ │ │ │ │ │ │ │ │ - if (geom.length > 0) { │ │ │ │ │ - // if there is a polygon, create an openlayers polygon, and assign │ │ │ │ │ - // it to the .geometry property of the feature │ │ │ │ │ - var ring = geom[0].getElementsByTagName("RING"); │ │ │ │ │ + // add in optional name │ │ │ │ │ + if (style.name) { │ │ │ │ │ + this.writeNode("Name", style.name, node); │ │ │ │ │ + } │ │ │ │ │ + // add in optional title │ │ │ │ │ + if (style.title) { │ │ │ │ │ + this.writeNode("Title", style.title, node); │ │ │ │ │ + } │ │ │ │ │ + // add in optional description │ │ │ │ │ + if (style.description) { │ │ │ │ │ + this.writeNode("Abstract", style.description, node); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var polys = []; │ │ │ │ │ - for (var rn = 0; rn < ring.length; rn++) { │ │ │ │ │ - var linearRings = []; │ │ │ │ │ - linearRings.push(this.parsePointGeometry(ring[rn])); │ │ │ │ │ + // add isdefault │ │ │ │ │ + if (style.isDefault) { │ │ │ │ │ + this.writeNode("IsDefault", style.isDefault, node); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - var holes = ring[rn].getElementsByTagName("HOLE"); │ │ │ │ │ - for (var hn = 0; hn < holes.length; hn++) { │ │ │ │ │ - linearRings.push(this.parsePointGeometry(holes[hn])); │ │ │ │ │ + // add FeatureTypeStyles │ │ │ │ │ + if (this.multipleSymbolizers && style.rules) { │ │ │ │ │ + // group style objects by symbolizer zIndex │ │ │ │ │ + var rulesByZ = { │ │ │ │ │ + 0: [] │ │ │ │ │ + }; │ │ │ │ │ + var zValues = [0]; │ │ │ │ │ + var rule, ruleMap, symbolizer, zIndex, clone; │ │ │ │ │ + for (var i = 0, ii = style.rules.length; i < ii; ++i) { │ │ │ │ │ + rule = style.rules[i]; │ │ │ │ │ + if (rule.symbolizers) { │ │ │ │ │ + ruleMap = {}; │ │ │ │ │ + for (var j = 0, jj = rule.symbolizers.length; j < jj; ++j) { │ │ │ │ │ + symbolizer = rule.symbolizers[j]; │ │ │ │ │ + zIndex = symbolizer.zIndex; │ │ │ │ │ + if (!(zIndex in ruleMap)) { │ │ │ │ │ + clone = rule.clone(); │ │ │ │ │ + clone.symbolizers = []; │ │ │ │ │ + ruleMap[zIndex] = clone; │ │ │ │ │ } │ │ │ │ │ - holes = null; │ │ │ │ │ - polys.push(new OpenLayers.Geometry.Polygon(linearRings)); │ │ │ │ │ - linearRings = null; │ │ │ │ │ + ruleMap[zIndex].symbolizers.push(symbolizer.clone()); │ │ │ │ │ } │ │ │ │ │ - ring = null; │ │ │ │ │ - │ │ │ │ │ - if (polys.length == 1) { │ │ │ │ │ - feature.geometry = polys[0]; │ │ │ │ │ - } else { │ │ │ │ │ - feature.geometry = new OpenLayers.Geometry.MultiPolygon(polys); │ │ │ │ │ + for (zIndex in ruleMap) { │ │ │ │ │ + if (!(zIndex in rulesByZ)) { │ │ │ │ │ + zValues.push(zIndex); │ │ │ │ │ + rulesByZ[zIndex] = []; │ │ │ │ │ + } │ │ │ │ │ + rulesByZ[zIndex].push(ruleMap[zIndex]); │ │ │ │ │ } │ │ │ │ │ + } else { │ │ │ │ │ + // no symbolizers in rule │ │ │ │ │ + rulesByZ[0].push(rule.clone()); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + // write one FeatureTypeStyle per zIndex │ │ │ │ │ + zValues.sort(); │ │ │ │ │ + var rules; │ │ │ │ │ + for (var i = 0, ii = zValues.length; i < ii; ++i) { │ │ │ │ │ + rules = rulesByZ[zValues[i]]; │ │ │ │ │ + if (rules.length > 0) { │ │ │ │ │ + clone = style.clone(); │ │ │ │ │ + clone.rules = rulesByZ[zValues[i]]; │ │ │ │ │ + this.writeNode("FeatureTypeStyle", clone, node); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - response.features.feature.push(feature); │ │ │ │ │ } │ │ │ │ │ + } else { │ │ │ │ │ + this.writeNode("FeatureTypeStyle", style, node); │ │ │ │ │ } │ │ │ │ │ - } else { │ │ │ │ │ - response.error = "Unidentified response type."; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return response; │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "IsDefault": function(bool) { │ │ │ │ │ + return this.createElementNSPlus( │ │ │ │ │ + "sld:IsDefault", { │ │ │ │ │ + value: (bool) ? "1" : "0" │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "FeatureTypeStyle": function(style) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:FeatureTypeStyle"); │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: parseAttributes │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {} An element to parse attributes from. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {Object} An attributes object, with properties set to attribute values. │ │ │ │ │ - */ │ │ │ │ │ - parseAttributes: function(node, type) { │ │ │ │ │ - var attributes = {}; │ │ │ │ │ - for (var attr = 0; attr < node.attributes.length; attr++) { │ │ │ │ │ - if (type == "number") { │ │ │ │ │ - attributes[node.attributes[attr].nodeName] = parseFloat(node.attributes[attr].nodeValue); │ │ │ │ │ - } else { │ │ │ │ │ - attributes[node.attributes[attr].nodeName] = node.attributes[attr].nodeValue; │ │ │ │ │ - } │ │ │ │ │ - } │ │ │ │ │ - return attributes; │ │ │ │ │ - }, │ │ │ │ │ + // OpenLayers currently stores no Name, Title, Abstract, │ │ │ │ │ + // FeatureTypeName, or SemanticTypeIdentifier information │ │ │ │ │ + // related to FeatureTypeStyle │ │ │ │ │ │ │ │ │ │ + // add in rules │ │ │ │ │ + for (var i = 0, len = style.rules.length; i < len; ++i) { │ │ │ │ │ + this.writeNode("Rule", style.rules[i], node); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Method: parsePointGeometry │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * node - {} An element to parse or arcxml data from. │ │ │ │ │ - * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} A linear ring represented by the node's points. │ │ │ │ │ - */ │ │ │ │ │ - parsePointGeometry: function(node) { │ │ │ │ │ - var ringPoints = []; │ │ │ │ │ - var coords = node.getElementsByTagName("COORDS"); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Rule": function(rule) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:Rule"); │ │ │ │ │ │ │ │ │ │ - if (coords.length > 0) { │ │ │ │ │ - // if coords is present, it's the only coords item │ │ │ │ │ - var coordArr = this.getChildValue(coords[0]); │ │ │ │ │ - coordArr = coordArr.split(/;/); │ │ │ │ │ - for (var cn = 0; cn < coordArr.length; cn++) { │ │ │ │ │ - var coordItems = coordArr[cn].split(/ /); │ │ │ │ │ - ringPoints.push(new OpenLayers.Geometry.Point(coordItems[0], coordItems[1])); │ │ │ │ │ - } │ │ │ │ │ - coords = null; │ │ │ │ │ - } else { │ │ │ │ │ - var point = node.getElementsByTagName("POINT"); │ │ │ │ │ - if (point.length > 0) { │ │ │ │ │ - for (var pn = 0; pn < point.length; pn++) { │ │ │ │ │ - ringPoints.push( │ │ │ │ │ - new OpenLayers.Geometry.Point( │ │ │ │ │ - parseFloat(point[pn].getAttribute("x")), │ │ │ │ │ - parseFloat(point[pn].getAttribute("y")) │ │ │ │ │ - ) │ │ │ │ │ - ); │ │ │ │ │ + // add in optional name │ │ │ │ │ + if (rule.name) { │ │ │ │ │ + this.writeNode("Name", rule.name, node); │ │ │ │ │ + } │ │ │ │ │ + // add in optional title │ │ │ │ │ + if (rule.title) { │ │ │ │ │ + this.writeNode("Title", rule.title, node); │ │ │ │ │ + } │ │ │ │ │ + // add in optional description │ │ │ │ │ + if (rule.description) { │ │ │ │ │ + this.writeNode("Abstract", rule.description, node); │ │ │ │ │ } │ │ │ │ │ - } │ │ │ │ │ - point = null; │ │ │ │ │ - } │ │ │ │ │ │ │ │ │ │ - return new OpenLayers.Geometry.LinearRing(ringPoints); │ │ │ │ │ - }, │ │ │ │ │ + // add in LegendGraphic here │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.ArcXML" │ │ │ │ │ -}); │ │ │ │ │ + // add in optional filters │ │ │ │ │ + if (rule.elseFilter) { │ │ │ │ │ + this.writeNode("ElseFilter", null, node); │ │ │ │ │ + } else if (rule.filter) { │ │ │ │ │ + this.writeNode("ogc:Filter", rule.filter, node); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ -OpenLayers.Format.ArcXML.Request = OpenLayers.Class({ │ │ │ │ │ - initialize: function(params) { │ │ │ │ │ - var defaults = { │ │ │ │ │ - get_image: { │ │ │ │ │ - properties: { │ │ │ │ │ - background: null, │ │ │ │ │ - /*{ │ │ │ │ │ - color: { r:255, g:255, b:255 }, │ │ │ │ │ - transcolor: null │ │ │ │ │ - },*/ │ │ │ │ │ - draw: true, │ │ │ │ │ - envelope: { │ │ │ │ │ - minx: 0, │ │ │ │ │ - miny: 0, │ │ │ │ │ - maxx: 0, │ │ │ │ │ - maxy: 0 │ │ │ │ │ - }, │ │ │ │ │ - featurecoordsys: { │ │ │ │ │ - id: 0, │ │ │ │ │ - string: "", │ │ │ │ │ - datumtransformid: 0, │ │ │ │ │ - datumtransformstring: "" │ │ │ │ │ - }, │ │ │ │ │ - filtercoordsys: { │ │ │ │ │ - id: 0, │ │ │ │ │ - string: "", │ │ │ │ │ - datumtransformid: 0, │ │ │ │ │ - datumtransformstring: "" │ │ │ │ │ - }, │ │ │ │ │ - imagesize: { │ │ │ │ │ - height: 0, │ │ │ │ │ - width: 0, │ │ │ │ │ - dpi: 96, │ │ │ │ │ - printheight: 0, │ │ │ │ │ - printwidth: 0, │ │ │ │ │ - scalesymbols: false │ │ │ │ │ - }, │ │ │ │ │ - layerlist: [], │ │ │ │ │ - /* no support for legends */ │ │ │ │ │ - output: { │ │ │ │ │ - baseurl: "", │ │ │ │ │ - legendbaseurl: "", │ │ │ │ │ - legendname: "", │ │ │ │ │ - legendpath: "", │ │ │ │ │ - legendurl: "", │ │ │ │ │ - name: "", │ │ │ │ │ - path: "", │ │ │ │ │ - type: "jpg", │ │ │ │ │ - url: "" │ │ │ │ │ + // add in scale limits │ │ │ │ │ + if (rule.minScaleDenominator != undefined) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "MinScaleDenominator", rule.minScaleDenominator, node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (rule.maxScaleDenominator != undefined) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "MaxScaleDenominator", rule.maxScaleDenominator, node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + │ │ │ │ │ + var type, symbolizer; │ │ │ │ │ + if (this.multipleSymbolizers && rule.symbolizers) { │ │ │ │ │ + var symbolizer; │ │ │ │ │ + for (var i = 0, ii = rule.symbolizers.length; i < ii; ++i) { │ │ │ │ │ + symbolizer = rule.symbolizers[i]; │ │ │ │ │ + type = symbolizer.CLASS_NAME.split(".").pop(); │ │ │ │ │ + this.writeNode( │ │ │ │ │ + type + "Symbolizer", symbolizer, node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } else { │ │ │ │ │ + // add in symbolizers (relies on geometry type keys) │ │ │ │ │ + var types = OpenLayers.Style.SYMBOLIZER_PREFIXES; │ │ │ │ │ + for (var i = 0, len = types.length; i < len; ++i) { │ │ │ │ │ + type = types[i]; │ │ │ │ │ + symbolizer = rule.symbolizer[type]; │ │ │ │ │ + if (symbolizer) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + type + "Symbolizer", symbolizer, node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + return node; │ │ │ │ │ + │ │ │ │ │ }, │ │ │ │ │ + "ElseFilter": function() { │ │ │ │ │ + return this.createElementNSPlus("sld:ElseFilter"); │ │ │ │ │ + }, │ │ │ │ │ + "MinScaleDenominator": function(scale) { │ │ │ │ │ + return this.createElementNSPlus( │ │ │ │ │ + "sld:MinScaleDenominator", { │ │ │ │ │ + value: scale │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "MaxScaleDenominator": function(scale) { │ │ │ │ │ + return this.createElementNSPlus( │ │ │ │ │ + "sld:MaxScaleDenominator", { │ │ │ │ │ + value: scale │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "LineSymbolizer": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:LineSymbolizer"); │ │ │ │ │ + this.writeNode("Stroke", symbolizer, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Stroke": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:Stroke"); │ │ │ │ │ │ │ │ │ │ - get_feature: { │ │ │ │ │ - layer: "", │ │ │ │ │ - query: { │ │ │ │ │ - isspatial: false, │ │ │ │ │ - featurecoordsys: { │ │ │ │ │ - id: 0, │ │ │ │ │ - string: "", │ │ │ │ │ - datumtransformid: 0, │ │ │ │ │ - datumtransformstring: "" │ │ │ │ │ - }, │ │ │ │ │ - filtercoordsys: { │ │ │ │ │ - id: 0, │ │ │ │ │ - string: "", │ │ │ │ │ - datumtransformid: 0, │ │ │ │ │ - datumtransformstring: "" │ │ │ │ │ + // GraphicFill here │ │ │ │ │ + // GraphicStroke here │ │ │ │ │ + │ │ │ │ │ + // add in CssParameters │ │ │ │ │ + if (symbolizer.strokeColor != undefined) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "strokeColor" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.strokeOpacity != undefined) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "strokeOpacity" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.strokeWidth != undefined) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "strokeWidth" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.strokeDashstyle != undefined && symbolizer.strokeDashstyle !== "solid") { │ │ │ │ │ + // assumes valid stroke-dasharray value │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "strokeDashstyle" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.strokeLinecap != undefined) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "strokeLinecap" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "CssParameter": function(obj) { │ │ │ │ │ + // not handling ogc:expressions for now │ │ │ │ │ + return this.createElementNSPlus("sld:CssParameter", { │ │ │ │ │ + attributes: { │ │ │ │ │ + name: this.getCssProperty(obj.key) │ │ │ │ │ }, │ │ │ │ │ - buffer: 0, │ │ │ │ │ - where: "", │ │ │ │ │ - spatialfilter: { │ │ │ │ │ - relation: "envelope_intersection", │ │ │ │ │ - envelope: null │ │ │ │ │ + value: obj.symbolizer[obj.key] │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "TextSymbolizer": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:TextSymbolizer"); │ │ │ │ │ + // add in optional Label │ │ │ │ │ + if (symbolizer.label != null) { │ │ │ │ │ + this.writeNode("Label", symbolizer.label, node); │ │ │ │ │ + } │ │ │ │ │ + // add in optional Font │ │ │ │ │ + if (symbolizer.fontFamily != null || │ │ │ │ │ + symbolizer.fontSize != null || │ │ │ │ │ + symbolizer.fontWeight != null || │ │ │ │ │ + symbolizer.fontStyle != null) { │ │ │ │ │ + this.writeNode("Font", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + // add in optional LabelPlacement │ │ │ │ │ + if (symbolizer.labelAnchorPointX != null || │ │ │ │ │ + symbolizer.labelAnchorPointY != null || │ │ │ │ │ + symbolizer.labelAlign != null || │ │ │ │ │ + symbolizer.labelXOffset != null || │ │ │ │ │ + symbolizer.labelYOffset != null || │ │ │ │ │ + symbolizer.labelRotation != null || │ │ │ │ │ + symbolizer.labelPerpendicularOffset != null) { │ │ │ │ │ + this.writeNode("LabelPlacement", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + // add in optional Halo │ │ │ │ │ + if (symbolizer.haloRadius != null || │ │ │ │ │ + symbolizer.haloColor != null || │ │ │ │ │ + symbolizer.haloOpacity != null) { │ │ │ │ │ + this.writeNode("Halo", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + // add in optional Fill │ │ │ │ │ + if (symbolizer.fontColor != null || │ │ │ │ │ + symbolizer.fontOpacity != null) { │ │ │ │ │ + this.writeNode("Fill", { │ │ │ │ │ + fillColor: symbolizer.fontColor, │ │ │ │ │ + fillOpacity: symbolizer.fontOpacity │ │ │ │ │ + }, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "LabelPlacement": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:LabelPlacement"); │ │ │ │ │ + // PointPlacement and LinePlacement are choices, so don't output both │ │ │ │ │ + if ((symbolizer.labelAnchorPointX != null || │ │ │ │ │ + symbolizer.labelAnchorPointY != null || │ │ │ │ │ + symbolizer.labelAlign != null || │ │ │ │ │ + symbolizer.labelXOffset != null || │ │ │ │ │ + symbolizer.labelYOffset != null || │ │ │ │ │ + symbolizer.labelRotation != null) && │ │ │ │ │ + symbolizer.labelPerpendicularOffset == null) { │ │ │ │ │ + this.writeNode("PointPlacement", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.labelPerpendicularOffset != null) { │ │ │ │ │ + this.writeNode("LinePlacement", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "LinePlacement": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:LinePlacement"); │ │ │ │ │ + this.writeNode("PerpendicularOffset", symbolizer.labelPerpendicularOffset, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PerpendicularOffset": function(value) { │ │ │ │ │ + return this.createElementNSPlus("sld:PerpendicularOffset", { │ │ │ │ │ + value: value │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "PointPlacement": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:PointPlacement"); │ │ │ │ │ + if (symbolizer.labelAnchorPointX != null || │ │ │ │ │ + symbolizer.labelAnchorPointY != null || │ │ │ │ │ + symbolizer.labelAlign != null) { │ │ │ │ │ + this.writeNode("AnchorPoint", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.labelXOffset != null || │ │ │ │ │ + symbolizer.labelYOffset != null) { │ │ │ │ │ + this.writeNode("Displacement", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.labelRotation != null) { │ │ │ │ │ + this.writeNode("Rotation", symbolizer.labelRotation, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "AnchorPoint": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:AnchorPoint"); │ │ │ │ │ + var x = symbolizer.labelAnchorPointX, │ │ │ │ │ + y = symbolizer.labelAnchorPointY; │ │ │ │ │ + if (x != null) { │ │ │ │ │ + this.writeNode("AnchorPointX", x, node); │ │ │ │ │ + } │ │ │ │ │ + if (y != null) { │ │ │ │ │ + this.writeNode("AnchorPointY", y, node); │ │ │ │ │ + } │ │ │ │ │ + if (x == null && y == null) { │ │ │ │ │ + var xAlign = symbolizer.labelAlign.substr(0, 1), │ │ │ │ │ + yAlign = symbolizer.labelAlign.substr(1, 1); │ │ │ │ │ + if (xAlign === "l") { │ │ │ │ │ + x = 0; │ │ │ │ │ + } else if (xAlign === "c") { │ │ │ │ │ + x = 0.5; │ │ │ │ │ + } else if (xAlign === "r") { │ │ │ │ │ + x = 1; │ │ │ │ │ + } │ │ │ │ │ + if (yAlign === "b") { │ │ │ │ │ + y = 0; │ │ │ │ │ + } else if (yAlign === "m") { │ │ │ │ │ + y = 0.5; │ │ │ │ │ + } else if (yAlign === "t") { │ │ │ │ │ + y = 1; │ │ │ │ │ } │ │ │ │ │ + this.writeNode("AnchorPointX", x, node); │ │ │ │ │ + this.writeNode("AnchorPointY", y, node); │ │ │ │ │ } │ │ │ │ │ + return node; │ │ │ │ │ }, │ │ │ │ │ - │ │ │ │ │ - environment: { │ │ │ │ │ - separators: { │ │ │ │ │ - cs: " ", │ │ │ │ │ - ts: ";" │ │ │ │ │ + "AnchorPointX": function(value) { │ │ │ │ │ + return this.createElementNSPlus("sld:AnchorPointX", { │ │ │ │ │ + value: value │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "AnchorPointY": function(value) { │ │ │ │ │ + return this.createElementNSPlus("sld:AnchorPointY", { │ │ │ │ │ + value: value │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Displacement": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:Displacement"); │ │ │ │ │ + if (symbolizer.labelXOffset != null) { │ │ │ │ │ + this.writeNode("DisplacementX", symbolizer.labelXOffset, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.labelYOffset != null) { │ │ │ │ │ + this.writeNode("DisplacementY", symbolizer.labelYOffset, node); │ │ │ │ │ } │ │ │ │ │ + return node; │ │ │ │ │ }, │ │ │ │ │ + "DisplacementX": function(value) { │ │ │ │ │ + return this.createElementNSPlus("sld:DisplacementX", { │ │ │ │ │ + value: value │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "DisplacementY": function(value) { │ │ │ │ │ + return this.createElementNSPlus("sld:DisplacementY", { │ │ │ │ │ + value: value │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Font": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:Font"); │ │ │ │ │ + // add in CssParameters │ │ │ │ │ + if (symbolizer.fontFamily) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "fontFamily" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.fontSize) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "fontSize" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.fontWeight) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "fontWeight" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.fontStyle) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "fontStyle" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Label": function(label) { │ │ │ │ │ + return this.writers.sld._OGCExpression.call( │ │ │ │ │ + this, "sld:Label", label │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "Halo": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:Halo"); │ │ │ │ │ + if (symbolizer.haloRadius) { │ │ │ │ │ + this.writeNode("Radius", symbolizer.haloRadius, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.haloColor || symbolizer.haloOpacity) { │ │ │ │ │ + this.writeNode("Fill", { │ │ │ │ │ + fillColor: symbolizer.haloColor, │ │ │ │ │ + fillOpacity: symbolizer.haloOpacity │ │ │ │ │ + }, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Radius": function(value) { │ │ │ │ │ + return this.createElementNSPlus("sld:Radius", { │ │ │ │ │ + value: value │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "RasterSymbolizer": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:RasterSymbolizer"); │ │ │ │ │ + if (symbolizer.geometry) { │ │ │ │ │ + this.writeNode("Geometry", symbolizer.geometry, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.opacity) { │ │ │ │ │ + this.writeNode("Opacity", symbolizer.opacity, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.colorMap) { │ │ │ │ │ + this.writeNode("ColorMap", symbolizer.colorMap, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Geometry": function(geometry) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:Geometry"); │ │ │ │ │ + if (geometry.property) { │ │ │ │ │ + this.writeNode("ogc:PropertyName", geometry, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "ColorMap": function(colorMap) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:ColorMap"); │ │ │ │ │ + for (var i = 0, len = colorMap.length; i < len; ++i) { │ │ │ │ │ + this.writeNode("ColorMapEntry", colorMap[i], node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "ColorMapEntry": function(colorMapEntry) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:ColorMapEntry"); │ │ │ │ │ + var a = colorMapEntry; │ │ │ │ │ + node.setAttribute("color", a.color); │ │ │ │ │ + a.opacity !== undefined && node.setAttribute("opacity", │ │ │ │ │ + parseFloat(a.opacity)); │ │ │ │ │ + a.quantity !== undefined && node.setAttribute("quantity", │ │ │ │ │ + parseFloat(a.quantity)); │ │ │ │ │ + a.label !== undefined && node.setAttribute("label", a.label); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "PolygonSymbolizer": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:PolygonSymbolizer"); │ │ │ │ │ + if (symbolizer.fill !== false) { │ │ │ │ │ + this.writeNode("Fill", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.stroke !== false) { │ │ │ │ │ + this.writeNode("Stroke", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Fill": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:Fill"); │ │ │ │ │ │ │ │ │ │ - layer: [], │ │ │ │ │ - workspaces: [] │ │ │ │ │ - }; │ │ │ │ │ - │ │ │ │ │ - return OpenLayers.Util.extend(this, defaults); │ │ │ │ │ - }, │ │ │ │ │ - │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.ArcXML.Request" │ │ │ │ │ -}); │ │ │ │ │ + // GraphicFill here │ │ │ │ │ │ │ │ │ │ -OpenLayers.Format.ArcXML.Response = OpenLayers.Class({ │ │ │ │ │ - initialize: function(params) { │ │ │ │ │ - var defaults = { │ │ │ │ │ - image: { │ │ │ │ │ - envelope: null, │ │ │ │ │ - output: '' │ │ │ │ │ + // add in CssParameters │ │ │ │ │ + if (symbolizer.fillColor) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "fillColor" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.fillOpacity != null) { │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "CssParameter", { │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + key: "fillOpacity" │ │ │ │ │ + }, │ │ │ │ │ + node │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ }, │ │ │ │ │ - │ │ │ │ │ - features: { │ │ │ │ │ - featurecount: 0, │ │ │ │ │ - envelope: null, │ │ │ │ │ - feature: [] │ │ │ │ │ + "PointSymbolizer": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:PointSymbolizer"); │ │ │ │ │ + this.writeNode("Graphic", symbolizer, node); │ │ │ │ │ + return node; │ │ │ │ │ }, │ │ │ │ │ + "Graphic": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:Graphic"); │ │ │ │ │ + if (symbolizer.externalGraphic != undefined) { │ │ │ │ │ + this.writeNode("ExternalGraphic", symbolizer, node); │ │ │ │ │ + } else { │ │ │ │ │ + this.writeNode("Mark", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - error: '' │ │ │ │ │ - }; │ │ │ │ │ + if (symbolizer.graphicOpacity != undefined) { │ │ │ │ │ + this.writeNode("Opacity", symbolizer.graphicOpacity, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.pointRadius != undefined) { │ │ │ │ │ + this.writeNode("Size", symbolizer.pointRadius * 2, node); │ │ │ │ │ + } else if (symbolizer.graphicWidth != undefined) { │ │ │ │ │ + this.writeNode("Size", symbolizer.graphicWidth, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.rotation != undefined) { │ │ │ │ │ + this.writeNode("Rotation", symbolizer.rotation, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "ExternalGraphic": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:ExternalGraphic"); │ │ │ │ │ + this.writeNode( │ │ │ │ │ + "OnlineResource", symbolizer.externalGraphic, node │ │ │ │ │ + ); │ │ │ │ │ + var format = symbolizer.graphicFormat || │ │ │ │ │ + this.getGraphicFormat(symbolizer.externalGraphic); │ │ │ │ │ + this.writeNode("Format", format, node); │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "Mark": function(symbolizer) { │ │ │ │ │ + var node = this.createElementNSPlus("sld:Mark"); │ │ │ │ │ + if (symbolizer.graphicName) { │ │ │ │ │ + this.writeNode("WellKnownName", symbolizer.graphicName, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.fill !== false) { │ │ │ │ │ + this.writeNode("Fill", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + if (symbolizer.stroke !== false) { │ │ │ │ │ + this.writeNode("Stroke", symbolizer, node); │ │ │ │ │ + } │ │ │ │ │ + return node; │ │ │ │ │ + }, │ │ │ │ │ + "WellKnownName": function(name) { │ │ │ │ │ + return this.createElementNSPlus("sld:WellKnownName", { │ │ │ │ │ + value: name │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Opacity": function(value) { │ │ │ │ │ + return this.createElementNSPlus("sld:Opacity", { │ │ │ │ │ + value: value │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Size": function(value) { │ │ │ │ │ + return this.writers.sld._OGCExpression.call( │ │ │ │ │ + this, "sld:Size", value │ │ │ │ │ + ); │ │ │ │ │ + }, │ │ │ │ │ + "Rotation": function(value) { │ │ │ │ │ + return this.createElementNSPlus("sld:Rotation", { │ │ │ │ │ + value: value │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "OnlineResource": function(href) { │ │ │ │ │ + return this.createElementNSPlus("sld:OnlineResource", { │ │ │ │ │ + attributes: { │ │ │ │ │ + "xlink:type": "simple", │ │ │ │ │ + "xlink:href": href │ │ │ │ │ + } │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ + "Format": function(format) { │ │ │ │ │ + return this.createElementNSPlus("sld:Format", { │ │ │ │ │ + value: format │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, OpenLayers.Format.Filter.v1_0_0.prototype.writers), │ │ │ │ │ │ │ │ │ │ - return OpenLayers.Util.extend(this, defaults); │ │ │ │ │ - }, │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.SLD.v1" │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Format.ArcXML.Response" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/ArcIMS.js │ │ │ │ │ + OpenLayers/Format/SLD/v1_0_0.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ - * @requires OpenLayers/Format/ArcXML.js │ │ │ │ │ - * @requires OpenLayers/Request.js │ │ │ │ │ + * @requires OpenLayers/Format/SLD/v1.js │ │ │ │ │ + * @requires OpenLayers/Format/Filter/v1_0_0.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.ArcIMS │ │ │ │ │ - * Instances of OpenLayers.Layer.ArcIMS are used to display data from ESRI ArcIMS │ │ │ │ │ - * Mapping Services. Create a new ArcIMS layer with the │ │ │ │ │ - * constructor. │ │ │ │ │ + * Class: OpenLayers.Format.SLD.v1_0_0 │ │ │ │ │ + * Write SLD version 1.0.0. │ │ │ │ │ * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.ArcIMS = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ +OpenLayers.Format.SLD.v1_0_0 = OpenLayers.Class( │ │ │ │ │ + OpenLayers.Format.SLD.v1, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constant: DEFAULT_PARAMS │ │ │ │ │ - * {Object} Default query string parameters. │ │ │ │ │ - */ │ │ │ │ │ - DEFAULT_PARAMS: { │ │ │ │ │ - ClientVersion: "9.2", │ │ │ │ │ - ServiceName: '' │ │ │ │ │ - }, │ │ │ │ │ + /** │ │ │ │ │ + * Constant: VERSION │ │ │ │ │ + * {String} 1.0.0 │ │ │ │ │ + */ │ │ │ │ │ + VERSION: "1.0.0", │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: featureCoordSys │ │ │ │ │ - * {String} Code for feature coordinate system. Default is "4326". │ │ │ │ │ + /** │ │ │ │ │ + * Property: schemaLocation │ │ │ │ │ + * {String} http://www.opengis.net/sld │ │ │ │ │ + * http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd │ │ │ │ │ + */ │ │ │ │ │ + schemaLocation: "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd", │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Format.SLD.v1_0_0 │ │ │ │ │ + * Instances of this class are not created directly. Use the │ │ │ │ │ + * constructor instead. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} An optional object whose properties will be set on │ │ │ │ │ + * this instance. │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Format.SLD.v1_0_0" │ │ │ │ │ + │ │ │ │ │ + }); │ │ │ │ │ +/* ====================================================================== │ │ │ │ │ + OpenLayers/Control/SLDSelect.js │ │ │ │ │ + ====================================================================== */ │ │ │ │ │ + │ │ │ │ │ +/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ + * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ + * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ + * full text of the license. */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Layer/WMS.js │ │ │ │ │ + * @requires OpenLayers/Handler/RegularPolygon.js │ │ │ │ │ + * @requires OpenLayers/Handler/Polygon.js │ │ │ │ │ + * @requires OpenLayers/Handler/Path.js │ │ │ │ │ + * @requires OpenLayers/Handler/Click.js │ │ │ │ │ + * @requires OpenLayers/Filter/Spatial.js │ │ │ │ │ + * @requires OpenLayers/Format/SLD/v1_0_0.js │ │ │ │ │ + */ │ │ │ │ │ + │ │ │ │ │ +/** │ │ │ │ │ + * Class: OpenLayers.Control.SLDSelect │ │ │ │ │ + * Perform selections on WMS layers using Styled Layer Descriptor (SLD) │ │ │ │ │ + * │ │ │ │ │ + * Inherits from: │ │ │ │ │ + * - │ │ │ │ │ + */ │ │ │ │ │ +OpenLayers.Control.SLDSelect = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * selected - Triggered when a selection occurs. Listeners receive an │ │ │ │ │ + * event with *filters* and *layer* properties. Filters will be an │ │ │ │ │ + * array of OpenLayers.Filter objects created in order to perform │ │ │ │ │ + * the particular selection. │ │ │ │ │ */ │ │ │ │ │ - featureCoordSys: "4326", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: filterCoordSys │ │ │ │ │ - * {String} Code for filter coordinate system. Default is "4326". │ │ │ │ │ + * APIProperty: clearOnDeactivate │ │ │ │ │ + * {Boolean} Should the selection be cleared when the control is │ │ │ │ │ + * deactivated. Default value is false. │ │ │ │ │ */ │ │ │ │ │ - filterCoordSys: "4326", │ │ │ │ │ + clearOnDeactivate: false, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ * APIProperty: layers │ │ │ │ │ - * {Array} An array of objects with layer properties. │ │ │ │ │ + * {Array()} The WMS layers this control will work │ │ │ │ │ + * on. │ │ │ │ │ */ │ │ │ │ │ layers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: async │ │ │ │ │ - * {Boolean} Request images asynchronously. Default is true. │ │ │ │ │ + * Property: callbacks │ │ │ │ │ + * {Object} The functions that are sent to the handler for callback │ │ │ │ │ */ │ │ │ │ │ - async: true, │ │ │ │ │ + callbacks: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: name │ │ │ │ │ - * {String} Layer name. Default is "ArcIMS". │ │ │ │ │ + * APIProperty: selectionSymbolizer │ │ │ │ │ + * {Object} Determines the styling of the selected objects. Default is │ │ │ │ │ + * a selection in red. │ │ │ │ │ */ │ │ │ │ │ - name: "ArcIMS", │ │ │ │ │ + selectionSymbolizer: { │ │ │ │ │ + 'Polygon': { │ │ │ │ │ + fillColor: '#FF0000', │ │ │ │ │ + stroke: false │ │ │ │ │ + }, │ │ │ │ │ + 'Line': { │ │ │ │ │ + strokeColor: '#FF0000', │ │ │ │ │ + strokeWidth: 2 │ │ │ │ │ + }, │ │ │ │ │ + 'Point': { │ │ │ │ │ + graphicName: 'square', │ │ │ │ │ + fillColor: '#FF0000', │ │ │ │ │ + pointRadius: 5 │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} The layer is a base layer. Default is true. │ │ │ │ │ + * APIProperty: layerOptions │ │ │ │ │ + * {Object} The options to apply to the selection layer, by default the │ │ │ │ │ + * selection layer will be kept out of the layer switcher. │ │ │ │ │ */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ + layerOptions: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constant: DEFAULT_OPTIONS │ │ │ │ │ - * {Object} Default layers properties. │ │ │ │ │ + * APIProperty: handlerOptions │ │ │ │ │ + * {Object} Used to set non-default properties on the control's handler │ │ │ │ │ */ │ │ │ │ │ - DEFAULT_OPTIONS: { │ │ │ │ │ - tileSize: new OpenLayers.Size(512, 512), │ │ │ │ │ - featureCoordSys: "4326", │ │ │ │ │ - filterCoordSys: "4326", │ │ │ │ │ - layers: null, │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ - async: true, │ │ │ │ │ - name: "ArcIMS" │ │ │ │ │ - }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.ArcIMS │ │ │ │ │ - * Create a new ArcIMS layer object. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ + * APIProperty: sketchStyle │ │ │ │ │ + * {|Object} Style or symbolizer to use for the sketch │ │ │ │ │ + * handler. The recommended way of styling the sketch layer, however, is │ │ │ │ │ + * to configure an in the layerOptions of the │ │ │ │ │ + * : │ │ │ │ │ + * │ │ │ │ │ * (code) │ │ │ │ │ - * var arcims = new OpenLayers.Layer.ArcIMS( │ │ │ │ │ - * "Global Sample", │ │ │ │ │ - * "http://sample.avencia.com/servlet/com.esri.esrimap.Esrimap", │ │ │ │ │ - * { │ │ │ │ │ - * service: "OpenLayers_Sample", │ │ │ │ │ - * layers: [ │ │ │ │ │ - * // layers to manipulate │ │ │ │ │ - * {id: "1", visible: true} │ │ │ │ │ - * ] │ │ │ │ │ + * new OpenLayers.Control.SLDSelect(OpenLayers.Handler.Path, { │ │ │ │ │ + * handlerOptions: { │ │ │ │ │ + * layerOptions: { │ │ │ │ │ + * styleMap: new OpenLayers.StyleMap({ │ │ │ │ │ + * "default": {strokeColor: "yellow"} │ │ │ │ │ + * }) │ │ │ │ │ + * } │ │ │ │ │ * } │ │ │ │ │ - * ); │ │ │ │ │ + * }); │ │ │ │ │ * (end) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * name - {String} A name for the layer │ │ │ │ │ - * url - {String} Base url for the ArcIMS server │ │ │ │ │ - * options - {Object} Optional object with properties to be set on the │ │ │ │ │ - * layer. │ │ │ │ │ */ │ │ │ │ │ - initialize: function(name, url, options) { │ │ │ │ │ - │ │ │ │ │ - this.tileSize = new OpenLayers.Size(512, 512); │ │ │ │ │ - │ │ │ │ │ - // parameters │ │ │ │ │ - this.params = OpenLayers.Util.applyDefaults({ │ │ │ │ │ - ServiceName: options.serviceName │ │ │ │ │ - }, │ │ │ │ │ - this.DEFAULT_PARAMS │ │ │ │ │ - ); │ │ │ │ │ - this.options = OpenLayers.Util.applyDefaults( │ │ │ │ │ - options, this.DEFAULT_OPTIONS │ │ │ │ │ - ); │ │ │ │ │ + sketchStyle: null, │ │ │ │ │ │ │ │ │ │ - OpenLayers.Layer.Grid.prototype.initialize.apply( │ │ │ │ │ - this, [name, url, this.params, options] │ │ │ │ │ - ); │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: wfsCache │ │ │ │ │ + * {Object} Cache to use for storing parsed results from │ │ │ │ │ + * . If not provided, │ │ │ │ │ + * these will be cached on the prototype. │ │ │ │ │ + */ │ │ │ │ │ + wfsCache: {}, │ │ │ │ │ │ │ │ │ │ - //layer is transparent │ │ │ │ │ - if (this.transparent) { │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: layerCache │ │ │ │ │ + * {Object} Cache to use for storing references to the selection layers. │ │ │ │ │ + * Normally each source layer will have exactly 1 selection layer of │ │ │ │ │ + * type OpenLayers.Layer.WMS. If not provided, layers will │ │ │ │ │ + * be cached on the prototype. Note that if is │ │ │ │ │ + * true, the layer will no longer be cached after deactivating the │ │ │ │ │ + * control. │ │ │ │ │ + */ │ │ │ │ │ + layerCache: {}, │ │ │ │ │ │ │ │ │ │ - // unless explicitly set in options, make layer an overlay │ │ │ │ │ - if (!this.isBaseLayer) { │ │ │ │ │ - this.isBaseLayer = false; │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Constructor: OpenLayers.Control.SLDSelect │ │ │ │ │ + * Create a new control for selecting features in WMS layers using │ │ │ │ │ + * Styled Layer Descriptor (SLD). │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * handler - {} A sketch handler class. This determines │ │ │ │ │ + * the type of selection, e.g. box (), point │ │ │ │ │ + * (), path () or │ │ │ │ │ + * polygon () selection. To use circle │ │ │ │ │ + * type selection, use and pass │ │ │ │ │ + * the number of desired sides (e.g. 40) as "sides" property to the │ │ │ │ │ + * . │ │ │ │ │ + * options - {Object} An object containing all configuration properties for │ │ │ │ │ + * the control. │ │ │ │ │ + * │ │ │ │ │ + * Valid options: │ │ │ │ │ + * layers - Array({}) The layers to perform the │ │ │ │ │ + * selection on. │ │ │ │ │ + */ │ │ │ │ │ + initialize: function(handler, options) { │ │ │ │ │ + OpenLayers.Control.prototype.initialize.apply(this, [options]); │ │ │ │ │ │ │ │ │ │ - // jpegs can never be transparent, so intelligently switch the │ │ │ │ │ - // format, depending on the browser's capabilities │ │ │ │ │ - if (this.format == "image/jpeg") { │ │ │ │ │ - this.format = OpenLayers.Util.alphaHack() ? "image/gif" : "image/png"; │ │ │ │ │ + this.callbacks = OpenLayers.Util.extend({ │ │ │ │ │ + done: this.select, │ │ │ │ │ + click: this.select │ │ │ │ │ + }, this.callbacks); │ │ │ │ │ + this.handlerOptions = this.handlerOptions || {}; │ │ │ │ │ + this.layerOptions = OpenLayers.Util.applyDefaults(this.layerOptions, { │ │ │ │ │ + displayInLayerSwitcher: false, │ │ │ │ │ + tileOptions: { │ │ │ │ │ + maxGetUrlLength: 2048 │ │ │ │ │ } │ │ │ │ │ + }); │ │ │ │ │ + if (this.sketchStyle) { │ │ │ │ │ + this.handlerOptions.layerOptions = OpenLayers.Util.applyDefaults( │ │ │ │ │ + this.handlerOptions.layerOptions, { │ │ │ │ │ + styleMap: new OpenLayers.StyleMap({ │ │ │ │ │ + "default": this.sketchStyle │ │ │ │ │ + }) │ │ │ │ │ + } │ │ │ │ │ + ); │ │ │ │ │ } │ │ │ │ │ + this.handler = new handler(this, this.callbacks, this.handlerOptions); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // create an empty layer list if no layers specified in the options │ │ │ │ │ - if (this.options.layers === null) { │ │ │ │ │ - this.options.layers = []; │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: destroy │ │ │ │ │ + * Take care of things that are not handled in superclass. │ │ │ │ │ + */ │ │ │ │ │ + destroy: function() { │ │ │ │ │ + for (var key in this.layerCache) { │ │ │ │ │ + delete this.layerCache[key]; │ │ │ │ │ + } │ │ │ │ │ + for (var key in this.wfsCache) { │ │ │ │ │ + delete this.wfsCache[key]; │ │ │ │ │ } │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getURL │ │ │ │ │ - * Return an image url this layer. │ │ │ │ │ + * Method: coupleLayerVisiblity │ │ │ │ │ + * Couple the selection layer and the source layer with respect to │ │ │ │ │ + * layer visibility. So if the source layer is turned off, the │ │ │ │ │ + * selection layer is also turned off. │ │ │ │ │ + * │ │ │ │ │ + * Context: │ │ │ │ │ + * - {} │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} A bounds representing the bbox for the │ │ │ │ │ - * request. │ │ │ │ │ + * evt - {Object} │ │ │ │ │ + */ │ │ │ │ │ + coupleLayerVisiblity: function(evt) { │ │ │ │ │ + this.setVisibility(evt.object.getVisibility()); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + /** │ │ │ │ │ + * Method: createSelectionLayer │ │ │ │ │ + * Creates a "clone" from the source layer in which the selection can │ │ │ │ │ + * be drawn. This ensures both the source layer and the selection are │ │ │ │ │ + * visible and not only the selection. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * source - {} The source layer on which the selection │ │ │ │ │ + * is performed. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A string with the map image's url. │ │ │ │ │ + * {} A WMS layer with maxGetUrlLength configured to 2048 │ │ │ │ │ + * since SLD selections can easily get quite long. │ │ │ │ │ */ │ │ │ │ │ - getURL: function(bounds) { │ │ │ │ │ - var url = ""; │ │ │ │ │ - bounds = this.adjustBounds(bounds); │ │ │ │ │ - │ │ │ │ │ - // create an arcxml request to generate the image │ │ │ │ │ - var axlReq = new OpenLayers.Format.ArcXML( │ │ │ │ │ - OpenLayers.Util.extend(this.options, { │ │ │ │ │ - requesttype: "image", │ │ │ │ │ - envelope: bounds.toArray(), │ │ │ │ │ - tileSize: this.tileSize │ │ │ │ │ - }) │ │ │ │ │ - ); │ │ │ │ │ - │ │ │ │ │ - // create a synchronous ajax request to get an arcims image │ │ │ │ │ - var req = new OpenLayers.Request.POST({ │ │ │ │ │ - url: this.getFullRequestString(), │ │ │ │ │ - data: axlReq.write(), │ │ │ │ │ - async: false │ │ │ │ │ - }); │ │ │ │ │ - │ │ │ │ │ - // if the response exists │ │ │ │ │ - if (req != null) { │ │ │ │ │ - var doc = req.responseXML; │ │ │ │ │ - │ │ │ │ │ - if (!doc || !doc.documentElement) { │ │ │ │ │ - doc = req.responseText; │ │ │ │ │ + createSelectionLayer: function(source) { │ │ │ │ │ + // check if we already have a selection layer for the source layer │ │ │ │ │ + var selectionLayer; │ │ │ │ │ + if (!this.layerCache[source.id]) { │ │ │ │ │ + selectionLayer = new OpenLayers.Layer.WMS(source.name, │ │ │ │ │ + source.url, source.params, │ │ │ │ │ + OpenLayers.Util.applyDefaults( │ │ │ │ │ + this.layerOptions, │ │ │ │ │ + source.getOptions()) │ │ │ │ │ + ); │ │ │ │ │ + this.layerCache[source.id] = selectionLayer; │ │ │ │ │ + // make sure the layers are coupled wrt visibility, but only │ │ │ │ │ + // if they are not displayed in the layer switcher, because in │ │ │ │ │ + // that case the user cannot control visibility. │ │ │ │ │ + if (this.layerOptions.displayInLayerSwitcher === false) { │ │ │ │ │ + source.events.on({ │ │ │ │ │ + "visibilitychanged": this.coupleLayerVisiblity, │ │ │ │ │ + scope: selectionLayer │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // create a new arcxml format to read the response │ │ │ │ │ - var axlResp = new OpenLayers.Format.ArcXML(); │ │ │ │ │ - var arcxml = axlResp.read(doc); │ │ │ │ │ - url = this.getUrlOrImage(arcxml.image.output); │ │ │ │ │ + this.map.addLayer(selectionLayer); │ │ │ │ │ + } else { │ │ │ │ │ + selectionLayer = this.layerCache[source.id]; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - return url; │ │ │ │ │ + return selectionLayer; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - │ │ │ │ │ /** │ │ │ │ │ - * Method: getURLasync │ │ │ │ │ - * Get an image url this layer asynchronously, and execute a callback │ │ │ │ │ - * when the image url is generated. │ │ │ │ │ + * Method: createSLD │ │ │ │ │ + * Create the SLD document for the layer using the supplied filters. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * bounds - {} A bounds representing the bbox for the │ │ │ │ │ - * request. │ │ │ │ │ - * callback - {Function} Function to call when image url is retrieved. │ │ │ │ │ - * scope - {Object} The scope of the callback method. │ │ │ │ │ + * layer - {} │ │ │ │ │ + * filters - Array({}) The filters to be applied. │ │ │ │ │ + * geometryAttributes - Array({Object}) The geometry attributes of the │ │ │ │ │ + * layer. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {String} The SLD document generated as a string. │ │ │ │ │ */ │ │ │ │ │ - getURLasync: function(bounds, callback, scope) { │ │ │ │ │ - bounds = this.adjustBounds(bounds); │ │ │ │ │ - │ │ │ │ │ - // create an arcxml request to generate the image │ │ │ │ │ - var axlReq = new OpenLayers.Format.ArcXML( │ │ │ │ │ - OpenLayers.Util.extend(this.options, { │ │ │ │ │ - requesttype: "image", │ │ │ │ │ - envelope: bounds.toArray(), │ │ │ │ │ - tileSize: this.tileSize │ │ │ │ │ - }) │ │ │ │ │ - ); │ │ │ │ │ + createSLD: function(layer, filters, geometryAttributes) { │ │ │ │ │ + var sld = { │ │ │ │ │ + version: "1.0.0", │ │ │ │ │ + namedLayers: {} │ │ │ │ │ + }; │ │ │ │ │ + var layerNames = [layer.params.LAYERS].join(",").split(","); │ │ │ │ │ + for (var i = 0, len = layerNames.length; i < len; i++) { │ │ │ │ │ + var name = layerNames[i]; │ │ │ │ │ + sld.namedLayers[name] = { │ │ │ │ │ + name: name, │ │ │ │ │ + userStyles: [] │ │ │ │ │ + }; │ │ │ │ │ + var symbolizer = this.selectionSymbolizer; │ │ │ │ │ + var geometryAttribute = geometryAttributes[i]; │ │ │ │ │ + if (geometryAttribute.type.indexOf('Polygon') >= 0) { │ │ │ │ │ + symbolizer = { │ │ │ │ │ + Polygon: this.selectionSymbolizer['Polygon'] │ │ │ │ │ + }; │ │ │ │ │ + } else if (geometryAttribute.type.indexOf('LineString') >= 0) { │ │ │ │ │ + symbolizer = { │ │ │ │ │ + Line: this.selectionSymbolizer['Line'] │ │ │ │ │ + }; │ │ │ │ │ + } else if (geometryAttribute.type.indexOf('Point') >= 0) { │ │ │ │ │ + symbolizer = { │ │ │ │ │ + Point: this.selectionSymbolizer['Point'] │ │ │ │ │ + }; │ │ │ │ │ + } │ │ │ │ │ + var filter = filters[i]; │ │ │ │ │ + sld.namedLayers[name].userStyles.push({ │ │ │ │ │ + name: 'default', │ │ │ │ │ + rules: [ │ │ │ │ │ + new OpenLayers.Rule({ │ │ │ │ │ + symbolizer: symbolizer, │ │ │ │ │ + filter: filter, │ │ │ │ │ + maxScaleDenominator: layer.options.minScale │ │ │ │ │ + }) │ │ │ │ │ + ] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + return new OpenLayers.Format.SLD({ │ │ │ │ │ + srsName: this.map.getProjection() │ │ │ │ │ + }).write(sld); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // create an asynchronous ajax request to get an arcims image │ │ │ │ │ - OpenLayers.Request.POST({ │ │ │ │ │ - url: this.getFullRequestString(), │ │ │ │ │ - async: true, │ │ │ │ │ - data: axlReq.write(), │ │ │ │ │ - callback: function(req) { │ │ │ │ │ - // process the response from ArcIMS, and call the callback function │ │ │ │ │ - // to set the image URL │ │ │ │ │ - var doc = req.responseXML; │ │ │ │ │ + /** │ │ │ │ │ + * Method: parseDescribeLayer │ │ │ │ │ + * Parse the SLD WMS DescribeLayer response and issue the corresponding │ │ │ │ │ + * WFS DescribeFeatureType request │ │ │ │ │ + * │ │ │ │ │ + * request - {XMLHttpRequest} The request object. │ │ │ │ │ + */ │ │ │ │ │ + parseDescribeLayer: function(request) { │ │ │ │ │ + var format = new OpenLayers.Format.WMSDescribeLayer(); │ │ │ │ │ + var doc = request.responseXML; │ │ │ │ │ + if (!doc || !doc.documentElement) { │ │ │ │ │ + doc = request.responseText; │ │ │ │ │ + } │ │ │ │ │ + var describeLayer = format.read(doc); │ │ │ │ │ + var typeNames = []; │ │ │ │ │ + var url = null; │ │ │ │ │ + for (var i = 0, len = describeLayer.length; i < len; i++) { │ │ │ │ │ + // perform a WFS DescribeFeatureType request │ │ │ │ │ + if (describeLayer[i].owsType == "WFS") { │ │ │ │ │ + typeNames.push(describeLayer[i].typeName); │ │ │ │ │ + url = describeLayer[i].owsURL; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + var options = { │ │ │ │ │ + url: url, │ │ │ │ │ + params: { │ │ │ │ │ + SERVICE: "WFS", │ │ │ │ │ + TYPENAME: typeNames.toString(), │ │ │ │ │ + REQUEST: "DescribeFeatureType", │ │ │ │ │ + VERSION: "1.0.0" │ │ │ │ │ + }, │ │ │ │ │ + callback: function(request) { │ │ │ │ │ + var format = new OpenLayers.Format.WFSDescribeFeatureType(); │ │ │ │ │ + var doc = request.responseXML; │ │ │ │ │ if (!doc || !doc.documentElement) { │ │ │ │ │ - doc = req.responseText; │ │ │ │ │ + doc = request.responseText; │ │ │ │ │ } │ │ │ │ │ - │ │ │ │ │ - // create a new arcxml format to read the response │ │ │ │ │ - var axlResp = new OpenLayers.Format.ArcXML(); │ │ │ │ │ - var arcxml = axlResp.read(doc); │ │ │ │ │ - │ │ │ │ │ - callback.call(scope, this.getUrlOrImage(arcxml.image.output)); │ │ │ │ │ + var describeFeatureType = format.read(doc); │ │ │ │ │ + this.control.wfsCache[this.layer.id] = describeFeatureType; │ │ │ │ │ + this.control._queue && this.control.applySelection(); │ │ │ │ │ }, │ │ │ │ │ scope: this │ │ │ │ │ - }); │ │ │ │ │ + }; │ │ │ │ │ + OpenLayers.Request.GET(options); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getUrlOrImage │ │ │ │ │ - * Extract a url or image from the ArcXML image output. │ │ │ │ │ + * Method: getGeometryAttributes │ │ │ │ │ + * Look up the geometry attributes from the WFS DescribeFeatureType response │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * output - {Object} The image.output property of the object returned from │ │ │ │ │ - * the ArcXML format read method. │ │ │ │ │ + * layer - {} The layer for which to look up the │ │ │ │ │ + * geometry attributes. │ │ │ │ │ * │ │ │ │ │ * Returns: │ │ │ │ │ - * {String} A URL for an image (potentially with the data protocol). │ │ │ │ │ + * Array({Object}) Array of geometry attributes │ │ │ │ │ */ │ │ │ │ │ - getUrlOrImage: function(output) { │ │ │ │ │ - var ret = ""; │ │ │ │ │ - if (output.url) { │ │ │ │ │ - // If the image response output url is a string, then the image │ │ │ │ │ - // data is not inline. │ │ │ │ │ - ret = output.url; │ │ │ │ │ - } else if (output.data) { │ │ │ │ │ - // The image data is inline and base64 encoded, create a data │ │ │ │ │ - // url for the image. This will only work for small images, │ │ │ │ │ - // due to browser url length limits. │ │ │ │ │ - ret = "data:image/" + output.type + │ │ │ │ │ - ";base64," + output.data; │ │ │ │ │ + getGeometryAttributes: function(layer) { │ │ │ │ │ + var result = []; │ │ │ │ │ + var cache = this.wfsCache[layer.id]; │ │ │ │ │ + for (var i = 0, len = cache.featureTypes.length; i < len; i++) { │ │ │ │ │ + var typeName = cache.featureTypes[i]; │ │ │ │ │ + var properties = typeName.properties; │ │ │ │ │ + for (var j = 0, lenj = properties.length; j < lenj; j++) { │ │ │ │ │ + var property = properties[j]; │ │ │ │ │ + var type = property.type; │ │ │ │ │ + if ((type.indexOf('LineString') >= 0) || │ │ │ │ │ + (type.indexOf('GeometryAssociationType') >= 0) || │ │ │ │ │ + (type.indexOf('GeometryPropertyType') >= 0) || │ │ │ │ │ + (type.indexOf('Point') >= 0) || │ │ │ │ │ + (type.indexOf('Polygon') >= 0)) { │ │ │ │ │ + result.push(property); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ - return ret; │ │ │ │ │ + return result; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: setLayerQuery │ │ │ │ │ - * Set the query definition on this layer. Query definitions are used to │ │ │ │ │ - * render parts of the spatial data in an image, and can be used to │ │ │ │ │ - * filter features or layers in the ArcIMS service. │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * id - {String} The ArcIMS layer ID. │ │ │ │ │ - * querydef - {Object} The query definition to apply to this layer. │ │ │ │ │ + * APIMethod: activate │ │ │ │ │ + * Activate the control. Activating the control will perform a SLD WMS │ │ │ │ │ + * DescribeLayer request followed by a WFS DescribeFeatureType request │ │ │ │ │ + * so that the proper symbolizers can be chosen based on the geometry │ │ │ │ │ + * type. │ │ │ │ │ */ │ │ │ │ │ - setLayerQuery: function(id, querydef) { │ │ │ │ │ - // find the matching layer, if it exists │ │ │ │ │ - for (var lyr = 0; lyr < this.options.layers.length; lyr++) { │ │ │ │ │ - if (id == this.options.layers[lyr].id) { │ │ │ │ │ - // replace this layer definition │ │ │ │ │ - this.options.layers[lyr].query = querydef; │ │ │ │ │ - return; │ │ │ │ │ + activate: function() { │ │ │ │ │ + var activated = OpenLayers.Control.prototype.activate.call(this); │ │ │ │ │ + if (activated) { │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + var layer = this.layers[i]; │ │ │ │ │ + if (layer && !this.wfsCache[layer.id]) { │ │ │ │ │ + var options = { │ │ │ │ │ + url: layer.url, │ │ │ │ │ + params: { │ │ │ │ │ + SERVICE: "WMS", │ │ │ │ │ + VERSION: layer.params.VERSION, │ │ │ │ │ + LAYERS: layer.params.LAYERS, │ │ │ │ │ + REQUEST: "DescribeLayer" │ │ │ │ │ + }, │ │ │ │ │ + callback: this.parseDescribeLayer, │ │ │ │ │ + scope: { │ │ │ │ │ + layer: layer, │ │ │ │ │ + control: this │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + OpenLayers.Request.GET(options); │ │ │ │ │ + } │ │ │ │ │ } │ │ │ │ │ } │ │ │ │ │ + return activated; │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // no layer found, create a new definition │ │ │ │ │ - this.options.layers.push({ │ │ │ │ │ - id: id, │ │ │ │ │ - visible: true, │ │ │ │ │ - query: querydef │ │ │ │ │ - }); │ │ │ │ │ + /** │ │ │ │ │ + * APIMethod: deactivate │ │ │ │ │ + * Deactivate the control. If clearOnDeactivate is true, remove the │ │ │ │ │ + * selection layer(s). │ │ │ │ │ + */ │ │ │ │ │ + deactivate: function() { │ │ │ │ │ + var deactivated = OpenLayers.Control.prototype.deactivate.call(this); │ │ │ │ │ + if (deactivated) { │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + var layer = this.layers[i]; │ │ │ │ │ + if (layer && this.clearOnDeactivate === true) { │ │ │ │ │ + var layerCache = this.layerCache; │ │ │ │ │ + var selectionLayer = layerCache[layer.id]; │ │ │ │ │ + if (selectionLayer) { │ │ │ │ │ + layer.events.un({ │ │ │ │ │ + "visibilitychanged": this.coupleLayerVisiblity, │ │ │ │ │ + scope: selectionLayer │ │ │ │ │ + }); │ │ │ │ │ + selectionLayer.destroy(); │ │ │ │ │ + delete layerCache[layer.id]; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return deactivated; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: getFeatureInfo │ │ │ │ │ - * Get feature information from ArcIMS. Using the applied geometry, apply │ │ │ │ │ - * the options to the query (buffer, area/envelope intersection), and │ │ │ │ │ - * query the ArcIMS service. │ │ │ │ │ - * │ │ │ │ │ - * A note about accuracy: │ │ │ │ │ - * ArcIMS interprets the accuracy attribute in feature requests to be │ │ │ │ │ - * something like the 'modulus' operator on feature coordinates, │ │ │ │ │ - * applied to the database geometry of the feature. It doesn't round, │ │ │ │ │ - * so your feature coordinates may be up to (1 x accuracy) offset from │ │ │ │ │ - * the actual feature coordinates. If the accuracy of the layer is not │ │ │ │ │ - * specified, the accuracy will be computed to be approximately 1 │ │ │ │ │ - * feature coordinate per screen pixel. │ │ │ │ │ + * APIMethod: setLayers │ │ │ │ │ + * Set the layers on which the selection should be performed. Call the │ │ │ │ │ + * setLayers method if the layer(s) to be used change and the same │ │ │ │ │ + * control should be used on a new set of layers. │ │ │ │ │ + * If the control is already active, it will be active after the new │ │ │ │ │ + * set of layers is set. │ │ │ │ │ * │ │ │ │ │ * Parameters: │ │ │ │ │ - * geometry - {} or {} The │ │ │ │ │ - * geometry to use when making the query. This should be a closed │ │ │ │ │ - * polygon for behavior approximating a free selection. │ │ │ │ │ - * layer - {Object} The ArcIMS layer definition. This is an anonymous object │ │ │ │ │ - * that looks like: │ │ │ │ │ - * (code) │ │ │ │ │ - * { │ │ │ │ │ - * id: "ArcXML layer ID", // the ArcXML layer ID │ │ │ │ │ - * query: { │ │ │ │ │ - * where: "STATE = 'PA'", // the where clause of the query │ │ │ │ │ - * accuracy: 100 // the accuracy of the returned feature │ │ │ │ │ - * } │ │ │ │ │ - * } │ │ │ │ │ - * (end) │ │ │ │ │ - * options - {Object} Object with non-default properties to set on the layer. │ │ │ │ │ - * Supported properties are buffer, callback, scope, and any other │ │ │ │ │ - * properties applicable to the ArcXML format. Set the 'callback' and │ │ │ │ │ - * 'scope' for an object and function to recieve the parsed features │ │ │ │ │ - * from ArcIMS. │ │ │ │ │ + * layers - {Array()} The new set of layers on which │ │ │ │ │ + * the selection should be performed. │ │ │ │ │ */ │ │ │ │ │ - getFeatureInfo: function(geometry, layer, options) { │ │ │ │ │ - // set the buffer to 1 unit (dd/m/ft?) by default │ │ │ │ │ - var buffer = options.buffer || 1; │ │ │ │ │ - // empty callback by default │ │ │ │ │ - var callback = options.callback || function() {}; │ │ │ │ │ - // default scope is window (global) │ │ │ │ │ - var scope = options.scope || window; │ │ │ │ │ - │ │ │ │ │ - // apply these option to the request options │ │ │ │ │ - var requestOptions = {}; │ │ │ │ │ - OpenLayers.Util.extend(requestOptions, this.options); │ │ │ │ │ - │ │ │ │ │ - // this is a feature request │ │ │ │ │ - requestOptions.requesttype = "feature"; │ │ │ │ │ - │ │ │ │ │ - if (geometry instanceof OpenLayers.LonLat) { │ │ │ │ │ - // create an envelope if the geometry is really a lon/lat │ │ │ │ │ - requestOptions.polygon = null; │ │ │ │ │ - requestOptions.envelope = [ │ │ │ │ │ - geometry.lon - buffer, │ │ │ │ │ - geometry.lat - buffer, │ │ │ │ │ - geometry.lon + buffer, │ │ │ │ │ - geometry.lat + buffer │ │ │ │ │ - ]; │ │ │ │ │ - } else if (geometry instanceof OpenLayers.Geometry.Polygon) { │ │ │ │ │ - // use the polygon assigned, and empty the envelope │ │ │ │ │ - requestOptions.envelope = null; │ │ │ │ │ - requestOptions.polygon = geometry; │ │ │ │ │ - } │ │ │ │ │ - │ │ │ │ │ - // create an arcxml request to get feature requests │ │ │ │ │ - var arcxml = new OpenLayers.Format.ArcXML(requestOptions); │ │ │ │ │ - │ │ │ │ │ - // apply any get feature options to the arcxml request │ │ │ │ │ - OpenLayers.Util.extend(arcxml.request.get_feature, options); │ │ │ │ │ - │ │ │ │ │ - arcxml.request.get_feature.layer = layer.id; │ │ │ │ │ - if (typeof layer.query.accuracy == "number") { │ │ │ │ │ - // set the accuracy if it was specified │ │ │ │ │ - arcxml.request.get_feature.query.accuracy = layer.query.accuracy; │ │ │ │ │ + setLayers: function(layers) { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + this.deactivate(); │ │ │ │ │ + this.layers = layers; │ │ │ │ │ + this.activate(); │ │ │ │ │ } else { │ │ │ │ │ - // guess that the accuracy is 1 per screen pixel │ │ │ │ │ - var mapCenter = this.map.getCenter(); │ │ │ │ │ - var viewPx = this.map.getViewPortPxFromLonLat(mapCenter); │ │ │ │ │ - viewPx.x++; │ │ │ │ │ - var mapOffCenter = this.map.getLonLatFromPixel(viewPx); │ │ │ │ │ - arcxml.request.get_feature.query.accuracy = mapOffCenter.lon - mapCenter.lon; │ │ │ │ │ + this.layers = layers; │ │ │ │ │ } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - // set the get_feature query to be the same as the layer passed in │ │ │ │ │ - arcxml.request.get_feature.query.where = layer.query.where; │ │ │ │ │ - │ │ │ │ │ - // use area_intersection │ │ │ │ │ - arcxml.request.get_feature.query.spatialfilter.relation = "area_intersection"; │ │ │ │ │ - │ │ │ │ │ - // create a new asynchronous request to get the feature info │ │ │ │ │ - OpenLayers.Request.POST({ │ │ │ │ │ - url: this.getFullRequestString({ │ │ │ │ │ - 'CustomService': 'Query' │ │ │ │ │ - }), │ │ │ │ │ - data: arcxml.write(), │ │ │ │ │ - callback: function(request) { │ │ │ │ │ - // parse the arcxml response │ │ │ │ │ - var response = arcxml.parseResponse(request.responseText); │ │ │ │ │ - │ │ │ │ │ - if (!arcxml.iserror()) { │ │ │ │ │ - // if the arcxml is not an error, call the callback with the features parsed │ │ │ │ │ - callback.call(scope, response.features); │ │ │ │ │ - } else { │ │ │ │ │ - // if the arcxml is an error, return null features selected │ │ │ │ │ - callback.call(scope, null); │ │ │ │ │ - } │ │ │ │ │ + /** │ │ │ │ │ + * Function: createFilter │ │ │ │ │ + * Create the filter to be used in the SLD. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometryAttribute - {Object} Used to get the name of the geometry │ │ │ │ │ + * attribute which is needed for constructing the spatial filter. │ │ │ │ │ + * geometry - {} The geometry to use. │ │ │ │ │ + * │ │ │ │ │ + * Returns: │ │ │ │ │ + * {} The spatial filter created. │ │ │ │ │ + */ │ │ │ │ │ + createFilter: function(geometryAttribute, geometry) { │ │ │ │ │ + var filter = null; │ │ │ │ │ + if (this.handler instanceof OpenLayers.Handler.RegularPolygon) { │ │ │ │ │ + // box │ │ │ │ │ + if (this.handler.irregular === true) { │ │ │ │ │ + filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ + type: OpenLayers.Filter.Spatial.BBOX, │ │ │ │ │ + property: geometryAttribute.name, │ │ │ │ │ + value: geometry.getBounds() │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ + type: OpenLayers.Filter.Spatial.INTERSECTS, │ │ │ │ │ + property: geometryAttribute.name, │ │ │ │ │ + value: geometry │ │ │ │ │ + }); │ │ │ │ │ } │ │ │ │ │ - }); │ │ │ │ │ + } else if (this.handler instanceof OpenLayers.Handler.Polygon) { │ │ │ │ │ + filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ + type: OpenLayers.Filter.Spatial.INTERSECTS, │ │ │ │ │ + property: geometryAttribute.name, │ │ │ │ │ + value: geometry │ │ │ │ │ + }); │ │ │ │ │ + } else if (this.handler instanceof OpenLayers.Handler.Path) { │ │ │ │ │ + // if source layer is point based, use DWITHIN instead │ │ │ │ │ + if (geometryAttribute.type.indexOf('Point') >= 0) { │ │ │ │ │ + filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ + type: OpenLayers.Filter.Spatial.DWITHIN, │ │ │ │ │ + property: geometryAttribute.name, │ │ │ │ │ + distance: this.map.getExtent().getWidth() * 0.01, │ │ │ │ │ + distanceUnits: this.map.getUnits(), │ │ │ │ │ + value: geometry │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ + type: OpenLayers.Filter.Spatial.INTERSECTS, │ │ │ │ │ + property: geometryAttribute.name, │ │ │ │ │ + value: geometry │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } else if (this.handler instanceof OpenLayers.Handler.Click) { │ │ │ │ │ + if (geometryAttribute.type.indexOf('Polygon') >= 0) { │ │ │ │ │ + filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ + type: OpenLayers.Filter.Spatial.INTERSECTS, │ │ │ │ │ + property: geometryAttribute.name, │ │ │ │ │ + value: geometry │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + filter = new OpenLayers.Filter.Spatial({ │ │ │ │ │ + type: OpenLayers.Filter.Spatial.DWITHIN, │ │ │ │ │ + property: geometryAttribute.name, │ │ │ │ │ + distance: this.map.getExtent().getWidth() * 0.01, │ │ │ │ │ + distanceUnits: this.map.getUnits(), │ │ │ │ │ + value: geometry │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + return filter; │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Method: clone │ │ │ │ │ - * Create a clone of this layer │ │ │ │ │ + * Method: select │ │ │ │ │ + * When the handler is done, use SLD_BODY on the selection layer to │ │ │ │ │ + * display the selection in the map. │ │ │ │ │ * │ │ │ │ │ - * Returns: │ │ │ │ │ - * {} An exact clone of this layer │ │ │ │ │ + * Parameters: │ │ │ │ │ + * geometry - {Object} or {} │ │ │ │ │ */ │ │ │ │ │ - clone: function(obj) { │ │ │ │ │ + select: function(geometry) { │ │ │ │ │ + this._queue = function() { │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + var layer = this.layers[i]; │ │ │ │ │ + var geometryAttributes = this.getGeometryAttributes(layer); │ │ │ │ │ + var filters = []; │ │ │ │ │ + for (var j = 0, lenj = geometryAttributes.length; j < lenj; j++) { │ │ │ │ │ + var geometryAttribute = geometryAttributes[j]; │ │ │ │ │ + if (geometryAttribute !== null) { │ │ │ │ │ + // from the click handler we will not get an actual │ │ │ │ │ + // geometry so transform │ │ │ │ │ + if (!(geometry instanceof OpenLayers.Geometry)) { │ │ │ │ │ + var point = this.map.getLonLatFromPixel( │ │ │ │ │ + geometry.xy); │ │ │ │ │ + geometry = new OpenLayers.Geometry.Point( │ │ │ │ │ + point.lon, point.lat); │ │ │ │ │ + } │ │ │ │ │ + var filter = this.createFilter(geometryAttribute, │ │ │ │ │ + geometry); │ │ │ │ │ + if (filter !== null) { │ │ │ │ │ + filters.push(filter); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ │ │ │ │ │ - if (obj == null) { │ │ │ │ │ - obj = new OpenLayers.Layer.ArcIMS(this.name, │ │ │ │ │ - this.url, │ │ │ │ │ - this.getOptions()); │ │ │ │ │ - } │ │ │ │ │ + var selectionLayer = this.createSelectionLayer(layer); │ │ │ │ │ │ │ │ │ │ - //get all additions from superclasses │ │ │ │ │ - obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); │ │ │ │ │ + this.events.triggerEvent("selected", { │ │ │ │ │ + layer: layer, │ │ │ │ │ + filters: filters │ │ │ │ │ + }); │ │ │ │ │ │ │ │ │ │ - // copy/set any non-init, non-simple values here │ │ │ │ │ + var sld = this.createSLD(layer, filters, geometryAttributes); │ │ │ │ │ │ │ │ │ │ - return obj; │ │ │ │ │ + selectionLayer.mergeNewParams({ │ │ │ │ │ + SLD_BODY: sld │ │ │ │ │ + }); │ │ │ │ │ + delete this._queue; │ │ │ │ │ + } │ │ │ │ │ + }; │ │ │ │ │ + this.applySelection(); │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ - CLASS_NAME: "OpenLayers.Layer.ArcIMS" │ │ │ │ │ + /** │ │ │ │ │ + * Method: applySelection │ │ │ │ │ + * Checks if all required wfs data is cached, and applies the selection │ │ │ │ │ + */ │ │ │ │ │ + applySelection: function() { │ │ │ │ │ + var canApply = true; │ │ │ │ │ + for (var i = 0, len = this.layers.length; i < len; i++) { │ │ │ │ │ + if (!this.wfsCache[this.layers[i].id]) { │ │ │ │ │ + canApply = false; │ │ │ │ │ + break; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + canApply && this._queue.call(this); │ │ │ │ │ + }, │ │ │ │ │ + │ │ │ │ │ + CLASS_NAME: "OpenLayers.Control.SLDSelect" │ │ │ │ │ }); │ │ │ │ │ /* ====================================================================== │ │ │ │ │ - OpenLayers/Layer/WMTS.js │ │ │ │ │ + OpenLayers/Control/CacheWrite.js │ │ │ │ │ ====================================================================== */ │ │ │ │ │ │ │ │ │ │ /* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for │ │ │ │ │ * full list of contributors). Published under the 2-clause BSD license. │ │ │ │ │ * See license.txt in the OpenLayers distribution or repository for the │ │ │ │ │ * full text of the license. */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * @requires OpenLayers/Layer/Grid.js │ │ │ │ │ + * @requires OpenLayers/Control.js │ │ │ │ │ + * @requires OpenLayers/Request.js │ │ │ │ │ + * @requires OpenLayers/Console.js │ │ │ │ │ */ │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Class: OpenLayers.Layer.WMTS │ │ │ │ │ - * Instances of the WMTS class allow viewing of tiles from a service that │ │ │ │ │ - * implements the OGC WMTS specification version 1.0.0. │ │ │ │ │ - * │ │ │ │ │ + * Class: OpenLayers.Control.CacheWrite │ │ │ │ │ + * A control for caching image tiles in the browser's local storage. The │ │ │ │ │ + * control is used to fetch and use the cached │ │ │ │ │ + * tile images. │ │ │ │ │ + * │ │ │ │ │ + * Note: Before using this control on any layer that is not your own, make sure │ │ │ │ │ + * that the terms of service of the tile provider allow local storage of tiles. │ │ │ │ │ + * │ │ │ │ │ * Inherits from: │ │ │ │ │ - * - │ │ │ │ │ + * - │ │ │ │ │ */ │ │ │ │ │ -OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, { │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: isBaseLayer │ │ │ │ │ - * {Boolean} The layer will be considered a base layer. Default is true. │ │ │ │ │ - */ │ │ │ │ │ - isBaseLayer: true, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * Property: version │ │ │ │ │ - * {String} WMTS version. Default is "1.0.0". │ │ │ │ │ - */ │ │ │ │ │ - version: "1.0.0", │ │ │ │ │ +OpenLayers.Control.CacheWrite = OpenLayers.Class(OpenLayers.Control, { │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: requestEncoding │ │ │ │ │ - * {String} Request encoding. Can be "REST" or "KVP". Default is "KVP". │ │ │ │ │ + /** │ │ │ │ │ + * APIProperty: events │ │ │ │ │ + * {} Events instance for listeners and triggering │ │ │ │ │ + * control specific events. │ │ │ │ │ + * │ │ │ │ │ + * To register events in the constructor, configure . │ │ │ │ │ + * │ │ │ │ │ + * Register a listener for a particular event with the following syntax: │ │ │ │ │ + * (code) │ │ │ │ │ + * control.events.register(type, obj, listener); │ │ │ │ │ + * (end) │ │ │ │ │ + * │ │ │ │ │ + * Supported event types (in addition to those from ): │ │ │ │ │ + * cachefull - Triggered when the cache is full. Listeners receive an │ │ │ │ │ + * object with a tile property as first argument. The tile references │ │ │ │ │ + * the tile that couldn't be cached. │ │ │ │ │ */ │ │ │ │ │ - requestEncoding: "KVP", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: url │ │ │ │ │ - * {String|Array(String)} The base URL or request URL template for the WMTS │ │ │ │ │ - * service. Must be provided. Array is only supported for base URLs, not │ │ │ │ │ - * for request URL templates. URL templates are only supported for │ │ │ │ │ - * REST . │ │ │ │ │ + * APIProperty: eventListeners │ │ │ │ │ + * {Object} Object with event listeners, keyed by event name. An optional │ │ │ │ │ + * scope property defines the scope that listeners will be executed in. │ │ │ │ │ */ │ │ │ │ │ - url: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: layer │ │ │ │ │ - * {String} The layer identifier advertised by the WMTS service. Must be │ │ │ │ │ - * provided. │ │ │ │ │ - */ │ │ │ │ │ - layer: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: matrixSet │ │ │ │ │ - * {String} One of the advertised matrix set identifiers. Must be provided. │ │ │ │ │ - */ │ │ │ │ │ - matrixSet: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: style │ │ │ │ │ - * {String} One of the advertised layer styles. Must be provided. │ │ │ │ │ - */ │ │ │ │ │ - style: null, │ │ │ │ │ - │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: format │ │ │ │ │ - * {String} The image MIME type. Default is "image/jpeg". │ │ │ │ │ + * APIProperty: layers │ │ │ │ │ + * {Array()}. Optional. If provided, caching │ │ │ │ │ + * will be enabled for these layers only, otherwise for all cacheable │ │ │ │ │ + * layers. │ │ │ │ │ */ │ │ │ │ │ - format: "image/jpeg", │ │ │ │ │ + layers: null, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: tileOrigin │ │ │ │ │ - * {} The top-left corner of the tile matrix in map │ │ │ │ │ - * units. If the tile origin for each matrix in a set is different, │ │ │ │ │ - * the should include a topLeftCorner property. If │ │ │ │ │ - * not provided, the tile origin will default to the top left corner │ │ │ │ │ - * of the layer . │ │ │ │ │ + * APIProperty: imageFormat │ │ │ │ │ + * {String} The image format used for caching. The default is "image/png". │ │ │ │ │ + * Supported formats depend on the user agent. If an unsupported │ │ │ │ │ + * is provided, "image/png" will be used. For aerial │ │ │ │ │ + * imagery, "image/jpeg" is recommended. │ │ │ │ │ */ │ │ │ │ │ - tileOrigin: null, │ │ │ │ │ + imageFormat: "image/png", │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: tileFullExtent │ │ │ │ │ - * {} The full extent of the tile set. If not supplied, │ │ │ │ │ - * the layer's property will be used. │ │ │ │ │ + * Property: quotaRegEx │ │ │ │ │ + * {RegExp} │ │ │ │ │ */ │ │ │ │ │ - tileFullExtent: null, │ │ │ │ │ + quotaRegEx: (/quota/i), │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: formatSuffix │ │ │ │ │ - * {String} For REST request encoding, an image format suffix must be │ │ │ │ │ - * included in the request. If not provided, the suffix will be derived │ │ │ │ │ - * from the property. │ │ │ │ │ + * Constructor: OpenLayers.Control.CacheWrite │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * options - {Object} Object with API properties for this control. │ │ │ │ │ */ │ │ │ │ │ - formatSuffix: null, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * APIProperty: matrixIds │ │ │ │ │ - * {Array} A list of tile matrix identifiers. If not provided, the matrix │ │ │ │ │ - * identifiers will be assumed to be integers corresponding to the │ │ │ │ │ - * map zoom level. If a list of strings is provided, each item should │ │ │ │ │ - * be the matrix identifier that corresponds to the map zoom level. │ │ │ │ │ - * Additionally, a list of objects can be provided. Each object should │ │ │ │ │ - * describe the matrix as presented in the WMTS capabilities. These │ │ │ │ │ - * objects should have the propertes shown below. │ │ │ │ │ + /** │ │ │ │ │ + * Method: setMap │ │ │ │ │ + * Set the map property for the control. │ │ │ │ │ * │ │ │ │ │ - * Matrix properties: │ │ │ │ │ - * identifier - {String} The matrix identifier (required). │ │ │ │ │ - * scaleDenominator - {Number} The matrix scale denominator. │ │ │ │ │ - * topLeftCorner - {} The top left corner of the │ │ │ │ │ - * matrix. Must be provided if different than the layer . │ │ │ │ │ - * tileWidth - {Number} The tile width for the matrix. Must be provided │ │ │ │ │ - * if different than the width given in the layer . │ │ │ │ │ - * tileHeight - {Number} The tile height for the matrix. Must be provided │ │ │ │ │ - * if different than the height given in the layer . │ │ │ │ │ + * Parameters: │ │ │ │ │ + * map - {} │ │ │ │ │ */ │ │ │ │ │ - matrixIds: null, │ │ │ │ │ + setMap: function(map) { │ │ │ │ │ + OpenLayers.Control.prototype.setMap.apply(this, arguments); │ │ │ │ │ + var i, layers = this.layers || map.layers; │ │ │ │ │ + for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ + this.addLayer({ │ │ │ │ │ + layer: layers[i] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + if (!this.layers) { │ │ │ │ │ + map.events.on({ │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + removeLayer: this.removeLayer, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: dimensions │ │ │ │ │ - * {Array} For RESTful request encoding, extra dimensions may be specified. │ │ │ │ │ - * Items in this list should be property names in the object. │ │ │ │ │ - * Values of extra dimensions will be determined from the corresponding │ │ │ │ │ - * values in the object. │ │ │ │ │ + * Method: addLayer │ │ │ │ │ + * Adds a layer to the control. Once added, tiles requested for this layer │ │ │ │ │ + * will be cached. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Object with a layer property referencing an │ │ │ │ │ + * instance │ │ │ │ │ */ │ │ │ │ │ - dimensions: null, │ │ │ │ │ + addLayer: function(evt) { │ │ │ │ │ + evt.layer.events.on({ │ │ │ │ │ + tileloadstart: this.makeSameOrigin, │ │ │ │ │ + tileloaded: this.onTileLoaded, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: params │ │ │ │ │ - * {Object} Extra parameters to include in tile requests. For KVP │ │ │ │ │ - * , these properties will be encoded in the request │ │ │ │ │ - * query string. For REST , these properties will │ │ │ │ │ - * become part of the request path, with order determined by the │ │ │ │ │ - * list. │ │ │ │ │ + * Method: removeLayer │ │ │ │ │ + * Removes a layer from the control. Once removed, tiles requested for this │ │ │ │ │ + * layer will no longer be cached. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Object} Object with a layer property referencing an │ │ │ │ │ + * instance │ │ │ │ │ */ │ │ │ │ │ - params: null, │ │ │ │ │ + removeLayer: function(evt) { │ │ │ │ │ + evt.layer.events.un({ │ │ │ │ │ + tileloadstart: this.makeSameOrigin, │ │ │ │ │ + tileloaded: this.onTileLoaded, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: zoomOffset │ │ │ │ │ - * {Number} If your cache has more levels than you want to provide │ │ │ │ │ - * access to with this layer, supply a zoomOffset. This zoom offset │ │ │ │ │ - * is added to the current map zoom level to determine the level │ │ │ │ │ - * for a requested tile. For example, if you supply a zoomOffset │ │ │ │ │ - * of 3, when the map is at the zoom 0, tiles will be requested from │ │ │ │ │ - * level 3 of your cache. Default is 0 (assumes cache level and map │ │ │ │ │ - * zoom are equivalent). Additionally, if this layer is to be used │ │ │ │ │ - * as an overlay and the cache has fewer zoom levels than the base │ │ │ │ │ - * layer, you can supply a negative zoomOffset. For example, if a │ │ │ │ │ - * map zoom level of 1 corresponds to your cache level zero, you would │ │ │ │ │ - * supply a -1 zoomOffset (and set the maxResolution of the layer │ │ │ │ │ - * appropriately). The zoomOffset value has no effect if complete │ │ │ │ │ - * matrix definitions (including scaleDenominator) are supplied in │ │ │ │ │ - * the property. Defaults to 0 (no zoom offset). │ │ │ │ │ + * Method: makeSameOrigin │ │ │ │ │ + * If the tile does not have CORS image loading enabled and is from a │ │ │ │ │ + * different origin, use OpenLayers.ProxyHost to make it a same origin url. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {} │ │ │ │ │ */ │ │ │ │ │ - zoomOffset: 0, │ │ │ │ │ + makeSameOrigin: function(evt) { │ │ │ │ │ + if (this.active) { │ │ │ │ │ + var tile = evt.tile; │ │ │ │ │ + if (tile instanceof OpenLayers.Tile.Image && │ │ │ │ │ + !tile.crossOriginKeyword && │ │ │ │ │ + tile.url.substr(0, 5) !== "data:") { │ │ │ │ │ + var sameOriginUrl = OpenLayers.Request.makeSameOrigin( │ │ │ │ │ + tile.url, OpenLayers.ProxyHost │ │ │ │ │ + ); │ │ │ │ │ + OpenLayers.Control.CacheWrite.urlMap[sameOriginUrl] = tile.url; │ │ │ │ │ + tile.url = sameOriginUrl; │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * APIProperty: serverResolutions │ │ │ │ │ - * {Array} A list of all resolutions available on the server. Only set this │ │ │ │ │ - * property if the map resolutions differ from the server. This │ │ │ │ │ - * property serves two purposes. (a) can include │ │ │ │ │ - * resolutions that the server supports and that you don't want to │ │ │ │ │ - * provide with this layer; you can also look at , which is │ │ │ │ │ - * an alternative to for that specific purpose. │ │ │ │ │ - * (b) The map can work with resolutions that aren't supported by │ │ │ │ │ - * the server, i.e. that aren't in . When the │ │ │ │ │ - * map is displayed in such a resolution data for the closest │ │ │ │ │ - * server-supported resolution is loaded and the layer div is │ │ │ │ │ - * stretched as necessary. │ │ │ │ │ + * Method: onTileLoaded │ │ │ │ │ + * Decides whether a tile can be cached and calls the cache method. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * evt - {Event} │ │ │ │ │ */ │ │ │ │ │ - serverResolutions: null, │ │ │ │ │ + onTileLoaded: function(evt) { │ │ │ │ │ + if (this.active && !evt.aborted && │ │ │ │ │ + evt.tile instanceof OpenLayers.Tile.Image && │ │ │ │ │ + evt.tile.url.substr(0, 5) !== 'data:') { │ │ │ │ │ + this.cache({ │ │ │ │ │ + tile: evt.tile │ │ │ │ │ + }); │ │ │ │ │ + delete OpenLayers.Control.CacheWrite.urlMap[evt.tile.url]; │ │ │ │ │ + } │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: formatSuffixMap │ │ │ │ │ - * {Object} a map between WMTS 'format' request parameter and tile image file suffix │ │ │ │ │ + * Method: cache │ │ │ │ │ + * Adds a tile to the cache. When the cache is full, the "cachefull" event │ │ │ │ │ + * is triggered. │ │ │ │ │ + * │ │ │ │ │ + * Parameters: │ │ │ │ │ + * obj - {Object} Object with a tile property, tile being the │ │ │ │ │ + * with the data to add to the cache │ │ │ │ │ */ │ │ │ │ │ - formatSuffixMap: { │ │ │ │ │ - "image/png": "png", │ │ │ │ │ - "image/png8": "png", │ │ │ │ │ - "image/png24": "png", │ │ │ │ │ - "image/png32": "png", │ │ │ │ │ - "png": "png", │ │ │ │ │ - "image/jpeg": "jpg", │ │ │ │ │ - "image/jpg": "jpg", │ │ │ │ │ - "jpeg": "jpg", │ │ │ │ │ - "jpg": "jpg" │ │ │ │ │ + cache: function(obj) { │ │ │ │ │ + if (window.localStorage) { │ │ │ │ │ + var tile = obj.tile; │ │ │ │ │ + try { │ │ │ │ │ + var canvasContext = tile.getCanvasContext(); │ │ │ │ │ + if (canvasContext) { │ │ │ │ │ + var urlMap = OpenLayers.Control.CacheWrite.urlMap; │ │ │ │ │ + var url = urlMap[tile.url] || tile.url; │ │ │ │ │ + window.localStorage.setItem( │ │ │ │ │ + "olCache_" + url, │ │ │ │ │ + canvasContext.canvas.toDataURL(this.imageFormat) │ │ │ │ │ + ); │ │ │ │ │ + } │ │ │ │ │ + } catch (e) { │ │ │ │ │ + // local storage full or CORS violation │ │ │ │ │ + var reason = e.name || e.message; │ │ │ │ │ + if (reason && this.quotaRegEx.test(reason)) { │ │ │ │ │ + this.events.triggerEvent("cachefull", { │ │ │ │ │ + tile: tile │ │ │ │ │ + }); │ │ │ │ │ + } else { │ │ │ │ │ + OpenLayers.Console.error(e.toString()); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ }, │ │ │ │ │ │ │ │ │ │ /** │ │ │ │ │ - * Property: matrix │ │ │ │ │ - * {Object} Matrix definition for the current map resolution. Updated by │ │ │ │ │ - * the method. │ │ │ │ │ + * Method: destroy │ │ │ │ │ + * The destroy method is used to perform any clean up before the control │ │ │ │ │ + * is dereferenced. Typically this is where event listeners are removed │ │ │ │ │ + * to prevent memory leaks. │ │ │ │ │ */ │ │ │ │ │ - matrix: null, │ │ │ │ │ + destroy: function() { │ │ │ │ │ + if (this.layers || this.map) { │ │ │ │ │ + var i, layers = this.layers || this.map.layers; │ │ │ │ │ + for (i = layers.length - 1; i >= 0; --i) { │ │ │ │ │ + this.removeLayer({ │ │ │ │ │ + layer: layers[i] │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + } │ │ │ │ │ + if (this.map) { │ │ │ │ │ + this.map.events.un({ │ │ │ │ │ + addlayer: this.addLayer, │ │ │ │ │ + removeLayer: this.removeLayer, │ │ │ │ │ + scope: this │ │ │ │ │ + }); │ │ │ │ │ + } │ │ │ │ │ + OpenLayers.Control.prototype.destroy.apply(this, arguments); │ │ │ │ │ + }, │ │ │ │ │ │ │ │ │ │ - /** │ │ │ │ │ - * Constructor: OpenLayers.Layer.WMTS │ │ │ │ │ - * Create a new WMTS layer. │ │ │ │ │ - * │ │ │ │ │ - * Example: │ │ │ │ │ - * (code) │ │ │ │ │ - * var wmts = new OpenLayers.Layer.WMTS({ │ │ │ │ │ - * name: "My WMTS Layer", │ │ │ │ │ - * url: "http://example.com/wmts", │ │ │ │ │ - * layer: "layer_id", │ │ │ │ │ - * style: "default", │ │ │ │ │ - * matrixSet: "matrix_id" │ │ │ │ │ - * }); │ │ │ │ │ - * (end) │ │ │ │ │ - * │ │ │ │ │ - * Parameters: │ │ │ │ │ - * config - {Object} Configuration properties for the layer. │ │ │ │ │ - * │ │ │ │ │ - * Required configuration properties: │ │ │ │ │ - * url - {String} The base url for the service. See the property. │ │ │ │ │ - * layer - {String} The layer identifier. See the property. │ │ │ │ │ - * style - {String} The layer style identifier. See the