Choosing OpenLayers or Leaflet?

I have used both OpenLayers and Leaflet in my apps. There has been so much discussion on this topic in this forum and others on planet-internet. They usually fall into 2 camps - features and flexibility of OpenLayers versus simplicity of Leaflet. I would not be surprised if someone spawns an "OpenLeaf" initiative soon marrying the best of both worlds!

I found Leaflet very simple to use, a petite 64K size, compared to over 700K Openlayers, and in very few steps you can create apps that have the freshness and eye-candy of today's web and mobile GIS apps. Your stack - GeoServer, PostGIS etc., is a standard stack, so OpenLayers or Leaflet could easily be incorporated.

Having said that, I would still go with OpenLayers for the following reasons

  1. There is just a TON of material around OpenLayers. It is a lot more mature than Leaflet.
  2. Check out the comparison on commits and users.
  3. OpenLayers, GeoServer, PostGIS stack is so proven in the FOSS world that you are going on a path that is solid.
  4. OpenLayers has tad bit more features on Map Controls.
  5. While its a bit more work to create transitions and visual-effects, it can be done in OpenLayers.

Leaflet all the way. I feel like Leaflet is the next step on the evolution of the open-source tile-based browser clients. Ka-Map -> OpenLayers -> Leaflet.

Leaflet is simple to use and does exactly what it says on the tin. OpenLayers has become bloated by trying to be all things to all people, Leaflet does 20% of things that are required 80% of the time.


Though I used Leaflet in my webGIS application, OpenLayers has much more advantages over Leaflet. For example if you want to use your application in mobile devices, OpenLayers is a must for the time being.

There are lots of resources related with OpenLayers, however I think developing application with Leaflet is easier than OpenLayers (it is easier to read a code and understand the structure). If you have a time limitation and have a little experience with JavaScript, using Leaflet might be a better solution to get it done faster. Or if you want to develop a very simple application, Leaflet can be much easier to adapt at first.

But after I developed an application with Leaflet, now I say I wish I had used OpenLayers at the beginning. Because when your application becomes complex (such as calling complex layers from a database, developing a robust mobile application, etc.), Leaflet starts to limit your abilities. So, I think spending a little more time to understand and learn OpenLayers structure at the learning stage will eventually worth it.

As the project details considered;

  1. Use the map interface to fetch Feature Info:

    Both Leaflet and OpenLayers can perfectly do that. The point here is to get the click event's coordinates and send request to the server. The request link will be the same for both applications.

  2. Create a customized tool that takes the lat/lon from user as to where he/she clicks on the map and then fetches the Climate Data from the raster (which is handled by a py script on the server):

    I achieved that myself in Leaflet (I was also calling the climate data by the way). I wasn't fetching the raster data from a server but the point here is to create a request link, which is easy for both applications. However if you want to select a polygon at this stage it is a bit hard on Leaflet to achieve.

  3. Allows user to upload excel, which is sent to the py script, which returns a GeoJSON, which creates Vector Features on the map:

    Approximately the same line of work for both Leaflet and OpenLayers. I can't say which one is better.

  4. Allow user to create vector polygons, which will fetch the Features it intersects from the WFS Layer:

    I have no idea about OpenLayers editing abilities but Leaflet has a plugin called Leaflet Draw, which is easy to use and manipulate the drawings (on javascript side) after drawing is completed. Also Leaflet has a WFS-T support if you want to manipulate the spatial data on WFS server. OpenLayers might be better than that, I don't know.

  5. Fetches Layer from the PostGIS Datastore on GeoServer and displays the layers on the map:

    Definitely OpenLayers is better for this job as it is easier to connect PostGIS server.

By the way, there is an application suite called OpenGeo Suite that includes OpenLayers, GeoServer and PostGIS; which will solve all the problems a web based GIS application developer has.