Skip to content

Commit 3a2eaf9

Browse files
committed
move link descriptions to json.
1 parent 2ad4152 commit 3a2eaf9

File tree

3 files changed

+21
-34
lines changed

3 files changed

+21
-34
lines changed

buttons.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
]},
7575
{ "id": "more", "name": "", "class": "directory", "source": [
7676
{ "id": "reset", "class": "reset" },
77-
{ "id": "heat" },
78-
{ "id": "osm" },
79-
{ "id": "g" },
77+
{ "id": "heat", "class": "externalLink", "url": "https://www.strava.com/maps/global-heatmap?style=dark&terrain=false&sport=Ride&gColor=red#{z}/{latitude}/{longitude}" },
78+
{ "id": "osm", "class": "externalLink", "url": "https://www.openstreetmap.org/edit#map={z1}/{latitude}/{longitude}" },
79+
{ "id": "g", "class": "externalLink", "url": "https://www.google.com/maps/@{latitude},{longitude},{z1}z" },
8080
{ "id": "about-menu", "name": "about", "class": "about" }
8181
]}
8282
]

src/button.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface CyclemapLayerSpecification {
2020
id: string;
2121
name?: string;
2222
class?: string;
23+
url?: string;
2324
group?: string;
2425
type?: string;
2526
source: SourceSpecification | CyclemapLayerSpecification[];
@@ -354,18 +355,18 @@ class ExternalLinkButton extends Button {
354355
select() {
355356
super.select();
356357
super.deselect();
357-
const url = this.getUrl();
358-
if(url !== undefined) {
359-
window.open(url);
360-
}
361-
}
362-
getUrl() {
363-
switch(this.layer.id) {
364-
case 'osm': return `https://www.openstreetmap.org/edit#map=${this.buttonControl.mainControl.getOsmPoint()}`;
365-
case 'heat': return `https://www.strava.com/heatmap#${this.buttonControl.mainControl.getHeatmapPoint()}/hot/ride`;
366-
case 'g': return `https://www.google.com/maps/@${this.buttonControl.mainControl.getGPoint()}z`;
367-
default: console.error(`external link not found ${this.layer.id}`); break;
358+
let url = this.layer.url;
359+
if(url === undefined) {
360+
console.error('url not defined');
361+
return;
368362
}
363+
const map = this.buttonControl.map!;
364+
url = url
365+
.replace("{z1}", (map.getZoom() + 1).toFixed(0))
366+
.replace("{z}", (map.getZoom()).toFixed(0))
367+
.replace("{latitude}", map.getCenter().lat.toFixed(5))
368+
.replace("{longitude}", map.getCenter().lng.toFixed(5));
369+
window.open(url);
369370
}
370371
}
371372

@@ -458,11 +459,13 @@ export class ButtonControl implements IControl {
458459
};
459460

460461
generateButton(layer: CyclemapLayerSpecification) {
461-
const className = layer.class != undefined ? layer.class : 'externalLink';
462-
if(!(className in this.generatorMap)) {
463-
console.error(`could not find class ${className} in generator map`);
462+
if(layer.class === undefined) {
463+
layer.class = 'externalLink';
464+
}
465+
if(!(layer.class in this.generatorMap)) {
466+
console.error(`could not find class ${layer.class} in generator map`);
464467
}
465-
return this.generatorMap[className](layer);
468+
return this.generatorMap[layer.class](layer);
466469
}
467470

468471
addLayerButton(layer: CyclemapLayerSpecification, root: HTMLElement | null = null) {

src/main.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,6 @@ export class MainControl implements IControl {
119119

120120
return buttons != null ? buttons : 'buttons.json';
121121
}
122-
123-
124-
getHeatmapPoint() {
125-
var zoom = this.map.getZoom() + 1;
126-
return `${zoom.toFixed(1)}/${util.reversedPointToString(this.map.getCenter()).replace(",","/")}`;
127-
}
128-
129-
getOsmPoint() {
130-
var zoom = this.map.getZoom() + 1;
131-
return `${zoom.toFixed(0)}/${util.pointToString(this.map.getCenter()).replace(",","/")}`;
132-
}
133-
134-
getGPoint() {
135-
var zoom = this.map.getZoom() + 1;
136-
return `${util.pointToString(this.map.getCenter())},${zoom.toFixed(0)}`;
137-
}
138122
}
139123

140124
export const mainControl = new MainControl();

0 commit comments

Comments
 (0)