我是Angular2和Leaflet Map的新手。我正在尝试创建一个下拉菜单,该更改会将地图更新为新的地图。例如,如果下拉值是伦敦,它将显示伦敦的地图位置,如果我将下拉值更改为纽约,地图将重新定位到纽约。刷新Leftlet地图的下拉角度2
侧nav.component.ts - >我在这里的下拉代码是有
<select class="form-control" [(ngModel)]="selectedGeo" >
<option value="" nonselected class="nonvalue">--Select--</option>
<option *ngFor="let geoArea of geoAreas" value="{{geoArea.value}}">
{{geoArea.value}}
</option>
</select>
侧nav.component.ts - >
geoAreas: Array<Object> =[] = [
{"id":"1","value":"New York"},
{"id":"2","value":"London"},
{"id":"3","value":"India"}
]。
map.component.html
<div class="col-8">
<div class="card">
<div id="londonMap" style="height: 500px"></div>
</div>
map.component.ts
import { Component, OnInit } from '@angular/core';
import * as L from "leaflet";
import { Map } from "leaflet";
@Component({
selector: 'app-map',
templateUrl: './map.component.html',
styleUrls: ['./map.component.css']
})
export class MapComponent implements OnInit {
public map: Map;
constructor() { }
ngOnInit() {
this.londonMap = L.map("londonMap", {
zoomControl: false,
center: L.latLng(51.505, -0.09),
zoom: 12,
minZoom: 4,
maxZoom: 19
});
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(this.londonMap);
this.NYMap = L.map("NYMap", {
zoomControl: false,
center: L.latLng(42.736424, -75.762713),
zoom: 7,
minZoom: 4,
maxZoom: 19
});
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(NYMap);
}
}
欢迎SO!您的代码在哪里处理选择值更改? – ghybs