<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: bwyss</title>
    <description>The latest articles on DEV Community by bwyss (@benwyssenview).</description>
    <link>https://dev.to/benwyssenview</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F299691%2F6f129bb8-4c54-43da-8d0e-b644d6f46e07.jpeg</url>
      <title>DEV Community: bwyss</title>
      <link>https://dev.to/benwyssenview</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/benwyssenview"/>
    <language>en</language>
    <item>
      <title>(almost) Everything I know about building an open source web application</title>
      <dc:creator>bwyss</dc:creator>
      <pubDate>Sun, 29 Dec 2019 02:51:01 +0000</pubDate>
      <link>https://dev.to/benwyssenview/almost-everything-i-know-about-building-an-open-source-web-application-42nl</link>
      <guid>https://dev.to/benwyssenview/almost-everything-i-know-about-building-an-open-source-web-application-42nl</guid>
      <description>&lt;p&gt;I have been building web mapping apps for some time and thought I'd jot down some notes on the subject.&lt;/p&gt;

&lt;p&gt;I'll cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Javascript libraries used to create a map on the web&lt;/li&gt;
&lt;li&gt;Geospatial data formats&lt;/li&gt;
&lt;li&gt;Getting data from point A (server / cloud) to point B (the web app / internet browser)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Software Resources
&lt;/h3&gt;

&lt;p&gt;First you're going to want to select a front end mapping API. There are many available, but I'll just focus on a few.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;2D&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.mapbox.com/mapbox-gl-js/api/"&gt;MapBox-GL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://leafletjs.com/"&gt;Leaflet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://openlayers.org/"&gt;Openlayers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://deck.gl/"&gt;Deck-GL&lt;/a&gt; (2.5D)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;3D&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://cesium.com/cesiumjs/"&gt;CesiumJs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.melowntech.com/products/vadstena/#content"&gt;Vadstena&lt;/a&gt; by Melown tech&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.harp.gl"&gt;Harp&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Geospatial DataBase&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://postgis.net/"&gt;PostGIS&lt;/a&gt; an extension of &lt;a href="https://www.postgresql.org/"&gt;PostgreSQL&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/couchbase/geocouch/"&gt;GeoCouch&lt;/a&gt; (an extension of &lt;a href="https://couchdb.apache.org/"&gt;CouchDB&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.mongodb.com/"&gt;MongoDB&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Middleware&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://geoserver.org/"&gt;GeoServer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://grass.osgeo.org/"&gt;GRASS GIS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://mapserver.org/"&gt;MapServer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Online Geospatial Tools&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://turfjs.org/"&gt;Turf.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://geojson.org/"&gt;GeoJson.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://maputnik.github.io/editor/#0.87/0/0"&gt;Maputnik&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2D
&lt;/h2&gt;

&lt;h5&gt;
  
  
  Pick Your API
&lt;/h5&gt;

&lt;p&gt;Ok, so you are after a 2D web mapping application, let's get started. Each of the above open source 2D web mapping apis are great and would probably fit the bill for most applications, but there are a few differences that might be worth considering. Leaflet might be the best bet for a basic project, while OpenLayers is probably better suited for  advanced applications. I tend to use MapBox-GL for most apps. I'll get into some reasons why a bit later in the post.&lt;/p&gt;

&lt;h5&gt;
  
  
  Basemap
&lt;/h5&gt;

&lt;p&gt;You are going to need a basemap. A basemap provides a background of geographical information for the map, it can be a satellite and or street map or a hybrid of the two. For most situations it is going to make sense to get a basemap from some kind of mapping provider. A few include: &lt;a href="https://www.openstreetmap.org/"&gt;OpenStreetMaps&lt;/a&gt;, &lt;a href="https://www.bing.com/maps"&gt;Bing Maps&lt;/a&gt;, some Googling will get you the rest of the way. &lt;a href="https://www.mapbox.com/mapbox-studio/"&gt;MapBox studio&lt;/a&gt; will allow you to create a custom styled basemap (based on OpenStreetMap data).&lt;/p&gt;

&lt;h5&gt;
  
  
  Scalability
&lt;/h5&gt;

