@corpsmap/corpsmap 3.2.65 → 3.2.68

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.
@@ -1,129 +1,149 @@
1
- import buffer from '@turf/buffer';
2
- import { point } from '@turf/helpers';
3
- import { polygon } from '@turf/helpers';
4
- import disjoint from '@turf/boolean-disjoint';
5
- import { join } from 'path';
1
+ import buffer from "@turf/buffer";
2
+ import { point } from "@turf/helpers";
3
+ import { polygon } from "@turf/helpers";
4
+ import disjoint from "@turf/boolean-disjoint";
5
+ //JB
6
+ // import { join } from 'path';
6
7
 
7
8
  export default {
8
- name: 'geojsonIdent',
9
+ name: "geojsonIdent",
9
10
 
10
- getReducer(){
11
+ getReducer() {
11
12
  const initialData = {
12
13
  shouldRegister: false,
13
14
  shouldHandleRemove: false,
14
15
  removedUid: null,
15
- data: {}
16
- }
16
+ data: {},
17
+ };
17
18
 
18
19
  return (state = initialData, { type, payload }) => {
19
- switch(type){
20
- case 'GEOJSON_IDENT_REGISTERED':
21
- case 'GEOJSON_IDENT_ADDED_FEATURES':
22
- case 'GEOJSON_IDENT_REMOVED_FEATURES':
23
- case 'GEOJSON_IDENT_HANDLED_REMOVE':
20
+ switch (type) {
21
+ case "GEOJSON_IDENT_REGISTERED":
22
+ case "GEOJSON_IDENT_ADDED_FEATURES":
23
+ case "GEOJSON_IDENT_REMOVED_FEATURES":
24
+ case "GEOJSON_IDENT_HANDLED_REMOVE":
24
25
  return Object.assign({}, state, payload);
25
- case 'LAYER_REMOVED':
26
+ case "LAYER_REMOVED":
26
27
  return Object.assign({}, state, {
27
28
  removedUid: payload.uid,
28
- shouldHandleRemove: true
29
- })
30
- default:
29
+ shouldHandleRemove: true,
30
+ });
31
+ default:
31
32
  return state;
32
33
  }
33
- }
34
- },
35
-
36
- doGeojsonIdentRegister: () => ({dispatch, store}) => {
37
- dispatch({type: 'GEOJSON_IDENT_REGISTERED', payload: { shouldRegister: false }});
38
- store.doIdentifyAddCollection({
39
- onIdentify: store.doGeojsonIdentFire
40
- })
41
- },
42
-
43
- doGeojsonIdentRemoveFeatures: (uid) => ({ dispatch, store }) => {
44
- dispatch({ type: 'GEOJSON_IDENT_HANDLED_REMOVE', payload: { shouldHandleRemove: false }});
45
- const uid = store.selectGeojsonRemovedUid();
46
- const data = store.selectGeojsonIdentFeatures();
47
- delete data[uid];
48
- dispatch({ type: 'GEOJSON_IDENT_REMOVED_FEATURES', payload: { data: Object.assign({}, data), removedUid: null}});
49
- },
50
-
51
- doGeojsonIdentAddFeatures: (uid, geojson, mapLayer) => ({dispatch, store}) => {
52
- const data = store.selectGeojsonIdentFeatures();
53
-
54
- if(!data[uid]) data[uid] = {
55
- features: [],
56
- maplayer: null
57
34
  };
58
-
59
- if(geojson){
60
- let newFeatures = [];
61
- if(geojson.length){
62
- newFeatures = geojson;
63
- }else if(geojson.features){
64
- newFeatures = geojson.features;
65
- }else{
66
- newFeatures = [ geojson ]
67
- }
68
- data[uid].features = [...data[uid].features, ...newFeatures];
69
- }
70
-
71
- if(mapLayer){
72
- data[uid].mapLayer = mapLayer;
73
- }
74
-
75
- dispatch({ type: 'GEOJSON_IDENT_ADDED_FEATURES', payload: { data: Object.assign({}, data) }});
76
35
  },
77
36
 
