Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit bd58a64

Browse files
author
Explv
committed
Use cache generated map labels
1 parent fff808e commit bd58a64

File tree

5 files changed

+15585
-434
lines changed

5 files changed

+15585
-434
lines changed

js/controls/location_lookup_control.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export var LocationLookupControl = L.Control.extend({
2323
Locations.getLocations(function(locations) {
2424
var locationsArray = $.map(locations, function (value, key) {
2525
return {
26-
label: value.name,
26+
label: value.name.replace(/<br>/g, ' '),
2727
value: value.position
2828
}
2929
});

js/controls/map_label_control.js

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,30 @@ var MapLabelsCanvas = CanvasLayer.extend({
2323
continue;
2424
}
2525

26+
// Map textScale values to font sizes
2627
let fontSize;
27-
let fontColour;
28-
29-
// Scale the font, and change colour based on location size
30-
switch (locations[i].size) {
31-
case 'default':
32-
fontSize = 0.08
33-
fontColour = 'white';
34-
break;
35-
case 'medium':
36-
fontSize = 0.10
37-
fontColour = 'white';
38-
break;
39-
case 'large':
40-
fontSize = 0.18
41-
fontColour = '#ffaa00';
28+
if (typeof locations[i].size === 'number') {
29+
switch (locations[i].size) {
30+
case 0:
31+
fontSize = 0.08; // default
32+
break;
33+
case 1:
34+
fontSize = 0.10; // medium
35+
break;
36+
case 2:
37+
fontSize = 0.18; // large
38+
break;
39+
default:
40+
fontSize = 0.08;
41+
}
42+
} else {
43+
fontSize = 0.08; // fallback
44+
}
45+
46+
// Convert textColor from decimal to hex, with fallback
47+
let fontColour = 'white';
48+
if (locations[i].color) {
49+
fontColour = '#' + locations[i].color.toString(16).padStart(6, '0');
4250
}
4351

4452
// Scale font size to match zoom
@@ -53,25 +61,31 @@ var MapLabelsCanvas = CanvasLayer.extend({
5361

5462
const name = locations[i].name
5563

56-
const words = name.split(' ')
57-
64+
// First split by <br> tags to handle explicit line breaks
65+
const brLines = name.split('<br>')
5866
const lines = []
5967

60-
let line = "";
61-
words.forEach(word => {
62-
if ((line + word).length < 10) {
63-
if (line !== "") {
64-
line += " "
68+
brLines.forEach(brLine => {
69+
const words = brLine.trim().split(' ')
70+
71+
let line = "";
72+
words.forEach(word => {
73+
if ((line + word).length < 10) {
74+
if (line !== "") {
75+
line += " "
76+
}
77+
line += word
78+
} else {
79+
if (line !== "") {
80+
lines.push(line);
81+
}
82+
line = word;
6583
}
66-
line += word
67-
} else {
84+
})
85+
if (line !== "") {
6886
lines.push(line);
69-
line = word;
7087
}
7188
})
72-
if (line !== "") {
73-
lines.push(line);
74-
}
7589

7690
let y = canvasPoint.y;
7791
lines.forEach(line => {

js/model/Locations.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ class Locations {
1515
}
1616

1717
$.ajax({
18-
url: "resources/locations.json",
18+
url: "resources/map_labels.json",
1919
dataType: "json",
2020
context: this,
2121
success: function( data ) {
22-
var locations = data["locations"];
23-
24-
for (var i in locations) {
22+
for (var i = 0; i < data.length; i++) {
2523
this.locations.push({
26-
"name": locations[i].name,
27-
"position": new Position(locations[i].coords[0], locations[i].coords[1], locations[i].coords[2]),
28-
"size": locations[i].size
24+
"name": data[i].name,
25+
"position": new Position(data[i].worldX, data[i].worldY, data[i].plane),
26+
"size": data[i].textScale,
27+
"color": data[i].textColor
2928
});
3029
}
3130

0 commit comments

Comments
 (0)