Search in sources :

Example 1 with XyzOptions

use of ol.source.XyzOptions in project gwt-ol3 by TDesjardins.

the class GeoJsonExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show() */
@Override
public void show(String exampleId) {
    // create linestring
    Coordinate coordinate1 = new Coordinate(4e6, 2e6);
    Coordinate coordinate2 = new Coordinate(8e6, -2e6);
    Coordinate[] coordinates = { coordinate1, coordinate2 };
    LineString lineString = new LineString(coordinates);
    // create feature
    FeatureOptions featureOptions = new FeatureOptions();
    featureOptions.setGeometry(lineString);
    Feature feature = new Feature(featureOptions);
    // convert feature to GeoJSON
    GeoJson geoJsonFormat = new GeoJson();
    java.lang.Object geoJson = geoJsonFormat.writeFeatureObject(feature, null);
    // convert features from GeoJSON
    Feature featureGeoJson = geoJsonFormat.readFeature(geoJson, null);
    // show converted features
    Collection<Feature> lstFeatures = new Collection<Feature>();
    lstFeatures.push(featureGeoJson);
    VectorOptions vectorSourceOptions = new VectorOptions();
    vectorSourceOptions.setFeatures(lstFeatures);
    Vector vectorSource = new Vector(vectorSourceOptions);
    VectorLayerOptions vectorLayerOptions = new VectorLayerOptions();
    vectorLayerOptions.setSource(vectorSource);
    ol.layer.Vector vectorLayer = new ol.layer.Vector(vectorLayerOptions);
    // create a 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();
    Coordinate centerCoordinate = new Coordinate(0, 0);
    view.setCenter(centerCoordinate);
    view.setZoom(2);
    // create the map
    MapOptions mapOptions = new MapOptions();
    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());
    DemoUtils.addDefaultControls(map.getControls());
    // add some interactions
    map.addInteraction(new KeyboardPan());
    map.addInteraction(new KeyboardZoom());
    map.addControl(new Rotate());
}
Also used : XyzOptions(ol.source.XyzOptions) ScaleLine(ol.control.ScaleLine) KeyboardPan(ol.interaction.KeyboardPan) Rotate(ol.control.Rotate) MapOptions(ol.MapOptions) GeoJson(ol.format.GeoJson) Feature(ol.Feature) LayerOptions(ol.layer.LayerOptions) VectorLayerOptions(ol.layer.VectorLayerOptions) FeatureOptions(ol.FeatureOptions) Vector(ol.source.Vector) Osm(ol.source.Osm) Tile(ol.layer.Tile) View(ol.View) Base(ol.layer.Base) VectorLayerOptions(ol.layer.VectorLayerOptions) Coordinate(ol.Coordinate) LineString(ol.geom.LineString) KeyboardZoom(ol.interaction.KeyboardZoom) Collection(ol.Collection) Map(ol.Map) VectorOptions(ol.source.VectorOptions)

Example 2 with XyzOptions

use of ol.source.XyzOptions in project gwt-ol3 by TDesjardins.

the class GraticuleExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    // 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();
    Coordinate centerCoordinate = new Coordinate(1490463, 6894388);
    view.setCenter(centerCoordinate);
    view.setZoom(10);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    map.addLayer(osmLayer);
    // add some controls
    map.addControl(new ZoomSlider());
    MousePosition mousePosition = new MousePosition();
    mousePosition.setCoordinateFormat(Coordinate.createStringXY(2));
    map.addControl(mousePosition);
    map.addControl(new ZoomToExtent());
    OverviewMap overviewMap = new OverviewMap();
    map.addControl(overviewMap);
    Graticule graticule = new Graticule();
    graticule.setMap(map);
}
Also used : XyzOptions(ol.source.XyzOptions) MapOptions(ol.MapOptions) OverviewMap(ol.control.OverviewMap) ZoomToExtent(ol.control.ZoomToExtent) Osm(ol.source.Osm) Tile(ol.layer.Tile) LayerOptions(ol.layer.LayerOptions) View(ol.View) MousePosition(ol.control.MousePosition) Graticule(ol.Graticule) Coordinate(ol.Coordinate) ZoomSlider(ol.control.ZoomSlider) OverviewMap(ol.control.OverviewMap) Map(ol.Map)

Example 3 with XyzOptions

use of ol.source.XyzOptions in project gwt-ol3 by TDesjardins.

