将搜索功能实现到OL3映射的最佳方法是什么?
我需要一个搜索输入,它会在搜索时向我显示一些选项,然后平移和缩放到特定的搜索词.非常像谷歌地图.
我需要将谷歌地图集成到我的OL3中吗?
我已经阅读了一些有关此事的帖子以及示例链接
但是我发现很难理解他们在示例中是如何做到的:
var gmap = new google.maps.Map(document.getElementById('gmap'), {
disableDefaultUI: true,
keyboardShortcuts: false,
draggable: false,
disableDoubleClickZoom: true,
scrollwheel: false,
streetViewControl: false
});
var view = new ol.View({
// make sure the view doesn't go beyond the 22 zoom levels of Google Maps
maxZoom: 21
});
view.on('change:center', function() {
var center = ol.proj.transform(view.getCenter(), 'EPSG:3857', 'EPSG:4326');
gmap.setCenter(new google.maps.LatLng(center[1], center[0]));
});
view.on('change:resolution', function() {
gmap.setZoom(view.getZoom());
});
var vector = new ol.layer.Vector({
source: new ol.source.GeoJSON({
url: 'data/geojson/countries.geojson',
projection: 'EPSG:3857'
}),
style: new ol.style.Style({ …Run Code Online (Sandbox Code Playgroud) 我想根据矢量图层要素(点)定位地图的中心和缩放级别.
我有一个填充我的地图的geojson文件:
var vectorSource = new ol.source.Vector({
url: 'assets/js/data.geojson',
format: new ol.format.GeoJSON(),
projection: 'ESPG:3857'
});
Run Code Online (Sandbox Code Playgroud)
我现在尝试获取矢量图层的范围:
vectorSource.once('change', function (e) {
if (vectorSource.getState() === 'ready') {
if (vectorLayer.getSource().getFeatures().length > 0) {
map.getView().fit(vectorSource.getExtent(), map.getSize());
}
}
});
Run Code Online (Sandbox Code Playgroud)
如何根据图层要素获取地图坐标并缩放到特定级别?
map.setCenter("// Center position of lon,lat based on layer features//");
map.setZoom("// Zoom level according to layer features//");
Run Code Online (Sandbox Code Playgroud)