Skip to content

Commit

Permalink
BWC for document layer label textType (#340)
Browse files Browse the repository at this point in the history
Signed-off-by: Junqiu Lei <junqiu@amazon.com>
  • Loading branch information
junqiu-lei authored Mar 14, 2023
1 parent 397e666 commit 02d7d9a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* Introduce disable tooltip on hover property ([#313](https://github.com/opensearch-project/dashboards-maps/pull/313))
* Update tooltip behavior change ([#317](https://github.com/opensearch-project/dashboards-maps/pull/317))
* Update max supported layer count ([#332](https://github.com/opensearch-project/dashboards-maps/pull/332))
* BWC for document layer label textType ([#340](https://github.com/opensearch-project/dashboards-maps/pull/340))
### Bug Fixes
* Fix property value undefined check ([#276](https://github.com/opensearch-project/dashboards-maps/pull/276))
* Show scroll bar when panel height reaches container bottom ([#295](https://github.com/opensearch-project/dashboards-maps/pull/295))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,19 @@ export const LabelConfig = ({
};

const onChangeLabelFieldText = (options: EuiComboBoxOptionOption[]) => {
onChangeLabel('textByField', options[0]?.label || '');
const newSelectedLayerConfig = {
...selectedLayerConfig,
style: {
...selectedLayerConfig.style,
label: {
...selectedLayerConfig.style?.label,
textByField: options[0]?.label || '',
// For backwards compatibility, set textType to BY_FIELD if textByField is set
textType: DOCUMENTS_LABEL_TEXT_TYPE.BY_FIELD,
},
},
};
setSelectedLayerConfig(newSelectedLayerConfig);
};

const label = selectedLayerConfig.style?.label;
Expand Down
10 changes: 3 additions & 7 deletions public/model/documentLayerFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,15 @@ const updateLayer = (
};

// The function to render label for document layer
const renderLabelLayer = (
layerConfig: DocumentLayerSpecification,
maplibreRef: MaplibreRef,
beforeLayerId: string | undefined
) => {
const renderLabelLayer = (layerConfig: DocumentLayerSpecification, maplibreRef: MaplibreRef) => {
const hasLabelLayer = hasSymbolLayer(maplibreRef.current!, layerConfig.id);
// If the label set to enabled, add the label layer
if (layerConfig.style?.label?.enabled) {
const symbolLayerSpec = createSymbolLayerSpecification(layerConfig);
if (hasLabelLayer) {
updateSymbolLayer(maplibreRef.current!, symbolLayerSpec);
} else {
addSymbolLayer(maplibreRef.current!, symbolLayerSpec, beforeLayerId);
addSymbolLayer(maplibreRef.current!, symbolLayerSpec);
}
} else {
// If the label set to disabled, remove the label layer if it exists
Expand Down Expand Up @@ -277,6 +273,6 @@ export const DocumentLayerFunctions = {
beforeLayerId: string | undefined
) => {
renderMarkerLayer(maplibreRef, layerConfig, data, beforeLayerId);
renderLabelLayer(layerConfig, maplibreRef, beforeLayerId);
renderLabelLayer(layerConfig, maplibreRef);
},
};
19 changes: 6 additions & 13 deletions public/model/map/layer_operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,13 @@ export const removeSymbolLayer = (map: Maplibre, layerId: string) => {
map.removeLayer(layerId + '-symbol');
};

export const addSymbolLayer = (
map: Maplibre,
specification: SymbolLayerSpecification,
beforeId?: string
): string => {
export const addSymbolLayer = (map: Maplibre, specification: SymbolLayerSpecification): string => {
const symbolLayerId = specification.sourceId + '-symbol';
map.addLayer(
{
id: symbolLayerId,
type: 'symbol',
source: specification.sourceId,
},
beforeId
);
map.addLayer({
id: symbolLayerId,
type: 'symbol',
source: specification.sourceId,
});
return updateSymbolLayer(map, specification);
};

Expand Down

0 comments on commit 02d7d9a

Please sign in to comment.