In the last few chapters, we gained a firm grip on using and customizing the most essential parts of OpenLayers 3. In this chapter, we will take a further step in creating a great application by focusing on user experience. A good web mapping or WebGIS application has a lot of convenient GUI options to modify the view. In some cases, your users will be more than happy if they are able to go through the view history with some button clicks, or if they can change the map's rotation, projection, or just zoom in to the selected feature. We will also learn how animations work and ways in which they can utilized in order to create our own special camera effects. We'll take a look at these topics in this chapter:
For this chapter, we will need exactly one-third of a party library: PROJ4JS. It is included in the code appendix, located at js/proj4js-2.3.10/proj4.js. We will see how this library is not really a third-party application with regard to OpenLayers 3, but rather an optional extension.
Furthermore, we have to modify our base layer as OpenStreetMap only supports Web Mercator, but we need a layer that comes in multiple projections. For this purpose, we utilize Natural Earth's 50m Land layer provided by Boundless's demo GeoServer.
First, let's make the necessary changes in our init function:
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'http://demo.opengeo.org/geoserver/wms',
params: {
layers: 'ne_50m_land',
format: 'image/png'
}
}),
name: 'Natural Earth Land'
}),
[…]
};As we've focused enough on interactions and controls in the previous chapters, we would rather focus on controlling the view in this one. We will create some tools and add them to the toolbar, but we will not build further structures to support our example project. In this chapter, we will take the final step in creating a WebGIS application by filling out the remaining gaps and consider it to then be complete.