Let's download the OpenLayers library. After you're done, you should have the OpenLayers library files set up on your computer. Perform the following steps:
v3.0.0.zip version of the OpenLayers v3.0.0. It's the green button on the bottom left of the Github release page for v3.0.0.v3.0.0 (or whatever your version is).v3.0.0 folder. Once inside, you'll see a lot of folders, but the ones we are concerned with right now are the folders named build and css, as seen in the following screenshot:
ol3 folder within an assets folder contained within a new folder ol3_samples in your home directory (or C:\ on Windows). Copy the previous build folder from v3.0.0 and rename it as js into the new ol3 directory and also copy the css folder into the same ol3 folder.sandbox into the ol3_samples directory. You can name the folder whatever you like, but we'll refer to it as the sandbox folder. Your new folder structure should look similar to the following screenshot:
We just installed OpenLayers 3 by copying over different pre-built, compressed JavaScript files containing the entire OpenLayers 3 library code (from the build directory) and the associated assets (style sheets). To use OpenLayers, you'll need at a minimum, the ol.js file (the other .js files will be needed during the book but are not always required) and the ol.css file. For best practice, we already gave you some tips to structure the code like separate assets, such as css and js, or separate library code from your own code.
If you open the ol.js file, you'll notice it is nearly unreadable. This is because this is a minified and obfuscated version, which basically means extra white space and unnecessary characters have been stripped out to cut down on the file size and some variables have been shortened whenever possible. While it is no longer readable, it is a bit smaller and thus requires less time to download. If you want to look at the uncompressed source code, you can view it by looking in the ol-debug.js file within the js folder of the ol3 directory.
You can, as we'll see in the last chapter of this book, build your own custom configurations of the library, including only the things you need. But for now, we'll just use the entire library. Now that we have our OpenLayers library files ready to use, let's make use of them!
The process for creating a map with OpenLayers requires, at a minimum, the following things:
ol.layer.* classol.Map class by adding a layerol.View class to set for the Map class (defining the area where the map will initially be displayed)Now, we're finally ready to create our first map!