【问题标题】:Add component to ngx-leaflet marker popup将组件添加到 ngx-leaflet 标记弹出窗口
【发布时间】:2019-01-11 06:30:16
【问题描述】:

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

【问题讨论】:

标签: angular leaflet angular-leaflet-directive


【解决方案1】:

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

// 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

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);
  }
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-19
    • 1970-01-01
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 2019-09-26
    相关资源
    最近更新 更多