Skip to content

Commit

Permalink
fixes issue on saving custom vector map options as part of visualizat…
Browse files Browse the repository at this point in the history
…ion (#1896)

Signed-off-by: Shivam Dhar <[email protected]>
(cherry picked from commit 6dfe116)
  • Loading branch information
Shivamdhar authored and github-actions[bot] committed Jul 22, 2022
1 parent a815acb commit 86ec049
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export interface RegionMapVisParams {
outlineWeight: number | '';
isDisplayWarning: boolean;
showAllShapes: boolean;
selectedCustomLayer?: VectorLayer;
selectedCustomJoinField?: FileLayerField;
selectedLayer?: VectorLayer;
selectedJoinField?: FileLayerField;
wms: WMSOptions;
Expand Down
17 changes: 11 additions & 6 deletions src/plugins/region_map/public/region_map_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function createRegionMapTypeDefinition(dependencies) {

const services = getServices(http);
const visualization = createRegionMapVisualization(dependencies);

const diffArray = (arr1, arr2) => {
return arr1.concat(arr2).filter((item) => !arr1.includes(item) || !arr2.includes(item));
};
Expand Down Expand Up @@ -201,9 +202,10 @@ provided base maps, or add your own. Darker colors represent higher values.',
const customIndices = await getCustomIndices();

let selectedLayer = vectorLayers[0];
let selectedCustomLayer = customVectorLayers[0];
let selectedJoinField = selectedLayer ? selectedLayer.fields[0] : null;
const selectedCustomJoinField = selectedCustomLayer ? selectedCustomLayer.fields[0] : null;

let selectedCustomLayer = customVectorLayers[0];
let selectedCustomJoinField = selectedCustomLayer ? selectedCustomLayer.fields[0] : null;

if (regionmapsConfig.includeOpenSearchMapsService) {
const layers = await serviceSettings.getFileLayers();
Expand Down Expand Up @@ -241,11 +243,9 @@ provided base maps, or add your own. Darker colors represent higher values.',
];

[selectedLayer] = vis.type.editorConfig.collections.vectorLayers;
[selectedCustomLayer] = vis.type.editorConfig.collections.customVectorLayers;
vis.params.selectedCustomLayer = selectedCustomLayer;
vis.params.selectedCustomJoinField = selectedCustomJoinField;

selectedJoinField = selectedLayer ? selectedLayer.fields[0] : null;
[selectedCustomLayer] = vis.type.editorConfig.collections.customVectorLayers;
selectedCustomJoinField = selectedCustomLayer ? selectedCustomLayer.fields[0] : null;

if (selectedLayer && !vis.params.selectedLayer && selectedLayer.isEMS) {
vis.params.emsHotLink = await serviceSettings.getEMSHotLink(selectedLayer);
Expand All @@ -257,6 +257,11 @@ provided base maps, or add your own. Darker colors represent higher values.',
vis.params.selectedJoinField = selectedJoinField;
}

if (!vis.params.selectedCustomLayer) {
vis.params.selectedCustomLayer = selectedCustomLayer;
vis.params.selectedCustomJoinField = selectedCustomJoinField;
}

vis.params.layerChosenByUser = vis.params.layerChosenByUser
? vis.params.layerChosenByUser
: DEFAULT_MAP_CHOICE;
Expand Down
15 changes: 9 additions & 6 deletions src/plugins/region_map/public/region_map_visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import { truncatedColorMaps } from '../../charts/public';
import { tooltipFormatter } from './tooltip_formatter';
import { mapTooltipProvider, ORIGIN, lazyLoadMapsLegacyModules } from '../../maps_legacy/public';
import { DEFAULT_MAP_CHOICE } from '../common';
import { DEFAULT_MAP_CHOICE, CUSTOM_MAP_CHOICE } from '../common';

export function createRegionMapVisualization({
http,
Expand Down Expand Up @@ -86,7 +86,7 @@ export function createRegionMapVisualization({
let selectedLayer;
if (DEFAULT_MAP_CHOICE === this._params.layerChosenByUser) {
selectedLayer = await this._loadConfig(this._params.selectedLayer);
this._params.selectedJoinField = selectedLayer.fields[0];
this._params.selectedJoinField = selectedLayer?.fields[0];
} else {
selectedLayer = this._params.selectedCustomLayer;
this._params.selectedJoinField = this._params.selectedCustomJoinField;
Expand Down Expand Up @@ -156,12 +156,15 @@ export function createRegionMapVisualization({
async _updateParams() {
await super._updateParams();
let selectedLayer;
if (DEFAULT_MAP_CHOICE === this._params.layerChosenByUser) {
if (DEFAULT_MAP_CHOICE === this._params.layerChosenByUser && this._params.selectedLayer) {
selectedLayer = await this._loadConfig(this._params.selectedLayer);
this._params.selectedJoinField = selectedLayer.fields[0];
} else {
this._params.selectedJoinField = selectedLayer?.fields[0];
} else if (
CUSTOM_MAP_CHOICE === this._params.layerChosenByUser &&
this._params.selectedCustomLayer
) {
selectedLayer = this._params.selectedCustomLayer;
this._params.selectedJoinField = this._params.selectedCustomJoinField;
this._params.selectedJoinField = this._params?.selectedCustomJoinField;
}

if (!this._params.selectedJoinField && selectedLayer) {
Expand Down

0 comments on commit 86ec049

Please sign in to comment.