forked from NASA-AMMOS/MMGIS
-
Notifications
You must be signed in to change notification settings - Fork 0
Emit feature:click on the bus for every vector feature click #292
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
Open
BhattaraiSijan
wants to merge
8
commits into
development
Choose a base branch
from
feat/feature-click-event
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2741535
Emit feature:click on the bus for every vector feature click
BhattaraiSijan c579f94
Merge remote-tracking branch 'origin/development' into feat/feature-c…
BhattaraiSijan 2afad18
feature:click: snapshot clicked feature through the vector-tile debounce
BhattaraiSijan a60cf9f
feature:click: centralize emit guards; respect disableLayerInteractio…
BhattaraiSijan 8e4fa2f
feature:click: emit a copied feature instead of a live core reference
BhattaraiSijan 6c5f70b
feature:click: resolve layerName through asLayerUUID on every path
BhattaraiSijan bdcc1ad
feature:click: docs row matches actual emit behavior
BhattaraiSijan 3d1b786
feature:click: extract payload builder and cover it with tests
BhattaraiSijan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export function buildFeatureClickPayload(feature, layerName, e) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this method seems overcomplicated, many unnecessary if conditionals and redundant assignments. can you simplify? |
||
| if (feature == null) return null | ||
| const featureCopy = { ...feature } | ||
| if (feature.geometry !== undefined) featureCopy.geometry = feature.geometry | ||
| if (feature.properties != null) | ||
| featureCopy.properties = { ...feature.properties } | ||
| return { | ||
| feature: featureCopy, | ||
| layerName: layerName ?? null, | ||
| latlng: e?.latlng ? { lat: e.latlng.lat, lng: e.latlng.lng } : null, | ||
| pixel: e?.containerPoint | ||
| ? { x: e.containerPoint.x, y: e.containerPoint.y } | ||
| : null, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { test, expect } from 'vitest' | ||
| import { buildFeatureClickPayload } from '../../src/essence/Basics/Map_/featureClickPayload.js' | ||
|
|
||
| const clickEvent = { | ||
| latlng: { lat: 34.2, lng: -118.1 }, | ||
| containerPoint: { x: 120, y: 340 }, | ||
| } | ||
|
|
||
| test.describe('buildFeatureClickPayload', () => { | ||
| test('returns null without a feature', () => { | ||
| expect(buildFeatureClickPayload(null, 'uuid-1', clickEvent)).toBeNull() | ||
| expect( | ||
| buildFeatureClickPayload(undefined, 'uuid-1', clickEvent) | ||
| ).toBeNull() | ||
| }) | ||
|
|
||
| test('maps a full click to the payload shape', () => { | ||
| const feature = { | ||
| type: 'Feature', | ||
| properties: { name: 'station-a' }, | ||
| geometry: { type: 'Point', coordinates: [-118.1, 34.2] }, | ||
| } | ||
| expect(buildFeatureClickPayload(feature, 'uuid-1', clickEvent)).toEqual( | ||
| { | ||
| feature, | ||
| layerName: 'uuid-1', | ||
| latlng: { lat: 34.2, lng: -118.1 }, | ||
| pixel: { x: 120, y: 340 }, | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| test('copies the feature and its properties', () => { | ||
| const feature = { | ||
| type: 'Feature', | ||
| properties: { name: 'station-a' }, | ||
| geometry: {}, | ||
| } | ||
| const payload = buildFeatureClickPayload(feature, 'uuid-1', clickEvent) | ||
| expect(payload.feature).not.toBe(feature) | ||
| expect(payload.feature.properties).not.toBe(feature.properties) | ||
|
|
||
| feature.properties.appendedLater = true | ||
| expect(payload.feature.properties.appendedLater).toBeUndefined() | ||
|
|
||
| payload.feature.properties.name = 'mutated-by-consumer' | ||
| expect(feature.properties.name).toBe('station-a') | ||
| }) | ||
|
|
||
| test('preserves a non-enumerable lazy geometry getter', () => { | ||
| const feature = { type: 'Feature', properties: {} } | ||
| Object.defineProperty(feature, 'geometry', { | ||
| enumerable: false, | ||
| get: () => ({ type: 'Point', coordinates: [10, 20] }), | ||
| }) | ||
| const payload = buildFeatureClickPayload(feature, 'uuid-1', clickEvent) | ||
| expect(payload.feature.geometry).toEqual({ | ||
| type: 'Point', | ||
| coordinates: [10, 20], | ||
| }) | ||
| }) | ||
|
|
||
| test('nulls latlng and pixel when the event lacks them', () => { | ||
| const feature = { type: 'Feature', properties: {} } | ||
| expect(buildFeatureClickPayload(feature, 'uuid-1', null)).toEqual({ | ||
| feature, | ||
| layerName: 'uuid-1', | ||
| latlng: null, | ||
| pixel: null, | ||
| }) | ||
| expect( | ||
| buildFeatureClickPayload(feature, 'uuid-1', { latlng: null }) | ||
| ).toMatchObject({ latlng: null, pixel: null }) | ||
| }) | ||
|
|
||
| test('keeps zero-valued coordinates and pixels', () => { | ||
| const feature = { type: 'Feature', properties: {} } | ||
| const payload = buildFeatureClickPayload(feature, 'uuid-1', { | ||
| latlng: { lat: 0, lng: 0 }, | ||
| containerPoint: { x: 0, y: 0 }, | ||
| }) | ||
| expect(payload.latlng).toEqual({ lat: 0, lng: 0 }) | ||
| expect(payload.pixel).toEqual({ x: 0, y: 0 }) | ||
| }) | ||
|
|
||
| test('passes layerName through and nulls it when absent', () => { | ||
| const feature = { type: 'Feature', properties: {} } | ||
| expect( | ||
| buildFeatureClickPayload(feature, 'uuid-1', clickEvent).layerName | ||
| ).toBe('uuid-1') | ||
| expect( | ||
| buildFeatureClickPayload(feature, null, clickEvent).layerName | ||
| ).toBeNull() | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what is this for?