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

fix: types of getPointInView and getCoordinateFromView #601

Merged
merged 1 commit into from
Jan 12, 2025

Conversation

KiwiKilian
Copy link
Collaborator

Fixes #600

I didn't change implementation, the types where wrong for what's returned.

  • The geographical coordinates are GeoJSON.Position and not GeoJSON.Point
  • Pixel coordinates are [x: number, y: number]
    • Just a better documented variant of [number, number]

@KiwiKilian KiwiKilian requested a review from tyrauber January 11, 2025 20:01
@KiwiKilian
Copy link
Collaborator Author

@brentforder please have a look, does this look right to you?

@brentforder
Copy link

brentforder commented Jan 11, 2025

@brentforder please have a look, does this look right to you?

Thank you very much @KiwiKilian!
It looks great for #600, except for a question coming up for me about how important consistency is for representing view coordinates now that I noticed these other variants in the library code:

  • MapViewRef queryRenderedFeaturesInRect(point: [screenPointX: number, screenPointY: number] ...)
  • PointAnnotation type FeaturePayload = GeoJSON.Feature<GeoJSON.Point, { screenPointX: number; screenPointY: number; }>
  • OnPressEvent { ... point { x: number; y: number }}

I'm thinking it might be good to consider these ^ variants of view coordinates here if we're deciding on a new, consistent representation. Considering the variants, I don't know if [x: number, y: number] is better or worse than { x: number; y: number }.

FWIW, ChatGPT produced this comparison for me:

Consideration [x: number, y: number] (Labeled Tuple) [x, y] (Standard Array) { x, y } (Object)
Semantics for View Coordinates ✅ Reasonable: x and y labeled as properties aligns well with view coordinates but still relies on developer awareness. ❌ Weak: [x, y] is overly generic, doesn’t convey its association with view-space coordinates, and there's no reason for view coordinates to be ordered. ✅ Strongest: { x, y } directly reflects the properties of a point in view coordinates.
Clarity ✅ Clearer than [x, y] during development due to TypeScript labels, but not at runtime.
❌ At runtime, it’s just an array, and indices (0, 1) lack explicit meaning.
❌ Ambiguous: users must know or document that 0 is x and 1 is y. ✅ Best clarity: x and y are explicit and self-documenting.
Runtime Safety ❌ Error-prone at runtime since the tuple degrades to an array without explicit names for elements. ❌ Error-prone: Misinterpreting indices (0 for x and 1 for y) is possible without documentation. ✅ Safe: Clear field names (x, y) reduce ambiguity and errors.
TypeScript Support ✅ Labels make access clear in TypeScript.
❌ Lacks runtime reflection of these labels
✅ Supported but lacks semantic richness.
❌ Indices (0, 1) are less descriptive.
✅ Best support: x and y are named fields, providing full clarity in both development and runtime contexts.
Compactness ✅ Compact like an array. ✅ Most compact option. ❌ Slightly more verbose.
Performance ✅ Compact and efficient. ✅ Compact and efficient. ❌ Slightly slower due to object overhead, but negligible.

@KiwiKilian
Copy link
Collaborator Author

Good point! This should be something for v11, as it will require breaking changes. Merging this fix for now.

See #602 for follow-up.

@KiwiKilian KiwiKilian merged commit c7537b5 into maplibre:beta Jan 12, 2025
13 checks passed
github-actions bot pushed a commit that referenced this pull request Jan 12, 2025
# [10.0.0-beta.20](v10.0.0-beta.19...v10.0.0-beta.20) (2025-01-12)

### Bug Fixes

