From caa2e09edb9c1db0af571013d006179bdc84f755 Mon Sep 17 00:00:00 2001
From: Eric <ericmabr@gmail.com>
Date: Mon, 31 Jul 2023 12:58:06 -0400
Subject: All mapType stuff and constructor is done

---
 src/client/views/nodes/MapBox/MapBox.tsx | 70 ++++++++++++++++++++++++--------
 1 file changed, 53 insertions(+), 17 deletions(-)

(limited to 'src/client/views/nodes/MapBox/MapBox.tsx')

diff --git a/src/client/views/nodes/MapBox/MapBox.tsx b/src/client/views/nodes/MapBox/MapBox.tsx
index 3c8e6203a..ad534f5f2 100644
--- a/src/client/views/nodes/MapBox/MapBox.tsx
+++ b/src/client/views/nodes/MapBox/MapBox.tsx
@@ -132,15 +132,21 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps
     private _disposer: {[key:string]:IReactionDisposer} = {}
     componentDidMount() {
         this.props.setContentView?.(this);
-        this._disposer.location = reaction(() => ({lat:this.rootDoc.latitude, lng:this.rootDoc.longitude}), 
+        this._disposer.location = reaction(() => ({lat:this.rootDoc.latitude, lng:this.rootDoc.longitude, zoom:this.rootDoc.zoom,mapType:this.rootDoc.mapType}), 
         (locationObject) => {
 
-            //TODO: SAVE ZOOM? VIEW STYLE?
             this._bingMap.current.setView({
+                mapTypeId: locationObject.mapType,
+                zoom:locationObject.zoom,
                 center: new this.MicrosoftMaps.Location(locationObject.lat, locationObject.lng),
             });
+            // this._bingMap.current.setZoom(locationObject.zoom);
+
+
 
         }, {fireImmediately: true});
+
+        
     }
 
     componentWillUnmount(): void {
@@ -678,7 +684,18 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps
     updateLayout = () => {
             this.dataDoc.latitude = this._bingMap.current.getCenter().latitude;
             this.dataDoc.longitude = this._bingMap.current.getCenter().longitude;
+            this.dataDoc.zoom = this._bingMap.current.getZoom();
+            // this.dataDoc.mapType = new this.MicrosoftMaps.MapTypeId();
     };
+    /*
+     * Updates maptype
+     */
+    @action
+    updateMapType = () => {
+            this.dataDoc.mapType = this._bingMap.current.getMapTypeId();
+
+    };
+
 
     searched_pin: any;
     /*
@@ -691,13 +708,18 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps
         const location = await this.bingGeocode(this._bingMap, this.bingSearchBarContents);
         this.dataDoc.latitude = location.latitude;
         this.dataDoc.longitude = location.longitude;
+        this.dataDoc.zoom = this._bingMap.current.getZoom();
+        // this.dataDoc.mapType = this._bingMap.current.getMapTypeId();
+        // this.bingSearchBarContents=location.name;
+
         // Centers on the searched location
-        this._bingMap.current.setView({
-            center: new this.MicrosoftMaps.Location(this.dataDoc.latitude, this.dataDoc.longitude),
-        });
-        this.MicrosoftMaps.Events.addHandler(this._bingMap.current, 'click', this.mapOnClick);
-        this.MicrosoftMaps.Events.addHandler(this._bingMap.current, 'viewchangeend', this.updateLayout);
+        this._bingMap.current.panTo(new this.MicrosoftMaps.Location(this.dataDoc.latitude, this.dataDoc.longitude));
 
+        // this._bingMap.current.setView({
+        //     center: new this.MicrosoftMaps.Location(this.dataDoc.latitude, this.dataDoc.longitude),
+        // });
+        
+        
 
         
         // Creates a temporary pin but does not add it to the dataDoc
@@ -714,12 +736,12 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps
     /**
      * Adds all pushpins in dataDoc onto the map (render) - OLD & UNUSED
      */
-    @action
-    addAllPins = () => {
-        this._bingMap.current.entities.clear();
-        if (this.searched_pin) this._bingMap.current.entities.push(this.searched_pin);
-        // this.allMapPushpins.map(pin => this.addPushpin(pin));
-    };
+    // @action
+    // addAllPins = () => {
+    //     this._bingMap.current.entities.clear();
+    //     if (this.searched_pin) this._bingMap.current.entities.push(this.searched_pin);
+    //     // this.allMapPushpins.map(pin => this.addPushpin(pin));
+    // };
 
     /*
      * Returns doc w/ relevant info
@@ -730,7 +752,9 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps
                 title: 'MapAnchor:' + this.rootDoc.title,
                 presLat: NumCast(this.dataDoc.latitude),
                 presLong: NumCast(this.dataDoc.longitude),
-                // presTransition: 1000,
+                presZoom: NumCast(this.dataDoc.zoom),
+                presMapType: this.dataDoc.mapType,
+                // presType: 
                 unrendered: true,
                 annotationOn: this.rootDoc,
             });
@@ -764,8 +788,8 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps
     */
     @action
     removePushpin = (pin:any)=>{
-        this._bingMap.current.entities.clear();
-        this.allMapPushpins
+        // this._bingMap.current.entities.clear();
+        // this.allMapPushpins
         this.allMapPushpins.map(pin => this.addPushpin(pin));
     }
 
@@ -798,7 +822,19 @@ export class MapBox extends ViewBoxAnnotatableComponent<ViewBoxAnnotatableProps
         else this.placePinOn = true;
     };
 
-    bingMapReady = (map: any) => (this._bingMap = map.map);
+    /*
+     * Called when BingMap is first rendered 
+     * Initializes starting values
+     */
+    bingMapReady = (map: any) => {
+        this._bingMap = map.map;
+        this.MicrosoftMaps.Events.addHandler(this._bingMap.current, 'click', this.mapOnClick);
+        this.MicrosoftMaps.Events.addHandler(this._bingMap.current, 'viewchangeend', this.updateLayout);
+        this.MicrosoftMaps.Events.addHandler(this._bingMap.current, 'maptypechanged', this.updateMapType);
+        this.updateLayout();
+        this.updateMapType();
+    }
+        
     render() {
         const renderAnnotations = (docFilters?: () => string[]) => null;
         return (
-- 
cgit v1.2.3-70-g09d2

