Skip to content

ERA-11057: track styles: track color expression #1243

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

Merged
merged 17 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ REACT_APP_DEFAULT_PATROL_FILTER_FROM_DAYS=1
# Feature flags
REACT_APP_LEGACY_RT_ENABLED=false
REACT_APP_EFB_FORM_SCHEMA_SUPPORT_ENABLED=false
REACT_APP_TIME_OF_DAY_TRACKING=false
REACT_APP_TIME_OF_DAY_TRACKING=true
80 changes: 41 additions & 39 deletions src/AnalyzersLayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React, { memo, useMemo } from 'react';
import withMapViewConfig from '../WithMapViewConfig';

import { LAYER_IDS, SOURCE_IDS } from '../constants';
import { useMapEventBinding, useMapLayer, useMapSource } from '../hooks';
import { useMapEventBinding } from '../hooks';
import useMapSources from '../hooks/useMapSources';
import useMapLayers from '../hooks/useMapLayers';

const { ANALYZER_POLYS_WARNING, ANALYZER_POLYS_CRITICAL, ANALYZER_LINES_WARNING,
ANALYZER_LINES_CRITICAL, SKY_LAYER } = LAYER_IDS;
Expand Down Expand Up @@ -68,44 +70,44 @@ const AnalyzerLayer = (
condition: !!isSubjectSymbolsLayerReady,
}), [isSubjectSymbolsLayerReady, minZoom]);

useMapSource(ANALYZER_POLYS_WARNING_SOURCE, warningPolys);
useMapLayer(
ANALYZER_POLYS_WARNING,
'line',
ANALYZER_POLYS_WARNING_SOURCE,
linePaint,
undefined,
layerConfig,
);

useMapSource(ANALYZER_POLYS_CRITICAL_SOURCE, criticalPolys);
useMapLayer(
ANALYZER_POLYS_CRITICAL,
'line',
ANALYZER_POLYS_CRITICAL_SOURCE,
criticalLinePaint, lineLayout,
layerConfig,
);

useMapSource(ANALYZER_LINES_WARNING_SOURCE, warningLines);
useMapLayer(
ANALYZER_LINES_WARNING,
'line',
ANALYZER_LINES_WARNING_SOURCE,
linePaint,
lineLayout,
layerConfig,
);

useMapSource(ANALYZER_LINES_CRITICAL_SOURCE, criticalLines);
useMapLayer(
ANALYZER_LINES_CRITICAL,
'line',
ANALYZER_LINES_CRITICAL_SOURCE,
criticalLinePaint,
lineLayout,
layerConfig,
);
useMapSources([{ id: ANALYZER_POLYS_WARNING_SOURCE, data: warningPolys }]);
useMapLayers([{
id: ANALYZER_POLYS_WARNING,
type: 'line',
sourceId: ANALYZER_POLYS_WARNING_SOURCE,
paint: linePaint,
options: layerConfig,
}]);

useMapSources([{ id: ANALYZER_POLYS_CRITICAL_SOURCE, data: criticalPolys }]);
useMapLayers([{
id: ANALYZER_POLYS_CRITICAL,
type: 'line',
sourceId: ANALYZER_POLYS_CRITICAL_SOURCE,
paint: criticalLinePaint,
layout: lineLayout,
options: layerConfig,
}]);

useMapSources([{ id: ANALYZER_LINES_WARNING_SOURCE, data: warningLines }]);
useMapLayers([{
id: ANALYZER_LINES_WARNING,
type: 'line',
sourceId: ANALYZER_LINES_WARNING_SOURCE,
paint: linePaint,
layout: lineLayout,
options: layerConfig,
}]);

useMapSources([{ id: ANALYZER_LINES_CRITICAL_SOURCE, data: criticalLines }]);
useMapLayers([{
id: ANALYZER_LINES_CRITICAL,
type: 'line',
sourceId: ANALYZER_LINES_CRITICAL_SOURCE,
paint: criticalLinePaint,
layout: lineLayout,
options: layerConfig,
}]);

