我正在尝试将图像层与矢量层组合在一起,但是当我向“视图”添加投影时,矢量消失了。我做错了吗?
以下是我要实现的目标的示例:https://stackblitz.com/edit/react-ol6
我希望下面的这两层在视图中在一起。
对于那些寻找答案的人,Mike提供了一个很好的解决方案,其中您可以将范围值设置为等于矢量层的扩展范围。再次谢谢你。
var extent = [-e,-e,e,e];
var source = new VectorSource({});
var vectorLayer = new VectorLayer({
source: source,
});
var imageLayer = new ImageLayer({
source: new Static({
url: "https://imgs.xkcd.com/comics/online_communities.png",
projection: new Projection({
units: "pixels",
extent: extent
}),
imageExtent: extent,
}),
});
vectorLayer.setZIndex(1);
imageLayer.setZIndex(0);
var olMap = new Map({
target: null,
layers: [imageLayer, vectorLayer],
view: new View({
projection: new Projection({
units: "pixels",
extent: extent,
}),
center: getCenter(extent),
// center: [0,0],
zoom: 0,
}),
});
class App extends Component {
componentDidMount() {
olMap.setTarget("olmap");
vectorLayer.getSource().addFeatures(features);
}
render() {
return (
<div className="App">
<div id="olmap" style={{ width: "100%", height: "80%" }} />
</div>
);
}
}
这也是他分享的闪电战:https://stackblitz.com/edit/react-ol6-xw1x9l