-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathsaved_gis_map.js
112 lines (99 loc) · 3.63 KB
/
saved_gis_map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import _ from 'lodash';
import { createSavedObjectClass } from '../../../../../../../src/plugins/saved_objects/public';
import {
getTimeFilters,
getMapZoom,
getMapCenter,
getLayerListRaw,
getMapExtent,
getRefreshConfig,
getQuery,
getFilters,
} from '../../selectors/map_selectors';
import { getIsLayerTOCOpen, getOpenTOCDetails } from '../../selectors/ui_selectors';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { convertMapExtentToPolygon } from '../../../../../../plugins/maps/public/elasticsearch_geo_utils';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { copyPersistentState } from '../../../../../../plugins/maps/public/reducers/util';
import { extractReferences, injectReferences } from '../../../common/migrations/references';
import { MAP_SAVED_OBJECT_TYPE } from '../../../common/constants';
export function createSavedGisMapClass(services) {
const SavedObjectClass = createSavedObjectClass(services);
class SavedGisMap extends SavedObjectClass {
static type = MAP_SAVED_OBJECT_TYPE;
// Mappings are used to place object properties into saved object _source
static mapping = {
title: 'text',
description: 'text',
mapStateJSON: 'text',
layerListJSON: 'text',
uiStateJSON: 'text',
bounds: {
type: 'object',
},
};
static fieldOrder = ['title', 'description'];
static searchSource = false;
constructor(id) {
super({
type: SavedGisMap.type,
mapping: SavedGisMap.mapping,
searchSource: SavedGisMap.searchSource,
extractReferences,
injectReferences: (savedObject, references) => {
const { attributes } = injectReferences({
attributes: { layerListJSON: savedObject.layerListJSON },
references,
});
savedObject.layerListJSON = attributes.layerListJSON;
const indexPatternIds = references
.filter(reference => {
return reference.type === 'index-pattern';
})
.map(reference => {
return reference.id;
});
savedObject.indexPatternIds = _.uniq(indexPatternIds);
},
// if this is null/undefined then the SavedObject will be assigned the defaults
id: id,
// default values that will get assigned if the doc is new
defaults: {
title: 'New Map',
description: '',
},
});
this.showInRecentlyAccessed = true;
}
getFullPath() {
return `/app/maps#map/${this.id}`;
}
getLayerList() {
return this.layerListJSON ? JSON.parse(this.layerListJSON) : null;
}
syncWithStore(state) {
const layerList = getLayerListRaw(state);
const layerListConfigOnly = copyPersistentState(layerList);
this.layerListJSON = JSON.stringify(layerListConfigOnly);
this.mapStateJSON = JSON.stringify({
zoom: getMapZoom(state),
center: getMapCenter(state),
timeFilters: getTimeFilters(state),
refreshConfig: getRefreshConfig(state),
query: _.omit(getQuery(state), 'queryLastTriggeredAt'),
filters: getFilters(state),
});
this.uiStateJSON = JSON.stringify({
isLayerTOCOpen: getIsLayerTOCOpen(state),
openTOCDetails: getOpenTOCDetails(state),
});
this.bounds = convertMapExtentToPolygon(getMapExtent(state));
}
}
return SavedGisMap;
}