* types of `getPointInView` and `getCoordinateFromView` ([#601](#601)) ([c7537b5](c7537b5))
Copy link

🎉 This PR is included in version 10.0.0-beta.20 🎉

The release is available on:

Your semantic-release bot 📦🚀

@KiwiKilian KiwiKilian deleted the fix/point-types branch January 14, 2025 08:05
github-actions bot pushed a commit that referenced this pull request Jan 14, 2025
# [10.0.0](v9.1.0...v10.0.0) (2025-01-14)

### Bug Fixes

* `VectorSource` `onPress` returning null geometry on Android ([250ee6f](250ee6f)), closes [#538](#538)
* `VectorSource` `onPress` returning null geometry on Android ([a130786](a130786)), closes [#538](#538)
* add @babel/plugin-transform-private-methods for jest ([3a2188f](3a2188f))
* add generic expo config plugin to remove duplicate signature ([#453](#453)) ([2671381](2671381))
* added GeometryCollection to GeoJSONUtils ([#556](#556)) ([e6b7a66](e6b7a66))
* allow MapView and Images to have no children ([#521](#521)) ([1e35bf6](1e35bf6))
* allow resetting contentInset with 0 ([#468](#468)) ([1fe42c6](1fe42c6))
* android example crashing on launch ([#372](#372)) ([aeef5c3](aeef5c3))
* cleanup yarn setup ([#463](#463)) ([d9a4d30](d9a4d30))
* corepack enable  on publish workflow ([2d13f33](2d13f33))
* correct types in MapView ([#268](#268)) ([0ea35c4](0ea35c4))
* disable code signing for release builds ([b3cf088](b3cf088))
* disable library code signing ([22030dd](22030dd))
* empty pbxproj and dwarf-with-dsym plugin config for EAS ([#458](#458)) ([0d54b46](0d54b46))
* expo-app should load library from workspace:. ([016b44a](016b44a))
* export custom header methods ([#552](#552)) ([58abdb0](58abdb0)), closes [#551](#551)
* group dependabot commits by core, dev and example ([#165](#165)) ([b697978](b697978))
* keep [@ts-ignore](https://github.com/ts-ignore) for headingIcon in library [#476](#476) ([#477](#477)) ([ef62454](ef62454))
* make `follow` props on `Camera` deterministic ([#550](#550)) ([e9256e7](e9256e7))
* make MarkerView props with defaults optional ([#460](#460)) ([185cf3e](185cf3e))
* plugin for debug simulator ([#164](#164)) ([06b23d4](06b23d4))
* remove AbortController test mock ([#403](#403)) ([698b558](698b558))
* round compass margins and attribution position to nearest integers [android] ([#294](#294)) ([c89c842](c89c842))
* setMaxAnimationFps on null ([#440](#440)) ([2884256](2884256))
* style expressions ([#466](#466)) ([2202908](2202908))
* trigger release after npm maintenance ([#548](#548)) ([f0fca00](f0fca00))
* types of `getPointInView` and `getCoordinateFromView` ([#601](#601)) ([c7537b5](c7537b5))
* updated Mapbox callstack check for iOS custom headers to check for MapLibre instead ([#461](#461)) ([a6d6216](a6d6216))
* use UIManager exported from react-native ([#511](#511)) ([a4030b5](a4030b5))
* yarn implementation ([#419](#419)) ([39233b1](39233b1))

### Continuous Integration

* add semantic release ([#526](#526)) ([069b6c5](069b6c5))

### Features

* add Expo plugin props ([#589](#589)) ([51fbb00](51fbb00))
* align react and react-native versions for development ([b92abfe](b92abfe))
* allow using google location engine on Android ([#586](#586)) ([92ffdb7](92ffdb7))
* configure packages/examples ([c4510c3](c4510c3))
* drop `MapLibreGL` naming and deprecate `export default` ([#567](#567)) ([aa0c73d](aa0c73d))
* export RegionPayload and MapLibreRNEvent types ([#544](#544)) ([b342f1b](b342f1b))
* extract android UserLocation FPS ([#428](#428)) ([8c0abaa](8c0abaa))
* make `setAccessToken(null)` obsolete ([#593](#593)) ([df44b48](df44b48))
* make Camera pure ([#471](#471)) ([23ecf88](23ecf88))
* MapLibre Android SDK 11.5.0 ([#455](#455)) ([042b759](042b759))
* monorepo configuration ([343e7ac](343e7ac))
* mv example packages/react-native-app ([5c9d3d0](5c9d3d0))
* mv examples, styles, assets, utils and scenes to packages/examples ([13600fe](13600fe))
* packages/expo-app ([c01abd5](c01abd5))
* remove deprecations ([#543](#543)) ([0c41ada](0c41ada))
* remove duplicate of `OfflinePackStatus` type ([#542](#542)) ([9e231b7](9e231b7))
* remove Style component ([#547](#547)) ([9d4c458](9d4c458))
* remove style property enums ([#558](#558)) ([b89a0dd](b89a0dd))
* setup build step ([#504](#504)) ([a017d64](a017d64))
* shared dependencies through packages/examples ([01a9586](01a9586))
* support new arch through interop layer ([#483](#483)) ([951e9cf](951e9cf))
* unify `MapView`s `styleURL` and `styleJSON` to `mapStyle` ([#559](#559)) ([7d22f16](7d22f16))
* update maplibre native version ([#61](#61)) ([25c418a](25c418a))
* upgrade [@Turf](https://github.com/turf) to v7 and remove geo utils ([#478](#478)) ([a45fc55](a45fc55))
* upgrade Android gradle setup ([#539](#539)) ([761ae0d](761ae0d))
* upgrade dependencies ([#535](#535)) ([047f87f](047f87f))
* upgrade MapLibre Native ([#563](#563)) ([d2b7f5d](d2b7f5d))
* upgrade MapLibre Native Android to v11.8.0 ([#597](#597)) ([410d0c3](410d0c3))
* upgrade MapLibre Native iOS to v6.10.0 ([#598](#598)) ([b596c76](b596c76))
* use `withPodfile` instead of `withDangerousMod` in Expo Plugin ([#587](#587)) ([56d02e1](56d02e1))

### BREAKING CHANGES

* remove `styleURL` and `styleJSON` from `MapView`, use `mapStyle` instead
* Removed style property enums
* Remove `Style` component, use `styleJSON` of `MapView` instead
* - Deprecated `UserTrackingModes` is removed in favor of `UserTrackingMode`
- Removed deprecated `setCamera` from `MapView`
- Removed deprecated `byId` methods from `ShapeSource`
- Removed deprecated `children` from `SymbolSource`
- Removed deprecated `assets` key from `Images`
- Removed deprecated event keys
* Replace OfflineProgressStatus with OfflinePackStatus
* Upgrade native packages and migrate components

* ci: move native builds to review

* ci: run release immediate for debugging

* ci: use android working directory for build

* docs: remove RELEASE.md

* chore: remove manual changelog task

* ci: enable release on beta branch

* ci: keep default tagFormat

* ci: setup npm tag fixes

* ci: run review on mr to beta

* ci: run fix tags on beta

* ci: fix name

* ci: clarify workflow_call

* ci: disable debugging

* ci: run fix tags in pr

* ci: setup fix tags to run on beta

* docs: prepare changelog for semantic-release

* ci: remove fix npm tags workflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants