From 30c8a435910ad015e19cbabdd982399591740cda Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Thu, 1 Feb 2024 23:23:00 +0100 Subject: [PATCH 1/2] Show feature title in edit window --- README.md | 9 +-------- app/javascript/controllers/feature_controller.js | 7 +++---- app/javascript/map/interactions/edit.js | 4 ++-- app/javascript/map/styles.js | 3 ++- app/views/maps/show.html.haml | 3 ++- spec/features/feature_edit_spec.rb | 2 +- 6 files changed, 11 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index ccd5ec6d..481b8a70 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,7 @@ https://excalidraw.com/#json=m0CjM7w_E-dtFDKmvQvIf,K07A5jDq8rCCqgmJMkjElw This app supports and stores data in an extended version of the [mapbox simplestyle spec](https://github.com/mapbox/simplestyle-spec/tree/master/1.1.0). - -Supported attributes so far: - -* All geometries: `title`, `desc` -* Point geometry: `marker-color` ('transparent' for none), `stroke`, `stroke-width`, `marker-icon`, - `marker-symbol` (supports single digit/character, emoji, line-awesome icon name) -* LineString geometry: `stroke-width`, `stroke` -* Polygon geometry: `stroke-width`, `stroke`, `fill` +See [[docs/geojson.md]] for supported attributes. ## Development Setup diff --git a/app/javascript/controllers/feature_controller.js b/app/javascript/controllers/feature_controller.js index f92c047e..8f3555bf 100644 --- a/app/javascript/controllers/feature_controller.js +++ b/app/javascript/controllers/feature_controller.js @@ -1,9 +1,7 @@ import { Controller } from '@hotwired/stimulus' -import { - flash, vectorSource, featureAsGeoJSON, deleteFeature, updateFeature -} from 'map/map' +import { flash, vectorSource, featureAsGeoJSON, deleteFeature, updateFeature } from 'map/map' import { mapChannel } from 'channels/map_channel' -import { selectEditInteraction, undoInteraction } from 'map/interactions/edit' +import { selectEditInteraction, undoInteraction, showFeatureEdit } from 'map/interactions/edit' export default class extends Controller { static targets = ['properties'] @@ -24,6 +22,7 @@ export default class extends Controller { }, 'Change feature properties') mapChannel.send_message('update_feature', newFeature) flash('Feature updated', 'success') + showFeatureEdit (feature) } delete () { diff --git a/app/javascript/map/interactions/edit.js b/app/javascript/map/interactions/edit.js index e74aea4d..f8ac74bd 100644 --- a/app/javascript/map/interactions/edit.js +++ b/app/javascript/map/interactions/edit.js @@ -289,9 +289,9 @@ export function initializeUndoInteraction () { export function showFeatureEdit (feature) { const detailsContainer = document.querySelector('.feature-details-edit') detailsContainer.dataset.featureId = feature.getId() - detailsContainer.querySelector('.feature-details-title').innerHTML = feature.getId() + detailsContainer.querySelector('.feature-details-title').innerHTML = feature.get('title') || feature.getId() detailsContainer.querySelector('.feature-details-desc').innerHTML = '' - detailsContainer.querySelector('.feature-details-atts-edit textarea').value = JSON.stringify(featureAsGeoJSON(feature).properties) || '{}' + detailsContainer.querySelector('.feature-details-atts-edit textarea').value = JSON.stringify(featureAsGeoJSON(feature).properties || {}) detailsContainer.style.display = 'block' detailsContainer.style.opacity = '0.9' } diff --git a/app/javascript/map/styles.js b/app/javascript/map/styles.js index 96759b5d..f3f0fd4b 100644 --- a/app/javascript/map/styles.js +++ b/app/javascript/map/styles.js @@ -7,8 +7,9 @@ import { polygonStyle, polygonHoverStyle, polygonSketchStyle } from 'map/styles/ const ol = window.ol export function title (feature) { + if (!feature.get('title')) { return null } return new ol.style.Text({ - text: feature.get('title') || feature.getId(), + text: feature.get('title'), font: '15px Calibri,sans-serif', fill: new ol.style.Fill({ color: '#000' }), stroke: new ol.style.Stroke({ color: '#fff', width: 3 }), diff --git a/app/views/maps/show.html.haml b/app/views/maps/show.html.haml index 51e13c91..cbd2b0ee 100644 --- a/app/views/maps/show.html.haml +++ b/app/views/maps/show.html.haml @@ -10,8 +10,9 @@ %p.feature-details-atts %p.feature-details-atts-edit %textarea{name: "properties", rows: "4", cols: "30", "data-feature-target": "properties" } + %a{href: 'https://github.com/digitaltom/mapforge/blob/main/docs/geojson.md'} Help %button.feature-update{ 'data-action': "click->feature#update"} Update - %button.feature-delete{ 'data-action': "click->feature#delete"} Delete + %button.feature-delete{ 'data-action': "click->feature#delete"} Delete Feature .feature-details.feature-details-view %h4.feature-details-title %p.feature-details-desc diff --git a/spec/features/feature_edit_spec.rb b/spec/features/feature_edit_spec.rb index 256f1b73..dbec3a95 100644 --- a/spec/features/feature_edit_spec.rb +++ b/spec/features/feature_edit_spec.rb @@ -34,7 +34,7 @@ it 'shows feature details' do expect(page).to have_css('.feature-details-edit') - expect(page).to have_text(polygon.id) + expect(page).to have_text('Poly Title') textarea = find('textarea') expect(textarea.value).to eq(polygon.properties.to_json) end From bb51a5b89d506e1712379513ed480e203d72fc33 Mon Sep 17 00:00:00 2001 From: "depfu[bot]" <23717796+depfu[bot]@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:25:19 +0000 Subject: [PATCH 2/2] Update importmap-rails to version 2.0.1 --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7ba83dd9..0e606b6d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -197,7 +197,7 @@ GEM i18n (1.14.1) concurrent-ruby (~> 1.0) ice_nine (0.11.2) - importmap-rails (1.2.3) + importmap-rails (2.0.1) actionpack (>= 6.0.0) activesupport (>= 6.0.0) railties (>= 6.0.0) @@ -271,7 +271,7 @@ GEM puma (6.4.2) nio4r (~> 2.0) racc (1.7.3) - rack (3.0.8) + rack (3.0.9) rack-session (2.0.0) rack (>= 3.0.0) rack-test (2.1.0)