I was debating with one of my collegues on OpenLayers v/s Leaflet. I made a point that OpenLayers is much better API if we wish to build a project, where you need direct connectivity to the Geoserver and PostGIS.

Then I found Open Data Kit, which looks pretty new but has the features of connectivity with the Geoserver and PostGIS.

So my project details are as follows,

  1. Use the map interface to fetch Feature Info
  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)
  3. Allows user to upload excel, which is sent to the py script, which returns a GeoJSON, which creates Vector Features on the map
  4. Allow user to create vector polygons, which will fetch the Features it intersects from the WFS Layer.
  5. Fetches Layer from the PostGIS Datastore on GeoServer and displays the layers on the map.

So now I am confused on which is better and why using OpenLayers over Leaflet makes more sense or not?

closed as primarily opinion-based by PolyGeo Mar 27 '18 at 23:48

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Depends on the project. – CaptDragon Sep 20 '12 at 16:55
  • 1
    a. Improve your question by giving more details on the project. b. You are talking about direct connection to the database (postgis) for the users, are you sure? – Pablo Sep 20 '12 at 17:06
  • sorry about that, updated my project details – Sam007 Sep 20 '12 at 17:30
  • In general I prefer Leaflet, because it tends to lead towards shorter and more readable .js files. But OL can do things that Leaflet can't, because you are allowed deeper and more detailed access - So, I agree. It depends on the project, but 1 vote for Leaflet from me. – MartinHvidberg Mar 28 '18 at 6:31

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.
  • 1
    Also what about mobile devices? Which is better suited? – Sam007 Oct 2 '12 at 15:35
  • 1
    Yes. I am currently building mobile apps using OpenLayers and SenchaTouch. There are plenty of mobile map apps running on Openlayers. Here are some examples openlayers.org/dev/examples/?q=mobile. – Ramesh Elaiyavalli Oct 2 '12 at 17:31

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 to be all things to all people, Leaflet does the 20% of things that are required 80% of the time.

  • 10
    So it's not just "Leaflet all the way", it's "Leaflet if you don't need any of all those features missing in it". I agree that Leaflet is much simpler to use, but if you need to do something not that common you have to go with OL. – Juan Aug 14 '15 at 17:44
  • Leaflet lacks many functions. Leaflet is good for just very basic maps but at as already explained by Ramesh Elaiyavalli Ol-3 is best and also you can reduce the size by selecting features by using custom built . – Abhijit Gujar May 11 '16 at 16:48

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;

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.

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.

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.

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.

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.


There is a great comparison on the two frameworks in this presentation:

Leaflet vs OpenLayers

And another article also has a great summary:

Customers often ask us, “Which is the best client-side JavaScript mapping library to use when building a modern web app with the Map Suite WebAPI Edition?” Like a lot of things in Software Development, the answer isn’t always clear. The answer depends on your requirements and development preferences. Since both frameworks are well documented and work solidly on mobile devices, we usually ask the following questions to help our customers make the right decision.

How simple is mapping portion of the app you are building?

The simpler the mapping requirements, the more we lean toward using Leaflet. Leaflet does a fantastic job of handling the most common mapping tasks like consuming base map tiles, panning, and zooming, and its API is easy to understand and simple to use. Once you go beyond the common tasks, however, you need to use Leaflet Plugins and this where things become more complicated. There might be functionality that you are looking for that unfortunately doesn’t exist.

If you have a feature rich application with lots of functionality, we gravitate toward using OpenLayers 3. OpenLayers 3 has a larger and more complex API that will allow you to do all of the common mapping functions that Leaflet does plus many more. For example, if your application has requirements involving map projection, OpenLayers 3 will allow you to accomplish these requirements more easily than if you are using Leaflet. Of course, with a more robust API comes a steeper learning curve, so keep that in mind when providing estimates to your project stakeholders.

How much JavaScript code do you want to write?

