-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFeature.js
124 lines (101 loc) · 2.6 KB
/
Feature.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
define([
"dojo/_base/declare", // declare
"dojo/_base/lang", // mixin, isArray, isString
"dojo/_base/array", // forEach
"./Style",
"./util/_base"
], function(declare, lang, array, Style, u){
return declare(null, {
// summary:
// The base class for all map features.
id: null,
visible: true,
bbox: null,
style: null,
parent: null,
map: null,
constructor: function(featureDef, kwArgs) {
if (kwArgs) lang.mixin(this, kwArgs);
if (featureDef) lang.mixin(this, featureDef);
if (!this.id) this.id = "_geo_"+u.uid();
if (this.styleClass && !lang.isArray(this.styleClass)) this.styleClass = [this.styleClass];
if (featureDef && featureDef.style) {
this.style = null;
this.addStyle(featureDef.style, true);
}
},
setMap: function(map) {
this.map = map;
if (this.styleClass) {
array.forEach(this.styleClass, function(_class){
var featuresByClass = map.featuresByClass;
if (!featuresByClass[_class]) featuresByClass[_class] = [];
featuresByClass[_class].push(this);
}, this);
}
},
setParent: function(parent) {
this.parent = parent;
},
set: function(attr, value) {
// setter name
var name = "_set_"+attr,
setter = this[name]
;
return setter && setter.call(this, value);
},
get: function(attr) {
// check if we have a getter function
var name = "_get_"+attr,
getter = this[name],
result
;
if (getter) {
result = getter.call(this);
}
else {
result = this.map.useAttrs ? (this.attrs && this.attrs[attr]!==undefined ? this.attrs[attr] : this[attr]) : this[attr];
}
return result;
},
addStyle: function(/* Array|Object */style, /* Boolean */preventRendering) {
if (!lang.isArray(style)) style = [style];
array.forEach(style, function(_style){
var s = new Style(_style, this.map);
if (!s.styleClass && !s.fid) {
s._features[this.id] = this;
if (!this.style) this.style = [];
this.style.push(s);
}
}, this);
if (!preventRendering) this.render();
},
render: function() {
},
toggleVisibility: function() {
this.show(!this.visible);
},
getBbox: function() {
return this.bbox;
},
on: function(/* String|Array? */events, /*Function*/ method, /*Object?*/ context) {
var map = this.map,
handle = this.onForHandle(null, {
events: lang.isString(events) ? [events] : events,
context: context,
method: method
})
;
return {
remove: function(feature) {
if (feature) feature.disconnect(handle);
else map.disconnect(handle);
}
};
},
onForHandle: function(/* String|Number */ handle, /*Object*/ kwArgs) {
},
disconnect: function(handle, key, keepIfKey) {
}
});
});