Skip to content

Commit

Permalink
Enable MapLibre 5.0 globe view with control.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Jan 6, 2025
1 parent 1e4a4d7 commit da22c80
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
28 changes: 11 additions & 17 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"@maplibre/maplibre-gl-inspect": "^1.7.0",
"maplibre-gl": "4.7.1",
"maplibre-gl": "5.0.0",
"pixelmatch": "^5.3.0",
"pmtiles": "^4.1.0",
"sirv": "^3.0.0",
Expand Down
36 changes: 24 additions & 12 deletions app/src/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ import { render } from "solid-js/web";
import "./index.css";
import MaplibreInspect from "@maplibre/maplibre-gl-inspect";
import "@maplibre/maplibre-gl-inspect/dist/maplibre-gl-inspect.css";
import maplibregl from "maplibre-gl";
import {
Map,
addProtocol,
getRTLTextPluginStatus,
setRTLTextPlugin,
NavigationControl,
GeolocateControl,
GlobeControl,
Popup,
ScaleControl,
removeProtocol,
} from "maplibre-gl";
import type { MapGeoJSONFeature, StyleSpecification } from "maplibre-gl";
import "maplibre-gl/dist/maplibre-gl.css";
import type { LayerSpecification } from "@maplibre/maplibre-gl-style-spec";
Expand Down Expand Up @@ -173,13 +184,13 @@ function MapLibreView(props: {
droppedArchive?: PMTiles;
}) {
let mapContainer: HTMLDivElement | undefined;
let mapRef: maplibregl.Map | undefined;
let mapRef: Map | undefined;
let protocolRef: Protocol | undefined;
let hiddenRef: HTMLDivElement | undefined;

onMount(() => {
if (maplibregl.getRTLTextPluginStatus() === "unavailable") {
maplibregl.setRTLTextPlugin(
if (getRTLTextPluginStatus() === "unavailable") {
setRTLTextPlugin(
"https://unpkg.com/@mapbox/[email protected]/mapbox-gl-rtl-text.min.js",
true,
);
Expand All @@ -192,18 +203,19 @@ function MapLibreView(props: {

const protocol = new Protocol({ metadata: true });
protocolRef = protocol;
maplibregl.addProtocol("pmtiles", protocol.tile);
addProtocol("pmtiles", protocol.tile);

const map = new maplibregl.Map({
const map = new Map({
hash: "map",
container: mapContainer,
style: getMaplibreStyle("", "en", false),
});

map.addControl(new maplibregl.NavigationControl());
map.addControl(new maplibregl.ScaleControl({}));
map.addControl(new NavigationControl());
map.addControl(new ScaleControl());
map.addControl(new GlobeControl());
map.addControl(
new maplibregl.GeolocateControl({
new GeolocateControl({
positionOptions: {
enableHighAccuracy: true,
},
Expand All @@ -216,14 +228,14 @@ function MapLibreView(props: {

map.addControl(
new MaplibreInspect({
popup: new maplibregl.Popup({
popup: new Popup({
closeButton: false,
closeOnClick: false,
}),
}),
);

const popup = new maplibregl.Popup({
const popup = new Popup({
closeButton: true,
closeOnClick: false,
maxWidth: "none",
Expand All @@ -245,7 +257,7 @@ function MapLibreView(props: {

return () => {
protocolRef = undefined;
maplibregl.removeProtocol("pmtiles");
removeProtocol("pmtiles");
map.remove();
};
});
Expand Down

0 comments on commit da22c80

Please sign in to comment.