繁体   English   中英

打开第 6 层 - 图像层与矢量图层相结合

[英]Open Layers 6 - Image Layer combine with Vector Layer

我正在尝试将图像层与矢量图层相结合,但是当我将投影添加到 View 时,矢量消失了。 难道我做错了什么?

这是我要实现的示例: 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>
        );
    }
}

他还分享了一个stackblitz: https://stackblitz.com/edit/react-ol6-xw1x9l

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM