我正在尝试在我的角度应用程序中使用OSM。我在应用程序中包含了OSM,但在我的例子中,我需要Nominatim的功能。当用户输入一个地方时,它应该返回位置的纬度和经度,地图应该聚焦到那个地方。
在Nominatim网站中,输入URL的地名
https://nominatim.openstreetmap.org/search?query=colombo
它返回经度和纬度。
https://nominatim.openstreetmap.org/search?query=colombo#map=12/6.9220/79.8562
如果有人知道如何用角度来做这件事,你的答案将会非常感激。
这是我的.ts文件
import { Component, OnInit } from '@angular/core';
declare var ol: any;
@Component({
selector: 'app-location',
templateUrl: './location.component.html',
styleUrls: ['./location.component.css']
})
export class LocationComponent implements OnInit {
map: any;
constructor() { }
ngOnInit() {
var mousePositionControl = new ol.control.MousePosition({
coordinateFormat: ol.coordinate.createStringXY(4),
projection: 'EPSG:4326',
undefinedHTML: ' '
});
this.map = new ol.Map({
target: 'map',
controls: ol.control.defaults({
attributionOptions: {
collapsible: false
}
}).extend([mousePositionControl]),
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([79.859619140625, 6.930062160235181]),
zoom: 8
})
});
this.map.on('click', function (args) {
var lonlat = ol.proj.transform(args.coordinate, 'EPSG:3857', 'EPSG:4326');
var lon = lonlat[0];
var lat = lonlat[1];
localStorage.setItem('lat', JSON.stringify(lat));
localStorage.setItem('long', JSON.stringify(lon));
});
}
}HTML文件
<input type="text" placeholder="place name" name="place name">
<div id="map" class="map"></div>
<div id="mouse-position"></div>发布于 2019-04-15 11:04:17
这可能对你有帮助- https://developer.mapquest.com/documentation/open/nominatim-search/search/
创建一个角服务,您可以在其中进行命名搜索,并将新的lon设置为map对象。
例如:
setCenter() {
var view = this.map.getView();
view.setCenter(ol.proj.fromLonLat([this.longitude, this.latitude]));
view.setZoom(8);
}https://stackoverflow.com/questions/55687592
复制相似问题