首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将组件添加到ngx-leaflet标记弹出窗口

将组件添加到ngx-leaflet标记弹出窗口
EN

Stack Overflow用户
提问于 2018-08-03 19:11:55
回答 1查看 941关注 0票数 2

如何将自定义组件绑定到ngx-leaflet弹出窗口?例如,我想要在弹出窗口中呈现一个自定义元素<my-card></my-card>,当我单击它时,我的组件将被呈现,而不是来自leaflet的标准弹出窗口。

EN

回答 1

Stack Overflow用户

发布于 2020-05-18 00:41:17

我建议您安装最新版本的ngx-leaflet和ngx-leaflet draw。我正试着专注于代码。看看这个,我想它会对你有帮助

代码语言:javascript
复制
// First install all dependencies
npm install leaflet
npm install leaflet-draw
npm install @asymmetrik/ngx-leaflet
npm install @asymmetrik/ngx-leaflet-draw

npm install --save-dev @types/leaflet
npm install --save-dev @types/leaflet-draw

代码语言:javascript
复制
import { NgZone } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MaterialDialogComponent } from './m-dialog.component';
import * as L from 'leaflet';
...
...
export class NgxLeafletComponent {
  dialogRef: MatDialogRef<MaterialDialogComponent>;

  public constructor(private zone: NgZone) {}

  public onMapReady(map: L.Map) {
      map.on(L.Draw.Event.CREATED, (e) => {
        const type = (e as any).layerType,
          layer = (e as any).layer;

        if (type === 'marker') {
          const markerCoordinates = layer._latlng;
          layer.on('click', () => {
            console.log(markerCoordinates); 
            this.zone.run(() => this.onClickMarker()); //error
          });
        }
      });
    }

  onClickMarker() {
    this.dialogRef = this.dialog.open(MaterialDialogComponent);
  }
 }

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

https://stackoverflow.com/questions/51671335

复制
相关文章

相似问题

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