View, Layer and Source in OpenLayers-Part 2

For Part-1, Click here

ol.View, ol.layer and ol.source are one of the foundations of OpenLayers application. You can not move ahead without understanding them. Let’s understand them with the help of following code.

  • ol.View: It is used to set the view of map. At line number 25 in above code snippet, our map object(defined at line number 18) accepts view property. The ol.View set the center and zoom level of map when it is loaded for the first time.
  • ol.layer: It is use to add layers(GIS data) to map. This is always used with ol.source. ol.layer defined at line number 21 under the map property layers. ol.layer has sub types for Raster, Vector, Tiles and other GIS data. For vector layer, we will use ol.layer.Vector, for raster layer, we will use ol.layer.Raster and so on. Here we are using, ol.layer.Tile for tile data. ol.layer is use to render the data on map.
  • ol.source: It is use to store layer data. It is always used with ol.layer. Similar to ol.layer, source has also relevant sub types for respective ol.layer. For vector layer, we have ol.source.Vector, For tile layer, we will have ol.source.Tile and so on.

ol.View is use to set the view of map.

ol.source is use to store layer data and ol.layer is use to render the layer data on map which it gets from ol.source. Source and Layer are always used together.

1 thought on “View, Layer and Source in OpenLayers-Part 2”

  1. Pingback: Clustered Features in OpenLayers - Spatial Dev Guru

Leave a Reply Cancel reply