/*******************************************************************************
 * Copyright 2014, 2017 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 com.github.tdesjardins.ol3.demo.client.constants.DemoConstants;
import com.github.tdesjardins.ol3.demo.client.utils.DemoUtils;
import com.google.gwt.user.client.Window;

import ol.Collection;
import ol.Coordinate;
import ol.Feature;
import ol.FeatureOptions;
import ol.Map;
import ol.MapOptions;
import ol.OLFactory;
import ol.View;
import ol.control.MousePosition;
import ol.control.MousePositionOptions;
import ol.control.ScaleLine;
import ol.event.EventListener;
import ol.events.condition.Condition;
import ol.geom.Polygon;
import ol.interaction.Select;
import ol.interaction.SelectOptions;
import ol.layer.Base;
import ol.layer.LayerOptions;
import ol.layer.Tile;
import ol.layer.VectorLayerOptions;
import ol.proj.Projection;
import ol.proj.ProjectionOptions;
import ol.source.Osm;
import ol.source.Vector;
import ol.source.VectorOptions;
import ol.source.XyzOptions;

/**
 * Example for feature selection.
 *
 * @author Tino Desjardins
 */
public class SelectFeaturesExample implements Example {

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

        Coordinate centerCoordinate = new Coordinate(13.37, 52.52);
        Coordinate transformedMidPoint = Projection.transform(centerCoordinate, DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);

        // create a polygon
        Polygon polygon = DemoUtils.createTestPolygon();

        // create a feature
        FeatureOptions featureOptions = OLFactory.createOptions();
        // TODO Setter for ID seems to doesn't have an effect in feature options.
        // featureOptions.setId("g1");
        featureOptions.setGeometry(polygon);

        Feature feature = new Feature(featureOptions);
        feature.setId("g1");
        feature.set("name", "triangle");

        // create another feature via cloning
        Feature feature2 = feature.clone();
        feature2.setId("g2");
        feature2.getGeometry().rotate(180, transformedMidPoint);

        Collection<Feature> lstFeatures = new Collection<Feature>();
        lstFeatures.push(feature);
        lstFeatures.push(feature2);

        VectorOptions vectorSourceOptions = OLFactory.createOptions();
        vectorSourceOptions.setFeatures(lstFeatures);
        Vector vectorSource = new Vector(vectorSourceOptions);

        VectorLayerOptions vectorLayerOptions = OLFactory.createOptions();
        vectorLayerOptions.setSource(vectorSource);
        ol.layer.Vector vectorLayer = new ol.layer.Vector(vectorLayerOptions);

        // create an OSM-layer
        XyzOptions osmSourceOptions = OLFactory.createOptions();
        Osm osmSource = new Osm(osmSourceOptions);
        LayerOptions osmLayerOptions = OLFactory.createOptions();
        osmLayerOptions.setSource(osmSource);
        Tile osmLayer = new Tile(osmLayerOptions);

        // create a view
        View view = new View();

        view.setCenter(transformedMidPoint);
        view.setZoom(14);

        // create the map
        MapOptions mapOptions = OLFactory.createOptions();
        mapOptions.setTarget(exampleId);
        mapOptions.setView(view);
        Collection<Base> lstLayer = new Collection<Base>();
        lstLayer.push(osmLayer);
        lstLayer.push(vectorLayer);
        mapOptions.setLayers(lstLayer);
        Map map = new Map(mapOptions);

        // add some controls
        map.addControl(new ScaleLine());

        MousePositionOptions mousePositionOptions = OLFactory.createOptions();
        ProjectionOptions projectionOptions = OLFactory.createOptions();
        projectionOptions.setCode(DemoConstants.EPSG_4326);
        mousePositionOptions.setProjection(new Projection(projectionOptions));

        MousePosition mousePosition = new MousePosition(mousePositionOptions);
        mousePosition.setCoordinateFormat(Coordinate.createStringXY(5));
        map.addControl(mousePosition);

        SelectOptions selectOptions = new SelectOptions();
        selectOptions.setCondition(Condition.getClick());

        // create a select interaction
        final Select selectFeature = new Select(selectOptions);
        map.addInteraction(selectFeature);

        EventListener<Select.Event> selectListener = new EventListener<Select.Event>() {

            @Override
            public void onEvent(Select.Event event) {

                Collection<Feature> selectedFeatures = selectFeature.getFeatures();

                if (selectedFeatures.getLength() > 0) {
                    Feature feature = selectedFeatures.item(0);
                    String output = "You selected feature with id '" + feature.getId() + "'"
                            + " and name '" + feature.get("name") + "'"
                            + " and geometry name '" + feature.getGeometryName() + "'"
                            + ".";
                    Window.alert(output);
                }

            }

        };

        selectFeature.on("select", selectListener);

    }

}

@@ -96,17 +96,17 @@
 014, 201
-7
+8
  gwt-ol3
@@ -1259,39 +1259,8 @@
 ne;%0A
-import ol.event.EventListener;%0A
 impo
@@ -4977,163 +4977,45 @@
     
-EventListener%3CSelect.Event%3E selectListener = new EventListener%3CSelect.Event%3E() %7B%0A%0A            @Override%0A            public void onEvent(Select.Event 
+selectFeature.on(%22select%22, (
 event)
+ -%3E
  %7B%0A%0A
@@ -5022,28 +5022,24 @@
             
-  
-  
 Collection%3CF
@@ -5107,20 +5107,16 @@
         
-    
 if (sele
@@ -5159,36 +5159,32 @@
             
-    
 Feature 
 feature = se
@@ -5163,33 +5163,41 @@
         Feature 
-f
+selectedF
 eature = selecte
@@ -5215,20 +5215,16 @@
 tem(0);%0A
-    
         
@@ -5278,25 +5278,33 @@
 ith id '%22 + 
-f
+selectedF
 eature.getId
@@ -5328,36 +5328,32 @@
                 
-  
-  
 + %22 and name '%22 
@@ -5346,33 +5346,41 @@
 %22 and name '%22 + 
-f
+selectedF
 eature.get(%22name
@@ -5380,36 +5380,32 @@
 t(%22name%22) + %22'%22%0A
-    
                 
@@ -5439,17 +5439,25 @@
 me '%22 + 
-f
+selectedF
 eature.g
@@ -5507,23 +5507,15 @@
     
-    
 + %22.%22;%0A
-    
     
@@ -5552,27 +5552,8 @@
 t);%0A
-                %7D%0A%0A
     
@@ -5576,60 +5576,8 @@
    %7D
-;%0A%0A        selectFeature.on(%22select%22, selectListener
 );%0A%0A

Use lamdas