【发布时间】:2021-01-25 16:22:41
【问题描述】:
我正在将标准 Angular 项目转换为 Angular Universal 项目,因此我必须摆脱“$window”。该项目没有使用任何模块,但使用的一些模块,如传单,正在使用它,所以我切换到 ngx-leaflet。
组件只访问@types\leaflet 对象来生成配置,地图生成留给带有ngx-leaflet 指令的html:leaflet。 html如下:
<div class="row w75 justify-content-center mb-5">
<div class="content-wrapper col-lg-9 col-sm11" >
<h3 class="center-title text-uppercase">Country locations</h3>
<div class="title-block2"></div>
<div id="map" leaflet [leafletOptions]="options" style="min-height: 700px">
</div>
</div>
</div>
<div class="row justify-content-center mt-3 mb-5">
<div class="content-wrapper col-12" >
<h3 class="center-title text-uppercase">Woldwide locations</h3>
<div class="title-block2"></div>
<div id="map2" leaflet [leafletOptions]="options2" style="min-height: 700px">
</div>
</div>
</div>
结果是确实出现了 2 个地图,每个地图都有其标记和功能弹出窗口,但只有第一个地图显示实际的地图图块,并且实际上显示了 2 个地图的所有图块,所以第二个地图只是gey backfgound。
在使用 ngx-leaflet 时我缺少什么吗? 例如: [containerId]="'map'" ?
控制器如下:
import {Component, OnInit} from '@angular/core';
import {icon, popup, marker, latLng, tileLayer, layerGroup, polyline,
Polyline, LayerGroup, LatLng, TileLayer} from 'leaflet';
@Component({
selector: 'app-map',
templateUrl: './coverage.component.html',
styleUrls: ['./coverage.component.scss']
})
export class CoverageComponent implements OnInit {
title = 'leafletApps';
popup = popup();
width = window.innerWidth;
polylinePoints: LatLng[] = [];
polyline: Polyline;
assetLayerGroup: LayerGroup = layerGroup();
assetLayerGroup2: LayerGroup = layerGroup();
myTitleLayer: TileLayer = tileLayer('https://tiles.stadiamaps.com/tiles/osm_bright/{z}/{x}/{y}{r}.png',
{ attribution: '© Angular LeafLet' });
options: {layers: any[], zoom: number, center: LatLng , dragging: boolean,
scrollWheelZoom: boolean } =
{
layers: [this.myTitleLayer, this.assetLayerGroup],
zoom: 6,
dragging: (this.width > 992),
scrollWheelZoom: false,
center: latLng(4.7110, -74.0721)
};
options2: {layers: any[], zoom: number, center: LatLng ,
dragging: boolean, scrollWheelZoom: boolean } =
{
layers: [this.myTitleLayer, this.assetLayerGroup2],
zoom: 3,
dragging: (this.width > 992),
scrollWheelZoom: false,
center: latLng(20, 0)
};
constructor() {}
ngOnInit() {
this.assetLayerGroup = this.fillMap1();
this.options.layers.push(this.myTitleLayer);
this.options.layers.push(this.assetLayerGroup);
this.assetLayerGroup2= this.fillMap2();
this.options2.layers.push(this.myTitleLayer);
this.options2.layers.push(this.assetLayerGroup2);
}
}
知道错误在哪里吗?
【问题讨论】:
标签: angular ngx-leaflet