@corpsmap/corpsmap 3.1.0 → 3.1.3

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,308 +1,312 @@
1
- import { transform } from "ol/proj";
2
- import { createSelector } from "redux-bundler";
3
- import _ from "lodash";
4
-
5
- const animateView = (options, view) => {
6
- view.animate(options);
7
- };
8
-
9
- const zoomToLocation = (center, zoom, view) => {
10
- animateView(
11
- {
12
- center: center,
13
- zoom: zoom,
14
- },
15
- view
16
- );
17
- };
18
-
19
- export default {
20
- name: "view",
21
-
22
- getReducer: () => {
23
- const initialData = {
24
- shouldReadUrlParams: false,
25
- shouldSetDefaults: false,
26
- center: [-98.579, 39.828],
27
- zoom: 4,
28
- rotation: 0,
29
- position: {},
30
- heading: 0,
31
- pitch: 0,
32
- roll: 0,
33
- minZoom: 0,
34
- maxZoom: 22,
35
- action: null,
36
- updating: false,
37
- listening: false,
38
- shouldUpdateZoom: false,
39
- };
40
-
41
- return (state = initialData, { type, payload }) => {
42
- switch (type) {
43
- case "VIEW_SET_DEFAULTS_START":
44
- case "VIEW_SET_DEFAULTS":
45
- case "VIEW_SET_PARAMS_START":
46
- case "VIEW_SET_PARAMS_COMPLETE":
47
- return Object.assign({}, state, payload);
48
- case "WINDOW_LOCATION_PARSED":
49
- return Object.assign({}, state, {
50
- shouldReadUrlParams: true,
51
- });
52
- case "MAP_INITIALIZED":
53
- return Object.assign({}, state, {
54
- shouldSetDefaults: true,
55
- });
56
- }
57
-
58
- if (type === "VIEW_START_ACTION") {
59
- return Object.assign({}, state, {
60
- updating: true,
61
- });
62
- }
63
-
64
- if (type === "VIEW_END_ACTION") {
65
- return Object.assign({}, state, {
66
- updating: false,
67
- });
68
- }
69
-
70
- if (type === "VIEW_EVENTS_REGISTERED") {
71
- return Object.assign({}, state, {
72
- listening: true,
73
- });
74
- }
75
-
76
- if (type === "VIEW_CHANGED") {
77
- return Object.assign({}, state, payload);
78
- }
79
-
80
- return state;
81
- };
82
- },
83
-
84
- doViewSetDefaults: (d) => ({ dispatch, store }) => {
85
- // grab the config from our launch config, override built-in defaults
86
- dispatch({
87
- type: "VIEW_SET_DEFAULTS_START",
88
- payload: { shouldSetDefaults: false },
89
- });
90
- const config = {
91
- center:
92
- d.centerX && d.centerY ? [d.centerX, d.centerY] : [-95.579, 39.828],
93
- zoom: d.centerZ ? d.centerZ : 4,
94
- rotation: d.rotation ? d.rotation : 0,
95
- position: {},
96
- heading: d.heading3d ? d.heading3d : 0,
97
- pitch: 0,
98
- roll: 0,
99
- minZoom: d.minzoom ? d.minzoom : 0,
100
- maxZoom: d.maxzoom ? d.maxzoom : 22,
101
-
102
- };
103
-
104
- dispatch({ type: "VIEW_SET_DEFAULTS", payload: config });
105
- },
106
-
107
- doViewSetFromParams: () => ({ dispatch, store }) => {
108
- dispatch({
109
- type: "VIEW_SET_PARAMS_START",
110
- payload: { shouldReadUrlParams: false },
111
- });
112
- const config = store.selectViewState();
113
- const params = store.selectWindowLocationParams();
114
-
115
- // grab config from url parameters and override everything
116
- if (Number(params.x)) config.center[0] = Number(params.x);
117
- if (Number(params.y)) config.center[1] = Number(params.y);
118
- if (Number(params.z)) config.zoom = Number(params.z);
119
-
120
- store.doSetView(config);
121
- //dispatch({ type: 'VIEW_SET_PARAMS_COMPLETE', payload: config });
122
- },
123
-
124
- doZoomToExtent: (extent, callback) => ({ dispatch, store }) => {
125
- dispatch({ type: "VIEW_START_ACTION" });
126
-
127
- const map = store.selectMap();
128
- const view = store.selectView();
129
- view.fit(extent, {
130
- size: map.getSize(),
131
- duration: 500,
132
- minResolution: 10,
133
- callback: () => {
134
- if (callback && typeof callback === "function") callback();
135
- dispatch({ type: "VIEW_END_ACTION" });
136
- },
137
- });
138
- },
139
-
140
- doZoomToLayerExtent: (uid) => ({ dispatch, store }) => {
141
- // @TODO get the layer from the store and figure out where to zoom to
142
- },
143
-
144
- doZoomToLocation: (center, zoom) => ({ dispatch, store }) => {
145
- dispatch({ type: "VIEW_START_ACTION" });
146
- const view = store.selectView();
147
- zoomToLocation(center, zoom, view);
148
- dispatch({ type: "VIEW_END_ACTION" });
149
- },
150
-
151
- doZoomIn: () => ({ dispatch, store }) => {
152
- dispatch({ type: "VIEW_START_ACTION" });
153
- const view = store.selectView();
154
- const currentZoom = view.getZoom();
155
- animateView(
156
- {
157
- zoom: currentZoom + 1,
158
- },
159
- view
160
- );
161
- dispatch({ type: "VIEW_END_ACTION" });
162
- },
163
-
164
- doZoomOut: () => ({ dispatch, store }) => {
165
- dispatch({ type: "VIEW_START_ACTION" });
166
- const view = store.selectView(); // pulling view
167
- const currentZoom = view.getZoom(); // getting current view
168
- animateView( // subtract 1 from current zoom
169
- {
170
- zoom: currentZoom - 1,
171
- },
172
- view
173
- );
174
- dispatch({ type: "VIEW_END_ACTION" });
175
- },
176
-
177
- doSetRotationNorth: () => ({ dispatch, store }) => {
178
- dispatch({ type: "VIEW_START_ACTION" });
179
- const view = store.selectView();
180
- animateView(
181
- {
182
- rotation: 0,
183
- },
184
- view
185
- );
186
- dispatch({ type: "VIEW_END_ACTION" });
187
- },
188
-
189
- doUpdateView: (e) => ({ dispatch, store }) => {
190
- const map = e.map;
191
- const view = map.getView();
192
- const zoom = view.getZoom();
193
- const center = transform(
194
- view.getCenter(),
195
- store.selectMapProjection(),
196
- "EPSG:4326"
197
- );
198
- const rotation = view.getRotation() * (180 / Math.PI);
199
- dispatch({ type: "VIEW_CHANGED", payload: { center, zoom, rotation } });
200
- },
201
-
202
- doSetView: (options) => ({ dispatch, store }) => {
203
- const view = store.selectView();
204
- if (!view) return null;
205
- animateView(
206
- {
207
- center: transform(
208
- options.center,
209
- "EPSG:4326",
210
- store.selectMapProjection()
211
- ),
212
- zoom: options.zoom,
213
- rotation: options.rotation,
214
- },
215
- view
216
- );
217
- },
218
-
219
- doListenToMap: () => ({ dispatch, store }) => {
220
- const map = store.selectMap();
221
- // now handled in the map bundle, need to dedupe these
222
- //map.on('moveend', _.throttle(store.doUpdateView, 200));
223
- dispatch({ type: "VIEW_EVENTS_REGISTERED" });
224
- },
225
-
226
- selectViewState: (state) => {
227
- return state.view;
228
- },
229
-
230
- selectViewAction: (state) => {
231
- return state.view.action;
232
- },
233
-
234
- selectViewCenter: createSelector(
235
- "selectAppTime",
236
- "selectMap",
237
- "selectViewState",
238
- (_, map, viewState) => {
239
- if (!map) return viewState.center;
240
- const view = map.getView();
241
- if (!view) return viewState.center;
242
- return view.getCenter();
243
- }
244
- ),
245
-
246
- selectMapSize: createSelector(
247
- "selectMap",
248
- "selectAppTime",
249
- (map, appTime) => {
250
- if (!map) return null;
251
- return map.getSize();
252
- }
253
- ),
254
-
255
- selectMapImageDisplay: createSelector("selectMapSize", (size) => {
256
- if (!size) return null;
257
- return [size[0], size[1], 92];
258
- }),
259
-
260
- selectMapExtent: createSelector(
261
- "selectAppTime",
262
- "selectView",
263
- "selectMapSize",
264
- "selectMapProjection",
265
- (_, view, size, mapProjection) => {
266
- if (!view) return null;
267
- const mapExtentWm = view.calculateExtent(size);
268
- const ll = transform(
269
- [mapExtentWm[0], mapExtentWm[1]],
270
- mapProjection,
271
- "EPSG:4326"
272
- );
273
- const ur = transform(
274
- [mapExtentWm[2], mapExtentWm[3]],
275
- mapProjection,
276
- "EPSG:4326"
277
- );
278
- return [ll[0], ll[1], ur[0], ur[1]];
279
- }
280
- ),
281
-
282
- selectResolution: createSelector(
283
- "selectView",
284
- "selectAppTime",
285
- (view, appTime) => {
286
- if (!view) return null;
287
- return view.getResolution();
288
- }
289
- ),
290
-
291
- reactAddListeners: (state) => {
292
- if (!state.view.listening && state.map.map2d)
293
- return { actionCreator: "doListenToMap" };
294
- },
295
-
296
- reactViewShouldReadUrlParams: (state) => {
297
- if (state.view.shouldReadUrlParams)
298
- return { actionCreator: "doViewSetFromParams" };
299
- },
300
-
301
- reactViewShouldSetDefaults: (state) => {
302
- if (state.view.shouldSetDefaults)
303
- return {
304
- actionCreator: "doViewSetDefaults",
305
- args: [state.config.default.map],
306
- };
307
- },
308
- };
1
+ import { transform } from "ol/proj";
2
+ import { createSelector } from "redux-bundler";
3
+ import _ from "lodash";
4
+
5
+ const animateView = (options, view) => {
6
+ view.animate(options);
7
+ };
8
+
9
+ const zoomToLocation = (center, zoom, view) => {
10
+ animateView(
11
+ {
12
+ center: center,
13
+ zoom: zoom,
14
+ },
15
+ view
16
+ );
17
+ };
18
+
19
+ export default {
20
+ name: "view",
21
+
22
+ getReducer: () => {
23
+ const initialData = {
24
+ shouldReadUrlParams: false,
25
+ shouldSetDefaults: false,
26
+ center: [-98.579, 39.828],
27
+ zoom: 4,
28
+ rotation: 0,
29
+ position: {},
30
+ heading: 0,
31
+ pitch: 0,
32
+ roll: 0,
33
+ minZoom: 0,
34
+ maxZoom: 22,
35
+ action: null,
36
+ updating: false,
37
+ listening: false,
38
+ shouldUpdateZoom: false,
39
+ // horse: true,
40
+ // limitMapExtent: true,
41
+ };
42
+
43
+ return (state = initialData, { type, payload }) => {
44
+ switch (type) {
45
+ case "VIEW_SET_DEFAULTS_START":
46
+ case "VIEW_SET_DEFAULTS":
47
+ case "VIEW_SET_PARAMS_START":
48
+ case "VIEW_SET_PARAMS_COMPLETE":
49
+ return Object.assign({}, state, payload);
50
+ case "WINDOW_LOCATION_PARSED":
51
+ return Object.assign({}, state, {
52
+ shouldReadUrlParams: true,
53
+ });
54
+ case "MAP_INITIALIZED":
55
+ return Object.assign({}, state, {
56
+ shouldSetDefaults: true,
57
+ });
58
+ }
59
+
60
+ if (type === "VIEW_START_ACTION") {
61
+ return Object.assign({}, state, {
62
+ updating: true,
63
+ });
64
+ }
65
+
66
+ if (type === "VIEW_END_ACTION") {
67
+ return Object.assign({}, state, {
68
+ updating: false,
69
+ });
70
+ }
71
+
72
+ if (type === "VIEW_EVENTS_REGISTERED") {
73
+ return Object.assign({}, state, {
74
+ listening: true,
75
+ });
76
+ }
77
+
78
+ if (type === "VIEW_CHANGED") {
79
+ return Object.assign({}, state, payload);
80
+ }
81
+
82
+ return state;
83
+ };
84
+ },
85
+
86
+ doViewSetDefaults: (d) => ({ dispatch, store }) => {
87
+ // grab the config from our launch config, override built-in defaults
88
+
89
+ dispatch({
90
+ type: "VIEW_SET_DEFAULTS_START",
91
+ payload: { shouldSetDefaults: false },
92
+ });
93
+ const config = {
94
+ center:
95
+ d.centerX && d.centerY ? [d.centerX, d.centerY] : [-95.579, 39.828],
96
+ zoom: d.centerZ ? d.centerZ : 4,
97
+ rotation: d.rotation ? d.rotation : 0,
98
+ position: {},
99
+ heading: d.heading3d ? d.heading3d : 0,
100
+ pitch: 0,
101
+ roll: 0,
102
+ minZoom: d.minzoom ? d.minzoom : 0,
103
+ maxZoom: d.maxzoom ? d.maxzoom : 22,
104
+ // limitMapExtent: d.limitMapExtent ? d.limitMapExtent : false,
105
+
106
+ };
107
+
108
+ dispatch({ type: "VIEW_SET_DEFAULTS", payload: config });
109
+ },
110
+
111
+ doViewSetFromParams: () => ({ dispatch, store }) => {
112
+ dispatch({
113
+ type: "VIEW_SET_PARAMS_START",
114
+ payload: { shouldReadUrlParams: false },
115
+ });
116
+ const config = store.selectViewState();
117
+ const params = store.selectWindowLocationParams();
118
+
119
+ // grab config from url parameters and override everything
120
+ if (Number(params.x)) config.center[0] = Number(params.x);
121
+ if (Number(params.y)) config.center[1] = Number(params.y);
122
+ if (Number(params.z)) config.zoom = Number(params.z);
123
+
124
+ store.doSetView(config);
125
+ //dispatch({ type: 'VIEW_SET_PARAMS_COMPLETE', payload: config });
126
+ },
127
+
128
+ doZoomToExtent: (extent, callback) => ({ dispatch, store }) => {
129
+ dispatch({ type: "VIEW_START_ACTION" });
130
+
131
+ const map = store.selectMap();
132
+ const view = store.selectView();
133
+ view.fit(extent, {
134
+ size: map.getSize(),
135
+ duration: 500,
136
+ minResolution: 10,
137
+ callback: () => {
138
+ if (callback && typeof callback === "function") callback();
139
+ dispatch({ type: "VIEW_END_ACTION" });
140
+ },
141
+ });
142
+ },
143
+
144
+ doZoomToLayerExtent: (uid) => ({ dispatch, store }) => {
145
+ // @TODO get the layer from the store and figure out where to zoom to
146
+ },
147
+
148
+ doZoomToLocation: (center, zoom) => ({ dispatch, store }) => {
149
+ dispatch({ type: "VIEW_START_ACTION" });
150
+ const view = store.selectView();
151
+ zoomToLocation(center, zoom, view);
152
+ dispatch({ type: "VIEW_END_ACTION" });
153
+ },
154
+
155
+ doZoomIn: () => ({ dispatch, store }) => {
156
+ dispatch({ type: "VIEW_START_ACTION" });
157
+ const view = store.selectView();
158
+ const currentZoom = view.getZoom();
159
+ animateView(
160
+ {
161
+ zoom: currentZoom + 1,
162
+ },
163
+ view
164
+ );
165
+ dispatch({ type: "VIEW_END_ACTION" });
166
+ },
167
+
168
+ doZoomOut: () => ({ dispatch, store }) => {
169
+ dispatch({ type: "VIEW_START_ACTION" });
170
+ const view = store.selectView(); // pulling view
171
+ const currentZoom = view.getZoom(); // getting current view
172
+ animateView( // subtract 1 from current zoom
173
+ {
174
+ zoom: currentZoom - 1,
175
+ },
176
+ view
177
+ );
178
+ dispatch({ type: "VIEW_END_ACTION" });
179
+ },
180
+
181
+ doSetRotationNorth: () => ({ dispatch, store }) => {
182
+ dispatch({ type: "VIEW_START_ACTION" });
183
+ const view = store.selectView();
184
+ animateView(
185
+ {
186
+ rotation: 0,
187
+ },
188
+ view
189
+ );
190
+ dispatch({ type: "VIEW_END_ACTION" });
191
+ },
192
+
193
+ doUpdateView: (e) => ({ dispatch, store }) => {
194
+ const map = e.map;
195
+ const view = map.getView();
196
+ const zoom = view.getZoom();
197
+ const center = transform(
198
+ view.getCenter(),
199
+ store.selectMapProjection(),
200
+ "EPSG:4326"
201
+ );
202
+ const rotation = view.getRotation() * (180 / Math.PI);
203
+ dispatch({ type: "VIEW_CHANGED", payload: { center, zoom, rotation } });
204
+ },
205
+
206
+ doSetView: (options) => ({ dispatch, store }) => {
207
+ const view = store.selectView();
208
+ if (!view) return null;
209
+ animateView(
210
+ {
211
+ center: transform(
212
+ options.center,
213
+ "EPSG:4326",
214
+ store.selectMapProjection()
215
+ ),
216
+ zoom: options.zoom,
217
+ rotation: options.rotation,
218
+ },
219
+ view
220
+ );
221
+ },
222
+
223
+ doListenToMap: () => ({ dispatch, store }) => {
224
+ const map = store.selectMap();
225
+ // now handled in the map bundle, need to dedupe these
226
+ //map.on('moveend', _.throttle(store.doUpdateView, 200));
227
+ dispatch({ type: "VIEW_EVENTS_REGISTERED" });
228
+ },
229
+
230
+ selectViewState: (state) => {
231
+ return state.view;
232
+ },
233
+
234
+ selectViewAction: (state) => {
235
+ return state.view.action;
236
+ },
237
+
238
+ selectViewCenter: createSelector(
239
+ "selectAppTime",
240
+ "selectMap",
241
+ "selectViewState",
242
+ (_, map, viewState) => {
243
+ if (!map) return viewState.center;
244
+ const view = map.getView();
245
+ if (!view) return viewState.center;
246
+ return view.getCenter();
247
+ }
248
+ ),
249
+
250
+ selectMapSize: createSelector(
251
+ "selectMap",
252
+ "selectAppTime",
253
+ (map, appTime) => {
254
+ if (!map) return null;
255
+ return map.getSize();
256
+ }
257
+ ),
258
+
259
+ selectMapImageDisplay: createSelector("selectMapSize", (size) => {
260
+ if (!size) return null;
261
+ return [size[0], size[1], 92];
262
+ }),
263
+
264
+ selectMapExtent: createSelector(
265
+ "selectAppTime",
266
+ "selectView",
267
+ "selectMapSize",
268
+ "selectMapProjection",
269
+ (_, view, size, mapProjection) => {
270
+ if (!view) return null;
271
+ const mapExtentWm = view.calculateExtent(size);
272
+ const ll = transform(
273
+ [mapExtentWm[0], mapExtentWm[1]],
274
+ mapProjection,
275
+ "EPSG:4326"
276
+ );
277
+ const ur = transform(
278
+ [mapExtentWm[2], mapExtentWm[3]],
279
+ mapProjection,
280
+ "EPSG:4326"
281
+ );
282
+ return [ll[0], ll[1], ur[0], ur[1]];
283
+ }
284
+ ),
285
+
286
+ selectResolution: createSelector(
287
+ "selectView",
288
+ "selectAppTime",
289
+ (view, appTime) => {
290
+ if (!view) return null;
291
+ return view.getResolution();
292
+ }
293
+ ),
294
+
295
+ reactAddListeners: (state) => {
296
+ if (!state.view.listening && state.map.map2d)
297
+ return { actionCreator: "doListenToMap" };
298
+ },
299
+
300
+ reactViewShouldReadUrlParams: (state) => {
301
+ if (state.view.shouldReadUrlParams)
302
+ return { actionCreator: "doViewSetFromParams" };
303
+ },
304
+
305
+ reactViewShouldSetDefaults: (state) => {
306
+ if (state.view.shouldSetDefaults)
307
+ return {
308
+ actionCreator: "doViewSetDefaults",
309
+ args: [state.config.default.map],
310
+ };
311
+ },
312
+ };
@@ -4,16 +4,17 @@ import { connect } from 'redux-bundler-react';
4
4
  class Map extends React.Component {
5
5
 
6
6
  componentDidMount(){
7
- const { doMapInitialize, viewState } = this.props;
7
+ const { doMapInitialize, viewState, limitMapExtent } = this.props;
8
8
  const { center, zoom, rotation, minZoom, maxZoom } = viewState;
9
- console.log(center)
9
+
10
10
  doMapInitialize(this.mapEl, {
11
11
  center: center,
12
12
  zoom: zoom,
13
13
  rotation: rotation,
14
14
  minZoom: minZoom,
15
15
  maxZoom: maxZoom,
16
- layers:[]
16
+ layers:[],
17
+ limitMapExtent: limitMapExtent
17
18
  });
18
19
  // doAddMapDragDropListeners(this.mapEl);
19
20
  }
@@ -35,6 +36,7 @@ class Map extends React.Component {
35
36
 
36
37
  export default connect(
37
38
  'doMapInitialize',
39
+ 'selectLimitMapExtent',
38
40
  'selectViewState',
39
41
  'selectCursorClass',
40
42
  'selectComponentsLeftSidebarCount',