@abi-software/flatmap-viewer 2.2.0-beta.3 → 2.2.0-beta.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": "@abi-software/flatmap-viewer",
3
- "version": "2.2.0-beta.3",
3
+ "version": "2.2.0-beta.4",
4
4
  "description": "Flatmap viewer using Maplibre GL",
5
5
  "repository": "https://github.com/ABI-Software/flatmap-viewer.git",
6
6
  "main": "src/main.js",
@@ -22,7 +22,7 @@ limitations under the License.
22
22
 
23
23
  //==============================================================================
24
24
 
25
- import maplibre from 'maplibre-gl';
25
+ import maplibregl from 'maplibre-gl';
26
26
  import 'maplibre-gl/dist/maplibre-gl.css';
27
27
 
28
28
  //==============================================================================
@@ -131,7 +131,7 @@ class FlatMap
131
131
 
132
132
  // Create the map
133
133
 
134
- this._map = new maplibre.Map(mapOptions);
134
+ this._map = new maplibregl.Map(mapOptions);
135
135
 
136
136
  // Show tile boundaries if debugging
137
137
 
@@ -146,7 +146,7 @@ class FlatMap
146
146
  // Do we want a fullscreen control?
147
147
 
148
148
  if (mapDescription.options.fullscreenControl === true) {
149
- this._map.addControl(new maplibre.FullscreenControl(), 'top-right');
149
+ this._map.addControl(new maplibregl.FullscreenControl(), 'top-right');
150
150
  }
151
151
 
152
152
  // Disable map rotation
@@ -176,7 +176,11 @@ class FlatMap
176
176
  this.setupUserInteractions_();
177
177
  } else if (this._initialState === null) {
178
178
  this._bounds = this._map.getBounds();
179
-
179
+ this._map.setMaxBounds(this._bounds);
180
+ const sw = maplibregl.MercatorCoordinate.fromLngLat(this._bounds.toArray()[0]);
181
+ const ne = maplibregl.MercatorCoordinate.fromLngLat(this._bounds.toArray()[1]);
182
+ this.__normalised_origin = [sw.x, ne.y];
183
+ this.__normalised_size = [ne.x - sw.x, sw.y - ne.y];
180
184
  if ('state' in this._options) {
181
185
  this._userInteractions.setState(this._options.state);
182
186
  }
@@ -559,7 +563,7 @@ class FlatMap
559
563
  //==================
560
564
  {
561
565
  if ('bounds' in this._options) {
562
- this._map.fitBounds(this._options['bounds']);
566
+ this._map.fitBounds(this._options['bounds'], {animate: false});
563
567
  }
564
568
  if ('center' in this._options) {
565
569
  this._map.setCenter(this._options['center']);
@@ -822,6 +826,52 @@ class FlatMap
822
826
  });
823
827
  }
824
828
 
829
+ /**
830
+ * Generate a callback as a result of panning/zooming the map.
831
+ *
832
+ * @param {string} type The event type, ``pan`` or ``zoom``.
833
+ * @param {Array.<float>} origin The map's normalised top-left corner
834
+ * @param {Array.<float>} size The map's normalised size
835
+ */
836
+ panZoomEvent(type)
837
+ //================
838
+ {
839
+ const bounds = this._map.getBounds();
840
+ if (this.__normalised_origin !== undefined) {
841
+ const sw = maplibregl.MercatorCoordinate.fromLngLat(bounds.toArray()[0]);
842
+ const ne = maplibregl.MercatorCoordinate.fromLngLat(bounds.toArray()[1]);
843
+ const top_left = [(sw.x - this.__normalised_origin[0])/this.__normalised_size[0],
844
+ (ne.y - this.__normalised_origin[1])/this.__normalised_size[1]];
845
+ const size = [(ne.x - sw.x)/this.__normalised_size[0],
846
+ (sw.y - ne.y)/this.__normalised_size[1]];
847
+ this.callback('pan-zoom', {
848
+ type: type,
849
+ origin: top_left,
850
+ size: size
851
+ });
852
+ }
853
+ }
854
+
855
+ /**
856
+ * Pan/zoom the map to a new view
857
+ *
858
+ * @param {Array.<float>} origin The map's normalised top-left corner
859
+ * @param {Array.<float>} size The map's normalised size
860
+ */
861
+ panZoomTo(origin, size)
862
+ //=====================
863
+ {
864
+ if (this.__normalised_origin !== undefined) {
865
+ const sw_x = origin[0]*this.__normalised_size[0] + this.__normalised_origin[0];
866
+ const ne_y = origin[1]*this.__normalised_size[1] + this.__normalised_origin[1];
867
+ const ne_x = sw_x + size[0]*this.__normalised_size[0];
868
+ const sw_y = ne_y + size[1]*this.__normalised_size[1];
869
+ const sw = (new maplibregl.MercatorCoordinate(sw_x, sw_y, 0)).toLngLat();
870
+ const ne = (new maplibregl.MercatorCoordinate(ne_x, ne_y, 0)).toLngLat();
871
+ this._map.fitBounds([sw, ne], {animate: false});
872
+ }
873
+ }
874
+
825
875
  //==========================================================================
826
876
 
827
877
  search(text)
@@ -224,6 +224,10 @@ export class UserInteractions
224
224
  this._map.on('mousemove', this.mouseMoveEvent_.bind(this));
225
225
  this._lastFeatureMouseEntered = null;
226
226
  this._lastFeatureModelsMouse = null;
227
+
228
+ // Handle pan/zoom events
229
+ this._map.on('move', this.panZoomEvent_.bind(this, 'pan'));
230
+ this._map.on('zoom', this.panZoomEvent_.bind(this, 'zoom'));
227
231
  }
228
232
 
229
233
  getState()
@@ -1103,6 +1107,12 @@ export class UserInteractions
1103
1107
 
1104
1108
  return true;
1105
1109
  }
1110
+
1111
+ panZoomEvent_(type)
1112
+ //=================
1113
+ {
1114
+ this._flatmap.panZoomEvent(type);
1115
+ }
1106
1116
  }
1107
1117
 
1108
1118
  //==============================================================================