A Mapbox GL JS Plugin that displays a globe minimap showing the main map's center.
![Display_a_map_on_a_webpage-4](https://private-user-images.githubusercontent.com/1833820/348031361-4d0be846-47bb-438d-8a27-145036056be0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNjM0MzQsIm5iZiI6MTczOTA2MzEzNCwicGF0aCI6Ii8xODMzODIwLzM0ODAzMTM2MS00ZDBiZTg0Ni00N2JiLTQzOGQtOGEyNy0xNDUwMzYwNTZiZTAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDlUMDEwNTM0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MjJiNzQ5NWYyYzE0NDNjMGQ3ZDBjMDY2NjBkOGNhYThjNzU4YzZhYjY4YWU0ZTAzNzkyNzY1N2UzNDQ2N2YwZCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.ZK39zFL_Bex1rfoPCeuREoozejYdlEQzo7mmj_Qu3L8)
You can customize the colors and size of minimap, and scale the marker.
![Display_a_map_on_a_webpage_and_index_html_—_globe-minimap](https://private-user-images.githubusercontent.com/1833820/347245014-41813154-ac92-4516-b942-88114a61b55e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwNjM0MzQsIm5iZiI6MTczOTA2MzEzNCwicGF0aCI6Ii8xODMzODIwLzM0NzI0NTAxNC00MTgxMzE1NC1hYzkyLTQ1MTYtYjk0Mi04ODExNGE2MWI1NWUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDlUMDEwNTM0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzdiMWI3ZDQwMDMyYWE2MmM4MGU5ZjcwMzJkODlmMzUzYjg3OWZjZWQ4NzQ2N2UzZTQxNTJiZDhhMDhlMzQ4YiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.R1cKPR7U6VvZ1P1IeBVJa-VDUqZOmXMjMeBxqXQjRA0)
Add the script tag to your HTML file after importing Mapbox GL JS:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bundle.js
"></script>
On Map load, add the control. You can specify the position of the globe using the second argument of addControl()
:
mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN';
const map = new mapboxgl.Map({
container: "map",
center: [-74.5, 40],
zoom: 3,
});
map.on("load", function () {
map.addControl(
new GlobeMinimap({
landColor: "#4ebf6e",
waterColor: "#8dcbe3"
}),
"bottom-right"
);
});
npm i mapbox-gl-globe-minimap
Import the module and add it to the map with addControl()
import GlobeMinimap from "mapbox-gl-globe-minimap";
...
mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN';
const map = new mapboxgl.Map({
container: "map",
center: [-74.5, 40],
zoom: 3,
});
map.on("load", function () {
map.addControl(
new GlobeMinimap({
landColor: "#4ebf6e",
waterColor: "#8dcbe3"
}),
"bottom-right"
);
});
option | type | description | default |
---|---|---|---|
globeSize |
Number |
Pixels to use for the diameter of the globe | 82 |
landColor |
String |
HTML color to use for land areas on the globe | 'white' |
waterColor |
String |
HTML color to use for water areas on the globe | 'rgba(30 40 70/60%)' |
markerColor |
String |
HTML color to use for the center point marker | '#ff2233' |
markerSize |
Number |
Scale ratio for the center point marker | 1 |
This is a modern incarnation of leaflet-globeminimap
, a leaflet plugin I made a while back. That plugin was inspired by the globe minimap used by the Google Earth View Chrome plugin.
Plugin architecture was derived from https://github.com/aesqe/mapboxgl-minimap
, and the modern d3.geoOrthographic
implementation is based on this observable notebook.