@corpsmap/corpsmap 4.1.29 → 4.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corpsmap/corpsmap",
3
- "version": "4.1.29",
3
+ "version": "4.1.31",
4
4
  "main": "dist/corpsmap.umd.js",
5
5
  "module": "dist/corpsmap.es.js",
6
6
  "type": "module",
@@ -41,6 +41,7 @@ const createNode = (options, map) => {
41
41
  url: options.url,
42
42
  info: options.info,
43
43
  identifyType: options.identifyType,
44
+ identifyLayers: options.identifyLayers,
44
45
  identifyFields: options.identifyFields,
45
46
  identifyRenameColums: options.identifyRenameColums,
46
47
  identifyFormatColumns: options.identifyFormatColumns,
@@ -415,7 +416,7 @@ export default {
415
416
  displayName: "New Folder",
416
417
  type: "Folder",
417
418
  },
418
- map
419
+ map,
419
420
  );
420
421
 
421
422
  node.parent = newFolder;
@@ -1,159 +1,215 @@
1
- import async from "async";
2
- import disjoint from "@turf/boolean-disjoint";
3
- import bbox from "@turf/bbox";
4
- import {
5
- formatArcgisVector,
6
- identifyExcludeColumnsArcgisvector,
7
- identifyIncludeColumnsArcgisvector,
8
- identifyRenameColumnsArcgisvector,
9
- identifyFormatColumnsArcgisvector,
10
- } from "../../openlayers-utils/format-utilities";
11
-
12
- function buildMapServerUrl(lyr, extent) {
13
- return [
14
- `${lyr.url}`,
15
- `?service=WFS`,
16
- `&version=1.0.0`,
17
- `&request=GetFeature`,
18
- `&bbox=${extent[0]},${extent[1]},${extent[2]},${extent[3]},EPSG:4326`,
19
- `&typeName=${lyr.layerList}`,
20
- `&outputFormat=application%2Fjson`,
21
- ].join("");
22
- }
23
-
24
- export default {
25
- name: "mapServerIdent",
26
-
27
- getReducer() {
28
- const initialData = {
29
- shouldRegister: true,
30
- };
31
-
32
- return (state = initialData, { type, payload }) => {
33
- switch (type) {
34
- case "MAP_SERVER_IDENT_REGISTERED":
35
- return Object.assign({}, state, payload);
36
- default:
37
- return state;
38
- }
39
- };
40
- },
41
-
42
- doMapServerIdentRegister:
43
- () =>
44
- ({ dispatch, store }) => {
45
- dispatch({
46
- type: "MAP_SERVER_IDENT_REGISTERED",
47
- payload: { shouldRegister: false },
48
- });
49
- store.doIdentifyAddCollection({
50
- onIdentify: store.doMapServerIdentFire,
51
- });
52
- },
53
-
54
- doMapServerIdentFire:
55
- (callback) =>
56
- ({ store, anonGet }) => {
57
- const visibleLayers = store.selectVisibleLayers();
58
- const identifyFeature = store.doSetIdentifyFeature();
59
- const extent = bbox(identifyFeature);
60
- const excludedColumns = store.selectIdentifyColumnsExclude();
61
- const queries = [];
62
-
63
- visibleLayers.forEach((lyr) => {
64
- if (lyr.identifyType && lyr.identifyType === "MAP") {
65
- const url = buildMapServerUrl(lyr, extent);
66
-
67
- queries.push((cb) => {
68
- anonGet(url, (err, response, body) => {
69
- if (err || response.statusCode !== 200) {
70
- return cb(null, {
71
- dataset: lyr.uid,
72
- layerName: lyr.displayName,
73
- err: `Error for ${lyr.displayName}`,
74
- result: { [lyr.uid]: {} },
75
- });
76
- }
77
- try {
78
- const data = JSON.parse(body);
79
- let outFeatures = data.features
80
- .filter((feature) => !disjoint(feature, identifyFeature))
81
- .map((feature) => {
82
- if (feature.properties.LATITUDE) {
83
- feature.properties.LATITUDE = Number(
84
- feature.properties.LATITUDE
85
- ).toFixed(6);
86
- }
87
- if (feature.properties.LONGITUDE) {
88
- feature.properties.LONGITUDE = Number(
89
- feature.properties.LONGITUDE
90
- ).toFixed(6);
91
- }
92
- return feature;
93
- });
94
-
95
- outFeatures = identifyExcludeColumnsArcgisvector(
96
- outFeatures,
97
- excludedColumns
98
- );
99
-
100
- if (lyr.identifyFields) {
101
- outFeatures = identifyIncludeColumnsArcgisvector(
102
- outFeatures,
103
- lyr.identifyFields
104
- );
105
- }
106
-
107
- const identifyRenameColumns =
108
- lyr.identifyRenameColumns ?? lyr.identifyRenameColums;
109
- if (identifyRenameColumns) {
110
- outFeatures = identifyRenameColumnsArcgisvector(
111
- outFeatures,
112
- identifyRenameColumns
113
- );
114
- }
115
-
116
- if (lyr.identifyFormatColumns) {
117
- outFeatures = identifyFormatColumnsArcgisvector(
118
- outFeatures,
119
- lyr.identifyFormatColumns
120
- );
121
- }
122
-
123
- outFeatures = formatArcgisVector(outFeatures);
124
-
125
- return cb(null, {
126
- dataset: lyr.uid,
127
- layerName: lyr.displayName,
128
- err: null,
129
- result: {
130
- [lyr.uid]: {
131
- type: "FeatureCollection",
132
- features: outFeatures,
133
- },
134
- },
135
- });
136
- } catch (parseErr) {
137
- console.log(parseErr);
138
- return cb(null, {
139
- dataset: lyr.uid,
140
- layerName: lyr.displayName,
141
- err: `Error for ${lyr.displayName}`,
142
- result: { [lyr.uid]: {} },
143
- });
144
- }
145
- });
146
- });
147
- }
148
- });
149
-
150
- async.parallel(queries, (err, results) => {
151
- callback(err, results);
152
- });
153
- },
154
-
155
- reactMapServerIdentShouldRegister: (state) => {
156
- if (state.mapServerIdent.shouldRegister)
157
- return { actionCreator: "doMapServerIdentRegister" };
158
- },
159
- };
1
+ import async from "async";
2
+ import disjoint from "@turf/boolean-disjoint";
3
+ import bbox from "@turf/bbox";
4
+ import {
5
+ formatArcgisVector,
6
+ identifyExcludeColumnsArcgisvector,
7
+ identifyIncludeColumnsArcgisvector,
8
+ identifyRenameColumnsArcgisvector,
9
+ identifyFormatColumnsArcgisvector,
10
+ } from "../../openlayers-utils/format-utilities";
11
+
12
+ // typeName is passed in so one layer can issue several requests (see identifyLayers below).
13
+ function buildMapServerUrl(lyr, typeName, extent) {
14
+ return [
15
+ `${lyr.url}`,
16
+ `?service=WFS`,
17
+ `&version=1.0.0`,
18
+ `&request=GetFeature`,
19
+ `&bbox=${extent[0]},${extent[1]},${extent[2]},${extent[3]},EPSG:4326`,
20
+ `&typeName=${typeName}`,
21
+ `&outputFormat=application%2Fjson`,
22
+ ].join("");
23
+ }
24
+
25
+ /**
26
+ * Work out which WFS requests to send for a layer.
27
+ *
28
+ * A layer with a non-empty `identifyLayers` array (e.g. a MapServer group such as a
29
+ * FUDS Top 10 site) sends one request per entry:
30
+ * identifyLayers: [{ layerList: "internal_property", displayName: "Property" }, ...]
31
+ * Results for those requests are keyed `${lyr.uid}:${displayName}`, which the identify
32
+ * UI splits on ":" to show "<layer name>:<displayName>".
33
+ *
34
+ * A layer without `identifyLayers` sends a single request using `layerList` and keeps
35
+ * the original result key (`lyr.uid`), so its behaviour is unchanged.
36
+ */
37
+ function getIdentifyTargets(lyr) {
38
+ const hasIdentifyLayers =
39
+ Array.isArray(lyr.identifyLayers) && lyr.identifyLayers.length > 0;
40
+
41
+ if (!hasIdentifyLayers) {
42
+ return [
43
+ {
44
+ typeName: lyr.layerList,
45
+ resultKey: lyr.uid,
46
+ layerName: lyr.displayName,
47
+ label: lyr.id,
48
+ },
49
+ ];
50
+ }
51
+
52
+ return lyr.identifyLayers
53
+ .filter((entry) => {
54
+ if (entry && entry.layerList) return true;
55
+ console.warn(
56
+ `[mapServerIdent] ${lyr.id}: identifyLayers entry has no layerList, skipping`,
57
+ entry
58
+ );
59
+ return false;
60
+ })
61
+ .map((entry) => {
62
+ const name = entry.displayName || entry.layerList;
63
+ return {
64
+ typeName: entry.layerList,
65
+ resultKey: `${lyr.uid}:${name}`,
66
+ layerName: `${lyr.displayName}:${name}`,
67
+ label: `${lyr.id}/${entry.layerList}`,
68
+ };
69
+ });
70
+ }
71
+
72
+ export default {
73
+ name: "mapServerIdent",
74
+
75
+ getReducer() {
76
+ const initialData = {
77
+ shouldRegister: true,
78
+ };
79
+
80
+ return (state = initialData, { type, payload }) => {
81
+ switch (type) {
82
+ case "MAP_SERVER_IDENT_REGISTERED":
83
+ return Object.assign({}, state, payload);
84
+ default:
85
+ return state;
86
+ }
87
+ };
88
+ },
89
+
90
+ doMapServerIdentRegister:
91
+ () =>
92
+ ({ dispatch, store }) => {
93
+ dispatch({
94
+ type: "MAP_SERVER_IDENT_REGISTERED",
95
+ payload: { shouldRegister: false },
96
+ });
97
+ store.doIdentifyAddCollection({
98
+ onIdentify: store.doMapServerIdentFire,
99
+ });
100
+ },
101
+
102
+ doMapServerIdentFire:
103
+ (callback) =>
104
+ ({ store, anonGet }) => {
105
+ const visibleLayers = store.selectVisibleLayers();
106
+ const identifyFeature = store.doSetIdentifyFeature();
107
+ const extent = bbox(identifyFeature);
108
+ const excludedColumns = store.selectIdentifyColumnsExclude();
109
+ const queries = [];
110
+
111
+ visibleLayers.forEach((lyr) => {
112
+ if (lyr.identifyType && lyr.identifyType === "MAP") {
113
+ const targets = getIdentifyTargets(lyr);
114
+
115
+ targets.forEach((target) => {
116
+ const url = buildMapServerUrl(lyr, target.typeName, extent);
117
+
118
+ queries.push((cb) => {
119
+ anonGet(url, (err, response, body) => {
120
+ if (err || response.statusCode !== 200) {
121
+ return cb(null, {
122
+ dataset: lyr.uid,
123
+ layerName: target.layerName,
124
+ err: `Error for ${target.layerName}`,
125
+ result: { [target.resultKey]: {} },
126
+ });
127
+ }
128
+ try {
129
+ const data = JSON.parse(body);
130
+ let outFeatures = data.features
131
+ .filter((feature) => !disjoint(feature, identifyFeature))
132
+ .map((feature) => {
133
+ if (feature.properties.LATITUDE) {
134
+ feature.properties.LATITUDE = Number(
135
+ feature.properties.LATITUDE
136
+ ).toFixed(6);
137
+ }
138
+ if (feature.properties.LONGITUDE) {
139
+ feature.properties.LONGITUDE = Number(
140
+ feature.properties.LONGITUDE
141
+ ).toFixed(6);
142
+ }
143
+ return feature;
144
+ });
145
+
146
+ outFeatures = identifyExcludeColumnsArcgisvector(
147
+ outFeatures,
148
+ excludedColumns
149
+ );
150
+
151
+ // Column options come from the parent layer; for FUDS Top 10 these are
152
+ // all null, so every sub-layer returns all of its columns.
153
+ if (lyr.identifyFields) {
154
+ outFeatures = identifyIncludeColumnsArcgisvector(
155
+ outFeatures,
156
+ lyr.identifyFields
157
+ );
158
+ }
159
+
160
+ const identifyRenameColumns =
161
+ lyr.identifyRenameColumns ?? lyr.identifyRenameColums;
162
+ if (identifyRenameColumns) {
163
+ outFeatures = identifyRenameColumnsArcgisvector(
164
+ outFeatures,
165
+ identifyRenameColumns
166
+ );
167
+ }
168
+
169
+ if (lyr.identifyFormatColumns) {
170
+ outFeatures = identifyFormatColumnsArcgisvector(
171
+ outFeatures,
172
+ lyr.identifyFormatColumns
173
+ );
174
+ }
175
+
176
+ outFeatures = formatArcgisVector(outFeatures);
177
+
178
+ // dataset stays lyr.uid (the UI looks the layer name up with it); the
179
+ // result key carries the sub-layer name for identifyLayers entries.
180
+
181
+ return cb(null, {
182
+ dataset: lyr.uid,
183
+ layerName: target.layerName,
184
+ err: null,
185
+ result: {
186
+ [target.resultKey]: {
187
+ type: "FeatureCollection",
188
+ features: outFeatures,
189
+ },
190
+ },
191
+ });
192
+ } catch (parseErr) {
193
+ return cb(null, {
194
+ dataset: lyr.uid,
195
+ layerName: target.layerName,
196
+ err: `Error for ${target.layerName}`,
197
+ result: { [target.resultKey]: {} },
198
+ });
199
+ }
200
+ });
201
+ });
202
+ });
203
+ }
204
+ });
205
+
206
+ async.parallel(queries, (err, results) => {
207
+ callback(err, results);
208
+ });
209
+ },
210
+
211
+ reactMapServerIdentShouldRegister: (state) => {
212
+ if (state.mapServerIdent.shouldRegister)
213
+ return { actionCreator: "doMapServerIdentRegister" };
214
+ },
215
+ };
@@ -74,4 +74,3 @@ export default {
74
74
  },
75
75
  };
76
76
 
77
- //debugger
@@ -16,4 +16,3 @@ const plugin = {
16
16
 
17
17
  export default plugin;
18
18
 
19
- //debugger
@@ -20,4 +20,3 @@ const plugin = {
20
20
 
21
21
  export default plugin;
22
22
 
23
- //debugger
@@ -32,4 +32,3 @@ export default {
32
32
  },
33
33
  };
34
34
 
35
- // debugger
@@ -77,4 +77,3 @@ export default {
77
77
  },
78
78
  };
79
79
 
80
- //debugger