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

Enable MapLibre 5.0 globe view with control. #346

Merged
merged 1 commit into from
Jan 6, 2025
Merged
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
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
Loading