From a07cd861649f60df53cc26dc9806e5dfd680bcd9 Mon Sep 17 00:00:00 2001 From: pembo Date: Sun, 9 Aug 2026 10:36:37 +0100 Subject: [PATCH 1/6] added a zoom out configuration allowing you to zoom back to see larger maps as a whole --- .../java/xyz/jpenilla/squaremap/common/config/WorldConfig.java | 2 ++ .../xyz/jpenilla/squaremap/common/task/UpdateWorldData.java | 1 + web/src/js/LayerControl.js | 1 + web/src/js/types.ts | 1 + web/src/js/util/World.js | 2 +- 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldConfig.java b/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldConfig.java index 7f10228b..214c696d 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldConfig.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/config/WorldConfig.java @@ -62,11 +62,13 @@ private void waterSettings() { public int ZOOM_MAX = 3; public int ZOOM_DEFAULT = 3; public int ZOOM_EXTRA = 2; + public int ZOOM_EXTRA_OUT = 0; private void zoomSettings() { this.ZOOM_MAX = this.getInt("map.zoom.maximum", this.ZOOM_MAX); this.ZOOM_DEFAULT = this.getInt("map.zoom.default", this.ZOOM_DEFAULT); this.ZOOM_EXTRA = this.getInt("map.zoom.extra", this.ZOOM_EXTRA); + this.ZOOM_EXTRA_OUT = this.getInt("map.zoom.extra-out", this.ZOOM_EXTRA_OUT); } public boolean BACKGROUND_RENDER_ENABLED = true; diff --git a/common/src/main/java/xyz/jpenilla/squaremap/common/task/UpdateWorldData.java b/common/src/main/java/xyz/jpenilla/squaremap/common/task/UpdateWorldData.java index 4056549b..77963908 100644 --- a/common/src/main/java/xyz/jpenilla/squaremap/common/task/UpdateWorldData.java +++ b/common/src/main/java/xyz/jpenilla/squaremap/common/task/UpdateWorldData.java @@ -131,6 +131,7 @@ private void writeWorldSettings( zoom.put("max", worldConfig.ZOOM_MAX); zoom.put("def", worldConfig.ZOOM_DEFAULT); zoom.put("extra", worldConfig.ZOOM_EXTRA); + zoom.put("extra_out", worldConfig.ZOOM_EXTRA_OUT); final Map settings = new HashMap<>(); settings.put("spawn", spawn); diff --git a/web/src/js/LayerControl.js b/web/src/js/LayerControl.js index 989ae437..9b536701 100644 --- a/web/src/js/LayerControl.js +++ b/web/src/js/LayerControl.js @@ -114,6 +114,7 @@ class LayerControl { createTileLayer(world) { return new SquaremapTileLayer(`tiles/${world.name}/{z}/{x}_{y}.png`, { tileSize: 512, + minZoom: 0 - (world.zoom.extra_out ?? 0), minNativeZoom: 0, maxNativeZoom: world.zoom.max, errorTileUrl: "images/clear.png", diff --git a/web/src/js/types.ts b/web/src/js/types.ts index 80579ed3..e2cfd2cf 100644 --- a/web/src/js/types.ts +++ b/web/src/js/types.ts @@ -62,6 +62,7 @@ export interface WorldSettings_Zoom { max: number; def: number; extra: number; + extra_out: number; } export interface WorldSettings { diff --git a/web/src/js/util/World.js b/web/src/js/util/World.js index 64afe796..e0bc1254 100644 --- a/web/src/js/util/World.js +++ b/web/src/js/util/World.js @@ -92,7 +92,7 @@ class World { // set center and zoom S.centerOn(this.spawn.x, this.spawn.z, this.zoom.def) - .setMinZoom(0) // extra zoom out doesn't work :( + .setMinZoom(0 - (this.zoom.extra_out ?? 0)) .setMaxZoom(this.zoom.max + this.zoom.extra); // update page title From d512b4b88ea950672f16127486bf0822e3149533 Mon Sep 17 00:00:00 2001 From: pembo Date: Sun, 9 Aug 2026 12:00:17 +0100 Subject: [PATCH 2/6] added a right click menu to the map, with options to: - zoom in/zoom out from the mouse position - 2 methods to copy the coordinates to the buffer. - 1) Just the X and Z - 2) X,Y,Z defaulting Y to 150 --- .vscode/settings.json | 4 ++ web/src/css/styles.css | 31 +++++++++++ web/src/js/ContextMenu.js | 107 ++++++++++++++++++++++++++++++++++++++ web/src/js/Squaremap.js | 4 ++ 4 files changed, 146 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 web/src/js/ContextMenu.js diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..e0120650 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "java.compile.nullAnalysis.mode": "automatic", + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/web/src/css/styles.css b/web/src/css/styles.css index ef53f67d..e11fd5e4 100644 --- a/web/src/css/styles.css +++ b/web/src/css/styles.css @@ -191,3 +191,34 @@ div.leaflet-control-layers.coordinates { background: rgba(128, 0, 0, 0.5); border: 1px solid rgba(128, 0, 0, 0.75); } +#context-menu { + display: none; + position: absolute; + z-index: 10001; + min-width: 200px; + padding: 4px 0; + background-color: rgba(0, 0, 0, 0.75); + border: 1px solid rgba(255, 255, 255, 0.2); + border-radius: 3px; + font: + 12px/1.5 "Helvetica Neue", + Arial, + Helvetica, + sans-serif; + color: #ffffff; + -webkit-user-select: none; + user-select: none; +} +.context-menu-item { + display: block; + padding: 6px 12px; + cursor: pointer; + white-space: nowrap; +} +.context-menu-item:hover { + background-color: rgba(255, 255, 255, 0.15); +} +.context-menu-separator { + margin: 4px 0; + border-top: 1px solid rgba(255, 255, 255, 0.2); +} diff --git a/web/src/js/ContextMenu.js b/web/src/js/ContextMenu.js new file mode 100644 index 00000000..a9189bd4 --- /dev/null +++ b/web/src/js/ContextMenu.js @@ -0,0 +1,107 @@ +import { S } from "./Squaremap.js"; + +class ContextMenu { + /** @type {HTMLDivElement} */ + menu; + /** @type {L.LatLng | null} */ + latlng; + /** @type {L.Point | null} */ + point; + + constructor() { + this.menu = document.createElement("div"); + this.menu.id = "context-menu"; + S.map.getContainer().appendChild(this.menu); + + this.addItem("Zoom in", () => this.zoom(1)); + this.addItem("Zoom out", () => this.zoom(-1)); + this.addSeparator(); + this.addItem("Copy coordinates", () => this.copyCoordinates()); + this.addItem("Copy coordinates (Y: 150)", () => this.copyCoordinates(150)); + + S.map.on("contextmenu", (e) => { + this.latlng = e.latlng; + this.point = S.toPoint(e.latlng); + this.open(e.containerPoint); + }); + S.map.on("movestart zoomstart click", () => this.close()); + document.addEventListener("keydown", (e) => { + if (e.key === "Escape") { + this.close(); + } + }); + document.addEventListener("click", (e) => { + if (!this.menu.contains(e.target)) { + this.close(); + } + }); + } + + /** + * @param {string} label + * @param {() => void} onClick + */ + addItem(label, onClick) { + const item = document.createElement("div"); + item.className = "context-menu-item"; + item.textContent = label; + item.addEventListener("click", () => { + onClick(); + this.close(); + }); + this.menu.appendChild(item); + } + + addSeparator() { + const separator = document.createElement("div"); + separator.className = "context-menu-separator"; + this.menu.appendChild(separator); + } + + /** + * @param {number} delta + */ + zoom(delta) { + if (this.latlng == null) { + return; + } + S.map.setZoomAround(this.latlng, S.map.getZoom() + delta); + } + + /** + * @param {number} [y] + */ + async copyCoordinates(y) { + if (this.point == null) { + return; + } + const x = Math.floor(this.point.x); + const z = Math.floor(this.point.y); + const text = y == null ? `${x}, ${z}` : `${x}, ${y}, ${z}`; + await navigator.clipboard.writeText(text); + } + + /** + * @param {L.Point} containerPoint + */ + open(containerPoint) { + this.menu.style.display = "block"; + const mapSize = S.map.getSize(); + let x = containerPoint.x; + let y = containerPoint.y; + if (x + this.menu.offsetWidth > mapSize.x) { + x -= this.menu.offsetWidth; + } + if (y + this.menu.offsetHeight > mapSize.y) { + y -= this.menu.offsetHeight; + } + this.menu.style.left = `${x}px`; + this.menu.style.top = `${y}px`; + } + + close() { + this.menu.style.display = "none"; + } +} + +export { ContextMenu }; diff --git a/web/src/js/Squaremap.js b/web/src/js/Squaremap.js index b1202bea..43257e90 100644 --- a/web/src/js/Squaremap.js +++ b/web/src/js/Squaremap.js @@ -4,6 +4,7 @@ import { WorldList } from "./WorldList.js"; import { UICoordinates } from "./UICoordinates.js"; import { UILink } from "./UILink.js"; import { LayerControl } from "./LayerControl.js"; +import { ContextMenu } from "./ContextMenu.js"; import L from "leaflet"; import "./addons/Ellipse.js"; import "./addons/RotateMarker.js"; @@ -29,6 +30,8 @@ class SquaremapMap { coordinates; /** @type {UILink} */ uiLink; + /** @type {ContextMenu} */ + contextMenu; /** @type {number} */ tick_count; /** @type {boolean} */ @@ -91,6 +94,7 @@ class SquaremapMap { this.getUrlParam("show_coordinates", "true") === "true", ); this.uiLink = new UILink(json.ui.link, this.getUrlParam("show_link_button", "true") === "true"); + this.contextMenu = new ContextMenu(); this.showControls = this.getUrlParam("show_controls", "true") === "true"; if (!this.showControls) { From 6ae1f2b9ce5dcd32b554b7785da1ffeb6dfc4fb1 Mon Sep 17 00:00:00 2001 From: pembo Date: Sun, 9 Aug 2026 12:43:05 +0100 Subject: [PATCH 3/6] updated gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 84932c9a..0d82b466 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,9 @@ out/ plugin/bin/ api/bin/ +#VScode +.vscode/ + # Compiled class file *.class From 34e136fd94ac3566818740bbe2e2900fb72518ab Mon Sep 17 00:00:00 2001 From: pembo Date: Sun, 9 Aug 2026 12:43:52 +0100 Subject: [PATCH 4/6] Delete .vscode directory --- .vscode/settings.json | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e0120650..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "java.compile.nullAnalysis.mode": "automatic", - "java.configuration.updateBuildConfiguration": "interactive" -} \ No newline at end of file From 7541ead4910b4b1f14b4da1ce927fc204e97abd5 Mon Sep 17 00:00:00 2001 From: pembo Date: Sun, 9 Aug 2026 12:44:59 +0100 Subject: [PATCH 5/6] added vscode files to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0d82b466..cb87de68 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ api/bin/ #VScode .vscode/ +*.code-workspace # Compiled class file *.class From d05cfb48273a52ba771dda0d30faabcd93f2398a Mon Sep 17 00:00:00 2001 From: pembo Date: Sun, 9 Aug 2026 21:13:32 +0100 Subject: [PATCH 6/6] updated context menu to remove the commas so it can be pasted into a minecraft tp command --- web/src/js/ContextMenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/js/ContextMenu.js b/web/src/js/ContextMenu.js index a9189bd4..247e839a 100644 --- a/web/src/js/ContextMenu.js +++ b/web/src/js/ContextMenu.js @@ -77,7 +77,7 @@ class ContextMenu { } const x = Math.floor(this.point.x); const z = Math.floor(this.point.y); - const text = y == null ? `${x}, ${z}` : `${x}, ${y}, ${z}`; + const text = y == null ? `${x} ${z}` : `${x} ${y} ${z}`; await navigator.clipboard.writeText(text); }