Search in sources :

Example 1 with LineString

use of ol.geom.LineString 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 LineString

use of ol.geom.LineString in project gwt-ol3 by TDesjardins.

the class GeoJsonTest method createTestFeature.

private Feature createTestFeature() {
    Coordinate coordinate1 = new Coordinate(1, 1);
    Coordinate coordinate2 = new Coordinate(5, 5);
    Coordinate[] coordinates = { coordinate1, coordinate2 };
    LineString lineString = new LineString(coordinates);
    // Create feature
    FeatureOptions featureOptions = new FeatureOptions();
    featureOptions.setGeometry(lineString);
    return new Feature(featureOptions);
}
Also used : Coordinate(ol.Coordinate) LineString(ol.geom.LineString) Feature(ol.Feature) FeatureOptions(ol.FeatureOptions)

Example 3 with LineString

use of ol.geom.LineString in project gwt-ol3 by TDesjardins.

the class WktTest method createTestFeature.

private Feature createTestFeature() {
    Coordinate coordinate1 = new Coordinate(1, 1);
    Coordinate coordinate2 = new Coordinate(5, 5);
    Coordinate[] coordinates = { coordinate1, coordinate2 };
    LineString lineString = new LineString(coordinates);
    // Create feature
    FeatureOptions featureOptions = new FeatureOptions();
    featureOptions.setGeometry(lineString);
    return new Feature(featureOptions);
}
Also used : Coordinate(ol.Coordinate) LineString(ol.geom.LineString) Feature(ol.Feature) FeatureOptions(ol.FeatureOptions)

Aggregations

Coordinate (ol.Coordinate)3 Feature (ol.Feature)3 FeatureOptions (ol.FeatureOptions)3 LineString (ol.geom.LineString)3 Collection (ol.Collection)1 Map (ol.Map)1 MapOptions (ol.MapOptions)1 View (ol.View)1 Rotate (ol.control.Rotate)1 ScaleLine (ol.control.ScaleLine)1 GeoJson (ol.format.GeoJson)1 KeyboardPan (ol.interaction.KeyboardPan)1 KeyboardZoom (ol.interaction.KeyboardZoom)1 Base (ol.layer.Base)1 LayerOptions (ol.layer.LayerOptions)1 Tile (ol.layer.Tile)1 VectorLayerOptions (ol.layer.VectorLayerOptions)1 Osm (ol.source.Osm)1 Vector (ol.source.Vector)1 VectorOptions (ol.source.VectorOptions)1