web analytics
GeoJSONGIS SoftwareJavaScriptopen source gis

Openlayers: Geospatial JavaScript Library – GIS Lounge

  • JavaScript can provide powerful mapping and spatial operation functionality
  • JavaScript has a low learning threshold and can be useful for current programmers
  • OpenLayers is a powerful JavaScript library used for mapping
  • OpenLayers works well with other JavaScript tools

One of the most under-utilized programming languages in geospatial analysis and processing is JavaScript. Relative to languages such as Python, R, Java, and C#, JavaScript is often the forgotten geospatial language, despite the large and growing libraries available for spatial functionality and display.

The syntax, relative to languages such as C and C#, is easier to understand, and you can simply use a web browser to test functionality and example script. Generally, the language is often used to run on client and server side applications. Using GIS server data, dynamic maps are often updated using JavaScript.

It is also used on the local side on machines that apply geospatial problem solving and there are growing libraries to enable more spatial analysis. The rise of OpenLayers, which is a JavaScript library used to create rich maps that can be placed on websites, has showcased the utility of JavaScript.

In a recent MapScaping podcast, Marc Jansen, a member of the steering committee for the OpenLayers project, discusses the utility of OpenLayers and JavaScript in geospatial processing and mapping.[1]

What OpenLayers can do is it can read different data formats with geospatial components. Common data formats that the tool works with include GeoRSS, KML (Keyhole Markup Language), Geography Markup Language (GML).

As an example, a GeoJSON file, which is an open standard, can be used to provide vector data and attribute information about given points. Vector data are also set up to be 3D by default with the Cesium tool used as the default display of 3D data.

Additionally, the Proj library enables the projection of vector and raster data well and works between and with many different types of projections. Despite varying formats often used for vector and pixel-based raster data, OpenLayers can re-project data to the desired projection relatively easy, making mapping far simpler for online tools.

What makes OpenLayers useful is different formats can be used together so that they can be stacked together and used for analysis, making it flexible for dynamic mapping and able to handle different data sources.[2] 

Other tools are also available and contributors are always adding more functionality within OpenLayers, often these contributions being small but useful functions users find.

Some of the common functionalities include map zooming, editing and adding points, digitizing polygons, rotating existing polygons, and other dynamic webmap functions. Most functions, in fact, that we know we can do using online maps today are found in OpenLayers.

Functionality includes pinching to zoom in and out, something users have become accustomed to on popular online maps, is available, where OpenLayers can detect a device’s capabilities to then determine if pinching would be used. Basic functions include snapping and measurement, but more complex analytical processing is not something OpenLayers is that well developed yet.

The library, however, can provide some very useful raster analytic capabilities. For instance, vegetation greenness index can be calculated on the fly or even determining how a rise in sea-level change affects surrounding landscapes. Users also have access to JavaScript libraries to add vector functionality as needed. The npm (Node Package Manager) tool helps to find and integrate different tools that users may find on popular sites such as GitHub. For instance, existing tools available allow one to take two vector points, such as cities, and calculate the arc distance or even potential flight path between the points.

Example showing the integration of turf.js with OpenLayers. The turf.js function along is used to display a marker every 200 meters along a street. Screenshot from OpenLayers.
Example showing the integration of turf.js with OpenLayers. The turf.js function along is used to display a marker every 200 meters along a street. Screenshot from OpenLayers.

Another useful tool is Turf.js, which provides powerful browser spatial analysis functionality and is a growing library.[3] Even popular tools such as ArcGIS have created JavaScript tools and an API for developers building geospatial applications.[4]

The benefit of OpenLayers, and by extension JavaScript, is that the learning barriers are low and yet can provide powerful mapping capabilities, particularly for web-based applications that are increasingly becoming common. For web-based functionality, few other languages are as powerful in dealing with server-side and client-side data handling and processing.

The ease in which one can make dynamic maps also given OpenLayers a major advantage over many other tools. For existing programmers, often JavaScript is over-looked but having skills to create and develop JavaScript tools, as well as use tools such as OpenLayers, has great benefits for employment and the type of applications that can be created. While JavaScript is still understated, its growing list of libraries and capabilities means we can expect this now 25-year old language will continue to grow in its geospatial utility.


[1]    For more on Marc Jansen and his views on OpenLayers and JavaScript, see:  https://mapscaping.com/blogs/the-mapscaping-podcast/openlayers-geospatial-javascript.

[2]    To learn and see more about OpenLayers functionality, see:  https://openlayers.org/.

[3]    The Tuf.js library can be found here:  https://turfjs.org/.

[4]    For more on ArcGIS’ JavaScript API, see:  https://developers.arcgis.com/javascript/.


Latest MapScaping Podcast

Show More

Related Articles

Back to top button