Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for local pmtiles tile package (via drag and drop) #1025

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

prusswan
Copy link

This adds support for using local pmtiles tile packages that can be loaded via drag and drop (and possibly file picker). The behavior is very similar to https://pmtiles.io. These tile packages can already be referenced/used as a data source in the style, e.g. Tile URL: pmtiles://filename.pmtiles/{z}/{x}/{y}, just lacking a way to load the content.

Visual changes:

Added new spot in the top toolbar for dropping pmtiles package, also works with Inspect:
image

Launch Checklist

  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Add an entry to CHANGELOG.md under the ## main section.

@codecov-commenter
Copy link

codecov-commenter commented Jan 24, 2025

Codecov Report

Attention: Patch coverage is 87.87879% with 4 lines in your changes missing coverage. Please review.

Project coverage is 64.46%. Comparing base (af01346) to head (cbbac9e).
Report is 59 commits behind head on main.

Files with missing lines Patch % Lines
src/components/App.tsx 33.33% 2 Missing ⚠️
src/components/MapMaplibreGl.tsx 88.88% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1025      +/-   ##
==========================================
+ Coverage   59.84%   64.46%   +4.61%     
==========================================
  Files         104      104              
  Lines        3011     5873    +2862     
  Branches      680     1728    +1048     
==========================================
+ Hits         1802     3786    +1984     
- Misses       1209     2085     +876     
- Partials        0        2       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/components/App.tsx Outdated Show resolved Hide resolved
src/components/AppToolbar.tsx Outdated Show resolved Hide resolved
src/components/MapMaplibreGl.tsx Outdated Show resolved Hide resolved
src/components/AppToolbar.tsx Outdated Show resolved Hide resolved
@prusswan prusswan force-pushed the support-local-pmtiles branch from 28794e9 to b4e63e4 Compare January 24, 2025 08:18
@prusswan prusswan force-pushed the support-local-pmtiles branch from b4e63e4 to a2809a9 Compare January 24, 2025 08:26
src/components/App.tsx Outdated Show resolved Hide resolved
@prusswan prusswan force-pushed the support-local-pmtiles branch from 921f304 to 29d78b2 Compare January 26, 2025 09:44
src/components/App.tsx Outdated Show resolved Hide resolved
@HarelM
Copy link
Collaborator

HarelM commented Jan 26, 2025

Looking at this holistically, I'm not sure this is the right way to achieve this.
Add sources as files may require support other file types like shp files, geojson etc, and the idea of this editor is to allow editing the style and I'm not sure it should handle loading of file like what is suggested here.
I don't know...

@prusswan prusswan force-pushed the support-local-pmtiles branch from 29d78b2 to a2572c2 Compare January 26, 2025 09:52
@prusswan
Copy link
Author

Looking at this holistically, I'm not sure this is the right way to achieve this. Add sources as files may require support other file types like shp files, geojson etc, and the idea of this editor is to allow editing the style and I'm not sure it should handle loading of file like what is suggested here. I don't know...

I agree that this functionality is only feasible for PMTiles (up to a certain size) and is aided by the design and implementation of PMTiles library itself.

@HarelM
Copy link
Collaborator

HarelM commented Jan 26, 2025

I've posted a message on slack, let's see what the community thinks about this feature.

Copy link
Collaborator

@louwers louwers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion there should be some way this feature is documented. Ideally it should be made discoverable. I suggest that when you drag anything onto the screen, you see a message saying what file types are supported. If you drag something that has an unsupported file type, you should get a message which file types are supported.

We can then extend the supported file types, for example, also allowing a style JSON to be dragged-and-dropped.

Copy link
Collaborator

@louwers louwers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be tested with Cypress as well.

@HarelM
Copy link
Collaborator

HarelM commented Jan 27, 2025

I'm not sure It can be tested since dragging a file into the browser requires the ability to connect with the OS or something.
Not sure, but I won't be surprised if this can't be tested.

@prusswan prusswan force-pushed the support-local-pmtiles branch from 9b0f37a to d6cde2f Compare January 27, 2025 13:40
@prusswan
Copy link
Author

In my opinion there should be some way this feature is documented. Ideally it should be made discoverable. I suggest that when you drag anything onto the screen, you see a message saying what file types are supported. If you drag something that has an unsupported file type, you should get a message which file types are supported.

I have set the file type to allow for .pmtiles only, this is reflected in the file picker. If invalid files are dragged instead, file rejection messages will be shown in console and alert dialog.

As for documentation, this can be a new section under the wiki?

@HarelM
Copy link
Collaborator

HarelM commented Jan 28, 2025

As far as I understand, and I might be wrong, this drag-and-drop is from inside the browser as opposed to this feature where you drag a file from the file viewer into the browser...

@louwers
Copy link
Collaborator

louwers commented Jan 28, 2025

Sorry, should have been more specific. This one looks like it should work:

Selects a file or files in an HTML5 input element or simulates dragging a file or files into the browser.

@HarelM
Copy link
Collaborator

HarelM commented Jan 28, 2025

Ahh, found what you were referring to here in the Cypress docs:
https://docs.cypress.io/api/commands/selectfile

cy.document().selectFile('file.json', { action: 'drag-drop' })

@prusswan
Copy link
Author

prusswan commented Jan 28, 2025

e2e test added: I wanted to test for popup but I simply could not get mouseover to work, so I settled for image diff. Hope this is not too big of change..

@prusswan prusswan requested a review from louwers January 28, 2025 15:55
@@ -1,5 +1,6 @@
import { defineConfig } from "cypress";
import { createRequire } from "module";
import getCompareSnapshotsPlugin from 'cypress-image-diff-js/plugin';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a simpler solution without image diff? Checking that there's no error in case the file type is OK and check that the error appears when the file isn't?

@prusswan prusswan force-pushed the support-local-pmtiles branch from 40bfbef to e32b006 Compare January 28, 2025 21:59
return e.errors.map(f => f.message).join("\n")
}).join("\n");
console.error("Dropzone file rejected:", errorMessageLine);
alert(errorMessageLine);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure there are better ways to notify the user of a problem, not to mention this is not translated...

const errorMessageLine = r.map(e => {
return e.errors.map(f => f.message).join("\n")
}).join("\n");
console.error("Dropzone file rejected:", errorMessageLine);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason to both print to the console and notify the user, so this can be removed I guess.

}

onFileRejected = (r: FileRejection[]) => {
const errorMessageLine = r.map(e => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it critical to collect all the error messages?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can just show the first error and apply translation for it, if that is okay with you.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning on translating all the errors?
I would simply present a generic error message to the user about failure to open the provided file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can log the errors from react-dropzone to console, and show a translatable error message to the user.

this.state.pmtilesProtocol!.add(file); // this is necessary for non-HTTP sources

if (map) {
file.getMetadata().then((metadata: any) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does metadata has a better type? topojson maybe?

@prusswan prusswan force-pushed the support-local-pmtiles branch from 087d113 to 27d8601 Compare January 28, 2025 23:05
@prusswan prusswan force-pushed the support-local-pmtiles branch from 27d8601 to cbbac9e Compare January 28, 2025 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants