在 openlayers 的共享视图中使用同一层
using same layer in shared view on openlayers
我想在两个视图中渲染同一层,但遇到了问题。该图层一次显示在一张地图上。如果放大或缩小,它有时反映在视图 1 上,有时反映在视图 2 上。
var roadLayer = new TileLayer({
source: new OSM(),
});
var view = new View({
center: [-6655.5402445057125, 6709968.258934638],
zoom: 13,
});
var map1 = new Map({
target: 'roadMap',
layers: [roadLayer],
view: view,
});
var map2 = new Map({
target: 'aerialMap',
layers: [roadLayer],
view: view,
});
但是您可以在两层中使用相同的来源:
var source = new OSM();
var view = new View({
center: [-6655.5402445057125, 6709968.258934638],
zoom: 13,
});
var map1 = new Map({
target: 'roadMap',
layers: [
new TileLayer({
source: source,
})
],
view: view,
});
var map2 = new Map({
target: 'aerialMap',
layers: [
new TileLayer({
source: source,
})
],
view: view,
});
我想在两个视图中渲染同一层,但遇到了问题。该图层一次显示在一张地图上。如果放大或缩小,它有时反映在视图 1 上,有时反映在视图 2 上。
var roadLayer = new TileLayer({
source: new OSM(),
});
var view = new View({
center: [-6655.5402445057125, 6709968.258934638],
zoom: 13,
});
var map1 = new Map({
target: 'roadMap',
layers: [roadLayer],
view: view,
});
var map2 = new Map({
target: 'aerialMap',
layers: [roadLayer],
view: view,
});
但是您可以在两层中使用相同的来源:
var source = new OSM();
var view = new View({
center: [-6655.5402445057125, 6709968.258934638],
zoom: 13,
});
var map1 = new Map({
target: 'roadMap',
layers: [
new TileLayer({
source: source,
})
],
view: view,
});
var map2 = new Map({
target: 'aerialMap',
layers: [
new TileLayer({
source: source,
})
],
view: view,
});