Compare commits

...

9 Commits

Author SHA1 Message Date
prusswan d6067814a8 removed comment for react-dropzone import 2025-01-24 16:40:16 +08:00
prusswan a2809a9669 make it clearer that the added protocol is for PMTiles only 2025-01-24 16:26:35 +08:00
prusswan 7693217a92 cleaned up props name and console logging 2025-01-24 16:24:04 +08:00
prusswan 486ede54e0 fixed i18n for PMTiles dropzone 2025-01-24 15:37:25 +08:00
prusswan 9db49eee23 fixed lint errors 2025-01-24 12:24:15 +08:00
prusswan cdfe88ffc0 removed unused prop (files in AppToolbar)
fixed TypeScript errors
2025-01-24 12:18:11 +08:00
prusswan 0fbda5dc84 fix for Inspect to work with FileSource 2025-01-24 01:39:07 +08:00
prusswan 7ee8e44ca1 parse FileSource from dropped file for protocol.add
# Conflicts:
#	src/components/MapMaplibreGl.tsx
2025-01-24 01:06:36 +08:00
prusswan 979137eb9c added react-dropzone 2025-01-24 01:03:15 +08:00
10 changed files with 96 additions and 9 deletions
+39 -4
View File
@@ -51,6 +51,7 @@
"react-collapse": "^5.1.1", "react-collapse": "^5.1.1",
"react-color": "^2.19.3", "react-color": "^2.19.3",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-dropzone": "^14.3.5",
"react-file-reader-input": "^2.0.0", "react-file-reader-input": "^2.0.0",
"react-i18next": "^15.4.0", "react-i18next": "^15.4.0",
"react-icon-base": "^2.1.2", "react-icon-base": "^2.1.2",
@@ -3856,6 +3857,14 @@
"node": ">= 4.0.0" "node": ">= 4.0.0"
} }
}, },
"node_modules/attr-accept": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/attr-accept/-/attr-accept-2.2.5.tgz",
"integrity": "sha512-0bDNnY/u6pPwHDMoF0FieU354oBi0a8rD9FcsLwzcGWbc8KS8KPIi7y+s13OlVY+gMWc/9xEMUgNE6Qm8ZllYQ==",
"engines": {
"node": ">=4"
}
},
"node_modules/available-typed-arrays": { "node_modules/available-typed-arrays": {
"version": "1.0.7", "version": "1.0.7",
"resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz",
@@ -6219,6 +6228,17 @@
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz", "resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
"integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==" "integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
}, },
"node_modules/file-selector": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/file-selector/-/file-selector-2.1.2.tgz",
"integrity": "sha512-QgXo+mXTe8ljeqUFaX3QVHc5osSItJ/Km+xpocx0aSqWGMSCf6qYs/VnzZgS864Pjn5iceMRFigeAV7AfTlaig==",
"dependencies": {
"tslib": "^2.7.0"
},
"engines": {
"node": ">= 12"
}
},
"node_modules/fill-range": { "node_modules/fill-range": {
"version": "7.1.1", "version": "7.1.1",
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz",
@@ -10641,6 +10661,22 @@
"react": "^18.3.1" "react": "^18.3.1"
} }
}, },
"node_modules/react-dropzone": {
"version": "14.3.5",
"resolved": "https://registry.npmjs.org/react-dropzone/-/react-dropzone-14.3.5.tgz",
"integrity": "sha512-9nDUaEEpqZLOz5v5SUcFA0CjM4vq8YbqO0WRls+EYT7+DvxUdzDPKNCPLqGfj3YL9MsniCLCD4RFA6M95V6KMQ==",
"dependencies": {
"attr-accept": "^2.2.4",
"file-selector": "^2.1.0",
"prop-types": "^15.8.1"
},
"engines": {
"node": ">= 10.13"
},
"peerDependencies": {
"react": ">= 16.8 || 18.0.0"
}
},
"node_modules/react-file-reader-input": { "node_modules/react-file-reader-input": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/react-file-reader-input/-/react-file-reader-input-2.0.0.tgz", "resolved": "https://registry.npmjs.org/react-file-reader-input/-/react-file-reader-input-2.0.0.tgz",
@@ -12535,10 +12571,9 @@
} }
}, },
"node_modules/tslib": { "node_modules/tslib": {
"version": "2.6.2", "version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="
"dev": true
}, },
"node_modules/tunnel-agent": { "node_modules/tunnel-agent": {
"version": "0.6.0", "version": "0.6.0",
+1
View File
@@ -65,6 +65,7 @@
"react-collapse": "^5.1.1", "react-collapse": "^5.1.1",
"react-color": "^2.19.3", "react-color": "^2.19.3",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-dropzone": "^14.3.5",
"react-file-reader-input": "^2.0.0", "react-file-reader-input": "^2.0.0",
"react-i18next": "^15.4.0", "react-i18next": "^15.4.0",
"react-icon-base": "^2.1.2", "react-icon-base": "^2.1.2",
+13 -1
View File
@@ -8,7 +8,7 @@ import get from 'lodash.get'
import {unset} from 'lodash' import {unset} from 'lodash'
import {arrayMoveMutable} from 'array-move' import {arrayMoveMutable} from 'array-move'
import hash from "string-hash"; import hash from "string-hash";
import { PMTiles } from "pmtiles"; import { FileSource, PMTiles } from 'pmtiles';
import {Map, LayerSpecification, StyleSpecification, ValidationError, SourceSpecification} from 'maplibre-gl' import {Map, LayerSpecification, StyleSpecification, ValidationError, SourceSpecification} from 'maplibre-gl'
import {latest, validateStyleMin} from '@maplibre/maplibre-gl-style-spec' import {latest, validateStyleMin} from '@maplibre/maplibre-gl-style-spec'
@@ -131,6 +131,7 @@ type AppState = {
debug: boolean debug: boolean
} }
fileHandle: FileSystemFileHandle | null fileHandle: FileSystemFileHandle | null
localPMTiles: PMTiles | null
} }
export default class App extends React.Component<any, AppState> { export default class App extends React.Component<any, AppState> {
@@ -287,6 +288,7 @@ export default class App extends React.Component<any, AppState> {
debugToolbox: false, debugToolbox: false,
}, },
fileHandle: null, fileHandle: null,
localPMTiles: null
} }
this.layerWatcher = new LayerWatcher({ this.layerWatcher = new LayerWatcher({
@@ -741,6 +743,7 @@ export default class App extends React.Component<any, AppState> {
onChange={this.onMapChange} onChange={this.onMapChange}
options={this.state.maplibreGlDebugOptions} options={this.state.maplibreGlDebugOptions}
inspectModeEnabled={this.state.mapState === "inspect"} inspectModeEnabled={this.state.mapState === "inspect"}
localPMTiles={this.state.localPMTiles}
highlightedLayer={this.state.mapStyle.layers[this.state.selectedLayerIndex]} highlightedLayer={this.state.mapStyle.layers[this.state.selectedLayerIndex]}
onLayerSelect={this.onLayerSelect} /> onLayerSelect={this.onLayerSelect} />
} }
@@ -881,6 +884,14 @@ export default class App extends React.Component<any, AppState> {
}); });
} }
onFileSelected = (e: File[]) => {
const file = e[0];
const pmt = new PMTiles(new FileSource(file));
this.setState({
localPMTiles: pmt
})
}
render() { render() {
const layers = this.state.mapStyle.layers || [] const layers = this.state.mapStyle.layers || []
const selectedLayer = layers.length > 0 ? layers[this.state.selectedLayerIndex] : undefined const selectedLayer = layers.length > 0 ? layers[this.state.selectedLayerIndex] : undefined
@@ -895,6 +906,7 @@ export default class App extends React.Component<any, AppState> {
onStyleOpen={this.onStyleChanged} onStyleOpen={this.onStyleChanged}
onSetMapState={this.setMapState} onSetMapState={this.setMapState}
onToggleModal={this.toggleModal.bind(this)} onToggleModal={this.toggleModal.bind(this)}
onFileSelected={this.onFileSelected}
/> />
const layerList = <LayerList const layerList = <LayerList
+12
View File
@@ -17,6 +17,8 @@ import maputnikLogo from 'maputnik-design/logos/logo-color.svg?inline'
import { withTranslation, WithTranslation } from 'react-i18next'; import { withTranslation, WithTranslation } from 'react-i18next';
import { supportedLanguages } from '../i18n'; import { supportedLanguages } from '../i18n';
import Dropzone from 'react-dropzone';
// This is required because of <https://stackoverflow.com/a/49846426>, there isn't another way to detect support that I'm aware of. // This is required because of <https://stackoverflow.com/a/49846426>, there isn't another way to detect support that I'm aware of.
const browser = detect(); const browser = detect();
const colorAccessibilityFiltersEnabled = ['chrome', 'firefox'].indexOf(browser!.name) > -1; const colorAccessibilityFiltersEnabled = ['chrome', 'firefox'].indexOf(browser!.name) > -1;
@@ -103,6 +105,7 @@ type AppToolbarInternalProps = {
onSetMapState(mapState: MapState): unknown onSetMapState(mapState: MapState): unknown
mapState?: MapState mapState?: MapState
renderer?: string renderer?: string
onFileSelected(...args: unknown[]): unknown
} & WithTranslation; } & WithTranslation;
class AppToolbarInternal extends React.Component<AppToolbarInternalProps> { class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
@@ -289,6 +292,15 @@ class AppToolbarInternal extends React.Component<AppToolbarInternalProps> {
<MdHelpOutline /> <MdHelpOutline />
<IconText>{t("Help")}</IconText> <IconText>{t("Help")}</IconText>
</ToolbarLink> </ToolbarLink>
<Dropzone onDrop={this.props.onFileSelected}>
{({getRootProps, getInputProps}) => (
<div {...getRootProps({className: 'dropzone maputnik-toolbar-link'})}>
<input {...getInputProps()} />
{t("Drop PMTiles file here")}
</div>
)}
</Dropzone>
</div> </div>
</div> </div>
</nav> </nav>
+21 -4
View File
@@ -15,7 +15,7 @@ import MaplibreGeocoder, { MaplibreGeocoderApi, MaplibreGeocoderApiConfig } from
import '@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css'; import '@maplibre/maplibre-gl-geocoder/dist/maplibre-gl-geocoder.css';
import { withTranslation, WithTranslation } from 'react-i18next' import { withTranslation, WithTranslation } from 'react-i18next'
import i18next from 'i18next' import i18next from 'i18next'
import { Protocol } from "pmtiles"; import { PMTiles, Protocol } from "pmtiles";
function renderPopup(popup: JSX.Element, mountNode: ReactDOM.Container): HTMLElement { function renderPopup(popup: JSX.Element, mountNode: ReactDOM.Container): HTMLElement {
ReactDOM.render(popup, mountNode); ReactDOM.render(popup, mountNode);
@@ -66,6 +66,7 @@ type MapMaplibreGlInternalProps = {
} }
replaceAccessTokens(mapStyle: StyleSpecification): StyleSpecification replaceAccessTokens(mapStyle: StyleSpecification): StyleSpecification
onChange(value: {center: LngLat, zoom: number}): unknown onChange(value: {center: LngLat, zoom: number}): unknown
localPMTiles: PMTiles | null;
} & WithTranslation; } & WithTranslation;
type MapMaplibreGlState = { type MapMaplibreGlState = {
@@ -74,6 +75,7 @@ type MapMaplibreGlState = {
geocoder: MaplibreGeocoder | null; geocoder: MaplibreGeocoder | null;
zoomControl: ZoomControl | null; zoomControl: ZoomControl | null;
zoom?: number; zoom?: number;
pmtilesProtocol: Protocol | null;
}; };
class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps, MapMaplibreGlState> { class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps, MapMaplibreGlState> {
@@ -93,6 +95,7 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
inspect: null, inspect: null,
geocoder: null, geocoder: null,
zoomControl: null, zoomControl: null,
pmtilesProtocol: new Protocol({metadata: true})
} }
i18next.on('languageChanged', () => { i18next.on('languageChanged', () => {
this.forceUpdate(); this.forceUpdate();
@@ -134,7 +137,21 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
this.state.inspect!.render(); this.state.inspect!.render();
}, 500); }, 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() { componentDidMount() {
@@ -149,8 +166,8 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
localIdeographFontFamily: false localIdeographFontFamily: false
} satisfies MapOptions; } satisfies MapOptions;
const protocol = new Protocol({metadata: true}); MapLibreGl.addProtocol("pmtiles", this.state.pmtilesProtocol!.tile);
MapLibreGl.addProtocol("pmtiles",protocol.tile);
const map = new MapLibreGl.Map(mapOpts); const map = new MapLibreGl.Map(mapOpts);
const mapViewChange = () => { const mapViewChange = () => {
+2
View File
@@ -35,6 +35,7 @@
"View": "Ansicht", "View": "Ansicht",
"Color accessibility": "Farbzugänglichkeit", "Color accessibility": "Farbzugänglichkeit",
"Help": "Hilfe", "Help": "Hilfe",
"Drop PMTiles file here": "__STRING_NOT_TRANSLATED__",
"Comments for the current layer. This is non-standard and not in the spec.": "Kommentare zur aktuellen Ebene. Das ist nicht standardmäßig und nicht in der Spezifikation.", "Comments for the current layer. This is non-standard and not in the spec.": "Kommentare zur aktuellen Ebene. Das ist nicht standardmäßig und nicht in der Spezifikation.",
"Comments": "Kommentare", "Comments": "Kommentare",
"Comment...": "Dein Kommentar...", "Comment...": "Dein Kommentar...",
@@ -81,6 +82,7 @@
"Close modal": "Modale Fenster schließen", "Close modal": "Modale Fenster schließen",
"Debug": "Debug", "Debug": "Debug",
"Options": "Optionen", "Options": "Optionen",
"<0>Open in OSM</0> &mdash; Opens the current view on openstreetmap.org": "__STRING_NOT_TRANSLATED__",
"Save Style": "Stil Speichern", "Save Style": "Stil Speichern",
"Save the JSON style to your computer.": "Speichere den JSON Stil auf deinem Computer.", "Save the JSON style to your computer.": "Speichere den JSON Stil auf deinem Computer.",
"Save as": "Speichern unter", "Save as": "Speichern unter",
+2
View File
@@ -35,6 +35,7 @@
"View": "Vue", "View": "Vue",
"Color accessibility": "Accessibilité des couleurs", "Color accessibility": "Accessibilité des couleurs",
"Help": "Aide", "Help": "Aide",
"Drop PMTiles file here": "__STRING_NOT_TRANSLATED__",
"Comments for the current layer. This is non-standard and not in the spec.": "Commentaires pour le calque actuel. Ceci n'est pas standard et n'est pas dans la spécification.", "Comments for the current layer. This is non-standard and not in the spec.": "Commentaires pour le calque actuel. Ceci n'est pas standard et n'est pas dans la spécification.",
"Comments": "Commentaires", "Comments": "Commentaires",
"Comment...": "Votre commentaire...", "Comment...": "Votre commentaire...",
@@ -81,6 +82,7 @@
"Close modal": "Fermer la fenêtre modale", "Close modal": "Fermer la fenêtre modale",
"Debug": "Déboguer", "Debug": "Déboguer",
"Options": "Options", "Options": "Options",
"<0>Open in OSM</0> &mdash; Opens the current view on openstreetmap.org": "__STRING_NOT_TRANSLATED__",
"Save Style": "Enregistrer le style", "Save Style": "Enregistrer le style",
"Save the JSON style to your computer.": "Enregistrer le style JSON sur votre ordinateur.", "Save the JSON style to your computer.": "Enregistrer le style JSON sur votre ordinateur.",
"Save as": "Enregistrer sous", "Save as": "Enregistrer sous",
+2
View File
@@ -35,6 +35,7 @@
"View": "תצוגה", "View": "תצוגה",
"Color accessibility": "נגישות צבעים", "Color accessibility": "נגישות צבעים",
"Help": "עזרה", "Help": "עזרה",
"Drop PMTiles file here": "__STRING_NOT_TRANSLATED__",
"Comments for the current layer. This is non-standard and not in the spec.": "הערות על השכבה הנוכחית. זה לא חלק מהספסיפיקציות", "Comments for the current layer. This is non-standard and not in the spec.": "הערות על השכבה הנוכחית. זה לא חלק מהספסיפיקציות",
"Comments": "הערות", "Comments": "הערות",
"Comment...": "הערה...", "Comment...": "הערה...",
@@ -81,6 +82,7 @@
"Close modal": "סגירת חלונית", "Close modal": "סגירת חלונית",
"Debug": "דיבאג", "Debug": "דיבאג",
"Options": "אפשרויות", "Options": "אפשרויות",
"<0>Open in OSM</0> &mdash; Opens the current view on openstreetmap.org": "__STRING_NOT_TRANSLATED__",
"Save Style": "שמירת הסטייל", "Save Style": "שמירת הסטייל",
"Save the JSON style to your computer.": "שמירת הסטייל JSON במחשב שלך.", "Save the JSON style to your computer.": "שמירת הסטייל JSON במחשב שלך.",
"Save as": "שמירה בשם", "Save as": "שמירה בשם",
+2
View File
@@ -35,6 +35,7 @@
"View": "表示", "View": "表示",
"Color accessibility": "色のアクセシビリティ", "Color accessibility": "色のアクセシビリティ",
"Help": "ヘルプ", "Help": "ヘルプ",
"Drop PMTiles file here": "__STRING_NOT_TRANSLATED__",
"Comments for the current layer. This is non-standard and not in the spec.": "現在のレイヤーのコメント。注意:この機能は標準ではないため、他のライブラリとの互換性状況はわかりません。", "Comments for the current layer. This is non-standard and not in the spec.": "現在のレイヤーのコメント。注意:この機能は標準ではないため、他のライブラリとの互換性状況はわかりません。",
"Comments": "コメント", "Comments": "コメント",
"Comment...": "コメントを書く", "Comment...": "コメントを書く",
@@ -81,6 +82,7 @@
"Close modal": "モーダルを閉じる", "Close modal": "モーダルを閉じる",
"Debug": "デバッグ", "Debug": "デバッグ",
"Options": "設定", "Options": "設定",
"<0>Open in OSM</0> &mdash; Opens the current view on openstreetmap.org": "__STRING_NOT_TRANSLATED__",
"Save Style": "スタイルを保存", "Save Style": "スタイルを保存",
"Save the JSON style to your computer.": "JSONスタイルをコンピュータに保存します。", "Save the JSON style to your computer.": "JSONスタイルをコンピュータに保存します。",
"Save as": "名前を付けて保存", "Save as": "名前を付けて保存",
+2
View File
@@ -35,6 +35,7 @@
"View": "视图", "View": "视图",
"Color accessibility": "颜色可访问性", "Color accessibility": "颜色可访问性",
"Help": "帮助", "Help": "帮助",
"Drop PMTiles file here": "__STRING_NOT_TRANSLATED__",
"Comments for the current layer. This is non-standard and not in the spec.": "当前图层的注释。注意:这不是标准功能,可能与其他库不兼容。", "Comments for the current layer. This is non-standard and not in the spec.": "当前图层的注释。注意:这不是标准功能,可能与其他库不兼容。",
"Comments": "注释", "Comments": "注释",
"Comment...": "写注释...", "Comment...": "写注释...",
@@ -81,6 +82,7 @@
"Close modal": "关闭模态框", "Close modal": "关闭模态框",
"Debug": "调试", "Debug": "调试",
"Options": "选项", "Options": "选项",
"<0>Open in OSM</0> &mdash; Opens the current view on openstreetmap.org": "__STRING_NOT_TRANSLATED__",
"Save Style": "保存样式", "Save Style": "保存样式",
"Save the JSON style to your computer.": "将JSON样式保存到您的计算机。", "Save the JSON style to your computer.": "将JSON样式保存到您的计算机。",
"Save as": "另存为", "Save as": "另存为",