设置地图层级
this.map.getView().setZoom(8);
定位到某一点
const bbox = [
[bounds.minX, bounds.minY],
[bounds.maxX, bounds.maxY]
];
const boundingExtent = ol.extent.boundingExtent(bbox);
const center4326 = ol.extent.getCenter(boundingExtent);
const center3857 = ol.proj.transform(center4326, 'EPSG:4326', 'EPSG:3857');
this.map.getView().setCenter(center3857);
增加WMTS服务
creatWmtsLayerFromXYZ: function (url, projection, opacity) {
if (!url || !projection || !opacity) return;
projection = ol.proj.get(projection);
const layer = new ol.layer.Tile({
source: new ol.source.XYZ({
url,
projection
}),
opacity,
maxZoom: 18
});
return layer;
},
const layer = creatWmtsLayerFromXYZ(url, "EPSG:4326", 1);
this.map.addLayer(layer);