Skip to content

Commit c80da47

Browse files
committed
feat!: Switched map tile provider (close #424)
1 parent 12389ab commit c80da47

File tree

2 files changed

+49
-16
lines changed

2 files changed

+49
-16
lines changed

src/main.ts

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import {
3939
UNIT_SYSTEM,
4040
DEFAULT_TILE_SERVER,
4141
getId,
42-
OBSIDIAN_LEAFLET_POPOVER_SOURCE
42+
OBSIDIAN_LEAFLET_POPOVER_SOURCE,
43+
DEFAULT_ATTRIBUTION
4344
} from "./utils";
4445
import {
4546
MapInterface,
@@ -332,7 +333,7 @@ export default class ObsidianLeaflet extends Plugin {
332333
params,
333334
source
334335
);
335-
336+
336337
const map = await renderer.getMap();
337338
this.registerMapEvents(map);
338339

@@ -392,8 +393,42 @@ export default class ObsidianLeaflet extends Plugin {
392393
if (
393394
this.data.version?.major != null &&
394395
this.data.version?.major < 5 &&
395-
(this.data.defaultTile.contains("openstreetmap") ||
396-
this.data.defaultTileDark.contains("openstreetmap"))
396+
(this.data.defaultTile.contains("stamen-tiles") ||
397+
this.data.defaultTileDark.contains("stamen-tiles"))
398+
) {
399+
new Notice(
400+
createFragment((e) => {
401+
e.createSpan({
402+
text: "Obsidian Leaflet: Stamen has removed its map tile servers."
403+
});
404+
e.createEl("br");
405+
e.createEl("br");
406+
e.createSpan({
407+
text: "Going forward, the default tile server will be "
408+
});
409+
e.createEl("a", {
410+
href: "https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png",
411+
text: "CartoDB"
412+
});
413+
e.createSpan({ text: "." });
414+
}),
415+
0
416+
);
417+
if (this.data.defaultTile.contains("stamen-tiles")) {
418+
this.data.defaultTile = DEFAULT_TILE_SERVER;
419+
}
420+
if (this.data.defaultTileDark.contains("stamen-tiles")) {
421+
this.data.defaultTileDark = DEFAULT_TILE_SERVER;
422+
}
423+
if (this.data.defaultAttribution.contains("Stamen Design")) {
424+
this.data.defaultAttribution = DEFAULT_ATTRIBUTION;
425+
}
426+
}
427+
if (
428+
this.data.version?.major != null &&
429+
this.data.version?.major < 6 &&
430+
(this.data.defaultTile.contains("stamen") ||
431+
this.data.defaultTileDark.contains("stamen"))
397432
) {
398433
new Notice(
399434
createFragment((e) => {
@@ -664,7 +699,10 @@ export default class ObsidianLeaflet extends Plugin {
664699
return ret;
665700
}
666701

667-
public async getLocalFileMarkers(file: TFile, markerFileName = "markers.json"): Promise<MarkerIcon[]> {
702+
public async getLocalFileMarkers(
703+
file: TFile,
704+
markerFileName = "markers.json"
705+
): Promise<MarkerIcon[]> {
668706
if (!file) return [];
669707
const markerFilePath = `${file.parent.path}/${markerFileName}`;
670708
const markerFile = this.app.vault.getAbstractFileByPath(markerFilePath);
@@ -673,7 +711,7 @@ export default class ObsidianLeaflet extends Plugin {
673711
const markerJson = await this.app.vault.read(markerFile);
674712
try {
675713
const icons = JSON.parse(markerJson);
676-
markers.push(...icons.map((i: Icon) => this.parseIcon(i)))
714+
markers.push(...icons.map((i: Icon) => this.parseIcon(i)));
677715
} catch {
678716
console.error(`Badly formatted marker file ${markerFilePath}`);
679717
}

src/utils/constants.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
import { Platform } from "obsidian";
2-
import {
3-
BlockParameters,
4-
LeafletMapOptions,
5-
ObsidianAppData
6-
} from "../types";
2+
import { BlockParameters, LeafletMapOptions, ObsidianAppData } from "../types";
73

84
export const OBSIDIAN_LEAFLET_POPOVER_SOURCE = "obsidian-leaflet";
95

106
export const VIEW_TYPE = "obsidian-leaflet-map-view";
117

128
export const DEFAULT_TILE_SERVER =
13-
"https://stamen-tiles.a.ssl.fastly.net/terrain/{z}/{x}/{y}.png";
14-
export const DEFAULT_TILE_SUBDOMAINS =
15-
"a,b,c";
16-
export const TILE_SUBDOMAINS_SPILT = ',';
9+
"https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png";
10+
export const DEFAULT_TILE_SUBDOMAINS = "a,b,c,d";
11+
export const TILE_SUBDOMAINS_SPILT = ",";
1712

1813
export const DEFAULT_ATTRIBUTION =
19-
'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://www.openstreetmap.org/copyright">ODbL</a>.';
14+
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="https://carto.com/attributions">CARTO</a>';
2015

2116
export const OVERLAY_TAG_REGEX = /^(\d+(?:\.\d+)?)\s?(\w*)/;
2217

0 commit comments

Comments
 (0)