-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathstatic-label.js
More file actions
99 lines (90 loc) · 2.68 KB
/
static-label.js
File metadata and controls
99 lines (90 loc) · 2.68 KB
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
/**
* Created by Nicholas Hallahan <nhallahan@spatialdev.com>
* on 8/15/14.
*/
var opts = {
url: "http://spatialserver.spatialdev.com/services/vector-tiles/gadm2014kenya/{z}/{x}/{y}.pbf",
debug: true,
clickableLayers: ['gadm0', 'gadm1', 'gadm2', 'gadm3', 'gadm4', 'gadm5'],
getIDForLayerFeature: function(feature) {
return feature.properties.id;
},
/**
* The filter function gets called when iterating though each vector tile feature (vtf). You have access
* to every property associated with a given feature (the feature, and the layer). You can also filter
* based of the context (each tile that the feature is drawn onto).
*
* Returning false skips over the feature and it is not drawn.
*
* @param feature
* @returns {boolean}
*/
filter: function(feature, context) {
if (feature.layer.name === 'gadm1_label' || feature.layer.name === 'gadm1') {
return true;
}
return false;
},
/**
* When we want to link events between layers, like clicking on a label and a
* corresponding polygon freature, this will return the corresponding mapping
* between layers. This provides knowledge of which other feature a given feature
* is linked to.
*
* @param layerName the layer we want to know the linked layer from
* @returns {string} returns corresponding linked layer
*/
layerLink: function(layerName) {
if (layerName.indexOf('_label') > -1) {
return layerName.replace('_label','');
}
return layerName + '_label';
},
style: function(feature) {
var style = {};
var selected = style.selected = {};
var type = feature.type;
switch (type) {
case 1: //'Point'
// unselected
style.color = '#ff0000';
style.radius = 3;
// selected
selected.color = 'rgba(255,255,0,0.5)';
selected.radius = 5;
break;
case 2: //'LineString'
// unselected
style.color = 'rgba(161,217,155,0.8)';
style.size = 3;
// selected
selected.color = 'rgba(255,25,0,0.5)';
selected.size = 3;
break;
case 3: //'Polygon'
// unselected
style.color = 'rgba(149,139,255,0.4)';
style.outline = {
color: 'rgb(20,20,20)',
size: 2
};
// selected
selected.color = 'rgba(255,25,0,0.3)';
selected.outline = {
color: '#d9534f',
size: 3
};
}
if (feature.layer.name === 'gadm1_label') {
style.staticLabel = function() {
var style = {
html: feature.properties.name,
iconSize: [125,30],
cssClass: 'label-icon-text'
};
return style;
};
}
return style;
}
}