Since Leaflet is a higher level API than OpenLayers 3, it usually takes less JavaScript code to get it up and running. Once you want to deviate from the standard functionality that Leaflet provides, however, it is likely that you will end up writing a lot of code unless there is a plug-in that meets your exact needs. On the other hand, OpenLayers 3 is a lower level API which requires more JavaScript coding to initialize and set up the map. This can be convenient when you have customized and complex requirements, as the API allows more control over the map and your data.


In closing, there are times when it’s best to use Leaflet and times when OpenLayers 3 wins out. If your mapping requirements are simple, it’s in your best interest to check out Leaflet first. But if you’re looking for a mapping library that is more customizable and don’t mind getting dirty with JavaScript development, reach for OpenLayers 3.

Since both libraries have their strengths, we have included code samples for both Leaflet and OpenLayers 3 with the Map Suite WebAPI Edition that can be downloaded through Product Center or viewed on the ThinkGeo Wiki. These samples are useful resources when deciding which client-side Javascript mapping library to use for your app because you can see first-hand the different user experiences and coding requirements between the two libraries.

From http://blog.thinkgeo.com/2015/09/08/leaflet-vs-openlayers-3-which-is-the-better-client-side-javascript-mapping-library/


I've just gone through this decision for my new mobile project and the clear winner is OpenLayers. Leaflet, as of this writing, was rather sluggish on mobile. The transitions for pan/zoom did not feel smooth and it was disorienting at times. Short of going native, I tried OpenLayers and the experience is much better. Still not as good as native, but definitely usable and a real option.

  • 1
    Interesting. I would have expected Leaflet to be lighter and smoother on a mobile device. Thanks for sharing this experience. – LarsH Sep 10 '14 at 23:29
  • @Christian Fritz - was your experience with OL3 or OL2? – sfletche Sep 11 '14 at 20:04
  • 2
    @sfletche the comparison was between OL3 and leaflet 0.7.3 – Christian Fritz Sep 11 '14 at 23:02

I'd say check the API documentation for both. For me it seems that OpenLayers offers an extensive bunch of features, however the development/debugging time is longer.

Leaflet is sexier and much more easy going rather than the OL, however if you want to do a lot with your map, I think someday you might need a feature which is not implemented in Leaflet yet!

I really recommend to take a look at APIs! OpenLayers & Leaflet

Also you might need to consider that current stable release for Leaflet is 0.5.1 but it's 2.12 for OpenLayers.

P.S. If I want to develop a mobile application, I think I might go for Leaflet.


There is a basic tutorial that compares the APIs of both OpenLayers 3 and Leaflet by having you build the same thing in both of them. It is written by Astun Technology and the tutorial tasks are:

  • Basic map with OSM tiles
  • OS-GB Map with Ordnance Survey tiles
  • GeoJSON layer with markers
    • Info for GeoJSON layer
  • WMS layer
    • Info for WMS layer

Here's the link: https://astuntechnology.github.io/osgis-ol3-leaflet/index.html

  • scrolling by spacebar is broken btw – bugmenot123 Jul 20 '15 at 11:14

It depends on what you are trying to do. Leaflet is simpler and faster for 80% of web map projects.

The same way you don't need a spaceship to go around your neighborhood, most of the time I found OpenLayers way too complex to do really simple things, specially from Version 3.

For example, creating a layer selector takes maybe 5-6 lines of code in Leaflet while in OpenLayers 4 you have to build it from scratch. You have awesome tools to do it, but most of the time you don't want a customised layer selector, just one that works fine.

Another important thing to consider is that most of the information, tutorials and debates around the internet are about OpenLayers 2. They are out of date, as Version 3 is not compatible with Version 2. And we're now on Version 4. Version 2 had a lot of simple stuff like layers selector, popups, etc. along with more complex functions; but for whatever reason they just deleted those kinds of things in order to evolve towards a complex and very powerful system. Furthermore, there is a lot more information now about Leaflet than in 2012, and it's a more mature technology.

As a conclusion, ask yourself if you need a car or a spaceship. You won't fly with a car, but driving a spaceship to go shopping can be really complicated.

Not the answer you're looking for? Browse other questions tagged or ask your own question.