&lt;p&gt;Before we get too far, we need to think for a moment about the data that you want to render in the map. If a lot of data needs to be rendered in the map, we can run into scalability issues if we are not careful. Most data formats that we will deal with in 2D maps fall into two categories: vector and raster data. Vector data can be points, lines and polygons. Raster data is generally served to the front end mapping environment as tiled images. If your application does not require scaling tricks, you can render vector data directly from &lt;a href="https://geojson.org/"&gt;GeoJSON&lt;/a&gt;. &lt;strong&gt;Tip&lt;/strong&gt; &lt;a href="http://geojson.io/"&gt;online GeoJson editor&lt;/a&gt; is a hand tool for creating and editing GeoJSON.&lt;/p&gt;

&lt;p&gt;In the early days of web mapping, it was easy to encounter performance issues when rendering too many vector features in a web browser. A solution was to burn the vector features into a raster on the server side, and then render the images in the web application. This is still a common approach with middleware solutions like &lt;a href="http://geoserver.org/"&gt;GeoServer&lt;/a&gt; or &lt;a href="https://mapserver.org/"&gt;MapServer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Another (more modern) approach is to use &lt;a href="https://github.com/mapbox/vector-tile-spec"&gt;MapBox vector tiles (MVT)&lt;/a&gt;. With MVTs you can render vast amounts of vector data to the web. MVTs can be generated (commonly on the server side) and served by a cloud provider or you can generate and serve them yourself.&lt;/p&gt;

&lt;p&gt;MapBox-GL and OpenLayers can render MVT, but Leaflet cannot without an extension. The MapBox-GL API provides integrated client side filtering and styling directly on the MVT spec. This can be a significant advantage if you plan to use MVT extensively in your app. &lt;strong&gt;Tip&lt;/strong&gt; &lt;a href="https://github.com/t-rex-tileserver/t-rex"&gt;T-Rex&lt;/a&gt;, &lt;a href="https://github.com/go-spatial/tegola"&gt;Tegola&lt;/a&gt;, &lt;a href="https://github.com/mapbox/tippecanoe"&gt;Tippecanoe&lt;/a&gt; and &lt;a href="https://github.com/mapbox/geojson-vt"&gt;Geojson-VT&lt;/a&gt; can be used to create MVTs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Navigation
&lt;/h4&gt;

&lt;p&gt;I have never build a navigation app, but there are a lot of navigation tools out there:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://project-osrm.org/"&gt;OSRM&lt;/a&gt; (open source)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Project-OSRM/osrm-backend"&gt;Open Source Routing Machine&lt;/a&gt; (open source)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/graphhopper/graphhopper"&gt;Graphhopper&lt;/a&gt; (open source)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.mapzen.com/blog/valhalla-intro/"&gt;Valhalla&lt;/a&gt; (open source)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.mapbox.com/api/"&gt;MapBox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/maps/documentation/directions/intro?hl=en"&gt;Google Maps&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.microsoft.com/en-us/bingmaps/v8-web-control/map-control-concepts/directions-module-examples/?redirectedfrom=MSDN"&gt;Bing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.arcgis.com/features/directions/"&gt;ESRI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://business.mapquest.com/products/routing-directions-api/"&gt;Mapquest&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Data Manipulation
&lt;/h5&gt;

&lt;p&gt;You may want to allow a user to tinker with the data, for example modify the location of a vector point. In this case you cannot modify raster images or MVT data directly from the font end application. One solution is to identify the modification in the front end, then send the change server side and then update the data, you will then need to re-render your data front end, however this could be troublesome, let me explain why: &lt;/p&gt;

&lt;p&gt;Suppose you are burning your vector data into rasters, you may want to cache these images (caching is a really good idea, we have not talked about rendering raster tiles in detail, but in a nut shell you will need to render a pyramid of tiles, each layer of the pyramid will be needed for all of the zoom levels available to your web mapping application). Now you have just changed a feature in your data, in order to make the data change visible in the map you will need to blow away your cache and start burning new images, this cache management can be a painful and expensive.&lt;/p&gt;

&lt;p&gt;If you are using MVT, a solution could be to first request the GeoJson data for a feature from the server or geospatial middleware (even if you are rending the bulk of the data using raster images or MVT). Then, you can manipulate that GeoJson feature on the front-end with &lt;a href="https://turfjs.org/"&gt;Turf.js&lt;/a&gt;, then pass your newly updated GeoJSON feature back to the server for a database update. Next, you will need to update the MVT and manage the cache, be carful, often times the MVT are cached client side. The best solution I have found is to isolate the layers that may get frequent updates from layers that are not often getting updated. Then modify the MVT headers such that the cache refresh rate is very low. This is not a very elegant solution, so if someone has better ideas I'm all ears.&lt;/p&gt;

