OpenLayers - A High performance, a featured-packed library for all your mapping needs

Kamalka Fernando
3 min readAug 8, 2022

--

Photo by GeoJango Maps on Unsplash

If you want to add a map layer to your website, this blog will help you with that. So let's learn about this.

OpenLayers is a free and open-source javascript-based library.

Getting Started!

  1. You need to have Node installed on your machine
  2. Install the OpenLayer package from npm
  3. Create a new project in your desired place and open it from cmd and run npx create-ol-app or you can run npx create-ol-app my-new-ol-app to create a new project folder with the OpenLayer package at once.
  4. Then start your node project by running npm start there you can see the default localhost copy that and paste it into your browser and see.

Basic Concepts

I am going to briefly discuss Map, View, Source, and Layer.

Map is the core component of OpenLayers. The map should have height and width attributes with some value if not the map won’t display. More details on ol/Map

Example:

In .html page :

In .css page:

In .js page:

View is for zoom level, center, and projection of the map. More details on ol/View

Example:

Source is to get remote data from other sources. OpenStreetMaps and Bing maps are some free map tile services that can be used and we can get the vector format as we wished. More Details ol/source/Source.

Example:

Layer is the virtual representation of data from the source we used. For more details ol/layers.Layers

There are four types of layers as follows,

  1. Tile Layer(ol/layer/Tile)
  2. Image Layer(ol/layer/Image)
  3. Vector Layer(ol/layer/Vector)
  4. VectorTile Layer(ol/layer/VectorTile)

Example:

These are the basics you should know about OpenLayers. If we organized what we discussed as a single code. You will get the following code on your .js file.

Thank you for Reading!!!

Keep connected to me on medium for more blogs!

--

--