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
 
50
 
51
   ionViewWillEnter() {
51
   ionViewWillEnter() {
52
     if(typeof this.shareService.getRootDevice() == "undefined") {
52
     if(typeof this.shareService.getRootDevice() == "undefined") {
53
+      console.log('ionViewWillEnter: Entro al undefined');
53
       this.storage.get('rootDevice').then((valDevice)=>{
54
       this.storage.get('rootDevice').then((valDevice)=>{
54
         if(valDevice == null) {
55
         if(valDevice == null) {
56
+          alert(valDevice);
57
+          console.log('ionViewWillEnter: Entro al valDevice == null ' + valDevice);
55
           this.navCtrl.push(DevicesPage);
58
           this.navCtrl.push(DevicesPage);
56
         } else {
59
         } else {
60
+          console.log('ionViewWillEnter: Entro al else del valDevice es ' + valDevice);
57
           let auth = this.shareService.getAuthToken();
61
           let auth = this.shareService.getAuthToken();
58
           this.vespotService.getDeviceById(auth, valDevice)
62
           this.vespotService.getDeviceById(auth, valDevice)
59
         	.subscribe(
63
         	.subscribe(
60
               (data) => { // Success
64
               (data) => { // Success
61
                 this.rootDevice = data[0];
65
                 this.rootDevice = data[0];
66
+                this.shareService.setRootDevice(this.rootDevice);
67
+                this.getRootDevicePosition();
62
               },
68
               },
63
               (error) =>{
69
               (error) =>{
64
       			       console.log('ionViewWillEnter: ' + error);
70
       			       console.log('ionViewWillEnter: ' + error);
68
       });
74
       });
69
 
75
 
70
     } else {
76
     } else {
77
+      console.log('ionViewWillEnter: Entro al getRootDevice');
71
       this.getRootDevicePosition();
78
       this.getRootDevicePosition();
79
+      //this.loadMap();
72
     }
80
     }
73
   }
81
   }
74
 
82
 
175
   }
183
   }
176
 
184
 
177
   updateMarker() {
185
   updateMarker() {
178
-    this.map.clear().then(() => {
179
       let auth = this.shareService.getAuthToken();
186
       let auth = this.shareService.getAuthToken();
180
       this.vespotService.getPositionByDeviceId(auth, this.shareService.getRootDevice().id)
187
       this.vespotService.getPositionByDeviceId(auth, this.shareService.getRootDevice().id)
181
     	.subscribe(
188
     	.subscribe(
182
           (data) => { // Success
189
           (data) => { // Success
183
             if(data[0].serverTime != this.rootPosition.serverTime) {
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
           (error) =>{
199
           (error) =>{
189
   			       console.log('updateMarker: ' + error);
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
 }