-
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull request overview
Refactors MapLibre layer handling so GeoJSON layers are treated similarly to other layer types (separate sources/styles per layer) and introduces layer-level flags intended to control clustering/heatmap behavior.
Changes:
- Introduces per-layer GeoJSON sources (
<type>-source-<layerId>) and new feature lookup helpers inmaplibre/layers/layers.js. - Updates various MapLibre modules/controllers to use the new feature lookup approach instead of
geojsonData. - Adds a Wikipedia marker icon and extends
Layersummaries withheatmap/clusterflags.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| public/icons/wikipedia.png | Adds an icon used by the Wikipedia layer features. |
| app/models/layer.rb | Adds heatmap/cluster fields and includes them in serialized layer summaries. |
| app/javascript/maplibre/undo.js | Starts migration away from geojsonData imports (but still needs further refactor). |
| app/javascript/maplibre/styles.js | Updates style initialization and heatmap layer handling; switches feature lookup to getFeature. |
| app/javascript/maplibre/routing/osrm.js | Switches route feature lookup to getFeature. |
| app/javascript/maplibre/map.js | Removes global geojsonData usage patterns and shifts rendering toward per-layer sources. |
| app/javascript/maplibre/layers/layers.js | Initializes per-layer GeoJSON sources/styles and adds getFeature/getFeatures/hasFeatures. |
| app/javascript/maplibre/feature.js | Uses new feature access helpers for edit gating and derived-feature generation inputs. |
| app/javascript/maplibre/edit.js | Uses new helpers for “untouched map” logic and URL-based selection. |
| app/javascript/maplibre/controls/shared.js | Updates feature list items to reference the new per-layer source names. |
| app/javascript/controllers/feature/modal_controller.js | Refactors selected-feature access (now needs getFeature import). |
| app/javascript/controllers/feature/edit_controller.js | Refactors edit-feature access (now needs getFeature import). |
Comments suppressed due to low confidence (1)
app/javascript/maplibre/map.js:123
initializeMaphighlights a URL-selected feature viahighlightFeature(feature, true)without passing the feature’s source. Since the default source inhighlightFeatureisgeojson-source(which is no longer created),setFeatureStatewill fail or highlight the wrong source. Determine the correct source for the feature (e.g., from the owning layer) and pass it explicitly.
const urlFeatureId = new URLSearchParams(window.location.search).get('f')
let feature = getFeature(urlFeatureId)
if (feature) {
resetControls()
highlightFeature(feature, true)
const center = centroid(feature)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def to_summary_json | ||
| json = { id: id, type: type, name: name } | ||
| json = { id: id, type: type, name: name, heatmap: !!heatmap, cluster: !!cluster } | ||
| json[:query] = query if type == "overpass" | ||
| json |
Copilot
AI
Feb 2, 2026
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.
to_summary_json now includes heatmap/cluster, but broadcast_update only broadcasts when name or query change. If heatmap/cluster are updated, connected clients won’t receive an update_layer event and will render stale settings; include these fields in the change check (or broadcast on any relevant update).
| // updateData requires a 'GeoJSONSourceDiff', with add/update/remove lists | ||
| map.getSource('geojson-source').setData(renderedGeojsonData()) | ||
| //map.getSource('geojson-source').setData(renderedGeojsonData()) | ||
| console.log('layers:', layers) | ||
| layers.filter(f => f.type !== 'geojson').forEach((layer) => { | ||
| layers.forEach((layer) => { | ||
| if (layer.geojson) { | ||
| console.log("Setting layer data", layer.type, layer.id, layer.geojson) | ||
| map.getSource(layer.type + '-source-' + layer.id).setData(layer.geojson, false) |
Copilot
AI
Feb 2, 2026
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.
redrawGeojson() no longer calls renderedGeojsonData() and instead pushes layer.geojson directly into each source. This drops the side effects of renderedGeojsonData() (km-marker source updates via renderKmMarkers() and extrusion polygons via renderExtrusionLines()), so km markers / extrusions will stop rendering/updating. Re-introduce those steps in the new per-layer rendering flow (and ensure derived features are included in the appropriate source data).
| const feature = geojsonData.features.find(f => f.id === targetId) | ||
| const feature = getFeature(targetId) | ||
| if (feature) { | ||
| flyToFeature(feature) |
Copilot
AI
Feb 2, 2026
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.
When handling onclick-target navigation, flyToFeature(feature) is called without a source. flyToFeature defaults to geojson-source, which no longer exists for per-layer sources, so the follow-up highlight will fail. Pass sourceName (or otherwise resolve the owning source) into flyToFeature.
| flyToFeature(feature) | |
| flyToFeature(feature, sourceName) |
| map.addLayer(setSource(styles()[styleName], sourceName)) | ||
| }) | ||
| if (heatmap) { map.addLayer(setSource(styles()['heatmap-layer'], sourceName)) } |
Copilot
AI
Feb 2, 2026
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.
initializeViewStyles now only adds the heatmap layer when heatmap=true, but existing callers (e.g. overpass layer initialization) invoke it with a single argument. This change will disable rendering for existing heatmap=true overpass queries unless those call sites are updated to pass the flag.
| f.e('#edit-buttons button', (e) => { e.classList.remove('active') }) | ||
| // allow edit in rw mode for geojson features only | ||
| if (window.gon.map_mode === 'rw' && geojsonData.features.find(f => f.id === feature.id)) { | ||
| if (window.gon.map_mode === 'rw' && getFeature(feature.id)) { |
Copilot
AI
Feb 2, 2026
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.
The edit-mode gate uses getFeature(feature.id), but getFeature currently searches all layer types (geojson/overpass/wikipedia). That means non-geojson features can incorrectly be treated as editable and show the edit UI in rw mode. Restrict this check to geojson layers only (e.g., getFeature(feature.id, 'geojson') or a dedicated getGeojsonFeature).
| if (window.gon.map_mode === 'rw' && getFeature(feature.id)) { | |
| if (window.gon.map_mode === 'rw' && getFeature(feature.id, 'geojson')) { |
| initLayers.forEach((layer) => { | ||
| addGeoJSONSource('geojson-source-' + layer.id, false) | ||
| initializeViewStyles('geojson-source-' + layer.id) | ||
| }) | ||
| redrawGeojson() |
Copilot
AI
Feb 2, 2026
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.
initializeLayers() calls redrawGeojson() before initializeOverpassLayers() / initializeWikipediaLayers(). If an overpass/wikipedia layer already has cached/preloaded layer.geojson, redrawGeojson() will attempt map.getSource('<type>-source-<id>').setData(...) before those sources are created and will throw. Create sources for all layers before calling redrawGeojson(), or guard redrawGeojson() against missing sources.
app/javascript/maplibre/edit.js
Outdated
| const feature = getFeature(urlFeatureId) | ||
| if (feature) { map.fire('draw.selectionchange', {features: [feature]}) } |
Copilot
AI
Feb 2, 2026
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.
On geojson.load, this selects urlFeatureId via getFeature(urlFeatureId) and then fires a draw selectionchange. Since getFeature currently searches all layer types, a non-geojson feature id in the URL could be returned and passed into draw, which expects editable geojson features. Restrict this lookup to geojson layers only (or use a geojson-specific helper).
| const feature = getFeature(urlFeatureId) | |
| if (feature) { map.fire('draw.selectionchange', {features: [feature]}) } | |
| if (!urlFeatureId) { return } | |
| const feature = getFeature(urlFeatureId) | |
| if (feature && feature.layer && feature.layer.type === 'geojson') { | |
| map.fire('draw.selectionchange', { features: [feature] }) | |
| } |
| addGeoJSONSource('geojson-source-' + layer.id, false) | ||
| initializeViewStyles('geojson-source-' + layer.id) |
Copilot
AI
Feb 2, 2026
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.
GeoJSON layers are always initialized with cluster=false and without passing the new heatmap flag into initializeViewStyles. Since layer summaries now include cluster/heatmap, these settings appear intended to be configurable but are currently ignored. Consider wiring layer.cluster into addGeoJSONSource(...) and layer.heatmap into initializeViewStyles(..., layer.heatmap).
| addGeoJSONSource('geojson-source-' + layer.id, false) | |
| initializeViewStyles('geojson-source-' + layer.id) | |
| addGeoJSONSource('geojson-source-' + layer.id, Boolean(layer.cluster)) | |
| initializeViewStyles('geojson-source-' + layer.id, Boolean(layer.heatmap)) |
| // updateData requires a 'GeoJSONSourceDiff', with add/update/remove lists | ||
| map.getSource('geojson-source').setData(renderedGeojsonData()) | ||
| //map.getSource('geojson-source').setData(renderedGeojsonData()) | ||
| console.log('layers:', layers) |
Copilot
AI
Feb 2, 2026
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.
The commented-out map.getSource('geojson-source').setData(renderedGeojsonData()) suggests renderedGeojsonData() might be re-enabled later, but that function still references geojsonData (now removed). Either update renderedGeojsonData() to use the new per-layer/merged storage or delete it to avoid a latent ReferenceError if this line is uncommented.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.