Search in sources :

Example 21 with LayerOptions

use of ol.layer.LayerOptions in project gwt-ol3 by TDesjardins.

the class XyzExample 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(7);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    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) 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 22 with LayerOptions

use of ol.layer.LayerOptions in project gwt-ol3 by TDesjardins.

the class ClusterExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show() */
@Override
public void show(String exampleId) {
    Collection<Feature> features = new Collection<Feature>();
    int e = 450000;
    for (int i = 0; i < 20000; ++i) {
        // create a point
        Coordinate coordinate = new Coordinate(2 * e * Math.random() - e, 2 * e * Math.random() - e);
        Point point = new Point(coordinate);
        // create feature
        FeatureOptions featureOptions = new FeatureOptions();
        featureOptions.setGeometry(point);
        Feature feature = new Feature(featureOptions);
        features.push(feature);
    }
    // create source
    VectorOptions vectorSourceOptions = new VectorOptions();
    vectorSourceOptions.setFeatures(features);
    Vector vectorSource = new Vector(vectorSourceOptions);
    // create clustering
    ClusterOptions clusterOptions = new ClusterOptions();
    clusterOptions.setDistance(40);
    clusterOptions.setSource(vectorSource);
    Cluster clusterSource = new Cluster(clusterOptions);
    // create vector layer
    VectorLayerOptions vectorLayerOptions = new VectorLayerOptions();
    vectorLayerOptions.setSource(clusterSource);
    vectorLayerOptions.setStyle(new GenericFunction<Feature, Style[]>() {

        @Override
        public Style[] call(Feature cluster) {
            // create style
            List<Style> style = new ArrayList<>();
            Feature[] features = (Feature[]) cluster.get("features");
            int clusterSize = features.length;
            StyleOptions styleOptions = new StyleOptions();
            TextOptions textOptions = new TextOptions();
            textOptions.setText(String.valueOf(clusterSize));
            styleOptions.setText(new Text(textOptions));
            CircleOptions circleOptions = new CircleOptions();
            circleOptions.setRadius(10);
            Color color = Color.getColorFromString("#3399CC");
            circleOptions.setFill(OLFactory.createFill(color));
            styleOptions.setImage(new Circle(circleOptions));
            style.add(new Style(styleOptions));
            return style.toArray(new Style[0]);
        }
    });
    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) Feature(ol.Feature) LayerOptions(ol.layer.LayerOptions) VectorLayerOptions(ol.layer.VectorLayerOptions) TextOptions(ol.style.TextOptions) FeatureOptions(ol.FeatureOptions) CircleOptions(ol.style.CircleOptions) Style(ol.style.Style) ArrayList(java.util.ArrayList) List(java.util.List) Vector(ol.source.Vector) Circle(ol.style.Circle) Color(ol.color.Color) Osm(ol.source.Osm) Cluster(ol.source.Cluster) StyleOptions(ol.style.StyleOptions) Tile(ol.layer.Tile) Text(ol.style.Text) Point(ol.geom.Point) View(ol.View) Point(ol.geom.Point) Base(ol.layer.Base) ClusterOptions(ol.source.ClusterOptions) VectorLayerOptions(ol.layer.VectorLayerOptions) Coordinate(ol.Coordinate) KeyboardZoom(ol.interaction.KeyboardZoom) Collection(ol.Collection) Map(ol.Map) VectorOptions(ol.source.VectorOptions)

Example 23 with LayerOptions

use of ol.layer.LayerOptions in project gwt-ol3 by TDesjardins.

the class GpxExample method show.

/* (non-Javadoc)
     * @see de.desjardins.ol3.demo.client.example.Example#show()
     */
@Override
public void show(String exampleId) {
    // create a OSM-layer
    Osm osmSource = new Osm();
    LayerOptions osmLayerOptions = OLFactory.createOptions();
    osmLayerOptions.setSource(osmSource);
    Tile osmLayer = new Tile(osmLayerOptions);
    // create a GPX vector layer
    VectorOptions vectorOptions = new VectorOptions();
    vectorOptions.setUrl("https://openlayers.org/en/v4.6.4/examples/data/gpx/fells_loop.gpx");
    vectorOptions.setFormat(new Gpx());
    ol.source.Vector vectorSource = new ol.source.Vector(vectorOptions);
    VectorLayerOptions vectorLayerOptions = new VectorLayerOptions();
    vectorLayerOptions.setSource(vectorSource);
    ol.layer.Vector gpxLayer = new ol.layer.Vector(vectorLayerOptions);
    // create a view
    View view = new View();
    Coordinate center = new Coordinate(-7916041.528716288, 5228379.045749711);
    view.setCenter(center);
    view.setZoom(12);
    // create the map
    MapOptions mapOptions = OLFactory.createOptions();
    mapOptions.setTarget(exampleId);
    mapOptions.setView(view);
    Map map = new Map(mapOptions);
    map.addLayer(osmLayer);
    map.addLayer(gpxLayer);
    // add some controls
    map.addControl(new ScaleLine());
    DemoUtils.addDefaultControls(map.getControls());
    Attribution attribution = new Attribution();
    attribution.setCollapsed(true);
    map.addControl(attribution);
    // add some interactions
    map.addInteraction(new KeyboardPan());
    map.addInteraction(new KeyboardZoom());
}
Also used : ScaleLine(ol.control.ScaleLine) KeyboardPan(ol.interaction.KeyboardPan) MapOptions(ol.MapOptions) Osm(ol.source.Osm) Tile(ol.layer.Tile) LayerOptions(ol.layer.LayerOptions) VectorLayerOptions(ol.layer.VectorLayerOptions) View(ol.View) Gpx(ol.format.Gpx) Attribution(ol.control.Attribution) VectorLayerOptions(ol.layer.VectorLayerOptions) Coordinate(ol.Coordinate) KeyboardZoom(ol.interaction.KeyboardZoom) Map(ol.Map) VectorOptions(ol.source.VectorOptions)

Aggregations

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