├── .gitignore ├── CHANGELOG.md ├── LICENSE.txt ├── README.md ├── doc ├── DynamicMeasure │ ├── all │ │ ├── _config │ │ │ ├── Languages.txt │ │ │ ├── Menu.txt │ │ │ └── Topics.txt │ │ ├── files │ │ │ └── DynamicMeasure-js.html │ │ ├── index.html │ │ ├── javascript │ │ │ ├── main.js │ │ │ ├── prettify.js │ │ │ └── searchdata.js │ │ ├── search │ │ │ └── NoResults.html │ │ └── styles │ │ │ ├── 1.css │ │ │ ├── 2.css │ │ │ └── main.css │ ├── api │ │ ├── _config │ │ │ ├── Languages.txt │ │ │ ├── Menu.txt │ │ │ └── Topics.txt │ │ ├── files │ │ │ └── DynamicMeasure-js.html │ │ ├── index.html │ │ ├── javascript │ │ │ ├── main.js │ │ │ ├── prettify.js │ │ │ └── searchdata.js │ │ ├── search │ │ │ └── NoResults.html │ │ └── styles │ │ │ ├── 1.css │ │ │ ├── 2.css │ │ │ └── main.css │ └── index.html └── _scripts │ ├── documentation.cmd │ ├── documentation.sh │ └── jorix.css ├── examples ├── measure-and-draw.html ├── measure-and-draw.js ├── measure-and-keep.html ├── measure-and-keep.js ├── measure-dynamic-dev.html ├── measure-dynamic.html └── measure-dynamic.js └── lib └── OpenLayers └── Control └── DynamicMeasure.js /.gitignore: -------------------------------------------------------------------------------- 1 | /tools 2 | /build 3 | /doc/_scripts/NaturalDocs.bat 4 | /doc/DynamicMeasure/all/_config/Data 5 | /doc/DynamicMeasure/api/_config/Data 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | Development code that is considered stable in the is in the *gh-pages* branch (note that *master* branch does not exist) 5 | 6 | 7 | On development 8 | -------------- 9 | 10 | (open for suggestions) 11 | 12 | 13 | [v1.2.2](https://github.com/jorix/OL-DynamicMeasure/tree/v1.2.2) 14 | ---------------------------------------------------------------- 15 | 16 | #### Improvements 17 | * Allows persistent annotations after measurement ([pull #9](https://github.com/jorix/OL-DynamicMeasure/pull/9)) 18 | 19 | #### Bugs 20 | * Fix: Overriding labels problem ([issue #7](https://github.com/jorix/OL-DynamicMeasure/issues/7)) 21 | * Fix problems in examples. 22 | 23 | 24 | [v1.2.1](https://github.com/jorix/OL-DynamicMeasure/tree/v1.2.1) 25 | ---------------------------------------------------------------- 26 | 27 | #### Bugs 28 | * When the map is panned elements (labels or lines) may not be displayed ([issue #4](https://github.com/jorix/OL-DynamicMeasure/pull/4)) 29 | 30 | 31 | [v1.2.0](https://github.com/jorix/OL-DynamicMeasure/tree/v1.2.0) 32 | ---------------------------------------------------------------- 33 | 34 | #### Improvements 35 | * Show bearing/heading of the segments. 36 | * Allows customize label positions. 37 | 38 | 39 | [v1.1.0](https://github.com/jorix/OL-DynamicMeasure/tree/v1.1.0) 40 | ---------------------------------------------------------------- 41 | 42 | #### Improvements 43 | * Add `maxSegments` option and set default to 1. 44 | * Allows measure and draw. Added `drawingLayer` and `multi` options. 45 | 46 | #### Bugs 47 | * Fix a mistake on a example to show and hide measurements in *measure-dynamic.html*. 48 | 49 | 50 | [v1.0.0](https://github.com/jorix/OL-DynamicMeasure/tree/v1.0.0) 51 | ---------------------------------------------------------------- 52 | 53 | #### Improvements 54 | * Allows to use functions `undo` & `redo` of drawing handlers. 55 | 56 | 57 | [v0.9.0](https://github.com/jorix/OL-DynamicMeasure/tree/v1.0.0) 58 | ---------------------------------------------------------------- 59 | 60 | #### Improvements 61 | * Make `DynamicMeasure` a control. 62 | * Display areas measurement (in the center of the polygon) 63 | 64 | #### Bugs 65 | * Fix issue #1 on deactivate method. 66 | 67 | 68 | [v0.1.0](https://github.com/jorix/OL-DynamicMeasure/tree/v0.1.0) 69 | ---------------------------------------------------------------- 70 | 71 | * Initial code, but is not a control. 72 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2018 Xavier Mamano, http://github.com/jorix/OL-DynamicMeasure 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Control for OpenLayers to measure and shows measurements at the cursor 2 | ====================================================================== 3 | 4 | Based on `OpenLayers.Control.Measure`, the **DynamicMeasure** control shows 5 | measurements on labels that follow the cursor. This avoids having to worry 6 | about preparing a DOM item to display measurements. 7 | 8 | The control also has preset styles to show lines and labels, so the only thing 9 | to do is add it to the map. 10 | 11 | Control allows displaying lengths and headings of the segments that form a polyline or a polygon. 12 | 13 | Examples: 14 | --------- 15 | * [measure-dynamic.html](http://jorix.github.com/OL-DynamicMeasure/examples/measure-dynamic.html) (adapted from "measure.html" OpenLayers example) 16 | 17 | Operation: 18 | --------- 19 | 20 | Example: 21 | 22 | ```javascript 23 | ... 24 | // to mesure length 25 | var cMeasure = new OpenLayers.Control.DynamicMeasure(OpenLayers.Handler.Path); 26 | map.addControl(cMeasure); 27 | ... 28 | // ... and to start measuring 29 | cMeasure.activate(); 30 | ... 31 | // ... and to stop it 32 | cMeasure.deactivate(); 33 | ... 34 | ``` 35 | 36 | This control is now adapted to handle the methods *undo* *redo* and *cancel* of drawing handlers. 37 | 38 | See the example [measure-dynamic-dev.html](http://jorix.github.com/OL-DynamicMeasure/examples/measure-dynamic-dev.html) (allows choose whether to use the patch posted on [OL-Ragbag](https://github.com/jorix/OL-Ragbag/blob/gh-pages/README.md#the-components)) 39 | 40 | The control can use it as a `DrawFeature` control, see example [measure-and-draw.html](http://jorix.github.com/OL-DynamicMeasure/examples/measure-and-draw.html) 41 | 42 | Measure annotations are shown for the current measurement by default. They can be keeped for all measures using the `keep` property, see example [measure-and-keep.html](http://jorix.github.com/OL-DynamicMeasure/examples/measure-and-keep.html) 43 | 44 | Documentation: 45 | -------------- 46 | * [API for users](http://jorix.github.com/OL-DynamicMeasure/doc/DynamicMeasure/api) 47 | * For developers 48 | * [all `DynamicMeasure` elements](http://jorix.github.com/OL-DynamicMeasure/doc/DynamicMeasure/all) 49 | 50 | Compatibility with OpenLayers releases: 51 | --------------------------------------- 52 | The `DynamicMeasure` control works correctly with release 2.11 or higher 53 | including the development version. 54 | 55 | Background 56 | ---------- 57 | According [**Yus's question in DEV**](http://osgeo-org.1803224.n2.nabble.com/Adding-Segment-Length-to-Path-tc7029815.html) 58 | some adjustments are made to solve some problems: 59 | labels do not remain at the end of measure, 60 | using the freehand the map is dirtied by the labels, 61 | layer of the labels (`vlayer`) should be on top of the drawing layer, 62 | allow use of immediate measure (new in 2.11) 63 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/_config/Languages.txt: -------------------------------------------------------------------------------- 1 | Format: 1.52 2 | 3 | # This is the Natural Docs languages file for this project. If you change 4 | # anything here, it will apply to THIS PROJECT ONLY. If you'd like to change 5 | # something for all your projects, edit the Languages.txt in Natural Docs' 6 | # Config directory instead. 7 | 8 | 9 | # You can prevent certain file extensions from being scanned like this: 10 | # Ignore Extensions: [extension] [extension] ... 11 | 12 | 13 | #------------------------------------------------------------------------------- 14 | # SYNTAX: 15 | # 16 | # Unlike other Natural Docs configuration files, in this file all comments 17 | # MUST be alone on a line. Some languages deal with the # character, so you 18 | # cannot put comments on the same line as content. 19 | # 20 | # Also, all lists are separated with spaces, not commas, again because some 21 | # languages may need to use them. 22 | # 23 | # Language: [name] 24 | # Alter Language: [name] 25 | # Defines a new language or alters an existing one. Its name can use any 26 | # characters. If any of the properties below have an add/replace form, you 27 | # must use that when using Alter Language. 28 | # 29 | # The language Shebang Script is special. It's entry is only used for 30 | # extensions, and files with those extensions have their shebang (#!) lines 31 | # read to determine the real language of the file. Extensionless files are 32 | # always treated this way. 33 | # 34 | # The language Text File is also special. It's treated as one big comment 35 | # so you can put Natural Docs content in them without special symbols. Also, 36 | # if you don't specify a package separator, ignored prefixes, or enum value 37 | # behavior, it will copy those settings from the language that is used most 38 | # in the source tree. 39 | # 40 | # Extensions: [extension] [extension] ... 41 | # [Add/Replace] Extensions: [extension] [extension] ... 42 | # Defines the file extensions of the language's source files. You can 43 | # redefine extensions found in the main languages file. You can use * to 44 | # mean any undefined extension. 45 | # 46 | # Shebang Strings: [string] [string] ... 47 | # [Add/Replace] Shebang Strings: [string] [string] ... 48 | # Defines a list of strings that can appear in the shebang (#!) line to 49 | # designate that it's part of the language. You can redefine strings found 50 | # in the main languages file. 51 | # 52 | # Ignore Prefixes in Index: [prefix] [prefix] ... 53 | # [Add/Replace] Ignored Prefixes in Index: [prefix] [prefix] ... 54 | # 55 | # Ignore [Topic Type] Prefixes in Index: [prefix] [prefix] ... 56 | # [Add/Replace] Ignored [Topic Type] Prefixes in Index: [prefix] [prefix] ... 57 | # Specifies prefixes that should be ignored when sorting symbols in an 58 | # index. Can be specified in general or for a specific topic type. 59 | # 60 | #------------------------------------------------------------------------------ 61 | # For basic language support only: 62 | # 63 | # Line Comments: [symbol] [symbol] ... 64 | # Defines a space-separated list of symbols that are used for line comments, 65 | # if any. 66 | # 67 | # Block Comments: [opening sym] [closing sym] [opening sym] [closing sym] ... 68 | # Defines a space-separated list of symbol pairs that are used for block 69 | # comments, if any. 70 | # 71 | # Package Separator: [symbol] 72 | # Defines the default package separator symbol. The default is a dot. 73 | # 74 | # [Topic Type] Prototype Enders: [symbol] [symbol] ... 75 | # When defined, Natural Docs will attempt to get a prototype from the code 76 | # immediately following the topic type. It stops when it reaches one of 77 | # these symbols. Use \n for line breaks. 78 | # 79 | # Line Extender: [symbol] 80 | # Defines the symbol that allows a prototype to span multiple lines if 81 | # normally a line break would end it. 82 | # 83 | # Enum Values: [global|under type|under parent] 84 | # Defines how enum values are referenced. The default is global. 85 | # global - Values are always global, referenced as 'value'. 86 | # under type - Values are under the enum type, referenced as 87 | # 'package.enum.value'. 88 | # under parent - Values are under the enum's parent, referenced as 89 | # 'package.value'. 90 | # 91 | # Perl Package: [perl package] 92 | # Specifies the Perl package used to fine-tune the language behavior in ways 93 | # too complex to do in this file. 94 | # 95 | #------------------------------------------------------------------------------ 96 | # For full language support only: 97 | # 98 | # Full Language Support: [perl package] 99 | # Specifies the Perl package that has the parsing routines necessary for full 100 | # language support. 101 | # 102 | #------------------------------------------------------------------------------- 103 | 104 | # The following languages are defined in the main file, if you'd like to alter 105 | # them: 106 | # 107 | # Text File, Shebang Script, C/C++, C#, Java, JavaScript, Perl, Python, 108 | # PHP, SQL, Visual Basic, Pascal, Assembly, Ada, Tcl, Ruby, Makefile, 109 | # ActionScript, ColdFusion, R, Fortran 110 | 111 | # If you add a language that you think would be useful to other developers 112 | # and should be included in Natural Docs by default, please e-mail it to 113 | # languages [at] naturaldocs [dot] org. 114 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/_config/Menu.txt: -------------------------------------------------------------------------------- 1 | Format: 1.52 2 | 3 | 4 | Title: Dynamic Measure 5 | SubTitle: Compatible with OpenLayers from 2.11 to 2.13 & dev 6 | 7 | Footer: View on github.com/jorixView on GitHub 8 | 9 | # You can add a timestamp to your documentation like one of these: 10 | # Timestamp: Generated on month day, year 11 | # Timestamp: Updated mm/dd/yyyy 12 | # Timestamp: Last updated mon day 13 | # 14 | # m - One or two digit month. January is "1" 15 | # mm - Always two digit month. January is "01" 16 | # mon - Short month word. January is "Jan" 17 | # month - Long month word. January is "January" 18 | # d - One or two digit day. 1 is "1" 19 | # dd - Always two digit day. 1 is "01" 20 | # day - Day with letter extension. 1 is "1st" 21 | # yy - Two digit year. 2006 is "06" 22 | # yyyy - Four digit year. 2006 is "2006" 23 | # year - Four digit year. 2006 is "2006" 24 | 25 | # These are indexes you deleted, so Natural Docs will not add them again 26 | # unless you remove them from this line. 27 | 28 | Don't Index: Classes, Constructor, Files, Functions, General, Constants, Properties 29 | 30 | 31 | # -------------------------------------------------------------------------- 32 | # 33 | # Cut and paste the lines below to change the order in which your files 34 | # appear on the menu. Don't worry about adding or removing files, Natural 35 | # Docs will take care of that. 36 | # 37 | # You can further organize the menu by grouping the entries. Add a 38 | # "Group: [name] {" line to start a group, and add a "}" to end it. 39 | # 40 | # You can add text and web links to the menu by adding "Text: [text]" and 41 | # "Link: [name] ([URL])" lines, respectively. 42 | # 43 | # The formatting and comments are auto-generated, so don't worry about 44 | # neatness when editing the file. Natural Docs will clean it up the next 45 | # time it is run. When working with groups, just deal with the braces and 46 | # forget about the indentation and comments. 47 | # 48 | # -------------------------------------------------------------------------- 49 | 50 | 51 | File: DynamicMeasure (DynamicMeasure.js) 52 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/_config/Topics.txt: -------------------------------------------------------------------------------- 1 | Format: 1.52 2 | 3 | # This is the Natural Docs topics file for this project. If you change anything 4 | # here, it will apply to THIS PROJECT ONLY. If you'd like to change something 5 | # for all your projects, edit the Topics.txt in Natural Docs' Config directory 6 | # instead. 7 | 8 | 9 | # If you'd like to prevent keywords from being recognized by Natural Docs, you 10 | # can do it like this: 11 | # Ignore Keywords: [keyword], [keyword], ... 12 | # 13 | # Or you can use the list syntax like how they are defined: 14 | # Ignore Keywords: 15 | # [keyword] 16 | # [keyword], [plural keyword] 17 | # ... 18 | 19 | 20 | #------------------------------------------------------------------------------- 21 | # SYNTAX: 22 | # 23 | # Topic Type: [name] 24 | # Alter Topic Type: [name] 25 | # Creates a new topic type or alters one from the main file. Each type gets 26 | # its own index and behavior settings. Its name can have letters, numbers, 27 | # spaces, and these charaters: - / . ' 28 | # 29 | # Plural: [name] 30 | # Sets the plural name of the topic type, if different. 31 | # 32 | # Keywords: 33 | # [keyword] 34 | # [keyword], [plural keyword] 35 | # ... 36 | # Defines or adds to the list of keywords for the topic type. They may only 37 | # contain letters, numbers, and spaces and are not case sensitive. Plural 38 | # keywords are used for list topics. You can redefine keywords found in the 39 | # main topics file. 40 | # 41 | # Index: [yes|no] 42 | # Whether the topics get their own index. Defaults to yes. Everything is 43 | # included in the general index regardless of this setting. 44 | # 45 | # Scope: [normal|start|end|always global] 46 | # How the topics affects scope. Defaults to normal. 47 | # normal - Topics stay within the current scope. 48 | # start - Topics start a new scope for all the topics beneath it, 49 | # like class topics. 50 | # end - Topics reset the scope back to global for all the topics 51 | # beneath it. 52 | # always global - Topics are defined as global, but do not change the scope 53 | # for any other topics. 54 | # 55 | # Class Hierarchy: [yes|no] 56 | # Whether the topics are part of the class hierarchy. Defaults to no. 57 | # 58 | # Page Title If First: [yes|no] 59 | # Whether the topic's title becomes the page title if it's the first one in 60 | # a file. Defaults to no. 61 | # 62 | # Break Lists: [yes|no] 63 | # Whether list topics should be broken into individual topics in the output. 64 | # Defaults to no. 65 | # 66 | # Can Group With: [type], [type], ... 67 | # Defines a list of topic types that this one can possibly be grouped with. 68 | # Defaults to none. 69 | #------------------------------------------------------------------------------- 70 | 71 | # The following topics are defined in the main file, if you'd like to alter 72 | # their behavior or add keywords: 73 | # 74 | # Generic, Class, Interface, Section, File, Group, Function, Variable, 75 | # Property, Type, Constant, Enumeration, Event, Delegate, Macro, 76 | # Database, Database Table, Database View, Database Index, Database 77 | # Cursor, Database Trigger, Cookie, Build Target 78 | 79 | # If you add something that you think would be useful to other developers 80 | # and should be included in Natural Docs by default, please e-mail it to 81 | # topics [at] naturaldocs [dot] org. 82 | 83 | 84 | Topic Type: Constructor 85 | 86 | Class Hierarchy: Yes 87 | Keywords: 88 | constructor 89 | initialize 90 | 91 | 92 | Alter Topic Type: Function 93 | 94 | Add Keywords: 95 | apimethod 96 | apifunction 97 | 98 | 99 | Alter Topic Type: Property 100 | 101 | Add Keywords: 102 | apiproperty 103 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/files/DynamicMeasure-js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | OpenLayers.Control.DynamicMeasure - Dynamic Measure 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

OpenLayers.Control.DynamicMeasure

Allows for drawing of features for measurements.

Inherits from

Summary
OpenLayers.Control.DynamicMeasureAllows for drawing of features for measurements.
Properties
accuracy{Integer} Digits measurement accuracy, default is 5.
persist{Boolean} Keep the temporary measurement after the measurement is complete.
styles{Object} Alterations of the default styles of the points lines poligons and labels text, could use keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelHeading”, “labelLength” and “labelArea”.
positions{Object} Alterations of the default position of the labels, could use keys: “labelSegments” & “labelHeading”, with values “start” “middle” and “end” refered of the current segment; and keys: “labelLength” & “labelArea” with additional values “center” (of the feature) and “initial” (initial point of the feature) and also mentioned previus values.
maxSegments{Integer|Null} Maximum number of visible segments measures, default is 1.
maxHeadings{Integer|Null} Maximum number of visible headings measures, default is 1.
layerSegmentsOptions{Object} Any optional properties to be set on the layer of layerSegments of the lengths of the segments.
layerHeadingOptions{Object} Any optional properties to be set on the layer of <layerHeading> of the angle of the segments.
layerLengthOptions{Object} Any optional properties to be set on the layer of layerLength of the total length.
layerAreaOptions{Object} Any optional properties to be set on the layer of layerArea of the total area.
drawingLayer{<OpenLayers.Layer.Vector>} Drawing layer to store the drawing when finished.
multi{Boolean} Cast features to multi-part geometries before passing to the drawing layer, only used if declared a drawingLayer.
keep{Boolean} Keep annotations for every measures.
layerSegments{<OpenLayers.Layer.Vector>} The temporary drawing layer to show the length of the segments.
layerLength{<OpenLayers.Layer.Vector>} The temporary drawing layer to show total length.
layerArea{<OpenLayers.Layer.Vector>} The temporary drawing layer to show total area.
layerSegmentsKeep{<OpenLayers.Layer.Vector>} The layer keep a copy of the length of every segments measured since tool activation.
layersLengthKeep{<OpenLayers.Layer.Vector>} The layer keep a copy of the length of every polyline/poly measured since tool activation.
layerAreaKeep{<OpenLayers.Layer.Vector>} The layer keep a copy of the area of every polygon
dynamicObj{Object} Internal use.
isArea{Boolean} Internal use.
Constructor
OpenLayers.Control.Measure
Functions
destroy
drawThis control does not have HTML component, so this method should be empty.
activate
deactivate
emptyKeepedRemove annotations from layers layerSegmentsKeep, layerLengthKeep, layerAreaKeep.
setImmediateSets the <immediate> property.
callbackCreate
callbackCancel
callbackDoneCalled when the measurement sketch is done.
drawFeature
copyAnnotations
callbackCancel
callbackPoint
callbackUndo
callbackRedo
callbackModify
showLabelSegmentlabelsNumber- {Integer} Number of the labels to be on the label layer.
showLabel
setMesureAttributesFormat measure[0] with digits of accuracy.
Constants
OpenLayers.Control.DynamicMeasure.stylesContains the keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a objects with style keys.
OpenLayers.Control.DynamicMeasure.positionsContains the keys: “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a strings with values ‘start’, ‘middle’ and ‘end’ allowed for all keys (refered of last segment) and ‘center’ and ‘initial’ (refered of the measured feature and only allowed for “labelLength” and “labelArea” keys)
15 | 16 |

Properties

17 | 18 |

accuracy

{Integer} Digits measurement accuracy, default is 5.

19 | 20 |

persist

{Boolean} Keep the temporary measurement after the measurement is complete.  The measurement will persist until a new measurement is started, the control is deactivated, or <cancel> is called.  Default is true.

21 | 22 |

styles

{Object} Alterations of the default styles of the points lines poligons and labels text, could use keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelHeading”, “labelLength” and “labelArea”.  Default is OpenLayers.Control.DynamicMeasure.styles.

23 | 24 |

positions

{Object} Alterations of the default position of the labels, could use keys: “labelSegments” & “labelHeading”, with values “start” “middle” and “end” refered of the current segment; and keys: “labelLength” & “labelArea” with additional values “center” (of the feature) and “initial” (initial point of the feature) and also mentioned previus values.  Default is OpenLayers.Control.DynamicMeasure.positions.

25 | 26 |

maxSegments

{Integer|Null} Maximum number of visible segments measures, default is 1.

To avoid soiling the track is desirable to reduce the number of visible segments.

27 | 28 |

maxHeadings

{Integer|Null} Maximum number of visible headings measures, default is 1.

To avoid soiling the track is desirable to reduce the number of visible segments.

29 | 30 |

layerSegmentsOptions

{Object} Any optional properties to be set on the layer of layerSegments of the lengths of the segments.  If set to null the layer does not act.

If `styleMap` options is set then the key “labelSegments” of the `styles` option is ignored.

31 | 32 |

layerHeadingOptions

{Object} Any optional properties to be set on the layer of <layerHeading> of the angle of the segments.  If set to null the layer does not act.  Default is null, set to {} to use a <layerHeading> to show headings.

If `styleMap` options is set then the key “labelHeading” of the `styles` option is ignored.

33 | 34 |

layerLengthOptions

{Object} Any optional properties to be set on the layer of layerLength of the total length.  If set to null the layer does not act.

If `styleMap` option is set then the key “labelLength” of the `styles` option is ignored.

35 | 36 |

layerAreaOptions

{Object} Any optional properties to be set on the layer of layerArea of the total area.  If set to null the layer does not act.

If `styleMap` is set then the key “labelArea” of the `styles` option is ignored.

37 | 38 |

drawingLayer

{<OpenLayers.Layer.Vector>} Drawing layer to store the drawing when finished.

39 | 40 |

multi

{Boolean} Cast features to multi-part geometries before passing to the drawing layer, only used if declared a drawingLayer.  Default is false.

41 | 42 |

keep

{Boolean} Keep annotations for every measures.

43 | 44 |

layerSegments

{<OpenLayers.Layer.Vector>} The temporary drawing layer to show the length of the segments.

45 | 46 |

layerLength

{<OpenLayers.Layer.Vector>} The temporary drawing layer to show total length.

47 | 48 |

layerArea

{<OpenLayers.Layer.Vector>} The temporary drawing layer to show total area.

49 | 50 |

layerSegmentsKeep

{<OpenLayers.Layer.Vector>} The layer keep a copy of the length of every segments measured since tool activation.

51 | 52 |

layersLengthKeep

{<OpenLayers.Layer.Vector>} The layer keep a copy of the length of every polyline/poly measured since tool activation.

53 | 54 |

layerAreaKeep

{<OpenLayers.Layer.Vector>} The layer keep a copy of the area of every polygon

55 | 56 |

dynamicObj

{Object} Internal use.

57 | 58 |

isArea

{Boolean} Internal use.

59 | 60 |

Constructor

61 | 62 |

OpenLayers.Control.Measure

Parameters

handler{<OpenLayers.Handler>}
options{Object}

Valid options

accuracy{Integer} Digits measurement accuracy, default is 5.
styles{Object} Alterations of the default styles of the points lines poligons and labels text, could use keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelLength”, “labelArea”.
positions{Object} Alterations of the default position of the labels.
handlerOptions{Object} Used to set non-default properties on the control’s handler.  If `layerOptions[“styleMap”]` is set then the keys: “Point”, “Line” and “Polygon” of the `styles` option are ignored.
layerSegmentsOptions{Object} Any optional properties to be set on the layer of layerSegments of the lengths of the segments.  If `styleMap` is set then the key “labelSegments” of the `styles` option is ignored.  If set to null the layer does not act.
layerLengthOptions{Object} Any optional properties to be set on the layer of layerLength of the total length.  If `styleMap` is set then the key “labelLength” of the `styles` option is ignored.  If set to null the layer does not act.
layerAreaOptions{Object} Any optional properties to be set on the layer of layerArea of the total area.  If `styleMap` is set then the key “labelArea” of the `styles` option is ignored.  If set to null the layer does not act.
layerHeadingOptions{Object} Any optional properties to be set on the layer of <layerHeading> of the angle of the segments.  If `styleMap` is set then the key “labelHeading” of the `styles` option is ignored.  If set to null the layer does not act.
drawingLayer{<OpenLayers.Layer.Vector>} Optional drawing layer to store the drawing when finished.
multi{Boolean} Cast features to multi-part geometries before passing to the drawing layer
keep{Boolean} Keep annotations for every measures.
63 | 64 |

Functions

65 | 66 |

destroy

destroy: function()
67 | 68 |

draw

draw: function()

This control does not have HTML component, so this method should be empty.

69 | 70 |

activate

activate: function()
71 | 72 |

deactivate

deactivate: function()
73 | 74 |

emptyKeeped

emptyKeeped: function ()

Remove annotations from layers layerSegmentsKeep, layerLengthKeep, layerAreaKeep.

75 | 76 |

setImmediate

setImmediate: function(immediate)

Sets the <immediate> property.  Changes the activity of immediate measurement.

77 | 78 |

callbackCreate

callbackCreate: function()
79 | 80 |

callbackCancel

callbackCancel: function()
81 | 82 |

callbackDone

callbackDone: function(geometry)

Called when the measurement sketch is done.

Parameters

geometry{<OpenLayers.Geometry>}
83 | 84 |

drawFeature

drawFeature: function(geometry)
85 | 86 |

copyAnnotations

copyAnnotations: function()
87 | 88 |

callbackCancel

89 | 90 |

callbackPoint

callbackPoint: function(point,
geometry)
91 | 92 |

callbackUndo

callbackUndo: function(point,
feature)
93 | 94 |

callbackRedo

callbackRedo: function(point,
feature)
95 | 96 |

callbackModify

callbackModify: function(point,
feature,
drawing)
97 | 98 |

showLabelSegment

showLabelSegment: function(labelsNumber,
fromIndex,
_points)

Parameters

labelsNumber- {Integer} Number of the labels to be on the label layer. fromIndex - {Integer} Index of the last point on the measured feature. points - Array({<OpenLayers.Geometry.Point>})

Returns

{Boolean}

99 | 100 |

showLabel

showLabel: function(layer,
labelsNumber,
fromIndex,
measure,
xy,
maxSegments)

Parameters

layer{<OpenLayers.Layer.Vector>} Layer of the labels. labelsNumber- {Integer} Number of the labels to be on the label layer.
fromIndex{Integer} Index of the last point on the measured feature.
measureArray({Float|String}) Measure provided by OL Measure control.
pointsArray({Fload}) Array of x and y of the point to draw the label.
maxSegments{Integer|Null} Maximum number of visible segments measures

Returns

{Boolean}

101 | 102 |

setMesureAttributes

setMesureAttributes: function(attributes,
measure)

Format measure[0] with digits of accuracy.  Could internationalize the format customizing <OpenLayers.Number.thousandsSeparator> and <OpenLayers.Number.decimalSeparator>

Parameters

attributes{object} Target attributes.
measureArray({*})
103 | 104 |

Constants

105 | 106 |

OpenLayers.Control.DynamicMeasure.styles

Contains the keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a objects with style keys.

107 | 108 |

OpenLayers.Control.DynamicMeasure.positions

Contains the keys: “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a strings with values ‘start’, ‘middle’ and ‘end’ allowed for all keys (refered of last segment) and ‘center’ and ‘initial’ (refered of the measured feature and only allowed for “labelLength” and “labelArea” keys)

109 | 110 |
111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
{OpenLayers.Layer.Vector} The temporary drawing layer to show the length of the segments.
{OpenLayers.Layer.Vector} The temporary drawing layer to show total length.
{OpenLayers.Layer.Vector} The temporary drawing layer to show total area.
{OpenLayers.Layer.Vector} Drawing layer to store the drawing when finished.
destroy: function()
draw: function()
This control does not have HTML component, so this method should be empty.
activate: function()
deactivate: function()
emptyKeeped: function ()
Remove annotations from layers layerSegmentsKeep, layerLengthKeep, layerAreaKeep.
setImmediate: function(immediate)
Sets the immediate property.
callbackCreate: function()
callbackCancel: function()
callbackDone: function(geometry)
Called when the measurement sketch is done.
drawFeature: function(geometry)
copyAnnotations: function()
callbackPoint: function(point,
geometry)
callbackUndo: function(point,
feature)
callbackRedo: function(point,
feature)
callbackModify: function(point,
feature,
drawing)
showLabelSegment: function(labelsNumber,
fromIndex,
_points)
labelsNumber- {Integer} Number of the labels to be on the label layer.
showLabel: function(layer,
labelsNumber,
fromIndex,
measure,
xy,
maxSegments)
setMesureAttributes: function(attributes,
measure)
Format measure[0] with digits of accuracy.
{Integer} Digits measurement accuracy, default is 5.
Contains the keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a objects with style keys.
Contains the keys: “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a strings with values ‘start’, ‘middle’ and ‘end’ allowed for all keys (refered of last segment) and ‘center’ and ‘initial’ (refered of the measured feature and only allowed for “labelLength” and “labelArea” keys)
122 | 123 | 124 | 125 | 126 |
Close
127 | 128 | 129 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/javascript/main.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jorix/OL-DynamicMeasure/8e95983d7c2ee05e7db2affd0e091b743ef3e8d1/doc/DynamicMeasure/all/javascript/main.js -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/javascript/prettify.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jorix/OL-DynamicMeasure/8e95983d7c2ee05e7db2affd0e091b743ef3e8d1/doc/DynamicMeasure/all/javascript/prettify.js -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/javascript/searchdata.js: -------------------------------------------------------------------------------- 1 | var indexSectionsWithContent = { 2 | 3 | } -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/search/NoResults.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
No Matches
-------------------------------------------------------------------------------- /doc/DynamicMeasure/all/styles/1.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jorix/OL-DynamicMeasure/8e95983d7c2ee05e7db2affd0e091b743ef3e8d1/doc/DynamicMeasure/all/styles/1.css -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/styles/2.css: -------------------------------------------------------------------------------- 1 | p { 2 | text-indent: 0; margin-bottom: 1em; 3 | } 4 | 5 | .MGroup { 6 | font-variant: normal; 7 | margin: 0.4em 0 0em 10px 8 | } 9 | 10 | .MTitle { 11 | font-variant: normal; 12 | } 13 | 14 | .CGroup .CTitle { 15 | font-variant: normal; 16 | } 17 | 18 | .SGroup .SEntry { 19 | font-variant: normal; 20 | } 21 | 22 | .CClass .CTopic h2.CTitle, 23 | #MainTopic .CTitle { 24 | background-color: #ddd; 25 | color: #025; 26 | border-radius: 16px; 27 | border-width:0; 28 | margin: 5px; 29 | margin: 0 10px 5px 10px; 30 | box-shadow: 0 0 10px rgba(0,0,0,0.6); 31 | } 32 | #MainTopic .CTitle { 33 | padding-right: 150px; /* used by #forkme_banner */ 34 | border-top-right-radius: 0; 35 | border-top-left-radius: 0; 36 | } 37 | #forkme_banner { 38 | display: block; 39 | position: absolute; 40 | top: 3px; right: 13px; 41 | z-index: 10; 42 | padding: 5px 5px 5px 36px; 43 | color: #fff !important; 44 | background: url('http://github.com/themes/slate/images/blacktocat.png') #0090ff no-repeat 3px 50%; 45 | box-shadow: 0 0 10px rgba(0,0,0,0.5); 46 | border-radius: 16px; 47 | text-decoration: none; 48 | font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif; 49 | font-size: 16px; 50 | line-height: 24px; 51 | font-weight: bold; 52 | } 53 | a#forkme_banner:hover, 54 | a#forkme_banner:focus { 55 | background: url('http://github.com/themes/slate/images/blacktocat.png') #000000 no-repeat 3px 50%; 56 | } 57 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/all/styles/main.css: -------------------------------------------------------------------------------- 1 | @import URL("1.css"); 2 | @import URL("2.css"); 3 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/_config/Languages.txt: -------------------------------------------------------------------------------- 1 | Format: 1.52 2 | 3 | # This is the Natural Docs languages file for this project. If you change 4 | # anything here, it will apply to THIS PROJECT ONLY. If you'd like to change 5 | # something for all your projects, edit the Languages.txt in Natural Docs' 6 | # Config directory instead. 7 | 8 | 9 | # You can prevent certain file extensions from being scanned like this: 10 | # Ignore Extensions: [extension] [extension] ... 11 | 12 | 13 | #------------------------------------------------------------------------------- 14 | # SYNTAX: 15 | # 16 | # Unlike other Natural Docs configuration files, in this file all comments 17 | # MUST be alone on a line. Some languages deal with the # character, so you 18 | # cannot put comments on the same line as content. 19 | # 20 | # Also, all lists are separated with spaces, not commas, again because some 21 | # languages may need to use them. 22 | # 23 | # Language: [name] 24 | # Alter Language: [name] 25 | # Defines a new language or alters an existing one. Its name can use any 26 | # characters. If any of the properties below have an add/replace form, you 27 | # must use that when using Alter Language. 28 | # 29 | # The language Shebang Script is special. It's entry is only used for 30 | # extensions, and files with those extensions have their shebang (#!) lines 31 | # read to determine the real language of the file. Extensionless files are 32 | # always treated this way. 33 | # 34 | # The language Text File is also special. It's treated as one big comment 35 | # so you can put Natural Docs content in them without special symbols. Also, 36 | # if you don't specify a package separator, ignored prefixes, or enum value 37 | # behavior, it will copy those settings from the language that is used most 38 | # in the source tree. 39 | # 40 | # Extensions: [extension] [extension] ... 41 | # [Add/Replace] Extensions: [extension] [extension] ... 42 | # Defines the file extensions of the language's source files. You can 43 | # redefine extensions found in the main languages file. You can use * to 44 | # mean any undefined extension. 45 | # 46 | # Shebang Strings: [string] [string] ... 47 | # [Add/Replace] Shebang Strings: [string] [string] ... 48 | # Defines a list of strings that can appear in the shebang (#!) line to 49 | # designate that it's part of the language. You can redefine strings found 50 | # in the main languages file. 51 | # 52 | # Ignore Prefixes in Index: [prefix] [prefix] ... 53 | # [Add/Replace] Ignored Prefixes in Index: [prefix] [prefix] ... 54 | # 55 | # Ignore [Topic Type] Prefixes in Index: [prefix] [prefix] ... 56 | # [Add/Replace] Ignored [Topic Type] Prefixes in Index: [prefix] [prefix] ... 57 | # Specifies prefixes that should be ignored when sorting symbols in an 58 | # index. Can be specified in general or for a specific topic type. 59 | # 60 | #------------------------------------------------------------------------------ 61 | # For basic language support only: 62 | # 63 | # Line Comments: [symbol] [symbol] ... 64 | # Defines a space-separated list of symbols that are used for line comments, 65 | # if any. 66 | # 67 | # Block Comments: [opening sym] [closing sym] [opening sym] [closing sym] ... 68 | # Defines a space-separated list of symbol pairs that are used for block 69 | # comments, if any. 70 | # 71 | # Package Separator: [symbol] 72 | # Defines the default package separator symbol. The default is a dot. 73 | # 74 | # [Topic Type] Prototype Enders: [symbol] [symbol] ... 75 | # When defined, Natural Docs will attempt to get a prototype from the code 76 | # immediately following the topic type. It stops when it reaches one of 77 | # these symbols. Use \n for line breaks. 78 | # 79 | # Line Extender: [symbol] 80 | # Defines the symbol that allows a prototype to span multiple lines if 81 | # normally a line break would end it. 82 | # 83 | # Enum Values: [global|under type|under parent] 84 | # Defines how enum values are referenced. The default is global. 85 | # global - Values are always global, referenced as 'value'. 86 | # under type - Values are under the enum type, referenced as 87 | # 'package.enum.value'. 88 | # under parent - Values are under the enum's parent, referenced as 89 | # 'package.value'. 90 | # 91 | # Perl Package: [perl package] 92 | # Specifies the Perl package used to fine-tune the language behavior in ways 93 | # too complex to do in this file. 94 | # 95 | #------------------------------------------------------------------------------ 96 | # For full language support only: 97 | # 98 | # Full Language Support: [perl package] 99 | # Specifies the Perl package that has the parsing routines necessary for full 100 | # language support. 101 | # 102 | #------------------------------------------------------------------------------- 103 | 104 | # The following languages are defined in the main file, if you'd like to alter 105 | # them: 106 | # 107 | # Text File, Shebang Script, C/C++, C#, Java, JavaScript, Perl, Python, 108 | # PHP, SQL, Visual Basic, Pascal, Assembly, Ada, Tcl, Ruby, Makefile, 109 | # ActionScript, ColdFusion, R, Fortran 110 | 111 | # If you add a language that you think would be useful to other developers 112 | # and should be included in Natural Docs by default, please e-mail it to 113 | # languages [at] naturaldocs [dot] org. 114 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/_config/Menu.txt: -------------------------------------------------------------------------------- 1 | Format: 1.52 2 | 3 | 4 | Title: Dynamic Measure 5 | SubTitle: Compatible with OpenLayers from 2.11 to 2.13 & dev 6 | 7 | Footer: View on github.com/jorixView on GitHub 8 | 9 | # You can add a timestamp to your documentation like one of these: 10 | # Timestamp: Generated on month day, year 11 | # Timestamp: Updated mm/dd/yyyy 12 | # Timestamp: Last updated mon day 13 | # 14 | # m - One or two digit month. January is "1" 15 | # mm - Always two digit month. January is "01" 16 | # mon - Short month word. January is "Jan" 17 | # month - Long month word. January is "January" 18 | # d - One or two digit day. 1 is "1" 19 | # dd - Always two digit day. 1 is "01" 20 | # day - Day with letter extension. 1 is "1st" 21 | # yy - Two digit year. 2006 is "06" 22 | # yyyy - Four digit year. 2006 is "2006" 23 | # year - Four digit year. 2006 is "2006" 24 | 25 | # These are indexes you deleted, so Natural Docs will not add them again 26 | # unless you remove them from this line. 27 | 28 | Don't Index: General, Properties, Constants, Constructor, Functions, Classes 29 | 30 | 31 | # -------------------------------------------------------------------------- 32 | # 33 | # Cut and paste the lines below to change the order in which your files 34 | # appear on the menu. Don't worry about adding or removing files, Natural 35 | # Docs will take care of that. 36 | # 37 | # You can further organize the menu by grouping the entries. Add a 38 | # "Group: [name] {" line to start a group, and add a "}" to end it. 39 | # 40 | # You can add text and web links to the menu by adding "Text: [text]" and 41 | # "Link: [name] ([URL])" lines, respectively. 42 | # 43 | # The formatting and comments are auto-generated, so don't worry about 44 | # neatness when editing the file. Natural Docs will clean it up the next 45 | # time it is run. When working with groups, just deal with the braces and 46 | # forget about the indentation and comments. 47 | # 48 | # -------------------------------------------------------------------------- 49 | 50 | 51 | File: DynamicMeasure (DynamicMeasure.js) 52 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/_config/Topics.txt: -------------------------------------------------------------------------------- 1 | Format: 1.52 2 | 3 | # This is the Natural Docs topics file for this project. If you change anything 4 | # here, it will apply to THIS PROJECT ONLY. If you'd like to change something 5 | # for all your projects, edit the Topics.txt in Natural Docs' Config directory 6 | # instead. 7 | 8 | 9 | Ignore Keywords: 10 | function, functions 11 | func, funcs 12 | procedure, procedures 13 | proc, procs 14 | routine, routines 15 | subroutine, subroutines 16 | sub, subs 17 | method, methods 18 | callback, callbacks 19 | property, properties 20 | prop, props 21 | 22 | 23 | #------------------------------------------------------------------------------- 24 | # SYNTAX: 25 | # 26 | # Topic Type: [name] 27 | # Alter Topic Type: [name] 28 | # Creates a new topic type or alters one from the main file. Each type gets 29 | # its own index and behavior settings. Its name can have letters, numbers, 30 | # spaces, and these charaters: - / . ' 31 | # 32 | # Plural: [name] 33 | # Sets the plural name of the topic type, if different. 34 | # 35 | # Keywords: 36 | # [keyword] 37 | # [keyword], [plural keyword] 38 | # ... 39 | # Defines or adds to the list of keywords for the topic type. They may only 40 | # contain letters, numbers, and spaces and are not case sensitive. Plural 41 | # keywords are used for list topics. You can redefine keywords found in the 42 | # main topics file. 43 | # 44 | # Index: [yes|no] 45 | # Whether the topics get their own index. Defaults to yes. Everything is 46 | # included in the general index regardless of this setting. 47 | # 48 | # Scope: [normal|start|end|always global] 49 | # How the topics affects scope. Defaults to normal. 50 | # normal - Topics stay within the current scope. 51 | # start - Topics start a new scope for all the topics beneath it, 52 | # like class topics. 53 | # end - Topics reset the scope back to global for all the topics 54 | # beneath it. 55 | # always global - Topics are defined as global, but do not change the scope 56 | # for any other topics. 57 | # 58 | # Class Hierarchy: [yes|no] 59 | # Whether the topics are part of the class hierarchy. Defaults to no. 60 | # 61 | # Page Title If First: [yes|no] 62 | # Whether the topic's title becomes the page title if it's the first one in 63 | # a file. Defaults to no. 64 | # 65 | # Break Lists: [yes|no] 66 | # Whether list topics should be broken into individual topics in the output. 67 | # Defaults to no. 68 | # 69 | # Can Group With: [type], [type], ... 70 | # Defines a list of topic types that this one can possibly be grouped with. 71 | # Defaults to none. 72 | #------------------------------------------------------------------------------- 73 | 74 | # The following topics are defined in the main file, if you'd like to alter 75 | # their behavior or add keywords: 76 | # 77 | # Generic, Class, Interface, Section, File, Group, Function, Variable, 78 | # Property, Type, Constant, Enumeration, Event, Delegate, Macro, 79 | # Database, Database Table, Database View, Database Index, Database 80 | # Cursor, Database Trigger, Cookie, Build Target 81 | 82 | # If you add something that you think would be useful to other developers 83 | # and should be included in Natural Docs by default, please e-mail it to 84 | # topics [at] naturaldocs [dot] org. 85 | 86 | 87 | Topic Type: Constructor 88 | 89 | Class Hierarchy: Yes 90 | Keywords: 91 | constructor 92 | initialize 93 | 94 | 95 | Alter Topic Type: Function 96 | 97 | Add Keywords: 98 | apimethod 99 | apifunction 100 | 101 | 102 | Alter Topic Type: Property 103 | 104 | Add Keywords: 105 | apiproperty 106 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/files/DynamicMeasure-js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | OpenLayers.Control.DynamicMeasure - Dynamic Measure 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

OpenLayers.Control.DynamicMeasure

Allows for drawing of features for measurements.

Inherits from

Summary
OpenLayers.Control.DynamicMeasureAllows for drawing of features for measurements.
Properties
accuracy{Integer} Digits measurement accuracy, default is 5.
persist{Boolean} Keep the temporary measurement after the measurement is complete.
styles{Object} Alterations of the default styles of the points lines poligons and labels text, could use keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelHeading”, “labelLength” and “labelArea”.
positions{Object} Alterations of the default position of the labels, could use keys: “labelSegments” & “labelHeading”, with values “start” “middle” and “end” refered of the current segment; and keys: “labelLength” & “labelArea” with additional values “center” (of the feature) and “initial” (initial point of the feature) and also mentioned previus values.
maxSegments{Integer|Null} Maximum number of visible segments measures, default is 1.
maxHeadings{Integer|Null} Maximum number of visible headings measures, default is 1.
layerSegmentsOptions{Object} Any optional properties to be set on the layer of <layerSegments> of the lengths of the segments.
layerHeadingOptions{Object} Any optional properties to be set on the layer of <layerHeading> of the angle of the segments.
layerLengthOptions{Object} Any optional properties to be set on the layer of <layerLength> of the total length.
layerAreaOptions{Object} Any optional properties to be set on the layer of <layerArea> of the total area.
drawingLayer{<OpenLayers.Layer.Vector>} Drawing layer to store the drawing when finished.
multi{Boolean} Cast features to multi-part geometries before passing to the drawing layer, only used if declared a drawingLayer.
keep{Boolean} Keep annotations for every measures.
Constructor
OpenLayers.Control.Measure
Functions
destroy
activate
deactivate
emptyKeepedRemove annotations from layers layerSegmentsKeep, layerLengthKeep, layerAreaKeep.
setImmediateSets the <immediate> property.
Constants
OpenLayers.Control.DynamicMeasure.stylesContains the keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a objects with style keys.
OpenLayers.Control.DynamicMeasure.positionsContains the keys: “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a strings with values ‘start’, ‘middle’ and ‘end’ allowed for all keys (refered of last segment) and ‘center’ and ‘initial’ (refered of the measured feature and only allowed for “labelLength” and “labelArea” keys)
15 | 16 |

Properties

17 | 18 |

accuracy

{Integer} Digits measurement accuracy, default is 5.

19 | 20 |

persist

{Boolean} Keep the temporary measurement after the measurement is complete.  The measurement will persist until a new measurement is started, the control is deactivated, or <cancel> is called.  Default is true.

21 | 22 |

styles

{Object} Alterations of the default styles of the points lines poligons and labels text, could use keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelHeading”, “labelLength” and “labelArea”.  Default is OpenLayers.Control.DynamicMeasure.styles.

23 | 24 |

positions

{Object} Alterations of the default position of the labels, could use keys: “labelSegments” & “labelHeading”, with values “start” “middle” and “end” refered of the current segment; and keys: “labelLength” & “labelArea” with additional values “center” (of the feature) and “initial” (initial point of the feature) and also mentioned previus values.  Default is OpenLayers.Control.DynamicMeasure.positions.

25 | 26 |

maxSegments

{Integer|Null} Maximum number of visible segments measures, default is 1.

To avoid soiling the track is desirable to reduce the number of visible segments.

27 | 28 |

maxHeadings

{Integer|Null} Maximum number of visible headings measures, default is 1.

To avoid soiling the track is desirable to reduce the number of visible segments.

29 | 30 |

layerSegmentsOptions

{Object} Any optional properties to be set on the layer of <layerSegments> of the lengths of the segments.  If set to null the layer does not act.

If `styleMap` options is set then the key “labelSegments” of the `styles` option is ignored.

31 | 32 |

layerHeadingOptions

{Object} Any optional properties to be set on the layer of <layerHeading> of the angle of the segments.  If set to null the layer does not act.  Default is null, set to {} to use a <layerHeading> to show headings.

If `styleMap` options is set then the key “labelHeading” of the `styles` option is ignored.

33 | 34 |

layerLengthOptions

{Object} Any optional properties to be set on the layer of <layerLength> of the total length.  If set to null the layer does not act.

If `styleMap` option is set then the key “labelLength” of the `styles` option is ignored.

35 | 36 |

layerAreaOptions

{Object} Any optional properties to be set on the layer of <layerArea> of the total area.  If set to null the layer does not act.

If `styleMap` is set then the key “labelArea” of the `styles` option is ignored.

37 | 38 |

drawingLayer

{<OpenLayers.Layer.Vector>} Drawing layer to store the drawing when finished.

39 | 40 |

multi

{Boolean} Cast features to multi-part geometries before passing to the drawing layer, only used if declared a drawingLayer.  Default is false.

41 | 42 |

keep

{Boolean} Keep annotations for every measures.

43 | 44 |

Constructor

45 | 46 |

OpenLayers.Control.Measure

Parameters

handler{<OpenLayers.Handler>}
options{Object}

Valid options

accuracy{Integer} Digits measurement accuracy, default is 5.
styles{Object} Alterations of the default styles of the points lines poligons and labels text, could use keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelLength”, “labelArea”.
positions{Object} Alterations of the default position of the labels.
handlerOptions{Object} Used to set non-default properties on the control’s handler.  If `layerOptions[“styleMap”]` is set then the keys: “Point”, “Line” and “Polygon” of the `styles` option are ignored.
layerSegmentsOptions{Object} Any optional properties to be set on the layer of <layerSegments> of the lengths of the segments.  If `styleMap` is set then the key “labelSegments” of the `styles` option is ignored.  If set to null the layer does not act.
layerLengthOptions{Object} Any optional properties to be set on the layer of <layerLength> of the total length.  If `styleMap` is set then the key “labelLength” of the `styles` option is ignored.  If set to null the layer does not act.
layerAreaOptions{Object} Any optional properties to be set on the layer of <layerArea> of the total area.  If `styleMap` is set then the key “labelArea” of the `styles` option is ignored.  If set to null the layer does not act.
layerHeadingOptions{Object} Any optional properties to be set on the layer of <layerHeading> of the angle of the segments.  If `styleMap` is set then the key “labelHeading” of the `styles` option is ignored.  If set to null the layer does not act.
drawingLayer{<OpenLayers.Layer.Vector>} Optional drawing layer to store the drawing when finished.
multi{Boolean} Cast features to multi-part geometries before passing to the drawing layer
keep{Boolean} Keep annotations for every measures.
47 | 48 |

Functions

49 | 50 |

destroy

destroy: function()
51 | 52 |

activate

activate: function()
53 | 54 |

deactivate

deactivate: function()
55 | 56 |

emptyKeeped

emptyKeeped: function ()

Remove annotations from layers layerSegmentsKeep, layerLengthKeep, layerAreaKeep.

57 | 58 |

setImmediate

setImmediate: function(immediate)

Sets the <immediate> property.  Changes the activity of immediate measurement.

59 | 60 |

Constants

61 | 62 |

OpenLayers.Control.DynamicMeasure.styles

Contains the keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a objects with style keys.

63 | 64 |

OpenLayers.Control.DynamicMeasure.positions

Contains the keys: “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a strings with values ‘start’, ‘middle’ and ‘end’ allowed for all keys (refered of last segment) and ‘center’ and ‘initial’ (refered of the measured feature and only allowed for “labelLength” and “labelArea” keys)

65 | 66 |
67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
{OpenLayers.Layer.Vector} Drawing layer to store the drawing when finished.
destroy: function()
activate: function()
deactivate: function()
emptyKeeped: function ()
Remove annotations from layers layerSegmentsKeep, layerLengthKeep, layerAreaKeep.
setImmediate: function(immediate)
Sets the immediate property.
Contains the keys: “Point”, “Line”, “Polygon”, “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a objects with style keys.
Contains the keys: “labelSegments”, “labelHeading”, “labelLength” and “labelArea” as a strings with values ‘start’, ‘middle’ and ‘end’ allowed for all keys (refered of last segment) and ‘center’ and ‘initial’ (refered of the measured feature and only allowed for “labelLength” and “labelArea” keys)
78 | 79 | 80 | 81 | 82 |
Close
83 | 84 | 85 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/javascript/main.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jorix/OL-DynamicMeasure/8e95983d7c2ee05e7db2affd0e091b743ef3e8d1/doc/DynamicMeasure/api/javascript/main.js -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/javascript/prettify.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jorix/OL-DynamicMeasure/8e95983d7c2ee05e7db2affd0e091b743ef3e8d1/doc/DynamicMeasure/api/javascript/prettify.js -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/javascript/searchdata.js: -------------------------------------------------------------------------------- 1 | var indexSectionsWithContent = { 2 | 3 | } -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/search/NoResults.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
No Matches
-------------------------------------------------------------------------------- /doc/DynamicMeasure/api/styles/1.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jorix/OL-DynamicMeasure/8e95983d7c2ee05e7db2affd0e091b743ef3e8d1/doc/DynamicMeasure/api/styles/1.css -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/styles/2.css: -------------------------------------------------------------------------------- 1 | p { 2 | text-indent: 0; margin-bottom: 1em; 3 | } 4 | 5 | .MGroup { 6 | font-variant: normal; 7 | margin: 0.4em 0 0em 10px 8 | } 9 | 10 | .MTitle { 11 | font-variant: normal; 12 | } 13 | 14 | .CGroup .CTitle { 15 | font-variant: normal; 16 | } 17 | 18 | .SGroup .SEntry { 19 | font-variant: normal; 20 | } 21 | 22 | .CClass .CTopic h2.CTitle, 23 | #MainTopic .CTitle { 24 | background-color: #ddd; 25 | color: #025; 26 | border-radius: 16px; 27 | border-width:0; 28 | margin: 5px; 29 | margin: 0 10px 5px 10px; 30 | box-shadow: 0 0 10px rgba(0,0,0,0.6); 31 | } 32 | #MainTopic .CTitle { 33 | padding-right: 150px; /* used by #forkme_banner */ 34 | border-top-right-radius: 0; 35 | border-top-left-radius: 0; 36 | } 37 | #forkme_banner { 38 | display: block; 39 | position: absolute; 40 | top: 3px; right: 13px; 41 | z-index: 10; 42 | padding: 5px 5px 5px 36px; 43 | color: #fff !important; 44 | background: url('http://github.com/themes/slate/images/blacktocat.png') #0090ff no-repeat 3px 50%; 45 | box-shadow: 0 0 10px rgba(0,0,0,0.5); 46 | border-radius: 16px; 47 | text-decoration: none; 48 | font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif; 49 | font-size: 16px; 50 | line-height: 24px; 51 | font-weight: bold; 52 | } 53 | a#forkme_banner:hover, 54 | a#forkme_banner:focus { 55 | background: url('http://github.com/themes/slate/images/blacktocat.png') #000000 no-repeat 3px 50%; 56 | } 57 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/api/styles/main.css: -------------------------------------------------------------------------------- 1 | @import URL("1.css"); 2 | @import URL("2.css"); 3 | -------------------------------------------------------------------------------- /doc/DynamicMeasure/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/_scripts/documentation.cmd: -------------------------------------------------------------------------------- 1 | call naturaldocs -i ../../lib/OpenLayers/Control -hl All -s Default ../../../_scripts/jorix -o HTML ../DynamicMeasure/all -p ../DynamicMeasure/all/_config 2 | call naturaldocs -i ../../lib/OpenLayers/Control -hl All -s Default ../../../_scripts/jorix -o HTML ../DynamicMeasure/api -p ../DynamicMeasure/api/_config 3 | 4 | pause -------------------------------------------------------------------------------- /doc/_scripts/documentation.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | naturaldocs -i ../../lib/OpenLayers/Control -hl All -s Default ../../../_scripts/jorix -o HTML ../DynamicMeasure/all -p ../DynamicMeasure/all/_config 3 | naturaldocs -i ../../lib/OpenLayers/Control -hl All -s Default ../../../_scripts/jorix -o HTML ../DynamicMeasure/api -p ../DynamicMeasure/api/_config -------------------------------------------------------------------------------- /doc/_scripts/jorix.css: -------------------------------------------------------------------------------- 1 | p { 2 | text-indent: 0; margin-bottom: 1em; 3 | } 4 | 5 | .MGroup { 6 | font-variant: normal; 7 | margin: 0.4em 0 0em 10px 8 | } 9 | 10 | .MTitle { 11 | font-variant: normal; 12 | } 13 | 14 | .CGroup .CTitle { 15 | font-variant: normal; 16 | } 17 | 18 | .SGroup .SEntry { 19 | font-variant: normal; 20 | } 21 | 22 | .CClass .CTopic h2.CTitle, 23 | #MainTopic .CTitle { 24 | background-color: #ddd; 25 | color: #025; 26 | border-radius: 16px; 27 | border-width:0; 28 | margin: 5px; 29 | margin: 0 10px 5px 10px; 30 | box-shadow: 0 0 10px rgba(0,0,0,0.6); 31 | } 32 | #MainTopic .CTitle { 33 | padding-right: 150px; /* used by #forkme_banner */ 34 | border-top-right-radius: 0; 35 | border-top-left-radius: 0; 36 | } 37 | #forkme_banner { 38 | display: block; 39 | position: absolute; 40 | top: 3px; right: 13px; 41 | z-index: 10; 42 | padding: 5px 5px 5px 36px; 43 | color: #fff !important; 44 | background: url('http://github.com/themes/slate/images/blacktocat.png') #0090ff no-repeat 3px 50%; 45 | box-shadow: 0 0 10px rgba(0,0,0,0.5); 46 | border-radius: 16px; 47 | text-decoration: none; 48 | font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif; 49 | font-size: 16px; 50 | line-height: 24px; 51 | font-weight: bold; 52 | } 53 | a#forkme_banner:hover, 54 | a#forkme_banner:focus { 55 | background: url('http://github.com/themes/slate/images/blacktocat.png') #000000 no-repeat 3px 50%; 56 | } 57 | -------------------------------------------------------------------------------- /examples/measure-and-draw.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Example of OpenLayers to measure and draw features 15 | 16 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |

Example of OpenLayers to measure and draw features

30 | View on GitHub 31 |
vertices, draw, measure, drawing, modify, delete
32 |
Example of DynamicMeasure control for measure and draw vector features.
33 |
34 |
35 | 49 |
50 |
51 |

52 | View the measure-and-draw.js 53 | source to see how this is done. 54 |

55 |
56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /examples/measure-and-draw.js: -------------------------------------------------------------------------------- 1 | // Alter default OpenLayers options 2 | // -------------------------------- 3 | 4 | // Allow testing of specific renderers via "?renderer=Canvas", etc 5 | var renderer = OpenLayers.Util.getParameters(window.location.href).renderer; 6 | OpenLayers.Layer.Vector.prototype.renderers = renderer ? 7 | [renderer] : 8 | OpenLayers.Layer.Vector.prototype.renderers; 9 | 10 | OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '3'; 11 | 12 | // Create Objects 13 | // -------------- 14 | 15 | // To report draw modify and delete events 16 | var reportEvent; 17 | if (window.console && window.console.log) { 18 | reportEvent = function(event) { 19 | console.log(event.type, 20 | event.feature ? event.feature.id : event.components); 21 | }; 22 | } else { 23 | reportEvent = function() {}; 24 | } 25 | 26 | // Create the vectorial layer 27 | var vectorLayer = new OpenLayers.Layer.Vector('Vector Layer'); 28 | vectorLayer.events.on({ 29 | 'beforefeaturemodified': reportEvent, 30 | 'featuremodified': function(e) { 31 | e.feature.state = OpenLayers.State.UPDATE; 32 | reportEvent(e); 33 | }, 34 | 'afterfeaturemodified': reportEvent, 35 | 'beforefeatureremoved': reportEvent, 36 | 'featureremoved': reportEvent, 37 | 'vertexmodified': reportEvent, 38 | 'sketchmodified': reportEvent, 39 | 'sketchstarted': reportEvent, 40 | 'sketchcomplete': reportEvent 41 | }); 42 | 43 | // Create and show the map 44 | var map = new OpenLayers.Map({ 45 | div: 'map', 46 | layers: [ 47 | new OpenLayers.Layer.WMS('osgeo WMS', 48 | 'http://vmap0.tiles.osgeo.org/wms/vmap0?', {layers: 'basic'}), 49 | vectorLayer 50 | ] 51 | }); 52 | map.setCenter(new OpenLayers.LonLat(0, 0), 3); 53 | 54 | // Create the control collection to draw vectorial features. 55 | var controls = { 56 | line: new OpenLayers.Control.DynamicMeasure(OpenLayers.Handler.Path, { 57 | drawingLayer: vectorLayer, 58 | geodesic: true // required by projection "EPSG:4326" 59 | }), 60 | polygon: new OpenLayers.Control.DynamicMeasure(OpenLayers.Handler.Polygon, { 61 | drawingLayer: vectorLayer, 62 | geodesic: true // required by projection "EPSG:4326" 63 | }) 64 | }; 65 | // add this controls to the map 66 | for (var key in controls) { 67 | map.addControl(controls[key]); 68 | } 69 | 70 | // Functions called from the form fields to choose the desired control to test. 71 | // ---------------------------------------------------------------------------- 72 | 73 | // Function to toggle the active control 74 | function toggleControl(element) { 75 | for (key in controls) { 76 | var control = controls[key]; 77 | if (element.value === key && element.checked) { 78 | control.activate(); 79 | } else { 80 | control.deactivate(); 81 | } 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /examples/measure-and-keep.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 11 | 12 | 13 | 14 | 15 | Example of OpenLayers to measure and draw features with persistent labels (keep) 16 | 17 | 18 | 19 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |

Example of OpenLayers to measure and draw features with 31 | persitent labels

32 | View on GitHub 33 |
vertices, draw, measure, drawing, modify, delete
34 |
Example of DynamicMeasure control for measure and draw vector features.
35 |
36 |
37 | 51 |
52 |

When DynamicMeasure is created with keep=true. 53 | We have to call the emptyKeeped method on the control to remove annotations.

54 |
55 |

56 |
57 | 58 |
59 |

60 | View the measure-and-keep.js 61 | source to see how this is done. 62 |

63 |
64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /examples/measure-and-keep.js: -------------------------------------------------------------------------------- 1 | // Alter default OpenLayers options 2 | // -------------------------------- 3 | 4 | // Allow testing of specific renderers via "?renderer=Canvas", etc 5 | var renderer = OpenLayers.Util.getParameters(window.location.href).renderer; 6 | OpenLayers.Layer.Vector.prototype.renderers = renderer ? 7 | [renderer] : 8 | OpenLayers.Layer.Vector.prototype.renderers; 9 | 10 | OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '3'; 11 | 12 | // Create Objects 13 | // -------------- 14 | 15 | // To report draw modify and delete events 16 | var reportEvent; 17 | if (window.console && window.console.log) { 18 | reportEvent = function(event) { 19 | console.log(event.type, 20 | event.feature ? event.feature.id : event.components); 21 | }; 22 | } else { 23 | reportEvent = function() {}; 24 | } 25 | 26 | // Create the vectorial layer 27 | var vectorLayer = new OpenLayers.Layer.Vector('Vector Layer'); 28 | vectorLayer.events.on({ 29 | 'beforefeaturemodified': reportEvent, 30 | 'featuremodified': function(e) { 31 | e.feature.state = OpenLayers.State.UPDATE; 32 | reportEvent(e); 33 | }, 34 | 'afterfeaturemodified': reportEvent, 35 | 'beforefeatureremoved': reportEvent, 36 | 'featureremoved': reportEvent, 37 | 'vertexmodified': reportEvent, 38 | 'sketchmodified': reportEvent, 39 | 'sketchstarted': reportEvent, 40 | 'sketchcomplete': reportEvent 41 | }); 42 | 43 | // Create and show the map 44 | var map = new OpenLayers.Map({ 45 | div: 'map', 46 | layers: [ 47 | new OpenLayers.Layer.WMS('osgeo WMS', 48 | 'http://vmap0.tiles.osgeo.org/wms/vmap0?', {layers: 'basic'}), 49 | vectorLayer, 50 | ] 51 | }); 52 | map.setCenter(new OpenLayers.LonLat(0, 0), 3); 53 | 54 | var styleLine = { 55 | 'Point': { 56 | pointRadius: 4, 57 | graphicName: 'square', 58 | fillColor: 'white', 59 | fillOpacity: 1, 60 | strokeWidth: 1, 61 | strokeOpacity: 1, 62 | strokeColor: '#333333' 63 | }, 64 | 'Line': { 65 | strokeWidth: 2, 66 | strokeOpacity: 1, 67 | strokeColor: '#666666', 68 | strokeDashstyle: 'dash' 69 | }, 70 | 'Polygon': { 71 | strokeWidth: 2, 72 | strokeOpacity: 1, 73 | strokeColor: '#666666', 74 | strokeDashstyle: 'solid', 75 | fillColor: 'white', 76 | fillOpacity: 0.3 77 | }, 78 | labelSegments: { 79 | label: '${measure} ${units}', 80 | fontSize: '11px', 81 | fontColor: '#7661AB', 82 | fontFamily: 'Verdana', 83 | labelOutlineColor: '#dddddd', 84 | labelAlign: 'cm', 85 | labelOutlineWidth: 2 86 | }, 87 | labelLength: { 88 | label: '${measure} ${units}\n', 89 | fontSize: '11px', 90 | fontWeight: 'bold', 91 | fontColor: '#800517', 92 | fontFamily: 'Verdana', 93 | labelOutlineColor: '#dddddd', 94 | labelAlign: 'lb', 95 | labelOutlineWidth: 3 96 | }, 97 | labelArea: { 98 | label: '${measure}\n${units}²\n', 99 | fontSize: '11px', 100 | fontWeight: 'bold', 101 | fontColor: '#800517', 102 | fontFamily: 'Verdana', 103 | labelOutlineColor: '#dddddd', 104 | labelAlign: 'cm', 105 | labelOutlineWidth: 3 106 | }, 107 | labelHeading: { 108 | label: '${measure} ${units}', 109 | fontSize: '11px', 110 | fontColor: '#800517', 111 | fontFamily: 'Verdana', 112 | labelOutlineColor: '#dddddd', 113 | labelAlign: 'cm', 114 | labelOutlineWidth: 3 115 | } 116 | }; 117 | 118 | // Create the control collection to draw vectorial features. 119 | var controls = { 120 | line: new OpenLayers.Control.DynamicMeasure(OpenLayers.Handler.Path, { 121 | persist: true, 122 | maxSegments: null, 123 | drawingLayer: vectorLayer, 124 | geodesic: true, // required by projection "EPSG:4326" 125 | keep: true 126 | }), 127 | polygon: new OpenLayers.Control.DynamicMeasure(OpenLayers.Handler.Polygon, { 128 | persist: false, 129 | maxSegments: null, 130 | drawingLayer: vectorLayer, 131 | geodesic: true, // required by projection "EPSG:4326" 132 | keep: true 133 | }) 134 | }; 135 | // add this controls to the map 136 | for (var key in controls) { 137 | map.addControl(controls[key]); 138 | } 139 | 140 | // Functions called from the form fields to choose the desired control to test. 141 | // ---------------------------------------------------------------------------- 142 | 143 | // Function to toggle the active control 144 | function toggleControl(element) { 145 | for (key in controls) { 146 | var control = controls[key]; 147 | if (element.value === key && element.checked) { 148 | control.activate(); 149 | } else { 150 | control.deactivate(); 151 | } 152 | } 153 | } 154 | 155 | function emptyAllKeeped() { 156 | var lineActive = controls.line.active, 157 | polygonActive = controls.polygon.active; 158 | controls.line.deactivate(); 159 | controls.line.emptyKeeped(); 160 | controls.polygon.deactivate(); 161 | controls.polygon.emptyKeeped(); 162 | if (lineActive) { 163 | controls.line.activate(); 164 | } 165 | if (polygonActive) { 166 | controls.polygon.activate(); 167 | } 168 | } 169 | 170 | -------------------------------------------------------------------------------- /examples/measure-dynamic-dev.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Example of OpenLayers to see measurements beside the cursor 15 | 16 | 17 | 24 | 25 | 26 | 35 | 36 | 37 |

??

38 | View on GitHub 39 |
40 | 43 | 44 |
45 | measuring, dynamic, area, length, distance, cursor 46 |
47 |

48 | Demonstrates the dynamic measure control to measure and see measurements beside the cursor. 49 |

50 |
51 |
52 |
53 |
54 | 86 |
87 |
88 |

89 | View the measure-dynamic.js 90 | source to see how this is done. 91 |

92 |
93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /examples/measure-dynamic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Example of OpenLayers to see measurements beside the cursor 15 | 16 | 17 | 18 | 19 | 20 | 21 | 30 | 31 | 32 |

OpenLayers Measure Example

33 | View on GitHub 34 |
35 | measuring, dynamic, area, length, distance, cursor 36 |
37 |

38 | Demonstrates the dynamic measure control to measure and see measurements beside the cursor. 39 |

40 |
41 |
42 |
43 |
44 | 76 |
77 |
78 |

79 | View the measure-dynamic.js 80 | source to see how this is done. 81 |

82 |
83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /examples/measure-dynamic.js: -------------------------------------------------------------------------------- 1 | // allow testing of specific renderers via "?renderer=Canvas", etc 2 | var renderer = OpenLayers.Util.getParameters(window.location.href).renderer; 3 | if (renderer) { 4 | OpenLayers.Layer.Vector.prototype.renderers = [renderer]; 5 | } 6 | 7 | // The map 8 | var map = new OpenLayers.Map({ 9 | div: 'map', 10 | layers: [ 11 | new OpenLayers.Layer.WMS('OpenLayers WMS', 12 | 'http://vmap0.tiles.osgeo.org/wms/vmap0?', {layers: 'basic'}) 13 | ] 14 | }); 15 | map.setCenter(new OpenLayers.LonLat(0, 0), 3); 16 | 17 | // The measure controls 18 | var measureControls = { 19 | /* NOTE: Should be sure whether projection requires `{geodesic:true}`. 20 | See: http://dev.openlayers.org/docs/files/OpenLayers/Control/Measure-js.html#OpenLayers.Control.Measure.geodesic 21 | "" 22 | Geodesic calculation works the same in both the ScaleLine and Measure 23 | controls, so it has the same prerequisites. The advice that proj4js 24 | is needed to make it work is only true to the extent it is with any 25 | re-projection in OpenLayers: as long as your map is in EPSG:900913, 26 | you don't need proj4js. As soon as you use a different projection, 27 | you need it. 28 | "" (from comment by Andreas Hocevar) 29 | See: http://osgeo-org.1560.x6.nabble.com/Getting-the-right-results-from-Measure-tool-using-EPSG-3776-td3921884.html#a3921894 30 | */ 31 | line: new OpenLayers.Control.DynamicMeasure( 32 | OpenLayers.Handler.Path, {geodesic:true}), 33 | polygon: new OpenLayers.Control.DynamicMeasure( 34 | OpenLayers.Handler.Polygon, {geodesic:true}) 35 | }; 36 | map.addControls([ 37 | measureControls.line, 38 | measureControls.polygon, 39 | new OpenLayers.Control.LayerSwitcher() 40 | ]); 41 | 42 | // functions used in the form to set the measure control. 43 | function toggleControl(element) { 44 | for (var key in measureControls) { 45 | if (element.value === key && element.checked) { 46 | measureControls[key].activate(); 47 | } else { 48 | measureControls[key].deactivate(); 49 | } 50 | } 51 | } 52 | function toggleShowSegments(element) { 53 | for (var key in measureControls) { 54 | var control = measureControls[key]; 55 | if (element.checked) { 56 | // * set `layerSegmentsOptions` at control creation as a object 57 | // or undefined to display length of segments. 58 | delete control.layerSegmentsOptions; 59 | } else { 60 | // * set `layerSegmentsOptions` at control creation to null to 61 | // not display. 62 | control.layerSegmentsOptions = null; 63 | } 64 | if (control.active) { 65 | control.deactivate(); 66 | control.activate(); 67 | } 68 | } 69 | } 70 | function toggleShowPerimeter(element) { 71 | var control = measureControls.polygon; 72 | if (element.checked) { 73 | // * set `layerLengthOptions` as a object or undefined to display 74 | // length of perimeter. 75 | delete control.layerLengthOptions; 76 | } else { 77 | // * set `layerLengthOptions` to null to not display. 78 | control.layerLengthOptions = null; 79 | } 80 | if (control.active) { 81 | control.deactivate(); 82 | control.activate(); 83 | } 84 | } 85 | function toggleShowHeading(element) { 86 | for (var key in measureControls) { 87 | var control = measureControls[key]; 88 | if (element.checked) { 89 | // * set `layerHeadingOptions` as a object or undefined to 90 | // display heading. 91 | control.layerHeadingOptions = {}; 92 | } else { 93 | // * set `layerHeadingOptions` to null to not display. 94 | control.layerHeadingOptions = null; 95 | } 96 | if (control.active) { 97 | control.deactivate(); 98 | control.activate(); 99 | } 100 | } 101 | } 102 | function changeMaxSegments(element) { 103 | var maxSegments = element.value !== '' ? 104 | parseInt(element.value, 10) : 105 | null; 106 | for (var key in measureControls) { 107 | measureControls[key].maxSegments = maxSegments; 108 | measureControls[key].maxHeadings = maxSegments; 109 | } 110 | } 111 | 112 | // Set current values, needed if form is reloaded with values 113 | toggleShowSegments(document.getElementById("showSegments")); 114 | toggleShowPerimeter(document.getElementById("showPerimeter")); 115 | toggleShowHeading(document.getElementById("showHeading")); 116 | changeMaxSegments(document.getElementById("maxSegments")); 117 | toggleControl(document.getElementById("lineToggle")); 118 | toggleControl(document.getElementById("polygonToggle")); 119 | -------------------------------------------------------------------------------- /lib/OpenLayers/Control/DynamicMeasure.js: -------------------------------------------------------------------------------- 1 | /* Copyright 2011-2018 Xavier Mamano, http://github.com/jorix/OL-DynamicMeasure 2 | * Published under MIT license. */ 3 | 4 | /** 5 | * @requires OpenLayers/Control/Measure.js 6 | * @requires OpenLayers/Rule.js 7 | * @requires OpenLayers/StyleMap.js 8 | */ 9 | 10 | /** 11 | * Class: OpenLayers.Control.DynamicMeasure 12 | * Allows for drawing of features for measurements. 13 | * 14 | * Inherits from: 15 | * - 16 | */ 17 | OpenLayers.Control.DynamicMeasure = OpenLayers.Class( 18 | OpenLayers.Control.Measure, { 19 | 20 | /** 21 | * APIProperty: accuracy 22 | * {Integer} Digits measurement accuracy, default is 5. 23 | */ 24 | accuracy: 5, 25 | 26 | /** 27 | * APIProperty: persist 28 | * {Boolean} Keep the temporary measurement after the 29 | * measurement is complete. The measurement will persist until a new 30 | * measurement is started, the control is deactivated, or is 31 | * called. Default is true. 32 | */ 33 | persist: true, 34 | 35 | /** 36 | * APIProperty: styles 37 | * {Object} Alterations of the default styles of the points lines poligons 38 | * and labels text, could use keys: "Point", "Line", 39 | * "Polygon", "labelSegments", "labelHeading", "labelLength" and 40 | * "labelArea". Default is . 41 | */ 42 | styles: null, 43 | 44 | /** 45 | * APIProperty: positions 46 | * {Object} Alterations of the default position of the labels, could use 47 | * keys: "labelSegments" & "labelHeading", with values "start" "middle" 48 | * and "end" refered of the current segment; and keys: "labelLength" & 49 | * "labelArea" with additional values "center" (of the feature) and 50 | * "initial" (initial point of the feature) and also mentioned previus 51 | * values. Default is 52 | * . 53 | */ 54 | positions: null, 55 | 56 | /** 57 | * APIProperty: maxSegments 58 | * {Integer|Null} Maximum number of visible segments measures, default is 1. 59 | * 60 | * To avoid soiling the track is desirable to reduce the number of visible 61 | * segments. 62 | */ 63 | maxSegments: 1, 64 | 65 | /** 66 | * APIProperty: maxHeadings 67 | * {Integer|Null} Maximum number of visible headings measures, default is 1. 68 | * 69 | * To avoid soiling the track is desirable to reduce the number of visible 70 | * segments. 71 | */ 72 | maxHeadings: 1, 73 | 74 | /** 75 | * APIProperty: layerSegmentsOptions 76 | * {Object} Any optional properties to be set on the 77 | * layer of of the lengths of the segments. If set to 78 | * null the layer does not act. 79 | * 80 | * If `styleMap` options is set then the key "labelSegments" of the 81 | * `styles` option is ignored. 82 | */ 83 | layerSegmentsOptions: undefined, 84 | 85 | /** 86 | * APIProperty: layerHeadingOptions 87 | * {Object} Any optional properties to be set on the 88 | * layer of of the angle of the segments. If set to 89 | * null the layer does not act. Default is null, set to {} to use a 90 | * to show headings. 91 | * 92 | * If `styleMap` options is set then the key "labelHeading" of the 93 | * `styles` option is ignored. 94 | */ 95 | layerHeadingOptions: null, 96 | 97 | /** 98 | * APIProperty: layerLengthOptions 99 | * {Object} Any optional properties to be set on the 100 | * layer of of the total length. If set to null the layer 101 | * does not act. 102 | * 103 | * If `styleMap` option is set then the key "labelLength" of the 104 | * `styles` option is ignored. 105 | */ 106 | layerLengthOptions: undefined, 107 | 108 | /** 109 | * APIProperty: layerAreaOptions 110 | * {Object} Any optional properties to be set on the 111 | * layer of of the total area. If set to null the layer does 112 | * not act. 113 | * 114 | * If `styleMap` is set then the key "labelArea" of the `styles` option 115 | * is ignored. 116 | */ 117 | layerAreaOptions: undefined, 118 | 119 | /** 120 | * APIProperty: drawingLayer 121 | * {} Drawing layer to store the drawing when 122 | * finished. 123 | */ 124 | drawingLayer: null, 125 | 126 | /** 127 | * APIProperty: multi 128 | * {Boolean} Cast features to multi-part geometries before passing to the 129 | * drawing layer, only used if declared a . 130 | * Default is false. 131 | */ 132 | multi: false, 133 | 134 | /** 135 | * APIProperty: keep 136 | * {Boolean} Keep annotations for every measures. 137 | */ 138 | keep: false, 139 | 140 | /** 141 | * Property: layerSegments 142 | * {} The temporary drawing layer to show the 143 | * length of the segments. 144 | */ 145 | layerSegments: null, 146 | 147 | /** 148 | * Property: layerLength 149 | * {} The temporary drawing layer to show total 150 | * length. 151 | */ 152 | layerLength: null, 153 | 154 | /** 155 | * Property: layerArea 156 | * {} The temporary drawing layer to show total 157 | * area. 158 | */ 159 | layerArea: null, 160 | 161 | /** 162 | * Property: layerSegmentsKeep 163 | * {} The layer keep a copy of the length of 164 | * every segments measured since tool activation. 165 | */ 166 | layerSegmentsKeep: null, 167 | 168 | /** 169 | * Property: layersLengthKeep 170 | * {} The layer keep a copy of the length of 171 | * every polyline/poly measured since tool activation. 172 | */ 173 | layerLengthKeep: null, 174 | 175 | /** 176 | * Property: layerAreaKeep 177 | * {} The layer keep a copy of the area of every 178 | * polygon 179 | */ 180 | layerAreaKeep: null, 181 | /** 182 | * Property: dynamicObj 183 | * {Object} Internal use. 184 | */ 185 | dynamicObj: null, 186 | 187 | /** 188 | * Property: isArea 189 | * {Boolean} Internal use. 190 | */ 191 | isArea: null, 192 | 193 | /** 194 | * Constructor: OpenLayers.Control.Measure 195 | * 196 | * Parameters: 197 | * handler - {} 198 | * options - {Object} 199 | * 200 | * Valid options: 201 | * accuracy - {Integer} Digits measurement accuracy, default is 5. 202 | * styles - {Object} Alterations of the default styles of the points lines 203 | * poligons and labels text, could use keys: "Point", 204 | * "Line", "Polygon", "labelSegments", "labelLength", "labelArea". 205 | * positions - {Object} Alterations of the default position of the labels. 206 | * handlerOptions - {Object} Used to set non-default properties on the 207 | * control's handler. If `layerOptions["styleMap"]` is set then the 208 | * keys: "Point", "Line" and "Polygon" of the `styles` option 209 | * are ignored. 210 | * layerSegmentsOptions - {Object} Any optional properties to be set on the 211 | * layer of of the lengths of the segments. If 212 | * `styleMap` is set then the key "labelSegments" of the `styles` option 213 | * is ignored. If set to null the layer does not act. 214 | * layerLengthOptions - {Object} Any optional properties to be set on the 215 | * layer of of the total length. If 216 | * `styleMap` is set then the key "labelLength" of the `styles` option 217 | * is ignored. If set to null the layer does not act. 218 | * layerAreaOptions - {Object} Any optional properties to be set on the 219 | * layer of of the total area. If 220 | * `styleMap` is set then the key "labelArea" of the `styles` option 221 | * is ignored. If set to null the layer does not act. 222 | * layerHeadingOptions - {Object} Any optional properties to be set on the 223 | * layer of of the angle of the segments. If 224 | * `styleMap` is set then the key "labelHeading" of the `styles` option 225 | * is ignored. If set to null the layer does not act. 226 | * drawingLayer - {} Optional drawing layer to 227 | * store the drawing when finished. 228 | * multi - {Boolean} Cast features to multi-part geometries before passing 229 | * to the drawing layer 230 | * keep - {Boolean} Keep annotations for every measures. 231 | */ 232 | initialize: function(handler, options) { 233 | 234 | // Manage options 235 | options = options || {}; 236 | 237 | // handlerOptions: persist & multi 238 | options.handlerOptions = OpenLayers.Util.extend( 239 | {persist: !options.drawingLayer}, options.handlerOptions 240 | ); 241 | if (options.drawingLayer && !('multi' in options.handlerOptions)) { 242 | options.handlerOptions.multi = options.multi; 243 | } 244 | 245 | // * styles option 246 | if (options.drawingLayer) { 247 | var sketchStyle = options.drawingLayer.styleMap && 248 | options.drawingLayer.styleMap.styles.temporary; 249 | if (sketchStyle) { 250 | options.handlerOptions 251 | .layerOptions = OpenLayers.Util.applyDefaults( 252 | options.handlerOptions.layerOptions, { 253 | styleMap: new OpenLayers.StyleMap({ 254 | 'default': sketchStyle 255 | }) 256 | } 257 | ); 258 | } 259 | } 260 | var optionsStyles = options.styles || {}; 261 | options.styles = optionsStyles; 262 | var defaultStyles = OpenLayers.Control.DynamicMeasure.styles; 263 | // * * styles for handler layer. 264 | if (!options.handlerOptions.layerOptions || 265 | !options.handlerOptions.layerOptions.styleMap) { 266 | // use the style option for layerOptions of the handler. 267 | var style = new OpenLayers.Style(null, {rules: [ 268 | new OpenLayers.Rule({symbolizer: { 269 | 'Point': OpenLayers.Util.applyDefaults( 270 | optionsStyles.Point, defaultStyles.Point), 271 | 'Line': OpenLayers.Util.applyDefaults( 272 | optionsStyles.Line, defaultStyles.Line), 273 | 'Polygon': OpenLayers.Util.applyDefaults( 274 | optionsStyles.Polygon, defaultStyles.Polygon) 275 | }}) 276 | ]}); 277 | options.handlerOptions = options.handlerOptions || {}; 278 | options.handlerOptions.layerOptions = 279 | options.handlerOptions.layerOptions || {}; 280 | options.handlerOptions.layerOptions.styleMap = 281 | new OpenLayers.StyleMap({'default': style}); 282 | } 283 | 284 | // * positions option 285 | options.positions = OpenLayers.Util.applyDefaults( 286 | options.positions, 287 | OpenLayers.Control.DynamicMeasure.positions 288 | ); 289 | 290 | // force some handler options 291 | options.callbacks = options.callbacks || {}; 292 | if (options.drawingLayer) { 293 | OpenLayers.Util.applyDefaults(options.callbacks, { 294 | create: function(vertex, feature) { 295 | this.callbackCreate(vertex, feature); 296 | this.drawingLayer.events.triggerEvent( 297 | 'sketchstarted', {vertex: vertex, feature: feature} 298 | ); 299 | }, 300 | modify: function(vertex, feature) { 301 | this.callbackModify(vertex, feature); 302 | this.drawingLayer.events.triggerEvent( 303 | 'sketchmodified', {vertex: vertex, feature: feature} 304 | ); 305 | }, 306 | done: function(geometry) { 307 | if (this.keep) { 308 | this.copyAnnotations(); 309 | } 310 | this.callbackDone(geometry); 311 | this.drawFeature(geometry); 312 | } 313 | }); 314 | } 315 | OpenLayers.Util.applyDefaults(options.callbacks, { 316 | create: this.callbackCreate, 317 | point: this.callbackPoint, 318 | cancel: this.callbackCancel, 319 | done: this.callbackDone, 320 | modify: this.callbackModify, 321 | redo: this.callbackRedo, 322 | undo: this.callbackUndo 323 | }); 324 | 325 | // do a trick with the handler to avoid blue background in freehand. 326 | var _self = this; 327 | var oldOnselectstart = document.onselectstart ? 328 | document.onselectstart : OpenLayers.Function.True; 329 | var handlerTuned = OpenLayers.Class(handler, { 330 | down: function(evt) { 331 | document.onselectstart = OpenLayers.Function.False; 332 | return handler.prototype.down.apply(this, arguments); 333 | }, 334 | up: function(evt) { 335 | document.onselectstart = oldOnselectstart; 336 | return handler.prototype.up.apply(this, arguments); 337 | }, 338 | move: function(evt) { 339 | if (!this.mouseDown) { 340 | document.onselectstart = oldOnselectstart; 341 | } 342 | return handler.prototype.move.apply(this, arguments); 343 | }, 344 | mouseout: function(evt) { 345 | if (OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) { 346 | if (this.mouseDown) { 347 | document.onselectstart = oldOnselectstart; 348 | } 349 | } 350 | return handler.prototype.mouseout.apply(this, arguments); 351 | }, 352 | finalize: function() { 353 | document.onselectstart = oldOnselectstart; 354 | handler.prototype.finalize.apply(this, arguments); 355 | } 356 | }, { 357 | undo: function() { 358 | var undone = handler.prototype.undo.call(this); 359 | if (undone) { 360 | this.callback('undo', 361 | [this.point.geometry, this.getSketch(), true]); 362 | } 363 | return undone; 364 | }, 365 | redo: function() { 366 | var redone = handler.prototype.redo.call(this); 367 | if (redone) { 368 | this.callback('redo', 369 | [this.point.geometry, this.getSketch(), true]); 370 | } 371 | return redone; 372 | } 373 | }); 374 | // ... and call the constructor 375 | OpenLayers.Control.Measure.prototype.initialize.call( 376 | this, handlerTuned, options); 377 | 378 | this.isArea = handler.prototype.polygon !== undefined; // duck typing 379 | }, 380 | 381 | /** 382 | * APIMethod: destroy 383 | */ 384 | destroy: function() { 385 | this.deactivate(); 386 | this.emptyKeeped(); 387 | //keep status may have change, destroy layerXxxxxKeep anyway 388 | if (this.layerSegmentsKeep) { 389 | this.layerSegmentsKeep.destroy(); 390 | this.layerSegmentsKeep = null; 391 | } 392 | if (this.layerLengthKeep) { 393 | this.layerLengthKeep.destroy(); 394 | this.layerLengthKeep = null; 395 | } 396 | if (this.layerAreaKeep) { 397 | this.layerAreaKeep.destroy(); 398 | this.layerAreaKeep = null; 399 | } 400 | OpenLayers.Control.Measure.prototype.destroy.apply(this, arguments); 401 | }, 402 | 403 | /** 404 | * Method: draw 405 | * This control does not have HTML component, so this method should 406 | * be empty. 407 | */ 408 | draw: function() {}, 409 | 410 | /** 411 | * APIMethod: activate 412 | */ 413 | activate: function() { 414 | var response = OpenLayers.Control.Measure.prototype.activate.apply( 415 | this, arguments); 416 | if (response) { 417 | // Create dynamicObj 418 | this.dynamicObj = {}; 419 | // Create layers 420 | var _optionsStyles = this.styles || {}, 421 | _defaultStyles = OpenLayers.Control.DynamicMeasure.styles, 422 | _self = this; 423 | var _create = function(styleName, initialOptions, nameSuffix) { 424 | nameSuffix = nameSuffix || ''; 425 | if (initialOptions === null) { 426 | return null; 427 | } 428 | var options = OpenLayers.Util.extend({ 429 | displayInLayerSwitcher: false, 430 | calculateInRange: OpenLayers.Function.True 431 | // ?? ,wrapDateLine: this.citeCompliant 432 | }, initialOptions); 433 | if (!options.styleMap) { 434 | var style = _optionsStyles[styleName]; 435 | 436 | options.styleMap = new OpenLayers.StyleMap({ 437 | 'default': OpenLayers.Util.applyDefaults(style, 438 | _defaultStyles[styleName]) 439 | }); 440 | } 441 | var layer = new OpenLayers.Layer.Vector( 442 | _self.CLASS_NAME + ' ' + styleName + nameSuffix, 443 | options); 444 | _self.map.addLayer(layer); 445 | return layer; 446 | }; 447 | this.layerSegments = 448 | _create('labelSegments', this.layerSegmentsOptions); 449 | this.layerHeading = 450 | _create('labelHeading', this.layerHeadingOptions); 451 | this.layerLength = _create('labelLength', this.layerLengthOptions); 452 | if (this.isArea) { 453 | this.layerArea = _create('labelArea', this.layerAreaOptions); 454 | } 455 | if (this.keep) { 456 | if (!this.layerSegmentsKeep) { 457 | this.layerSegmentsKeep = 458 | _create('labelSegments', this.layerSegmentsOptions, 459 | 'Keep'); 460 | } 461 | if (!this.layerLengthKeep) { 462 | this.layerLengthKeep = 463 | _create('labelLength', this.layerLengthOptions, 464 | 'Keep'); 465 | } 466 | if (!this.layerAreaKeep) { 467 | this.layerAreaKeep = 468 | _create('labelArea', this.layerAreaOptions, 469 | 'Keep'); 470 | } 471 | } 472 | } 473 | return response; 474 | }, 475 | 476 | /** 477 | * APIMethod: deactivate 478 | */ 479 | deactivate: function() { 480 | var response = OpenLayers.Control.Measure.prototype.deactivate.apply( 481 | this, arguments); 482 | if (response) { 483 | if (this.layerSegments) { 484 | this.layerSegments.destroy(); 485 | } 486 | if (this.layerLength) { 487 | this.layerLength.destroy(); 488 | } 489 | if (this.layerHeading) { 490 | this.layerHeading.destroy(); 491 | } 492 | if (this.layerArea) { 493 | this.layerArea.destroy(); 494 | } 495 | this.dynamicObj = null; 496 | this.layerSegments = null; 497 | this.layerLength = null; 498 | this.layerHeading = null; 499 | this.layerArea = null; 500 | } 501 | return response; 502 | }, 503 | 504 | /** 505 | * APIMethod: emptyKeeped 506 | * Remove annotations from layers layerSegmentsKeep, layerLengthKeep, 507 | * layerAreaKeep. 508 | */ 509 | emptyKeeped: function () { 510 | if (this.layerSegmentsKeep) { 511 | this.layerSegmentsKeep.destroyFeatures(); 512 | } 513 | if (this.layerLengthKeep) { 514 | this.layerLengthKeep.destroyFeatures(); 515 | } 516 | if (this.layerAreaKeep) { 517 | this.layerAreaKeep.destroyFeatures(); 518 | } 519 | }, 520 | 521 | /** 522 | * APIMethod: setImmediate 523 | * Sets the property. Changes the activity of immediate 524 | * measurement. 525 | */ 526 | setImmediate: function(immediate) { 527 | this.immediate = immediate; 528 | }, 529 | 530 | /** 531 | * Method: callbackCreate 532 | */ 533 | callbackCreate: function() { 534 | var dynamicObj = this.dynamicObj; 535 | dynamicObj.drawing = false; 536 | dynamicObj.freehand = false; 537 | dynamicObj.fromIndex = 0; 538 | dynamicObj.countSegments = 0; 539 | }, 540 | 541 | /** 542 | * Method: callbackCancel 543 | */ 544 | callbackCancel: function() { 545 | this.destroyLabels(); 546 | }, 547 | 548 | /** 549 | * Method: callbackDone 550 | * Called when the measurement sketch is done. 551 | * 552 | * Parameters: 553 | * geometry - {} 554 | */ 555 | callbackDone: function(geometry) { 556 | this.measureComplete(geometry); 557 | if (!this.persist) { 558 | this.destroyLabels(); 559 | } 560 | }, 561 | 562 | /** 563 | * Method: drawFeature 564 | */ 565 | drawFeature: function(geometry) { 566 | var feature = new OpenLayers.Feature.Vector(geometry); 567 | var proceed = this.drawingLayer.events.triggerEvent( 568 | 'sketchcomplete', {feature: feature} 569 | ); 570 | if (proceed !== false) { 571 | feature.state = OpenLayers.State.INSERT; 572 | this.drawingLayer.addFeatures([feature]); 573 | if (this.featureAdded) { 574 | // for compatibility 575 | this.featureAdded(feature); 576 | } 577 | this.events.triggerEvent('featureadded', {feature: feature}); 578 | } 579 | }, 580 | 581 | /** 582 | * Method: copyAnnotations 583 | */ 584 | copyAnnotations: function() { 585 | var _insertable = function(feat) { 586 | feat.state = OpenLayers.State.INSERT; 587 | }; 588 | // Segments measures 589 | var segments = this.layerSegments.clone(); 590 | var segmentsFeatures = segments.features; 591 | for(i = 0; i > segmentsFeatures.length; i++) { 592 | segmentsFeatures[i].state = OpenLayers.State.INSERT; 593 | } 594 | this.layerSegmentsKeep.addFeatures(segmentsFeatures); 595 | // Length measures 596 | var lengths = this.layerLength.clone(); 597 | var lengthsFeatures = lengths.features; 598 | for(i = 0; i > lengthsFeatures.length; i++) { 599 | lengthsFeatures[i].state = OpenLayers.State.INSERT; 600 | } 601 | this.layerLengthKeep.addFeatures(lengthsFeatures); 602 | // Area measures 603 | if (this.isArea) { 604 | var areas = this.layerArea.clone(); 605 | var areasFeatures = areas.features; 606 | for(i = 0; i > areasFeatures.length; i++) { 607 | areasFeatures[i].state = OpenLayers.State.INSERT; 608 | } 609 | this.layerAreaKeep.addFeatures(areasFeatures); 610 | } 611 | }, 612 | 613 | /** 614 | * Method: callbackCancel 615 | */ 616 | destroyLabels: function() { 617 | if (this.layerSegments) { 618 | this.layerSegments.destroyFeatures(null, {silent: true}); 619 | } 620 | if (this.layerLength) { 621 | this.layerLength.destroyFeatures(null, {silent: true}); 622 | } 623 | if (this.layerHeading) { 624 | this.layerHeading.destroyFeatures(null, {silent: true}); 625 | } 626 | if (this.layerArea) { 627 | this.layerArea.destroyFeatures(null, {silent: true}); 628 | } 629 | }, 630 | 631 | /** 632 | * Method: callbackPoint 633 | */ 634 | callbackPoint: function(point, geometry) { 635 | var dynamicObj = this.dynamicObj; 636 | if (!dynamicObj.drawing) { 637 | this.destroyLabels(); 638 | } 639 | if (!this.handler.freehandMode(this.handler.evt)) { 640 | dynamicObj.fromIndex = this.handler.getCurrentPointIndex() - 1; 641 | dynamicObj.freehand = false; 642 | dynamicObj.countSegments++; 643 | } else if (!dynamicObj.freehand) { 644 | // freehand has started 645 | dynamicObj.fromIndex = this.handler.getCurrentPointIndex() - 1; 646 | dynamicObj.freehand = true; 647 | dynamicObj.countSegments++; 648 | } 649 | 650 | this.measurePartial(point, geometry); 651 | dynamicObj.drawing = true; 652 | }, 653 | 654 | /** 655 | * Method: callbackUndo 656 | */ 657 | callbackUndo: function(point, feature) { 658 | var _self = this, 659 | undoLabel = function(layer) { 660 | if (layer) { 661 | var features = layer.features, 662 | lastSegmentIndex = features.length - 1, 663 | lastSegment = features[lastSegmentIndex], 664 | lastSegmentFromIndex = lastSegment.attributes.from, 665 | lastPointIndex = _self.handler.getCurrentPointIndex(); 666 | if (lastSegmentFromIndex >= lastPointIndex) { 667 | var dynamicObj = _self.dynamicObj; 668 | layer.destroyFeatures(lastSegment); 669 | lastSegment = features[lastSegmentIndex - 1]; 670 | dynamicObj.fromIndex = lastSegment.attributes.from; 671 | dynamicObj.countSegments = features.length; 672 | } 673 | } 674 | }; 675 | undoLabel(this.layerSegments); 676 | undoLabel(this.layerHeading); 677 | this.callbackModify(point, feature, true); 678 | }, 679 | 680 | /** 681 | * Method: callbackRedo 682 | */ 683 | callbackRedo: function(point, feature) { 684 | var line = this.handler.line.geometry, 685 | currIndex = this.handler.getCurrentPointIndex(); 686 | var dynamicObj = this.dynamicObj; 687 | this.showLabelSegment( 688 | dynamicObj.countSegments, 689 | dynamicObj.fromIndex, 690 | line.components.slice(dynamicObj.fromIndex, currIndex) 691 | ); 692 | dynamicObj.fromIndex = this.handler.getCurrentPointIndex() - 1; 693 | dynamicObj.countSegments++; 694 | this.callbackModify(point, feature, true); 695 | }, 696 | 697 | /** 698 | * Method: callbackModify 699 | */ 700 | callbackModify: function(point, feature, drawing) { 701 | if (this.immediate) { 702 | this.measureImmediate(point, feature, drawing); 703 | } 704 | 705 | var dynamicObj = this.dynamicObj; 706 | if (dynamicObj.drawing === false) { 707 | return; 708 | } 709 | 710 | var line = this.handler.line.geometry, 711 | currIndex = this.handler.getCurrentPointIndex(); 712 | if (!this.handler.freehandMode(this.handler.evt) && 713 | dynamicObj.freehand) { 714 | // freehand has stopped 715 | dynamicObj.fromIndex = currIndex - 1; 716 | dynamicObj.freehand = false; 717 | dynamicObj.countSegments++; 718 | } 719 | 720 | // total measure 721 | var totalLength = this.getBestLength(line); 722 | if (!totalLength[0]) { 723 | return; 724 | } 725 | var positions = this.positions, 726 | positionGet = { 727 | center: function() { 728 | var center = feature.geometry.getBounds().clone(); 729 | center.extend(point); 730 | center = center.getCenterLonLat(); 731 | return [center.lon, center.lat]; 732 | }, 733 | initial: function() { 734 | var initial = line.components[0]; 735 | return [initial.x, initial.y]; 736 | }, 737 | start: function() { 738 | var start = line.components[dynamicObj.fromIndex]; 739 | return [start.x, start.y]; 740 | }, 741 | middle: function() { 742 | var start = line.components[dynamicObj.fromIndex]; 743 | return [(start.x + point.x) / 2, (start.y + point.y) / 2]; 744 | }, 745 | end: function() { 746 | return [point.x, point.y]; 747 | } 748 | }; 749 | if (this.layerLength) { 750 | this.showLabel( 751 | this.layerLength, 1, 0, totalLength, 752 | positionGet[positions.labelLength](), 1); 753 | } 754 | if (this.isArea) { 755 | if (this.layerArea) { 756 | var totalArea = this.getBestArea(feature.geometry); 757 | if (totalArea[0] || this.layerArea.features.length) { 758 | this.showLabel(this.layerArea, 1, 0, 759 | totalArea, positionGet[positions.labelArea](), 1); 760 | } 761 | } 762 | if (this.showLabelSegment( 763 | 1, 0, [line.components[currIndex], line.components[0]])) { 764 | dynamicObj.countSegments++; 765 | } 766 | } 767 | this.showLabelSegment( 768 | dynamicObj.countSegments, 769 | dynamicObj.fromIndex, 770 | line.components.slice(dynamicObj.fromIndex, currIndex + 1) 771 | ); 772 | }, 773 | 774 | /** 775 | * Function: showLabelSegment 776 | * 777 | * Parameters: 778 | * labelsNumber- {Integer} Number of the labels to be on the label layer. 779 | * fromIndex - {Integer} Index of the last point on the measured feature. 780 | * points - Array({}) 781 | * 782 | * Returns: 783 | * {Boolean} 784 | */ 785 | showLabelSegment: function(labelsNumber, fromIndex, _points) { 786 | var layerSegments = this.layerSegments, 787 | layerHeading = this.layerHeading; 788 | if (!layerSegments && !layerHeading) { 789 | return false; 790 | } 791 | // clone points 792 | var points = [], 793 | pointsLen = _points.length; 794 | for (var i = 0; i < pointsLen; i++) { 795 | points.push(_points[i].clone()); 796 | } 797 | var segmentLength = 798 | this.getBestLength(new OpenLayers.Geometry.LineString(points)); 799 | if (segmentLength[0] == 0) { 800 | return false; 801 | } 802 | var positions = this.positions, 803 | from = points[0], 804 | to = points[pointsLen - 1], 805 | positionGet = { 806 | start: function() { 807 | return [from.x, from.y]; 808 | }, 809 | middle: function() { 810 | return [(from.x + to.x) / 2, (from.y + to.y) / 2]; 811 | }, 812 | end: function() { 813 | return [to.x, to.y]; 814 | } 815 | }, 816 | created = false; 817 | if (layerSegments) { 818 | created = this.showLabel(layerSegments, labelsNumber, fromIndex, 819 | segmentLength, 820 | positionGet[positions.labelSegments](), 821 | this.maxSegments); 822 | } 823 | if (layerHeading) { 824 | var heading = Math.atan2(to.y - from.y, to.x - from.x), 825 | bearing = 90 - heading * 180 / Math.PI; 826 | if (bearing < 0) { 827 | bearing += 360; 828 | } 829 | created = this.showLabel(layerHeading, 830 | labelsNumber, fromIndex, 831 | [bearing, '°'], 832 | positionGet[positions.labelHeading](), 833 | this.maxHeadings) || created; 834 | } 835 | return created; 836 | }, 837 | 838 | /** 839 | * Function: showLabel 840 | * 841 | * Parameters: 842 | * layer - {} Layer of the labels. 843 | * labelsNumber- {Integer} Number of the labels to be on the label layer. 844 | * fromIndex - {Integer} Index of the last point on the measured feature. 845 | * measure - Array({Float|String}) Measure provided by OL Measure control. 846 | * points - Array({Fload}) Array of x and y of the point to draw the label. 847 | * maxSegments - {Integer|Null} Maximum number of visible segments measures 848 | * 849 | * Returns: 850 | * {Boolean} 851 | */ 852 | showLabel: function( 853 | layer, labelsNumber, fromIndex, measure, xy, maxSegments) { 854 | var featureLabel, featureAux, 855 | features = layer.features; 856 | if (features.length < labelsNumber) { 857 | // add a label 858 | featureLabel = new OpenLayers.Feature.Vector( 859 | new OpenLayers.Geometry.Point(xy[0], xy[1]), 860 | {from: fromIndex} 861 | ); 862 | this.setMesureAttributes(featureLabel.attributes, measure); 863 | layer.addFeatures([featureLabel]); 864 | if (maxSegments !== null) { 865 | var hide = (features.length - maxSegments) - 1; 866 | if (hide >= 0) { 867 | featureAux = features[hide]; 868 | featureAux.style = {display: 'none'}; 869 | layer.drawFeature(featureAux); 870 | } 871 | } 872 | return true; 873 | } else { 874 | // update a label 875 | featureLabel = features[labelsNumber - 1]; 876 | var geometry = featureLabel.geometry; 877 | geometry.x = xy[0]; 878 | geometry.y = xy[1]; 879 | geometry.clearBounds(); 880 | this.setMesureAttributes(featureLabel.attributes, measure); 881 | layer.drawFeature(featureLabel); 882 | if (maxSegments !== null) { 883 | var show = (features.length - maxSegments); 884 | if (show >= 0) { 885 | featureAux = features[show]; 886 | if (featureAux.style) { 887 | delete featureAux.style; 888 | layer.drawFeature(featureAux); 889 | } 890 | } 891 | } 892 | return false; 893 | } 894 | }, 895 | 896 | /** 897 | * Method: setMesureAttributes 898 | * Format measure[0] with digits of . Could internationalize the 899 | * format customizing and 900 | * 901 | * 902 | * Parameters: 903 | * attributes - {object} Target attributes. 904 | * measure - Array({*}) 905 | */ 906 | setMesureAttributes: function(attributes, measure) { 907 | attributes.measure = OpenLayers.Number.format( 908 | Number(measure[0].toPrecision(this.accuracy)), null); 909 | attributes.units = measure[1]; 910 | }, 911 | 912 | CLASS_NAME: 'OpenLayers.Control.DynamicMeasure' 913 | }); 914 | 915 | /** 916 | * Constant: OpenLayers.Control.DynamicMeasure.styles 917 | * Contains the keys: "Point", "Line", "Polygon", 918 | * "labelSegments", "labelHeading", "labelLength" and 919 | * "labelArea" as a objects with style keys. 920 | */ 921 | OpenLayers.Control.DynamicMeasure.styles = { 922 | 'Point': { 923 | pointRadius: 4, 924 | graphicName: 'square', 925 | fillColor: 'white', 926 | fillOpacity: 1, 927 | strokeWidth: 1, 928 | strokeOpacity: 1, 929 | strokeColor: '#333333' 930 | }, 931 | 'Line': { 932 | strokeWidth: 2, 933 | strokeOpacity: 1, 934 | strokeColor: '#666666', 935 | strokeDashstyle: 'dash' 936 | }, 937 | 'Polygon': { 938 | strokeWidth: 2, 939 | strokeOpacity: 1, 940 | strokeColor: '#666666', 941 | strokeDashstyle: 'solid', 942 | fillColor: 'white', 943 | fillOpacity: 0.3 944 | }, 945 | labelSegments: { 946 | label: '${measure} ${units}', 947 | fontSize: '11px', 948 | fontColor: '#800517', 949 | fontFamily: 'Verdana', 950 | labelOutlineColor: '#dddddd', 951 | labelAlign: 'cm', 952 | labelOutlineWidth: 2 953 | }, 954 | labelLength: { 955 | label: '${measure} ${units}\n', 956 | fontSize: '11px', 957 | fontWeight: 'bold', 958 | fontColor: '#800517', 959 | fontFamily: 'Verdana', 960 | labelOutlineColor: '#dddddd', 961 | labelAlign: 'lb', 962 | labelOutlineWidth: 3 963 | }, 964 | labelArea: { 965 | label: '${measure}\n${units}²\n', 966 | fontSize: '11px', 967 | fontWeight: 'bold', 968 | fontColor: '#800517', 969 | fontFamily: 'Verdana', 970 | labelOutlineColor: '#dddddd', 971 | labelAlign: 'cm', 972 | labelOutlineWidth: 3 973 | }, 974 | labelHeading: { 975 | label: '${measure} ${units}', 976 | fontSize: '11px', 977 | fontColor: '#800517', 978 | fontFamily: 'Verdana', 979 | labelOutlineColor: '#dddddd', 980 | labelAlign: 'cm', 981 | labelOutlineWidth: 3 982 | } 983 | }; 984 | 985 | /** 986 | * Constant: OpenLayers.Control.DynamicMeasure.positions 987 | * Contains the keys: "labelSegments", "labelHeading", 988 | * "labelLength" and "labelArea" as a strings with values 'start', 989 | * 'middle' and 'end' allowed for all keys (refered of last segment) and 990 | * 'center' and 'initial' (refered of the measured feature and only allowed 991 | * for "labelLength" and "labelArea" keys) 992 | */ 993 | OpenLayers.Control.DynamicMeasure.positions = { 994 | labelSegments: 'middle', 995 | labelLength: 'end', 996 | labelArea: 'center', 997 | labelHeading: 'start' 998 | }; 999 | --------------------------------------------------------------------------------