-
-
Notifications
You must be signed in to change notification settings - Fork 82
Add stubby MapLibre shell using local style and tiles resources #535
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
748ed9a
Added stubby MapLibre shell using local style and tiles resources
migurski 6097b6c
Moved starter template down to local.html
migurski 9d9a712
Added basemap-assets so fonts and sprites are also local
migurski 97264ef
Copied useful instructions to local.html
migurski b90ae02
Merge branch 'main' into migurski/init-starter-template
migurski 3d25f01
Merge branch 'main' of https://github.com/protomaps/basemaps into mig…
migurski 00cfe09
Replaced recommended tiles build with direct mvn/java calls
migurski a4fc1aa
Replaced submodule with a curl/unzip from protomaps/basemaps-assets
migurski 42fc66e
Finished removing the submodule
migurski 3c491eb
Added optional glyph and sprites args for generate_style
migurski 815248a
Lint
migurski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| .vscode | ||
| node_modules | ||
| basemaps-assets |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| <!DOCTYPE html> | ||
| <!-- | ||
|
|
||
| This example displays a map using Tiles and Styles generated locally. | ||
| Use it to preview basemap changes made in this repository. | ||
|
|
||
| Start by building tiles/data/monaco.pmtiles: | ||
|
|
||
| cd tiles | ||
| mvn clean package -DskipTests | ||
| java -jar target/*-with-deps.jar --download --area=monaco --force | ||
| cd - | ||
|
|
||
| Generate styles/style.json with sprites and fonts in a local basemaps-assets directory: | ||
|
|
||
| cd styles | ||
| npm run generate_style style.json https://example.com/tilejson.json light en \ | ||
| 'http://localhost:8080/basemaps-assets/sprites/v4/light' \ | ||
| 'http://localhost:8080/basemaps-assets/fonts/{fontstack}/{range}.pbf' | ||
| cd - | ||
|
|
||
| Populate basemaps-assets directory with fonts and sprite sheets: | ||
|
|
||
| curl -L https://github.com/protomaps/basemaps-assets/archive/refs/heads/main.zip -o /tmp/basemaps-assets-main.zip | ||
| unzip /tmp/basemaps-assets-main.zip 'basemaps-assets-main/fonts/*' 'basemaps-assets-main/sprites/*' -d /tmp | ||
| mv /tmp/basemaps-assets-main basemaps-assets | ||
|
|
||
| Run local web server to view http://localhost:8080/examples/local.html: | ||
|
|
||
| npx http-server -p 8080 -c-1 | ||
|
|
||
| --> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Local Styles and Tiles - Protomaps Starter</title> | ||
|
|
||
| <!-- MapLibre GL JS --> | ||
| <script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script> | ||
| <link href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" rel="stylesheet"> | ||
|
|
||
| <!-- PMTiles protocol --> | ||
| <script src="https://unpkg.com/[email protected]/dist/pmtiles.js"></script> | ||
|
|
||
| <style> | ||
| body { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
| #map { | ||
| position: absolute; | ||
| top: 0; | ||
| bottom: 0; | ||
| width: 100%; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div id="map"></div> | ||
|
|
||
| <script> | ||
| // Register PMTiles protocol | ||
| let protocol = new pmtiles.Protocol(); | ||
| maplibregl.addProtocol("pmtiles", protocol.tile); | ||
|
|
||
| // Load and modify the style to use local PMTiles | ||
| fetch('../styles/style.json') | ||
| .then(response => response.json()) | ||
| .then(style => { | ||
| // Replace the source URL with the local PMTiles file | ||
| style.sources.protomaps = { | ||
| type: "vector", | ||
| url: "pmtiles://../tiles/monaco.pmtiles", | ||
| attribution: style.sources.protomaps.attribution | ||
| }; | ||
|
|
||
| // Initialize map with modified style | ||
| const map = new maplibregl.Map({ | ||
| container: 'map', | ||
| style: style, | ||
| center: [7.41488, 43.73019], // Monaco [longitude, latitude] | ||
| zoom: 16, | ||
| hash: true // Allows sharing location via URL hash | ||
| }); | ||
|
|
||
| // Add navigation controls | ||
| map.addControl(new maplibregl.NavigationControl(), 'top-right'); | ||
|
|
||
| // Add scale control | ||
| map.addControl(new maplibregl.ScaleControl({ | ||
| maxWidth: 80, | ||
| unit: 'metric' | ||
| }), 'bottom-left'); | ||
| }) | ||
| .catch(error => { | ||
| console.error('Error loading style:', error); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.