@corpsmap/corpsmap 3.2.68 → 3.2.71

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