Skip to content

Commit

Permalink
fix bug with osm button.
Browse files Browse the repository at this point in the history
  • Loading branch information
arichnad committed Feb 5, 2024
1 parent 25bf4d4 commit 1648951
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions dist/cyclemaps.js

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@
<div id="about" class="about" onClick="document.getElementById('about').style.display = 'none';"><div class="border">
<ul>
<li>if you notice a problem, please
<a class="osm-link" href="#" onclick="
window.open(`https://www.openstreetmap.org/edit#map=${window.mainControl.getOsmPoint()}`);
">edit osm</a></li>
<a class="osm-link" href="#" onclick="window.mainControl.openOsmEdit();">edit osm</a></li>
<li>"surface" is how we know what is unpaved</li>
<li>changes to osm take two weeks to propagate</li>
</ul>
Expand Down Expand Up @@ -214,9 +212,7 @@
</ul>

<p>if you notice an issue that can't be fixed by
<a class="osm-link" href="#" onclick="
window.open(`https://www.openstreetmap.org/edit#map=${window.mainControl.getOsmPoint()}`);
">editing osm</a>,
<a class="osm-link" href="#" onclick="window.mainControl.openOsmEdit();">editing osm</a>,
please <a href="https://github.com/cyclemap/openmaptiles-cycle/issues/new">file a ticket</a>. if you see a route that SHOULDN'T be a bike route, we want to hear from you: please <a href="https://github.com/cyclemap/openmaptiles-cycle/issues/new">file a ticket</a>!</p>
</div></div>
<script>
Expand Down
9 changes: 5 additions & 4 deletions src/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class LayerIdsButton extends Button {
}
}

class ExternalLinkButton extends Button {
export class ExternalLinkButton extends Button {
constructor(layer: CyclemapLayerSpecification, buttonControl: ButtonControl) {
super(layer, buttonControl);
}
Expand All @@ -360,13 +360,14 @@ class ExternalLinkButton extends Button {
console.error('url not defined');
return;
}
const map = this.buttonControl.map!;
url = url
window.open(ExternalLinkButton.formatUrl(this.buttonControl.map!, url));
}
static formatUrl(map: Map, url: string) {
return url
.replace("{z1}", (map.getZoom() + 1).toFixed(0))
.replace("{z}", (map.getZoom()).toFixed(0))
.replace("{latitude}", map.getCenter().lat.toFixed(5))
.replace("{longitude}", map.getCenter().lng.toFixed(5));
window.open(url);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { ButtonControl } from './button.js';
import { ButtonControl, ExternalLinkButton } from './button.js';
import { SaveControl } from './save.js';
import { RouteControl } from './route.js';
import * as util from './util.js';
Expand Down Expand Up @@ -119,6 +119,10 @@ export class MainControl implements IControl {

return buttons != null ? buttons : 'buttons.json';
}

openOsmEdit() {
window.open(ExternalLinkButton.formatUrl(this.map!, 'https://www.openstreetmap.org/edit#map={z1}/{latitude}/{longitude}'));
}
}

export const mainControl = new MainControl();
Expand Down

0 comments on commit 1648951

Please sign in to comment.