&lt;h2&gt;
  
  
  3D
&lt;/h2&gt;

&lt;p&gt;Because 3D web rendering is kind of new, I have only had the opportunity to deep dive into CesiumJS, so I'm going to talk mostly about that.&lt;/p&gt;

&lt;p&gt;Raster tiles can be rendered in a 3D environment. Vector formats like GeoJSON can also be rendered in a 3D environment, however, similar to the 2D environment, if you render a lot of vector features you can run into performance issue quickly.&lt;/p&gt;

&lt;p&gt;When viewing a map in 2D, you are looking at the data from a top down - birds eye view. Raster and vector formats are well suited for this perspective. However, when we start looking at the map in 3D it is interesting to explore different ways of rendering data. For this reason, Cesium has developed &lt;a href="https://github.com/AnalyticalGraphicsInc/3d%20tiles"&gt;3D tiles&lt;/a&gt; and &lt;a href="https://github.com/AnalyticalGraphicsInc/quantized-mesh"&gt;quantized mesh terrain format&lt;/a&gt; formats that can be used to render point-cloud, 3D models and terrain data.&lt;/p&gt;

&lt;h4&gt;
  
  
  3D Tiles
&lt;/h4&gt;

&lt;p&gt;In &lt;a href="https://cesium.com/cesiumjs/"&gt;CesiumJS&lt;/a&gt; or &lt;a href="https://deck.gl/#/"&gt;Deck-GL&lt;/a&gt; ecosystems 3D tiles can be used to render data in the map. 3D tiles are a spatial data structure that enable hierarchical level of detail (HLOD) so only visible tiles are streamed to the front-end map.&lt;/p&gt;

&lt;p&gt;With 3D tiles you can encode a bunch of data formats into 3D tiles and then render 3D tiles in CesiumJS. The formats include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;glTF (.gltf, .glb)&lt;/li&gt;
&lt;li&gt;CityGML (.citygml, .xml, .gml)&lt;/li&gt;
&lt;li&gt;KML/COLLADA (.kml, .kmz)&lt;/li&gt;
&lt;li&gt;LASer (.las, .laz)&lt;/li&gt;
&lt;li&gt;COLLADA (.dae)&lt;/li&gt;
&lt;li&gt;Wavefront OBJ (.obj)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the above data formats are wrapped into the 3D tiles spec and rendered in the web, CesiumJS will "define a spatial hierarchy for fast streaming and precision rendering, balancing performance and visual quality at any scale from global to building interiors". This is a necessity when rendering very large data sets like point clouds. It's worth mentioning that ESRI has a similar open source spec called &lt;a href="https://github.com/Esri/i3s-spec"&gt;i3s&lt;/a&gt;, shoot me a note if you know of an open source i3s web consumer.&lt;/p&gt;

&lt;p&gt;Cesium also developed a terrain spec, with it you can take a digital elevation model (DEM) and convert it into a quantized mesh terrain format. You can create and serve 3D tiles and terrain in the cloud via &lt;a href="https://cesium.com/cesium-ion/"&gt;Cesium ion&lt;/a&gt; or you can create them using open source tools like &lt;a href="https://github.com/connormanning/entwine"&gt;Entwine&lt;/a&gt;, for point cloud -&amp;gt; 3D tiles and &lt;a href="https://github.com/tum-gis/cesium-terrain-builder-docker"&gt;cesium terrain builder docker&lt;/a&gt; for DEM -&amp;gt; terrain. &lt;strong&gt;Side note&lt;/strong&gt; if you are after a simple point cloud web render Cesium might be over kill and you might want to check out &lt;a href="http://potree.org/"&gt;Potree&lt;/a&gt;. &lt;strong&gt;Tip&lt;/strong&gt; &lt;a href="https://github.com/Oslandia/lopocs"&gt;lopocs&lt;/a&gt; is an open source point-cloud server. &lt;strong&gt;Pro-tip&lt;/strong&gt; check out &lt;a href="https://pdal.io/"&gt;PDAL&lt;/a&gt; for all your point cloud translating and manipulating needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Back-End
&lt;/h2&gt;

