@lgv/visualization-map 0.0.3 → 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 +1 -1
- package/src/visualization/index.js +26 -14
package/package.json
CHANGED
|
@@ -68,11 +68,32 @@ class VisualizationMap extends LinearGrid {
|
|
|
68
68
|
* Generate main visualization, i.e. everything that sits inside the svg.
|
|
69
69
|
*/
|
|
70
70
|
determineDataType() {
|
|
71
|
-
this.isFeatureCollection = this.data && this.
|
|
71
|
+
this.isFeatureCollection = this.data && this.Data.source.features;
|
|
72
72
|
this.isPoint = this.data && this.data.coordinates && this.data.type.lower() == "point";
|
|
73
73
|
this.isXY = this.data && this.data.metadata && this.data.results;
|
|
74
74
|
}
|
|
75
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
|
+
|
|
76
97
|
/**
|
|
77
98
|
* Generate main visualization, i.e. everything that sits inside the svg.
|
|
78
99
|
*/
|
|
@@ -124,20 +145,8 @@ class VisualizationMap extends LinearGrid {
|
|
|
124
145
|
// update tile server
|
|
125
146
|
L.tileLayer(this.tileserver).addTo(this.map);
|
|
126
147
|
|
|
127
|
-
// determine bounding box
|
|
128
|
-
let bounds = (this.isFeatureCollection || this.isPoint) ? L.geoJSON(this.Data.source).getBounds() : (this.isXY ? this.data.metadata.bounds : this.map.getBounds());
|
|
129
|
-
|
|
130
148
|
// fit to bounds
|
|
131
|
-
|
|
132
|
-
// several data points
|
|
133
|
-
this.map.fitBounds(bounds);
|
|
134
|
-
} else if (this.isPoint) {
|
|
135
|
-
// zoom out if only provided single data point
|
|
136
|
-
this.map.setView(bounds.getCenter(), this.map.getMaxZoom() / 2);
|
|
137
|
-
} else {
|
|
138
|
-
// no geo data provided so center world
|
|
139
|
-
this.map.setView(bounds.getCenter());
|
|
140
|
-
}
|
|
149
|
+
this.fitToData();
|
|
141
150
|
|
|
142
151
|
}
|
|
143
152
|
|
|
@@ -186,6 +195,9 @@ class VisualizationMap extends LinearGrid {
|
|
|
186
195
|
// generate visualization
|
|
187
196
|
this.generateChart();
|
|
188
197
|
|
|
198
|
+
// fit to bounds
|
|
199
|
+
this.fitToData();
|
|
200
|
+
|
|
189
201
|
}
|
|
190
202
|
|
|
191
203
|
}
|