Explorar el Código

Fixed bad load map

Jorge Baquero hace 7 años
padre
commit
254330d1da
Se han modificado 1 ficheros con 14 adiciones y 9 borrados
  1. 14 9
      src/pages/main/main.ts

+ 14 - 9
src/pages/main/main.ts Ver fichero

@@ -50,15 +50,21 @@ export class Main {
50 50
 
51 51
   ionViewWillEnter() {
52 52
     if(typeof this.shareService.getRootDevice() == "undefined") {
53
+      console.log('ionViewWillEnter: Entro al undefined');
53 54
       this.storage.get('rootDevice').then((valDevice)=>{
54 55
         if(valDevice == null) {
56
+          alert(valDevice);
57
+          console.log('ionViewWillEnter: Entro al valDevice == null ' + valDevice);
55 58
           this.navCtrl.push(DevicesPage);
56 59
         } else {
60
+          console.log('ionViewWillEnter: Entro al else del valDevice es ' + valDevice);
57 61
           let auth = this.shareService.getAuthToken();
58 62
           this.vespotService.getDeviceById(auth, valDevice)
59 63
         	.subscribe(
60 64
               (data) => { // Success
61 65
                 this.rootDevice = data[0];
66
+                this.shareService.setRootDevice(this.rootDevice);
67
+                this.getRootDevicePosition();
62 68
               },
63 69
               (error) =>{
64 70
       			       console.log('ionViewWillEnter: ' + error);
@@ -68,7 +74,9 @@ export class Main {
68 74
       });
69 75
 
70 76
     } else {
77
+      console.log('ionViewWillEnter: Entro al getRootDevice');
71 78
       this.getRootDevicePosition();
79
+      //this.loadMap();
72 80
     }
73 81
   }
74 82
 
@@ -175,26 +183,23 @@ export class Main {
175 183
   }
176 184
 
177 185
   updateMarker() {
178
-    this.map.clear().then(() => {
179 186
       let auth = this.shareService.getAuthToken();
180 187
       this.vespotService.getPositionByDeviceId(auth, this.shareService.getRootDevice().id)
181 188
     	.subscribe(
182 189
           (data) => { // Success
183 190
             if(data[0].serverTime != this.rootPosition.serverTime) {
184
-            this.rootPosition = data[0];
185
-            this.getPosition();
191
+              this.map.clear().then(() => {
192
+                this.rootPosition = data[0];
193
+                this.getPosition();
194
+              }).catch(error =>{
195
+                console.log('loadMap: ' + error);
196
+              });
186 197
             }
187 198
           },
188 199
           (error) =>{
189 200
   			       console.log('updateMarker: ' + error);
190 201
           }
191 202
         );
192
-    })
193
-    .catch(error =>{
194
-      console.log('loadMap: ' + error);
195
-    });
196
-
197
-
198 203
   }
199 204
 
200 205
 }