-
-
Notifications
You must be signed in to change notification settings - Fork 414
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
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # src/components/MapMaplibreGl.tsx
fixed TypeScript errors
Codecov ReportAttention: Patch coverage is
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. |
28794e9
to
b4e63e4
Compare
b4e63e4
to
a2809a9
Compare
921f304
to
29d78b2
Compare
Looking at this holistically, I'm not sure this is the right way to achieve this. |
29d78b2
to
a2572c2
Compare
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. |
I've posted a message on slack, let's see what the community thinks about this feature. |
There was a problem hiding this 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.
There was a problem hiding this 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.
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. |
9b0f37a
to
d6cde2f
Compare
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? |
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... |
Sorry, should have been more specific. This one looks like it should work:
|
Ahh, found what you were referring to here in the Cypress docs: cy.document().selectFile('file.json', { action: 'drag-drop' }) |
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.. |
cypress.config.ts
Outdated
@@ -1,5 +1,6 @@ | |||
import { defineConfig } from "cypress"; | |||
import { createRequire } from "module"; | |||
import getCompareSnapshotsPlugin from 'cypress-image-diff-js/plugin'; |
There was a problem hiding this comment.
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?
40bfbef
to
e32b006
Compare
src/components/AppToolbar.tsx
Outdated
return e.errors.map(f => f.message).join("\n") | ||
}).join("\n"); | ||
console.error("Dropzone file rejected:", errorMessageLine); | ||
alert(errorMessageLine); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/components/MapMaplibreGl.tsx
Outdated
this.state.pmtilesProtocol!.add(file); // this is necessary for non-HTTP sources | ||
|
||
if (map) { | ||
file.getMetadata().then((metadata: any) => { |
There was a problem hiding this comment.
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?
087d113
to
27d8601
Compare
27d8601
to
cbbac9e
Compare
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:
Launch Checklist
CHANGELOG.md
under the## main
section.