Skip to content

Commit

Permalink
feat!: Switched map tile provider (close #424)
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Oct 31, 2023
1 parent 12389ab commit c80da47
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
50 changes: 44 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import {
UNIT_SYSTEM,
DEFAULT_TILE_SERVER,
getId,
OBSIDIAN_LEAFLET_POPOVER_SOURCE
OBSIDIAN_LEAFLET_POPOVER_SOURCE,
DEFAULT_ATTRIBUTION
} from "./utils";
import {
MapInterface,
Expand Down Expand Up @@ -332,7 +333,7 @@ export default class ObsidianLeaflet extends Plugin {
params,
source
);

const map = await renderer.getMap();
this.registerMapEvents(map);

Expand Down Expand Up @@ -392,8 +393,42 @@ export default class ObsidianLeaflet extends Plugin {
if (
this.data.version?.major != null &&
this.data.version?.major < 5 &&
(this.data.defaultTile.contains("openstreetmap") ||
this.data.defaultTileDark.contains("openstreetmap"))
(this.data.defaultTile.contains("stamen-tiles") ||
this.data.defaultTileDark.contains("stamen-tiles"))
) {
new Notice(
createFragment((e) => {
e.createSpan({
text: "Obsidian Leaflet: Stamen has removed its map tile servers."
});
e.createEl("br");
e.createEl("br");
e.createSpan({
text: "Going forward, the default tile server will be "
});
e.createEl("a", {
href: "https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png",
text: "CartoDB"
});
e.createSpan({ text: "." });
}),
0
);
if (this.data.defaultTile.contains("stamen-tiles")) {
this.data.defaultTile = DEFAULT_TILE_SERVER;
}
if (this.data.defaultTileDark.contains("stamen-tiles")) {
this.data.defaultTileDark = DEFAULT_TILE_SERVER;
}
if (this.data.defaultAttribution.contains("Stamen Design")) {
this.data.defaultAttribution = DEFAULT_ATTRIBUTION;
}
}
if (
this.data.version?.major != null &&
this.data.version?.major < 6 &&
(this.data.defaultTile.contains("stamen") ||
this.data.defaultTileDark.contains("stamen"))
) {
new Notice(
createFragment((e) => {
Expand Down Expand Up @@ -664,7 +699,10 @@ export default class ObsidianLeaflet extends Plugin {
return ret;
}

public async getLocalFileMarkers(file: TFile, markerFileName = "markers.json"): Promise<MarkerIcon[]> {
public async getLocalFileMarkers(
file: TFile,
markerFileName = "markers.json"
): Promise<MarkerIcon[]> {
if (!file) return [];
const markerFilePath = `${file.parent.path}/${markerFileName}`;
const markerFile = this.app.vault.getAbstractFileByPath(markerFilePath);
Expand All @@ -673,7 +711,7 @@ export default class ObsidianLeaflet extends Plugin {
const markerJson = await this.app.vault.read(markerFile);
try {
const icons = JSON.parse(markerJson);
markers.push(...icons.map((i: Icon) => this.parseIcon(i)))
markers.push(...icons.map((i: Icon) => this.parseIcon(i)));
} catch {
console.error(`Badly formatted marker file ${markerFilePath}`);
}
Expand Down
15 changes: 5 additions & 10 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { Platform } from "obsidian";
import {
BlockParameters,
LeafletMapOptions,
ObsidianAppData
} from "../types";
import { BlockParameters, LeafletMapOptions, ObsidianAppData } from "../types";

export const OBSIDIAN_LEAFLET_POPOVER_SOURCE = "obsidian-leaflet";

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

export const DEFAULT_TILE_SERVER =
"https://stamen-tiles.a.ssl.fastly.net/terrain/{z}/{x}/{y}.png";
export const DEFAULT_TILE_SUBDOMAINS =
"a,b,c";
export const TILE_SUBDOMAINS_SPILT = ',';
"https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png";
export const DEFAULT_TILE_SUBDOMAINS = "a,b,c,d";
export const TILE_SUBDOMAINS_SPILT = ",";

export const DEFAULT_ATTRIBUTION =
'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>.';
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="https://carto.com/attributions">CARTO</a>';

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

Expand Down

0 comments on commit c80da47

Please sign in to comment.