Search code examples
canvasmapsgisopenlayersopenlayers-5

How can I convert VectorSource to RasterSource


In OpenLayers ol.source.ImageVector has been deprecated since v5.
Docs recommended to use an ol.layer.Vector with renderMode: 'image' instead.
But what if I want to get an another raster source at output? (Not a layer)
Is there any workaround?


Solution

  • The output from ol.source.Raster is always a raster source. The input can be either a source or layer.

    OpenLayers 4:

    https://codepen.io/mike-000/pen/KKpgrmx

    new ol.source.Raster({
      sources: [
        new ol.source.ImageVector({
          source: new ol.source.Vector()
        })
      ]
    })
    

    OpenLayers 5:

    new ol.source.Raster({
      sources: [
        new ol.layer.Vector({
          source: new ol.source.Vector()
        }),
        renderMode: 'image'
      ]
    })
    

    OpenLayers 6:

    https://codepen.io/mike-000/pen/BaNLvyq

    new ol.source.Raster({
      sources: [
        new ol.layer.VectorImage({
          source: new ol.source.Vector()
        })
      ]
    })