// (eventType = 'click', handlerFn = noop, layerId = null, condition = true)
useMapEventBinding('mouseenter', onAnalyzerFeatureEnter, ANALYZER_POLYS_WARNING);
Expand Down
22 changes: 12 additions & 10 deletions src/BaseLayerRenderer/TileLayerRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import React, { memo, useContext, useMemo, useEffect } from 'react';
import { MapContext } from '../App';

import { TILE_LAYER_SOURCE_TYPES, LAYER_IDS, MAX_ZOOM, MIN_ZOOM } from '../constants';
import { useMapLayer, useMapSource } from '../hooks';

import { calcConfigForMapAndSourceFromLayer } from '../utils/layers';
import useMapSources from '../hooks/useMapSources';
import useMapLayers from '../hooks/useMapLayers';

const { TOPMOST_STYLE_LAYER } = LAYER_IDS;

Expand All @@ -25,7 +26,7 @@ const SourceComponent = ({ id, tileUrl, sourceConfig }) => {
...sourceConfig,
}), [sourceConfig, tileUrl]);

useMapSource(id, null, config);
useMapSources([{ id }], config);

return null;
};
Expand All @@ -50,14 +51,15 @@ const TileLayerRenderer = (props) => {
}
}, [map, mapConfig]);

useMapLayer(
`tile-layer-${activeLayer?.id}`,
'raster',
`layer-source-${activeLayer?.id}`,
undefined,
undefined,
{ before: TOPMOST_STYLE_LAYER, condition: !!activeLayer }
);
useMapLayers([{
id: `tile-layer-${activeLayer?.id}`,
type: 'raster',
sourceId: `layer-source-${activeLayer?.id}`,
options: {
before: TOPMOST_STYLE_LAYER,
condition: !!activeLayer
}
}]);

return layers
.filter(layer => TILE_LAYER_SOURCE_TYPES.includes(layer.attributes.type))
Expand Down
14 changes: 11 additions & 3 deletions src/ClustersLayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { getMapSubjectFeatureCollectionWithVirtualPositioning } from '../selecto
import { getShouldEventsBeClustered, getShouldSubjectsBeClustered } from '../selectors/clusters';
import { MapContext } from '../App';
import useClusterBufferPolygon from '../hooks/useClusterBufferPolygon';
import { useMapEventBinding, useMapLayer, useMapSource } from '../hooks';
import { useMapEventBinding } from '../hooks';
import useMapSources from '../hooks/useMapSources';
import useMapLayers from '../hooks/useMapLayers';

const {
CLUSTERS_LAYER_ID,
Expand Down Expand Up @@ -53,8 +55,14 @@ const ClustersLayer = ({ onShowClusterSelectPopup }) => {
subjectFeatureCollection.features,
]);

useMapSource(CLUSTERS_SOURCE_ID, clustersSourceData, CLUSTER_SOURCE_CONFIG);
useMapLayer(CLUSTERS_LAYER_ID, 'circle', CLUSTERS_SOURCE_ID, CLUSTER_LAYER_PAINT, null, CLUSTER_LAYER_CONFIG);
useMapSources([{ id: CLUSTERS_SOURCE_ID, data: clustersSourceData }], CLUSTER_SOURCE_CONFIG);
useMapLayers([{
id: CLUSTERS_LAYER_ID,
type: 'circle',
sourceId: CLUSTERS_SOURCE_ID,
paint: CLUSTER_LAYER_PAINT,
options: CLUSTER_LAYER_CONFIG
}]);

const { removeClusterPolygon, renderClusterPolygon } = useClusterBufferPolygon();

Expand Down
15 changes: 12 additions & 3 deletions src/EventGeometryLayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { getShowReportsOnMap } from '../selectors/clusters';
import { LAYER_IDS, SOURCE_IDS } from '../constants';
import { MAP_LOCATION_SELECTION_MODES } from '../ducks/map-ui';
import { PRIORITY_COLOR_MAP } from '../utils/events';
import { useMapEventBinding, useMapLayer, useMapSource } from '../hooks';
import { useMapEventBinding } from '../hooks';
import useMapSources from '../hooks/useMapSources';
import useMapLayers from '../hooks/useMapLayers';

