mirror of
https://github.com/maputnik/editor.git
synced 2026-08-02 03:07:27 +00:00
Compare commits
107 Commits
9b8668e559
..
v3.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fc334ad85 | |||
| 42a040e91a | |||
| f5757dd8a2 | |||
| 3b79303f83 | |||
| 55a487d0c8 | |||
| 03f3c5c032 | |||
| 02efeec96d | |||
| 4896c40554 | |||
| 40f1837835 | |||
| 3f94ab2f3b | |||
| 0cd4ab6e0a | |||
| fce182050d | |||
| abe6230932 | |||
| 6f4c34b29a | |||
| 3f011a21dc | |||
| 54c1b761fd | |||
| 7289e26563 | |||
| 4d5c74f4ee | |||
| 285fa6e509 | |||
| 5d4b9e9654 | |||
| bd576e7bae | |||
| 8d5d8e1ee0 | |||
| b503a44aa4 | |||
| 1607c985d9 | |||
| bdcc5ddc31 | |||
| 2545c55f1a | |||
| b238e07b0b | |||
| fc500449d7 | |||
| 0af01c7c39 | |||
| 65f4ced302 | |||
| c78025c9e4 | |||
| 1fbeb66f55 | |||
| 3ad55d7f97 | |||
| ba35f260a5 | |||
| d178e2f46b | |||
| 60bcfcf208 | |||
| 7ceb2ccabd | |||
| d5140d77ba | |||
| 70571dc1cc | |||
| 62f1a0622a | |||
| 9b9f0b4c78 | |||
| e2e29d7f5e | |||
| 728de3aed6 | |||
| f1d98099df | |||
| 9e7cec932b | |||
| 701e1f4c79 | |||
| 9f682a4213 | |||
| 530907610e | |||
| 719c8e5a22 | |||
| 104ce8221c | |||
| 81c157e3e3 | |||
| 0b466fd3b8 | |||
| 0eeba50de8 | |||
| 23b24376ee | |||
| d852443a03 | |||
| 4f3a8c8ecf | |||
| 6742c0b3a9 | |||
| cf9d9cb2ab | |||
| 727bc7dfae | |||
| 0bbb04e4ff | |||
| 4ea1958275 | |||
| db93ce1be1 | |||
| 2d242c2a47 | |||
| 1805763ba5 | |||
| 499d183dcc | |||
| 60c57135c4 | |||
| 0098931748 | |||
| 9067746fbd | |||
| a168b3a3b1 | |||
| c2f21364f2 | |||
| 84452b555c | |||
| 24445cc411 | |||
| 3545264d69 | |||
| 5870336c63 | |||
| 751e92224c | |||
| 8e19a63d30 | |||
| 0c9870368e | |||
| b2fa703ceb | |||
| c1fde6f749 | |||
| 0aa0c57fb2 | |||
| 3ddb55aec7 | |||
| 2fef0467b6 | |||
| eb985f4d95 | |||
| c486aa2139 | |||
| 244dbfb194 | |||
| 533f647c71 | |||
| 4b977fd33e | |||
| e58b92b0cd | |||
| 6de2705ac7 | |||
| f66ed31c85 | |||
| 599240033a | |||
| f5b7eccf52 | |||
| 14032136a7 | |||
| 2c12f00467 | |||
| 516554fd82 | |||
| 0b8dd230c6 | |||
| 076013450e | |||
| af6fcff85c | |||
| 42f5247c27 | |||
| f8e6bbf268 | |||
| 0e24478c38 | |||
| 61f867c7fa | |||
| 71c04d7d2e | |||
| bdb0e0ef37 | |||
| ed97eed7e0 | |||
| 4b0fb350b8 | |||
| 806cefe98f |
+29
-23
@@ -7,17 +7,7 @@ on:
|
|||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-docker:
|
|
||||||
name: build docker
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- run: docker build -t test-docker-image-build .
|
|
||||||
|
|
||||||
# build the editor
|
|
||||||
build-node:
|
build-node:
|
||||||
name: "build on ${{ matrix.os }}"
|
name: "build on ${{ matrix.os }}"
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@@ -30,8 +20,8 @@ jobs:
|
|||||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version-file: '.nvmrc'
|
node-version-file: '.nvmrc'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -47,8 +37,8 @@ jobs:
|
|||||||
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
|
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version-file: '.nvmrc'
|
node-version-file: '.nvmrc'
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
@@ -61,7 +51,7 @@ jobs:
|
|||||||
|
|
||||||
# Build and upload desktop CLI artifacts
|
# Build and upload desktop CLI artifacts
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v6
|
||||||
with:
|
with:
|
||||||
go-version: ^1.23.x
|
go-version: ^1.23.x
|
||||||
cache-dependency-path: desktop/go.sum
|
cache-dependency-path: desktop/go.sum
|
||||||
@@ -89,23 +79,39 @@ jobs:
|
|||||||
path: ./desktop/bin/windows/
|
path: ./desktop/bin/windows/
|
||||||
|
|
||||||
e2e-tests:
|
e2e-tests:
|
||||||
name: "E2E tests using ${{ matrix.browser }}"
|
name: "E2E tests using chrome"
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
browser: [ chrome ]
|
|
||||||
|
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- name: Cypress run
|
- name: Cypress run
|
||||||
uses: cypress-io/github-action@v6
|
uses: cypress-io/github-action@v6
|
||||||
with:
|
with:
|
||||||
build: npm run build
|
build: npm run build
|
||||||
start: npm run start
|
start: npm run start
|
||||||
browser: ${{ matrix.browser }}
|
browser: chrome
|
||||||
|
- name: Upload coverage reports to Codecov
|
||||||
|
uses: codecov/codecov-action@v5
|
||||||
|
with:
|
||||||
|
files: ${{ github.workspace }}/.nyc_output/out.json
|
||||||
|
verbose: true
|
||||||
|
|
||||||
|
e2e-tests-docker:
|
||||||
|
name: "E2E tests using chrome and docker"
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
- run: npm ci
|
||||||
|
- name: Cypress run
|
||||||
|
uses: cypress-io/github-action@v6
|
||||||
|
with:
|
||||||
|
build: docker build -t maputnik .
|
||||||
|
start: docker run --rm --network host maputnik --port=8888
|
||||||
|
browser: chrome
|
||||||
- name: Upload coverage reports to Codecov
|
- name: Upload coverage reports to Codecov
|
||||||
uses: codecov/codecov-action@v5
|
uses: codecov/codecov-action@v5
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: main
|
ref: main
|
||||||
|
|
||||||
- name: Use Node.js from nvmrc
|
- name: Use Node.js from nvmrc
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version-file: ".nvmrc"
|
node-version-file: ".nvmrc"
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: ${{ github.event_name == 'push' }}
|
if: ${{ github.event_name == 'push' }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Use Node.js from nvmrc
|
- name: Use Node.js from nvmrc
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version-file: '.nvmrc'
|
node-version-file: '.nvmrc'
|
||||||
|
|
||||||
@@ -46,6 +46,6 @@ jobs:
|
|||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- run: docker build -t ghcr.io/maplibre/maputnik:main .
|
- run: docker build -t ghcr.io/maplibre/maputnik:main .
|
||||||
- run: docker push ghcr.io/maplibre/maputnik:main
|
- run: docker push ghcr.io/maplibre/maputnik:main
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: main
|
ref: main
|
||||||
|
|
||||||
- name: Use Node.js from nvmrc
|
- name: Use Node.js from nvmrc
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version-file: ".nvmrc"
|
node-version-file: ".nvmrc"
|
||||||
|
|
||||||
@@ -39,19 +39,19 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
shell: bash
|
shell: bash
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: main
|
ref: main
|
||||||
|
|
||||||
- name: Use Node.js from nvmrc
|
- name: Use Node.js from nvmrc
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v5
|
||||||
with:
|
with:
|
||||||
node-version-file: ".nvmrc"
|
node-version-file: ".nvmrc"
|
||||||
registry-url: "https://registry.npmjs.org"
|
registry-url: "https://registry.npmjs.org"
|
||||||
|
|
||||||
- name: Set up Go for desktop build
|
- name: Set up Go for desktop build
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v6
|
||||||
with:
|
with:
|
||||||
go-version: ^1.23.x
|
go-version: ^1.23.x
|
||||||
cache-dependency-path: desktop/go.sum
|
cache-dependency-path: desktop/go.sum
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ ci:
|
|||||||
|
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v5.0.0
|
rev: v6.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-added-large-files
|
- id: check-added-large-files
|
||||||
- id: check-executables-have-shebangs
|
- id: check-executables-have-shebangs
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
Maputnik is a MapLibre style editor written using React and TypeScript.
|
||||||
|
|
||||||
|
To get started, install all npm packages:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
Verify code correctness by running ESLint:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run lint
|
||||||
|
```
|
||||||
|
|
||||||
|
Or try fixing lint issues with:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run lint -- --fix
|
||||||
|
```
|
||||||
|
|
||||||
|
The project type checked and built with:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
To run the tests make sure that xvfb is installed:
|
||||||
|
|
||||||
|
```
|
||||||
|
apt install xvfb
|
||||||
|
```
|
||||||
|
|
||||||
|
Run the development server in the background with Vite:
|
||||||
|
|
||||||
|
```
|
||||||
|
nohup npm run start &
|
||||||
|
```
|
||||||
|
|
||||||
|
Then start the Cypress tests with:
|
||||||
|
|
||||||
|
```
|
||||||
|
xvfb-run -a npm run test
|
||||||
|
```
|
||||||
|
|
||||||
|
## Pull Requests
|
||||||
|
|
||||||
|
- Pull requests should update `CHANGELOG.md` with a short description of the change.
|
||||||
+21
-2
@@ -1,5 +1,14 @@
|
|||||||
## main
|
## main
|
||||||
|
|
||||||
|
### ✨ Features and improvements
|
||||||
|
- _...Add new stuff here..._
|
||||||
|
|
||||||
|
### 🐞 Bug fixes
|
||||||
|
|
||||||
|
- _...Add new stuff here..._
|
||||||
|
|
||||||
|
## 3.0.0
|
||||||
|
|
||||||
### ✨ Features and improvements
|
### ✨ Features and improvements
|
||||||
- Fix radio/delete filter buttons styling regression
|
- Fix radio/delete filter buttons styling regression
|
||||||
- Add german translation
|
- Add german translation
|
||||||
@@ -11,12 +20,22 @@
|
|||||||
- Upgrade to MapLibre LG JS v5
|
- Upgrade to MapLibre LG JS v5
|
||||||
- Upgrade Vite 6 and Cypress 14 ([#970](https://github.com/maplibre/maputnik/pull/970))
|
- Upgrade Vite 6 and Cypress 14 ([#970](https://github.com/maplibre/maputnik/pull/970))
|
||||||
- Upgrade OpenLayers from v6 to v10
|
- Upgrade OpenLayers from v6 to v10
|
||||||
- _...Add new stuff here..._
|
- When loading a style into localStorage that causes a QuotaExceededError, purge localStorage and retry
|
||||||
|
- Remove react-autobind dependency
|
||||||
|
- Remove usage of legacy `childContextTypes` API
|
||||||
|
- Refactor Field components to use arrow function syntax
|
||||||
|
- Replace react-autocomplete with Downshift in the autocomplete component
|
||||||
|
- Add LocationIQ as supported map provider with access token field and gallery style
|
||||||
|
- Use maputnik go binary for the docker image to allow file watching
|
||||||
|
- Revmove support for `debug` and `localport` url parameters
|
||||||
|
- Replace react-sortable-hoc with dnd-kit to avoid react console warnings and also use a maintained library
|
||||||
|
|
||||||
### 🐞 Bug fixes
|
### 🐞 Bug fixes
|
||||||
|
|
||||||
- Fix incorrect handing of network error response (#944)
|
- Fix incorrect handing of network error response (#944)
|
||||||
- _...Add new stuff here..._
|
- Show an error when adding a layer with a duplicate ID
|
||||||
|
- Replace deprecated `ReactDOM.render` usage with `createRoot` and drop the
|
||||||
|
`DOMNodeRemoved` cleanup hack
|
||||||
|
|
||||||
## 2.1.1
|
## 2.1.1
|
||||||
|
|
||||||
|
|||||||
+8
-10
@@ -1,16 +1,14 @@
|
|||||||
FROM node:18 as builder
|
FROM golang:1.23-alpine AS builder
|
||||||
WORKDIR /maputnik
|
WORKDIR /maputnik
|
||||||
|
|
||||||
# Only copy package.json to prevent npm install from running on every build
|
RUN apk add --no-cache nodejs npm make git gcc g++ libc-dev
|
||||||
COPY package.json package-lock.json .npmrc ./
|
|
||||||
RUN npm ci
|
|
||||||
|
|
||||||
# Build maputnik
|
# Build maputnik
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npx vite build
|
RUN npm ci
|
||||||
|
RUN CGO_ENABLED=1 GOOS=linux npm run build-linux
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
FROM alpine:latest
|
||||||
# Create a clean nginx-alpine slim image with just the build results
|
WORKDIR /app
|
||||||
FROM nginx:alpine-slim
|
COPY --from=builder /maputnik/desktop/bin/linux ./
|
||||||
|
ENTRYPOINT ["/app/maputnik"]
|
||||||
COPY --from=builder /maputnik/dist /usr/share/nginx/html/
|
|
||||||
|
|||||||
@@ -18,9 +18,15 @@ targeted at developers and map designers.
|
|||||||
- In a Docker, run this command and browse to http://localhost:8888, Ctrl+C to stop the server.
|
- In a Docker, run this command and browse to http://localhost:8888, Ctrl+C to stop the server.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -it --rm -p 8888:80 ghcr.io/maplibre/maputnik:main
|
docker run -it --rm -p 8888:8000 ghcr.io/maplibre/maputnik:main
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To see the CLI options (for example file watching or style serving) run:
|
||||||
|
```bash
|
||||||
|
docker run -it --rm -p 8888:8000 ghcr.io/maplibre/maputnik:main --help
|
||||||
|
```
|
||||||
|
You might need to mount a volume (`-v`) to be able to use these options.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
The documentation can be found in the [Wiki](https://github.com/maplibre/maputnik/wiki). You are welcome to collaborate!
|
The documentation can be found in the [Wiki](https://github.com/maplibre/maputnik/wiki). You are welcome to collaborate!
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export default defineConfig({
|
|||||||
exclude: "cypress/**/*.*",
|
exclude: "cypress/**/*.*",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
e2e: {
|
e2e: {
|
||||||
setupNodeEvents(on, config) {
|
setupNodeEvents(on, config) {
|
||||||
// implement node event listeners here
|
// implement node event listeners here
|
||||||
@@ -20,4 +21,11 @@ export default defineConfig({
|
|||||||
openMode: 0,
|
openMode: 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
component: {
|
||||||
|
devServer: {
|
||||||
|
framework: "react",
|
||||||
|
bundler: "vite",
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ describe("history", () => {
|
|||||||
it("undo/redo", () => {
|
it("undo/redo", () => {
|
||||||
when.setStyle("geojson");
|
when.setStyle("geojson");
|
||||||
when.modal.open();
|
when.modal.open();
|
||||||
then(get.styleFromLocalStorage()).shouldDeepNestedInclude({ layers: [] });
|
|
||||||
|
|
||||||
when.modal.fillLayers({
|
when.modal.fillLayers({
|
||||||
id: "step 1",
|
id: "step 1",
|
||||||
|
|||||||
@@ -378,8 +378,57 @@ describe("layers", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("groups", () => {
|
it("groups", () => {
|
||||||
// TODO
|
when.modal.open();
|
||||||
// Click each of the layer groups.
|
const id1 = when.modal.fillLayers({
|
||||||
|
id: "aa",
|
||||||
|
type: "line",
|
||||||
|
layer: "example",
|
||||||
|
});
|
||||||
|
|
||||||
|
when.modal.open();
|
||||||
|
const id2 = when.modal.fillLayers({
|
||||||
|
id: "aa-2",
|
||||||
|
type: "line",
|
||||||
|
layer: "example",
|
||||||
|
});
|
||||||
|
|
||||||
|
when.modal.open();
|
||||||
|
const id3 = when.modal.fillLayers({
|
||||||
|
id: "b",
|
||||||
|
type: "line",
|
||||||
|
layer: "example",
|
||||||
|
});
|
||||||
|
|
||||||
|
then(get.elementByTestId("layer-list-item:" + id1)).shouldBeVisible();
|
||||||
|
then(get.elementByTestId("layer-list-item:" + id2)).shouldNotBeVisible();
|
||||||
|
then(get.elementByTestId("layer-list-item:" + id3)).shouldBeVisible();
|
||||||
|
when.click("layer-list-group:aa-0");
|
||||||
|
then(get.elementByTestId("layer-list-item:" + id1)).shouldBeVisible();
|
||||||
|
then(get.elementByTestId("layer-list-item:" + id2)).shouldBeVisible();
|
||||||
|
then(get.elementByTestId("layer-list-item:" + id3)).shouldBeVisible();
|
||||||
|
when.click("layer-list-item:" + id2);
|
||||||
|
when.click("skip-target-layer-editor");
|
||||||
|
when.click("menu-move-layer-down");
|
||||||
|
then(get.elementByTestId("layer-list-group:aa-0")).shouldNotExist();
|
||||||
|
then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
||||||
|
layers: [
|
||||||
|
{
|
||||||
|
id: "aa",
|
||||||
|
type: "line",
|
||||||
|
source: "example",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "b",
|
||||||
|
type: "line",
|
||||||
|
source: "example",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "aa-2",
|
||||||
|
type: "line",
|
||||||
|
source: "example",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -495,9 +544,7 @@ describe("layers", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe("layereditor jsonlint should error", ()=>{
|
describe("layereditor jsonlint should error", ()=>{
|
||||||
|
|
||||||
it("add", () => {
|
it("add", () => {
|
||||||
const id = when.modal.fillLayers({
|
const id = when.modal.fillLayers({
|
||||||
type: "circle",
|
type: "circle",
|
||||||
@@ -523,4 +570,42 @@ describe("layers", () => {
|
|||||||
error.should('exist');
|
error.should('exist');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("drag and drop", () => {
|
||||||
|
it("move layer should update local storage", () => {
|
||||||
|
when.modal.open();
|
||||||
|
const firstId = when.modal.fillLayers({
|
||||||
|
id: "a",
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
when.modal.open();
|
||||||
|
const secondId = when.modal.fillLayers({
|
||||||
|
id: "b",
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
when.modal.open();
|
||||||
|
const thirdId = when.modal.fillLayers({
|
||||||
|
id: "c",
|
||||||
|
type: "background",
|
||||||
|
});
|
||||||
|
when.dragAndDrop(get.elementByTestId("layer-list-item:" + firstId), get.elementByTestId("layer-list-item:" + thirdId));
|
||||||
|
|
||||||
|
then(get.styleFromLocalStorage()).shouldDeepNestedInclude({
|
||||||
|
layers: [
|
||||||
|
{
|
||||||
|
id: secondId,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: thirdId,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: firstId,
|
||||||
|
type: "background",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ const baseUrl = "http://localhost:8888/";
|
|||||||
|
|
||||||
const styleFromWindow = (win: Window) => {
|
const styleFromWindow = (win: Window) => {
|
||||||
const styleId = win.localStorage.getItem("maputnik:latest_style");
|
const styleId = win.localStorage.getItem("maputnik:latest_style");
|
||||||
const styleItem = win.localStorage.getItem(`maputnik:style:${styleId}`);
|
const styleItemKey = `maputnik:style:${styleId}`;
|
||||||
const obj = JSON.parse(styleItem || "");
|
const styleItem = win.localStorage.getItem(styleItemKey);
|
||||||
|
if (!styleItem) throw new Error("Could not get styleItem from localStorage");
|
||||||
|
const obj = JSON.parse(styleItem);
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,8 +94,8 @@ export class MaputnikDriver {
|
|||||||
public when = {
|
public when = {
|
||||||
...this.helper.when,
|
...this.helper.when,
|
||||||
modal: this.modalDriver.when,
|
modal: this.modalDriver.when,
|
||||||
within: (selector: string, fn: () => void) => {
|
doWithin: (selector: string, fn: () => void) => {
|
||||||
this.helper.when.within(fn, selector);
|
this.helper.when.doWithin(fn, selector);
|
||||||
},
|
},
|
||||||
tab: () => this.helper.get.element("body").tab(),
|
tab: () => this.helper.get.element("body").tab(),
|
||||||
waitForExampleFileResponse: () => {
|
waitForExampleFileResponse: () => {
|
||||||
@@ -108,25 +110,25 @@ export class MaputnikDriver {
|
|||||||
styleProperties: "geojson" | "raster" | "both" | "layer" | "",
|
styleProperties: "geojson" | "raster" | "both" | "layer" | "",
|
||||||
zoom?: number
|
zoom?: number
|
||||||
) => {
|
) => {
|
||||||
let url = "?debug";
|
const url = new URL(baseUrl);
|
||||||
switch (styleProperties) {
|
switch (styleProperties) {
|
||||||
case "geojson":
|
case "geojson":
|
||||||
url += `&style=${baseUrl}geojson-style.json`;
|
url.searchParams.set("style", baseUrl + "geojson-style.json");
|
||||||
break;
|
break;
|
||||||
case "raster":
|
case "raster":
|
||||||
url += `&style=${baseUrl}raster-style.json`;
|
url.searchParams.set("style", baseUrl + "raster-style.json");
|
||||||
break;
|
break;
|
||||||
case "both":
|
case "both":
|
||||||
url += `&style=${baseUrl}geojson-raster-style.json`;
|
url.searchParams.set("style", baseUrl + "geojson-raster-style.json");
|
||||||
break;
|
break;
|
||||||
case "layer":
|
case "layer":
|
||||||
url += `&style=${baseUrl}/example-layer-style.json`;
|
url.searchParams.set("style", baseUrl + "example-layer-style.json");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (zoom) {
|
if (zoom) {
|
||||||
url += `#${zoom}/41.3805/2.1635`;
|
url.hash = `${zoom}/41.3805/2.1635`;
|
||||||
}
|
}
|
||||||
this.helper.when.visit(baseUrl + url);
|
this.helper.when.visit(url.toString());
|
||||||
if (styleProperties) {
|
if (styleProperties) {
|
||||||
this.helper.when.acceptConfirm();
|
this.helper.when.acceptConfirm();
|
||||||
}
|
}
|
||||||
@@ -143,7 +145,7 @@ export class MaputnikDriver {
|
|||||||
},
|
},
|
||||||
|
|
||||||
selectWithin: (selector: string, value: string) => {
|
selectWithin: (selector: string, value: string) => {
|
||||||
this.when.within(selector, () => {
|
this.when.doWithin(selector, () => {
|
||||||
this.helper.get.element("select").select(value);
|
this.helper.get.element("select").select(value);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ export default class ModalDriver {
|
|||||||
this.helper.when.type("add-layer.layer-id.input", id);
|
this.helper.when.type("add-layer.layer-id.input", id);
|
||||||
|
|
||||||
if (layer) {
|
if (layer) {
|
||||||
this.helper.when.within(() => {
|
this.helper.when.doWithin(() => {
|
||||||
this.helper.get.element("input").type(layer!);
|
this.helper.get.element("input").clear().type(layer!);
|
||||||
}, "add-layer.layer-source-block");
|
}, "add-layer.layer-source-block");
|
||||||
}
|
}
|
||||||
this.helper.when.click("add-layer");
|
this.helper.when.click("add-layer");
|
||||||
|
|||||||
@@ -224,6 +224,18 @@ describe("modals", () => {
|
|||||||
).shouldInclude({ "maputnik:stadia_access_token": apiKey });
|
).shouldInclude({ "maputnik:stadia_access_token": apiKey });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("locationiq access token", () => {
|
||||||
|
const apiKey = "testing123";
|
||||||
|
when.setValue(
|
||||||
|
"modal:settings.maputnik:locationiq_access_token",
|
||||||
|
apiKey
|
||||||
|
);
|
||||||
|
when.click("modal:settings.name");
|
||||||
|
then(
|
||||||
|
get.styleFromLocalStorage().then((style) => style.metadata)
|
||||||
|
).shouldInclude({ "maputnik:locationiq_access_token": apiKey });
|
||||||
|
});
|
||||||
|
|
||||||
it("style renderer", () => {
|
it("style renderer", () => {
|
||||||
cy.on("uncaught:exception", () => false); // this is due to the fact that this is an invalid style for openlayers
|
cy.on("uncaught:exception", () => false); // this is due to the fact that this is an invalid style for openlayers
|
||||||
when.select("modal:settings.maputnik:renderer", "ol");
|
when.select("modal:settings.maputnik:renderer", "ol");
|
||||||
@@ -272,7 +284,63 @@ describe("modals", () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("add layer", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
when.setStyle("layer");
|
||||||
|
when.modal.open();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows duplicate id error", () => {
|
||||||
|
when.setValue("add-layer.layer-id.input", "background");
|
||||||
|
when.click("add-layer");
|
||||||
|
then(get.elementByTestId("modal:add-layer")).shouldExist();
|
||||||
|
then(get.element(".maputnik-modal-error")).shouldContainText(
|
||||||
|
"Layer ID already exists"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("sources", () => {
|
describe("sources", () => {
|
||||||
it("toggle");
|
it("toggle");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Handle localStorage QuotaExceededError", () => {
|
||||||
|
it("handles quota exceeded error when opening style from URL", () => {
|
||||||
|
// Clear localStorage to start fresh
|
||||||
|
cy.clearLocalStorage();
|
||||||
|
|
||||||
|
// fill localStorage until we get a QuotaExceededError
|
||||||
|
cy.window().then(win => {
|
||||||
|
let chunkSize = 1000;
|
||||||
|
const chunk = new Array(chunkSize).join("x");
|
||||||
|
let index = 0;
|
||||||
|
|
||||||
|
// Keep adding until we hit the quota
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
const key = `maputnik:fill-${index++}`;
|
||||||
|
win.localStorage.setItem(key, chunk);
|
||||||
|
} catch (e: any) {
|
||||||
|
// Verify it's a quota error
|
||||||
|
if (e.name === 'QuotaExceededError') {
|
||||||
|
if (chunkSize <= 1) return;
|
||||||
|
else {
|
||||||
|
chunkSize /= 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw e; // Unexpected error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Open the style via URL input
|
||||||
|
when.click("nav:open");
|
||||||
|
when.setValue("modal:open.url.input", get.exampleFileUrl());
|
||||||
|
when.click("modal:open.url.button");
|
||||||
|
|
||||||
|
then(get.responseBody("example-style.json")).shouldEqualToStoredStyle();
|
||||||
|
then(get.styleFromLocalStorage()).shouldExist();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,114 @@
|
|||||||
{
|
{
|
||||||
"id": "test-style",
|
"id": "test-style",
|
||||||
"version": 8,
|
"version": 8,
|
||||||
"name": "Test Style",
|
"name": "Test Style",
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"maputnik:renderer": "mlgljs"
|
"maputnik:renderer": "mlgljs",
|
||||||
},
|
"data": [
|
||||||
"sources": {},
|
0,
|
||||||
"glyphs": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
1,
|
||||||
"sprites": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
2,
|
||||||
"layers": []
|
3,
|
||||||
|
4,
|
||||||
|
5,
|
||||||
|
6,
|
||||||
|
7,
|
||||||
|
8,
|
||||||
|
9,
|
||||||
|
10,
|
||||||
|
11,
|
||||||
|
12,
|
||||||
|
13,
|
||||||
|
14,
|
||||||
|
15,
|
||||||
|
16,
|
||||||
|
17,
|
||||||
|
18,
|
||||||
|
19,
|
||||||
|
20,
|
||||||
|
21,
|
||||||
|
22,
|
||||||
|
23,
|
||||||
|
24,
|
||||||
|
25,
|
||||||
|
26,
|
||||||
|
27,
|
||||||
|
28,
|
||||||
|
29,
|
||||||
|
30,
|
||||||
|
31,
|
||||||
|
32,
|
||||||
|
33,
|
||||||
|
34,
|
||||||
|
35,
|
||||||
|
36,
|
||||||
|
37,
|
||||||
|
38,
|
||||||
|
39,
|
||||||
|
40,
|
||||||
|
41,
|
||||||
|
42,
|
||||||
|
43,
|
||||||
|
44,
|
||||||
|
45,
|
||||||
|
46,
|
||||||
|
47,
|
||||||
|
48,
|
||||||
|
49,
|
||||||
|
50,
|
||||||
|
51,
|
||||||
|
52,
|
||||||
|
53,
|
||||||
|
54,
|
||||||
|
55,
|
||||||
|
56,
|
||||||
|
57,
|
||||||
|
58,
|
||||||
|
59,
|
||||||
|
60,
|
||||||
|
61,
|
||||||
|
62,
|
||||||
|
63,
|
||||||
|
64,
|
||||||
|
65,
|
||||||
|
66,
|
||||||
|
67,
|
||||||
|
68,
|
||||||
|
69,
|
||||||
|
70,
|
||||||
|
71,
|
||||||
|
72,
|
||||||
|
73,
|
||||||
|
74,
|
||||||
|
75,
|
||||||
|
76,
|
||||||
|
77,
|
||||||
|
78,
|
||||||
|
79,
|
||||||
|
80,
|
||||||
|
81,
|
||||||
|
82,
|
||||||
|
83,
|
||||||
|
84,
|
||||||
|
85,
|
||||||
|
86,
|
||||||
|
87,
|
||||||
|
88,
|
||||||
|
89,
|
||||||
|
90,
|
||||||
|
91,
|
||||||
|
92,
|
||||||
|
93,
|
||||||
|
94,
|
||||||
|
95,
|
||||||
|
96,
|
||||||
|
97,
|
||||||
|
98,
|
||||||
|
99
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"sources": {},
|
||||||
|
"glyphs": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
|
"sprites": "https://example.local/fonts/{fontstack}/{range}.pbf",
|
||||||
|
"layers": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
|
<title>Components App</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div data-cy-root></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// ***********************************************************
|
||||||
|
// This example support/component.ts is processed and
|
||||||
|
// loaded automatically before your test files.
|
||||||
|
//
|
||||||
|
// This is a great place to put global configuration and
|
||||||
|
// behavior that modifies Cypress.
|
||||||
|
//
|
||||||
|
// You can change the location of this file or turn off
|
||||||
|
// automatically serving support files with the
|
||||||
|
// 'supportFile' configuration option.
|
||||||
|
//
|
||||||
|
// You can read more here:
|
||||||
|
// https://on.cypress.io/configuration
|
||||||
|
// ***********************************************************
|
||||||
|
|
||||||
|
// Import commands.js using ES2015 syntax:
|
||||||
|
import './commands'
|
||||||
|
|
||||||
|
import { mount } from 'cypress/react'
|
||||||
|
|
||||||
|
// Augment the Cypress namespace to include type definitions for
|
||||||
|
// your custom command.
|
||||||
|
// Alternatively, can be defined in cypress/support/component.d.ts
|
||||||
|
// with a <reference path="./component" /> at the top of your spec.
|
||||||
|
declare global {
|
||||||
|
/* eslint-disable @typescript-eslint/no-namespace */
|
||||||
|
namespace Cypress {
|
||||||
|
interface Chainable {
|
||||||
|
mount: typeof mount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Cypress.Commands.add('mount', mount)
|
||||||
|
|
||||||
|
// Example use:
|
||||||
|
// cy.mount(<MyComponent />)
|
||||||
+5
-2
@@ -2,8 +2,7 @@ SOURCEDIR=.
|
|||||||
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')
|
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')
|
||||||
BINARY=maputnik
|
BINARY=maputnik
|
||||||
VERSION := $(shell node -p "require('../package.json').version")
|
VERSION := $(shell node -p "require('../package.json').version")
|
||||||
GOPATH := $(if $(GOPATH),$(GOPATH),$(HOME)/go)
|
GOBIN := $(or $(shell if [ -d /go/bin ]; then echo "/go/bin"; fi),$(HOME)/go/bin)
|
||||||
GOBIN := $(if $(GOBIN),$(GOBIN),$(HOME)/go/bin)
|
|
||||||
|
|
||||||
all: $(BINARY)
|
all: $(BINARY)
|
||||||
|
|
||||||
@@ -11,6 +10,10 @@ $(BINARY): $(GOBIN)/gox $(GOBIN)/go-winres $(SOURCES) version.go rice-box.go win
|
|||||||
$(GOBIN)/go-winres make --product-version=$(VERSION)
|
$(GOBIN)/go-winres make --product-version=$(VERSION)
|
||||||
$(GOBIN)/gox -osarch "windows/amd64 linux/amd64 darwin/amd64" -output "bin/{{.OS}}/${BINARY}"
|
$(GOBIN)/gox -osarch "windows/amd64 linux/amd64 darwin/amd64" -output "bin/{{.OS}}/${BINARY}"
|
||||||
|
|
||||||
|
bin/linux/$(BINARY): $(GOBIN)/gox $(GOBIN)/go-winres $(SOURCES) version.go rice-box.go winres/winres.json
|
||||||
|
$(GOBIN)/go-winres make --product-version=$(VERSION)
|
||||||
|
$(GOBIN)/gox -osarch "linux/amd64" -output "bin/{{.OS}}/${BINARY}"
|
||||||
|
|
||||||
winres/winres.json: winres/winres_template.json
|
winres/winres.json: winres/winres_template.json
|
||||||
sed 's/{{.Version}}/$(VERSION)/g' winres/winres_template.json > $@
|
sed 's/{{.Version}}/$(VERSION)/g' winres/winres_template.json > $@
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -5,8 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"github.com/GeertJohan/go.rice"
|
||||||
"github.com/GeertJohan/go.rice"
|
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/maputnik/desktop/filewatch"
|
"github.com/maputnik/desktop/filewatch"
|
||||||
|
|||||||
Generated
+691
-900
File diff suppressed because it is too large
Load Diff
+29
-28
@@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "maputnik",
|
"name": "maputnik",
|
||||||
"version": "2.1.1",
|
"version": "3.0.0",
|
||||||
"description": "A MapLibre GL visual style editor",
|
"description": "A MapLibre GL visual style editor",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "''",
|
"main": "''",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "vite",
|
"start": "vite",
|
||||||
"build": "tsc && vite build --base=/maputnik/",
|
"build": "tsc && vite build --mode=production",
|
||||||
"build-desktop": "tsc && vite build --base=/ && cd desktop && make",
|
"build-desktop": "tsc && vite build --mode=desktop && cd desktop && make",
|
||||||
|
"build-linux": "tsc && vite build --mode=desktop && cd desktop && make bin/linux/maputnik",
|
||||||
"i18n:refresh": "i18next 'src/**/*.{ts,tsx,js,jsx}'",
|
"i18n:refresh": "i18next 'src/**/*.{ts,tsx,js,jsx}'",
|
||||||
"lint": "eslint",
|
"lint": "eslint",
|
||||||
"test": "cypress run",
|
"test": "cypress run",
|
||||||
@@ -23,22 +24,26 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://github.com/maplibre/maputnik#readme",
|
"homepage": "https://github.com/maplibre/maputnik#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@dnd-kit/core": "^6.3.1",
|
||||||
|
"@dnd-kit/sortable": "^10.0.0",
|
||||||
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
"@mapbox/mapbox-gl-rtl-text": "^0.3.0",
|
"@mapbox/mapbox-gl-rtl-text": "^0.3.0",
|
||||||
"@maplibre/maplibre-gl-geocoder": "^1.9.0",
|
"@maplibre/maplibre-gl-geocoder": "^1.9.0",
|
||||||
"@maplibre/maplibre-gl-inspect": "^1.7.1",
|
"@maplibre/maplibre-gl-inspect": "^1.7.1",
|
||||||
"@maplibre/maplibre-gl-style-spec": "^23.2.3",
|
"@maplibre/maplibre-gl-style-spec": "^23.3.0",
|
||||||
"@mdi/js": "^7.4.47",
|
"@mdi/js": "^7.4.47",
|
||||||
"@mdi/react": "^1.6.1",
|
"@mdi/react": "^1.6.1",
|
||||||
"@prantlf/jsonlint": "^16.0.0",
|
"@prantlf/jsonlint": "^16.0.0",
|
||||||
"array-move": "^4.0.0",
|
"array-move": "^4.0.0",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"classnames": "^2.5.1",
|
"classnames": "^2.5.1",
|
||||||
"codemirror": "^5.65.19",
|
"codemirror": "^5.65.20",
|
||||||
"color": "^5.0.0",
|
"color": "^5.0.0",
|
||||||
"detect-browser": "^5.3.0",
|
"detect-browser": "^5.3.0",
|
||||||
|
"downshift": "^9.0.10",
|
||||||
"events": "^3.3.0",
|
"events": "^3.3.0",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"i18next": "^25.2.1",
|
"i18next": "^25.5.2",
|
||||||
"i18next-browser-languagedetector": "^8.2.0",
|
"i18next-browser-languagedetector": "^8.2.0",
|
||||||
"i18next-resources-to-backend": "^1.2.1",
|
"i18next-resources-to-backend": "^1.2.1",
|
||||||
"json-stringify-pretty-compact": "^4.0.0",
|
"json-stringify-pretty-compact": "^4.0.0",
|
||||||
@@ -50,26 +55,23 @@
|
|||||||
"lodash.get": "^4.4.2",
|
"lodash.get": "^4.4.2",
|
||||||
"lodash.isequal": "^4.5.0",
|
"lodash.isequal": "^4.5.0",
|
||||||
"lodash.throttle": "^4.1.1",
|
"lodash.throttle": "^4.1.1",
|
||||||
"maplibre-gl": "^5.5.0",
|
"maplibre-gl": "^5.7.1",
|
||||||
"maputnik-design": "github:maputnik/design#172b06c",
|
"maputnik-design": "github:maputnik/design#172b06c",
|
||||||
"ol": "^10.5.0",
|
"ol": "^10.6.1",
|
||||||
"ol-mapbox-style": "^13.0.1",
|
"ol-mapbox-style": "^13.1.0",
|
||||||
"pmtiles": "^4.3.0",
|
"pmtiles": "^4.3.0",
|
||||||
"prop-types": "^15.8.1",
|
"prop-types": "^15.8.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-accessible-accordion": "^5.0.1",
|
"react-accessible-accordion": "^5.0.1",
|
||||||
"react-aria-menubutton": "^7.0.3",
|
"react-aria-menubutton": "^7.0.3",
|
||||||
"react-aria-modal": "^5.0.2",
|
"react-aria-modal": "^5.0.2",
|
||||||
"react-autobind": "^1.0.6",
|
|
||||||
"react-autocomplete": "^1.8.1",
|
|
||||||
"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-file-reader-input": "^2.0.0",
|
"react-file-reader-input": "^2.0.0",
|
||||||
"react-i18next": "^15.5.3",
|
"react-i18next": "^15.7.3",
|
||||||
"react-icon-base": "^2.1.2",
|
"react-icon-base": "^2.1.2",
|
||||||
"react-icons": "^5.5.0",
|
"react-icons": "^5.5.0",
|
||||||
"react-sortable-hoc": "^2.0.0",
|
|
||||||
"reconnecting-websocket": "^4.4.0",
|
"reconnecting-websocket": "^4.4.0",
|
||||||
"slugify": "^1.6.6",
|
"slugify": "^1.6.6",
|
||||||
"string-hash": "^1.1.3",
|
"string-hash": "^1.1.3",
|
||||||
@@ -93,12 +95,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cypress/code-coverage": "^3.14.4",
|
"@cypress/code-coverage": "^3.14.6",
|
||||||
"@eslint/js": "^9.29.0",
|
"@eslint/js": "^9.35.0",
|
||||||
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
||||||
"@rollup/plugin-replace": "^6.0.2",
|
"@rollup/plugin-replace": "^6.0.2",
|
||||||
"@shellygo/cypress-test-utils": "^5.0.0",
|
"@shellygo/cypress-test-utils": "^6.0.1",
|
||||||
"@types/codemirror": "^5.60.15",
|
"@types/codemirror": "^5.60.16",
|
||||||
"@types/color": "^4.2.0",
|
"@types/color": "^4.2.0",
|
||||||
"@types/cors": "^2.8.19",
|
"@types/cors": "^2.8.19",
|
||||||
"@types/file-saver": "^2.0.7",
|
"@types/file-saver": "^2.0.7",
|
||||||
@@ -114,7 +116,6 @@
|
|||||||
"@types/react": "^18.2.67",
|
"@types/react": "^18.2.67",
|
||||||
"@types/react-aria-menubutton": "^6.2.14",
|
"@types/react-aria-menubutton": "^6.2.14",
|
||||||
"@types/react-aria-modal": "^5.0.0",
|
"@types/react-aria-modal": "^5.0.0",
|
||||||
"@types/react-autocomplete": "^1.8.11",
|
|
||||||
"@types/react-collapse": "^5.0.4",
|
"@types/react-collapse": "^5.0.4",
|
||||||
"@types/react-color": "^3.0.13",
|
"@types/react-color": "^3.0.13",
|
||||||
"@types/react-dom": "^18.2.22",
|
"@types/react-dom": "^18.2.22",
|
||||||
@@ -123,11 +124,11 @@
|
|||||||
"@types/string-hash": "^1.1.3",
|
"@types/string-hash": "^1.1.3",
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
"@types/wicg-file-system-access": "^2023.10.6",
|
"@types/wicg-file-system-access": "^2023.10.6",
|
||||||
"@vitejs/plugin-react": "^4.5.2",
|
"@vitejs/plugin-react": "^5.0.2",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"cypress": "^14.4.1",
|
"cypress": "^15.1.0",
|
||||||
"cypress-plugin-tab": "^1.0.5",
|
"cypress-plugin-tab": "^1.0.5",
|
||||||
"eslint": "^9.29.0",
|
"eslint": "^9.35.0",
|
||||||
"eslint-plugin-react": "^7.37.5",
|
"eslint-plugin-react": "^7.37.5",
|
||||||
"eslint-plugin-react-hooks": "^5.2.0",
|
"eslint-plugin-react-hooks": "^5.2.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.20",
|
"eslint-plugin-react-refresh": "^0.4.20",
|
||||||
@@ -136,14 +137,14 @@
|
|||||||
"istanbul-lib-coverage": "^3.2.2",
|
"istanbul-lib-coverage": "^3.2.2",
|
||||||
"postcss": "^8.5.6",
|
"postcss": "^8.5.6",
|
||||||
"react-hot-loader": "^4.13.1",
|
"react-hot-loader": "^4.13.1",
|
||||||
"sass": "^1.89.2",
|
"sass": "^1.92.1",
|
||||||
"stylelint": "^16.20.0",
|
"stylelint": "^16.24.0",
|
||||||
"stylelint-config-recommended-scss": "^15.0.1",
|
"stylelint-config-recommended-scss": "^16.0.0",
|
||||||
"stylelint-scss": "^6.12.1",
|
"stylelint-scss": "^6.12.1",
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.8.3",
|
||||||
"typescript-eslint": "^8.34.0",
|
"typescript-eslint": "^8.43.0",
|
||||||
"uuid": "^11.1.0",
|
"uuid": "^13.0.0",
|
||||||
"vite": "^6.3.5",
|
"vite": "^7.1.5",
|
||||||
"vite-plugin-istanbul": "^7.0.0"
|
"vite-plugin-istanbul": "^7.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+92
-149
@@ -1,5 +1,3 @@
|
|||||||
// @ts-ignore - this can be easily replaced with arrow functions
|
|
||||||
import autoBind from 'react-autobind';
|
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import cloneDeep from 'lodash.clonedeep'
|
import cloneDeep from 'lodash.clonedeep'
|
||||||
import clamp from 'lodash.clamp'
|
import clamp from 'lodash.clamp'
|
||||||
@@ -29,17 +27,14 @@ import ModalDebug from './ModalDebug'
|
|||||||
|
|
||||||
import {downloadGlyphsMetadata, downloadSpriteMetadata} from '../libs/metadata'
|
import {downloadGlyphsMetadata, downloadSpriteMetadata} from '../libs/metadata'
|
||||||
import style from '../libs/style'
|
import style from '../libs/style'
|
||||||
import { initialStyleUrl, loadStyleUrl, removeStyleQuerystring } from '../libs/urlopen'
|
|
||||||
import { undoMessages, redoMessages } from '../libs/diffmessage'
|
import { undoMessages, redoMessages } from '../libs/diffmessage'
|
||||||
import { StyleStore } from '../libs/stylestore'
|
import { createStyleStore, type IStyleStore } from '../libs/store/style-store-factory'
|
||||||
import { ApiStyleStore } from '../libs/apistore'
|
|
||||||
import { RevisionStore } from '../libs/revisions'
|
import { RevisionStore } from '../libs/revisions'
|
||||||
import LayerWatcher from '../libs/layerwatcher'
|
import LayerWatcher from '../libs/layerwatcher'
|
||||||
import tokens from '../config/tokens.json'
|
import tokens from '../config/tokens.json'
|
||||||
import isEqual from 'lodash.isequal'
|
import isEqual from 'lodash.isequal'
|
||||||
import Debug from '../libs/debug'
|
|
||||||
import { SortEnd } from 'react-sortable-hoc';
|
|
||||||
import { MapOptions } from 'maplibre-gl';
|
import { MapOptions } from 'maplibre-gl';
|
||||||
|
import { OnStyleChangedOpts, StyleSpecificationWithId } from '../libs/definitions'
|
||||||
|
|
||||||
// Buffer must be defined globally for @maplibre/maplibre-gl-style-spec validate() function to succeed.
|
// Buffer must be defined globally for @maplibre/maplibre-gl-style-spec validate() function to succeed.
|
||||||
window.Buffer = buffer.Buffer;
|
window.Buffer = buffer.Buffer;
|
||||||
@@ -48,6 +43,7 @@ function setFetchAccessToken(url: string, mapStyle: StyleSpecification) {
|
|||||||
const matchesTilehosting = url.match(/\.tilehosting\.com/);
|
const matchesTilehosting = url.match(/\.tilehosting\.com/);
|
||||||
const matchesMaptiler = url.match(/\.maptiler\.com/);
|
const matchesMaptiler = url.match(/\.maptiler\.com/);
|
||||||
const matchesThunderforest = url.match(/\.thunderforest\.com/);
|
const matchesThunderforest = url.match(/\.thunderforest\.com/);
|
||||||
|
const matchesLocationIQ = url.match(/\.locationiq\.com/);
|
||||||
if (matchesTilehosting || matchesMaptiler) {
|
if (matchesTilehosting || matchesMaptiler) {
|
||||||
const accessToken = style.getAccessToken("openmaptiles", mapStyle, {allowFallback: true})
|
const accessToken = style.getAccessToken("openmaptiles", mapStyle, {allowFallback: true})
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
@@ -60,6 +56,12 @@ function setFetchAccessToken(url: string, mapStyle: StyleSpecification) {
|
|||||||
return url.replace('{key}', accessToken)
|
return url.replace('{key}', accessToken)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (matchesLocationIQ) {
|
||||||
|
const accessToken = style.getAccessToken("locationiq", mapStyle, {allowFallback: true})
|
||||||
|
if (accessToken) {
|
||||||
|
return url.replace('{key}', accessToken)
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@@ -78,12 +80,6 @@ function updateRootSpec(spec: any, fieldName: string, newValues: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type OnStyleChangedOpts = {
|
|
||||||
save?: boolean
|
|
||||||
addRevision?: boolean
|
|
||||||
initialLoad?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
type MappedErrors = {
|
type MappedErrors = {
|
||||||
message: string
|
message: string
|
||||||
parsed?: {
|
parsed?: {
|
||||||
@@ -99,11 +95,11 @@ type MappedErrors = {
|
|||||||
type AppState = {
|
type AppState = {
|
||||||
errors: MappedErrors[],
|
errors: MappedErrors[],
|
||||||
infos: string[],
|
infos: string[],
|
||||||
mapStyle: StyleSpecification & {id: string},
|
mapStyle: StyleSpecificationWithId,
|
||||||
dirtyMapStyle?: StyleSpecification,
|
dirtyMapStyle?: StyleSpecification,
|
||||||
selectedLayerIndex: number,
|
selectedLayerIndex: number,
|
||||||
selectedLayerOriginalId?: string,
|
selectedLayerOriginalId?: string,
|
||||||
sources: {[key: string]: SourceSpecification},
|
sources: {[key: string]: SourceSpecification & {layers: string[]} },
|
||||||
vectorLayers: {},
|
vectorLayers: {},
|
||||||
spec: any,
|
spec: any,
|
||||||
mapView: {
|
mapView: {
|
||||||
@@ -135,26 +131,56 @@ type AppState = {
|
|||||||
|
|
||||||
export default class App extends React.Component<any, AppState> {
|
export default class App extends React.Component<any, AppState> {
|
||||||
revisionStore: RevisionStore;
|
revisionStore: RevisionStore;
|
||||||
styleStore: StyleStore | ApiStyleStore;
|
styleStore: IStyleStore | null = null;
|
||||||
layerWatcher: LayerWatcher;
|
layerWatcher: LayerWatcher;
|
||||||
|
|
||||||
constructor(props: any) {
|
constructor(props: any) {
|
||||||
super(props)
|
super(props)
|
||||||
autoBind(this);
|
|
||||||
|
|
||||||
this.revisionStore = new RevisionStore()
|
this.revisionStore = new RevisionStore();
|
||||||
const params = new URLSearchParams(window.location.search.substring(1))
|
this.configureKeyboardShortcuts();
|
||||||
let port = params.get("localport")
|
|
||||||
if (port == null && (window.location.port !== "80" && window.location.port !== "443")) {
|
this.state = {
|
||||||
port = window.location.port
|
errors: [],
|
||||||
|
infos: [],
|
||||||
|
mapStyle: style.emptyStyle,
|
||||||
|
selectedLayerIndex: 0,
|
||||||
|
sources: {},
|
||||||
|
vectorLayers: {},
|
||||||
|
mapState: "map",
|
||||||
|
spec: latest,
|
||||||
|
mapView: {
|
||||||
|
zoom: 0,
|
||||||
|
center: {
|
||||||
|
lng: 0,
|
||||||
|
lat: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isOpen: {
|
||||||
|
settings: false,
|
||||||
|
sources: false,
|
||||||
|
open: false,
|
||||||
|
shortcuts: false,
|
||||||
|
export: false,
|
||||||
|
debug: false,
|
||||||
|
},
|
||||||
|
maplibreGlDebugOptions: {
|
||||||
|
showTileBoundaries: false,
|
||||||
|
showCollisionBoxes: false,
|
||||||
|
showOverdrawInspector: false,
|
||||||
|
},
|
||||||
|
openlayersDebugOptions: {
|
||||||
|
debugToolbox: false,
|
||||||
|
},
|
||||||
|
fileHandle: null,
|
||||||
}
|
}
|
||||||
this.styleStore = new ApiStyleStore({
|
|
||||||
onLocalStyleChange: mapStyle => this.onStyleChanged(mapStyle, {save: false}),
|
this.layerWatcher = new LayerWatcher({
|
||||||
port: port,
|
onVectorLayersChange: v => this.setState({ vectorLayers: v })
|
||||||
host: params.get("localhost")
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
configureKeyboardShortcuts = () => {
|
||||||
const shortcuts = [
|
const shortcuts = [
|
||||||
{
|
{
|
||||||
key: "?",
|
key: "?",
|
||||||
@@ -224,74 +250,6 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const styleUrl = initialStyleUrl()
|
|
||||||
if(styleUrl && window.confirm("Load style from URL: " + styleUrl + " and discard current changes?")) {
|
|
||||||
this.styleStore = new StyleStore()
|
|
||||||
loadStyleUrl(styleUrl, mapStyle => this.onStyleChanged(mapStyle))
|
|
||||||
removeStyleQuerystring()
|
|
||||||
} else {
|
|
||||||
if(styleUrl) {
|
|
||||||
removeStyleQuerystring()
|
|
||||||
}
|
|
||||||
this.styleStore.init(err => {
|
|
||||||
if(err) {
|
|
||||||
console.log('Falling back to local storage for storing styles')
|
|
||||||
this.styleStore = new StyleStore()
|
|
||||||
}
|
|
||||||
this.styleStore.latestStyle(mapStyle => this.onStyleChanged(mapStyle, {initialLoad: true}))
|
|
||||||
|
|
||||||
if(Debug.enabled()) {
|
|
||||||
Debug.set("maputnik", "styleStore", this.styleStore);
|
|
||||||
Debug.set("maputnik", "revisionStore", this.revisionStore);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Debug.enabled()) {
|
|
||||||
Debug.set("maputnik", "revisionStore", this.revisionStore);
|
|
||||||
Debug.set("maputnik", "styleStore", this.styleStore);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.state = {
|
|
||||||
errors: [],
|
|
||||||
infos: [],
|
|
||||||
mapStyle: style.emptyStyle,
|
|
||||||
selectedLayerIndex: 0,
|
|
||||||
sources: {},
|
|
||||||
vectorLayers: {},
|
|
||||||
mapState: "map",
|
|
||||||
spec: latest,
|
|
||||||
mapView: {
|
|
||||||
zoom: 0,
|
|
||||||
center: {
|
|
||||||
lng: 0,
|
|
||||||
lat: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
isOpen: {
|
|
||||||
settings: false,
|
|
||||||
sources: false,
|
|
||||||
open: false,
|
|
||||||
shortcuts: false,
|
|
||||||
export: false,
|
|
||||||
// TODO: Disabled for now, this should be opened on the Nth visit to the editor
|
|
||||||
debug: false,
|
|
||||||
},
|
|
||||||
maplibreGlDebugOptions: {
|
|
||||||
showTileBoundaries: false,
|
|
||||||
showCollisionBoxes: false,
|
|
||||||
showOverdrawInspector: false,
|
|
||||||
},
|
|
||||||
openlayersDebugOptions: {
|
|
||||||
debugToolbox: false,
|
|
||||||
},
|
|
||||||
fileHandle: null,
|
|
||||||
}
|
|
||||||
|
|
||||||
this.layerWatcher = new LayerWatcher({
|
|
||||||
onVectorLayersChange: v => this.setState({ vectorLayers: v })
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeyPress = (e: KeyboardEvent) => {
|
handleKeyPress = (e: KeyboardEvent) => {
|
||||||
@@ -317,7 +275,8 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
async componentDidMount() {
|
||||||
|
this.styleStore = await createStyleStore((mapStyle, opts) => this.onStyleChanged(mapStyle, opts));
|
||||||
window.addEventListener("keydown", this.handleKeyPress);
|
window.addEventListener("keydown", this.handleKeyPress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,8 +284,8 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
window.removeEventListener("keydown", this.handleKeyPress);
|
window.removeEventListener("keydown", this.handleKeyPress);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveStyle(snapshotStyle: StyleSpecification & {id: string}) {
|
saveStyle(snapshotStyle: StyleSpecificationWithId) {
|
||||||
this.styleStore.save(snapshotStyle)
|
this.styleStore?.save(snapshotStyle)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFonts(urlTemplate: string) {
|
updateFonts(urlTemplate: string) {
|
||||||
@@ -367,7 +326,7 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
this.onStyleChanged(changedStyle)
|
this.onStyleChanged(changedStyle)
|
||||||
}
|
}
|
||||||
|
|
||||||
onStyleChanged = (newStyle: StyleSpecification & {id: string}, opts: OnStyleChangedOpts={}) => {
|
onStyleChanged = (newStyle: StyleSpecificationWithId, opts: OnStyleChangedOpts={}): void => {
|
||||||
opts = {
|
opts = {
|
||||||
save: true,
|
save: true,
|
||||||
addRevision: true,
|
addRevision: true,
|
||||||
@@ -398,7 +357,6 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const errors: ValidationError[] = validateStyleMin(newStyle) || [];
|
const errors: ValidationError[] = validateStyleMin(newStyle) || [];
|
||||||
|
|
||||||
// The validate function doesn't give us errors for duplicate error with
|
// The validate function doesn't give us errors for duplicate error with
|
||||||
// empty string for layer.id, manually deal with that here.
|
// empty string for layer.id, manually deal with that here.
|
||||||
const layerErrors: (Error | ValidationError)[] = [];
|
const layerErrors: (Error | ValidationError)[] = [];
|
||||||
@@ -477,7 +435,7 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
dirtyMapStyle = cloneDeep(newStyle);
|
dirtyMapStyle = cloneDeep(newStyle);
|
||||||
|
|
||||||
errors.forEach(error => {
|
for (const error of errors) {
|
||||||
const {message} = error;
|
const {message} = error;
|
||||||
if (message) {
|
if (message) {
|
||||||
try {
|
try {
|
||||||
@@ -487,10 +445,10 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
unset(dirtyMapStyle, unsetPath);
|
unset(dirtyMapStyle, unsetPath);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.warn(err);
|
console.warn(message + " " + err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newStyle.glyphs !== this.state.mapStyle.glyphs) {
|
if(newStyle.glyphs !== this.state.mapStyle.glyphs) {
|
||||||
@@ -504,7 +462,7 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
this.revisionStore.addRevision(newStyle);
|
this.revisionStore.addRevision(newStyle);
|
||||||
}
|
}
|
||||||
if (opts.save) {
|
if (opts.save) {
|
||||||
this.saveStyle(newStyle as StyleSpecification & {id: string});
|
this.saveStyle(newStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -537,7 +495,7 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onMoveLayer = (move: SortEnd) => {
|
onMoveLayer = (move: {oldIndex: number; newIndex: number}) => {
|
||||||
let { oldIndex, newIndex } = move;
|
let { oldIndex, newIndex } = move;
|
||||||
let layers = this.state.mapStyle.layers;
|
let layers = this.state.mapStyle.layers;
|
||||||
oldIndex = clamp(oldIndex, 0, layers.length-1);
|
oldIndex = clamp(oldIndex, 0, layers.length-1);
|
||||||
@@ -617,7 +575,7 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
}, this.setStateInUrl);
|
}, this.setStateInUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultValues = (styleObj: StyleSpecification & {id: string}) => {
|
setDefaultValues = (styleObj: StyleSpecificationWithId) => {
|
||||||
const metadata: {[key: string]: string} = styleObj.metadata || {} as any
|
const metadata: {[key: string]: string} = styleObj.metadata || {} as any
|
||||||
if(metadata['maputnik:renderer'] === undefined) {
|
if(metadata['maputnik:renderer'] === undefined) {
|
||||||
const changedStyle = {
|
const changedStyle = {
|
||||||
@@ -633,27 +591,28 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openStyle = (styleObj: StyleSpecification & {id: string}, fileHandle: FileSystemFileHandle | null) => {
|
openStyle = (styleObj: StyleSpecificationWithId, fileHandle: FileSystemFileHandle | null) => {
|
||||||
this.setState({fileHandle: fileHandle});
|
this.setState({fileHandle: fileHandle});
|
||||||
styleObj = this.setDefaultValues(styleObj)
|
styleObj = this.setDefaultValues(styleObj)
|
||||||
this.onStyleChanged(styleObj)
|
this.onStyleChanged(styleObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchSources() {
|
async fetchSources() {
|
||||||
const sourceList: {[key: string]: any} = {};
|
const sourceList: {[key: string]: SourceSpecification & {layers: string[]}} = {};
|
||||||
|
for(const key of Object.keys(this.state.mapStyle.sources)) {
|
||||||
for(const [key, val] of Object.entries(this.state.mapStyle.sources)) {
|
const source = this.state.mapStyle.sources[key];
|
||||||
if(
|
if(source.type !== "vector" || !('url' in source)) {
|
||||||
!Object.prototype.hasOwnProperty.call(this.state.sources, key) &&
|
sourceList[key] = this.state.sources[key] || {...this.state.mapStyle.sources[key]};
|
||||||
val.type === "vector" &&
|
if (sourceList[key].layers === undefined) {
|
||||||
Object.prototype.hasOwnProperty.call(val, "url")
|
sourceList[key].layers = [];
|
||||||
) {
|
}
|
||||||
|
} else {
|
||||||
sourceList[key] = {
|
sourceList[key] = {
|
||||||
type: val.type,
|
type: source.type,
|
||||||
layers: []
|
layers: []
|
||||||
};
|
};
|
||||||
|
|
||||||
let url = val.url;
|
let url = source.url;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
url = setFetchAccessToken(url!, this.state.mapStyle)
|
url = setFetchAccessToken(url!, this.state.mapStyle)
|
||||||
@@ -666,44 +625,28 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new objects before setState
|
|
||||||
const sources = Object.assign({}, {
|
|
||||||
[key]: this.state.sources[key],
|
|
||||||
});
|
|
||||||
|
|
||||||
for(const layer of json.vector_layers) {
|
for(const layer of json.vector_layers) {
|
||||||
(sources[key] as any).layers.push(layer.id)
|
sourceList[key].layers.push(layer.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
|
||||||
sources: sources
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (url!.startsWith("pmtiles://")) {
|
try {
|
||||||
(new PMTiles(url!.substr(10))).getTileJson("")
|
if (url!.startsWith("pmtiles://")) {
|
||||||
.then(json => setVectorLayers(json))
|
const json = await (new PMTiles(url!.substring(10))).getTileJson("");
|
||||||
.catch(err => {
|
setVectorLayers(json);
|
||||||
console.error("Failed to process sources for '%s'", url, err);
|
} else {
|
||||||
});
|
const response = await fetch(url!, { mode: 'cors' });
|
||||||
} else {
|
const json = await response.json();
|
||||||
fetch(url!, {
|
setVectorLayers(json);
|
||||||
mode: 'cors',
|
}
|
||||||
})
|
} catch(err) {
|
||||||
.then(response => response.json())
|
console.error(`Failed to process source for url: '${url}', ${err}`);
|
||||||
.then(json => setVectorLayers(json))
|
|
||||||
.catch(err => {
|
|
||||||
console.error("Failed to process sources for '%s'", url, err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
sourceList[key] = this.state.sources[key] || this.state.mapStyle.sources[key];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isEqual(this.state.sources, sourceList)) {
|
if(!isEqual(this.state.sources, sourceList)) {
|
||||||
console.debug("Setting sources");
|
console.debug("Setting sources", sourceList);
|
||||||
this.setState({
|
this.setState({
|
||||||
sources: sourceList
|
sources: sourceList
|
||||||
})
|
})
|
||||||
@@ -880,8 +823,8 @@ export default class App extends React.Component<any, AppState> {
|
|||||||
this.setModal(modalName, !this.state.isOpen[modalName]);
|
this.setModal(modalName, !this.state.isOpen[modalName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
onSetFileHandle(fileHandle: FileSystemFileHandle | null) {
|
onSetFileHandle = (fileHandle: FileSystemFileHandle | null) => {
|
||||||
this.setState({fileHandle: fileHandle});
|
this.setState({ fileHandle });
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeOpenlayersDebug = (key: keyof AppState["openlayersDebugOptions"], value: boolean) => {
|
onChangeOpenlayersDebug = (key: keyof AppState["openlayersDebugOptions"], value: boolean) => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import ScrollContainer from './ScrollContainer'
|
import ScrollContainer from './ScrollContainer'
|
||||||
import { WithTranslation, withTranslation } from 'react-i18next';
|
import { WithTranslation, withTranslation } from 'react-i18next';
|
||||||
|
import { IconContext } from 'react-icons';
|
||||||
|
|
||||||
type AppLayoutInternalProps = {
|
type AppLayoutInternalProps = {
|
||||||
toolbar: React.ReactElement
|
toolbar: React.ReactElement
|
||||||
@@ -13,38 +13,31 @@ type AppLayoutInternalProps = {
|
|||||||
} & WithTranslation;
|
} & WithTranslation;
|
||||||
|
|
||||||
class AppLayoutInternal extends React.Component<AppLayoutInternalProps> {
|
class AppLayoutInternal extends React.Component<AppLayoutInternalProps> {
|
||||||
static childContextTypes = {
|
|
||||||
reactIconBase: PropTypes.object
|
|
||||||
}
|
|
||||||
|
|
||||||
getChildContext() {
|
|
||||||
return {
|
|
||||||
reactIconBase: { size: 14 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
document.body.dir = this.props.i18n.dir();
|
document.body.dir = this.props.i18n.dir();
|
||||||
|
|
||||||
return <div className="maputnik-layout">
|
return <IconContext.Provider value={{size: '14px'}}>
|
||||||
{this.props.toolbar}
|
<div className="maputnik-layout">
|
||||||
<div className="maputnik-layout-main">
|
{this.props.toolbar}
|
||||||
<div className="maputnik-layout-list">
|
<div className="maputnik-layout-main">
|
||||||
{this.props.layerList}
|
<div className="maputnik-layout-list">
|
||||||
|
{this.props.layerList}
|
||||||
|
</div>
|
||||||
|
<div className="maputnik-layout-drawer">
|
||||||
|
<ScrollContainer>
|
||||||
|
{this.props.layerEditor}
|
||||||
|
</ScrollContainer>
|
||||||
|
</div>
|
||||||
|
{this.props.map}
|
||||||
</div>
|
</div>
|
||||||
<div className="maputnik-layout-drawer">
|
{this.props.bottom && <div className="maputnik-layout-bottom">
|
||||||
<ScrollContainer>
|
{this.props.bottom}
|
||||||
{this.props.layerEditor}
|
|
||||||
</ScrollContainer>
|
|
||||||
</div>
|
</div>
|
||||||
{this.props.map}
|
}
|
||||||
|
{this.props.modals}
|
||||||
</div>
|
</div>
|
||||||
{this.props.bottom && <div className="maputnik-layout-bottom">
|
</IconContext.Provider>
|
||||||
{this.props.bottom}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
{this.props.modals}
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import pkgJson from '../../package.json'
|
|||||||
import maputnikLogo from 'maputnik-design/logos/logo-color.svg?inline'
|
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 type { OnStyleChangedCallback } from '../libs/definitions';
|
||||||
|
|
||||||
// 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();
|
||||||
@@ -93,9 +94,9 @@ export type MapState = "map" | "inspect" | "filter-achromatopsia" | "filter-deut
|
|||||||
type AppToolbarInternalProps = {
|
type AppToolbarInternalProps = {
|
||||||
mapStyle: object
|
mapStyle: object
|
||||||
inspectModeEnabled: boolean
|
inspectModeEnabled: boolean
|
||||||
onStyleChanged(...args: unknown[]): unknown
|
onStyleChanged: OnStyleChangedCallback
|
||||||
// A new style has been uploaded
|
// A new style has been uploaded
|
||||||
onStyleOpen(...args: unknown[]): unknown
|
onStyleOpen: OnStyleChangedCallback
|
||||||
// A dict of source id's and the available source layers
|
// A dict of source id's and the available source layers
|
||||||
sources: object
|
sources: object
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import InputArray, { FieldArrayProps as InputArrayProps } from './InputArray'
|
import InputArray, { FieldArrayProps as InputArrayProps } from './InputArray'
|
||||||
import Fieldset from './Fieldset'
|
import Fieldset from './Fieldset'
|
||||||
|
|
||||||
@@ -9,10 +8,12 @@ type FieldArrayProps = InputArrayProps & {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class FieldArray extends React.Component<FieldArrayProps> {
|
const FieldArray: React.FC<FieldArrayProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Fieldset label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
<Fieldset label={props.label} fieldSpec={props.fieldSpec}>
|
||||||
<InputArray {...this.props} />
|
<InputArray {...props} />
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldArray;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import Block from './Block'
|
import Block from './Block'
|
||||||
import InputAutocomplete, { InputAutocompleteProps } from './InputAutocomplete'
|
import InputAutocomplete, { InputAutocompleteProps } from './InputAutocomplete'
|
||||||
|
|
||||||
@@ -8,10 +7,12 @@ type FieldAutocompleteProps = InputAutocompleteProps & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default class FieldAutocomplete extends React.Component<FieldAutocompleteProps> {
|
const FieldAutocomplete: React.FC<FieldAutocompleteProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Block label={this.props.label}>
|
<Block label={props.label}>
|
||||||
<InputAutocomplete {...this.props} />
|
<InputAutocomplete {...props} />
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldAutocomplete;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import Block from './Block'
|
import Block from './Block'
|
||||||
import InputCheckbox, {InputCheckboxProps} from './InputCheckbox'
|
import InputCheckbox, {InputCheckboxProps} from './InputCheckbox'
|
||||||
|
|
||||||
@@ -8,10 +7,12 @@ type FieldCheckboxProps = InputCheckboxProps & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default class FieldCheckbox extends React.Component<FieldCheckboxProps> {
|
const FieldCheckbox: React.FC<FieldCheckboxProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Block label={this.props.label}>
|
<Block label={props.label}>
|
||||||
<InputCheckbox {...this.props} />
|
<InputCheckbox {...props} />
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldCheckbox;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import Block from './Block'
|
import Block from './Block'
|
||||||
import InputColor, {InputColorProps} from './InputColor'
|
import InputColor, {InputColorProps} from './InputColor'
|
||||||
|
|
||||||
@@ -11,10 +10,12 @@ type FieldColorProps = InputColorProps & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default class FieldColor extends React.Component<FieldColorProps> {
|
const FieldColor: React.FC<FieldColorProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Block label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
<Block label={props.label} fieldSpec={props.fieldSpec}>
|
||||||
<InputColor {...this.props} />
|
<InputColor {...props} />
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldColor;
|
||||||
|
|||||||
@@ -10,29 +10,31 @@ type FieldCommentInternalProps = {
|
|||||||
error: {message: string}
|
error: {message: string}
|
||||||
} & WithTranslation;
|
} & WithTranslation;
|
||||||
|
|
||||||
class FieldCommentInternal extends React.Component<FieldCommentInternalProps> {
|
const FieldCommentInternal: React.FC<FieldCommentInternalProps> = (props) => {
|
||||||
render() {
|
const t = props.t;
|
||||||
const t = this.props.t;
|
const fieldSpec = {
|
||||||
const fieldSpec = {
|
doc: t(
|
||||||
doc: t("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."
|
||||||
};
|
),
|
||||||
|
};
|
||||||
|
|
||||||
return <Block
|
return (
|
||||||
|
<Block
|
||||||
label={t("Comments")}
|
label={t("Comments")}
|
||||||
fieldSpec={fieldSpec}
|
fieldSpec={fieldSpec}
|
||||||
data-wd-key="layer-comment"
|
data-wd-key="layer-comment"
|
||||||
error={this.props.error}
|
error={props.error}
|
||||||
>
|
>
|
||||||
<InputString
|
<InputString
|
||||||
multi={true}
|
multi={true}
|
||||||
value={this.props.value}
|
value={props.value}
|
||||||
onChange={this.props.onChange}
|
onChange={props.onChange}
|
||||||
default={t("Comment...")}
|
default={t("Comment...")}
|
||||||
data-wd-key="layer-comment.input"
|
data-wd-key="layer-comment.input"
|
||||||
/>
|
/>
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
const FieldComment = withTranslation()(FieldCommentInternal);
|
const FieldComment = withTranslation()(FieldCommentInternal);
|
||||||
export default FieldComment;
|
export default FieldComment;
|
||||||
|
|||||||
@@ -9,57 +9,45 @@ type FieldDocLabelProps = {
|
|||||||
onToggleDoc?(...args: unknown[]): unknown
|
onToggleDoc?(...args: unknown[]): unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
type FieldDocLabelState = {
|
|
||||||
open: boolean
|
|
||||||
};
|
|
||||||
|
|
||||||
export default class FieldDocLabel extends React.Component<FieldDocLabelProps, FieldDocLabelState> {
|
const FieldDocLabel: React.FC<FieldDocLabelProps> = (props) => {
|
||||||
constructor (props: FieldDocLabelProps) {
|
const [open, setOpen] = React.useState(false);
|
||||||
super(props);
|
|
||||||
this.state = {
|
const onToggleDoc = (state: boolean) => {
|
||||||
open: false,
|
setOpen(state);
|
||||||
|
if (props.onToggleDoc) {
|
||||||
|
props.onToggleDoc(state);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
onToggleDoc = (open: boolean) => {
|
const { label, fieldSpec } = props;
|
||||||
this.setState({
|
const { doc } = fieldSpec || {};
|
||||||
open,
|
|
||||||
}, () => {
|
|
||||||
if (this.props.onToggleDoc) {
|
|
||||||
this.props.onToggleDoc(this.state.open);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
if (doc) {
|
||||||
const {label, fieldSpec} = this.props;
|
return (
|
||||||
const {doc} = fieldSpec || {};
|
<label className="maputnik-doc-wrapper">
|
||||||
|
|
||||||
if (doc) {
|
|
||||||
return <label className="maputnik-doc-wrapper">
|
|
||||||
<div className="maputnik-doc-target">
|
<div className="maputnik-doc-target">
|
||||||
{label}
|
{label}
|
||||||
{'\xa0'}
|
{'\xa0'}
|
||||||
<button
|
<button
|
||||||
aria-label={this.state.open ? "close property documentation" : "open property documentation"}
|
aria-label={open ? 'close property documentation' : 'open property documentation'}
|
||||||
className={`maputnik-doc-button maputnik-doc-button--${this.state.open ? 'open' : 'closed'}`}
|
className={`maputnik-doc-button maputnik-doc-button--${open ? 'open' : 'closed'}`}
|
||||||
onClick={() => this.onToggleDoc(!this.state.open)}
|
onClick={() => onToggleDoc(!open)}
|
||||||
data-wd-key={'field-doc-button-'+label}
|
data-wd-key={'field-doc-button-' + label}
|
||||||
>
|
>
|
||||||
{this.state.open ? <MdHighlightOff /> : <MdInfoOutline />}
|
{open ? <MdHighlightOff /> : <MdInfoOutline />}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
}
|
);
|
||||||
else if (label) {
|
} else if (label) {
|
||||||
return <label className="maputnik-doc-wrapper">
|
return (
|
||||||
<div className="maputnik-doc-target">
|
<label className="maputnik-doc-wrapper">
|
||||||
{label}
|
<div className="maputnik-doc-target">{label}</div>
|
||||||
</div>
|
|
||||||
</label>
|
</label>
|
||||||
}
|
);
|
||||||
else {
|
|
||||||
<div />
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
return <div />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FieldDocLabel;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import InputDynamicArray, {FieldDynamicArrayProps as InputDynamicArrayProps} from './InputDynamicArray'
|
import InputDynamicArray, {FieldDynamicArrayProps as InputDynamicArrayProps} from './InputDynamicArray'
|
||||||
import Fieldset from './Fieldset'
|
import Fieldset from './Fieldset'
|
||||||
|
|
||||||
@@ -6,10 +5,12 @@ type FieldDynamicArrayProps = InputDynamicArrayProps & {
|
|||||||
name?: string
|
name?: string
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class FieldDynamicArray extends React.Component<FieldDynamicArrayProps> {
|
const FieldDynamicArray: React.FC<FieldDynamicArrayProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Fieldset label={this.props.label}>
|
<Fieldset label={props.label}>
|
||||||
<InputDynamicArray {...this.props} />
|
<InputDynamicArray {...props} />
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldDynamicArray;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import InputEnum, {InputEnumProps} from './InputEnum'
|
import InputEnum, {InputEnumProps} from './InputEnum'
|
||||||
import Fieldset from './Fieldset';
|
import Fieldset from './Fieldset';
|
||||||
|
|
||||||
@@ -11,10 +10,12 @@ type FieldEnumProps = InputEnumProps & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default class FieldEnum extends React.Component<FieldEnumProps> {
|
const FieldEnum: React.FC<FieldEnumProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Fieldset label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
<Fieldset label={props.label} fieldSpec={props.fieldSpec}>
|
||||||
<InputEnum {...this.props} />
|
<InputEnum {...props} />
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldEnum;
|
||||||
|
|||||||
+188
-216
@@ -111,296 +111,268 @@ type FieldFunctionProps = {
|
|||||||
value?: any
|
value?: any
|
||||||
};
|
};
|
||||||
|
|
||||||
type FieldFunctionState = {
|
|
||||||
dataType: string
|
|
||||||
isEditing: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Supports displaying spec field for zoom function objects
|
/** Supports displaying spec field for zoom function objects
|
||||||
* https://www.mapbox.com/mapbox-gl-style-spec/#types-function-zoom-property
|
* https://www.mapbox.com/mapbox-gl-style-spec/#types-function-zoom-property
|
||||||
*/
|
*/
|
||||||
export default class FieldFunction extends React.Component<FieldFunctionProps, FieldFunctionState> {
|
const FieldFunction: React.FC<FieldFunctionProps> = (props) => {
|
||||||
constructor (props: FieldFunctionProps) {
|
const [dataType, setDataType] = React.useState(
|
||||||
super(props);
|
getDataType(props.value, props.fieldSpec)
|
||||||
this.state = {
|
);
|
||||||
dataType: getDataType(props.value, props.fieldSpec),
|
const [isEditing, setIsEditing] = React.useState(false);
|
||||||
isEditing: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static getDerivedStateFromProps(props: Readonly<FieldFunctionProps>, state: FieldFunctionState) {
|
React.useEffect(() => {
|
||||||
// Because otherwise when editing values we end up accidentally changing field type.
|
if (!isEditing) {
|
||||||
if (state.isEditing) {
|
setDataType(getDataType(props.value, props.fieldSpec));
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
else {
|
}, [props.value, props.fieldSpec, isEditing]);
|
||||||
return {
|
|
||||||
isEditing: false,
|
|
||||||
dataType: getDataType(props.value, props.fieldSpec)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getFieldFunctionType(fieldSpec: any) {
|
const getFieldFunctionType = (fieldSpec: any) => {
|
||||||
if (fieldSpec.expression.interpolated) {
|
if (fieldSpec.expression.interpolated) {
|
||||||
return "exponential"
|
return 'exponential';
|
||||||
}
|
}
|
||||||
if (fieldSpec.type === "number") {
|
if (fieldSpec.type === 'number') {
|
||||||
return "interval"
|
return 'interval';
|
||||||
}
|
}
|
||||||
return "categorical"
|
return 'categorical';
|
||||||
}
|
};
|
||||||
|
|
||||||
addStop = () => {
|
const addStop = () => {
|
||||||
const stops = this.props.value.stops.slice(0)
|
const stops = props.value.stops.slice(0);
|
||||||
const lastStop = stops[stops.length - 1]
|
const lastStop = stops[stops.length - 1];
|
||||||
if (typeof lastStop[0] === "object") {
|
if (typeof lastStop[0] === 'object') {
|
||||||
stops.push([
|
stops.push([
|
||||||
{zoom: lastStop[0].zoom + 1, value: lastStop[0].value},
|
{ zoom: lastStop[0].zoom + 1, value: lastStop[0].value },
|
||||||
lastStop[1]
|
lastStop[1],
|
||||||
])
|
]);
|
||||||
}
|
} else {
|
||||||
else {
|
stops.push([lastStop[0] + 1, lastStop[1]]);
|
||||||
stops.push([lastStop[0] + 1, lastStop[1]])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const changedValue = {
|
const changedValue = {
|
||||||
...this.props.value,
|
...props.value,
|
||||||
stops: stops,
|
stops: stops,
|
||||||
}
|
};
|
||||||
|
|
||||||
this.props.onChange(this.props.fieldName, changedValue)
|
props.onChange(props.fieldName, changedValue);
|
||||||
}
|
};
|
||||||
|
|
||||||
deleteExpression = () => {
|
const deleteExpression = () => {
|
||||||
const {fieldSpec, fieldName} = this.props;
|
const { fieldSpec, fieldName } = props;
|
||||||
this.props.onChange(fieldName, fieldSpec.default);
|
props.onChange(fieldName, fieldSpec.default);
|
||||||
this.setState({
|
setDataType('value');
|
||||||
dataType: "value",
|
};
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteStop = (stopIdx: number) => {
|
const deleteStop = (stopIdx: number) => {
|
||||||
const stops = this.props.value.stops.slice(0)
|
const stops = props.value.stops.slice(0);
|
||||||
stops.splice(stopIdx, 1)
|
stops.splice(stopIdx, 1);
|
||||||
|
|
||||||
let changedValue = {
|
let changedValue: any = {
|
||||||
...this.props.value,
|
...props.value,
|
||||||
stops: stops,
|
stops: stops,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (stops.length === 1) {
|
||||||
|
changedValue = stops[0][1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(stops.length === 1) {
|
props.onChange(props.fieldName, changedValue);
|
||||||
changedValue = stops[0][1]
|
};
|
||||||
}
|
|
||||||
|
|
||||||
this.props.onChange(this.props.fieldName, changedValue)
|
const makeZoomFunction = () => {
|
||||||
}
|
const { value } = props;
|
||||||
|
|
||||||
makeZoomFunction = () => {
|
let zoomFunc: any;
|
||||||
const {value} = this.props;
|
if (typeof value === 'object') {
|
||||||
|
|
||||||
let zoomFunc;
|
|
||||||
if (typeof(value) === "object") {
|
|
||||||
if (value.stops) {
|
if (value.stops) {
|
||||||
zoomFunc = {
|
zoomFunc = {
|
||||||
base: value.base,
|
base: value.base,
|
||||||
stops: value.stops.map((stop: Stop) => {
|
stops: value.stops.map((stop: Stop) => {
|
||||||
return [stop[0].zoom, stop[1] || findDefaultFromSpec(this.props.fieldSpec)];
|
return [stop[0].zoom, stop[1] || findDefaultFromSpec(props.fieldSpec)];
|
||||||
})
|
}),
|
||||||
}
|
};
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
zoomFunc = {
|
zoomFunc = {
|
||||||
base: value.base,
|
base: value.base,
|
||||||
stops: [
|
stops: [
|
||||||
[6, findDefaultFromSpec(this.props.fieldSpec)],
|
[6, findDefaultFromSpec(props.fieldSpec)],
|
||||||
[10, findDefaultFromSpec(this.props.fieldSpec)]
|
[10, findDefaultFromSpec(props.fieldSpec)],
|
||||||
]
|
],
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
zoomFunc = {
|
zoomFunc = {
|
||||||
stops: [
|
stops: [
|
||||||
[6, value || findDefaultFromSpec(this.props.fieldSpec)],
|
[6, value || findDefaultFromSpec(props.fieldSpec)],
|
||||||
[10, value || findDefaultFromSpec(this.props.fieldSpec)]
|
[10, value || findDefaultFromSpec(props.fieldSpec)],
|
||||||
]
|
],
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.onChange(this.props.fieldName, zoomFunc)
|
props.onChange(props.fieldName, zoomFunc);
|
||||||
}
|
};
|
||||||
|
|
||||||
undoExpression = () => {
|
const undoExpression = () => {
|
||||||
const {value, fieldName} = this.props;
|
const { value, fieldName } = props;
|
||||||
|
|
||||||
if (isGetExpression(value)) {
|
if (isGetExpression(value)) {
|
||||||
this.props.onChange(fieldName, {
|
props.onChange(fieldName, {
|
||||||
"type": "identity",
|
type: 'identity',
|
||||||
"property": value[1]
|
property: value[1],
|
||||||
});
|
|
||||||
this.setState({
|
|
||||||
dataType: "value",
|
|
||||||
});
|
});
|
||||||
|
setDataType('value');
|
||||||
|
} else if (isLiteralExpression(value)) {
|
||||||
|
props.onChange(fieldName, value[1]);
|
||||||
|
setDataType('value');
|
||||||
}
|
}
|
||||||
else if (isLiteralExpression(value)) {
|
};
|
||||||
this.props.onChange(fieldName, value[1]);
|
|
||||||
this.setState({
|
|
||||||
dataType: "value",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
canUndo = () => {
|
const canUndo = () => {
|
||||||
const {value, fieldSpec} = this.props;
|
const { value, fieldSpec } = props;
|
||||||
return (
|
return (
|
||||||
isGetExpression(value) ||
|
isGetExpression(value) ||
|
||||||
isLiteralExpression(value) ||
|
isLiteralExpression(value) ||
|
||||||
isPrimative(value) ||
|
isPrimative(value) ||
|
||||||
(Array.isArray(value) && fieldSpec.type === "array")
|
(Array.isArray(value) && fieldSpec.type === 'array')
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
makeExpression = () => {
|
const makeExpression = () => {
|
||||||
const {value, fieldSpec} = this.props;
|
const { value, fieldSpec } = props;
|
||||||
let expression;
|
let expression;
|
||||||
|
|
||||||
if (typeof(value) === "object" && 'stops' in value) {
|
if (typeof value === 'object' && 'stops' in value) {
|
||||||
expression = styleFunction.convertFunction(value, fieldSpec);
|
expression = styleFunction.convertFunction(value, fieldSpec);
|
||||||
|
} else if (isIdentityProperty(value)) {
|
||||||
|
expression = ['get', value.property];
|
||||||
|
} else {
|
||||||
|
expression = ['literal', value || props.fieldSpec.default];
|
||||||
}
|
}
|
||||||
else if (isIdentityProperty(value)) {
|
props.onChange(props.fieldName, expression);
|
||||||
expression = ["get", value.property];
|
};
|
||||||
}
|
|
||||||
else {
|
|
||||||
expression = ["literal", value || this.props.fieldSpec.default];
|
|
||||||
}
|
|
||||||
this.props.onChange(this.props.fieldName, expression);
|
|
||||||
}
|
|
||||||
|
|
||||||
makeDataFunction = () => {
|
const makeDataFunction = () => {
|
||||||
const functionType = this.getFieldFunctionType(this.props.fieldSpec);
|
const functionType = getFieldFunctionType(props.fieldSpec);
|
||||||
const stopValue = functionType === 'categorical' ? '' : 0;
|
const stopValue = functionType === 'categorical' ? '' : 0;
|
||||||
const {value} = this.props;
|
const { value } = props;
|
||||||
let dataFunc;
|
let dataFunc;
|
||||||
|
|
||||||
if (typeof(value) === "object") {
|
if (typeof value === 'object') {
|
||||||
if (value.stops) {
|
if (value.stops) {
|
||||||
dataFunc = {
|
dataFunc = {
|
||||||
property: "",
|
property: '',
|
||||||
type: functionType,
|
type: functionType,
|
||||||
base: value.base,
|
base: value.base,
|
||||||
stops: value.stops.map((stop: Stop) => {
|
stops: value.stops.map((stop: Stop) => {
|
||||||
return [{zoom: stop[0], value: stopValue}, stop[1] || findDefaultFromSpec(this.props.fieldSpec)];
|
return [{ zoom: stop[0], value: stopValue }, stop[1] || findDefaultFromSpec(props.fieldSpec)];
|
||||||
})
|
}),
|
||||||
}
|
};
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dataFunc = {
|
dataFunc = {
|
||||||
property: "",
|
property: '',
|
||||||
type: functionType,
|
type: functionType,
|
||||||
base: value.base,
|
base: value.base,
|
||||||
stops: [
|
stops: [
|
||||||
[{zoom: 6, value: stopValue}, findDefaultFromSpec(this.props.fieldSpec)],
|
[{ zoom: 6, value: stopValue }, findDefaultFromSpec(props.fieldSpec)],
|
||||||
[{zoom: 10, value: stopValue}, findDefaultFromSpec(this.props.fieldSpec)]
|
[{ zoom: 10, value: stopValue }, findDefaultFromSpec(props.fieldSpec)],
|
||||||
]
|
],
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
dataFunc = {
|
dataFunc = {
|
||||||
property: "",
|
property: '',
|
||||||
type: functionType,
|
type: functionType,
|
||||||
base: value.base,
|
base: value.base,
|
||||||
stops: [
|
stops: [
|
||||||
[{zoom: 6, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)],
|
[{ zoom: 6, value: stopValue }, props.value || findDefaultFromSpec(props.fieldSpec)],
|
||||||
[{zoom: 10, value: stopValue}, this.props.value || findDefaultFromSpec(this.props.fieldSpec)]
|
[{ zoom: 10, value: stopValue }, props.value || findDefaultFromSpec(props.fieldSpec)],
|
||||||
]
|
],
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.onChange(this.props.fieldName, dataFunc)
|
props.onChange(props.fieldName, dataFunc);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onMarkEditing = () => {
|
||||||
|
setIsEditing(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onUnmarkEditing = () => {
|
||||||
|
setIsEditing(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const propClass =
|
||||||
|
props.fieldSpec.default === props.value ? 'maputnik-default-property' : 'maputnik-modified-property';
|
||||||
|
|
||||||
|
let specField;
|
||||||
|
|
||||||
|
if (dataType === 'expression') {
|
||||||
|
specField = (
|
||||||
|
<ExpressionProperty
|
||||||
|
errors={props.errors}
|
||||||
|
onChange={props.onChange.bind(null, props.fieldName)}
|
||||||
|
canUndo={canUndo}
|
||||||
|
onUndo={undoExpression}
|
||||||
|
onDelete={deleteExpression}
|
||||||
|
fieldType={props.fieldType}
|
||||||
|
fieldName={props.fieldName}
|
||||||
|
fieldSpec={props.fieldSpec}
|
||||||
|
value={props.value}
|
||||||
|
onFocus={onMarkEditing}
|
||||||
|
onBlur={onUnmarkEditing}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else if (dataType === 'zoom_function') {
|
||||||
|
specField = (
|
||||||
|
<ZoomProperty
|
||||||
|
errors={props.errors}
|
||||||
|
onChange={props.onChange.bind(null)}
|
||||||
|
fieldType={props.fieldType}
|
||||||
|
fieldName={props.fieldName}
|
||||||
|
fieldSpec={props.fieldSpec}
|
||||||
|
value={props.value}
|
||||||
|
onDeleteStop={deleteStop}
|
||||||
|
onAddStop={addStop}
|
||||||
|
onChangeToDataFunction={makeDataFunction}
|
||||||
|
onExpressionClick={makeExpression}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else if (dataType === 'data_function') {
|
||||||
|
specField = (
|
||||||
|
<DataProperty
|
||||||
|
errors={props.errors}
|
||||||
|
onChange={props.onChange.bind(null)}
|
||||||
|
fieldType={props.fieldType}
|
||||||
|
fieldName={props.fieldName}
|
||||||
|
fieldSpec={props.fieldSpec}
|
||||||
|
value={props.value}
|
||||||
|
onDeleteStop={deleteStop}
|
||||||
|
onAddStop={addStop}
|
||||||
|
onChangeToZoomFunction={makeZoomFunction}
|
||||||
|
onExpressionClick={makeExpression}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
specField = (
|
||||||
|
<SpecProperty
|
||||||
|
errors={props.errors}
|
||||||
|
onChange={props.onChange.bind(null)}
|
||||||
|
fieldType={props.fieldType}
|
||||||
|
fieldName={props.fieldName}
|
||||||
|
fieldSpec={props.fieldSpec}
|
||||||
|
value={props.value}
|
||||||
|
onZoomClick={makeZoomFunction}
|
||||||
|
onDataClick={makeDataFunction}
|
||||||
|
onExpressionClick={makeExpression}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMarkEditing = () => {
|
return (
|
||||||
this.setState({isEditing: true});
|
<div className={propClass} data-wd-key={'spec-field-container:' + props.fieldName}>
|
||||||
}
|
|
||||||
|
|
||||||
onUnmarkEditing = () => {
|
|
||||||
this.setState({isEditing: false});
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const {dataType} = this.state;
|
|
||||||
const propClass = this.props.fieldSpec.default === this.props.value ? "maputnik-default-property" : "maputnik-modified-property"
|
|
||||||
let specField;
|
|
||||||
|
|
||||||
if (dataType === "expression") {
|
|
||||||
specField = (
|
|
||||||
<ExpressionProperty
|
|
||||||
errors={this.props.errors}
|
|
||||||
onChange={this.props.onChange.bind(this, this.props.fieldName)}
|
|
||||||
canUndo={this.canUndo}
|
|
||||||
onUndo={this.undoExpression}
|
|
||||||
onDelete={this.deleteExpression}
|
|
||||||
fieldType={this.props.fieldType}
|
|
||||||
fieldName={this.props.fieldName}
|
|
||||||
fieldSpec={this.props.fieldSpec}
|
|
||||||
value={this.props.value}
|
|
||||||
onFocus={this.onMarkEditing}
|
|
||||||
onBlur={this.onUnmarkEditing}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else if (dataType === "zoom_function") {
|
|
||||||
specField = (
|
|
||||||
<ZoomProperty
|
|
||||||
errors={this.props.errors}
|
|
||||||
onChange={this.props.onChange.bind(this)}
|
|
||||||
fieldType={this.props.fieldType}
|
|
||||||
fieldName={this.props.fieldName}
|
|
||||||
fieldSpec={this.props.fieldSpec}
|
|
||||||
value={this.props.value}
|
|
||||||
onDeleteStop={this.deleteStop}
|
|
||||||
onAddStop={this.addStop}
|
|
||||||
onChangeToDataFunction={this.makeDataFunction}
|
|
||||||
onExpressionClick={this.makeExpression}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else if (dataType === "data_function") {
|
|
||||||
// TODO: Rename to FieldFunction **this file** shouldn't be called that
|
|
||||||
specField = (
|
|
||||||
<DataProperty
|
|
||||||
errors={this.props.errors}
|
|
||||||
onChange={this.props.onChange.bind(this)}
|
|
||||||
fieldType={this.props.fieldType}
|
|
||||||
fieldName={this.props.fieldName}
|
|
||||||
fieldSpec={this.props.fieldSpec}
|
|
||||||
value={this.props.value}
|
|
||||||
onDeleteStop={this.deleteStop}
|
|
||||||
onAddStop={this.addStop}
|
|
||||||
onChangeToZoomFunction={this.makeZoomFunction}
|
|
||||||
onExpressionClick={this.makeExpression}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
specField = (
|
|
||||||
<SpecProperty
|
|
||||||
errors={this.props.errors}
|
|
||||||
onChange={this.props.onChange.bind(this)}
|
|
||||||
fieldType={this.props.fieldType}
|
|
||||||
fieldName={this.props.fieldName}
|
|
||||||
fieldSpec={this.props.fieldSpec}
|
|
||||||
value={this.props.value}
|
|
||||||
onZoomClick={this.makeZoomFunction}
|
|
||||||
onDataClick={this.makeDataFunction}
|
|
||||||
onExpressionClick={this.makeExpression}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return <div className={propClass} data-wd-key={"spec-field-container:"+this.props.fieldName}>
|
|
||||||
{specField}
|
{specField}
|
||||||
</div>
|
</div>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldFunction;
|
||||||
|
|||||||
+12
-12
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
|
|
||||||
import latest from '@maplibre/maplibre-gl-style-spec/dist/latest.json'
|
import latest from '@maplibre/maplibre-gl-style-spec/dist/latest.json'
|
||||||
import Block from './Block'
|
import Block from './Block'
|
||||||
@@ -11,18 +10,19 @@ type FieldIdProps = {
|
|||||||
error?: {message: string}
|
error?: {message: string}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class FieldId extends React.Component<FieldIdProps> {
|
const FieldId: React.FC<FieldIdProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Block label="ID" fieldSpec={latest.layer.id}
|
<Block label="ID" fieldSpec={latest.layer.id}
|
||||||
|
data-wd-key={props.wdKey}
|
||||||
data-wd-key={this.props.wdKey}
|
error={props.error}
|
||||||
error={this.props.error}
|
|
||||||
>
|
>
|
||||||
<InputString
|
<InputString
|
||||||
value={this.props.value}
|
value={props.value}
|
||||||
onInput={this.props.onChange}
|
onInput={props.onChange}
|
||||||
data-wd-key={this.props.wdKey + ".input"}
|
data-wd-key={props.wdKey + ".input"}
|
||||||
/>
|
/>
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldId;
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import React from 'react'
|
|
||||||
import InputJson, {InputJsonProps} from './InputJson'
|
import InputJson, {InputJsonProps} from './InputJson'
|
||||||
|
|
||||||
|
|
||||||
type FieldJsonProps = InputJsonProps & {};
|
type FieldJsonProps = InputJsonProps & {};
|
||||||
|
|
||||||
|
|
||||||
export default class FieldJson extends React.Component<FieldJsonProps> {
|
const FieldJson: React.FC<FieldJsonProps> = (props) => {
|
||||||
render() {
|
return <InputJson {...props} />;
|
||||||
return <InputJson {...this.props} />
|
};
|
||||||
}
|
|
||||||
}
|
export default FieldJson;
|
||||||
|
|||||||
@@ -11,25 +11,25 @@ type FieldMaxZoomInternalProps = {
|
|||||||
error?: {message: string}
|
error?: {message: string}
|
||||||
} & WithTranslation;
|
} & WithTranslation;
|
||||||
|
|
||||||
class FieldMaxZoomInternal extends React.Component<FieldMaxZoomInternalProps> {
|
const FieldMaxZoomInternal: React.FC<FieldMaxZoomInternalProps> = (props) => {
|
||||||
render() {
|
const t = props.t;
|
||||||
const t = this.props.t;
|
return (
|
||||||
return <Block label={t("Max Zoom")} fieldSpec={latest.layer.maxzoom}
|
<Block label={t('Max Zoom')} fieldSpec={latest.layer.maxzoom}
|
||||||
error={this.props.error}
|
error={props.error}
|
||||||
data-wd-key="max-zoom"
|
data-wd-key="max-zoom"
|
||||||
>
|
>
|
||||||
<InputNumber
|
<InputNumber
|
||||||
allowRange={true}
|
allowRange={true}
|
||||||
value={this.props.value}
|
value={props.value}
|
||||||
onChange={this.props.onChange}
|
onChange={props.onChange}
|
||||||
min={latest.layer.maxzoom.minimum}
|
min={latest.layer.maxzoom.minimum}
|
||||||
max={latest.layer.maxzoom.maximum}
|
max={latest.layer.maxzoom.maximum}
|
||||||
default={latest.layer.maxzoom.maximum}
|
default={latest.layer.maxzoom.maximum}
|
||||||
data-wd-key="max-zoom.input"
|
data-wd-key="max-zoom.input"
|
||||||
/>
|
/>
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
const FieldMaxZoom = withTranslation()(FieldMaxZoomInternal);
|
const FieldMaxZoom = withTranslation()(FieldMaxZoomInternal);
|
||||||
export default FieldMaxZoom;
|
export default FieldMaxZoom;
|
||||||
|
|||||||
@@ -11,25 +11,25 @@ type FieldMinZoomInternalProps = {
|
|||||||
error?: {message: string}
|
error?: {message: string}
|
||||||
} & WithTranslation;
|
} & WithTranslation;
|
||||||
|
|
||||||
class FieldMinZoomInternal extends React.Component<FieldMinZoomInternalProps> {
|
const FieldMinZoomInternal: React.FC<FieldMinZoomInternalProps> = (props) => {
|
||||||
render() {
|
const t = props.t;
|
||||||
const t = this.props.t;
|
return (
|
||||||
return <Block label={t("Min Zoom")} fieldSpec={latest.layer.minzoom}
|
<Block label={t('Min Zoom')} fieldSpec={latest.layer.minzoom}
|
||||||
error={this.props.error}
|
error={props.error}
|
||||||
data-wd-key="min-zoom"
|
data-wd-key="min-zoom"
|
||||||
>
|
>
|
||||||
<InputNumber
|
<InputNumber
|
||||||
allowRange={true}
|
allowRange={true}
|
||||||
value={this.props.value}
|
value={props.value}
|
||||||
onChange={this.props.onChange}
|
onChange={props.onChange}
|
||||||
min={latest.layer.minzoom.minimum}
|
min={latest.layer.minzoom.minimum}
|
||||||
max={latest.layer.minzoom.maximum}
|
max={latest.layer.minzoom.maximum}
|
||||||
default={latest.layer.minzoom.minimum}
|
default={latest.layer.minzoom.minimum}
|
||||||
data-wd-key='min-zoom.input'
|
data-wd-key='min-zoom.input'
|
||||||
/>
|
/>
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
const FieldMinZoom = withTranslation()(FieldMinZoomInternal);
|
const FieldMinZoom = withTranslation()(FieldMinZoomInternal);
|
||||||
export default FieldMinZoom;
|
export default FieldMinZoom;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import InputMultiInput, {InputMultiInputProps} from './InputMultiInput'
|
import InputMultiInput, {InputMultiInputProps} from './InputMultiInput'
|
||||||
import Fieldset from './Fieldset'
|
import Fieldset from './Fieldset'
|
||||||
|
|
||||||
@@ -8,10 +7,12 @@ type FieldMultiInputProps = InputMultiInputProps & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default class FieldMultiInput extends React.Component<FieldMultiInputProps> {
|
const FieldMultiInput: React.FC<FieldMultiInputProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Fieldset label={this.props.label}>
|
<Fieldset label={props.label}>
|
||||||
<InputMultiInput {...this.props} />
|
<InputMultiInput {...props} />
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldMultiInput;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import InputNumber, {InputNumberProps} from './InputNumber'
|
import InputNumber, {InputNumberProps} from './InputNumber'
|
||||||
import Block from './Block'
|
import Block from './Block'
|
||||||
|
|
||||||
@@ -11,10 +10,12 @@ type FieldNumberProps = InputNumberProps & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default class FieldNumber extends React.Component<FieldNumberProps> {
|
const FieldNumber: React.FC<FieldNumberProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Block label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
<Block label={props.label} fieldSpec={props.fieldSpec}>
|
||||||
<InputNumber {...this.props} />
|
<InputNumber {...props} />
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldNumber;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import Block from './Block'
|
import Block from './Block'
|
||||||
import InputSelect, {InputSelectProps} from './InputSelect'
|
import InputSelect, {InputSelectProps} from './InputSelect'
|
||||||
|
|
||||||
@@ -11,10 +10,12 @@ type FieldSelectProps = InputSelectProps & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default class FieldSelect extends React.Component<FieldSelectProps> {
|
const FieldSelect: React.FC<FieldSelectProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Block label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
<Block label={props.label} fieldSpec={props.fieldSpec}>
|
||||||
<InputSelect {...this.props}/>
|
<InputSelect {...props} />
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldSelect;
|
||||||
|
|||||||
@@ -13,28 +13,30 @@ type FieldSourceInternalProps = {
|
|||||||
error?: {message: string}
|
error?: {message: string}
|
||||||
} & WithTranslation;
|
} & WithTranslation;
|
||||||
|
|
||||||
class FieldSourceInternal extends React.Component<FieldSourceInternalProps> {
|
const FieldSourceInternal: React.FC<FieldSourceInternalProps> = ({
|
||||||
static defaultProps = {
|
onChange = () => {},
|
||||||
onChange: () => {},
|
sourceIds = [],
|
||||||
sourceIds: [],
|
wdKey,
|
||||||
}
|
value,
|
||||||
|
error,
|
||||||
render() {
|
t
|
||||||
const t = this.props.t;
|
}) => {
|
||||||
return <Block
|
return (
|
||||||
label={t("Source")}
|
<Block
|
||||||
|
label={t('Source')}
|
||||||
fieldSpec={latest.layer.source}
|
fieldSpec={latest.layer.source}
|
||||||
error={this.props.error}
|
error={error}
|
||||||
data-wd-key={this.props.wdKey}
|
data-wd-key={wdKey}
|
||||||
>
|
>
|
||||||
<InputAutocomplete
|
<InputAutocomplete
|
||||||
value={this.props.value}
|
value={value}
|
||||||
onChange={this.props.onChange}
|
onChange={onChange}
|
||||||
options={this.props.sourceIds?.map(src => [src, src])}
|
options={sourceIds?.map((src) => [src, src])}
|
||||||
/>
|
/>
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
const FieldSource = withTranslation()(FieldSourceInternal);
|
const FieldSource = withTranslation()(FieldSourceInternal);
|
||||||
export default FieldSource;
|
export default FieldSource;
|
||||||
|
|||||||
@@ -9,34 +9,31 @@ type FieldSourceLayerInternalProps = {
|
|||||||
value?: string
|
value?: string
|
||||||
onChange?(...args: unknown[]): unknown
|
onChange?(...args: unknown[]): unknown
|
||||||
sourceLayerIds?: unknown[]
|
sourceLayerIds?: unknown[]
|
||||||
isFixed?: boolean
|
|
||||||
error?: {message: string}
|
error?: {message: string}
|
||||||
} & WithTranslation;
|
} & WithTranslation;
|
||||||
|
|
||||||
class FieldSourceLayerInternal extends React.Component<FieldSourceLayerInternalProps> {
|
const FieldSourceLayerInternal: React.FC<FieldSourceLayerInternalProps> = ({
|
||||||
static defaultProps = {
|
onChange = () => {},
|
||||||
onChange: () => {},
|
sourceLayerIds = [],
|
||||||
sourceLayerIds: [],
|
value,
|
||||||
isFixed: false
|
error,
|
||||||
}
|
t
|
||||||
|
}) => {
|
||||||
render() {
|
return (
|
||||||
const t = this.props.t;
|
<Block
|
||||||
return <Block
|
label={t('Source Layer')}
|
||||||
label={t("Source Layer")}
|
|
||||||
fieldSpec={latest.layer['source-layer']}
|
fieldSpec={latest.layer['source-layer']}
|
||||||
data-wd-key="layer-source-layer"
|
data-wd-key="layer-source-layer"
|
||||||
error={this.props.error}
|
error={error}
|
||||||
>
|
>
|
||||||
<InputAutocomplete
|
<InputAutocomplete
|
||||||
keepMenuWithinWindowBounds={!!this.props.isFixed}
|
value={value}
|
||||||
value={this.props.value}
|
onChange={onChange}
|
||||||
onChange={this.props.onChange}
|
options={sourceLayerIds?.map((l) => [l, l])}
|
||||||
options={this.props.sourceLayerIds?.map(l => [l, l])}
|
|
||||||
/>
|
/>
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
const FieldSourceLayer = withTranslation()(FieldSourceLayerInternal);
|
const FieldSourceLayer = withTranslation()(FieldSourceLayerInternal);
|
||||||
export default FieldSourceLayer;
|
export default FieldSourceLayer;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import Block from './Block'
|
import Block from './Block'
|
||||||
import InputString, {InputStringProps} from './InputString'
|
import InputString, {InputStringProps} from './InputString'
|
||||||
|
|
||||||
@@ -10,10 +9,12 @@ type FieldStringProps = InputStringProps & {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class FieldString extends React.Component<FieldStringProps> {
|
const FieldString: React.FC<FieldStringProps> = (props) => {
|
||||||
render() {
|
return (
|
||||||
return <Block label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
<Block label={props.label} fieldSpec={props.fieldSpec}>
|
||||||
<InputString {...this.props} />
|
<InputString {...props} />
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default FieldString;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import {v8} from '@maplibre/maplibre-gl-style-spec'
|
||||||
import latest from '@maplibre/maplibre-gl-style-spec/dist/latest.json'
|
|
||||||
import Block from './Block'
|
import Block from './Block'
|
||||||
import InputSelect from './InputSelect'
|
import InputSelect from './InputSelect'
|
||||||
import InputString from './InputString'
|
import InputString from './InputString'
|
||||||
import { WithTranslation, withTranslation } from 'react-i18next';
|
import { WithTranslation, withTranslation } from 'react-i18next';
|
||||||
|
import { startCase } from 'lodash'
|
||||||
|
|
||||||
type FieldTypeInternalProps = {
|
type FieldTypeInternalProps = {
|
||||||
value: string
|
value: string
|
||||||
@@ -14,44 +14,34 @@ type FieldTypeInternalProps = {
|
|||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
} & WithTranslation;
|
} & WithTranslation;
|
||||||
|
|
||||||
class FieldTypeInternal extends React.Component<FieldTypeInternalProps> {
|
const FieldTypeInternal: React.FC<FieldTypeInternalProps> = ({
|
||||||
static defaultProps = {
|
t,
|
||||||
disabled: false,
|
value,
|
||||||
}
|
wdKey,
|
||||||
|
onChange,
|
||||||
render() {
|
error,
|
||||||
const t = this.props.t;
|
disabled = false
|
||||||
return <Block label={t("Type")} fieldSpec={latest.layer.type}
|
}) => {
|
||||||
data-wd-key={this.props.wdKey}
|
const layerstypes: [string, string][] = Object.keys(v8.layer.type.values || {}).map(v => [v, startCase(v.replace(/-/g, ' '))]);
|
||||||
error={this.props.error}
|
return (
|
||||||
|
<Block label={t('Type')} fieldSpec={v8.layer.type}
|
||||||
|
data-wd-key={wdKey}
|
||||||
|
error={error}
|
||||||
>
|
>
|
||||||
{this.props.disabled &&
|
{disabled && (
|
||||||
<InputString
|
<InputString value={value} disabled={true} />
|
||||||
value={this.props.value}
|
)}
|
||||||
disabled={true}
|
{!disabled && (
|
||||||
/>
|
|
||||||
}
|
|
||||||
{!this.props.disabled &&
|
|
||||||
<InputSelect
|
<InputSelect
|
||||||
options={[
|
options={layerstypes}
|
||||||
['background', 'Background'],
|
onChange={onChange}
|
||||||
['fill', 'Fill'],
|
value={value}
|
||||||
['line', 'Line'],
|
data-wd-key={wdKey + '.select'}
|
||||||
['symbol', 'Symbol'],
|
|
||||||
['raster', 'Raster'],
|
|
||||||
['circle', 'Circle'],
|
|
||||||
['fill-extrusion', 'Fill Extrusion'],
|
|
||||||
['hillshade', 'Hillshade'],
|
|
||||||
['heatmap', 'Heatmap'],
|
|
||||||
]}
|
|
||||||
onChange={this.props.onChange}
|
|
||||||
value={this.props.value}
|
|
||||||
data-wd-key={this.props.wdKey + ".select"}
|
|
||||||
/>
|
/>
|
||||||
}
|
)}
|
||||||
</Block>
|
</Block>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
const FieldType = withTranslation()(FieldTypeInternal);
|
const FieldType = withTranslation()(FieldTypeInternal);
|
||||||
export default FieldType;
|
export default FieldType;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import InputUrl, {FieldUrlProps as InputUrlProps} from './InputUrl'
|
import InputUrl, {FieldUrlProps as InputUrlProps} from './InputUrl'
|
||||||
import Block from './Block'
|
import Block from './Block'
|
||||||
|
|
||||||
@@ -11,12 +10,12 @@ type FieldUrlProps = InputUrlProps & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default class FieldUrl extends React.Component<FieldUrlProps> {
|
const FieldUrl: React.FC<FieldUrlProps> = (props) => {
|
||||||
render () {
|
return (
|
||||||
return (
|
<Block label={props.label} fieldSpec={props.fieldSpec}>
|
||||||
<Block label={this.props.label} fieldSpec={this.props.fieldSpec}>
|
<InputUrl {...props} />
|
||||||
<InputUrl {...this.props} />
|
</Block>
|
||||||
</Block>
|
);
|
||||||
);
|
};
|
||||||
}
|
|
||||||
}
|
export default FieldUrl;
|
||||||
|
|||||||
+26
-43
@@ -9,57 +9,40 @@ type FieldsetProps = PropsWithChildren & {
|
|||||||
action?: ReactElement,
|
action?: ReactElement,
|
||||||
};
|
};
|
||||||
|
|
||||||
type FieldsetState = {
|
|
||||||
showDoc: boolean
|
|
||||||
};
|
|
||||||
|
|
||||||
export default class Fieldset extends React.Component<FieldsetProps, FieldsetState> {
|
const Fieldset: React.FC<FieldsetProps> = (props) => {
|
||||||
_labelId: string;
|
const [showDoc, setShowDoc] = React.useState(false);
|
||||||
|
const labelId = React.useRef(generateUniqueId('fieldset_label_'));
|
||||||
|
|
||||||
constructor (props: FieldsetProps) {
|
const onToggleDoc = (val: boolean) => {
|
||||||
super(props);
|
setShowDoc(val);
|
||||||
this._labelId = generateUniqueId(`fieldset_label_`);
|
};
|
||||||
this.state = {
|
|
||||||
showDoc: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onToggleDoc = (val: boolean) => {
|
return (
|
||||||
this.setState({
|
<div className="maputnik-input-block" role="group" aria-labelledby={labelId.current}>
|
||||||
showDoc: val
|
{props.fieldSpec && (
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render () {
|
|
||||||
return <div className="maputnik-input-block" role="group" aria-labelledby={this._labelId}>
|
|
||||||
{this.props.fieldSpec &&
|
|
||||||
<div className="maputnik-input-block-label">
|
<div className="maputnik-input-block-label">
|
||||||
<FieldDocLabel
|
<FieldDocLabel
|
||||||
label={this.props.label}
|
label={props.label}
|
||||||
onToggleDoc={this.onToggleDoc}
|
onToggleDoc={onToggleDoc}
|
||||||
fieldSpec={this.props.fieldSpec}
|
fieldSpec={props.fieldSpec}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
}
|
)}
|
||||||
{!this.props.fieldSpec &&
|
{!props.fieldSpec && (
|
||||||
<div className="maputnik-input-block-label">
|
<div className="maputnik-input-block-label">
|
||||||
{this.props.label}
|
{props.label}
|
||||||
</div>
|
</div>
|
||||||
}
|
)}
|
||||||
<div className="maputnik-input-block-action">
|
<div className="maputnik-input-block-action">{props.action}</div>
|
||||||
{this.props.action}
|
<div className="maputnik-input-block-content">{props.children}</div>
|
||||||
</div>
|
{props.fieldSpec && (
|
||||||
<div className="maputnik-input-block-content">
|
<div className="maputnik-doc-inline" style={{ display: showDoc ? '' : 'none' }}>
|
||||||
{this.props.children}
|
<Doc fieldSpec={props.fieldSpec} />
|
||||||
</div>
|
|
||||||
{this.props.fieldSpec &&
|
|
||||||
<div
|
|
||||||
className="maputnik-doc-inline"
|
|
||||||
style={{display: this.state.showDoc ? '' : 'none'}}
|
|
||||||
>
|
|
||||||
<Doc fieldSpec={this.props.fieldSpec} />
|
|
||||||
</div>
|
</div>
|
||||||
}
|
)}
|
||||||
</div>
|
</div>
|
||||||
}
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Fieldset;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {mdiTableRowPlusAfter} from '@mdi/js';
|
import {mdiTableRowPlusAfter} from '@mdi/js';
|
||||||
import {isEqual} from 'lodash';
|
import {isEqual} from 'lodash';
|
||||||
import {ExpressionSpecification, LegacyFilterSpecification, StyleSpecification} from 'maplibre-gl'
|
import {ExpressionSpecification, LegacyFilterSpecification} from 'maplibre-gl'
|
||||||
import {latest, migrate, convertFilter} from '@maplibre/maplibre-gl-style-spec'
|
import {latest, migrate, convertFilter} from '@maplibre/maplibre-gl-style-spec'
|
||||||
import {mdiFunctionVariant} from '@mdi/js';
|
import {mdiFunctionVariant} from '@mdi/js';
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@ import InputButton from './InputButton'
|
|||||||
import Doc from './Doc'
|
import Doc from './Doc'
|
||||||
import ExpressionProperty from './_ExpressionProperty';
|
import ExpressionProperty from './_ExpressionProperty';
|
||||||
import { WithTranslation, withTranslation } from 'react-i18next';
|
import { WithTranslation, withTranslation } from 'react-i18next';
|
||||||
|
import type { StyleSpecificationWithId } from '../libs/definitions';
|
||||||
|
|
||||||
|
|
||||||
function combiningFilter(props: FilterEditorInternalProps): LegacyFilterSpecification | ExpressionSpecification {
|
function combiningFilter(props: FilterEditorInternalProps): LegacyFilterSpecification | ExpressionSpecification {
|
||||||
@@ -39,7 +40,7 @@ function migrateFilter(filter: LegacyFilterSpecification | ExpressionSpecificati
|
|||||||
return (migrate(createStyleFromFilter(filter) as any).layers[0] as any).filter;
|
return (migrate(createStyleFromFilter(filter) as any).layers[0] as any).filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createStyleFromFilter(filter: LegacyFilterSpecification | ExpressionSpecification): StyleSpecification & {id: string} {
|
function createStyleFromFilter(filter: LegacyFilterSpecification | ExpressionSpecification): StyleSpecificationWithId {
|
||||||
return {
|
return {
|
||||||
"id": "tmp",
|
"id": "tmp",
|
||||||
"version": 8,
|
"version": 8,
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import InputAutocomplete from './InputAutocomplete'
|
||||||
|
import { mount } from 'cypress/react'
|
||||||
|
|
||||||
|
const fruits = ['apple', 'banana', 'cherry'];
|
||||||
|
|
||||||
|
describe('<InputAutocomplete />', () => {
|
||||||
|
it('filters options when typing', () => {
|
||||||
|
mount(
|
||||||
|
<InputAutocomplete aria-label="Fruit" options={fruits.map(f => [f, f])} />
|
||||||
|
);
|
||||||
|
cy.get('input').focus();
|
||||||
|
cy.get('.maputnik-autocomplete-menu-item').should('have.length', 3);
|
||||||
|
cy.get('input').type('ch');
|
||||||
|
cy.get('.maputnik-autocomplete-menu-item').should('have.length', 1).and('contain', 'cherry');
|
||||||
|
cy.get('.maputnik-autocomplete-menu-item').click();
|
||||||
|
cy.get('input').should('have.value', 'cherry');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,100 +1,116 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import Autocomplete from 'react-autocomplete'
|
import {useCombobox} from 'downshift'
|
||||||
|
|
||||||
|
const MAX_HEIGHT = 140
|
||||||
const MAX_HEIGHT = 140;
|
|
||||||
|
|
||||||
export type InputAutocompleteProps = {
|
export type InputAutocompleteProps = {
|
||||||
value?: string
|
value?: string
|
||||||
options: any[]
|
options?: any[]
|
||||||
onChange(value: string | undefined): unknown
|
onChange?(value: string | undefined): unknown
|
||||||
keepMenuWithinWindowBounds?: boolean
|
|
||||||
'aria-label'?: string
|
'aria-label'?: string
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class InputAutocomplete extends React.Component<InputAutocompleteProps> {
|
export default function InputAutocomplete({
|
||||||
state = {
|
value,
|
||||||
maxHeight: MAX_HEIGHT
|
options = [],
|
||||||
}
|
onChange = () => {},
|
||||||
|
'aria-label': ariaLabel,
|
||||||
|
}: InputAutocompleteProps) {
|
||||||
|
const [input, setInput] = React.useState(value || '')
|
||||||
|
const menuRef = React.useRef<HTMLDivElement>(null)
|
||||||
|
const [maxHeight, setMaxHeight] = React.useState(MAX_HEIGHT)
|
||||||
|
|
||||||
autocompleteMenuEl: HTMLDivElement | null = null;
|
const filteredItems = React.useMemo(() => {
|
||||||
|
const lv = input.toLowerCase()
|
||||||
|
return options.filter((item) => item[0].toLowerCase().includes(lv))
|
||||||
|
}, [options, input])
|
||||||
|
|
||||||
static defaultProps = {
|
const calcMaxHeight = React.useCallback(() => {
|
||||||
onChange: () => {},
|
if (menuRef.current) {
|
||||||
options: [],
|
const space = window.innerHeight - menuRef.current.getBoundingClientRect().top
|
||||||
}
|
setMaxHeight(Math.min(space, MAX_HEIGHT))
|
||||||
|
|
||||||
calcMaxHeight() {
|
|
||||||
if(this.props.keepMenuWithinWindowBounds) {
|
|
||||||
const maxHeight = window.innerHeight - this.autocompleteMenuEl!.getBoundingClientRect().top;
|
|
||||||
const limitedMaxHeight = Math.min(maxHeight, MAX_HEIGHT);
|
|
||||||
|
|
||||||
if(limitedMaxHeight != this.state.maxHeight) {
|
|
||||||
this.setState({
|
|
||||||
maxHeight: limitedMaxHeight
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}, [])
|
||||||
|
|
||||||
componentDidMount() {
|
const {
|
||||||
this.calcMaxHeight();
|
isOpen,
|
||||||
}
|
getMenuProps,
|
||||||
|
getInputProps,
|
||||||
|
getItemProps,
|
||||||
|
highlightedIndex,
|
||||||
|
openMenu,
|
||||||
|
} = useCombobox({
|
||||||
|
items: filteredItems,
|
||||||
|
inputValue: input,
|
||||||
|
itemToString: (item) => (item ? item[0] : ''),
|
||||||
|
stateReducer: (_state, action) => {
|
||||||
|
if (action.type === useCombobox.stateChangeTypes.InputClick) {
|
||||||
|
return {...action.changes, isOpen: true}
|
||||||
|
}
|
||||||
|
return action.changes
|
||||||
|
},
|
||||||
|
onSelectedItemChange: ({selectedItem}) => {
|
||||||
|
const v = selectedItem ? selectedItem[0] : ''
|
||||||
|
setInput(v)
|
||||||
|
onChange(selectedItem ? selectedItem[0] : undefined)
|
||||||
|
},
|
||||||
|
onInputValueChange: ({inputValue: v}) => {
|
||||||
|
if (typeof v === 'string') {
|
||||||
|
setInput(v)
|
||||||
|
onChange(v === '' ? undefined : v)
|
||||||
|
openMenu()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
componentDidUpdate() {
|
React.useEffect(() => {
|
||||||
this.calcMaxHeight();
|
if (isOpen) {
|
||||||
}
|
calcMaxHeight()
|
||||||
|
}
|
||||||
|
}, [isOpen, calcMaxHeight])
|
||||||
|
|
||||||
onChange(v: string) {
|
React.useEffect(() => {
|
||||||
this.props.onChange(v === "" ? undefined : v);
|
window.addEventListener('resize', calcMaxHeight)
|
||||||
}
|
return () => window.removeEventListener('resize', calcMaxHeight)
|
||||||
|
}, [calcMaxHeight])
|
||||||
|
|
||||||
render() {
|
React.useEffect(() => {
|
||||||
return <div
|
setInput(value || '')
|
||||||
ref={(el) => {
|
}, [value])
|
||||||
this.autocompleteMenuEl = el;
|
|
||||||
}}
|
return (
|
||||||
>
|
<div className="maputnik-autocomplete">
|
||||||
<Autocomplete
|
<input
|
||||||
menuStyle={{
|
{...getInputProps({
|
||||||
position: "fixed",
|
'aria-label': ariaLabel,
|
||||||
overflow: "auto",
|
className: 'maputnik-string',
|
||||||
maxHeight: this.state.maxHeight,
|
spellCheck: false,
|
||||||
zIndex: '998'
|
onFocus: () => openMenu(),
|
||||||
}}
|
})}
|
||||||
wrapperProps={{
|
|
||||||
className: "maputnik-autocomplete",
|
|
||||||
style: {}
|
|
||||||
}}
|
|
||||||
inputProps={{
|
|
||||||
'aria-label': this.props['aria-label'],
|
|
||||||
className: "maputnik-string",
|
|
||||||
spellCheck: false
|
|
||||||
}}
|
|
||||||
value={this.props.value}
|
|
||||||
items={this.props.options}
|
|
||||||
getItemValue={(item) => item[0]}
|
|
||||||
onSelect={v => this.onChange(v)}
|
|
||||||
onChange={(_e, v) => this.onChange(v)}
|
|
||||||
shouldItemRender={(item, value="") => {
|
|
||||||
if (typeof(value) === "string") {
|
|
||||||
return item[0].toLowerCase().indexOf(value.toLowerCase()) > -1
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}}
|
|
||||||
renderItem={(item, isHighlighted) => (
|
|
||||||
<div
|
|
||||||
key={item[0]}
|
|
||||||
className={classnames({
|
|
||||||
"maputnik-autocomplete-menu-item": true,
|
|
||||||
"maputnik-autocomplete-menu-item-selected": isHighlighted,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
{item[1]}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
|
<div
|
||||||
|
{...getMenuProps({}, {suppressRefError: true})}
|
||||||
|
ref={menuRef}
|
||||||
|
style={{position: 'fixed', overflow: 'auto', maxHeight, zIndex: 998}}
|
||||||
|
className="maputnik-autocomplete-menu"
|
||||||
|
>
|
||||||
|
{isOpen &&
|
||||||
|
filteredItems.map((item, index) => (
|
||||||
|
<div
|
||||||
|
key={item[0]}
|
||||||
|
{...getItemProps({
|
||||||
|
item,
|
||||||
|
index,
|
||||||
|
className: classnames('maputnik-autocomplete-menu-item', {
|
||||||
|
'maputnik-autocomplete-menu-item-selected': highlightedIndex === index,
|
||||||
|
}),
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{item[1]}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+143
-89
@@ -1,9 +1,10 @@
|
|||||||
import React, {type JSX} from 'react'
|
import React, {type JSX} from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import { Wrapper, Button, Menu, MenuItem } from 'react-aria-menubutton'
|
import { Wrapper, Button, Menu, MenuItem } from 'react-aria-menubutton'
|
||||||
import {Accordion} from 'react-accessible-accordion';
|
import {Accordion} from 'react-accessible-accordion';
|
||||||
import {MdMoreVert} from 'react-icons/md'
|
import {MdMoreVert} from 'react-icons/md'
|
||||||
|
import { IconContext } from 'react-icons'
|
||||||
import {BackgroundLayerSpecification, LayerSpecification, SourceSpecification} from 'maplibre-gl';
|
import {BackgroundLayerSpecification, LayerSpecification, SourceSpecification} from 'maplibre-gl';
|
||||||
|
import {v8} from '@maplibre/maplibre-gl-style-spec';
|
||||||
|
|
||||||
import FieldJson from './FieldJson'
|
import FieldJson from './FieldJson'
|
||||||
import FilterEditor from './FilterEditor'
|
import FilterEditor from './FilterEditor'
|
||||||
@@ -17,23 +18,79 @@ import FieldComment from './FieldComment'
|
|||||||
import FieldSource from './FieldSource'
|
import FieldSource from './FieldSource'
|
||||||
import FieldSourceLayer from './FieldSourceLayer'
|
import FieldSourceLayer from './FieldSourceLayer'
|
||||||
import { changeType, changeProperty } from '../libs/layer'
|
import { changeType, changeProperty } from '../libs/layer'
|
||||||
import layout from '../config/layout.json'
|
|
||||||
import {formatLayerId} from '../libs/format';
|
import {formatLayerId} from '../libs/format';
|
||||||
import { WithTranslation, withTranslation } from 'react-i18next';
|
import { WithTranslation, withTranslation } from 'react-i18next';
|
||||||
import { TFunction } from 'i18next';
|
import { TFunction } from 'i18next';
|
||||||
|
import { NON_SOURCE_LAYERS } from '../libs/non-source-layers';
|
||||||
|
import { OnMoveLayerCallback } from '../libs/definitions';
|
||||||
|
|
||||||
|
type MaputnikLayoutGroup = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
type: string;
|
||||||
|
fields: string[];
|
||||||
|
}
|
||||||
|
|
||||||
function getLayoutForType(type: LayerSpecification["type"], t: TFunction) {
|
function getLayoutForSymbolType(t: TFunction): MaputnikLayoutGroup[] {
|
||||||
return layout[type] ? {
|
const groups: MaputnikLayoutGroup[] = [];
|
||||||
...layout[type],
|
groups.push({
|
||||||
groups: layout[type].groups.map(group => {
|
title: t("General layout properties"),
|
||||||
return {
|
id: "General_layout_properties",
|
||||||
...group,
|
type: "properties",
|
||||||
id: group.title.replace(/ /g, "_"),
|
fields: Object.keys(v8["layout_symbol"]).filter(f => f.startsWith("symbol-"))
|
||||||
title: t(group.title)
|
});
|
||||||
};
|
groups.push({
|
||||||
}),
|
title: t("Text layout properties"),
|
||||||
} : layout.invalid;
|
id: "Text_layout_properties",
|
||||||
|
type: "properties",
|
||||||
|
fields: Object.keys(v8["layout_symbol"]).filter(f => f.startsWith("text-"))
|
||||||
|
});
|
||||||
|
groups.push({
|
||||||
|
title: t("Icon layout properties"),
|
||||||
|
id: "Icon_layout_properties",
|
||||||
|
type: "properties",
|
||||||
|
fields: Object.keys(v8["layout_symbol"]).filter(f => f.startsWith("icon-"))
|
||||||
|
});
|
||||||
|
groups.push({
|
||||||
|
title: t("Text paint properties"),
|
||||||
|
id: "Text_paint_properties",
|
||||||
|
type: "properties",
|
||||||
|
fields: Object.keys(v8["paint_symbol"]).filter(f => f.startsWith("text-"))
|
||||||
|
});
|
||||||
|
groups.push({
|
||||||
|
title: t("Icon paint properties"),
|
||||||
|
id: "Icon_paint_properties",
|
||||||
|
type: "properties",
|
||||||
|
fields: Object.keys(v8["paint_symbol"]).filter(f => f.startsWith("icon-"))
|
||||||
|
});
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLayoutForType(type: LayerSpecification["type"], t: TFunction): MaputnikLayoutGroup[] {
|
||||||
|
if (Object.keys(v8.layer.type.values).indexOf(type) < 0) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
if (type === "symbol") {
|
||||||
|
return getLayoutForSymbolType(t);
|
||||||
|
}
|
||||||
|
const groups: MaputnikLayoutGroup[] = [];
|
||||||
|
if (Object.keys(v8["paint_" + type]).length > 0) {
|
||||||
|
groups.push({
|
||||||
|
title: t("Paint properties"),
|
||||||
|
id: "Paint_properties",
|
||||||
|
type: "properties",
|
||||||
|
fields: Object.keys(v8["paint_" + type]),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (Object.keys(v8["layout_" + type]).length > 0) {
|
||||||
|
groups.push({
|
||||||
|
title: t("Layout properties"),
|
||||||
|
id: "Layout_properties",
|
||||||
|
type: "properties",
|
||||||
|
fields: Object.keys(v8["layout_" + type])
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
function layoutGroups(layerType: LayerSpecification["type"], t: TFunction): {id: string, title: string, type: string, fields?: string[]}[] {
|
function layoutGroups(layerType: LayerSpecification["type"], t: TFunction): {id: string, title: string, type: string, fields?: string[]}[] {
|
||||||
@@ -53,18 +110,18 @@ function layoutGroups(layerType: LayerSpecification["type"], t: TFunction): {id:
|
|||||||
type: 'jsoneditor'
|
type: 'jsoneditor'
|
||||||
}
|
}
|
||||||
return [layerGroup, filterGroup]
|
return [layerGroup, filterGroup]
|
||||||
.concat(getLayoutForType(layerType, t).groups)
|
.concat(getLayoutForType(layerType, t))
|
||||||
.concat([editorGroup])
|
.concat([editorGroup])
|
||||||
}
|
}
|
||||||
|
|
||||||
type LayerEditorInternalProps = {
|
type LayerEditorInternalProps = {
|
||||||
layer: LayerSpecification
|
layer: LayerSpecification
|
||||||
sources: {[key: string]: SourceSpecification}
|
sources: {[key: string]: SourceSpecification & {layers: string[]}}
|
||||||
vectorLayers: {[key: string]: any}
|
vectorLayers: {[key: string]: any}
|
||||||
spec: object
|
spec: object
|
||||||
onLayerChanged(...args: unknown[]): unknown
|
onLayerChanged(...args: unknown[]): unknown
|
||||||
onLayerIdChange(...args: unknown[]): unknown
|
onLayerIdChange(...args: unknown[]): unknown
|
||||||
onMoveLayer(...args: unknown[]): unknown
|
onMoveLayer: OnMoveLayerCallback
|
||||||
onLayerDestroy(...args: unknown[]): unknown
|
onLayerDestroy(...args: unknown[]): unknown
|
||||||
onLayerCopy(...args: unknown[]): unknown
|
onLayerCopy(...args: unknown[]): unknown
|
||||||
onLayerVisibilityToggle(...args: unknown[]): unknown
|
onLayerVisibilityToggle(...args: unknown[]): unknown
|
||||||
@@ -86,18 +143,13 @@ class LayerEditorInternal extends React.Component<LayerEditorInternalProps, Laye
|
|||||||
onLayerDestroyed: () => {},
|
onLayerDestroyed: () => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
static childContextTypes = {
|
|
||||||
reactIconBase: PropTypes.object
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(props: LayerEditorInternalProps) {
|
constructor(props: LayerEditorInternalProps) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
//TODO: Clean this up and refactor into function
|
|
||||||
const editorGroups: {[keys:string]: boolean} = {}
|
const editorGroups: {[keys:string]: boolean} = {}
|
||||||
layoutGroups(this.props.layer.type, props.t).forEach(group => {
|
for (const group of layoutGroups(this.props.layer.type, props.t)) {
|
||||||
editorGroups[group.title] = true
|
editorGroups[group.title] = true
|
||||||
})
|
}
|
||||||
|
|
||||||
this.state = { editorGroups }
|
this.state = { editorGroups }
|
||||||
}
|
}
|
||||||
@@ -105,25 +157,17 @@ class LayerEditorInternal extends React.Component<LayerEditorInternalProps, Laye
|
|||||||
static getDerivedStateFromProps(props: Readonly<LayerEditorInternalProps>, state: LayerEditorState) {
|
static getDerivedStateFromProps(props: Readonly<LayerEditorInternalProps>, state: LayerEditorState) {
|
||||||
const additionalGroups = { ...state.editorGroups }
|
const additionalGroups = { ...state.editorGroups }
|
||||||
|
|
||||||
getLayoutForType(props.layer.type, props.t).groups.forEach(group => {
|
for (const group of getLayoutForType(props.layer.type, props.t)) {
|
||||||
if(!(group.title in additionalGroups)) {
|
if(!(group.title in additionalGroups)) {
|
||||||
additionalGroups[group.title] = true
|
additionalGroups[group.title] = true
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
editorGroups: additionalGroups
|
editorGroups: additionalGroups
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getChildContext () {
|
|
||||||
return {
|
|
||||||
reactIconBase: {
|
|
||||||
size: 14,
|
|
||||||
color: '#8e8e8e',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
changeProperty(group: keyof LayerSpecification | null, property: string, newValue: any) {
|
changeProperty(group: keyof LayerSpecification | null, property: string, newValue: any) {
|
||||||
this.props.onLayerChanged(
|
this.props.onLayerChanged(
|
||||||
@@ -165,7 +209,7 @@ class LayerEditorInternal extends React.Component<LayerEditorInternalProps, Laye
|
|||||||
let sourceLayerIds;
|
let sourceLayerIds;
|
||||||
const layer = this.props.layer as Exclude<LayerSpecification, BackgroundLayerSpecification>;
|
const layer = this.props.layer as Exclude<LayerSpecification, BackgroundLayerSpecification>;
|
||||||
if(Object.prototype.hasOwnProperty.call(this.props.sources, layer.source)) {
|
if(Object.prototype.hasOwnProperty.call(this.props.sources, layer.source)) {
|
||||||
sourceLayerIds = (this.props.sources[layer.source] as any).layers;
|
sourceLayerIds = this.props.sources[layer.source].layers;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
@@ -192,7 +236,7 @@ class LayerEditorInternal extends React.Component<LayerEditorInternalProps, Laye
|
|||||||
onChange={v => this.changeProperty(null, 'source', v)}
|
onChange={v => this.changeProperty(null, 'source', v)}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
{['background', 'raster', 'hillshade', 'heatmap'].indexOf(this.props.layer.type) < 0 &&
|
{!NON_SOURCE_LAYERS.includes(this.props.layer.type) &&
|
||||||
<FieldSourceLayer
|
<FieldSourceLayer
|
||||||
error={errorData['source-layer']}
|
error={errorData['source-layer']}
|
||||||
sourceLayerIds={sourceLayerIds}
|
sourceLayerIds={sourceLayerIds}
|
||||||
@@ -279,30 +323,38 @@ class LayerEditorInternal extends React.Component<LayerEditorInternalProps, Laye
|
|||||||
|
|
||||||
const layout = this.props.layer.layout || {}
|
const layout = this.props.layer.layout || {}
|
||||||
|
|
||||||
const items: {[key: string]: {text: string, handler: () => void, disabled?: boolean}} = {
|
const items: {[key: string]: {
|
||||||
|
text: string,
|
||||||
|
handler: () => void,
|
||||||
|
disabled?: boolean,
|
||||||
|
wdKey?: string
|
||||||
|
}} = {
|
||||||
delete: {
|
delete: {
|
||||||
text: t("Delete"),
|
text: t("Delete"),
|
||||||
handler: () => this.props.onLayerDestroy(this.props.layerIndex)
|
handler: () => this.props.onLayerDestroy(this.props.layerIndex),
|
||||||
|
wdKey: "menu-delete-layer"
|
||||||
},
|
},
|
||||||
duplicate: {
|
duplicate: {
|
||||||
text: t("Duplicate"),
|
text: t("Duplicate"),
|
||||||
handler: () => this.props.onLayerCopy(this.props.layerIndex)
|
handler: () => this.props.onLayerCopy(this.props.layerIndex),
|
||||||
|
wdKey: "menu-duplicate-layer"
|
||||||
},
|
},
|
||||||
hide: {
|
hide: {
|
||||||
text: (layout.visibility === "none") ? t("Show") : t("Hide"),
|
text: (layout.visibility === "none") ? t("Show") : t("Hide"),
|
||||||
handler: () => this.props.onLayerVisibilityToggle(this.props.layerIndex)
|
handler: () => this.props.onLayerVisibilityToggle(this.props.layerIndex),
|
||||||
|
wdKey: "menu-hide-layer"
|
||||||
},
|
},
|
||||||
moveLayerUp: {
|
moveLayerUp: {
|
||||||
text: t("Move layer up"),
|
text: t("Move layer up"),
|
||||||
// Not actually used...
|
|
||||||
disabled: this.props.isFirstLayer,
|
disabled: this.props.isFirstLayer,
|
||||||
handler: () => this.moveLayer(-1)
|
handler: () => this.moveLayer(-1),
|
||||||
|
wdKey: "menu-move-layer-up"
|
||||||
},
|
},
|
||||||
moveLayerDown: {
|
moveLayerDown: {
|
||||||
text: t("Move layer down"),
|
text: t("Move layer down"),
|
||||||
// Not actually used...
|
|
||||||
disabled: this.props.isLastLayer,
|
disabled: this.props.isLastLayer,
|
||||||
handler: () => this.moveLayer(+1)
|
handler: () => this.moveLayer(+1),
|
||||||
|
wdKey: "menu-move-layer-down"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,53 +363,55 @@ class LayerEditorInternal extends React.Component<LayerEditorInternalProps, Laye
|
|||||||
items[id].handler();
|
items[id].handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
return <section className="maputnik-layer-editor"
|
return <IconContext.Provider value={{size: '14px', color: '#8e8e8e'}}>
|
||||||
role="main"
|
<section className="maputnik-layer-editor"
|
||||||
aria-label={t("Layer editor")}
|
role="main"
|
||||||
>
|
aria-label={t("Layer editor")}
|
||||||
<header>
|
|
||||||
<div className="layer-header">
|
|
||||||
<h2 className="layer-header__title">
|
|
||||||
{t("Layer: {{layerId}}", { layerId: formatLayerId(this.props.layer.id) })}
|
|
||||||
</h2>
|
|
||||||
<div className="layer-header__info">
|
|
||||||
<Wrapper
|
|
||||||
className='more-menu'
|
|
||||||
onSelection={handleSelection}
|
|
||||||
closeOnSelection={false}
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
id="skip-target-layer-editor"
|
|
||||||
data-wd-key="skip-target-layer-editor"
|
|
||||||
className='more-menu__button'
|
|
||||||
title={"Layer options"}>
|
|
||||||
<MdMoreVert className="more-menu__button__svg" />
|
|
||||||
</Button>
|
|
||||||
<Menu>
|
|
||||||
<ul className="more-menu__menu">
|
|
||||||
{Object.keys(items).map((id) => {
|
|
||||||
const item = items[id];
|
|
||||||
return <li key={id}>
|
|
||||||
<MenuItem value={id} className='more-menu__menu__item'>
|
|
||||||
{item.text}
|
|
||||||
</MenuItem>
|
|
||||||
</li>
|
|
||||||
})}
|
|
||||||
</ul>
|
|
||||||
</Menu>
|
|
||||||
</Wrapper>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</header>
|
|
||||||
<Accordion
|
|
||||||
allowMultipleExpanded={true}
|
|
||||||
allowZeroExpanded={true}
|
|
||||||
preExpanded={groupIds}
|
|
||||||
>
|
>
|
||||||
{groups}
|
<header>
|
||||||
</Accordion>
|
<div className="layer-header">
|
||||||
</section>
|
<h2 className="layer-header__title">
|
||||||
|
{t("Layer: {{layerId}}", { layerId: formatLayerId(this.props.layer.id) })}
|
||||||
|
</h2>
|
||||||
|
<div className="layer-header__info">
|
||||||
|
<Wrapper
|
||||||
|
className='more-menu'
|
||||||
|
onSelection={handleSelection}
|
||||||
|
closeOnSelection={false}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
id="skip-target-layer-editor"
|
||||||
|
data-wd-key="skip-target-layer-editor"
|
||||||
|
className='more-menu__button'
|
||||||
|
title={"Layer options"}>
|
||||||
|
<MdMoreVert className="more-menu__button__svg" />
|
||||||
|
</Button>
|
||||||
|
<Menu>
|
||||||
|
<ul className="more-menu__menu">
|
||||||
|
{Object.keys(items).map((id) => {
|
||||||
|
const item = items[id];
|
||||||
|
return <li key={id}>
|
||||||
|
<MenuItem value={id} className='more-menu__menu__item' data-wd-key={item.wdKey}>
|
||||||
|
{item.text}
|
||||||
|
</MenuItem>
|
||||||
|
</li>
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
</Menu>
|
||||||
|
</Wrapper>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</header>
|
||||||
|
<Accordion
|
||||||
|
allowMultipleExpanded={true}
|
||||||
|
allowZeroExpanded={true}
|
||||||
|
preExpanded={groupIds}
|
||||||
|
>
|
||||||
|
{groups}
|
||||||
|
</Accordion>
|
||||||
|
</section>
|
||||||
|
</IconContext.Provider>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,28 @@
|
|||||||
import React, {type JSX} from 'react'
|
import React, {type JSX} from 'react'
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
|
import {
|
||||||
|
DndContext,
|
||||||
|
PointerSensor,
|
||||||
|
useSensor,
|
||||||
|
useSensors,
|
||||||
|
closestCenter,
|
||||||
|
DragEndEvent,
|
||||||
|
} from '@dnd-kit/core';
|
||||||
|
import {
|
||||||
|
SortableContext,
|
||||||
|
verticalListSortingStrategy,
|
||||||
|
} from '@dnd-kit/sortable';
|
||||||
|
|
||||||
import LayerListGroup from './LayerListGroup'
|
import LayerListGroup from './LayerListGroup'
|
||||||
import LayerListItem from './LayerListItem'
|
import LayerListItem from './LayerListItem'
|
||||||
import ModalAdd from './ModalAdd'
|
import ModalAdd from './ModalAdd'
|
||||||
|
|
||||||
import {SortEndHandler, SortableContainer} from 'react-sortable-hoc';
|
import type {LayerSpecification, SourceSpecification} from 'maplibre-gl';
|
||||||
import type {LayerSpecification} from 'maplibre-gl';
|
|
||||||
import generateUniqueId from '../libs/document-uid';
|
import generateUniqueId from '../libs/document-uid';
|
||||||
import { findClosestCommonPrefix, layerPrefix } from '../libs/layer';
|
import { findClosestCommonPrefix, layerPrefix } from '../libs/layer';
|
||||||
import { WithTranslation, withTranslation } from 'react-i18next';
|
import { WithTranslation, withTranslation } from 'react-i18next';
|
||||||
|
import { OnMoveLayerCallback } from '../libs/definitions';
|
||||||
|
|
||||||
type LayerListContainerProps = {
|
type LayerListContainerProps = {
|
||||||
layers: LayerSpecification[]
|
layers: LayerSpecification[]
|
||||||
@@ -20,7 +32,7 @@ type LayerListContainerProps = {
|
|||||||
onLayerDestroy?(...args: unknown[]): unknown
|
onLayerDestroy?(...args: unknown[]): unknown
|
||||||
onLayerCopy(...args: unknown[]): unknown
|
onLayerCopy(...args: unknown[]): unknown
|
||||||
onLayerVisibilityToggle(...args: unknown[]): unknown
|
onLayerVisibilityToggle(...args: unknown[]): unknown
|
||||||
sources: object
|
sources: Record<string, SourceSpecification & {layers: string[]}>;
|
||||||
errors: any[]
|
errors: any[]
|
||||||
};
|
};
|
||||||
type LayerListContainerInternalProps = LayerListContainerProps & WithTranslation;
|
type LayerListContainerInternalProps = LayerListContainerProps & WithTranslation;
|
||||||
@@ -242,7 +254,6 @@ class LayerListContainerInternal extends React.Component<LayerListContainerInter
|
|||||||
'maputnik-layer-list-item-group-last': idxInGroup == layers.length - 1 && layers.length > 1,
|
'maputnik-layer-list-item-group-last': idxInGroup == layers.length - 1 && layers.length > 1,
|
||||||
'maputnik-layer-list-item--error': !!layerError
|
'maputnik-layer-list-item--error': !!layerError
|
||||||
})}
|
})}
|
||||||
index={idx}
|
|
||||||
key={layer.key}
|
key={layer.key}
|
||||||
id={layer.key}
|
id={layer.key}
|
||||||
layerId={layer.id}
|
layerId={layer.id}
|
||||||
@@ -319,20 +330,35 @@ class LayerListContainerInternal extends React.Component<LayerListContainerInter
|
|||||||
}
|
}
|
||||||
|
|
||||||
const LayerListContainer = withTranslation()(LayerListContainerInternal);
|
const LayerListContainer = withTranslation()(LayerListContainerInternal);
|
||||||
const LayerListContainerSortable = SortableContainer((props: LayerListContainerProps) => <LayerListContainer {...props} />)
|
|
||||||
|
|
||||||
type LayerListProps = LayerListContainerProps & {
|
type LayerListProps = LayerListContainerProps & {
|
||||||
onMoveLayer: SortEndHandler
|
onMoveLayer: OnMoveLayerCallback
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class LayerList extends React.Component<LayerListProps> {
|
const LayerList: React.FC<LayerListProps> = (props) => {
|
||||||
render() {
|
const sensors = useSensors(useSensor(PointerSensor));
|
||||||
return <LayerListContainerSortable
|
|
||||||
{...this.props}
|
const handleDragEnd = (event: DragEndEvent) => {
|
||||||
helperClass='sortableHelper'
|
const {active, over} = event;
|
||||||
onSortEnd={this.props.onMoveLayer.bind(this)}
|
if (!over) return;
|
||||||
useDragHandle={true}
|
|
||||||
shouldCancelStart={() => false}
|
const oldIndex = props.layers.findIndex(layer => layer.id === active.id);
|
||||||
/>
|
const newIndex = props.layers.findIndex(layer => layer.id === over.id);
|
||||||
}
|
|
||||||
|
if (oldIndex !== -1 && newIndex !== -1 && oldIndex !== newIndex) {
|
||||||
|
props.onMoveLayer({oldIndex, newIndex});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const layerIds = props.layers.map(layer => layer.id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
|
||||||
|
<SortableContext items={layerIds} strategy={verticalListSortingStrategy}>
|
||||||
|
<LayerListContainer {...props} />
|
||||||
|
</SortableContext>
|
||||||
|
</DndContext>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default LayerList;
|
||||||
|
|||||||
@@ -1,20 +1,23 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
import classnames from 'classnames'
|
import classnames from 'classnames'
|
||||||
|
|
||||||
import {MdContentCopy, MdVisibility, MdVisibilityOff, MdDelete} from 'react-icons/md'
|
import {MdContentCopy, MdVisibility, MdVisibilityOff, MdDelete} from 'react-icons/md'
|
||||||
|
import { IconContext } from 'react-icons'
|
||||||
|
import {useSortable} from '@dnd-kit/sortable'
|
||||||
|
import {CSS} from '@dnd-kit/utilities'
|
||||||
|
|
||||||
import IconLayer from './IconLayer'
|
import IconLayer from './IconLayer'
|
||||||
import {SortableElement, SortableHandle} from 'react-sortable-hoc'
|
|
||||||
|
|
||||||
|
|
||||||
type DraggableLabelProps = {
|
type DraggableLabelProps = {
|
||||||
layerId: string
|
layerId: string
|
||||||
layerType: string
|
layerType: string
|
||||||
|
dragAttributes?: React.HTMLAttributes<HTMLElement>
|
||||||
|
dragListeners?: React.HTMLAttributes<HTMLElement>
|
||||||
};
|
};
|
||||||
|
|
||||||
const DraggableLabel = SortableHandle((props: DraggableLabelProps) => {
|
const DraggableLabel: React.FC<DraggableLabelProps> = (props) => {
|
||||||
return <div className="maputnik-layer-list-item-handle">
|
const {dragAttributes, dragListeners} = props;
|
||||||
|
return <div className="maputnik-layer-list-item-handle" {...dragAttributes} {...dragListeners}>
|
||||||
<IconLayer
|
<IconLayer
|
||||||
className="layer-handle__icon"
|
className="layer-handle__icon"
|
||||||
type={props.layerType}
|
type={props.layerType}
|
||||||
@@ -23,7 +26,7 @@ const DraggableLabel = SortableHandle((props: DraggableLabelProps) => {
|
|||||||
{props.layerId}
|
{props.layerId}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
});
|
};
|
||||||
|
|
||||||
type IconActionProps = {
|
type IconActionProps = {
|
||||||
action: string
|
action: string
|
||||||
@@ -82,63 +85,80 @@ type LayerListItemProps = {
|
|||||||
onLayerVisibilityToggle?(...args: unknown[]): unknown
|
onLayerVisibilityToggle?(...args: unknown[]): unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
class LayerListItem extends React.Component<LayerListItemProps> {
|
const LayerListItem = React.forwardRef<HTMLLIElement, LayerListItemProps>((props, ref) => {
|
||||||
static defaultProps = {
|
const {
|
||||||
isSelected: false,
|
isSelected = false,
|
||||||
visibility: 'visible',
|
visibility = 'visible',
|
||||||
onLayerCopy: () => {},
|
onLayerCopy = () => {},
|
||||||
onLayerDestroy: () => {},
|
onLayerDestroy = () => {},
|
||||||
onLayerVisibilityToggle: () => {},
|
onLayerVisibilityToggle = () => {},
|
||||||
}
|
} = props;
|
||||||
|
|
||||||
static childContextTypes = {
|
const {
|
||||||
reactIconBase: PropTypes.object
|
attributes,
|
||||||
}
|
listeners,
|
||||||
|
setNodeRef,
|
||||||
|
transform,
|
||||||
|
transition,
|
||||||
|
isDragging,
|
||||||
|
} = useSortable({id: props.layerId});
|
||||||
|
|
||||||
getChildContext() {
|
const style = {
|
||||||
return {
|
transform: CSS.Transform.toString(transform),
|
||||||
reactIconBase: { size: 14 }
|
transition,
|
||||||
}
|
opacity: isDragging ? 0.5 : 1,
|
||||||
}
|
};
|
||||||
|
|
||||||
render() {
|
const visibilityAction = visibility === 'visible' ? 'show' : 'hide';
|
||||||
const visibilityAction = this.props.visibility === 'visible' ? 'show' : 'hide';
|
|
||||||
|
|
||||||
return <li
|
// Cast ref to MutableRefObject since we know from the codebase that's what's always passed
|
||||||
id={this.props.id}
|
const refObject = ref as React.MutableRefObject<HTMLLIElement | null> | null;
|
||||||
key={this.props.layerId}
|
|
||||||
onClick={_e => this.props.onLayerSelect(this.props.layerIndex)}
|
return <IconContext.Provider value={{size: '14px'}}>
|
||||||
data-wd-key={"layer-list-item:"+this.props.layerId}
|
<li
|
||||||
|
ref={(node) => {
|
||||||
|
setNodeRef(node);
|
||||||
|
if (refObject) {
|
||||||
|
refObject.current = node;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
style={style}
|
||||||
|
id={props.id}
|
||||||
|
onClick={_e => props.onLayerSelect(props.layerIndex)}
|
||||||
|
data-wd-key={"layer-list-item:" + props.layerId}
|
||||||
className={classnames({
|
className={classnames({
|
||||||
"maputnik-layer-list-item": true,
|
"maputnik-layer-list-item": true,
|
||||||
"maputnik-layer-list-item-selected": this.props.isSelected,
|
"maputnik-layer-list-item-selected": isSelected,
|
||||||
[this.props.className!]: true,
|
[props.className!]: true,
|
||||||
})}>
|
})}>
|
||||||
<DraggableLabel {...this.props} />
|
<DraggableLabel
|
||||||
|
layerId={props.layerId}
|
||||||
|
layerType={props.layerType}
|
||||||
|
dragAttributes={attributes}
|
||||||
|
dragListeners={listeners}
|
||||||
|
/>
|
||||||
<span style={{flexGrow: 1}} />
|
<span style={{flexGrow: 1}} />
|
||||||
<IconAction
|
<IconAction
|
||||||
wdKey={"layer-list-item:"+this.props.layerId+":delete"}
|
wdKey={"layer-list-item:" + props.layerId+":delete"}
|
||||||
action={'delete'}
|
action={'delete'}
|
||||||
classBlockName="delete"
|
classBlockName="delete"
|
||||||
onClick={_e => this.props.onLayerDestroy!(this.props.layerIndex)}
|
onClick={_e => onLayerDestroy!(props.layerIndex)}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
wdKey={"layer-list-item:"+this.props.layerId+":copy"}
|
wdKey={"layer-list-item:" + props.layerId+":copy"}
|
||||||
action={'duplicate'}
|
action={'duplicate'}
|
||||||
classBlockName="duplicate"
|
classBlockName="duplicate"
|
||||||
onClick={_e => this.props.onLayerCopy!(this.props.layerIndex)}
|
onClick={_e => onLayerCopy!(props.layerIndex)}
|
||||||
/>
|
/>
|
||||||
<IconAction
|
<IconAction
|
||||||
wdKey={"layer-list-item:"+this.props.layerId+":toggle-visibility"}
|
wdKey={"layer-list-item:"+props.layerId+":toggle-visibility"}
|
||||||
action={visibilityAction}
|
action={visibilityAction}
|
||||||
classBlockName="visibility"
|
classBlockName="visibility"
|
||||||
classBlockModifier={visibilityAction}
|
classBlockModifier={visibilityAction}
|
||||||
onClick={_e => this.props.onLayerVisibilityToggle!(this.props.layerIndex)}
|
onClick={_e => onLayerVisibilityToggle!(props.layerIndex)}
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
}
|
</IconContext.Provider>
|
||||||
}
|
});
|
||||||
|
|
||||||
const LayerListItemSortable = SortableElement<LayerListItemProps>((props: LayerListItemProps) => <LayerListItem {...props} />);
|
export default LayerListItem;
|
||||||
|
|
||||||
export default LayerListItemSortable;
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, {type JSX} from 'react'
|
import React, {type JSX} from 'react'
|
||||||
import ReactDOM from 'react-dom'
|
import {createRoot} from 'react-dom/client'
|
||||||
import MapLibreGl, {LayerSpecification, LngLat, Map, MapOptions, SourceSpecification, StyleSpecification} from 'maplibre-gl'
|
import MapLibreGl, {LayerSpecification, LngLat, Map, MapOptions, SourceSpecification, StyleSpecification} from 'maplibre-gl'
|
||||||
import MaplibreInspect from '@maplibre/maplibre-gl-inspect'
|
import MaplibreInspect from '@maplibre/maplibre-gl-inspect'
|
||||||
import colors from '@maplibre/maplibre-gl-inspect/lib/colors'
|
import colors from '@maplibre/maplibre-gl-inspect/lib/colors'
|
||||||
@@ -17,8 +17,14 @@ import { withTranslation, WithTranslation } from 'react-i18next'
|
|||||||
import i18next from 'i18next'
|
import i18next from 'i18next'
|
||||||
import { Protocol } from "pmtiles";
|
import { Protocol } from "pmtiles";
|
||||||
|
|
||||||
function renderPopup(popup: JSX.Element, mountNode: ReactDOM.Container): HTMLElement {
|
function renderPopup(
|
||||||
ReactDOM.render(popup, mountNode);
|
popupElement: JSX.Element,
|
||||||
|
mountNode: HTMLElement,
|
||||||
|
popup: MapLibreGl.Popup
|
||||||
|
): HTMLElement {
|
||||||
|
const root = createRoot(mountNode);
|
||||||
|
popup.once('close', () => root.unmount());
|
||||||
|
root.render(popupElement);
|
||||||
return mountNode as HTMLElement;
|
return mountNode as HTMLElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,10 +180,12 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
|
|||||||
|
|
||||||
const tmpNode = document.createElement('div');
|
const tmpNode = document.createElement('div');
|
||||||
|
|
||||||
|
const inspectPopup = new MapLibreGl.Popup({
|
||||||
|
closeOnClick: false
|
||||||
|
});
|
||||||
|
|
||||||
const inspect = new MaplibreInspect({
|
const inspect = new MaplibreInspect({
|
||||||
popup: new MapLibreGl.Popup({
|
popup: inspectPopup,
|
||||||
closeOnClick: false
|
|
||||||
}),
|
|
||||||
showMapPopup: true,
|
showMapPopup: true,
|
||||||
showMapPopupOnHover: false,
|
showMapPopupOnHover: false,
|
||||||
showInspectMapPopupOnHover: true,
|
showInspectMapPopupOnHover: true,
|
||||||
@@ -189,9 +197,21 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
|
|||||||
buildInspectStyle: (originalMapStyle: StyleSpecification, coloredLayers: HighlightedLayer[]) => buildInspectStyle(originalMapStyle, coloredLayers, this.props.highlightedLayer),
|
buildInspectStyle: (originalMapStyle: StyleSpecification, coloredLayers: HighlightedLayer[]) => buildInspectStyle(originalMapStyle, coloredLayers, this.props.highlightedLayer),
|
||||||
renderPopup: (features: InspectFeature[]) => {
|
renderPopup: (features: InspectFeature[]) => {
|
||||||
if(this.props.inspectModeEnabled) {
|
if(this.props.inspectModeEnabled) {
|
||||||
return renderPopup(<MapMaplibreGlFeaturePropertyPopup features={features} />, tmpNode);
|
return renderPopup(
|
||||||
|
<MapMaplibreGlFeaturePropertyPopup features={features} />,
|
||||||
|
tmpNode,
|
||||||
|
inspectPopup
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return renderPopup(<MapMaplibreGlLayerPopup features={features} onLayerSelect={this.onLayerSelectById} zoom={this.state.zoom} />, tmpNode);
|
return renderPopup(
|
||||||
|
<MapMaplibreGlLayerPopup
|
||||||
|
features={features}
|
||||||
|
onLayerSelect={this.onLayerSelectById}
|
||||||
|
zoom={this.state.zoom}
|
||||||
|
/>,
|
||||||
|
tmpNode,
|
||||||
|
inspectPopup
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
+56
-42
@@ -6,8 +6,9 @@ import FieldType from './FieldType'
|
|||||||
import FieldId from './FieldId'
|
import FieldId from './FieldId'
|
||||||
import FieldSource from './FieldSource'
|
import FieldSource from './FieldSource'
|
||||||
import FieldSourceLayer from './FieldSourceLayer'
|
import FieldSourceLayer from './FieldSourceLayer'
|
||||||
import type {LayerSpecification} from 'maplibre-gl'
|
import type {LayerSpecification, SourceSpecification} from 'maplibre-gl'
|
||||||
import { WithTranslation, withTranslation } from 'react-i18next';
|
import { WithTranslation, withTranslation } from 'react-i18next';
|
||||||
|
import { NON_SOURCE_LAYERS } from '../libs/non-source-layers'
|
||||||
|
|
||||||
type ModalAddInternalProps = {
|
type ModalAddInternalProps = {
|
||||||
layers: LayerSpecification[]
|
layers: LayerSpecification[]
|
||||||
@@ -15,7 +16,7 @@ type ModalAddInternalProps = {
|
|||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
onOpenToggle(open: boolean): unknown
|
onOpenToggle(open: boolean): unknown
|
||||||
// A dict of source id's and the available source layers
|
// A dict of source id's and the available source layers
|
||||||
sources: any
|
sources: Record<string, SourceSpecification & {layers: string[]}>;
|
||||||
} & WithTranslation;
|
} & WithTranslation;
|
||||||
|
|
||||||
type ModalAddState = {
|
type ModalAddState = {
|
||||||
@@ -23,10 +24,16 @@ type ModalAddState = {
|
|||||||
id: string
|
id: string
|
||||||
source?: string
|
source?: string
|
||||||
'source-layer'?: string
|
'source-layer'?: string
|
||||||
|
error?: string | null
|
||||||
};
|
};
|
||||||
|
|
||||||
class ModalAddInternal extends React.Component<ModalAddInternalProps, ModalAddState> {
|
class ModalAddInternal extends React.Component<ModalAddInternalProps, ModalAddState> {
|
||||||
addLayer = () => {
|
addLayer = () => {
|
||||||
|
if (this.props.layers.some(l => l.id === this.state.id)) {
|
||||||
|
this.setState({ error: this.props.t('Layer ID already exists') })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const changedLayers = this.props.layers.slice(0)
|
const changedLayers = this.props.layers.slice(0)
|
||||||
const layer: ModalAddState = {
|
const layer: ModalAddState = {
|
||||||
id: this.state.id,
|
id: this.state.id,
|
||||||
@@ -35,15 +42,16 @@ class ModalAddInternal extends React.Component<ModalAddInternalProps, ModalAddSt
|
|||||||
|
|
||||||
if(this.state.type !== 'background') {
|
if(this.state.type !== 'background') {
|
||||||
layer.source = this.state.source
|
layer.source = this.state.source
|
||||||
if(this.state.type !== 'raster' && this.state['source-layer']) {
|
if(!NON_SOURCE_LAYERS.includes(this.state.type) && this.state['source-layer']) {
|
||||||
layer['source-layer'] = this.state['source-layer']
|
layer['source-layer'] = this.state['source-layer']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
changedLayers.push(layer as LayerSpecification)
|
changedLayers.push(layer as LayerSpecification)
|
||||||
|
this.setState({ error: null }, () => {
|
||||||
this.props.onLayersChange(changedLayers)
|
this.props.onLayersChange(changedLayers)
|
||||||
this.props.onOpenToggle(false)
|
this.props.onOpenToggle(false)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props: ModalAddInternalProps) {
|
constructor(props: ModalAddInternalProps) {
|
||||||
@@ -51,11 +59,15 @@ class ModalAddInternal extends React.Component<ModalAddInternalProps, ModalAddSt
|
|||||||
const state: ModalAddState = {
|
const state: ModalAddState = {
|
||||||
type: 'fill',
|
type: 'fill',
|
||||||
id: '',
|
id: '',
|
||||||
|
error: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
if(props.sources.length > 0) {
|
if(Object.keys(props.sources).length > 0) {
|
||||||
state.source = Object.keys(this.props.sources)[0];
|
state.source = Object.keys(this.props.sources)[0];
|
||||||
state['source-layer'] = this.props.sources[state.source as keyof ModalAddInternalProps["sources"]][0]
|
const sourceLayers = this.props.sources[state.source].layers || []
|
||||||
|
if (sourceLayers.length > 0) {
|
||||||
|
state['source-layer'] = sourceLayers[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
@@ -89,39 +101,26 @@ class ModalAddInternal extends React.Component<ModalAddInternalProps, ModalAddSt
|
|||||||
return sourceObj.layers || [];
|
return sourceObj.layers || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
getSources(type: string) {
|
getSources(type: LayerSpecification["type"]) {
|
||||||
const sources = [];
|
|
||||||
|
|
||||||
const types = {
|
switch(type) {
|
||||||
vector: [
|
case 'background':
|
||||||
"fill",
|
return [];
|
||||||
"line",
|
case 'hillshade':
|
||||||
"symbol",
|
case 'color-relief':
|
||||||
"circle",
|
return Object.entries(this.props.sources).filter(([_, v]) => v.type === 'raster-dem').map(([k, _]) => k);
|
||||||
"fill-extrusion",
|
case 'raster':
|
||||||
"heatmap"
|
return Object.entries(this.props.sources).filter(([_, v]) => v.type === 'raster').map(([k, _]) => k);
|
||||||
],
|
case 'heatmap':
|
||||||
raster: [
|
case 'circle':
|
||||||
"raster"
|
case 'fill':
|
||||||
],
|
case 'fill-extrusion':
|
||||||
geojson: [
|
case 'line':
|
||||||
"fill",
|
case 'symbol':
|
||||||
"line",
|
return Object.entries(this.props.sources).filter(([_, v]) => v.type === 'vector' || v.type === 'geojson').map(([k, _]) => k);
|
||||||
"symbol",
|
default:
|
||||||
"circle",
|
return [];
|
||||||
"fill-extrusion",
|
|
||||||
"heatmap"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(const [key, val] of Object.entries(this.props.sources) as any) {
|
|
||||||
const valType = val.type as keyof typeof types;
|
|
||||||
if(types[valType] && types[valType].indexOf(type) > -1) {
|
|
||||||
sources.push(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return sources;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,6 +128,21 @@ class ModalAddInternal extends React.Component<ModalAddInternalProps, ModalAddSt
|
|||||||
const t = this.props.t;
|
const t = this.props.t;
|
||||||
const sources = this.getSources(this.state.type);
|
const sources = this.getSources(this.state.type);
|
||||||
const layers = this.getLayersForSource(this.state.source!);
|
const layers = this.getLayersForSource(this.state.source!);
|
||||||
|
let errorElement;
|
||||||
|
if (this.state.error) {
|
||||||
|
errorElement = (
|
||||||
|
<div className="maputnik-modal-error">
|
||||||
|
{this.state.error}
|
||||||
|
<a
|
||||||
|
href="#"
|
||||||
|
onClick={() => this.setState({ error: null })}
|
||||||
|
className="maputnik-modal-error-close"
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return <Modal
|
return <Modal
|
||||||
isOpen={this.props.isOpen}
|
isOpen={this.props.isOpen}
|
||||||
@@ -137,12 +151,13 @@ class ModalAddInternal extends React.Component<ModalAddInternalProps, ModalAddSt
|
|||||||
data-wd-key="modal:add-layer"
|
data-wd-key="modal:add-layer"
|
||||||
className="maputnik-add-modal"
|
className="maputnik-add-modal"
|
||||||
>
|
>
|
||||||
|
{errorElement}
|
||||||
<div className="maputnik-add-layer">
|
<div className="maputnik-add-layer">
|
||||||
<FieldId
|
<FieldId
|
||||||
value={this.state.id}
|
value={this.state.id}
|
||||||
wdKey="add-layer.layer-id"
|
wdKey="add-layer.layer-id"
|
||||||
onChange={(v: string) => {
|
onChange={(v: string) => {
|
||||||
this.setState({ id: v })
|
this.setState({ id: v, error: null })
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<FieldType
|
<FieldType
|
||||||
@@ -158,9 +173,8 @@ class ModalAddInternal extends React.Component<ModalAddInternalProps, ModalAddSt
|
|||||||
onChange={(v: string) => this.setState({ source: v })}
|
onChange={(v: string) => this.setState({ source: v })}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
{['background', 'raster', 'hillshade', 'heatmap'].indexOf(this.state.type) < 0 &&
|
{!NON_SOURCE_LAYERS.includes(this.state.type) &&
|
||||||
<FieldSourceLayer
|
<FieldSourceLayer
|
||||||
isFixed={true}
|
|
||||||
sourceLayerIds={layers}
|
sourceLayerIds={layers}
|
||||||
value={this.state['source-layer']}
|
value={this.state['source-layer']}
|
||||||
onChange={(v: string) => this.setState({ 'source-layer': v })}
|
onChange={(v: string) => this.setState({ 'source-layer': v })}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import Slugify from 'slugify'
|
|||||||
import {saveAs} from 'file-saver'
|
import {saveAs} from 'file-saver'
|
||||||
import {version} from 'maplibre-gl/package.json'
|
import {version} from 'maplibre-gl/package.json'
|
||||||
import {format} from '@maplibre/maplibre-gl-style-spec'
|
import {format} from '@maplibre/maplibre-gl-style-spec'
|
||||||
import type {StyleSpecification} from 'maplibre-gl'
|
|
||||||
import {MdMap, MdSave} from 'react-icons/md'
|
import {MdMap, MdSave} from 'react-icons/md'
|
||||||
import {WithTranslation, withTranslation} from 'react-i18next';
|
import {WithTranslation, withTranslation} from 'react-i18next';
|
||||||
|
|
||||||
@@ -12,6 +11,7 @@ import InputButton from './InputButton'
|
|||||||
import Modal from './Modal'
|
import Modal from './Modal'
|
||||||
import style from '../libs/style'
|
import style from '../libs/style'
|
||||||
import fieldSpecAdditional from '../libs/field-spec-additional'
|
import fieldSpecAdditional from '../libs/field-spec-additional'
|
||||||
|
import type {OnStyleChangedCallback, StyleSpecificationWithId} from '../libs/definitions'
|
||||||
|
|
||||||
|
|
||||||
const MAPLIBRE_GL_VERSION = version;
|
const MAPLIBRE_GL_VERSION = version;
|
||||||
@@ -19,8 +19,8 @@ const showSaveFilePickerAvailable = typeof window.showSaveFilePicker === "functi
|
|||||||
|
|
||||||
|
|
||||||
type ModalExportInternalProps = {
|
type ModalExportInternalProps = {
|
||||||
mapStyle: StyleSpecification & { id: string }
|
mapStyle: StyleSpecificationWithId
|
||||||
onStyleChanged(...args: unknown[]): unknown
|
onStyleChanged: OnStyleChangedCallback
|
||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
onOpenToggle(...args: unknown[]): unknown
|
onOpenToggle(...args: unknown[]): unknown
|
||||||
onSetFileHandle(fileHandle: FileSystemFileHandle | null): unknown
|
onSetFileHandle(fileHandle: FileSystemFileHandle | null): unknown
|
||||||
@@ -186,6 +186,12 @@ class ModalExportInternal extends React.Component<ModalExportInternalProps> {
|
|||||||
value={(this.props.mapStyle.metadata || {} as any)['maputnik:stadia_access_token']}
|
value={(this.props.mapStyle.metadata || {} as any)['maputnik:stadia_access_token']}
|
||||||
onChange={this.changeMetadataProperty.bind(this, "maputnik:stadia_access_token")}
|
onChange={this.changeMetadataProperty.bind(this, "maputnik:stadia_access_token")}
|
||||||
/>
|
/>
|
||||||
|
<FieldString
|
||||||
|
label={fsa.maputnik.locationiq_access_token.label}
|
||||||
|
fieldSpec={fsa.maputnik.locationiq_access_token}
|
||||||
|
value={(this.props.mapStyle.metadata || {} as any)['maputnik:locationiq_access_token']}
|
||||||
|
onChange={this.changeMetadataProperty.bind(this, "maputnik:locationiq_access_token")}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="maputnik-modal-export-buttons">
|
<div className="maputnik-modal-export-buttons">
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ import FieldEnum from './FieldEnum'
|
|||||||
import FieldColor from './FieldColor'
|
import FieldColor from './FieldColor'
|
||||||
import Modal from './Modal'
|
import Modal from './Modal'
|
||||||
import fieldSpecAdditional from '../libs/field-spec-additional'
|
import fieldSpecAdditional from '../libs/field-spec-additional'
|
||||||
|
import type {OnStyleChangedCallback, StyleSpecificationWithId} from '../libs/definitions';
|
||||||
|
|
||||||
type ModalSettingsInternalProps = {
|
type ModalSettingsInternalProps = {
|
||||||
mapStyle: StyleSpecification
|
mapStyle: StyleSpecificationWithId
|
||||||
onStyleChanged(...args: unknown[]): unknown
|
onStyleChanged: OnStyleChangedCallback
|
||||||
onChangeMetadataProperty(...args: unknown[]): unknown
|
onChangeMetadataProperty(...args: unknown[]): unknown
|
||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
onOpenToggle(...args: unknown[]): unknown
|
onOpenToggle(...args: unknown[]): unknown
|
||||||
@@ -62,7 +63,7 @@ class ModalSettingsInternal extends React.Component<ModalSettingsInternalProps>
|
|||||||
changeTerrainProperty(property: keyof TerrainSpecification, value: any) {
|
changeTerrainProperty(property: keyof TerrainSpecification, value: any) {
|
||||||
const terrain = {
|
const terrain = {
|
||||||
...this.props.mapStyle.terrain,
|
...this.props.mapStyle.terrain,
|
||||||
}
|
} as TerrainSpecification;
|
||||||
|
|
||||||
if (value === undefined) {
|
if (value === undefined) {
|
||||||
delete terrain[property];
|
delete terrain[property];
|
||||||
@@ -164,6 +165,14 @@ class ModalSettingsInternal extends React.Component<ModalSettingsInternalProps>
|
|||||||
onChange={onChangeMetadataProperty.bind(this, "maputnik:stadia_access_token")}
|
onChange={onChangeMetadataProperty.bind(this, "maputnik:stadia_access_token")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FieldString
|
||||||
|
label={fsa.maputnik.locationiq_access_token.label}
|
||||||
|
fieldSpec={fsa.maputnik.locationiq_access_token}
|
||||||
|
data-wd-key="modal:settings.maputnik:locationiq_access_token"
|
||||||
|
value={metadata['maputnik:locationiq_access_token']}
|
||||||
|
onChange={onChangeMetadataProperty.bind(this, "maputnik:locationiq_access_token")}
|
||||||
|
/>
|
||||||
|
|
||||||
<FieldArray
|
<FieldArray
|
||||||
label={t("Center")}
|
label={t("Center")}
|
||||||
fieldSpec={latest.$root.center}
|
fieldSpec={latest.$root.center}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {MdAddCircleOutline, MdDelete} from 'react-icons/md'
|
import {MdAddCircleOutline, MdDelete} from 'react-icons/md'
|
||||||
import latest from '@maplibre/maplibre-gl-style-spec/dist/latest.json'
|
import latest from '@maplibre/maplibre-gl-style-spec/dist/latest.json'
|
||||||
import type {GeoJSONSourceSpecification, RasterDEMSourceSpecification, RasterSourceSpecification, SourceSpecification, StyleSpecification, VectorSourceSpecification} from 'maplibre-gl'
|
import type {GeoJSONSourceSpecification, RasterDEMSourceSpecification, RasterSourceSpecification, SourceSpecification, VectorSourceSpecification} from 'maplibre-gl'
|
||||||
import { WithTranslation, withTranslation } from 'react-i18next';
|
import { WithTranslation, withTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import Modal from './Modal'
|
import Modal from './Modal'
|
||||||
@@ -13,6 +13,7 @@ import ModalSourcesTypeEditor, { EditorMode } from './ModalSourcesTypeEditor'
|
|||||||
import style from '../libs/style'
|
import style from '../libs/style'
|
||||||
import { deleteSource, addSource, changeSource } from '../libs/source'
|
import { deleteSource, addSource, changeSource } from '../libs/source'
|
||||||
import publicSources from '../config/tilesets.json'
|
import publicSources from '../config/tilesets.json'
|
||||||
|
import { OnStyleChangedCallback, StyleSpecificationWithId } from '../libs/definitions';
|
||||||
|
|
||||||
|
|
||||||
type PublicSourceProps = {
|
type PublicSourceProps = {
|
||||||
@@ -270,10 +271,10 @@ class AddSource extends React.Component<AddSourceProps, AddSourceState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ModalSourcesInternalProps = {
|
type ModalSourcesInternalProps = {
|
||||||
mapStyle: StyleSpecification
|
mapStyle: StyleSpecificationWithId
|
||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
onOpenToggle(...args: unknown[]): unknown
|
onOpenToggle(...args: unknown[]): unknown
|
||||||
onStyleChanged(...args: unknown[]): unknown
|
onStyleChanged: OnStyleChangedCallback
|
||||||
} & WithTranslation;
|
} & WithTranslation;
|
||||||
|
|
||||||
class ModalSourcesInternal extends React.Component<ModalSourcesInternalProps> {
|
class ModalSourcesInternal extends React.Component<ModalSourcesInternalProps> {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import React from 'react'
|
|
||||||
import Block from './Block'
|
import Block from './Block'
|
||||||
import InputSpec, { SpecFieldProps as InputFieldSpecProps } from './InputSpec'
|
import InputSpec, { SpecFieldProps as InputFieldSpecProps } from './InputSpec'
|
||||||
import Fieldset from './Fieldset'
|
import Fieldset from './Fieldset'
|
||||||
@@ -20,27 +19,25 @@ export type SpecFieldProps = InputFieldSpecProps & {
|
|||||||
name?: string
|
name?: string
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class SpecField extends React.Component<SpecFieldProps> {
|
const SpecField: React.FC<SpecFieldProps> = (props) => {
|
||||||
render() {
|
const fieldType = props.fieldSpec?.type;
|
||||||
const fieldType = this.props.fieldSpec?.type;
|
|
||||||
|
|
||||||
const typeBlockFn = typeMap[fieldType!];
|
const typeBlockFn = typeMap[fieldType!];
|
||||||
|
|
||||||
let TypeBlock;
|
let TypeBlock;
|
||||||
if (typeBlockFn) {
|
if (typeBlockFn) {
|
||||||
TypeBlock = typeBlockFn(this.props);
|
TypeBlock = typeBlockFn(props);
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.warn("No such type for '%s'", fieldType);
|
|
||||||
TypeBlock = Block;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <TypeBlock
|
|
||||||
label={this.props.label}
|
|
||||||
action={this.props.action}
|
|
||||||
fieldSpec={this.props.fieldSpec}
|
|
||||||
>
|
|
||||||
<InputSpec {...this.props} />
|
|
||||||
</TypeBlock>
|
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
console.warn("No such type for '%s'", fieldType);
|
||||||
|
TypeBlock = Block;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TypeBlock label={props.label} action={props.action} fieldSpec={props.fieldSpec}>
|
||||||
|
<InputSpec {...props} />
|
||||||
|
</TypeBlock>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SpecField;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class FunctionInputButtonsInternal extends React.Component<FunctionInputButtonsI
|
|||||||
const t = this.props.t;
|
const t = this.props.t;
|
||||||
let makeZoomInputButton, makeDataInputButton, expressionInputButton;
|
let makeZoomInputButton, makeDataInputButton, expressionInputButton;
|
||||||
|
|
||||||
if (this.props.fieldSpec.expression.parameters.includes('zoom')) {
|
if (this.props.fieldSpec.expression?.parameters.includes('zoom')) {
|
||||||
expressionInputButton = (
|
expressionInputButton = (
|
||||||
<InputButton
|
<InputButton
|
||||||
className="maputnik-make-zoom-function"
|
className="maputnik-make-zoom-function"
|
||||||
|
|||||||
@@ -1,240 +0,0 @@
|
|||||||
{
|
|
||||||
"line": {
|
|
||||||
"groups": [
|
|
||||||
{
|
|
||||||
"title": "Paint properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"line-opacity",
|
|
||||||
"line-color",
|
|
||||||
"line-width",
|
|
||||||
"line-offset",
|
|
||||||
"line-blur",
|
|
||||||
"line-dasharray",
|
|
||||||
"line-pattern",
|
|
||||||
"line-translate",
|
|
||||||
"line-translate-anchor",
|
|
||||||
"line-gap-width"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Layout properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"line-cap",
|
|
||||||
"line-join",
|
|
||||||
"line-miter-limit",
|
|
||||||
"line-round-limit"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"background": {
|
|
||||||
"groups": [
|
|
||||||
{
|
|
||||||
"title": "Paint properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"background-color",
|
|
||||||
"background-pattern",
|
|
||||||
"background-opacity"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"fill": {
|
|
||||||
"groups": [
|
|
||||||
{
|
|
||||||
"title": "Paint properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"fill-opacity",
|
|
||||||
"fill-color",
|
|
||||||
"fill-antialias",
|
|
||||||
"fill-outline-color",
|
|
||||||
"fill-pattern",
|
|
||||||
"fill-translate",
|
|
||||||
"fill-translate-anchor"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"fill-extrusion": {
|
|
||||||
"groups": [
|
|
||||||
{
|
|
||||||
"title": "Paint properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"fill-extrusion-opacity",
|
|
||||||
"fill-extrusion-color",
|
|
||||||
"fill-extrusion-translate",
|
|
||||||
"fill-extrusion-translate-anchor",
|
|
||||||
"fill-extrusion-pattern",
|
|
||||||
"fill-extrusion-height",
|
|
||||||
"fill-extrusion-base",
|
|
||||||
"fill-extrusion-vertical-gradient"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"circle": {
|
|
||||||
"groups": [
|
|
||||||
{
|
|
||||||
"title": "Paint properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"circle-color",
|
|
||||||
"circle-opacity",
|
|
||||||
"circle-stroke-color",
|
|
||||||
"circle-stroke-opacity",
|
|
||||||
"circle-blur",
|
|
||||||
"circle-radius",
|
|
||||||
"circle-stroke-width",
|
|
||||||
"circle-pitch-scale",
|
|
||||||
"circle-translate",
|
|
||||||
"circle-translate-anchor",
|
|
||||||
"circle-pitch-alignment"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"symbol": {
|
|
||||||
"groups": [
|
|
||||||
{
|
|
||||||
"title": "General layout properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"symbol-placement",
|
|
||||||
"symbol-spacing",
|
|
||||||
"symbol-avoid-edges",
|
|
||||||
"symbol-z-order"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Text layout properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"text-field",
|
|
||||||
"text-font",
|
|
||||||
"text-size",
|
|
||||||
"text-line-height",
|
|
||||||
"text-padding",
|
|
||||||
"text-allow-overlap",
|
|
||||||
"text-ignore-placement",
|
|
||||||
"text-pitch-alignment",
|
|
||||||
"text-rotation-alignment",
|
|
||||||
"text-max-width",
|
|
||||||
"text-letter-spacing",
|
|
||||||
"text-justify",
|
|
||||||
"text-anchor",
|
|
||||||
"text-max-angle",
|
|
||||||
"text-writing-mode",
|
|
||||||
"text-rotate",
|
|
||||||
"text-keep-upright",
|
|
||||||
"text-transform",
|
|
||||||
"text-offset",
|
|
||||||
"text-optional",
|
|
||||||
"text-variable-anchor",
|
|
||||||
"text-radial-offset"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Icon layout properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"icon-image",
|
|
||||||
"icon-allow-overlap",
|
|
||||||
"icon-ignore-placement",
|
|
||||||
"icon-optional",
|
|
||||||
"icon-rotation-alignment",
|
|
||||||
"icon-size",
|
|
||||||
"icon-text-fit",
|
|
||||||
"icon-text-fit-padding",
|
|
||||||
"icon-rotate",
|
|
||||||
"icon-padding",
|
|
||||||
"icon-keep-upright",
|
|
||||||
"icon-offset",
|
|
||||||
"icon-anchor",
|
|
||||||
"icon-pitch-alignment"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Text paint properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"text-color",
|
|
||||||
"text-opacity",
|
|
||||||
"text-halo-color",
|
|
||||||
"text-halo-width",
|
|
||||||
"text-halo-blur",
|
|
||||||
"text-translate",
|
|
||||||
"text-translate-anchor"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Icon paint properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"icon-color",
|
|
||||||
"icon-opacity",
|
|
||||||
"icon-halo-color",
|
|
||||||
"icon-halo-width",
|
|
||||||
"icon-halo-blur",
|
|
||||||
"icon-translate",
|
|
||||||
"icon-translate-anchor"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"raster": {
|
|
||||||
"groups": [
|
|
||||||
{
|
|
||||||
"title": "Paint properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"raster-opacity",
|
|
||||||
"raster-hue-rotate",
|
|
||||||
"raster-brightness-min",
|
|
||||||
"raster-brightness-max",
|
|
||||||
"raster-saturation",
|
|
||||||
"raster-contrast",
|
|
||||||
"raster-fade-duration",
|
|
||||||
"raster-resampling"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"hillshade": {
|
|
||||||
"groups": [
|
|
||||||
{
|
|
||||||
"title": "Paint properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"hillshade-illumination-direction",
|
|
||||||
"hillshade-illumination-anchor",
|
|
||||||
"hillshade-exaggeration",
|
|
||||||
"hillshade-shadow-color",
|
|
||||||
"hillshade-highlight-color",
|
|
||||||
"hillshade-accent-color"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"heatmap": {
|
|
||||||
"groups": [
|
|
||||||
{
|
|
||||||
"title": "Paint properties",
|
|
||||||
"type": "properties",
|
|
||||||
"fields": [
|
|
||||||
"heatmap-radius",
|
|
||||||
"heatmap-weight",
|
|
||||||
"heatmap-intensity",
|
|
||||||
"heatmap-opacity"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"invalid": {
|
|
||||||
"groups": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+18
-24
@@ -11,12 +11,30 @@
|
|||||||
"url": "https://americanamap.org/style.json",
|
"url": "https://americanamap.org/style.json",
|
||||||
"thumbnail": "https://github.com/maplibre/maputnik/assets/649392/23fa75ad-63e6-43f5-8837-03cdb0428bac"
|
"thumbnail": "https://github.com/maplibre/maputnik/assets/649392/23fa75ad-63e6-43f5-8837-03cdb0428bac"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "aws-hybrid",
|
||||||
|
"title": "AWS Hybrid",
|
||||||
|
"url": "https://maps.geo.eu-west-1.amazonaws.com/v2/styles/Hybrid/descriptor?key=v1.public.eyJqdGkiOiJiOTNkYjBlZi04OWUzLTQxMGUtODFhMC0zYjZjZjVmZWZmMDgifYtukap0NBaJpcrS6Vit9j03GJgK9Bn-RSu5UCe3jkdSql2kKp3IEgLPtyLssbmKUdVO11sXddjK3ZOZy8V6QG0olv0K_1tOxyMIe4DAO3IV6H4VzHWiaXlbSakGiEgFLuHBdcfLDeMotye7N6rSRxuZb0CN9ytH9VjLly6-NEBRZezO_qPQyvdTFdeZsARIpL0f9YVpxPxPVvUcAWYCk5LpaPseRCDPrY5SlCdA1ZKqUA4F9RzxSTxB73Fel_SoNDkCNaux1VposBu791-uUpDzUpr7leKckrPXrpZ2hwnFbafVxFV9vq4fLTpB5KoBksuLfGNIwAx1RLLxWuMhE4c.ZGQzZDY2OGQtMWQxMy00ZTEwLWIyZGUtOGVjYzUzMjU3OGE4&color-scheme=Light",
|
||||||
|
"thumbnail": "https://maputnik.s3.eu-west-1.amazonaws.com/thumbnails/aws-hybrid.jpg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "aws-standard",
|
||||||
|
"title": "AWS Standard",
|
||||||
|
"url": "https://maps.geo.eu-west-1.amazonaws.com/v2/styles/Standard/descriptor?key=v1.public.eyJqdGkiOiJiOTNkYjBlZi04OWUzLTQxMGUtODFhMC0zYjZjZjVmZWZmMDgifYtukap0NBaJpcrS6Vit9j03GJgK9Bn-RSu5UCe3jkdSql2kKp3IEgLPtyLssbmKUdVO11sXddjK3ZOZy8V6QG0olv0K_1tOxyMIe4DAO3IV6H4VzHWiaXlbSakGiEgFLuHBdcfLDeMotye7N6rSRxuZb0CN9ytH9VjLly6-NEBRZezO_qPQyvdTFdeZsARIpL0f9YVpxPxPVvUcAWYCk5LpaPseRCDPrY5SlCdA1ZKqUA4F9RzxSTxB73Fel_SoNDkCNaux1VposBu791-uUpDzUpr7leKckrPXrpZ2hwnFbafVxFV9vq4fLTpB5KoBksuLfGNIwAx1RLLxWuMhE4c.ZGQzZDY2OGQtMWQxMy00ZTEwLWIyZGUtOGVjYzUzMjU3OGE4&color-scheme=Light",
|
||||||
|
"thumbnail": "https://maputnik.s3.eu-west-1.amazonaws.com/thumbnails/aws-standard.jpg"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "dark-matter",
|
"id": "dark-matter",
|
||||||
"title": "Dark Matter",
|
"title": "Dark Matter",
|
||||||
"url": "https://cdn.jsdelivr.net/gh/openmaptiles/dark-matter-gl-style@v1.9/style.json",
|
"url": "https://cdn.jsdelivr.net/gh/openmaptiles/dark-matter-gl-style@v1.9/style.json",
|
||||||
"thumbnail": "https://maputnik.github.io/thumbnails/dark-matter.png"
|
"thumbnail": "https://maputnik.github.io/thumbnails/dark-matter.png"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "locationiq-streets",
|
||||||
|
"title": "LocationIQ Streets",
|
||||||
|
"url": "https://tiles.locationiq.com/v3/streets/vector.json?key={key}",
|
||||||
|
"thumbnail": "https://static-assets.locationiq.com/maputnik/locationiq-streets.png"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "maptiler-basic-gl-style",
|
"id": "maptiler-basic-gl-style",
|
||||||
"title": "MapTiler Basic",
|
"title": "MapTiler Basic",
|
||||||
@@ -29,30 +47,6 @@
|
|||||||
"url": "https://cdn.jsdelivr.net/gh/openmaptiles/toner-gl-style@v1.0/style.json",
|
"url": "https://cdn.jsdelivr.net/gh/openmaptiles/toner-gl-style@v1.0/style.json",
|
||||||
"thumbnail": "https://maputnik.github.io/thumbnails/toner.png"
|
"thumbnail": "https://maputnik.github.io/thumbnails/toner.png"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id": "os-zoomstack-light",
|
|
||||||
"title": "Zoomstack Light",
|
|
||||||
"url": "https://s3-eu-west-1.amazonaws.com/tiles.os.uk/v2/styles/open-zoomstack-light/style.json",
|
|
||||||
"thumbnail": "https://maputnik.github.io/thumbnails/os-zoomstack-light.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "os-zoomstack-night",
|
|
||||||
"title": "Zoomstack Night",
|
|
||||||
"url": "https://s3-eu-west-1.amazonaws.com/tiles.os.uk/v2/styles/open-zoomstack-night/style.json",
|
|
||||||
"thumbnail": "https://maputnik.github.io/thumbnails/os-zoomstack-night.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "os-zoomstack-outdoor",
|
|
||||||
"title": "Zoomstack Outdoor",
|
|
||||||
"url": "https://s3-eu-west-1.amazonaws.com/tiles.os.uk/v2/styles/open-zoomstack-outdoor/style.json",
|
|
||||||
"thumbnail": "https://maputnik.github.io/thumbnails/os-zoomstack-outdoor.png"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "os-zoomstack-road",
|
|
||||||
"title": "Zoomstack Road",
|
|
||||||
"url": "https://s3-eu-west-1.amazonaws.com/tiles.os.uk/v2/styles/open-zoomstack-road/style.json",
|
|
||||||
"thumbnail": "https://maputnik.github.io/thumbnails/os-zoomstack-road.png"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "osm-bright",
|
"id": "osm-bright",
|
||||||
"title": "OSM Bright",
|
"title": "OSM Bright",
|
||||||
|
|||||||
@@ -18,5 +18,10 @@
|
|||||||
"type": "vector",
|
"type": "vector",
|
||||||
"url": "https://s3-eu-west-1.amazonaws.com/tiles.os.uk/v2/data/vector/open-zoomstack/config.json",
|
"url": "https://s3-eu-west-1.amazonaws.com/tiles.os.uk/v2/data/vector/open-zoomstack/config.json",
|
||||||
"title": "OS Open Zoomstack v2"
|
"title": "OS Open Zoomstack v2"
|
||||||
|
},
|
||||||
|
"locationiq": {
|
||||||
|
"type": "vector",
|
||||||
|
"url": "https://tiles.locationiq.com/v3/pbf/tiles.json?key={key}",
|
||||||
|
"title": "LocationIQ"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
"openmaptiles": "get_your_own_OpIi9ZULNHzrESv6T2vL",
|
"openmaptiles": "get_your_own_OpIi9ZULNHzrESv6T2vL",
|
||||||
"thunderforest": "b71f7f0ba4064f5eb9e903859a9cf5c6"
|
"thunderforest": "b71f7f0ba4064f5eb9e903859a9cf5c6",
|
||||||
|
"locationiq": "pk.put_your_api_key_here7bb23dffeb4"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
interface DebugStore {
|
|
||||||
[namespace: string]: {
|
|
||||||
[key: string]: any
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const debugStore: DebugStore = {};
|
|
||||||
|
|
||||||
function enabled() {
|
|
||||||
const qs = new URL(window.location.href).searchParams;
|
|
||||||
const debugQs = qs.get("debug");
|
|
||||||
if(debugQs) {
|
|
||||||
return !!debugQs.match(/^(|1|true)$/);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function genErr() {
|
|
||||||
return new Error("Debug not enabled, enable by appending '?debug' to your query string");
|
|
||||||
}
|
|
||||||
|
|
||||||
function set(namespace: keyof DebugStore, key: string, value: any) {
|
|
||||||
if(!enabled()) {
|
|
||||||
throw genErr();
|
|
||||||
}
|
|
||||||
debugStore[namespace] = debugStore[namespace] || {};
|
|
||||||
debugStore[namespace][key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get(namespace: keyof DebugStore, key: string) {
|
|
||||||
if(!enabled()) {
|
|
||||||
throw genErr();
|
|
||||||
}
|
|
||||||
if(Object.prototype.hasOwnProperty.call(debugStore, namespace)) {
|
|
||||||
return debugStore[namespace][key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const mod = {
|
|
||||||
enabled,
|
|
||||||
get,
|
|
||||||
set
|
|
||||||
};
|
|
||||||
|
|
||||||
(window as any).debug = mod;
|
|
||||||
export default mod;
|
|
||||||
Vendored
+18
@@ -0,0 +1,18 @@
|
|||||||
|
import type { StyleSpecification } from "maplibre-gl";
|
||||||
|
|
||||||
|
export type StyleSpecificationWithId = StyleSpecification & {id: string};
|
||||||
|
|
||||||
|
export type OnStyleChangedOpts = {
|
||||||
|
save?: boolean;
|
||||||
|
addRevision?: boolean;
|
||||||
|
initialLoad?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OnStyleChangedCallback = (newStyle: StyleSpecificationWithId, opts: OnStyleChangedOpts={}) => void;
|
||||||
|
|
||||||
|
export type OnMoveLayerCallback = (move: {oldIndex: number; newIndex: number}) => void;
|
||||||
|
|
||||||
|
export interface IStyleStore {
|
||||||
|
getLatestStyle(): Promise<StyleSpecificationWithId>;
|
||||||
|
save(mapStyle: StyleSpecificationWithId): StyleSpecificationWithId;
|
||||||
|
}
|
||||||
@@ -20,6 +20,12 @@ const spec = (t: TFunction) => ({
|
|||||||
docUrl: "https://docs.stadiamaps.com/authentication/",
|
docUrl: "https://docs.stadiamaps.com/authentication/",
|
||||||
docUrlLinkText: t("Learn More")
|
docUrlLinkText: t("Learn More")
|
||||||
},
|
},
|
||||||
|
locationiq_access_token: {
|
||||||
|
label: t("LocationIQ Access Token"),
|
||||||
|
doc: t("Public access token for LocationIQ services."),
|
||||||
|
docUrl: "https://docs.locationiq.com/docs/maps",
|
||||||
|
docUrlLinkText: t("Learn More")
|
||||||
|
},
|
||||||
style_renderer: {
|
style_renderer: {
|
||||||
label: t("Style Renderer"),
|
label: t("Style Renderer"),
|
||||||
doc: t("Choose the default Maputnik renderer for this style.")
|
doc: t("Choose the default Maputnik renderer for this style.")
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export const NON_SOURCE_LAYERS = ['background', 'raster', 'hillshade', 'heatmap', 'color-relief']
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import type {StyleSpecification} from "maplibre-gl";
|
import { StyleSpecificationWithId } from "./definitions";
|
||||||
|
|
||||||
export class RevisionStore {
|
export class RevisionStore {
|
||||||
revisions: (StyleSpecification & {id: string})[];
|
revisions: StyleSpecificationWithId[];
|
||||||
currentIdx: number;
|
currentIdx: number;
|
||||||
|
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ export class RevisionStore {
|
|||||||
return this.revisions[this.currentIdx]
|
return this.revisions[this.currentIdx]
|
||||||
}
|
}
|
||||||
|
|
||||||
addRevision(revision: StyleSpecification & {id: string}) {
|
addRevision(revision: StyleSpecificationWithId) {
|
||||||
// clear any "redo" revisions once a change is made
|
// clear any "redo" revisions once a change is made
|
||||||
// and ensure current index is at end of list
|
// and ensure current index is at end of list
|
||||||
this.revisions = this.revisions.slice(0, this.currentIdx + 1);
|
this.revisions = this.revisions.slice(0, this.currentIdx + 1);
|
||||||
|
|||||||
+5
-4
@@ -1,6 +1,7 @@
|
|||||||
import type {StyleSpecification, SourceSpecification} from "maplibre-gl";
|
import type {SourceSpecification} from "maplibre-gl";
|
||||||
|
import type {StyleSpecificationWithId} from "./definitions";
|
||||||
|
|
||||||
export function deleteSource(mapStyle: StyleSpecification, sourceId: string) {
|
export function deleteSource(mapStyle: StyleSpecificationWithId, sourceId: string) {
|
||||||
const remainingSources = { ...mapStyle.sources}
|
const remainingSources = { ...mapStyle.sources}
|
||||||
delete remainingSources[sourceId]
|
delete remainingSources[sourceId]
|
||||||
return {
|
return {
|
||||||
@@ -10,11 +11,11 @@ export function deleteSource(mapStyle: StyleSpecification, sourceId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function addSource(mapStyle: StyleSpecification, sourceId: string, source: SourceSpecification) {
|
export function addSource(mapStyle: StyleSpecificationWithId, sourceId: string, source: SourceSpecification) {
|
||||||
return changeSource(mapStyle, sourceId, source)
|
return changeSource(mapStyle, sourceId, source)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function changeSource(mapStyle: StyleSpecification, sourceId: string, source: SourceSpecification) {
|
export function changeSource(mapStyle: StyleSpecificationWithId, sourceId: string, source: SourceSpecification) {
|
||||||
const changedSources = {
|
const changedSources = {
|
||||||
...mapStyle.sources,
|
...mapStyle.sources,
|
||||||
[sourceId]: source
|
[sourceId]: source
|
||||||
|
|||||||
@@ -1,46 +1,38 @@
|
|||||||
import style from './style.js'
|
import style from '../style'
|
||||||
import {format} from '@maplibre/maplibre-gl-style-spec'
|
import {format} from '@maplibre/maplibre-gl-style-spec'
|
||||||
import type {StyleSpecification} from 'maplibre-gl'
|
|
||||||
import ReconnectingWebSocket from 'reconnecting-websocket'
|
import ReconnectingWebSocket from 'reconnecting-websocket'
|
||||||
|
import type {IStyleStore, OnStyleChangedCallback, StyleSpecificationWithId} from '../definitions'
|
||||||
|
|
||||||
export type ApiStyleStoreOptions = {
|
export type ApiStyleStoreOptions = {
|
||||||
port: string | null
|
onLocalStyleChange?: OnStyleChangedCallback
|
||||||
host: string | null
|
|
||||||
onLocalStyleChange?: (style: any) => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ApiStyleStore {
|
export class ApiStyleStore implements IStyleStore {
|
||||||
|
|
||||||
localUrl: string;
|
localUrl: string;
|
||||||
websocketUrl: string;
|
websocketUrl: string;
|
||||||
latestStyleId: string | undefined = undefined;
|
latestStyleId: string | undefined = undefined;
|
||||||
onLocalStyleChange: (style: any) => void;
|
onLocalStyleChange: OnStyleChangedCallback;
|
||||||
|
|
||||||
constructor(opts: ApiStyleStoreOptions) {
|
constructor(opts: ApiStyleStoreOptions) {
|
||||||
this.onLocalStyleChange = opts.onLocalStyleChange || (() => {})
|
this.onLocalStyleChange = opts.onLocalStyleChange || (() => {})
|
||||||
const port = opts.port || '8000'
|
const port = window.location.port
|
||||||
const host = opts.host || 'localhost'
|
const host = 'localhost'
|
||||||
this.localUrl = `http://${host}:${port}`
|
this.localUrl = `http://${host}:${port}`
|
||||||
this.websocketUrl = `ws://${host}:${port}/ws`
|
this.websocketUrl = `ws://${host}:${port}/ws`
|
||||||
this.init = this.init.bind(this)
|
this.init = this.init.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(cb: (...args: any[]) => void) {
|
async init(): Promise<void> {
|
||||||
fetch(this.localUrl + '/styles', {
|
try {
|
||||||
mode: 'cors',
|
const response = await fetch(this.localUrl + '/styles', {mode: 'cors'});
|
||||||
})
|
const body = await response.json();
|
||||||
.then((response) => {
|
const styleIds = body;
|
||||||
return response.json();
|
this.latestStyleId = styleIds[0]
|
||||||
})
|
this.notifyLocalChanges();
|
||||||
.then((body) => {
|
} catch {
|
||||||
const styleIds = body;
|
throw new Error('Can not connect to style API');
|
||||||
this.latestStyleId = styleIds[0]
|
}
|
||||||
this.notifyLocalChanges()
|
|
||||||
cb(null)
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
cb(new Error('Can not connect to style API'))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyLocalChanges() {
|
notifyLocalChanges() {
|
||||||
@@ -59,24 +51,20 @@ export class ApiStyleStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
latestStyle(cb: (...args: any[]) => void) {
|
async getLatestStyle(): Promise<StyleSpecificationWithId> {
|
||||||
if(this.latestStyleId) {
|
if(this.latestStyleId) {
|
||||||
fetch(this.localUrl + '/styles/' + this.latestStyleId, {
|
const response = await fetch(this.localUrl + '/styles/' + this.latestStyleId, {
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
})
|
});
|
||||||
.then(function(response) {
|
const body = await response.json();
|
||||||
return response.json();
|
return style.ensureStyleValidity(body);
|
||||||
})
|
|
||||||
.then(function(body) {
|
|
||||||
cb(style.ensureStyleValidity(body))
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('No latest style available. You need to init the api backend first.')
|
throw new Error('No latest style available. You need to init the api backend first.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save current style replacing previous version
|
// Save current style replacing previous version
|
||||||
save(mapStyle: StyleSpecification & { id: string }) {
|
save(mapStyle: StyleSpecificationWithId) {
|
||||||
const styleJSON = format(
|
const styleJSON = format(
|
||||||
style.stripAccessTokens(
|
style.stripAccessTokens(
|
||||||
style.replaceAccessTokens(mapStyle)
|
style.replaceAccessTokens(mapStyle)
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
|
import { IStyleStore, OnStyleChangedCallback } from "../definitions";
|
||||||
|
import { getStyleUrlFromAddressbarAndRemoveItIfNeeded, loadStyleUrl } from "../urlopen";
|
||||||
|
import { ApiStyleStore } from "./apistore";
|
||||||
|
import { StyleStore } from "./stylestore";
|
||||||
|
|
||||||
|
export async function createStyleStore(onStyleChanged: OnStyleChangedCallback): Promise<IStyleStore> {
|
||||||
|
const styleUrl = getStyleUrlFromAddressbarAndRemoveItIfNeeded();
|
||||||
|
const useStyleUrl = styleUrl && window.confirm("Load style from URL: " + styleUrl + " and discard current changes?");
|
||||||
|
let styleStore: IStyleStore;
|
||||||
|
if (import.meta.env.MODE === 'desktop' && !useStyleUrl) {
|
||||||
|
const apiStyleStore = new ApiStyleStore({
|
||||||
|
onLocalStyleChange: mapStyle => onStyleChanged(mapStyle, {save: false}),
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await apiStyleStore.init();
|
||||||
|
styleStore = apiStyleStore;
|
||||||
|
} catch {
|
||||||
|
styleStore = new StyleStore();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
styleStore = new StyleStore();
|
||||||
|
}
|
||||||
|
const styleToLoad = useStyleUrl ? await loadStyleUrl(styleUrl) : await styleStore.getLatestStyle();
|
||||||
|
onStyleChanged(styleToLoad, {initialLoad: true, save: false});
|
||||||
|
return styleStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { IStyleStore };
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import style from './style'
|
import style from '../style'
|
||||||
import {loadStyleUrl} from './urlopen'
|
import {loadStyleUrl} from '../urlopen'
|
||||||
import publicSources from '../config/styles.json'
|
import publicSources from '../../config/styles.json'
|
||||||
import type {StyleSpecification} from 'maplibre-gl'
|
import type {IStyleStore, StyleSpecificationWithId} from '../definitions'
|
||||||
|
|
||||||
const storagePrefix = "maputnik"
|
const storagePrefix = "maputnik"
|
||||||
const stylePrefix = 'style'
|
const stylePrefix = 'style'
|
||||||
@@ -13,8 +13,8 @@ const storageKeys = {
|
|||||||
const defaultStyleUrl = publicSources[0].url
|
const defaultStyleUrl = publicSources[0].url
|
||||||
|
|
||||||
// Fetch a default style via URL and return it or a fallback style via callback
|
// Fetch a default style via URL and return it or a fallback style via callback
|
||||||
export function loadDefaultStyle(cb: (...args: any[]) => void) {
|
export function loadDefaultStyle(): Promise<StyleSpecificationWithId> {
|
||||||
loadStyleUrl(defaultStyleUrl, cb)
|
return loadStyleUrl(defaultStyleUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return style ids and dates of all styles stored in local storage
|
// Return style ids and dates of all styles stored in local storage
|
||||||
@@ -51,7 +51,7 @@ function styleKey(styleId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Manages many possible styles that are stored in the local storage
|
// Manages many possible styles that are stored in the local storage
|
||||||
export class StyleStore {
|
export class StyleStore implements IStyleStore {
|
||||||
/**
|
/**
|
||||||
* List of style ids
|
* List of style ids
|
||||||
*/
|
*/
|
||||||
@@ -63,10 +63,6 @@ export class StyleStore {
|
|||||||
this.mapStyles = loadStoredStyles();
|
this.mapStyles = loadStoredStyles();
|
||||||
}
|
}
|
||||||
|
|
||||||
init(cb: (...args: any[]) => void) {
|
|
||||||
cb(null)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete entire style history
|
// Delete entire style history
|
||||||
purge() {
|
purge() {
|
||||||
for (let i = 0; i < window.localStorage.length; i++) {
|
for (let i = 0; i < window.localStorage.length; i++) {
|
||||||
@@ -78,21 +74,45 @@ export class StyleStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the last edited style
|
// Find the last edited style
|
||||||
latestStyle(cb: (...args: any[]) => void) {
|
async getLatestStyle(): Promise<StyleSpecificationWithId> {
|
||||||
if(this.mapStyles.length === 0) return loadDefaultStyle(cb)
|
if(this.mapStyles.length === 0) {
|
||||||
|
return loadDefaultStyle();
|
||||||
|
}
|
||||||
const styleId = window.localStorage.getItem(storageKeys.latest) as string;
|
const styleId = window.localStorage.getItem(storageKeys.latest) as string;
|
||||||
const styleItem = window.localStorage.getItem(styleKey(styleId))
|
const styleItem = window.localStorage.getItem(styleKey(styleId))
|
||||||
|
|
||||||
if(styleItem) return cb(JSON.parse(styleItem))
|
if (styleItem) {
|
||||||
loadDefaultStyle(cb)
|
return JSON.parse(styleItem) as StyleSpecificationWithId;
|
||||||
|
}
|
||||||
|
return loadDefaultStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save current style replacing previous version
|
// Save current style replacing previous version
|
||||||
save(mapStyle: StyleSpecification & { id: string }) {
|
save(mapStyle: StyleSpecificationWithId) {
|
||||||
mapStyle = style.ensureStyleValidity(mapStyle)
|
mapStyle = style.ensureStyleValidity(mapStyle)
|
||||||
const key = styleKey(mapStyle.id)
|
const key = styleKey(mapStyle.id)
|
||||||
window.localStorage.setItem(key, JSON.stringify(mapStyle))
|
|
||||||
window.localStorage.setItem(storageKeys.latest, mapStyle.id)
|
const saveFn = () => {
|
||||||
|
window.localStorage.setItem(key, JSON.stringify(mapStyle))
|
||||||
|
window.localStorage.setItem(storageKeys.latest, mapStyle.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
saveFn()
|
||||||
|
} catch (e) {
|
||||||
|
// Handle quota exceeded error
|
||||||
|
if (e instanceof DOMException && (
|
||||||
|
e.code === 22 || // Firefox
|
||||||
|
e.code === 1014 || // Firefox
|
||||||
|
e.name === 'QuotaExceededError' ||
|
||||||
|
e.name === 'NS_ERROR_DOM_QUOTA_REACHED'
|
||||||
|
)) {
|
||||||
|
this.purge()
|
||||||
|
saveFn() // Retry after clearing
|
||||||
|
} else {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
return mapStyle
|
return mapStyle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+10
-6
@@ -1,6 +1,7 @@
|
|||||||
import {derefLayers} from '@maplibre/maplibre-gl-style-spec'
|
import {derefLayers} from '@maplibre/maplibre-gl-style-spec'
|
||||||
import type {StyleSpecification, LayerSpecification} from 'maplibre-gl'
|
import type {StyleSpecification, LayerSpecification} from 'maplibre-gl'
|
||||||
import tokens from '../config/tokens.json'
|
import tokens from '../config/tokens.json'
|
||||||
|
import type {StyleSpecificationWithId} from './definitions'
|
||||||
|
|
||||||
// Empty style is always used if no style could be restored or fetched
|
// Empty style is always used if no style could be restored or fetched
|
||||||
const emptyStyle = ensureStyleValidity({
|
const emptyStyle = ensureStyleValidity({
|
||||||
@@ -13,15 +14,14 @@ function generateId() {
|
|||||||
return Math.random().toString(36).substring(2, 9)
|
return Math.random().toString(36).substring(2, 9)
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureHasId(style: StyleSpecification & { id?: string }): StyleSpecification & { id: string } {
|
function ensureHasId(style: StyleSpecification & { id?: string }): StyleSpecificationWithId {
|
||||||
if(!('id' in style) || !style.id) {
|
if(!('id' in style) || !style.id) {
|
||||||
style.id = generateId();
|
style.id = generateId();
|
||||||
return style as StyleSpecification & { id: string };
|
|
||||||
}
|
}
|
||||||
return style as StyleSpecification & { id: string };
|
return style as StyleSpecificationWithId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureHasNoInteractive(style: StyleSpecification & {id: string}) {
|
function ensureHasNoInteractive(style: StyleSpecificationWithId) {
|
||||||
const changedLayers = style.layers.map(layer => {
|
const changedLayers = style.layers.map(layer => {
|
||||||
const changedLayer: LayerSpecification & { interactive?: any } = { ...layer }
|
const changedLayer: LayerSpecification & { interactive?: any } = { ...layer }
|
||||||
delete changedLayer.interactive
|
delete changedLayer.interactive
|
||||||
@@ -34,14 +34,14 @@ function ensureHasNoInteractive(style: StyleSpecification & {id: string}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureHasNoRefs(style: StyleSpecification & {id: string}) {
|
function ensureHasNoRefs(style: StyleSpecificationWithId) {
|
||||||
return {
|
return {
|
||||||
...style,
|
...style,
|
||||||
layers: derefLayers(style.layers)
|
layers: derefLayers(style.layers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ensureStyleValidity(style: StyleSpecification): StyleSpecification & { id: string } {
|
function ensureStyleValidity(style: StyleSpecification): StyleSpecificationWithId {
|
||||||
return ensureHasNoInteractive(ensureHasNoRefs(ensureHasId(style)))
|
return ensureHasNoInteractive(ensureHasNoRefs(ensureHasId(style)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +79,9 @@ function replaceSourceAccessToken(mapStyle: StyleSpecification, sourceName: stri
|
|||||||
// so we need to check the source URL.
|
// so we need to check the source URL.
|
||||||
authSourceName = "stadia"
|
authSourceName = "stadia"
|
||||||
}
|
}
|
||||||
|
else if (("url" in source) && source.url?.match(/\.locationiq\.com/)) {
|
||||||
|
authSourceName = "locationiq"
|
||||||
|
}
|
||||||
|
|
||||||
const accessToken = getAccessToken(authSourceName, mapStyle, opts)
|
const accessToken = getAccessToken(authSourceName, mapStyle, opts)
|
||||||
|
|
||||||
@@ -138,6 +141,7 @@ function stripAccessTokens(mapStyle: StyleSpecification) {
|
|||||||
delete changedMetadata['maputnik:openmaptiles_access_token'];
|
delete changedMetadata['maputnik:openmaptiles_access_token'];
|
||||||
delete changedMetadata['maputnik:thunderforest_access_token'];
|
delete changedMetadata['maputnik:thunderforest_access_token'];
|
||||||
delete changedMetadata['maputnik:stadia_access_token'];
|
delete changedMetadata['maputnik:stadia_access_token'];
|
||||||
|
delete changedMetadata['maputnik:locationiq_access_token'];
|
||||||
return {
|
return {
|
||||||
...mapStyle,
|
...mapStyle,
|
||||||
metadata: changedMetadata
|
metadata: changedMetadata
|
||||||
|
|||||||
+20
-23
@@ -1,30 +1,27 @@
|
|||||||
import style from './style'
|
import style from './style'
|
||||||
|
import { StyleSpecificationWithId } from './definitions';
|
||||||
|
|
||||||
export function initialStyleUrl() {
|
export function getStyleUrlFromAddressbarAndRemoveItIfNeeded(): string | null {
|
||||||
const initialUrl = new URL(window.location.href);
|
const initialUrl = new URL(window.location.href);
|
||||||
return initialUrl.searchParams.get('style');
|
const styleUrl = initialUrl.searchParams.get('style');
|
||||||
|
if (styleUrl) {
|
||||||
|
initialUrl.searchParams.delete('style');
|
||||||
|
window.history.replaceState({}, document.title, initialUrl.toString())
|
||||||
|
}
|
||||||
|
return styleUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadStyleUrl(styleUrl: string, cb: (...args: any[]) => void) {
|
export async function loadStyleUrl(styleUrl: string): Promise<StyleSpecificationWithId> {
|
||||||
console.log('Loading style', styleUrl)
|
console.log('Loading style', styleUrl)
|
||||||
fetch(styleUrl, {
|
try {
|
||||||
mode: 'cors',
|
const response = await fetch(styleUrl, {
|
||||||
credentials: "same-origin"
|
mode: 'cors',
|
||||||
})
|
credentials: "same-origin"
|
||||||
.then(function(response) {
|
});
|
||||||
return response.json();
|
const body = await response.json();
|
||||||
})
|
return style.ensureStyleValidity(body);
|
||||||
.then(function(body) {
|
} catch {
|
||||||
cb(style.ensureStyleValidity(body))
|
console.warn('Could not fetch default style: ' + styleUrl)
|
||||||
})
|
return style.emptyStyle
|
||||||
.catch(function() {
|
}
|
||||||
console.warn('Could not fetch default style', styleUrl)
|
|
||||||
cb(style.emptyStyle)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function removeStyleQuerystring() {
|
|
||||||
const initialUrl = new URL(window.location.href);
|
|
||||||
initialUrl.searchParams.delete('style');
|
|
||||||
window.history.replaceState({}, document.title, initialUrl.toString())
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,13 @@
|
|||||||
"Must provide protocol: <1>https://</1>": "Protokoll erforderlich: <1>https://</1>",
|
"Must provide protocol: <1>https://</1>": "Protokoll erforderlich: <1>https://</1>",
|
||||||
"Must provide protocol: <1>http://</1> or <3>https://</3>": "Protokoll erforderlich: <1>http://</1> oder <3>https://</3>",
|
"Must provide protocol: <1>http://</1> or <3>https://</3>": "Protokoll erforderlich: <1>http://</1> oder <3>https://</3>",
|
||||||
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "Die CORS-Politik erlaubt es nicht, Ressourcen über http von https zu laden, benutze eine <1>https://</1>-Domain",
|
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "Die CORS-Politik erlaubt es nicht, Ressourcen über http von https zu laden, benutze eine <1>https://</1>-Domain",
|
||||||
|
"General layout properties": "Allgemeine Layouteigenschaften",
|
||||||
|
"Text layout properties": "Text-Layouteigenschaften",
|
||||||
|
"Icon layout properties": "Icon-Layouteigenschaften",
|
||||||
|
"Text paint properties": "Text-Darstellungseigenschaften",
|
||||||
|
"Icon paint properties": "Icon-Darstellungseigenschaften",
|
||||||
|
"Paint properties": "Darstellungseigenschaften",
|
||||||
|
"Layout properties": "Layouteigenschaften",
|
||||||
"Layer": "Ebene",
|
"Layer": "Ebene",
|
||||||
"JSON Editor": "JSON-Editor",
|
"JSON Editor": "JSON-Editor",
|
||||||
"Delete": "Löschen",
|
"Delete": "Löschen",
|
||||||
@@ -79,6 +86,7 @@
|
|||||||
"center:": "Zentrum:",
|
"center:": "Zentrum:",
|
||||||
"rotation:": "Rotation:",
|
"rotation:": "Rotation:",
|
||||||
"Close modal": "Modale Fenster schließen",
|
"Close modal": "Modale Fenster schließen",
|
||||||
|
"Layer ID already exists": "Layer-ID existiert bereits",
|
||||||
"Debug": "Debug",
|
"Debug": "Debug",
|
||||||
"Options": "Optionen",
|
"Options": "Optionen",
|
||||||
"Save Style": "Stil Speichern",
|
"Save Style": "Stil Speichern",
|
||||||
@@ -182,20 +190,15 @@
|
|||||||
"Public access token for Thunderforest services.": "Öffentlicher Zugriffstoken für Thunderforest-Dienste.",
|
"Public access token for Thunderforest services.": "Öffentlicher Zugriffstoken für Thunderforest-Dienste.",
|
||||||
"Stadia Maps API Key": "Stadia Maps API-Schlüssel",
|
"Stadia Maps API Key": "Stadia Maps API-Schlüssel",
|
||||||
"API key for Stadia Maps.": "API-Schlüssel für Stadia Maps.",
|
"API key for Stadia Maps.": "API-Schlüssel für Stadia Maps.",
|
||||||
|
"LocationIQ Access Token": "LocationIQ Zugriffstoken",
|
||||||
|
"Public access token for LocationIQ services.": "Öffentlicher Zugriffstoken für LocationIQ-Dienste.",
|
||||||
"Style Renderer": "Stil-Renderer",
|
"Style Renderer": "Stil-Renderer",
|
||||||
"Choose the default Maputnik renderer for this style.": "Wähle den Standard-Renderer für diesen Stil aus.",
|
"Choose the default Maputnik renderer for this style.": "Wähle den Standard-Renderer für diesen Stil aus.",
|
||||||
"Paint properties": "Darstellungseigenschaften",
|
|
||||||
"Opacity": "Deckkraft",
|
"Opacity": "Deckkraft",
|
||||||
"Radius": "Radius",
|
"Radius": "Radius",
|
||||||
"Text paint properties": "Text-Darstellungseigenschaften",
|
|
||||||
"Icon paint properties": "Icon-Darstellungseigenschaften",
|
|
||||||
"Text layout properties": "Text-Layouteigenschaften",
|
|
||||||
"Icon layout properties": "Icon-Layouteigenschaften",
|
|
||||||
"General layout properties": "Allgemeine Layouteigenschaften",
|
|
||||||
"Color": "Farbe",
|
"Color": "Farbe",
|
||||||
"Outline color": "Umrissfarbe",
|
"Outline color": "Umrissfarbe",
|
||||||
"Language": "Sprache",
|
"Language": "Sprache",
|
||||||
"Layout properties": "Layouteigenschaften",
|
|
||||||
"Width": "Breite",
|
"Width": "Breite",
|
||||||
"Height": "Höhe",
|
"Height": "Höhe",
|
||||||
"Field": "Feld",
|
"Field": "Feld",
|
||||||
|
|||||||
@@ -59,6 +59,13 @@
|
|||||||
"Must provide protocol: <1>https://</1>": "Protocole requis : <1>https://</1>",
|
"Must provide protocol: <1>https://</1>": "Protocole requis : <1>https://</1>",
|
||||||
"Must provide protocol: <1>http://</1> or <3>https://</3>": "Protocole requis : <1>http://</1> ou <3>https://</3>",
|
"Must provide protocol: <1>http://</1> or <3>https://</3>": "Protocole requis : <1>http://</1> ou <3>https://</3>",
|
||||||
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "La politique CORS ne permet pas de récupérer des ressources servies sur http depuis https, utilisez un protocole <1>https://</1>",
|
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "La politique CORS ne permet pas de récupérer des ressources servies sur http depuis https, utilisez un protocole <1>https://</1>",
|
||||||
|
"General layout properties": "Propriétés générales de mise en page",
|
||||||
|
"Text layout properties": "Propriétés de mise en page du texte",
|
||||||
|
"Icon layout properties": "Propriétés de mise en page de l'icône",
|
||||||
|
"Text paint properties": "Propriétés de peinture du texte",
|
||||||
|
"Icon paint properties": "Propriétés de peinture de l'icône",
|
||||||
|
"Paint properties": "Propriétés de peinture",
|
||||||
|
"Layout properties": "Propriétés de mise en page",
|
||||||
"Layer": "Calque",
|
"Layer": "Calque",
|
||||||
"JSON Editor": "Éditeur JSON",
|
"JSON Editor": "Éditeur JSON",
|
||||||
"Delete": "Supprimer",
|
"Delete": "Supprimer",
|
||||||
@@ -79,6 +86,7 @@
|
|||||||
"center:": "centre :",
|
"center:": "centre :",
|
||||||
"rotation:": "rotation :",
|
"rotation:": "rotation :",
|
||||||
"Close modal": "Fermer la fenêtre modale",
|
"Close modal": "Fermer la fenêtre modale",
|
||||||
|
"Layer ID already exists": "L'identifiant du calque existe déjà",
|
||||||
"Debug": "Déboguer",
|
"Debug": "Déboguer",
|
||||||
"Options": "Options",
|
"Options": "Options",
|
||||||
"Save Style": "Enregistrer le style",
|
"Save Style": "Enregistrer le style",
|
||||||
@@ -182,15 +190,10 @@
|
|||||||
"Public access token for Thunderforest services.": "Jeton d'accès public pour les services Thunderforest.",
|
"Public access token for Thunderforest services.": "Jeton d'accès public pour les services Thunderforest.",
|
||||||
"Stadia Maps API Key": "Clé d'API Stadia Maps",
|
"Stadia Maps API Key": "Clé d'API Stadia Maps",
|
||||||
"API key for Stadia Maps.": "Clé d'API pour Stadia Maps.",
|
"API key for Stadia Maps.": "Clé d'API pour Stadia Maps.",
|
||||||
|
"LocationIQ Access Token": "Jeton d'accès LocationIQ",
|
||||||
|
"Public access token for LocationIQ services.": "Jeton d'accès public pour les services LocationIQ.",
|
||||||
"Style Renderer": "Moteur de rendu pour le style",
|
"Style Renderer": "Moteur de rendu pour le style",
|
||||||
"Choose the default Maputnik renderer for this style.": "Choisissez le moteur de rendu Maputnik par défaut pour ce style.",
|
"Choose the default Maputnik renderer for this style.": "Choisissez le moteur de rendu Maputnik par défaut pour ce style.",
|
||||||
"Language": "Langue",
|
"Language": "Langue",
|
||||||
"Layer options": "Options du calque",
|
"Layer options": "Options du calque"
|
||||||
"Paint properties": "Propriétés de peinture",
|
|
||||||
"Layout properties": "Propriétés de mise en page",
|
|
||||||
"General layout properties": "Propriétés générales de mise en page",
|
|
||||||
"Text layout properties": "Propriétés de mise en page du texte",
|
|
||||||
"Icon layout properties": "Propriétés de mise en page de l'icône",
|
|
||||||
"Text paint properties": "Propriétés de peinture du texte",
|
|
||||||
"Icon paint properties": "Propriétés de peinture de l'icône"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,13 @@
|
|||||||
"Must provide protocol: <1>https://</1>": "נדרש פרוטוקול: <1>https://</1>",
|
"Must provide protocol: <1>https://</1>": "נדרש פרוטוקול: <1>https://</1>",
|
||||||
"Must provide protocol: <1>http://</1> or <3>https://</3>": "נדרשים פרוטוקולים: <1>http://</1> או <3>https://</3>",
|
"Must provide protocol: <1>http://</1> or <3>https://</3>": "נדרשים פרוטוקולים: <1>http://</1> או <3>https://</3>",
|
||||||
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain",
|
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain",
|
||||||
|
"General layout properties": "תכונות פריסה כלליות",
|
||||||
|
"Text layout properties": "תכונות פריסה של טקסט",
|
||||||
|
"Icon layout properties": "תכונות פריסה של סמליל",
|
||||||
|
"Text paint properties": "תכונות ציור של טקסט",
|
||||||
|
"Icon paint properties": "תכונות ציור של סמליל",
|
||||||
|
"Paint properties": "תכונות ציור",
|
||||||
|
"Layout properties": "תכונות פריסה",
|
||||||
"Layer": "שכבה",
|
"Layer": "שכבה",
|
||||||
"JSON Editor": "עורך JSON",
|
"JSON Editor": "עורך JSON",
|
||||||
"Delete": "מחיקה",
|
"Delete": "מחיקה",
|
||||||
@@ -79,6 +86,7 @@
|
|||||||
"center:": "מרכז:",
|
"center:": "מרכז:",
|
||||||
"rotation:": "סיבוב:",
|
"rotation:": "סיבוב:",
|
||||||
"Close modal": "סגירת חלונית",
|
"Close modal": "סגירת חלונית",
|
||||||
|
"Layer ID already exists": "מזהה השכבה כבר קיים",
|
||||||
"Debug": "דיבאג",
|
"Debug": "דיבאג",
|
||||||
"Options": "אפשרויות",
|
"Options": "אפשרויות",
|
||||||
"Save Style": "שמירת הסטייל",
|
"Save Style": "שמירת הסטייל",
|
||||||
@@ -182,6 +190,8 @@
|
|||||||
"Public access token for Thunderforest services.": "Public access token for Thunderforest services.",
|
"Public access token for Thunderforest services.": "Public access token for Thunderforest services.",
|
||||||
"Stadia Maps API Key": "Stadia Maps API Key",
|
"Stadia Maps API Key": "Stadia Maps API Key",
|
||||||
"API key for Stadia Maps.": "API key for Stadia Maps",
|
"API key for Stadia Maps.": "API key for Stadia Maps",
|
||||||
|
"LocationIQ Access Token": "LocationIQ Access Token",
|
||||||
|
"Public access token for LocationIQ services.": "Public access token for LocationIQ services.",
|
||||||
"Style Renderer": "צייר הסטייל",
|
"Style Renderer": "צייר הסטייל",
|
||||||
"Choose the default Maputnik renderer for this style.": "בחירת צייר ברירת המחדל של מפוטניק עבור הסטייל הזה",
|
"Choose the default Maputnik renderer for this style.": "בחירת צייר ברירת המחדל של מפוטניק עבור הסטייל הזה",
|
||||||
"Language": "שפה",
|
"Language": "שפה",
|
||||||
|
|||||||
@@ -59,6 +59,13 @@
|
|||||||
"Must provide protocol: <1>https://</1>": "Protocollo richiesto: <1>https://</1>",
|
"Must provide protocol: <1>https://</1>": "Protocollo richiesto: <1>https://</1>",
|
||||||
"Must provide protocol: <1>http://</1> or <3>https://</3>": "Protocollo richiesto: <1>http://</1> o <3>https://</3>",
|
"Must provide protocol: <1>http://</1> or <3>https://</3>": "Protocollo richiesto: <1>http://</1> o <3>https://</3>",
|
||||||
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "La politica CORS non permette di caricare risorse tramite http da https, utilizza un dominio <1>https://</1>.",
|
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "La politica CORS non permette di caricare risorse tramite http da https, utilizza un dominio <1>https://</1>.",
|
||||||
|
"General layout properties": "Proprietà generali del layout",
|
||||||
|
"Text layout properties": "Proprietà di layout del testo",
|
||||||
|
"Icon layout properties": "Proprietà di layout dell'icona",
|
||||||
|
"Text paint properties": "Proprietà di pittura del testo",
|
||||||
|
"Icon paint properties": "Proprietà di pittura dell'icona",
|
||||||
|
"Paint properties": "Proprietà di pittura",
|
||||||
|
"Layout properties": "Proprietà di layout",
|
||||||
"Layer": "Livello",
|
"Layer": "Livello",
|
||||||
"JSON Editor": "Editor JSON",
|
"JSON Editor": "Editor JSON",
|
||||||
"Delete": "Elimina",
|
"Delete": "Elimina",
|
||||||
@@ -79,6 +86,7 @@
|
|||||||
"center:": "centro:",
|
"center:": "centro:",
|
||||||
"rotation:": "rotazione:",
|
"rotation:": "rotazione:",
|
||||||
"Close modal": "Chiudi finestra modale",
|
"Close modal": "Chiudi finestra modale",
|
||||||
|
"Layer ID already exists": "L'ID del layer esiste già",
|
||||||
"Debug": "Debug",
|
"Debug": "Debug",
|
||||||
"Options": "Opzioni",
|
"Options": "Opzioni",
|
||||||
"Save Style": "Opzioni stile",
|
"Save Style": "Opzioni stile",
|
||||||
@@ -182,6 +190,8 @@
|
|||||||
"Public access token for Thunderforest services.": "Token di accesso pubblico per i servizi Thunderforest.",
|
"Public access token for Thunderforest services.": "Token di accesso pubblico per i servizi Thunderforest.",
|
||||||
"Stadia Maps API Key": "Chiave API di Stadia Maps.",
|
"Stadia Maps API Key": "Chiave API di Stadia Maps.",
|
||||||
"API key for Stadia Maps.": "Chiave API per Stadia Maps.",
|
"API key for Stadia Maps.": "Chiave API per Stadia Maps.",
|
||||||
|
"LocationIQ Access Token": "Token di accesso LocationIQ",
|
||||||
|
"Public access token for LocationIQ services.": "Token di accesso pubblico per i servizi LocationIQ.",
|
||||||
"Style Renderer": "Renderer dello stile",
|
"Style Renderer": "Renderer dello stile",
|
||||||
"Choose the default Maputnik renderer for this style.": "Scegli il renderer predefinito di Maputnik per questo stile.",
|
"Choose the default Maputnik renderer for this style.": "Scegli il renderer predefinito di Maputnik per questo stile.",
|
||||||
"Language": "Lingua",
|
"Language": "Lingua",
|
||||||
|
|||||||
@@ -59,6 +59,13 @@
|
|||||||
"Must provide protocol: <1>https://</1>": "プロトコルを指定してください: <1>https://</1>",
|
"Must provide protocol: <1>https://</1>": "プロトコルを指定してください: <1>https://</1>",
|
||||||
"Must provide protocol: <1>http://</1> or <3>https://</3>": "プロトコルを指定してください: <1>http://</1> または <3>https://</3>",
|
"Must provide protocol: <1>http://</1> or <3>https://</3>": "プロトコルを指定してください: <1>http://</1> または <3>https://</3>",
|
||||||
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "CORS使用時は、http経由で提供されるリソースをhttpsから取得することはできません。<1>https://</1> ドメインを使用してください。",
|
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "CORS使用時は、http経由で提供されるリソースをhttpsから取得することはできません。<1>https://</1> ドメインを使用してください。",
|
||||||
|
"General layout properties": "一般レイアウトプロパティ",
|
||||||
|
"Text layout properties": "文字レイアウトプロパティ",
|
||||||
|
"Icon layout properties": "アイコンレイアウトプロパティ",
|
||||||
|
"Text paint properties": "文字ペイントプロパティ",
|
||||||
|
"Icon paint properties": "アイコンペイントプロパティ",
|
||||||
|
"Paint properties": "ペイントプロパティ",
|
||||||
|
"Layout properties": "レイアウトプロパティ",
|
||||||
"Layer": "レイヤー",
|
"Layer": "レイヤー",
|
||||||
"JSON Editor": "JSONエディタ",
|
"JSON Editor": "JSONエディタ",
|
||||||
"Delete": "削除",
|
"Delete": "削除",
|
||||||
@@ -79,6 +86,7 @@
|
|||||||
"center:": "中央:",
|
"center:": "中央:",
|
||||||
"rotation:": "回転角度:",
|
"rotation:": "回転角度:",
|
||||||
"Close modal": "モーダルを閉じる",
|
"Close modal": "モーダルを閉じる",
|
||||||
|
"Layer ID already exists": "レイヤーIDは既に存在します",
|
||||||
"Debug": "デバッグ",
|
"Debug": "デバッグ",
|
||||||
"Options": "設定",
|
"Options": "設定",
|
||||||
"Save Style": "スタイルを保存",
|
"Save Style": "スタイルを保存",
|
||||||
@@ -182,16 +190,11 @@
|
|||||||
"Public access token for Thunderforest services.": "Thunderforest サービスの公開用アクセストークン",
|
"Public access token for Thunderforest services.": "Thunderforest サービスの公開用アクセストークン",
|
||||||
"Stadia Maps API Key": "Stadia Maps API キー",
|
"Stadia Maps API Key": "Stadia Maps API キー",
|
||||||
"API key for Stadia Maps.": "Stadia Maps の API キー",
|
"API key for Stadia Maps.": "Stadia Maps の API キー",
|
||||||
|
"LocationIQ Access Token": "LocationIQ アクセストークン",
|
||||||
|
"Public access token for LocationIQ services.": "LocationIQ サービス用のパブリックアクセストークン。",
|
||||||
"Style Renderer": "スタイルレンダラ",
|
"Style Renderer": "スタイルレンダラ",
|
||||||
"Choose the default Maputnik renderer for this style.": "このスタイルのデフォルトの Maputnik レンダラを選択してください",
|
"Choose the default Maputnik renderer for this style.": "このスタイルのデフォルトの Maputnik レンダラを選択してください",
|
||||||
"Language": "言語",
|
"Language": "言語",
|
||||||
"<0>Open in OSM</0> — Opens the current view on openstreetmap.org": "現在のビューを <0>openstreetmap.org で開く</0>",
|
"<0>Open in OSM</0> — Opens the current view on openstreetmap.org": "現在のビューを <0>openstreetmap.org で開く</0>",
|
||||||
"Layer options": "レイヤー設定",
|
"Layer options": "レイヤー設定"
|
||||||
"Paint properties": "ペイントプロパティ",
|
|
||||||
"Layout properties": "レイアウトプロパティ",
|
|
||||||
"General layout properties": "一般レイアウトプロパティ",
|
|
||||||
"Text layout properties": "文字レイアウトプロパティ",
|
|
||||||
"Icon layout properties": "アイコンレイアウトプロパティ",
|
|
||||||
"Text paint properties": "文字ペイントプロパティ",
|
|
||||||
"Icon paint properties": "アイコンペイントプロパティ"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,13 @@
|
|||||||
"Must provide protocol: <1>https://</1>": "必须提供协议:<1>https://</1>",
|
"Must provide protocol: <1>https://</1>": "必须提供协议:<1>https://</1>",
|
||||||
"Must provide protocol: <1>http://</1> or <3>https://</3>": "必须提供协议:<1>http://</1> 或 <3>https://</3>",
|
"Must provide protocol: <1>http://</1> or <3>https://</3>": "必须提供协议:<1>http://</1> 或 <3>https://</3>",
|
||||||
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "CORS 策略不允许从 https 访问通过 http 提供的资源,请使用 <1>https://</1> 域名。",
|
"CORS policy won't allow fetching resources served over http from https, use a <1>https://</1> domain": "CORS 策略不允许从 https 访问通过 http 提供的资源,请使用 <1>https://</1> 域名。",
|
||||||
|
"General layout properties": "常规布局属性",
|
||||||
|
"Text layout properties": "文本布局属性",
|
||||||
|
"Icon layout properties": "图标布局属性",
|
||||||
|
"Text paint properties": "文本绘制属性",
|
||||||
|
"Icon paint properties": "图标绘制属性",
|
||||||
|
"Paint properties": "绘制属性",
|
||||||
|
"Layout properties": "布局属性",
|
||||||
"Layer": "图层",
|
"Layer": "图层",
|
||||||
"JSON Editor": "JSON编辑器",
|
"JSON Editor": "JSON编辑器",
|
||||||
"Delete": "删除",
|
"Delete": "删除",
|
||||||
@@ -79,6 +86,7 @@
|
|||||||
"center:": "中心:",
|
"center:": "中心:",
|
||||||
"rotation:": "旋转:",
|
"rotation:": "旋转:",
|
||||||
"Close modal": "关闭模态框",
|
"Close modal": "关闭模态框",
|
||||||
|
"Layer ID already exists": "图层ID已存在",
|
||||||
"Debug": "调试",
|
"Debug": "调试",
|
||||||
"Options": "选项",
|
"Options": "选项",
|
||||||
"Save Style": "保存样式",
|
"Save Style": "保存样式",
|
||||||
@@ -182,16 +190,11 @@
|
|||||||
"Public access token for Thunderforest services.": "Thunderforest 服务的公共访问令牌。",
|
"Public access token for Thunderforest services.": "Thunderforest 服务的公共访问令牌。",
|
||||||
"Stadia Maps API Key": "Stadia Maps API 密钥",
|
"Stadia Maps API Key": "Stadia Maps API 密钥",
|
||||||
"API key for Stadia Maps.": "Stadia Maps 的 API 密钥",
|
"API key for Stadia Maps.": "Stadia Maps 的 API 密钥",
|
||||||
|
"LocationIQ Access Token": "LocationIQ 访问令牌",
|
||||||
|
"Public access token for LocationIQ services.": "LocationIQ 服务的公共访问令牌。",
|
||||||
"Style Renderer": "样式渲染器",
|
"Style Renderer": "样式渲染器",
|
||||||
"Choose the default Maputnik renderer for this style.": "为这种样式选择默认的Maputnik渲染器。",
|
"Choose the default Maputnik renderer for this style.": "为这种样式选择默认的Maputnik渲染器。",
|
||||||
"Language": "语言",
|
"Language": "语言",
|
||||||
"<0>Open in OSM</0> — Opens the current view on openstreetmap.org": "在 openstreetmap.org 打开当前视图",
|
"<0>Open in OSM</0> — Opens the current view on openstreetmap.org": "在 openstreetmap.org 打开当前视图",
|
||||||
"Layer options": "图层选项",
|
"Layer options": "图层选项"
|
||||||
"Paint properties": "绘制属性",
|
|
||||||
"Layout properties": "布局属性",
|
|
||||||
"General layout properties": "常规布局属性",
|
|
||||||
"Text layout properties": "文本布局属性",
|
|
||||||
"Icon layout properties": "图标布局属性",
|
|
||||||
"Text paint properties": "文本绘制属性",
|
|
||||||
"Icon paint properties": "图标绘制属性"
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -3,7 +3,7 @@ import react from "@vitejs/plugin-react";
|
|||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import istanbul from "vite-plugin-istanbul";
|
import istanbul from "vite-plugin-istanbul";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => ({
|
||||||
server: {
|
server: {
|
||||||
port: 8888,
|
port: 8888,
|
||||||
},
|
},
|
||||||
@@ -27,7 +27,8 @@ export default defineConfig({
|
|||||||
forceBuildInstrument: true, //Instrument the source code for cypress runs
|
forceBuildInstrument: true, //Instrument the source code for cypress runs
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
base: mode === "desktop" ? "/" : "/maputnik/",
|
||||||
define: {
|
define: {
|
||||||
global: "window",
|
global: "window"
|
||||||
},
|
},
|
||||||
});
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user