-
-
Notifications
You must be signed in to change notification settings - Fork 446
Add support for local pmtiles tile package (via drag and drop) #1025
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
979137e
7ee8e44
0fbda5d
cdfe88f
9db49ee
486ede5
7693217
a2809a9
d606781
a2572c2
d6cde2f
cbbac9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ import MaplibreGeocoder, { MaplibreGeocoderApi, MaplibreGeocoderApiConfig } from | |
| import '@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css'; | ||
| import { withTranslation, WithTranslation } from 'react-i18next' | ||
| import i18next from 'i18next' | ||
| import { Protocol } from "pmtiles"; | ||
| import { PMTiles, Protocol } from "pmtiles"; | ||
|
|
||
| function renderPopup(popup: JSX.Element, mountNode: ReactDOM.Container): HTMLElement { | ||
| ReactDOM.render(popup, mountNode); | ||
|
|
@@ -66,6 +66,7 @@ type MapMaplibreGlInternalProps = { | |
| } | ||
| replaceAccessTokens(mapStyle: StyleSpecification): StyleSpecification | ||
| onChange(value: {center: LngLat, zoom: number}): unknown | ||
| localPMTiles: PMTiles | null; | ||
| } & WithTranslation; | ||
|
|
||
| type MapMaplibreGlState = { | ||
|
|
@@ -74,6 +75,7 @@ type MapMaplibreGlState = { | |
| geocoder: MaplibreGeocoder | null; | ||
| zoomControl: ZoomControl | null; | ||
| zoom?: number; | ||
| pmtilesProtocol: Protocol | null; | ||
| }; | ||
|
|
||
| class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps, MapMaplibreGlState> { | ||
|
|
@@ -93,6 +95,7 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps, | |
| inspect: null, | ||
| geocoder: null, | ||
| zoomControl: null, | ||
| pmtilesProtocol: new Protocol({metadata: true}) | ||
| } | ||
| i18next.on('languageChanged', () => { | ||
| this.forceUpdate(); | ||
|
|
@@ -134,7 +137,21 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps, | |
| this.state.inspect!.render(); | ||
| }, 500); | ||
| } | ||
|
|
||
|
|
||
| if (this.props.localPMTiles) { | ||
| const file = this.props.localPMTiles; | ||
| this.state.pmtilesProtocol!.add(file); // this is necessary for non-HTTP sources | ||
|
|
||
| if (map) { | ||
| file.getMetadata().then((metadata: any) => { | ||
|
||
| const layerNames = metadata.vector_layers.map((e: LayerSpecification) => e.id); | ||
|
|
||
| // used by maplibre-gl-inspect to pick up inspectable layers | ||
| map.style.sourceCaches["source"]._source.vectorLayerIds = layerNames; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| componentDidMount() { | ||
|
|
@@ -149,8 +166,8 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps, | |
| localIdeographFontFamily: false | ||
| } satisfies MapOptions; | ||
|
|
||
| const protocol = new Protocol({metadata: true}); | ||
| MapLibreGl.addProtocol("pmtiles",protocol.tile); | ||
| MapLibreGl.addProtocol("pmtiles", this.state.pmtilesProtocol!.tile); | ||
|
|
||
| const map = new MapLibreGl.Map(mapOpts); | ||
|
|
||
| const mapViewChange = () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.