Search in sources :

Example 6 with ViewOptions

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

the class ConstrainedViewExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    XyzOptions xyzOptions = OLFactory.createOptions();
    xyzOptions.setUrl("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}");
    xyzOptions.setAttributions("Tiles &copy; <a href=\"http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer\">ArcGIS</a>");
    Xyz xyzSource = new Xyz(xyzOptions);
    LayerOptions xyzLayerOptions = OLFactory.createOptions();
    xyzLayerOptions.setSource(xyzSource);
    Tile xyzLayer = new Tile(xyzLayerOptions);
    // create a view
    View view = new View();
    Coordinate centerCoordinate = new Coordinate(-121.1, 47.5);
    Coordinate transformedCenterCoordinate = Projection.transform(centerCoordinate, "EPSG:4326", "EPSG:3857");
    view.setCenter(transformedCenterCoordinate);
    view.setZoom(12);
    // restrict zoom
    view.setMinZoom(11);
    view.setMaxZoom(14);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    // restrict extent
    ViewOptions viewOptions = new ViewOptions();
    viewOptions.setCenter(map.getView().getCenter());
    viewOptions.setExtent(map.getView().calculateExtent(map.getSize()));
    viewOptions.setZoom(map.getView().getZoom());
    viewOptions.setMinZoom(map.getView().getMinZoom());
    viewOptions.setMaxZoom(map.getView().getMaxZoom());
    View restrictedView = new View(viewOptions);
    map.setView(restrictedView);
    ol.control.Attribution attributionControl = new ol.control.Attribution();
    attributionControl.setCollapsed(false);
    map.addControl(attributionControl);
    MousePosition mousePosition = new MousePosition();
    mousePosition.setCoordinateFormat(Coordinate.createStringXY(2));
    map.addControl(mousePosition);
    map.addLayer(xyzLayer);
}
Also used : XyzOptions(ol.source.XyzOptions) MapOptions(ol.MapOptions) ViewOptions(ol.ViewOptions) Tile(ol.layer.Tile) LayerOptions(ol.layer.LayerOptions) View(ol.View) MousePosition(ol.control.MousePosition) Coordinate(ol.Coordinate) Xyz(ol.source.Xyz) Map(ol.Map)

Example 7 with ViewOptions

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

the class StaticImageExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    ProjectionOptions projectionOptions = OLFactory.createOptions();
    Extent imageExtent = new Extent(0, 0, 1024, 968);
    projectionOptions.setCode("pixel");
    projectionOptions.setExtent(imageExtent);
    projectionOptions.setUnits("pixels");
    Projection projection = new Projection(projectionOptions);
    ImageStaticOptions imageStaticOptions = OLFactory.createOptions();
    imageStaticOptions.setUrl("http://imgs.xkcd.com/comics/online_communities.png");
    imageStaticOptions.setImageSize(new Size(1024, 968));
    imageStaticOptions.setImageExtent(imageExtent);
    imageStaticOptions.setProjection(projection);
    // create attribution
    imageStaticOptions.setAttributions("&copy; <a href=\"http://xkcd.com/license.html\">xkcd</a>");
    ImageStatic imageStatic = new ImageStatic(imageStaticOptions);
    LayerOptions layerOptions = OLFactory.createOptions();
    layerOptions.setSource(imageStatic);
    Image image = new Image(layerOptions);
    Collection<Base> layers = new Collection<Base>();
    layers.push(image);
    ViewOptions viewOptions = OLFactory.createOptions();
    viewOptions.setCenter(new Coordinate(500, 500));
    viewOptions.setProjection(projection);
    viewOptions.setZoom(2);
    View view = new View(viewOptions);
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    mapOptions.setLayers(layers);
    Map map = new Map(mapOptions);
    // add some controls
    DemoUtils.addDefaultControls(map.getControls());
    ol.control.Attribution attributionControl = new ol.control.Attribution();
    attributionControl.setCollapsed(false);
    map.addControl(attributionControl);
}
Also used : ImageStatic(ol.source.ImageStatic) Extent(ol.Extent) MapOptions(ol.MapOptions) Size(ol.Size) ViewOptions(ol.ViewOptions) Projection(ol.proj.Projection) Image(ol.layer.Image) LayerOptions(ol.layer.LayerOptions) View(ol.View) Base(ol.layer.Base) Coordinate(ol.Coordinate) Collection(ol.Collection) ProjectionOptions(ol.proj.ProjectionOptions) ImageStaticOptions(ol.source.ImageStaticOptions) Map(ol.Map)

Aggregations

View (ol.View)7 ViewOptions (ol.ViewOptions)7 MapOptions (ol.MapOptions)6 Projection (ol.proj.Projection)6 Coordinate (ol.Coordinate)5 Map (ol.Map)5 LayerOptions (ol.layer.LayerOptions)5 ProjectionOptions (ol.proj.ProjectionOptions)4 Rotate (ol.control.Rotate)3 ScaleLine (ol.control.ScaleLine)3 KeyboardPan (ol.interaction.KeyboardPan)3 KeyboardZoom (ol.interaction.KeyboardZoom)3 Image (ol.layer.Image)3 Collection (ol.Collection)2 Extent (ol.Extent)2 Base (ol.layer.Base)2 Tile (ol.layer.Tile)2 XyzOptions (ol.source.XyzOptions)2 Size (ol.Size)1 MousePosition (ol.control.MousePosition)1