feat(views/geo): set default theme

This commit is contained in:
Elian Doran 2025-07-24 15:52:01 +03:00
parent 45457c6f76
commit 60e7b9ffb0
No known key found for this signature in database
4 changed files with 12 additions and 5 deletions

View File

@ -207,12 +207,13 @@ export default class BookPropertiesWidget extends NoteContextAwareWidget {
const $select = $("<select>", { const $select = $("<select>", {
class: "form-select form-select-sm" class: "form-select form-select-sm"
}); });
const actualValue = note.getLabelValue(property.bindToLabel) ?? property.defaultValue;
for (const option of property.options) { for (const option of property.options) {
const $option = $("<option>", { const $option = $("<option>", {
value: option.value, value: option.value,
text: option.label text: option.label
}); });
if (note.getLabelValue(property.bindToLabel) === option.value) { if (actualValue === option.value) {
$option.prop("selected", true); $option.prop("selected", true);
} }
$select.append($option); $select.append($option);

View File

@ -3,7 +3,7 @@ import FNote from "../../entities/fnote";
import attributes from "../../services/attributes"; import attributes from "../../services/attributes";
import { ViewTypeOptions } from "../../services/note_list_renderer" import { ViewTypeOptions } from "../../services/note_list_renderer"
import NoteContextAwareWidget from "../note_context_aware_widget"; import NoteContextAwareWidget from "../note_context_aware_widget";
import { MAP_LAYERS } from "../view_widgets/geo_view/map_layer"; import { DEFAULT_MAP_LAYER_NAME, MAP_LAYERS } from "../view_widgets/geo_view/map_layer";
interface BookConfig { interface BookConfig {
properties: BookProperty[]; properties: BookProperty[];
@ -35,6 +35,10 @@ interface ComboBoxProperty {
type: "combobox", type: "combobox",
label: string; label: string;
bindToLabel: string; bindToLabel: string;
/**
* The default value is used when the label is not set.
*/
defaultValue?: string;
options: { value: string; label: string }[]; options: { value: string; label: string }[];
} }
@ -103,6 +107,7 @@ export const bookPropertiesConfig: Record<ViewTypeOptions, BookConfig> = {
label: t("book_properties_config.map-style"), label: t("book_properties_config.map-style"),
type: "combobox", type: "combobox",
bindToLabel: "mapStyle", bindToLabel: "mapStyle",
defaultValue: DEFAULT_MAP_LAYER_NAME,
options: Object.entries(MAP_LAYERS).map(([id, layer]) => ({ options: Object.entries(MAP_LAYERS).map(([id, layer]) => ({
value: id, value: id,
label: layer.name label: layer.name

View File

@ -11,7 +11,7 @@ import { CommandListenerData, EventData } from "../../../components/app_context.
import { createNewNote, moveMarker, setupDragging } from "./editing.js"; import { createNewNote, moveMarker, setupDragging } from "./editing.js";
import { openMapContextMenu } from "./context_menu.js"; import { openMapContextMenu } from "./context_menu.js";
import attributes from "../../../services/attributes.js"; import attributes from "../../../services/attributes.js";
import { MAP_LAYERS } from "./map_layer.js"; import { DEFAULT_MAP_LAYER_NAME, MAP_LAYERS } from "./map_layer.js";
const TPL = /*html*/` const TPL = /*html*/`
<div class="geo-view"> <div class="geo-view">
@ -146,9 +146,9 @@ export default class GeoView extends ViewMode<MapData> {
worldCopyJump: true worldCopyJump: true
}); });
const layerName = this.parentNote.getLabelValue("mapStyle") ?? "openstreetmap"; const layerName = this.parentNote.getLabelValue("mapStyle") ?? DEFAULT_MAP_LAYER_NAME;
let layer: Layer; let layer: Layer;
const layerData = MAP_LAYERS[layerName] ?? MAP_LAYERS["openstreetmap"]; const layerData = MAP_LAYERS[layerName];
if (layerData.type === "vector") { if (layerData.type === "vector") {
const style = (typeof layerData.style === "string" ? layerData.style : await layerData.style()); const style = (typeof layerData.style === "string" ? layerData.style : await layerData.style());

View File

@ -50,3 +50,4 @@ export const MAP_LAYERS: Record<string, VectorLayer | RasterLayer> = {
} }
}; };
export const DEFAULT_MAP_LAYER_NAME: keyof typeof MAP_LAYERS = "versatiles-colorful";