78
- doGeojsonIdentFire: (callback) => ({dispatch, store}) => {
79
- const coords = store.selectIdentifyCoordinates();
80
- const resolution = store.selectResolution();
81
- const data = store.selectGeojsonIdentFeatures();
82
- let identifyFeature = null;
83
-
84
- if(typeof coords[0] === 'number'){
85
- const pt = point(coords);
86
- const radius = resolution * 5 / 1000;
87
- identifyFeature = buffer(pt, radius, {
88
- units: 'kilometers'
89
- })
90
- }else{
91
- identifyFeature = polygon(coords);
92
- }
93
-
94
- try{
95
- const out = [];
96
-
97
- Object.keys(data).forEach((key) => {
98
-
99
- const outFeatures = [];
100
- const inFeatures = data[key].features;
101
- const mapLayer = data[key].mapLayer;
102
- if(mapLayer.getVisible()){
103
- inFeatures.forEach((feature) => {
104
- if(!disjoint(identifyFeature, feature)) outFeatures.push(feature);
105
- })
106
- out.push({
107
- dataset: key,
108
- err: null,
109
- result: {
110
- [key]: {
111
- type: 'FeatureCollection',
112
- features: outFeatures
113
- }
114
- }
115
- })
37
+ doGeojsonIdentRegister:
38
+ () =>
39
+ ({ dispatch, store }) => {
40
+ dispatch({
41
+ type: "GEOJSON_IDENT_REGISTERED",
42
+ payload: { shouldRegister: false },
43
+ });
44
+ store.doIdentifyAddCollection({
45
+ onIdentify: store.doGeojsonIdentFire,
46
+ });
47
+ },
48
+
49
+ doGeojsonIdentRemoveFeatures:
50
+ (uid) =>
51
+ ({ dispatch, store }) => {
52
+ dispatch({
53
+ type: "GEOJSON_IDENT_HANDLED_REMOVE",
54
+ payload: { shouldHandleRemove: false },
55
+ });
56
+ const uid = store.selectGeojsonRemovedUid();
57
+ const data = store.selectGeojsonIdentFeatures();
58
+ delete data[uid];
59
+ dispatch({
60
+ type: "GEOJSON_IDENT_REMOVED_FEATURES",
61
+ payload: { data: Object.assign({}, data), removedUid: null },
62
+ });
63
+ },
64
+
65
+ doGeojsonIdentAddFeatures:
66
+ (uid, geojson, mapLayer) =>
67
+ ({ dispatch, store }) => {
68
+ const data = store.selectGeojsonIdentFeatures();
69
+
70
+ if (!data[uid])
71
+ data[uid] = {
72
+ features: [],
73
+ maplayer: null,
74
+ };
75
+
76
+ if (geojson) {
77
+ let newFeatures = [];
78
+ if (geojson.length) {
79
+ newFeatures = geojson;
80
+ } else if (geojson.features) {
81
+ newFeatures = geojson.features;
82
+ } else {
83
+ newFeatures = [geojson];
116
84
  }
85
+ data[uid].features = [...data[uid].features, ...newFeatures];
86
+ }
117
87
 
118
- })
88
+ if (mapLayer) {
89
+ data[uid].mapLayer = mapLayer;
90
+ }
119
91
 
120
- callback(null, out);
92
+ dispatch({
93
+ type: "GEOJSON_IDENT_ADDED_FEATURES",
94
+ payload: { data: Object.assign({}, data) },
95
+ });
96
+ },
97
+
98
+ doGeojsonIdentFire:
99
+ (callback) =>
100
+ ({ dispatch, store }) => {
101
+ const coords = store.selectIdentifyCoordinates();
102
+ const resolution = store.selectResolution();
103
+ const data = store.selectGeojsonIdentFeatures();
104
+ let identifyFeature = null;
105
+
106
+ if (typeof coords[0] === "number") {
107
+ const pt = point(coords);
108
+ const radius = (resolution * 5) / 1000;
109
+ identifyFeature = buffer(pt, radius, {
110
+ units: "kilometers",
111
+ });
112
+ } else {
113
+ identifyFeature = polygon(coords);
114
+ }
121
115
 
122
- }catch(err){
123
- console.log(err);
124
- callback(err);
125
- }
126
- },
116
+ try {
117
+ const out = [];
118
+
119
+ Object.keys(data).forEach((key) => {
120
+ const outFeatures = [];
121
+ const inFeatures = data[key].features;
122
+ const mapLayer = data[key].mapLayer;
123
+ if (mapLayer.getVisible()) {
124
+ inFeatures.forEach((feature) => {
125
+ if (!disjoint(identifyFeature, feature))
126
+ outFeatures.push(feature);
127
+ });
128
+ out.push({
129
+ dataset: key,
130
+ err: null,
131
+ result: {
132
+ [key]: {
133
+ type: "FeatureCollection",
134
+ features: outFeatures,
135
+ },
136
+ },
137
+ });
138
+ }
139
+ });
140
+
141
+ callback(null, out);
142
+ } catch (err) {
143
+ console.log(err);
144
+ callback(err);
145
+ }
146
+ },
127
147
 
128
148
  selectGeojsonIdentFeatures: (state) => {
129
149
  return state.geojsonIdent.data;
@@ -134,10 +154,12 @@ export default {
134
154
  },
135
155
 
136
156
  reactGeojsonIdentShouldRegister: (state) => {
137
- if(state.geojsonIdent.shouldRegister) return { actionCreator: 'doGeojsonIdentRegister' };
157
+ if (state.geojsonIdent.shouldRegister)
158
+ return { actionCreator: "doGeojsonIdentRegister" };
138
159
  },
139
160
 
140
161
  reactGeojsonIdentShouldHandleRemove: (state) => {
141
- if(state.geojsonIdent.shouldHandleRemove) return { actionCreator: 'doGeojsonIdentRemoveFeatures' };
142
- }
143
- }
162
+ if (state.geojsonIdent.shouldHandleRemove)
163
+ return { actionCreator: "doGeojsonIdentRemoveFeatures" };
164
+ },
165
+ };