-
Notifications
You must be signed in to change notification settings - Fork 6
/
coordArray.js
64 lines (52 loc) · 1.33 KB
/
coordArray.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
define([
"dojo/_base/declare",
"./_base"
], function(declare, djeo){
var dependency = "CoordArray";
djeo.registerDependency(dependency);
return {
push: function(feature, point) {
var factory = this._getFactory(feature);
if (!factory) return;
var _coords = feature.getCoords(),
_point = feature.map.getCoords(point)
;
if (feature.getCoordsType() == "LineString") {
_coords.push(_point);
if (feature.coords != _coords) {
feature.coords.push(point);
}
}
factory.push(feature, point);
},
set: function(feature, index, point) {
var factory = this._getFactory(feature);
if (!factory) return;
var _coords = feature.getCoords(),
_point = feature.map.getCoords(point)
;
if (feature.getCoordsType() == "LineString") {
_coords[index] = _point;
if (feature.coords != _coords) {
feature.coords[index] = point;
}
}
factory.set(feature, index, point);
},
remove: function(feature, index) {
var factory = this._getFactory(feature);
if (!factory) return;
var _coords = feature.getCoords();
if (feature.getCoordsType() == "LineString") {
_coords.splice(index, 1);
if (feature.coords != _coords) {
feature.coords.splice(index, 1);
}
}
factory.remove(feature, index);
},
_getFactory: function(feature) {
return feature.map.engine.getFactory(dependency);
}
};
});