⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modifyfeature.js

📁 用来在地图上做操作GIS,在地图上做标记
💻 JS
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license. * See http://svn.openlayers.org/trunk/openlayers/release-license.txt  * for the full text of the license. *//** * @requires OpenLayers/Control/DragFeature.js * @requires OpenLayers/Control/SelectFeature.js * @requires OpenLayers/Handler/Keyboard.js *  * Class: OpenLayers.Control.ModifyFeature * Control to modify features.  When activated, a click renders the vertices *     of a feature - these vertices can then be dragged.  By default, the *     delete key will delete the vertex under the mouse.  New features are *     added by dragging "virtual vertices" between vertices.  Create a new *     control with the <OpenLayers.Control.ModifyFeature> constructor. * * Inherits From: *  - <OpenLayers.Control> */OpenLayers.Control.ModifyFeature = OpenLayers.Class(OpenLayers.Control, {    /**     * APIProperty: geometryTypes     * {Array(String)} To restrict modification to a limited set of geometry     *     types, send a list of strings corresponding to the geometry class     *     names.     */    geometryTypes: null,    /**     * Property: layer     * {<OpenLayers.Layer.Vector>}     */    layer: null,        /**     * Property: feature     * {<OpenLayers.Feature.Vector>} Feature currently available for modification.     */    feature: null,        /**     * Property: vertices     * {Array(<OpenLayers.Feature.Vector>)} Verticies currently available     *     for dragging.     */    vertices: null,        /**     * Property: virtualVertices     * {Array(<OpenLayers.Feature.Vector>)} Virtual vertices in the middle     *     of each edge.     */    virtualVertices: null,    /**     * Property: selectControl     * {<OpenLayers.Control.Select>}     */    selectControl: null,        /**     * Property: dragControl     * {<OpenLayers.Control.DragFeature>}     */    dragControl: null,        /**     * Property: keyboardHandler     * {<OpenLayers.Handler.Keyboard>}     */    keyboardHandler: null,        /**     * APIProperty: deleteCodes     * {Array(Integer)} Keycodes for deleting verticies.  Set to null to disable     *     vertex deltion by keypress.  If non-null, keypresses with codes     *     in this array will delete vertices under the mouse. Default     *     is 46 and 100, the 'delete' and lowercase 'd' keys.     */    deleteCodes: null,    /**     * APIProperty: virtualStyle     * {<OpenLayers.Feature.Vector.Style>}     */    virtualStyle: null,        /**     * APIProperty: onModificationStart      * {Function} Optional function to be called when a feature is selected     *     to be modified. The function should expect to be called with a     *     feature.  This could be used for example to allow to lock the     *     feature on server-side.     */    onModificationStart: function() {},    /**     * APIProperty: onModification     * {Function} Optional function to be called when a feature has been     *     modified.  The function should expect to be called with a feature.     */    onModification: function() {},    /**     * APIProperty: onModificationEnd     * {Function} Optional function to be called when a feature is finished      *     being modified.  The function should expect to be called with a     *     feature.     */    onModificationEnd: function() {},    /**     * Constructor: OpenLayers.Control.ModifyFeature     * Create a new modify feature control.     *     * Parameters:     * layer - {<OpenLayers.Layer.Vector>} Layer that contains features that     *     will be modified.     * options - {Object} Optional object whose properties will be set on the     *     control.     */    initialize: function(layer, options) {        this.layer = layer;        this.vertices = [];        this.virtualVertices = [];        this.styleVirtual = OpenLayers.Util.extend({}, this.layer.style);        this.styleVirtual.fillOpacity = 0.3;        this.styleVirtual.strokeOpacity = 0.3;        this.deleteCodes = [46, 100];        OpenLayers.Control.prototype.initialize.apply(this, [options]);        if(!(this.deleteCodes instanceof Array)) {            this.deleteCodes = [this.deleteCodes];        }        var control = this;        // configure the select control        var selectOptions = {            geometryTypes: this.geometryTypes,            onSelect: function(feature) {                control.selectFeature.apply(control, [feature]);            },            onUnselect: function(feature) {                control.unselectFeature.apply(control, [feature]);            }        };        this.selectControl = new OpenLayers.Control.SelectFeature(            layer, selectOptions        );        // configure the drag control        var dragOptions = {            geometryTypes: ["OpenLayers.Geometry.Point"],            snappingOptions: this.snappingOptions,            onStart: function(feature, pixel) {                control.dragStart.apply(control, [feature, pixel]);            },            onDrag: function(feature) {                control.dragVertex.apply(control, [feature]);            },            onComplete: function(feature) {                control.dragComplete.apply(control, [feature]);            }        };        this.dragControl = new OpenLayers.Control.DragFeature(            layer, dragOptions        );        // configure the keyboard handler        var keyboardOptions = {            keypress: this.handleKeypress        };        this.keyboardHandler = new OpenLayers.Handler.Keyboard(            this, keyboardOptions        );    },    /**     * APIMethod: destroy     * Take care of things that are not handled in superclass.     */    destroy: function() {        this.layer = null;        this.selectControl.destroy();        this.dragControl.destroy();        this.keyboardHandler.destroy();        OpenLayers.Control.prototype.destroy.apply(this, []);    },    /**     * APIMethod: activate     * Activate the control and the feature handler.     *      * Returns:     * {Boolean} Successfully activated the control and feature handler.     */    activate: function() {        return (this.selectControl.activate() &&                this.keyboardHandler.activate() &&                OpenLayers.Control.prototype.activate.apply(this, arguments));    },    /**     * APIMethod: deactivate     * Deactivate the controls.     *     * Returns:      * {Boolean} Successfully deactivated the control.     */    deactivate: function() {        var deactivated = false;        // the return from the controls is unimportant in this case        if(OpenLayers.Control.prototype.deactivate.apply(this, arguments)) {            this.layer.removeFeatures(this.vertices);            this.layer.removeFeatures(this.virtualVertices);            this.vertices = [];            this.dragControl.deactivate();            if(this.feature) {                this.selectControl.unselect.apply(this.selectControl,                                                  [this.feature]);            }            this.selectControl.deactivate();            this.keyboardHandler.deactivate();            deactivated = true;        }        return deactivated;    },    /**     * Method: selectFeature     * Called when the select feature control selects a feature.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -