The rise in popularity of mobile devices—smart phones and tablets—has changed the landscape of web development. Now, users expect our websites and applications to work on their mobile devices' smaller screens, respond to touchscreen interfaces and know where they are via integrated GPS. OpenLayers 3 provides some great features targeting mobile platforms, and we will highlight those in this chapter. But, developing mobile-friendly web applications has its challenges too, so we'll look at how to debug web applications on mobile devices and at some strategies to use when mobile devices lose their network connections.
In this chapter, we will cover the following topics:
One of the biggest differences between desktop and mobile web applications is how we interact with an application. On a desktop or laptop computer, we have a keyboard and a mouse or trackpad, and we point and click or click and drag things. On mobile devices though, there is no keyboard and no mouse pointer. Instead, we use our fingers, and we do things like touch, drag, and tap. We can also do more complicated things, such as pinching two fingers together or rotating two fingers, and we usually expect this to do something in an application. In mapping applications on touch devices, for instance, we might expect that dragging a finger will pan the map and pinching two fingers will zoom in or out.
OpenLayers provides touch support for us in the form of interactions—recall that we talked about interactions in Chapter 8, Interacting with Your Map. The touch-specific interactions are as follows:
ol.interaction.DragPan: This pans the map in response to one or more fingers being dragged across the screenol.interaction.PinchRotate: This rotates the map in response to two fingers twisting in a circular motion on the screenol.interaction.PinchZoom: This zooms the map in or out in response to two fingers pinching in or out on the screenThese interactions are created by default and enabled on devices that support touch events. Let's see them in action!