-
Notifications
You must be signed in to change notification settings - Fork 6
/
_base.js
90 lines (80 loc) · 1.98 KB
/
_base.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
define([
"dojo/_base/lang",
"dojo/_base/array"
], function(lang, array){
var d = {
defaultLayerID: "ROADMAP",
defaultEngine: "djeo",
// registry of feature constructors
featureTypes: {},
// supported events
events: {mouseover: 1, mouseout: 1, click: 1, mousemove: 1, contextmenu: 1}
};
var deps = {};
d.dependencies = deps;
d.registerDependency = function(moduleId, func) {
deps[moduleId] = func || 1;
};
d.defaultStyle = [
{
stroke: "black",
strokeWidth: 0.5,
strokeOpacity: 1,
fill: "#B7B7B7",
fillOpacity: 0.8,
shape: "square", // circle, square, triangle, star, cross, or x
size: 10
},
{
theme: "highlight",
stroke: "orange",
area: {strokeWidth: 3},
rScale: 1.5
}
];
d.getLayerClassId = function(/* String */layerId) {
// check if we've got a complex structure like "layerClassId:url"
var colonIndex = layerId.indexOf(":");
return (colonIndex > 0) ? layerId.substring(0, colonIndex) : layerId;
};
d.getTraversedAttr = function(feature, attr) {
// current feature
var f = feature;
while (f) {
var attrValue = f[attr];
if (attrValue !== undefined) {
return attrValue;
}
f = f.parent;
}
};
d.forEach = function(features, callback, thisObject) {
if (!lang.isArray(features)) features = [features];
array.forEach(features, function(feature){
if (feature.isContainer) forEachIn(feature, callback, thisObject);
else callback.call(thisObject, feature);
});
};
function forEachIn(featureContainer, callback, thisObject) {
var features = featureContainer.features,
numFeatures = features.length
;
array.forEach(features, function(feature){
if (feature.isContainer) {
forEachIn(feature, callback, thisObject)
}
else {
callback.call(thisObject, feature);
}
});
}
// building array of scales; array index corresponds to zoom
// scale is the number of pixels per map projection unit
// scale = 256*2^zoom/(2*Math.PI*earthRadius)
var scales = [1/156543.034];
for(var i=1; i<20; i++) {
scales[i] = 2 * scales[i-1];
}
d.scales = scales;
return d;
});