私が作成しているアプリでは、ポイントのグループを、ネストされたマップのクリック イベントで参照される featureGroup に動的に追加します。つまり、要点は、さまざまな地域が表示された国の地図を持っているということです。地域をクリックすると、地図の境界がその多角形に適合し、その多角形に関連付けられたポイント (都市など) が表示されます。単一のポイント/都市をクリックすると、さらに掘り下げられ、選択した都市内のすべての図書館など、最初にクリックしたポイントに関連付けられた別のポイント グループが表示されます。
問題は、ポイント (ライブラリ) の最終グループが featureGroup にあると (これは、クリック イベントのネストされた性質のために必要です)、グループで fitBounds/getBounds を使用できないことです。以下は最小限の例です (ngx-leaflet-tutorial-ngcli チュートリアルに基づく):
app.component.html
<div class="map"
leaflet
(leafletMapReady)="onMapReady($event)"
[leafletOptions]="options"></div>
app.component.ts
import { Component, OnInit } from '@angular/core';
import * as L from 'leaflet';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
googleMaps = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}', {
maxZoom: 20,
subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
detectRetina: true
});
summit = L.marker([ 46.8523, -121.7603 ], {
icon: L.icon({
iconSize: [ 25, 41 ],
iconAnchor: [ 13, 41 ],
iconUrl: 'leaflet/marker-icon.png',
shadowUrl: 'leaflet/marker-shadow.png'
})
});
paradise = L.marker([ 46.78465227596462,-121.74141269177198 ], {
icon: L.icon({
iconSize: [ 25, 41 ],
iconAnchor: [ 13, 41 ],
iconUrl: 'leaflet/marker-icon.png',
shadowUrl: 'leaflet/marker-shadow.png'
})
});
fGroup = L.featureGroup();
options = {
layers: [ this.googleMaps, this.fGroup ],
zoom: 7,
center: L.latLng([ 46.879966, -121.726909 ])
};
onMapReady(map: L.Map) {
this.paradise.addTo(this.fGroup);
this.summit.addTo(this.fGroup);
console.log(this.fGroup);
}
ngOnInit(){
}
}
私console.log
はfeatureGroupの出力を示していました:
NewClass {options: {…}, _layers: {…}, _initHooksCalled: true, _leaflet_id: 183, _mapToAdd: NewClass, …}
options: {}
_initHooksCalled: true
_layers: {184: NewClass, 186: NewClass}
_leaflet_id: 183
_map: NewClass {options: {…}, _container: div.map.leaflet-container.leaflet-touch.leaflet-retina.leaflet-fade-anim.leaflet-grab.leaflet-touch-…, _leaflet_id: 2, _containerId: 3, _fadeAnimated: true, …}
_mapToAdd: NewClass {options: {…}, _container: div.map.leaflet-container.leaflet-touch.leaflet-retina.leaflet-fade-anim.leaflet-grab.leaflet-touch-…, _leaflet_id: 2, _containerId: 3, _fadeAnimated: true, …}
_zoomAnimated: true
__proto__: NewClass
ご覧のとおり、_bounds
利用可能な方法はありません。ngx-leaflet の featureGroup に Bounds を適合させる方法はありますか?