@lgv/visualization-map 0.0.2 → 0.0.4

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": "@lgv/visualization-map",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "description": "ES6 d3.js core visualization scaffold object and utilities for maps.",
6
6
  "main": "src/index.js",
@@ -12,7 +12,7 @@
12
12
  "build": "webpack build --config webpack.prod.js",
13
13
  "coverage": "c8 --reporter=html --reporter=text ava --node-arguments='--experimental-json-modules'",
14
14
  "start": "webpack serve --config webpack.dev.js",
15
- "startdocker": "webpack serve --config webpack.dev.js --host 0.0.0.0 --public 0.0.0.0",
15
+ "startdocker": "webpack serve --config webpack.dev.js --host 0.0.0.0 --allowed-hosts all",
16
16
  "test": "npx ava --verbose --serial --timeout 1m --node-arguments='--experimental-json-modules'"
17
17
  },
18
18
  "repository": {
@@ -36,13 +36,14 @@
36
36
  "css-loader": "^6.7.2",
37
37
  "html-webpack-plugin": "^5.3.2",
38
38
  "style-loader": "^3.3.1",
39
- "webpack-cli": "^4.7.2",
40
- "webpack-dev-server": "^3.11.2"
39
+ "webpack": "^5.86.0",
40
+ "webpack-cli": "^5.1.4",
41
+ "webpack-dev-server": "^4.15.1"
41
42
  },
42
43
  "dependencies": {
43
44
  "@deck.gl/core": "^8.8.20",
44
45
  "@deck.gl/layers": "^8.8.20",
45
- "@lgv/visualization-chart": "^0.3.6",
46
+ "@lgv/visualization-chart": "^0.3.21",
46
47
  "@msrvida/vega-deck.gl": "^3.3.4",
47
48
  "leaflet": "^1.9.2",
48
49
  "vega": "^5.22.1"
@@ -6,7 +6,8 @@ const configuration = {
6
6
  };
7
7
 
8
8
  const configurationColor = {
9
- p1: ["#F7BBB5", "#F37765", "#EF4223", "#992B20", "#37150E"]
9
+ p1: ["#0a86ca", "#0a86ca"],
10
+ p2: ["#F7BBB5", "#F37765", "#EF4223", "#992B20", "#37150E"]
10
11
  };
11
12
 
12
13
  const configurationLayout = {
@@ -64,7 +64,7 @@ class Heatmap extends VisualizationMap {
64
64
  mark = base - 5;
65
65
  break;
66
66
  }
67
- console.log(mark)
67
+
68
68
  return mark;
69
69
 
70
70
  }
@@ -22,14 +22,12 @@ class VisualizationMap extends LinearGrid {
22
22
  super(data, width, height, MapData, label, name);
23
23
 
24
24
  // determine type of data object
25
- this.isFeatureCollection = this.data.features;
26
- this.isPoint = this.data.coordinates && this.data.type.lower() == "point";
27
- this.isXY = this.data.metadata && this.data.results;
25
+ this.determineDataType();
28
26
 
29
27
  // determine x/y center
30
- let x = this.isFeatureCollection ? mean(this.data.features, d => d.geometry.coordinates[1]) : (this.isPoint ? this.data.coordinates[1] : mean([this.data.metadata.bounds[0][1],this.data.metadata.bounds[1][1]]));
28
+ let x = this.isFeatureCollection ? mean(this.data.features, d => d.geometry.coordinates[1]) : (this.isPoint ? this.data.coordinates[1] : (this.isXY ? mean([this.data.metadata.bounds[0][1],this.data.metadata.bounds[1][1]]) : 0));
31
29
 
32
- let y = this.isFeatureCollection ? mean(this.data.features, d => d.geometry.coordinates[0]) : (this.isPoint ? this.data.coordinates[0] : mean([this.data.metadata.bounds[0][0],this.data.metadata.bounds[1][0]]));
30
+ let y = this.isFeatureCollection ? mean(this.data.features, d => d.geometry.coordinates[0]) : (this.isPoint ? this.data.coordinates[0] : (this.isXY ? mean([this.data.metadata.bounds[0][0],this.data.metadata.bounds[1][0]]) : 0));
33
31
 
34
32
  // update self
35
33
  this.center = [x,y];
@@ -53,14 +51,49 @@ class VisualizationMap extends LinearGrid {
53
51
  // process data
54
52
  // update data object now that map exists
55
53
  this.Data.map = this.map;
56
- this.data = this.Data.update;
54
+ if (this.Data.data) this.data = this.Data.update;
57
55
 
58
56
  // render overlay
59
57
  this.generateChart();
60
58
 
59
+ // broadcast event
60
+ this.container.dispatch("map-change", {
61
+ bubbles: true
62
+ });
63
+
61
64
  });
62
65
  }
63
66
 
67
+ /**
68
+ * Generate main visualization, i.e. everything that sits inside the svg.
69
+ */
70
+ determineDataType() {
71
+ this.isFeatureCollection = this.data && this.Data.source.features;
72
+ this.isPoint = this.data && this.data.coordinates && this.data.type.lower() == "point";
73
+ this.isXY = this.data && this.data.metadata && this.data.results;
74
+ }
75
+
76
+ /**
77
+ * Fit map tightly to data boundary.
78
+ */
79
+ fitToData() {
80
+
81
+ // determine bounding box
82
+ let bounds = (this.isFeatureCollection || this.isPoint) ? L.geoJSON(this.Data.source).getBounds() : (this.isXY ? this.data.metadata.bounds : this.map.getBounds());
83
+
84
+ // fit to bounds
85
+ if (this.isFeatureCollection || this.isXY) {
86
+ // several data points
87
+ this.map.fitBounds(bounds);
88
+ } else if (this.isPoint) {
89
+ // zoom out if only provided single data point
90
+ this.map.setView(bounds.getCenter(), this.map.getMaxZoom() / 2);
91
+ } else {
92
+ // no geo data provided so center world
93
+ this.map.setView(bounds.getCenter());
94
+ }
95
+ }
96
+
64
97
  /**
65
98
  * Generate main visualization, i.e. everything that sits inside the svg.
66
99
  */
@@ -112,17 +145,8 @@ class VisualizationMap extends LinearGrid {
112
145
  // update tile server
113
146
  L.tileLayer(this.tileserver).addTo(this.map);
114
147
 
115
- // determine bounding box
116
- let bounds = (this.isFeatureCollection || this.isPoint) ? L.geoJSON(this.Data.source).getBounds() : this.data.metadata.bounds;
117
-
118
148
  // fit to bounds
119
- if (this.isFeatureCollection || this.isXY) {
120
- // several data points
121
- this.map.fitBounds(bounds);
122
- } else {
123
- // zoom out if only provided single data point
124
- this.map.setView(bounds.getCenter(), this.map.getMaxZoom() / 2);
125
- }
149
+ this.fitToData();
126
150
 
127
151
  }
128
152
 
@@ -165,9 +189,15 @@ class VisualizationMap extends LinearGrid {
165
189
  this.Data.data = this.Data.update;
166
190
  this.data = this.Data.data;
167
191
 
192
+ // determine type of data object
193
+ this.determineDataType();
194
+
168
195
  // generate visualization
169
196
  this.generateChart();
170
197
 
198
+ // fit to bounds
199
+ this.fitToData();
200
+
171
201
  }
172
202
 
173
203
  }