All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mware.web.product.map.controlBar.js Maven / Gradle / Ivy

The newest version!
/*
 * This file is part of the BigConnect project.
 *
 * Copyright (c) 2013-2020 MWARE SOLUTIONS SRL
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation with the addition of the
 * following permission added to Section 15 as permitted in Section 7(a):
 * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
 * MWARE SOLUTIONS SRL, MWARE SOLUTIONS SRL DISCLAIMS THE WARRANTY OF
 * NON INFRINGEMENT OF THIRD PARTY RIGHTS
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA, 02110-1301 USA, or download the license from the following URL:
 * https://www.gnu.org/licenses/agpl-3.0.txt
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License.
 *
 * You can be released from the requirements of the license by purchasing
 * a commercial license. Buying such a license is mandatory as soon as you
 * develop commercial activities involving the BigConnect software without
 * disclosing the source code of your own applications.
 *
 * These activities include: offering paid services to customers as an ASP,
 * embedding the product in a web application, shipping BigConnect with a
 * closed source product.
 */
define(['openlayers'], function (ol) {
    'use strict';

    /**
     * Control bar for OL3
     * The control bar is a container for other controls. It can be used to create toolbars.
     * Control bars can be nested and combined with ol.control.Toggle to handle activate/deactivate.
     *
     * @constructor
     * @extends {ol.control.Control}
     * @param {Object=} opt_options Control options.
     *        className {String} class of the control
     *        group {bool} is a group, default false
     *        toggleOne {bool} only one toggle control is active at a time, default false
     *        autoDeactivate {bool} used with subbar to deactivate all control when top level control deactivate, default false
     *        controls {Array} a list of control to add to the bar
     */
    ol.control.Bar = function (options) {
        if (!options) options = {};
        var element = $("
").addClass('ol-unselectable ol-control ol-bar'); if (options.className) element.addClass(options.className); if (options.group) element.addClass('ol-group'); ol.control.Control.call(this, { element: element.get(0), target: options.target }); this.set('toggleOne', options.toggleOne); this.set('autoDeactivate', options.autoDeactivate); this.controls_ = []; if (options.controls instanceof Array) { for (var i = 0; i < options.controls.length; i++) { this.addControl(options.controls[i]); } } }; ol.inherits(ol.control.Bar, ol.control.Control); /** * Set the control visibility * @param {boolean} b */ ol.control.Bar.prototype.setVisible = function (val) { if (val) $(this.element).show(); else $(this.element).hide(); } /** * Get the control visibility * @return {boolean} b */ ol.control.Bar.prototype.getVisible = function () { return ($(this.element).css('display') != 'none'); } /** * Set the map instance the control is associated with * and add its controls associated to this map. * @param {ol.Map} map The map instance. */ ol.control.Bar.prototype.setMap = function (map) { ol.control.Control.prototype.setMap.call(this, map); for (var i = 0; i < this.controls_.length; i++) { var c = this.controls_[i]; // map.addControl(c); c.setMap(map); } }; /** * Get controls in the panel * @param {Array} */ ol.control.Bar.prototype.getControls = function () { return this.controls_; }; /** * Set tool bar position * @param {top|left|bottom|right} */ ol.control.Bar.prototype.setPosition = function (pos) { $(this.element).removeClass('ol-left ol-top ol-bottom ol-right'); pos = pos.split('-'); for (var i = 0; i < pos.length; i++) { switch (pos[i]) { case 'top': case 'left': case 'bottom': case 'right': $(this.element).addClass("ol-" + pos[i]); break; default: break; } } }; /** * Add a control to the bar * @param {ol.control} c control to add */ ol.control.Bar.prototype.addControl = function (c) { this.controls_.push(c); c.setTarget(this.element); if (this.getMap()) { this.getMap().addControl(c); } // Activate and toogleOne c.on('change:active', this.onActivateControl_, this); if (c.getActive && c.getActive()) { c.dispatchEvent({type: 'change:active', key: 'active', oldValue: false, active: true}); } }; /** * Deativate all controls in a bar * @param {ol.control} except a control */ ol.control.Bar.prototype.deactivateControls = function (except) { for (var i = 0; i < this.controls_.length; i++) { if (this.controls_[i] !== except && this.controls_[i].setActive) { this.controls_[i].setActive(false); } } }; /** * Auto activate/deactivate controls in the bar * @param {boolean} b activate/deactivate */ ol.control.Bar.prototype.setActive = function (b) { if (!b && this.get("autoDeactivate")) { this.deactivateControls(); } if (b) { var ctrls = this.getControls(); for (var i = 0, sb; (sb = ctrls[i]); i++) { if (sb.get("autoActivate")) sb.setActive(true); } } } /** * Post-process an activated/deactivated control * @param {ol.event} an object with a target {ol.control} and active flag {bool} */ ol.control.Bar.prototype.onActivateControl_ = function (e) { if (!e.active || !this.get('toggleOne')) return; var n; var ctrl = e.target; for (n = 0; n < this.controls_.length; n++) { if (this.controls_[n] === ctrl) break; } // Not here! if (n == this.controls_.length) return; this.deactivateControls(this.controls_[n]); }; /** A simple push button control * * @constructor * @extends {ol.control.Control} * @param {Object=} opt_options Control options. * className {String} class of the control * title {String} title of the control * html {String} html to insert in the control * handleClick {function} callback when control is clicked (or use change:active event) */ ol.control.Button = function (options) { options = options || {}; var element = $("
").addClass((options.className || "") + ' ol-button ol-unselectable ol-control'); var self = this; $("




© 2015 - 2024 Weber Informatics LLC | Privacy Policy