the class MarkerExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show() */
@Override
public void show(String exampleId) {
    // create a point
    Coordinate coordinate1 = OLFactory.createCoordinate(4e6, 2e6);
    Point point1 = new Point(coordinate1);
    // create feature
    FeatureOptions featureOptions = OLFactory.createOptions();
    featureOptions.setGeometry(point1);
    Feature feature = new Feature(featureOptions);
    Collection<Feature> features = new Collection<Feature>();
    features.push(feature);
    // create source
    VectorOptions vectorSourceOptions = OLFactory.createOptions();
    vectorSourceOptions.setFeatures(features);
    Vector vectorSource = new Vector(vectorSourceOptions);
    // create style
    StyleOptions styleOptions = new StyleOptions();
    IconOptions iconOptions = new IconOptions();
    iconOptions.setSrc("https://openlayers.org/en/v3.20.1/examples/data/icon.png");
    Icon icon = new Icon(iconOptions);
    styleOptions.setImage(icon);
    Style style = new Style(styleOptions);
    VectorLayerOptions vectorLayerOptions = OLFactory.createOptions();
    vectorLayerOptions.setSource(vectorSource);
    vectorLayerOptions.setStyle(style);
    ol.layer.Vector vectorLayer = new ol.layer.Vector(vectorLayerOptions);
    // create a 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();
    Coordinate centerCoordinate = OLFactory.createCoordinate(0, 0);
    view.setCenter(centerCoordinate);
    view.setZoom(2);
    // create the map
    MapOptions mapOptions = new MapOptions();
    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());
    DemoUtils.addDefaultControls(map.getControls());
    // add some interactions
    map.addInteraction(new KeyboardPan());
    map.addInteraction(new KeyboardZoom());
    map.addControl(new Rotate());
}
Also used : XyzOptions(ol.source.XyzOptions) ScaleLine(ol.control.ScaleLine) KeyboardPan(ol.interaction.KeyboardPan) Rotate(ol.control.Rotate) MapOptions(ol.MapOptions) Feature(ol.Feature) LayerOptions(ol.layer.LayerOptions) VectorLayerOptions(ol.layer.VectorLayerOptions) FeatureOptions(ol.FeatureOptions) IconOptions(ol.style.IconOptions) Style(ol.style.Style) Vector(ol.source.Vector) Osm(ol.source.Osm) StyleOptions(ol.style.StyleOptions) Tile(ol.layer.Tile) Point(ol.geom.Point) View(ol.View) Base(ol.layer.Base) VectorLayerOptions(ol.layer.VectorLayerOptions) Coordinate(ol.Coordinate) KeyboardZoom(ol.interaction.KeyboardZoom) Collection(ol.Collection) Icon(ol.style.Icon) Map(ol.Map) VectorOptions(ol.source.VectorOptions)

Example 4 with XyzOptions

use of ol.source.XyzOptions in project gwt-ol3 by TDesjardins.

the class RasterExample method show.

/*
     * (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    XyzOptions osmSourceOptions = OLFactory.createOptions();
    osmSourceOptions.setCrossOrigin("Anonymous");
    Osm osmSource = new Osm(osmSourceOptions);
    LayerOptions osmLayerOptions = OLFactory.createOptions();
    osmLayerOptions.setSource(osmSource);
    // create OSM layer only for background and attribution
    Tile osmLayer = new Tile(osmLayerOptions);
    // create raster source
    Raster raster = getRasterSource(osmSource, RasterOperationType.PIXEL);
    LayerOptions layerOptions = OLFactory.createOptions();
    layerOptions.setSource(raster);
    Image image = new Image(layerOptions);
    Collection<Base> layers = new Collection<>();
    layers.push(osmLayer);
    layers.push(image);
    View view = new View();
    Coordinate centerCoordinate = new Coordinate(-0.1275, 51.507222);
    Coordinate transformedCenterCoordinate = Projection.transform(centerCoordinate, DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
    view.setCenter(transformedCenterCoordinate);
    view.setZoom(10);
    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());
}
Also used : XyzOptions(ol.source.XyzOptions) MapOptions(ol.MapOptions) Raster(ol.source.Raster) Osm(ol.source.Osm) Tile(ol.layer.Tile) Image(ol.layer.Image) LayerOptions(ol.layer.LayerOptions) View(ol.View) Base(ol.layer.Base) Coordinate(ol.Coordinate) Collection(ol.Collection) Map(ol.Map)

Example 5 with XyzOptions

use of ol.source.XyzOptions in project gwt-ol3 by TDesjardins.

the class SelectFeaturesExample 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 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);
    selectFeature.on("select", (event) -> {
        Collection<Feature> selectedFeatures = selectFeature.getFeatures();
        if (selectedFeatures.getLength() > 0) {
            Feature selectedFeature = selectedFeatures.item(0);
            String output = "You selected feature with id '" + selectedFeature.getId() + "'" + " and name '" + selectedFeature.get("name") + "'" + " and geometry name '" + selectedFeature.getGeometryName() + "'" + ".";
            Window.alert(output);
        }
    });
}
Also used : XyzOptions(ol.source.XyzOptions) ScaleLine(ol.control.ScaleLine) MapOptions(ol.MapOptions) MousePositionOptions(ol.control.MousePositionOptions) Projection(ol.proj.Projection) Feature(ol.Feature) LayerOptions(ol.layer.LayerOptions) VectorLayerOptions(ol.layer.VectorLayerOptions) FeatureOptions(ol.FeatureOptions) MousePosition(ol.control.MousePosition) Polygon(ol.geom.Polygon) Vector(ol.source.Vector) SelectOptions(ol.interaction.SelectOptions) Osm(ol.source.Osm) Tile(ol.layer.Tile) View(ol.View) Base(ol.layer.Base) VectorLayerOptions(ol.layer.VectorLayerOptions) Coordinate(ol.Coordinate) Select(ol.interaction.Select) Collection(ol.Collection) ProjectionOptions(ol.proj.ProjectionOptions) Map(ol.Map) VectorOptions(ol.source.VectorOptions)

Aggregations

LayerOptions (ol.layer.LayerOptions)16 Tile (ol.layer.Tile)16 XyzOptions (ol.source.XyzOptions)16 Coordinate (ol.Coordinate)15 Map (ol.Map)15 MapOptions (ol.MapOptions)15 View (ol.View)15 Osm (ol.source.Osm)13 ScaleLine (ol.control.ScaleLine)8 KeyboardPan (ol.interaction.KeyboardPan)7 KeyboardZoom (ol.interaction.KeyboardZoom)7 Collection (ol.Collection)6 MousePosition (ol.control.MousePosition)6 Base (ol.layer.Base)6 Feature (ol.Feature)4 FeatureOptions (ol.FeatureOptions)4 Attribution (ol.control.Attribution)4 Rotate (ol.control.Rotate)4 VectorLayerOptions (ol.layer.VectorLayerOptions)4 Vector (ol.source.Vector)4