Open Layers 6 - Image Layer 结合 Vector Layer
Open Layers 6 - Image Layer combine with Vector Layer
我正在尝试将图像层与矢量图层相结合,但是当我将投影添加到视图时,矢量消失了。我做错了什么吗?
这是我正在努力实现的一个例子:
https://stackblitz.com/edit/react-ol6
我希望下面的这两层在视图中在一起。
Vector Layer
Image Layer
对于那些寻找答案的人,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>
);
}
}
这里还有一个他分享的 stackblitz:https://stackblitz.com/edit/react-ol6-xw1x9l
我正在尝试将图像层与矢量图层相结合,但是当我将投影添加到视图时,矢量消失了。我做错了什么吗?
这是我正在努力实现的一个例子: https://stackblitz.com/edit/react-ol6
我希望下面的这两层在视图中在一起。
Vector Layer
Image Layer
对于那些寻找答案的人,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>
);
}
}
这里还有一个他分享的 stackblitz:https://stackblitz.com/edit/react-ol6-xw1x9l