通过angular2中的下拉菜单刷新Leftlet贴图
我对Angular2和传单地图不熟悉。我正在尝试创建一个下拉列表,该值的更改将刷新地图到一个新的。例如,如果下拉值为伦敦,它将显示伦敦的地图位置,如果我将下拉值更改为纽约,地图将重新定位为纽约 side-nav.component.ts->这里是我的下拉代码通过angular2中的下拉菜单刷新Leftlet贴图,angular,leaflet,angular-leaflet-directive,Angular,Leaflet,Angular Leaflet Directive,我对Angular2和传单地图不熟悉。我正在尝试创建一个下拉列表,该值的更改将刷新地图到一个新的。例如,如果下拉值为伦敦,它将显示伦敦的地图位置,如果我将下拉值更改为纽约,地图将重新定位为纽约 side-nav.component.ts->这里是我的下拉代码 <select class="form-control" [(ngModel)]="selectedGeo" > <option value="" nonselected class="nonvalue"
<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>
侧向导航组件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);
}
}
您可以非常简单地请求当前地图更改其视图,而不是更改地图容器,通常使用,甚至 如果您只是切换地图容器,并且用户已经在新地图周围移动/平移,他/她将只看到新地图移动到的最后一个位置,而不是初始位置 您需要将目标坐标记录到select中,或者至少从一些集中变量(可能是您的地理区域)中检索它们
下面是一个使用flyTo plain JS的示例:欢迎使用SO!处理选择值更改的代码在哪里?感谢您的回复。从side-nav.component.ts中的map.component.ts获取map变量还有一个问题。这就是为什么不能使用此设置的原因。