&lt;p&gt;The data that you want to render on the map is going to be saved somewhere, the two conventional solutions for this are a database or a geospatial cloud service. There are a number of geospatial hosting / serving solutions out there, MapBox, Here, Esri, Carto, MapZen to name a few. This could be a good solution if you want to pay a monthly fee and be done. But this post is on open source solutions so I am going to focus on that. You might need a geospatial database depending on the complexity and size of your data and your application requirements. &lt;strong&gt;Tip&lt;/strong&gt; &lt;a href="https://gis.stackexchange.com/"&gt;Geo-Stackexchange&lt;/a&gt; is a great resource for geospatial software development questions.&lt;/p&gt;

&lt;h4&gt;
  
  
  Vector Data
&lt;/h4&gt;

&lt;p&gt;A geospatial database will allow you to geo-index your data, this allows the data to be accessed much more efficiently. Geospatial databases also allow you to do geospatial operations on the data. For example you might want to find all of the points that are within a given distance from another point. The most feature rich open source geospatial database is &lt;a href="https://postgis.net/"&gt;PostGIS&lt;/a&gt; which is an extension of &lt;a href="https://www.postgresql.org/"&gt;PostgreSQL&lt;/a&gt;. If you are looking for a noSQL option then &lt;a href="https://github.com/couchbase/geocouch/"&gt;GeoCouch&lt;/a&gt; (an extension of &lt;a href="https://couchdb.apache.org/"&gt;CouchDB&lt;/a&gt;) may be a good fit, or if you just need to serve up some GeoJSON features &lt;a href="https://www.mongodb.com/"&gt;MongoDB&lt;/a&gt; might be all you need. &lt;strong&gt;Pro-tip&lt;/strong&gt; &lt;a href="https://gdal.org/"&gt;GDAL&lt;/a&gt; is a translator library for raster and vector geospatial data formats.&lt;/p&gt;

&lt;h4&gt;
  
  
  Raster Data
&lt;/h4&gt;

&lt;p&gt;PostGIS is probably the best option for hosting raster geospatial data. In order to get those raster to the web, you are going to need a geospatial middleware, see below for details. &lt;strong&gt;Tips&lt;/strong&gt; &lt;a href="https://github.com/mapbox/rasterio"&gt;rasterio&lt;/a&gt; is a nifty little raster project that can read and write geospatial raster data and &lt;a href="https://qgis.org/en/site/"&gt;QGIS&lt;/a&gt; is an open source GIS tool I use for pre-processing geospatial data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Geospatial Middleware
&lt;/h2&gt;

&lt;p&gt;A geospatial middleware is used to translate or transform data from the database or from a directory into a format that is easily interpreted by the mapping API in the front-end. For example, if you have some vector data in your database or in a file directory, the middleware can generate and serve MVT to the front end web application. Middleware can also generate and serve raster tiles from a raster source file. &lt;a href="http://geoserver.org/"&gt;GeoServer&lt;/a&gt;, &lt;a href="https://grass.osgeo.org/"&gt;GRASS GIS&lt;/a&gt; and &lt;a href="https://mapserver.org/"&gt;MapServer&lt;/a&gt; are a few great middleware tools. A geospatial middleware is also going to help you by moving geospatial data around in an &lt;a href="https://www.opengeospatial.org/standards"&gt;OGC&lt;/a&gt; standard format (which is a good idea!). &lt;strong&gt;Pro-tip&lt;/strong&gt; &lt;a href="http://geonode.org/"&gt;GeoNode&lt;/a&gt; is a full-stack open source geospatial content management solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wish List
&lt;/h2&gt;

&lt;p&gt;If I could snap my fingers and change anything in the open source web mapping world, I would love to see a 3D vector tiles spec developed for the CesiumJS ecosystem.&lt;/p&gt;

&lt;p&gt;Also, I would change the way that the MapBox-GL API manages the basemap layer. If you render a basemap and then add some raster or vector layers on top of the basemap and then change the basemap for example from a street map to a satellite map, you will need re-order all of your layers to get back to the map state as it was before the basemap was changed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Community
&lt;/h2&gt;

&lt;p&gt;If you're like me and get hooked on this stuff, you'll also want to check out &lt;a href="https://foss4g.org/"&gt;FOSS4G&lt;/a&gt; a yearly open geospatial technology and business conference organized by the &lt;a href="https://www.osgeo.org/"&gt;Open Source Geospatial Foundation&lt;/a&gt;. They also have regional flavors of the conference. Hope to see you there!&lt;/p&gt;

</description>
      <category>gis</category>
      <category>mapping</category>
    </item>
  </channel>
</rss>
