传单.locate手表选项中断。更改标签Ionic 3后找到 [英] Leaflet .locate watch option breaks .locate after changing tab Ionic 3

查看:159
本文介绍了传单.locate手表选项中断。更改标签Ionic 3后找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  ionViewDidEnter()将一个函数loadmap(){} {
this.loadmap();


$ b $ / code>

里面的loadmap我有

  this.map = leaflet.map(map)。fitWorld(); 

多数民众赞成我如何初始化地图





  ionViewDidLeave(){

this.map。去掉();





$ p

这是我的.locate函数:

  var usermarker; 


this.map.locate({
setView:true,
maxZoom:120,
watch:true,
enableHighAccuracy:true (locationfound,e => {
if(!usermarker){
usermarker = new L.marker(








} (e.latlng).addTo(this.map);
} else {
usermarker.setLatLng(e.latlng);
}
})。on(locationerror ,error => {
if(usermarker){
this.map.removeLayer(usermarker);
usermarker = undefined;
}
});

问题出在第一时间.locate function works.but if i change tab and go back to map



谢谢

解决方案

你必须调用 map.stopLocate() 除了 map.remove()


停止观看由 map.locate({watch:true})启动的位置


现场演示: https://plnkr.co/edit/PKMPjfX3zD3QdWmEI0iX?p=preview (使用切换贴图按钮来模拟您更改的标签页)

这就是说,Leaflet可以在使用< a href =http://leafletjs.com/reference.html#map-remove =nofollow nore ferrer> remove 映射方法。 =>合并于宣传单张/宣传单张#5893


I have one function called loadmap(){} where im creating map.Im loading this function with

 ionViewDidEnter() {
this.loadmap();


  }

Inside loadmap i have

  this.map = leaflet.map("map").fitWorld();

thats how i initialize map

This is how i remove map when user changes tab.

ionViewDidLeave(){

    this.map.remove();


  }

This is my .locate function:

var usermarker;


  this.map.locate({
    setView: true,
    maxZoom: 120,
    watch:true,
    enableHighAccuracy:true



  }).on("locationfound", e => {
    if (!usermarker) {
      usermarker = new L.marker(e.latlng).addTo(this.map);
  } else {
      usermarker.setLatLng(e.latlng);
  }
}).on("locationerror", error => {
  if (usermarker) {
      this.map.removeLayer(usermarker);
      usermarker = undefined;
  }
});

The problem is in first time .locate function works.but if i change tab and go back to map tab .locate function doesnt work.if i remove watch option it works.

Thanks

解决方案

You have to call map.stopLocate() besides map.remove():

Stops watching location previously initiated by map.locate({watch: true})

Live demo: https://plnkr.co/edit/PKMPjfX3zD3QdWmEI0iX?p=preview (use the "Toggle map" button to simulate your changing tabs)

That being said, it is true that Leaflet could automatically do this when using the remove map method. => Merged in PR Leaflet/Leaflet#5893

这篇关于传单.locate手表选项中断。更改标签Ionic 3后找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