首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误TypeError:无法读取ngx传单和esri-传单-地编码器上未定义的属性“topleft”

错误TypeError:无法读取ngx传单和esri-传单-地编码器上未定义的属性“topleft”
EN

Stack Overflow用户
提问于 2020-05-05 08:37:15
回答 1查看 463关注 0票数 0

我正在使用@asymmetrik/ngx-leaflet@asymmetrik/ngx-leaflet-draw作为传单地图在我的角度9项目。我尝试了一个添加搜索选项在地图上‘esri-传单-地理编码器’。在没有使用@asymmetrik/ngx-leaflet@asymmetrik/ngx-leaflet-draw的情况下,我成功地将搜索选项放置在地图中,没有错误。效果很好。这是我的工作代码:

代码语言:javascript
复制
/*npm install esri-leaflet esri-leaflet-geocoder*/
import * as L from 'leaflet';
import * as esriGeo from 'esri-leaflet-geocoder';

export class MapComponent implements OnInit {
  public searchControl = new esriGeo.Geosearch();
  
  ngOnInit() {
    this.initMap();        // not all codes are here;
    this.tiles.addTo(L.map);   // not all codes are here;
    
    this.searchControl.addTo(L.map);
  }
}

输出图像:

但是当我尝试实现@asymmetrik/ngx-leaflet@asymmetrik/ngx-leaflet-draw之前所做的相同的代码时,它说的是一些错误:ERROR TypeError: Cannot read property 'topleft' of undefined错误输出图像:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-08 04:31:05

我刚解决了问题。虽然我使用的是ngx-leaflet,所以在这里,L.Map不是映射的当前实例。ngx-leafletLeafletDirective初始化映射。因此,工作代码是:

代码语言:javascript
复制
/*npm install esri-leaflet esri-leaflet-geocoder*/
import * as L from 'leaflet';
import * as esriGeo from 'esri-leaflet-geocoder';
import { LeafletDirective } from '@asymmetrik/ngx-leaflet'; //new import

export class MapComponent implements OnInit {
  public searchControl = new esriGeo.Geosearch();
  
  ngOnInit() {
    const map = this.leafletDirective.getMap(); // initialize map
    
    this.searchControl.addTo(map);
  }
}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61609050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档