Table of Contents for
Mastering OpenLayers 3

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Mastering OpenLayers 3 by Gábor Farkas Published by Packt Publishing, 2016
  1. Cover
  2. Table of Contents
  3. Mastering OpenLayers 3
  4. Mastering OpenLayers 3
  5. Credits
  6. About the Author
  7. About the Reviewer
  8. www.PacktPub.com
  9. Preface
  10. What you need for this book
  11. Who this book is for
  12. Conventions
  13. Reader feedback
  14. Customer support
  15. 1. Creating Simple Maps with OpenLayers 3
  16. Structure of OpenLayers 3
  17. Building the layout
  18. Using the API documentation
  19. Debugging the code
  20. Summary
  21. 2. Applying Custom Styles
  22. Customizing the default appearance
  23. Styling vector layers
  24. Customizing the appearance with JavaScript
  25. Creating a WebGIS client layout
  26. Summary
  27. 3. Working with Layers
  28. Building a layer tree
  29. Adding layers dynamically
  30. Adding vector layers with the File API
  31. Adding vector layers with a library
  32. Removing layers dynamically
  33. Changing layer attributes
  34. Changing the layer order with the Drag and Drop API
  35. Clearing the message bar
  36. Summary
  37. 4. Using Vector Data
  38. Accessing attributes
  39. Setting attributes
  40. Validating attributes
  41. Creating thematic layers
  42. Saving vector data
  43. Saving with WFS-T
  44. Modifying the geometry
  45. Summary
  46. 5. Creating Responsive Applications with Interactions and Controls
  47. Building the toolbar
  48. Mapping interactions to controls
  49. Building a set of feature selection controls
  50. Adding new vector layers
  51. Building a set of drawing tools
  52. Modifying and snapping to features
  53. Creating new interactions
  54. Building a measuring control
  55. Summary
  56. 6. Controlling the Map – View and Projection
  57. Customizing a view
  58. Constraining a view
  59. Creating a navigation history
  60. Working with extents
  61. Rotating a view
  62. Changing the map's projection
  63. Creating custom animations
  64. Summary
  65. 7. Mastering Renderers
  66. Using different renderers
  67. Creating a WebGL map
  68. Drawing lines and polygons with WebGL
  69. Blending layers
  70. Clipping layers
  71. Exporting a map
  72. Creating a raster calculator
  73. Creating a convolution matrix
  74. Clipping a layer with WebGL
  75. Summary
  76. 8. OpenLayers 3 for Mobile
  77. Responsive styling with CSS
  78. Generating geocaches
  79. Adding device-dependent controls
  80. Vectorizing the mobile version
  81. Making the mobile application interactive
  82. Summary
  83. 9. Tools of the Trade – Integrating Third-Party Applications
  84. Exporting a QGIS project
  85. Importing shapefiles
  86. Spatial analysis with Turf
  87. Spatial analysis with JSTS
  88. 3D rendering with Cesium
  89. Summary
  90. 10. Compiling Custom Builds with Closure
  91. Configuring Node JS
  92. Compiling OpenLayers 3
  93. Bundling an application with OpenLayers 3
  94. Extending OpenLayers 3
  95. Creating rich documentation with JSDoc
  96. Summary
  97. Index

Chapter 8. OpenLayers 3 for Mobile

Now that we are through with the hardest parts of this book, and you have mastered a lot of very important aspects of the library, we will discuss an entirely different concept of OpenLayers 3 in this chapter. We will create a geocaching application that can be used on handheld devices and desktop computers too. We will write this application from scratch and utilize some of the knowledge we just harnessed from the previous chapters.

For those who don't know what exactly geocaching is, let's start with a brief explanation. Geocaching is a great outdoor activity. A player needs two essential things: a device with GPS and a database of geocaches. There are plenty of little boxes hidden in Nature, marked with a point, and uploaded in a geocaching database. The game is usually played as follows: the player picks a cache on the device; if the location is found, the cache still needs to be located as it is usually well-hidden. When the player finds the box, there is usually a notebook in it, along with some trinkets. The player then can read the content of the notebook, write something into it, take some of the items, or put something in the box. Finally, the player puts the cache back to its original place and moves on.

In this chapter, we will discuss the following topics:

  • Responsive web design with OpenLayers 3
  • Using the HTML5 Geolocation API through the library
  • Creating multipurpose web mapping applications

Before getting started

As stated previously, we will write a brand new application in this chapter. However, there are some general considerations we made in an early stage of our learning. We will use these considerations and also the very simple code built with them. In this chapter, we will use the final code, produced in Chapter 2, Applying Custom Styles, called ch02_webgis, as a basis.

Basic considerations

One of the most challenging problems in responsive web design is detecting the type of the client's device. There are several effective approaches such as adjusting the style of the web page to the screen's dimensions with CSS media queries, or detecting the type of the hardware from the navigator.userAgent property in JavaScript (device detection). These methods are quite practical for a blog, news page, or shopping page, but not effective in our case.

The goal of our application is to adapt to the different capabilities of handheld and desktop computers. If we are working on a desktop computer, we will be dispatchers, able to modify the locations and the attributes of the geocaches. However, if we use a handheld device, we are geocachers and would like to have an application that can help us find those caches.

As technology rapidly develops, it is hard to separate desktop devices from handheld devices based on common attributes. For example, the dimensions of a modern handheld device's screen in pixels surpass the dimensions of an old monitor. Scanning for touch and orientation capabilities also yields false results, as nowadays some of the modern laptops also have touch screens and built-in GPS receivers. However, we do have to separate the two roles in a simple manner; thus, we make this false assumption and nominate every touch device as a receiver and every non-touch device as a dispatcher. This way, we can use feature detection to issue roles.