Search in sources :

Example 11 with View

use of ol.View in project gwt-ol3 by TDesjardins.

the class AnimationExample method show.

/* (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 an OSM-layer
    XyzOptions osmSourceOptions = new XyzOptions();
    Osm osmSource = new Osm(osmSourceOptions);
    LayerOptions osmLayerOptions = new LayerOptions();
    osmLayerOptions.setSource(osmSource);
    Tile osmLayer = new Tile(osmLayerOptions);
    // create a view
    View view = new View();
    view.setCenter(transformedMidPoint);
    view.setZoom(16);
    // create the map
    MapOptions mapOptions = new MapOptions();
    mapOptions.setLoadTilesWhileAnimating(true);
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Collection<Base> lstLayer = new Collection<Base>();
    lstLayer.push(osmLayer);
    mapOptions.setLayers(lstLayer);
    Map map = new Map(mapOptions);
    // add some controls
    map.addControl(new ScaleLine());
    MousePositionOptions mousePositionOptions = new MousePositionOptions();
    ProjectionOptions projectionOptions = new ProjectionOptions();
    projectionOptions.setCode(DemoConstants.EPSG_4326);
    mousePositionOptions.setProjection(new Projection(projectionOptions));
    MousePosition mousePosition = new MousePosition(mousePositionOptions);
    mousePosition.setCoordinateFormat(Coordinate.createStringXY(5));
    map.addControl(mousePosition);
    Coordinate tvTowerCoordinate = Projection.transform(new Coordinate(13.409, 52.52), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
    Coordinate pplaceCoordinate = Projection.transform(new Coordinate(13.377, 52.509), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
    Coordinate zooCoordinate = Projection.transform(new Coordinate(13.338, 52.508), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
    final List<Coordinate> coordinates = Arrays.asList(transformedMidPoint, tvTowerCoordinate, pplaceCoordinate, zooCoordinate);
    Scheduler.get().scheduleFixedPeriod(() -> {
        int index = getNextIndex(coordinates.size());
        AnimationOptions panAnimationOptions = new AnimationOptions();
        panAnimationOptions.setDuration(2000);
        // Switch this to rotate the animation while animating.
        // panAnimationOptions.setRotation(view.getRotation() + 2 * Math.PI);
        panAnimationOptions.setCenter(coordinates.get(index));
        view.animate(panAnimationOptions);
        AnimationOptions zoomOutAnimationOptions = new AnimationOptions();
        zoomOutAnimationOptions.setDuration(1000);
        zoomOutAnimationOptions.setResolution(view.getResolution() + 4);
        AnimationOptions zoomInAnimationOptions = new AnimationOptions();
        zoomInAnimationOptions.setDuration(1000);
        zoomInAnimationOptions.setResolution(view.getResolution());
        view.animate(zoomOutAnimationOptions, zoomInAnimationOptions);
        return true;
    }, 6000);
}
Also used : XyzOptions(ol.source.XyzOptions) ScaleLine(ol.control.ScaleLine) MapOptions(ol.MapOptions) MousePositionOptions(ol.control.MousePositionOptions) Osm(ol.source.Osm) Tile(ol.layer.Tile) Projection(ol.proj.Projection) LayerOptions(ol.layer.LayerOptions) View(ol.View) Base(ol.layer.Base) MousePosition(ol.control.MousePosition) Coordinate(ol.Coordinate) AnimationOptions(ol.animation.AnimationOptions) Collection(ol.Collection) ProjectionOptions(ol.proj.ProjectionOptions) Map(ol.Map)

Example 12 with View

use of ol.View in project gwt-ol3 by TDesjardins.

the class ViewTest method testView.

public void testView() {
    injectUrlAndTest(() -> {
        View view = getTestView();
        assertNotNull(view);
        assertTrue(view instanceof Object);
    });
}
Also used : View(ol.View)

Example 13 with View

use of ol.View in project gwt-ol3 by TDesjardins.

the class ViewTest method testViewEvents.

public void testViewEvents() {
    injectUrlAndTest(() -> {
        View view = getTestView();
        view.addCenterChangeListener(new EventListener<Object.Event>() {

            @Override
            public void onEvent(Event event) {
                centerChanged = true;
            }
        });
        view.addResolutionChangeListener(new EventListener<Object.Event>() {

            @Override
            public void onEvent(Event event) {
                resolutionChanged = true;
            }
        });
        view.addRotationChangeListener(new EventListener<Object.Event>() {

            @Override
            public void onEvent(Event event) {
                rotationChanged = true;
            }
        });
        assertFalse(this.centerChanged);
        assertFalse(this.resolutionChanged);
        assertFalse(this.rotationChanged);
        view.setCenter(new Coordinate(660000, 190001));
        assertTrue(this.centerChanged);
        assertFalse(this.resolutionChanged);
        assertFalse(this.rotationChanged);
        view.setZoom(8);
        assertTrue(this.resolutionChanged);
        assertFalse(this.rotationChanged);
        view.setRotation(Math.PI);
        assertTrue(this.rotationChanged);
    });
}
Also used : Event(ol.Object.Event) View(ol.View)

Example 14 with View

use of ol.View in project gwt-ol3 by TDesjardins.

the class ViewTest method getTestView.

private View getTestView() {
    ProjectionOptions projectionOptions = new ProjectionOptions();
    projectionOptions.setCode("EPSG:21781");
    projectionOptions.setUnits("m");
    assertNotNull(projectionOptions);
    Projection projection = new Projection(projectionOptions);
    assertNotNull(projection);
    ViewOptions viewOptions = new ViewOptions();
    viewOptions.setProjection(projection);
    View view = new View(viewOptions);
    Coordinate centerCoordinate = new Coordinate(660000, 190000);
    view.setCenter(centerCoordinate);
    view.setZoom(9);
    return view;
}
Also used : ViewOptions(ol.ViewOptions) Projection(ol.proj.Projection) ProjectionOptions(ol.proj.ProjectionOptions) View(ol.View)

Example 15 with View

use of ol.View in project gwt-ol3 by TDesjardins.

the class MapTest method testMapCreation.

public void testMapCreation() {
    injectUrlAndTest(() -> {
        ProjectionOptions projectionOptions = new ProjectionOptions();
        projectionOptions.setCode("EPSG:21781");
        projectionOptions.setUnits("m");
        Projection projection = new Projection(projectionOptions);
        ViewOptions viewOptions = new ViewOptions();
        viewOptions.setProjection(projection);
        View view = new View(viewOptions);
        Coordinate centerCoordinate = new Coordinate(660000, 190000);
        view.setCenter(centerCoordinate);
        view.setZoom(9);
        final MapOptions mapOptions = new MapOptions();
        mapOptions.setTarget("map");
        mapOptions.setView(view);
        mapOptions.setLoadTilesWhileAnimating(true);
        mapOptions.setLoadTilesWhileInteracting(true);
        Map map = new Map(mapOptions);
        assertNotNull(map);
    });
}
Also used : MapOptions(ol.MapOptions) ViewOptions(ol.ViewOptions) Projection(ol.proj.Projection) ProjectionOptions(ol.proj.ProjectionOptions) View(ol.View)

Aggregations

View (ol.View)28 MapOptions (ol.MapOptions)25 Coordinate (ol.Coordinate)24 Map (ol.Map)24 LayerOptions (ol.layer.LayerOptions)21 Tile (ol.layer.Tile)18 XyzOptions (ol.source.XyzOptions)15 ScaleLine (ol.control.ScaleLine)14 KeyboardPan (ol.interaction.KeyboardPan)13 KeyboardZoom (ol.interaction.KeyboardZoom)13 Osm (ol.source.Osm)13 Rotate (ol.control.Rotate)9 Collection (ol.Collection)8 Base (ol.layer.Base)8 Projection (ol.proj.Projection)8 ViewOptions (ol.ViewOptions)7 MousePosition (ol.control.MousePosition)7 Attribution (ol.control.Attribution)6 VectorLayerOptions (ol.layer.VectorLayerOptions)6 Image (ol.layer.Image)5