Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added customization options #446

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ darkMode: true
| lock | Control whether the map will start locked or unlocked | false |
| recenter | Forces map to stay re-center itself after panning. | false |
| noScrollZoom | Turns off scrollwheel zooming. | false |
| disableCreateMarkerOnRightClick | Disable creation of markers when right clicking on the map | false |
| disableMapViewControl | Disables display of the map view control (Show all markers) | false |
| disableResetZoomControl | Disables display of the reset zoom control | false |
| disableFilterControl | Disables display of the filter control | false |
| disableGpxControl | Disables display of the gpx control (Zoom to GPX track) | false |
| disableLockControl | Disables display of the lock control | false |
| disableLayerControl | Disables display of the layer control | false |
| disableSaveMapControl | Disables display of the save map control | false |
| disableDistanceDisplay | Disables display of the distance widget | false |

> \*: Requires the [DataView plugin](https://github.com/blacksmithgu/obsidian-dataview).

Expand Down
180 changes: 106 additions & 74 deletions src/map/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,15 @@ export abstract class BaseMap extends Events implements BaseMapDefinition {
addLayerControl() {
if (this.layerControlAdded) return;
this.layerControlAdded = true;
this.filterControl?.remove();
this.layerControl.addTo(this.leafletInstance);
this.filterControl?.addTo(this.leafletInstance);
if(!this.options.disableFilterControl) {
this.filterControl?.remove();
this.filterControl?.addTo(this.leafletInstance);
}
if(!this.options.disableLayerControl) {
this.layerControl.addTo(this.leafletInstance);
}
}

onFirstLayerReady(callback: (...args: any[]) => any) {
if (this.mapLayers.length) {
callback();
Expand Down Expand Up @@ -577,10 +582,12 @@ export abstract class BaseMap extends Events implements BaseMapDefinition {
);

geo.leafletInstance.addTo(this.geojsonLayer);
this.layerControl.addOverlay(
geo.leafletInstance,
alias && alias.length ? alias : `GeoJSON ${added + 1}`
);
if(!this.options.disableLayerControl) {
this.layerControl.addOverlay(
geo.leafletInstance,
alias && alias.length ? alias : `GeoJSON ${added + 1}`
);
}

added++;
} catch (e) {
Expand Down Expand Up @@ -614,10 +621,12 @@ export abstract class BaseMap extends Events implements BaseMapDefinition {
);
gpxInstance.show();
gpxInstance.leafletInstance.addTo(this.gpxLayer);
this.layerControl.addOverlay(
gpxInstance.leafletInstance,
alias ?? `GPX ${added + 1}`
);
if(!this.options.disableLayerControl) {
this.layerControl.addOverlay(
gpxInstance.leafletInstance,
alias ?? `GPX ${added + 1}`
);
}
added++;
} catch (e) {
console.error(e);
Expand All @@ -629,10 +638,12 @@ export abstract class BaseMap extends Events implements BaseMapDefinition {
}
}

this.gpxControl = gpxControl(
{ position: "bottomleft" },
this
).addTo(this.leafletInstance);
if(!this.options.disableGpxControl) {
this.gpxControl = gpxControl(
{ position: "bottomleft" },
this
).addTo(this.leafletInstance);
}
}

if (this.geojsonData.length || this.gpxData.length) {
Expand Down Expand Up @@ -663,7 +674,9 @@ export abstract class BaseMap extends Events implements BaseMapDefinition {
pane: "image-overlay"
});

this.layerControl.addOverlay(image, overlay.alias);
if(!this.options.disableLayerControl) {
this.layerControl.addOverlay(image, overlay.alias);
}
}
});
}
Expand All @@ -679,10 +692,12 @@ export abstract class BaseMap extends Events implements BaseMapDefinition {
if (on && on == "on") {
layer.addTo(this.tileOverlayLayer);
}
this.layerControl.addOverlay(
layer,
name && name.length ? name : `Layer ${index}`
);
if(!this.options.disableLayerControl) {
this.layerControl.addOverlay(
layer,
name && name.length ? name : `Layer ${index}`
);
}
}
});
}
Expand Down Expand Up @@ -721,32 +736,42 @@ export abstract class BaseMap extends Events implements BaseMapDefinition {
});
}
}
this.filterControl = filterMarkerControl(
{ position: "topright" },
this
).addTo(this.leafletInstance);
this.lockControl = lockControl({ position: "topright" }, this).addTo(
this.leafletInstance
);
zoomControl({ position: "topleft" }, this).addTo(this.leafletInstance);
resetZoomControl({ position: "topleft" }, this).addTo(
this.leafletInstance
);
this.distanceDisplay = distanceDisplay(
{
position: "bottomleft"
},
this
).addTo(this.leafletInstance);
if(!this.options.disableFilterControl) {
this.filterControl = filterMarkerControl(
{ position: "topright" },
this
).addTo(this.leafletInstance);
}
if(!this.options.disableLockControl) {
this.lockControl = lockControl({ position: "topright" }, this).addTo(
this.leafletInstance
);
}
if(!this.options.disableMapViewControl) {
zoomControl({ position: "topleft" }, this).addTo(this.leafletInstance);
}
if(!this.options.disableResetZoomControl) {
resetZoomControl({ position: "topleft" }, this).addTo(
this.leafletInstance
);
}
if(!this.options.disableDistanceDisplay) {
this.distanceDisplay = distanceDisplay(
{
position: "bottomleft"
},
this
).addTo(this.leafletInstance);
}

