/*******************************************************************************
 * Copyright 2014, 2016 gwt-ol3
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.github.tdesjardins.ol3.demo.client.example;

import ol.Coordinate;
import ol.Map;
import ol.MapOptions;
import ol.OLFactory;
import ol.View;
import ol.control.Attribution;
import ol.event.MeasureEvent;
import ol.event.MeasureListener;
import ol.gwt.Measure;

import com.github.tdesjardins.ol3.demo.client.utils.DemoUtils;
import com.google.gwt.core.client.GWT;

import ol.layer.Tile;
import ol.proj.Projection;
import ol.source.Osm;
import ol.source.XyzOptions;
import ol.layer.LayerOptions;

/**
 * Example measuring on an OSM layer.
 *
 * @author Tino Desjardins
 *
 */
public class MeasureExample implements Example {

    /* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
    @Override
    public void show(String exampleId) {

        // create a OSM-layer
        XyzOptions osmSourceOptions = OLFactory.createOptions();

        Osm osmSource = OLFactory.createOsm(osmSourceOptions);
        LayerOptions osmLayerOptions = OLFactory.createOptions();
        osmLayerOptions.setSource(osmSource);

        Tile osmLayer = OLFactory.createTileLayer(osmLayerOptions);

        // create a view
        View view = OLFactory.createView();

        Coordinate centerCoordinate = OLFactory.createCoordinate(-0.1275, 51.507222);
        Coordinate transformedCenterCoordinate = Projection.transform(centerCoordinate, "EPSG:4326", "EPSG:3857");

        view.setCenter(transformedCenterCoordinate);
        view.setZoom(10);

        // create the map
        MapOptions mapOptions = OLFactory.createOptions();
        mapOptions.setTarget(exampleId);
        mapOptions.setView(view);

        Map map = OLFactory.createMap(mapOptions);

        map.addLayer(osmLayer);

        // add some controls
        map.addControl(OLFactory.createScaleLine());
        DemoUtils.addDefaultControls(map.getControls());

        Attribution attribution = OLFactory.createAttributionControl();
        attribution.setCollapsed(true);

        map.addControl(attribution);

        // add some interactions
        map.addInteraction(OLFactory.createKeyboardPan());
        map.addInteraction(OLFactory.createKeyboardZoom());

		// add measurement functionality to the map
		final Measure measure = new Measure(map);
		// start measuring immediately
		measure.startMeasureLength(new MeasureListener() {

			@Override
			public void onMeasure(MeasureEvent evt) {
				// log the measured length
				GWT.log("measure: " + evt.getMeasure());
			}

		}, true, true);

    }

}


@@ -96,17 +96,17 @@
 014, 201
-6
+7
  gwt-ol3
@@ -925,24 +925,53 @@
 ttribution;%0A
+import ol.control.ScaleLine;%0A
 import ol.ev
@@ -1043,16 +1043,87 @@
 Measure;
+%0Aimport ol.interaction.KeyboardPan;%0Aimport ol.interaction.KeyboardZoom;
 %0A%0Aimport
@@ -1749,32 +1749,20 @@
 ource = 
-OLFactory.create
+new 
 Osm(osmS
@@ -1917,33 +1917,16 @@
 r = 
-OLFactory.createTileLayer
+new Tile
 (osm
@@ -2049,32 +2049,20 @@
 inate = 
-OLFactory.create
+new 
 Coordina
@@ -2460,32 +2460,20 @@
 p map = 
-OLFactory.create
+new 
 Map(mapO
@@ -2567,32 +2567,20 @@
 Control(
-OLFactory.create
+new 
 ScaleLin
@@ -2677,32 +2677,20 @@
 ution = 
-OLFactory.create
+new 
 Attribut
@@ -2692,23 +2692,16 @@
 ribution
-Control
 ();%0A    
@@ -2835,32 +2835,20 @@
 raction(
-OLFactory.create
+new 
 Keyboard
@@ -2882,32 +2882,20 @@
 raction(
-OLFactory.create
+new 
 Keyboard
@@ -2904,18 +2904,24 @@
 om());%0A%0A
-%09%09
+        
 // add m
@@ -2956,18 +2956,24 @@
 the map%0A
-%09%09
+        
 final Me
@@ -3006,18 +3006,24 @@
 e(map);%0A
-%09%09
+        
 // start
@@ -3045,18 +3045,24 @@
 diately%0A
-%09%09
+        
 measure.
@@ -3109,24 +3109,42 @@
  %7B%0A%0A
-%09%09%09@Override%0A%09%09%09
+            @Override%0A            
 publ
@@ -3181,20 +3181,32 @@
  evt) %7B%0A
-%09%09%09%09
+                
 // log t
@@ -3228,12 +3228,24 @@
 gth%0A
-%09%09%09%09
+                
 GWT.
@@ -3285,16 +3285,31 @@
 ));%0A
-%09%09%09%7D%0A%0A%09%09
+            %7D%0A%0A        
 %7D, t

Refactor MeasureExample