-
Notifications
You must be signed in to change notification settings - Fork 0
/
KI_1_style.js
72 lines (58 loc) · 2.19 KB
/
KI_1_style.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
var size = 0;
var style_KI_1 = function(feature, resolution){
var context = {
feature: feature,
variables: {}
};
var value = ""
var labelText = "";
size = 0;
var labelFont = "9.75px \'MS Shell Dlg 2\', sans-serif";
var labelFill = "rgba(0, 0, 0, 1)";
var textAlign = "left";
var offsetX = 8;
var offsetY = 3;
if ("" !== null) {
labelText = String("");
}
var style = [ new ol.style.Style({
image: new ol.style.RegularShape({radius: 4.0 + size, points: 3,
stroke: new ol.style.Stroke({color: 'rgba(0,0,0,1.0)', lineDash: null, lineCap: 'butt', lineJoin: 'miter', width: 0}), fill: new ol.style.Fill({color: 'rgba(0,251,96,1.0)'})}),
text: createTextStyle(feature, resolution, labelText, labelFont,
labelFill)
})];
return style;
}
function update() {
var features = lyr_KI_1.getSource().getFeatures();
features.forEach(function(feature){
var context = {
feature: feature,
variables: {}
};
// Get the label text as a string
var text = "";
// Get the center point in pixel space
var center = ol.extent.getCenter(feature.getGeometry().getExtent());
var pixelCenter = map.getPixelFromCoordinate(center);
var size = 12;
var halfText = (size + 1) * (text.length / 4);
// Create a bounding box for the label using known pixel heights
var minx = parseInt(pixelCenter[0] - halfText);
var maxx = parseInt(pixelCenter[0] + halfText);
var maxy = parseInt(pixelCenter[1] - (size / 2));
var miny = parseInt(pixelCenter[1] + (size / 2));
// Get bounding box points back into coordinate space
var min = map.getCoordinateFromPixel([minx, miny]);
var max = map.getCoordinateFromPixel([maxx, maxy]);
// Create the bounds
var bounds = {
bottomLeft: min,
topRight: max
};
// Weight longer labels higher, use their name as the ID
labelEngine.ingestLabel(bounds, text, text.length, feature)
});
// Call the label callbacks for showing and hiding
labelEngine.update();
};