openlayers设置ImageStatic可见不可见

 <script type="text/javascript">
        var extent = [0, 0, 418, 600];
        var projection = new ol.proj.Projection({
            code: 'xkcd-image',
            units: 'pixels',
            extent: extent
        });

        var map = new ol.Map({
            layers: [
              new ol.layer.Tile({
                  source: new ol.source.OSM()
              }),
              new ol.layer.Group({
                  layers: [
                      new ol.layer.Image({
                          source: new ol.source.ImageStatic({
                              url: 'http://localhost:2265/images3/test2.png',
                              projection: projection,
                              imageExtent: extent,
                          })
                      }),
                     new ol.layer.Image({
                         source: new ol.source.ImageStatic({
                             url: 'http://localhost:2265/images2/test1.png',
                             projection: projection,
                             imageExtent: extent,
                         })
                     })
                  ]
              })
            ],
            target: 'map',
            view: new ol.View({
                projection: projection,
                center: ol.extent.getCenter(extent),
                zoom: 2,
                maxZoom: 8
            })
        });
        var layers = map.getLayers().getArray()[1].getLayers().getArray();
        var tiss = layer.getVisible();
        var frame = 1;
        setInterval(function () {
            layers[frame].setVisible(false);
            frame = (frame + 1) % 2;
            layers[frame].setVisible(false);
        }, 500);
    </script>

转载自:https://blog.csdn.net/h1534589653/article/details/77703537

You may also like...

退出移动版