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:
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.
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.