-
Notifications
You must be signed in to change notification settings - Fork 383
/
mapInfo.js
195 lines (176 loc) · 6.63 KB
/
mapInfo.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* Copyright 2017, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const { get, omit, isArray } = require('lodash');
const { createSelector, createStructuredSelector } = require('reselect');
const {mapSelector} = require('./map');
const { currentLocaleSelector } = require('./locale');
const MapInfoUtils = require('../utils/MapInfoUtils');
/**
* selects mapinfo state
* @name mapinfo
* @memberof selectors
* @static
*/
/**
* Get mapinfo requests from state
* @function
* @memberof selectors.mapinfo
* @param {object} state the state
* @return {object} the mapinfo requests
*/
const mapInfoRequestsSelector = state => get(state, "mapInfo.requests") || [];
const isMapInfoOpen = state => !!mapInfoRequestsSelector(state) && mapInfoRequestsSelector(state).length > 0;
/**
* selects generalInfoFormat from state
* @memberof selectors.mapinfo
* @param {object} state the state
* @return {string} the maptype in the state
*/
const generalInfoFormatSelector = (state) => get(state, "mapInfo.configuration.infoFormat", "text/plain");
const showEmptyMessageGFISelector = (state) => get(state, "mapInfo.configuration.showEmptyMessageGFI", true);
const mapInfoConfigurationSelector = (state) => get(state, "mapInfo.configuration", {});
const measureActiveSelector = (state) => get(state, "controls.measure.enabled") && (get(state, "measurement.lineMeasureEnabled") || get(state, "measurement.areaMeasureEnabled") || get(state, "measurement.bearingMeasureEnabled"));
/**
* Clicked point of mapInfo
* @param {object} state the state
*/
const clickPointSelector = state => state && state.mapInfo && state.mapInfo.clickPoint;
const clickLayerSelector = state => state && state.mapInfo && state.mapInfo.clickLayer;
const showMarkerSelector = state => state && state.mapInfo && state.mapInfo.showMarker;
const itemIdSelector = state => get(state, "mapInfo.itemId", null);
const overrideParamsSelector = state => get(state, "mapInfo.overrideParams", {});
const filterNameListSelector = state => get(state, "mapInfo.filterNameList", []);
const drawSupportActiveSelector = (state) => {
const drawStatus = get(state, "draw.drawStatus", false);
return drawStatus && drawStatus !== 'clean' && drawStatus !== 'stop';
};
const annotationsEditingSelector = (state) => get(state, "annotations.editing");
const mapInfoDisabledSelector = (state) => !get(state, "mapInfo.enabled", false);
/**
* selects stopGetFeatureInfo from state
* @memberof selectors.mapinfo
* @param {object} state the state
* @return {boolean} true if the get feature info has to stop the request
*/
const stopGetFeatureInfoSelector = createSelector(
mapInfoDisabledSelector,
measureActiveSelector,
drawSupportActiveSelector,
annotationsEditingSelector,
(isMapInfoDisabled, isMeasureActive, isDrawSupportActive, isAnnotationsEditing) =>
isMapInfoDisabled
|| !!isMeasureActive
|| isDrawSupportActive
|| !!isAnnotationsEditing
);
/**
* Defines the general options of the identifyTool to build the request
*/
const identifyOptionsSelector = createStructuredSelector({
format: generalInfoFormatSelector,
map: mapSelector,
point: clickPointSelector,
currentLocale: currentLocaleSelector
});
const isHighlightEnabledSelector = (state = {}) => state.mapInfo && state.mapInfo.highlight;
const indexSelector = (state = {}) => state && state.mapInfo && state.mapInfo.index;
const responsesSelector = state => state.mapInfo && state.mapInfo.responses || [];
/**
* Gets only the valid responses
*/
const validResponsesSelector = createSelector(
responsesSelector,
generalInfoFormatSelector,
(responses, format) => {
const validatorFormat = MapInfoUtils.getValidator(format);
return validatorFormat.getValidResponses(responses);
});
const currentResponseSelector = createSelector(
validResponsesSelector, indexSelector,
(responses = [], index = 0) => responses[index]
);
const currentFeatureSelector = state => {
const currentResponse = currentResponseSelector(state) || {};
return get(currentResponse, 'layerMetadata.features');
};
const currentFeatureCrsSelector = state => {
const currentResponse = currentResponseSelector(state) || {};
return get(currentResponse, 'layerMetadata.featuresCrs');
};
/**
* Returns the a function that returns the correct style based on the geometry type, to use in the highlight
* @param {feature} f the feature in json format
*/
const getStyleForFeature = (style) => (f = {}) =>
f.style
|| (f.geometry && (f.geometry.type === "Point" || f.geometry.type === "MultiPoint"))
// point style circle requires radius (it's strange circle should be a default)
? style
// no radius means normal polygon, line or other. TODO: fix VectorStyle to omit radius automatically
: omit(style, 'radius');
/**
* Create a function that add the style property to the feature.
*/
const applyMapInfoStyle = style => f => ({
...f,
style: getStyleForFeature(style)(f)
});
/**
* gets the configured state for highlight mapInfo features.
* @param {object} state the application state
* @returns {object} style object
*/
const highlightStyleSelector = state => get(state, 'mapInfo.highlightStyle', {
color: '#3388ff',
weight: 4,
radius: 4,
dashArray: '',
fillColor: '#3388ff',
fillOpacity: 0.2
});
const clickedPointWithFeaturesSelector = createSelector(
clickPointSelector,
isHighlightEnabledSelector,
currentFeatureSelector,
currentFeatureCrsSelector,
showMarkerSelector,
highlightStyleSelector,
(clickPoint, highlight, features, featuresCrs, showMarker, style) => showMarker && clickPoint
? highlight
? {
...clickPoint,
featuresCrs,
features: features && isArray(features)
&& features
.map(applyMapInfoStyle(style))
}
: clickPoint
: undefined
);
module.exports = {
isMapInfoOpen,
indexSelector,
responsesSelector,
validResponsesSelector,
currentFeatureSelector,
currentFeatureCrsSelector,
clickedPointWithFeaturesSelector,
highlightStyleSelector,
identifyOptionsSelector,
clickPointSelector,
clickLayerSelector,
generalInfoFormatSelector,
mapInfoRequestsSelector,
stopGetFeatureInfoSelector,
showEmptyMessageGFISelector,
mapInfoConfigurationSelector,
isHighlightEnabledSelector,
itemIdSelector,
overrideParamsSelector,
filterNameListSelector
};