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

First pass / rough draft of HTMLMapmlViewerElement.matchMedia API, #1008

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

prushforth
Copy link
Member

@prushforth prushforth commented Nov 4, 2024

  • add matchMedia to <map> element API
  • document matchMedia API in en & fr
  • add/ update documentation of mapml-extension to for prefers-map-content
  • update mapml-extension to add tests for multiple prefers-map-content values

Copy link
Member Author

@prushforth prushforth left a comment

Choose a reason for hiding this comment

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

Looks good, see suggestions/comments.

<map-input name="z" type="zoom" value="18" min="0" max="18"></map-input>
<map-input name="x" type="location" units="tilematrix" axis="column" min="0" max="262144"></map-input>
<map-input name="y" type="location" units="tilematrix" axis="row" min="0" max="262144"></map-input>
<map-link rel="tile" tref="https://tile.openstreetmap.org/{z}/{x}/{y}.png"></map-link>
Copy link
Member Author

Choose a reason for hiding this comment

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

I have been starting to create tests that have no tiles in them at all, so that there's no network waiting going on, or minimal if possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

By that, does it mean we just won't have a base map for test cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well we'll have a map, but the layer will be sort of fake, in that the tref attribute should point to nothing. Let me see if I can find an example...

Copy link
Member Author

@prushforth prushforth Nov 25, 2024

Choose a reason for hiding this comment

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

Here's an example: https://github.com/Maps4HTML/MapML.js/blob/main/test/e2e/elements/map-layer/layer-extent.html the tiles just return 404 not found, but it doesn't harm the test afaik

Copy link
Member Author

@prushforth prushforth left a comment

Choose a reason for hiding this comment

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

Overall pretty good! Apply some of the cleanup suggestions and I think we can probably merge it. Let's see what @AliyanH thinks...

@AliyanH AliyanH marked this pull request as ready for review November 27, 2024 17:15
@AliyanH
Copy link
Member

AliyanH commented Nov 27, 2024

Will we also sync web-map.js with the matchMedia API?

Copy link
Member

@AliyanH AliyanH left a comment

Choose a reason for hiding this comment

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

Looks pretty cool! Especially with the support for extents!

@@ -986,7 +989,256 @@ export class HTMLMapmlViewerElement extends HTMLElement {
}
});
}
matchMedia(query) {
Copy link
Member

Choose a reason for hiding this comment

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

For documentation - all possible features:

  • prefers-color-scheme (i.e. dark or light)
  • prefers-lang (i.e. en, fr)
  • map-projection (i.e. OSMTILE, CBMTILE)
  • map-zoom (i.e. > or < Int)
  • prefers-map-content
  • map-top-left-easting (i.e. > or < Double)
  • map-bottom-right-easting (i.e. > or < Double)
  • map-bottom-right-northing (i.e. > or < Double)
  • map-top-left-northing (i.e. > or < Double)

};
}
},
'map-top-left-easting': {
Copy link
Member

Choose a reason for hiding this comment

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

map-top-left-easting (i.e. > or < Double)
map-bottom-right-easting (i.e. > or < Double)
map-bottom-right-northing (i.e. > or < Double)
map-top-left-northing (i.e. > or < Double)

May be a little hard for users to understand/utilize the extent feature queries. A nice graphic in the docs or something similar would be needed to explain the extents and how to properly use them via media queries

'prefers-lang': {
type: 'discrete',
get values() {
return [navigator.language.substring(0, 2)];
Copy link
Member

Choose a reason for hiding this comment

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

language subtag may not always be of 2 characters i.e. https://datatracker.ietf.org/doc/html/rfc5646#appendix-A. Would it instead be better to use .split('-')[0]?

valueType: 'integer',
canBeNegative: false,
canBeZero: true,
get extraValues() {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this extraValues, while all the others are just values? Did not find this being used anywhere

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, I think it can be removed... tbd

@prushforth
Copy link
Member Author

Will we also sync web-map.js with the matchMedia API?

oh, yes, we need to make a to-do list for sure, and this is on it. Also tests (well a copy of existing tests for matchMedia) to apply to <map is="web-map">.matchMedia(...)

@prushforth
Copy link
Member Author

prushforth commented Nov 27, 2024

Will we also sync web-map.js with the matchMedia API?

oh, yes, we need to make a to-do list for sure, and this is on it. Also tests (well a copy of existing tests for matchMedia) to apply to .matchMedia(...)

I moved matchMedia into its own file. To be determined: best way to apply existing tests to both <mapml-viewer> and <map is=web-map>

depends on media-query-parser and media-query-solver.

Use multi-select values of contentPreference sent by mapml-extension
(relies on M.options.contentPreference being an array).

Update map-zoom handling to compare current map zoom against query

Add window.matchMedia query + event listener for color-scheme changes,
allows map to adapt without having to shake it.

Change the way prefers-lang selects the language (use navigator.language,
not navigator.languages, because other values aren't of use).

Make matchMedia(query).matches a boolean value

Added tests for map-zoom and prefers-color-scheme

Added tests for bounding box and map-projection

Added test for combined matchMedia API

Add matchMedia to web-map.js
Fix up some other stuff that had fallen through the cracks of keeping
mapml-viewer and web-map in sync

Create elementSupport/viewers/matchMedia.js, de-duplicates code
Import matchMedia from matchMedia.js into both mapml-viewer and web-map

Add MIT license for media-query-parser and -solver
Update version to 0.15.0

Added web-map test for combined-matchMedia

Add ${mapType} to title of each test so logs are explicit
Use map.getByTestId, on id generated to be unique within parent map
@prushforth prushforth merged commit 3a006ea into Maps4HTML:main Dec 3, 2024
1 check passed
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.

3 participants