In the previous examples, we worked hard to reduce the size of the library by cutting out some irrelevant parts. Now, let's do the contrary and extend the library with additional functionality. Remember the example where we measured distance on an ellipsoid? We used the debug library of an older OpenLayers 3 version to achieve this. Now, we will build the ol.Ellipsoid class in our next custom build. You can find a JavaScript file, named ellipsoid.js, in the examples folder and an example named ch10_test_ellispsoid. The latter is the exact copy of ch05_measure with ch05_measure_vincenty.js. First, open up ellipsoid.js. This is how a well-structured code looks from the aspect of the Closure Compiler. There are headers everywhere with type definitions and additional information. These headers are written in the syntax of JSDoc, but JSDoc and Closure Compiler go hand in hand.
The first part of the code resolves the dependencies of this constructor and provides a name for it:
goog.provide('ol.Ellipsoid');
goog.require('goog.math');
goog.require('ol.Coordinate');Then, the constructor is defined with every parameter and method. The important part is the header. It is clearly defined. Closure has to deal with a constructor that has two input parameters:
/**
* @constructor
* @param {number} a Major radius.
* @param {number} flattening Flattening.
*/However, as there is nothing else specified, this constructor won't get exported unless we modify this header. The standard Closure way to do this is by declaring the symbol as exportable and setting the generate_exports compiler parameter to true. However, this won't work with the library. As the exportable symbols are preprocessed with the custom build tools, we have to use an OpenLayers 3-only tag: api. Let's extend the header with the new tag:
/**
* @constructor
* @param {number} a Major radius.
* @param {number} flattening Flattening.
* @api
*/We are not yet done with the code. As we would like to expose the ellipsoid object's vincentyDistance method, we have to make it exportable, too:
/**
* Returns the distance from c1 to c2 using Vincenty.
*
* @param {ol.Coordinate} c1 Coordinate 1.
* @param {ol.Coordinate} c2 Coordinate 1.
* @param {number=} opt_minDeltaLambda Minimum delta lambda for convergence.
* @param {number=} opt_maxIterations Maximum iterations.
* @return {number} Vincenty distance.
* @api
*/Next, we create a plugins folder inside the source code directory's src folder. We copy the modified ellipsoid.js to this folder. We're almost there. The only thing left to do is remove the info.json file from the build folder. This file is generated by the build tool if it does not exist. If it is there, the tool simply parses the exportable symbols from it and builds the library accordingly. However, as we try to extend the library, the symbols in that file will not correspond with the truly exportable symbols. As a result, if we extend a library and compile it without removing the file, the new symbols won't be exported. If we remove something from the source code and compile it without removing the file, the Closure Compiler will throw an error:

Now that everything is in place, we can run the compiler with the default configuration file. We run the compiler with the following command:
node tasks/build.js config/ol.json ol_ellipsoid.js
If you copy the resulting library in the examples' folder and link it in ch10_test_ellipsoid.html in the place of the original OpenLayers 3 library, you will see that ol.Ellipsoid is now exposed:
