comparison geotemco/js/Map/MapControl.js @ 0:b12c99b7c3f0

commit for previous development
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Mon, 19 Jan 2015 17:13:49 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b12c99b7c3f0
1 /*
2 * MapControl.js
3 *
4 * Copyright (c) 2012, Stefan Jänicke. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22 /**
23 * @class MapControl
24 * Generic map control interface
25 * @author Stefan Jänicke (stjaenicke@informatik.uni-leipzig.de)
26 * @release 1.0
27 * @release date: 2012-07-27
28 * @version date: 2012-07-27
29 */
30 function MapControl(map, button, label, onActivate, onDeactivate) {
31
32 var control = this;
33 this.button = button;
34 this.enabled = true;
35 this.activated = false;
36 this.label = label;
37
38 if (this.button != null) {
39 $(this.button).addClass(label + 'Deactivated');
40 $(this.button).attr("title", GeoTemConfig.getString(GeoTemConfig.language, label));
41 //vhz
42 $(this.button).click(function() {
43 control.checkStatus();
44 });
45 }
46
47 this.checkStatus = function() {
48 if (control.enabled) {
49 if ( typeof map.activeControl != 'undefined') {
50 if (control.activated) {
51 control.deactivate();
52 } else {
53 map.activeControl.deactivate();
54 control.activate();
55 }
56 } else {
57 control.activate();
58 }
59 }
60 };
61
62 this.setButtonClass = function(removeClass, addClass) {
63 if (this.button != null) {
64 $(this.button).removeClass(label + removeClass);
65 $(this.button).addClass(label + addClass);
66 $(this.button).attr("title", GeoTemConfig.getString(GeoTemConfig.language, label));
67 }
68 };
69
70 this.disable = function() {
71 this.enabled = false;
72 this.setButtonClass('Deactivated', 'Disabled');
73 };
74
75 this.enable = function() {
76 this.enabled = true;
77 this.setButtonClass('Disabled', 'Deactivated');
78 };
79
80 this.activate = function() {
81 onActivate();
82 this.activated = true;
83 this.setButtonClass('Deactivated', 'Activated');
84 map.activeControl = this;
85 };
86
87 this.deactivate = function() {
88 onDeactivate();
89 this.activated = false;
90 this.setButtonClass('Activated', 'Deactivated');
91 map.activeControl = undefined;
92 };
93
94 };