if (this.options.isMapView) {
if (this.options.isMapView && !this.options.disableMapViewControl) {
mapViewControl(
{
position: "bottomright"
},
this
).addTo(this.leafletInstance);
} else if (!this.options.isInitiativeView) {
} else if (!this.options.isInitiativeView && !this.options.disableSaveMapControl) {
saveMapParametersControl(
{
position: "bottomright"
Expand All @@ -765,7 +790,9 @@ export abstract class BaseMap extends Events implements BaseMapDefinition {
updateLockState(state: boolean): void {
this.options.lock = state;

this.lockControl.setState(this.options.lock);
if(!this.options.disableLockControl) {
this.lockControl.setState(this.options.lock);
}
this.trigger("lock");
}

Expand Down Expand Up @@ -918,7 +945,9 @@ export abstract class BaseMap extends Events implements BaseMapDefinition {
]);
this.distanceTooltips.last().open(`${display} (${segment})`);

this.distanceDisplay.setText(display);
if(!this.options.disableDistanceDisplay) {
this.distanceDisplay.setText(display);
}
this.distanceLines.last().redraw();
});

Expand Down Expand Up @@ -1080,44 +1109,47 @@ export abstract class BaseMap extends Events implements BaseMapDefinition {

return;
}
if (this.markerIcons.size <= 1) {
this.log(
`No additional marker types defined. Adding default marker.`
);
this.createMarker(
this.defaultIcon.type,
[evt.latlng.lat, evt.latlng.lng],
undefined
);
return;
}

let contextMenu = new Menu();

contextMenu.setNoIcon();

this.log(`Opening marker context menu.`);

this.markerIcons.forEach((marker: MarkerIcon) => {
if (!marker.type || !marker.html) return;
contextMenu.addItem((item) => {
item.setTitle(
marker.type == "default" ? "Default" : marker.type
if(!this.options.disableCreateMarkerOnRightClick) {
if (this.markerIcons.size <= 1) {
this.log(
`No additional marker types defined. Adding default marker.`
);
item.onClick(async () => {
this.log(`${marker.type} selected. Creating marker.`);
this.createMarker(
marker.type,
[evt.latlng.lat, evt.latlng.lng],
undefined
this.createMarker(
this.defaultIcon.type,
[evt.latlng.lat, evt.latlng.lng],
undefined
);
return;
}

let contextMenu = new Menu();

contextMenu.setNoIcon();

this.log(`Opening marker context menu.`);

this.markerIcons.forEach((marker: MarkerIcon) => {
if (!marker.type || !marker.html) return;
contextMenu.addItem((item) => {
item.setTitle(
marker.type == "default" ? "Default" : marker.type
);
this.trigger("should-save");
item.onClick(async () => {
this.log(`${marker.type} selected. Creating marker.`);
this.createMarker(
marker.type,
[evt.latlng.lat, evt.latlng.lng],
undefined
);
this.trigger("should-save");
});
});
});
});

contextMenu.showAtMouseEvent(evt.originalEvent);

contextMenu.showAtMouseEvent(evt.originalEvent);
}
}

handleMapContextMobile(evt: L.LeafletMouseEvent, overlay?: Overlay) {
let contextMenu = new Menu();

Expand Down
11 changes: 10 additions & 1 deletion src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,16 @@ export class LeafletRenderer extends MarkdownRenderChild {
verbose: this.params.verbose,
zoomDelta: +this.params.zoomDelta,
zoomFeatures: this.params.zoomFeatures,
zoomMarkers: this.params.showAllMarkers
zoomMarkers: this.params.showAllMarkers,
disableCreateMarkerOnRightClick: this.params.disableCreateMarkerOnRightClick,
disableMapViewControl: this.params.disableMapViewControl,
disableResetZoomControl: this.params.disableResetZoomControl,
disableFilterControl: this.params.disableFilterControl,
disableGpxControl: this.params.disableGpxControl,
disableLockControl: this.params.disableLockControl,
disableLayerControl: this.params.disableLayerControl,
disableSaveMapControl: this.params.disableSaveMapControl,
disableDistanceDisplay: this.params.disableDistanceDisplay
};

this.preserveAspect = this.params.preserveAspect ?? false;
Expand Down
11 changes: 11 additions & 0 deletions types/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,16 @@ export interface BlockParameters {
recenter?: boolean;
noScrollZoom?: boolean;
lock?: boolean;

disableCreateMarkerOnRightClick?: boolean;

disableMapViewControl?: boolean;
disableResetZoomControl?: boolean;
disableFilterControl?: boolean;
disableGpxControl?: boolean;
disableLockControl?: boolean;
disableLayerControl?: boolean;
disableSaveMapControl?: boolean;
disableDistanceDisplay?: boolean;
}

11 changes: 11 additions & 0 deletions types/map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ export interface LeafletMapOptions {
zoomDelta?: number;
zoomFeatures?: boolean;
zoomMarkers?: boolean;

disableCreateMarkerOnRightClick?: boolean;

disableMapViewControl?: boolean;
disableResetZoomControl?: boolean;
disableFilterControl?: boolean;
disableGpxControl?: boolean;
disableLockControl?: boolean;
disableLayerControl?: boolean;
disableSaveMapControl?: boolean;
disableDistanceDisplay?: boolean;
}

declare class Popup {
Expand Down