Skip to content

Commit 72a1636

Browse files
authored
Merge pull request #37 from E4Warning/copilot/fix-spain-training-data-map-again
2 parents 1a72e41 + 37189c7 commit 72a1636

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

js/app.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ async function loadObservationOverlay(regionKey) {
613613
presenceRaw.toLowerCase() === 'true' :
614614
Boolean(presenceRaw);
615615

616-
if (!Number.isFinite(lat) || !Number.isFinite(lon) || !isPresent) {
616+
// Only filter out invalid coordinates, not based on presence
617+
if (!Number.isFinite(lat) || !Number.isFinite(lon)) {
617618
return null;
618619
}
619620

@@ -636,7 +637,8 @@ async function loadObservationOverlay(regionKey) {
636637
};
637638

638639
mapManager.addObservationLayer(geojson, visible, {
639-
fillColor: '#ffd92f',
640+
fillColor: '#ffd92f', // Yellow for presence points
641+
fillColorAbsence: '#a6cee3', // Light blue for absence points
640642
strokeColor: '#000000',
641643
strokeWidth: 1.5,
642644
radius: regionKey === 'barcelona' ? 7 : 6,

js/mapManager.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class MapManager {
200200
*/
201201
addObservationLayer(geojsonData, visible = true, options = {}) {
202202
const fillColor = options.fillColor || options.color || '#ffd92f';
203+
const fillColorAbsence = options.fillColorAbsence || '#a6cee3';
203204
const strokeColor = options.strokeColor || '#000000';
204205
const radius = options.radius || 6;
205206
const strokeWidth = options.strokeWidth !== undefined ? options.strokeWidth : 1.25;
@@ -218,13 +219,21 @@ class MapManager {
218219
data: geojsonData
219220
});
220221

222+
// Use data-driven styling for presence/absence coloring
223+
const colorExpression = [
224+
'case',
225+
['==', ['get', 'presence'], true],
226+
fillColor,
227+
fillColorAbsence
228+
];
229+
221230
this.mbMap.addLayer({
222231
id: this.observationLayerId,
223232
type: 'circle',
224233
source: this.observationSourceId,
225234
paint: {
226235
'circle-radius': radius,
227-
'circle-color': fillColor,
236+
'circle-color': colorExpression,
228237
'circle-opacity': opacity,
229238
'circle-stroke-color': strokeColor,
230239
'circle-stroke-width': strokeWidth
@@ -239,14 +248,18 @@ class MapManager {
239248

240249
if (this.map) {
241250
this.layers.observations = L.geoJSON(geojsonData, {
242-
pointToLayer: (_, latlng) => L.circleMarker(latlng, {
243-
radius: radius,
244-
color: strokeColor,
245-
weight: strokeWidth,
246-
fillColor: fillColor,
247-
fillOpacity: opacity,
248-
opacity: opacity
249-
})
251+
pointToLayer: (feature, latlng) => {
252+
const isPresent = feature.properties?.presence === true;
253+
const color = isPresent ? fillColor : fillColorAbsence;
254+
return L.circleMarker(latlng, {
255+
radius: radius,
256+
color: strokeColor,
257+
weight: strokeWidth,
258+
fillColor: color,
259+
fillOpacity: opacity,
260+
opacity: opacity
261+
});
262+
}
250263
});
251264

252265
if (visible) {

0 commit comments

Comments
 (0)