我想在开放层中显示多个基础层。我不知道我在做什么错。代码被摘录如下
import 'ol/ol.css';
import GeoJSON from 'ol/format/GeoJSON';
import Map from 'ol/Map';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import View from 'ol/View';
import sync from 'ol-hashed';
import TileLayer from 'ol/layer/Tile';
import XYZSource from 'ol/source/XYZ';
//! [map-const]
const map = new Map({
//! [map-const]
target: 'map-container',
view: new View({
center: [0, 0],
zoom: 2
})
});
sync(map);
//! [source]
const source = new XYZSource({
url: 'http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg'
});
const source2 = new VectorSource({
format: new GeoJSON(),
url: './data/countries.json'
})
//! [source]
//! [layers]
const layer = new TileLayer({
source: source
});
const layer2 = new VectorLayer({
source: source2
})
map.addLayer(layer)
map.addLayer(laye2)
//! [layers]
实际上,我试图显示两层,但是两层都堆叠在一起。 我不知道我是否需要为此添加控件。请帮助我