-
Notifications
You must be signed in to change notification settings - Fork 15
/
label.js
57 lines (53 loc) · 2.16 KB
/
label.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
import { centroid } from "../helpers/centroid.js";
import { figuration } from "../helpers/figuration.js";
export function label(selection, projection, planar, options = {}, clipid) {
let geojson = options.geojson;
let values = options.values;
let fill = options.fill ? options.fill : "#474342";
let fontSize = options.fontSize ? options.fontSize : 10;
let fontFamily = options.fontFamily ? options.fontFamily : "Roboto";
let textDecoration = options.textDecoration ? options.textDecoration : "none";
let fontWeight = options.fontWeight ? options.fontWeight : "normal";
let fontStyle = options.fontStyle ? options.fontStyle : "normal";
let opacity = options.opacity != undefined ? options.opacity : 1;
let halo = options.halo == true ? true : false;
let halo_style = options.halo_style ? options.halo_style : ["white", 4, 0.5];
//const features = centroid(geojson, { planar: planar }).features;
let features;
if (figuration(geojson) == "p") {
features = geojson.features;
} else {
features = centroid(geojson, { planar: planar }).features;
}
selection
.append("g")
.attr("class", options.id)
.attr("data-layer", JSON.stringify({ _type: "label" }))
.attr("data-layer", undefined)
.selectAll("text")
.data(
features
.filter((d) => d.geometry.coordinates != undefined)
.filter((d) => d.properties[values] != undefined)
)
.join("text")
.attr("class", "onglobe_coords")
.attr("x", (d) => projection(d.geometry.coordinates)[0])
.attr("y", (d) => projection(d.geometry.coordinates)[1])
.attr("fill", fill)
.attr("opacity", opacity)
.attr("font-size", fontSize)
.attr("font-family", fontFamily)
.attr("font-style", fontStyle)
.attr("text-decoration", textDecoration)
.attr("font-weight", fontWeight)
.attr("text-anchor", "middle")
.attr("dominant-baseline", "middle")
.attr("paint-order", "stroke")
.attr("stroke", halo ? halo_style[0] : "none")
.attr("stroke-width", halo ? halo_style[1] : 0)
.attr("stroke-opacity", halo ? halo_style[2] : 0)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.text((d) => d.properties[values]);
}