const { EVENT_GEOMETRY_LAYER, EVENT_SYMBOLS } = LAYER_IDS;

Expand Down Expand Up @@ -61,9 +63,16 @@ const EventGeometryLayer = ({ onClick }) => {
const onMouseEnter = () => map.getCanvas().style.cursor = 'pointer';
const onMouseLeave = () => map.getCanvas().style.cursor = '';

useMapSource(EVENT_GEOMETRY, eventFeatureCollection);
useMapSources([{ id: EVENT_GEOMETRY, data: eventFeatureCollection }]);

useMapLayer(EVENT_GEOMETRY_LAYER, 'fill', EVENT_GEOMETRY, paint, layout, layerConfig);
useMapLayers([{
id: EVENT_GEOMETRY_LAYER,
type: 'fill',
sourceId: EVENT_GEOMETRY,
paint,
layout,
options: layerConfig
}]);

useMapEventBinding('click', onClick, EVENT_GEOMETRY_LAYER);
useMapEventBinding('mouseenter', onMouseEnter, EVENT_GEOMETRY_LAYER);
Expand Down
4 changes: 2 additions & 2 deletions src/EventsLayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { getMapEventSymbolPointsWithVirtualDate } from '../selectors/events';
import { getShouldEventsBeClustered, getShowReportsOnMap } from '../selectors/clusters';
import { MapContext } from '../App';
import MapImageFromSvgSpriteRenderer, { calcSvgImageIconId } from '../MapImageFromSvgSpriteRenderer';
import { useMapSource } from '../hooks';
import useMapSources from '../hooks/useMapSources';
import { withMultiLayerHandlerAwareness } from '../utils/map-handlers';

import EventGeometryLayer from '../EventGeometryLayer';
Expand Down Expand Up @@ -241,7 +241,7 @@ const EventsLayer = ({
...mapEventFeatures,
features: !shouldEventsBeClustered && !!showReportsOnMap ? mapEventFeatures.features : [],
};
useMapSource(UNCLUSTERED_EVENTS_SOURCE, geoJson);
useMapSources([{ id: UNCLUSTERED_EVENTS_SOURCE, data: geoJson }]);

const isSubjectSymbolsLayerReady = !!map.getLayer(SUBJECT_SYMBOLS);
const isClustersSourceReady = !!map.getSource(CLUSTERS_SOURCE_ID);
Expand Down
43 changes: 34 additions & 9 deletions src/FeatureLayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { LAYER_IDS, DEFAULT_SYMBOL_LAYOUT, DEFAULT_SYMBOL_PAINT, SOURCE_IDS } fr

import MarkerImage from '../common/images/icons/mapbox-blue-marker-icon.png';
import RangerStationsImage from '../common/images/icons/ranger-stations.png';
import { useMapEventBinding, useMapLayer, useMapSource } from '../hooks';
import { useMapEventBinding } from '../hooks';
import useMapSources from '../hooks/useMapSources';
import useMapLayers from '../hooks/useMapLayers';

const { FEATURE_FILLS, FEATURE_LINES, FEATURE_SYMBOLS, SKY_LAYER } = LAYER_IDS;

Expand Down Expand Up @@ -114,14 +116,37 @@ const FeatureLayer = ({ symbols, lines, polygons, onFeatureSymbolClick, mapUserL

const layerConfig = { minZoom, before: SKY_LAYER };

useMapSource(MAP_FEATURES_LINES_SOURCE, lines);
useMapSource(MAP_FEATURES_POLYGONS_SOURCE, polygons);
useMapSource(MAP_FEATURES_SYMBOLS_SOURCE, symbols);

// (layerId, type, sourceId, paint, layout, filter, minzoom, maxzoom, condition = true)
useMapLayer(FEATURE_FILLS, 'fill', MAP_FEATURES_POLYGONS_SOURCE, fillPaint, fillLayout, layerConfig);
useMapLayer(FEATURE_LINES, 'line', MAP_FEATURES_LINES_SOURCE, linePaint, lineLayout, layerConfig);
useMapLayer(FEATURE_SYMBOLS, 'symbol', MAP_FEATURES_SYMBOLS_SOURCE, symbolPaint, layout, layerConfig);
useMapSources([{ id: MAP_FEATURES_LINES_SOURCE, data: lines }]);
useMapSources([{ id: MAP_FEATURES_POLYGONS_SOURCE, data: polygons }]);
useMapSources([{ id: MAP_FEATURES_SYMBOLS_SOURCE, data: symbols }]);

// (layerId, type, sourceId, paint, layout, filter, min-zoom, max-zoom, condition = true)
useMapLayers([{
id: FEATURE_FILLS,
type: 'fill',
sourceId: MAP_FEATURES_POLYGONS_SOURCE,
paint: fillPaint,
layout: fillLayout,
options: layerConfig
}]);

useMapLayers([{
id: FEATURE_LINES,
type: 'line',
sourceId: MAP_FEATURES_LINES_SOURCE,
paint: linePaint,
layout: lineLayout,
options: layerConfig
}]);

useMapLayers([{
id: FEATURE_SYMBOLS,
type: 'symbol',
sourceId: MAP_FEATURES_SYMBOLS_SOURCE,
paint: symbolPaint,
layout: layout,
options: layerConfig
}]);

useMapEventBinding('click', onSymbolClick, FEATURE_SYMBOLS);
useMapEventBinding('mouseenter', onSymbolMouseEnter, FEATURE_SYMBOLS);
Expand Down
15 changes: 12 additions & 3 deletions src/HeatLayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { useSelector } from 'react-redux';
import { LAYER_IDS, MAX_ZOOM } from '../constants';
import { metersToPixelsAtMaxZoom } from '../utils/map';
import { uuid } from '../utils/string';
import { useMapLayer, useMapSource } from '../hooks';
import useMapSources from '../hooks/useMapSources';
import useMapLayers from '../hooks/useMapLayers';

const { HEATMAP_LAYER, SKY_LAYER } = LAYER_IDS;

Expand All @@ -30,8 +31,16 @@ const HeatLayer = ({ points }) => {
};
}, [heatmapStyles.intensity, heatmapStyles.radiusInMeters, points]);

useMapSource(`heatmap-source-${idRef.current}`, points);
useMapLayer(`${HEATMAP_LAYER}-${idRef.current}`, 'heatmap', `heatmap-source-${idRef.current}`, paint, null, { before: SKY_LAYER });
useMapSources([{ id: `heatmap-source-${idRef.current}`, data: points }]);
useMapLayers([{
id: `${HEATMAP_LAYER}-${idRef.current}`,
type: 'heatmap',
sourceId: `heatmap-source-${idRef.current}`,
paint,
options: {
before: SKY_LAYER
}
}]);

return null;
};
Expand Down
22 changes: 19 additions & 3 deletions src/LabeledSymbolLayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { DEFAULT_SYMBOL_LAYOUT, DEFAULT_SYMBOL_PAINT } from '../constants';
import { withMap } from '../EarthRangerMap';
import withMapViewConfig from '../WithMapViewConfig';

import { useMapEventBinding, useMapLayer } from '../hooks';
import { useMapEventBinding } from '../hooks';
import useMapLayers from '../hooks/useMapLayers';

const LabeledSymbolLayer = (
{ before, paint, layout, textPaint, textLayout, id, sourceId, map, mapUserLayoutConfigByLayerId, onClick, onInit,
Expand Down Expand Up @@ -79,8 +80,23 @@ const LabeledSymbolLayer = (
useMapEventBinding('mouseleave', handleMouseLeave, id);
useMapEventBinding('mouseleave', handleMouseLeave, textLayerId);

useMapLayer(id, 'symbol', sourceId, symbolPaint, symbolLayout, layerConfig);
useMapLayer(textLayerId, 'symbol', sourceId, labelPaint, labelLayout, layerConfig);
useMapLayers([{
id: id,
type: 'symbol',
sourceId,
paint: symbolPaint,
layout: symbolLayout,
options: layerConfig
}]);

useMapLayers([{
id: textLayerId,
type: 'symbol',
sourceId,
paint: labelPaint,
layout: labelLayout,
options: layerConfig
}]);

return null;
};
Expand Down
Loading