-
Notifications
You must be signed in to change notification settings - Fork 1
Handle geojson layers like other layers #605
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
digitaltom
wants to merge
8
commits into
main
Choose a base branch
from
unify_layer_handling
base: main
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
c336539
Handle geojson layers like other layers
digitaltom e30eb46
Update @turf/bbox to version 7.3.3
depfu[bot] 0fe1003
Update @turf/boolean-point-on-line to version 7.3.3
depfu[bot] 65b7335
Update rubycritic to version 4.12.0
depfu[bot] ece1224
Update globals to version 17.3.0
depfu[bot] a28ebd3
generalize layer - source naming
digitaltom e78f365
Apply suggestion from @Copilot
digitaltom 875194f
only select geojson features for edit
digitaltom 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| import { Controller } from '@hotwired/stimulus' | ||
| import { mapChannel } from 'channels/map_channel' | ||
| import { geojsonData } from 'maplibre/map' | ||
| import { defaultLineWidth, featureColor, featureOutlineColor } from 'maplibre/styles' | ||
| import { AnimateLineAnimation, AnimatePolygonAnimation, animateViewFromProperties } from 'maplibre/animations' | ||
| import { status } from 'helpers/status' | ||
| import { showFeatureDetails, highlightedFeatureId } from 'maplibre/feature' | ||
| import * as functions from 'helpers/functions' | ||
| import * as dom from 'helpers/dom' | ||
| import { draw, select, unselect } from 'maplibre/edit' | ||
| import { getFeature } from 'maplibre/layers/layers' | ||
|
|
||
| let easyMDE | ||
|
|
||
|
|
@@ -33,12 +33,12 @@ export default class extends Controller { | |
| this.show_feature_edit_ui() | ||
|
|
||
| // add feature to draw | ||
| const feature = this.getFeature() | ||
| const feature = this.getSelectedFeature() | ||
| draw.add(feature) | ||
| select(feature) | ||
| } else { | ||
| // repeated click on the current edit mode returns to feature description | ||
| showFeatureDetails(this.getFeature()) | ||
| showFeatureDetails(this.getSelectedFeature()) | ||
| unselect() | ||
| } | ||
| document.querySelector('#feature-edit-raw .error').innerHTML = '' | ||
|
|
@@ -49,7 +49,7 @@ export default class extends Controller { | |
| if (this.element.classList.contains('modal-pull-down')) { | ||
| this.pullUpModal(this.element) | ||
| } | ||
| const feature = this.getFeature() | ||
| const feature = this.getSelectedFeature() | ||
| dom.showElements(['#feature-edit-ui', '#button-add-label', '#button-add-desc']) | ||
| dom.hideElements(['#feature-edit-raw', '#feature-label', '#feature-desc']) | ||
| functions.e('em-emoji-picker', e => { e.remove() }) | ||
|
|
@@ -134,15 +134,15 @@ export default class extends Controller { | |
| if (this.element.classList.contains('modal-pull-down')) { | ||
| this.pullUpModal(this.element) | ||
| } | ||
| const feature = this.getFeature() | ||
| const feature = this.getSelectedFeature() | ||
| dom.hideElements(['#feature-edit-ui']) | ||
| dom.showElements(['#feature-edit-raw']) | ||
| document.querySelector('#feature-edit-raw textarea') | ||
| .value = JSON.stringify(feature.properties, undefined, 2) | ||
| } | ||
|
|
||
| show_add_label () { | ||
| document.querySelector('#feature-label input').value = this.getFeature().properties.label || null | ||
| document.querySelector('#feature-label input').value = this.getSelectedFeature().properties.label || null | ||
| dom.hideElements(['#button-add-label']) | ||
| dom.showElements(['#feature-label']) | ||
| } | ||
|
|
@@ -153,7 +153,7 @@ export default class extends Controller { | |
| // https://github.com/Ionaru/easy-markdown-editor | ||
| await import('easymde') // import EasyMDE UMD bundle | ||
| if (easyMDE) { easyMDE.toTextArea() } | ||
| document.querySelector('#feature-desc-input').value = this.getFeature().properties.desc || '' | ||
| document.querySelector('#feature-desc-input').value = this.getSelectedFeature().properties.desc || '' | ||
| easyMDE = new window.EasyMDE({ | ||
| element: document.getElementById('feature-desc-input'), | ||
| placeholder: 'Add a description text', | ||
|
|
@@ -168,7 +168,7 @@ export default class extends Controller { | |
| } | ||
|
|
||
| updateDesc () { | ||
| const feature = this.getFeature() | ||
| const feature = this.getSelectedFeature() | ||
| try { | ||
| if (easyMDE && feature.properties.desc !== easyMDE.value()) { | ||
| feature.properties.desc = easyMDE.value() | ||
|
|
@@ -181,7 +181,7 @@ export default class extends Controller { | |
| } | ||
|
|
||
| saveFeature () { | ||
| const feature = this.getFeature() | ||
| const feature = this.getSelectedFeature() | ||
| status('Saving feature ' + feature.id) | ||
| // send shallow copy of feature to avoid changes during send | ||
| mapChannel.send_message('update_feature', { ...feature }) | ||
|
|
@@ -214,16 +214,16 @@ export default class extends Controller { | |
| modal.style.removeProperty('height') | ||
| } | ||
|
|
||
| getFeature () { | ||
| getSelectedFeature () { | ||
| const id = this.featureIdValue | ||
| return geojsonData.features.find(f => f.id === id) | ||
| return getFeature(id) | ||
| } | ||
|
Comment on lines
+217
to
220
|
||
|
|
||
| async copy(event) { | ||
| if (functions.isFormFieldFocused()) { return } | ||
| if (!highlightedFeatureId) { return } | ||
|
|
||
| const feature = this.getFeature() | ||
| const feature = this.getSelectedFeature() | ||
| if (feature) { | ||
| await navigator.clipboard.writeText(JSON.stringify(feature)) | ||
| event.preventDefault() | ||
|
|
@@ -234,7 +234,7 @@ export default class extends Controller { | |
| } | ||
|
|
||
| animate () { | ||
| const feature = this.getFeature() | ||
| const feature = this.getSelectedFeature() | ||
| console.log('Animating ' + feature.id) | ||
| if (feature.geometry.type === 'LineString') { | ||
| new AnimateLineAnimation().run(feature) | ||
|
|
||
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
Oops, something went wrong.
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.
getEditFeature()callsgetFeature(id)but this file does not importgetFeature, so the controller will crash when invoked. ImportgetFeaturefrommaplibre/layers/layers(and consider handlingnullif the feature cannot be found).