squaremap Documentation
repository·master·Indexed 19 days ago
https://github.com/jpenilla/squaremapA lightweight, high-performance live world map viewer for Minecraft servers. Compatible with Paper, Fabric, NeoForge, and Sponge, it provides a 2D top-down web view with real-time player tracking. Includes a developer API (squaremap-api) for drawing markers and shapes, and a comprehensive set of administrative commands for managing map rendering, visibility, and configuration.
What's inside squaremap
- squaremap is a minimalistic and lightweight live world map viewer for Minecraft servers. It functions as a plugin or mod that hooks into your server to generate and manage a live, viewable map in any web browser. It features ultra-fast rendering, a 2D top-down view designed for navigation, and player markers that display yaw rotation, health, and armor.
Supported platforms for squaremap
mastersquaremap is compatible with the following Minecraft server platforms:
- Paper
- Fabric (requires Fabric API)
- NeoForge
- Sponge
Add squaremap-api to your project
masterTo use the squaremap API in your own plugin or mod, add the
squaremap-apidependency to your build configuration. Releases are published to Maven Central.Note: The scope should be
provided(Maven) orcompileOnly(Gradle) because the API is provided by the squaremap plugin at runtime.### Maven ```xml <dependency> <groupId>xyz.jpenilla</groupId> <artifactId>squaremap-api</artifactId> <version>1.3.11</version> <scope>provided</scope> </dependency>Gradle
repositories { mavenCentral() } dependencies { compileOnly("xyz.jpenilla", "squaremap-api", "1.3.11") }Set up a development environment for squaremap
masterTo develop squaremap or its web UI, ensure you have the following prerequisites:
- JDK: An up-to-date JDK (Java 21 or later).
- Bun: Installed on your system for building the web UI.
- Web Dependencies: Run
bun installinside thewebdirectory.
Building the Plugin
Use the Gradle
buildtask:./gradlew buildDeveloping the Web UI
The web UI is automatically built and included in the plugin JAR by Gradle. For local development with Hot Module Reloading (HMR), use the Gradle run tasks (e.g.,
:squaremap-paper:runServer). Gradle will automatically pass the following system properties to the server:squaremap.devFrontend=truesquaremap.frontendPath=<absolute path to ./web>
When these properties are present, the plugin proxies requests to the Vite dev server.
# Build the plugin ./gradlew build # Install web dependencies cd web && bun installUnderstand the Player data model
masterThe
Playerclass represents a player on the map. It manages the player's state (name, UUID, world, position, armor, health, and display name) and handles the visual representation of the player via a Leaflet marker and a nameplate tooltip.Key behaviors:
- Marker Management: Automatically creates, updates, or removes a Leaflet marker based on the player's position and whether the current world's
player_trackeris enabled. - Nameplates: Generates and updates a nameplate tooltip that can display the player's head, display name, health, and armor, depending on the world configuration.
- Synchronization: The
update(player)method is the primary way to sync the internal state with new data received from the server. - Cross-world visibility: If a player is in a different world than the one currently being viewed, their associated UI elements (like links in a player list) are marked with the
other-worldCSS class.
- Marker Management: Automatically creates, updates, or removes a Leaflet marker based on the player's position and whether the current world's
How Squaremap manages coordinate systems
masterSquaremap uses a custom coordinate system where map positions are defined by
xandz(typical of Minecraft-style maps) rather than standard Latitude and Longitude.To bridge this with the underlying Leaflet engine, the
SquaremapMapclass performs coordinate transformations:toLatLng(x, z): Converts pixel coordinates to Leaflet'sLatLng. It usespixelsToMetersto handle the scale.toPoint(latlng): Converts a LeafletLatLngback into pixel coordinates.setScale(zoom): Calculates thescalefactor based on the current zoom level using the formula1 / Math.pow(2, zoom). This scale is essential for all coordinate conversions.
Understand the World data model
masterThe
Worldclass represents a specific Minecraft world (e.g., Overworld, Nether, or The End) within the Squaremap web client. It manages world-specific settings, tile layer updates, and marker layers.Key responsibilities include:
- Configuration: Loading world settings like zoom levels, spawn points, and update intervals from
tiles/{world_name}/settings.json. - Lifecycle Management: Using
load()to initialize the map view andunload()to clean up layers and player markers. - Dynamic Updates: The
tick()method handles periodic refreshing of map tiles and markers based ontiles_update_intervalandmarker_update_interval. - Visuals: Automatically sets the map background based on the world
type(nether,the_end, ornormal).
- Configuration: Loading world settings like zoom levels, spawn points, and update intervals from
Use the squaremap API to draw on maps
mastersquaremap provides APIs for drawing markers, shapes, icons, and other elements on rendered maps. Javadocs are hosted on the Maven repository alongside the binaries and are typically automatically downloaded by your IDE when you add the dependency.Get player head URL with `getHeadUrl()`
masterReturns a URL for the player's head icon by replacing placeholders in the current world's
heads_urlconfiguration with the player'suuidandname.const headUrl = playerInstance.getHeadUrl(); // Example output: "images/heads/uuid_here.png"Manage player markers with `removeMarker()`
masterThe
removeMarker()method cleans up the player's visual presence on the map. It removes the Leaflet marker from the map and theplayersLayer, and deletes the marker from the internalS.playerList.markersregistry using the player'suuid.playerInstance.removeMarker();Unload a world and clean up resources
masterCall
unload()to remove the current world's data from the map. This method:- Clears all player markers from
S.playerList. - Iterates through all managed
markerLayers, removes them from theS.layerControlUI, and removes them from the Leaflet map instance. - Deletes the layers from the internal
markerLayersMap.
world.unload();- Clears all player markers from
Manage map overlays with LayerControl
masterThe
LayerControlclass provides a mechanism to manage Leaflet layers as overlays, including persistent visibility settings usinglocalStorage. It integrates with the globalS.mapinstance.Key Methods
addOverlay(name, layer, hide): Adds a Leaflet layer to the map controls with a specific name. Ifhideis true, the layer is added to the control but not immediately rendered on the map. Visibility is checked againstlocalStorageusing the keyhide_${layer.id}.removeOverlay(layer): Removes a layer from the map controls and the map itself.hideLayer(layer): Persistently hides a layer by settinghide_${layer.id}to"true"inlocalStorage.showLayer(layer): Persistently shows a layer by settinghide_${layer.id}to"false"inlocalStorage.
Note: Visibility state is persisted in the browser's
localStoragebased on theidproperty of the Leaflet layer.// Example usage of LayerControl methods const lc = new LayerControl(); // ... init logic ... const myLayer = L.layerGroup(); myLayer.id = 'custom_layer_id'; // Add an overlay that is hidden by default lc.addOverlay('My Custom Layer', myLayer, true); // Persistently hide the layer lc.hideLayer(myLayer); // Persistently show the layer lc.showLayer(myLayer);