Search in sources :

Example 1 with Raster

use of ol.source.Raster 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 2 with Raster

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

the class RasterExample method getRasterSource.

private static Raster getRasterSource(Source source, RasterOperationType type) {
    // wrap source with raster source layer
    RasterOptions rasterOptions = OLFactory.createRasterOptionsWithSource(source);
    rasterOptions.setOperationType(type);
    RasterOperation<?> rasterOperation = null;
    switch(type) {
        case PIXEL:
            rasterOperation = (PixelColor[] pixels) -> {
                final int channel = 0;
                final int threshold = 245;
                // get pixel of first source
                PixelColor pixel = pixels[0];
                // extract pixel value and apply operation
                int value = pixel.getChannel(channel);
                pixel.clear();
                if (value > threshold) {
                    pixel.setChannel(channel, 255);
                    pixel.setAlpha(128);
                }
                return pixel;
            };
            break;
        case IMAGE:
            rasterOperation = (ImageData[] sourceImages) -> {
                // get image of first source
                ImageData image = sourceImages[0];
                // apply image wide operation, make the lower part of the image darker
                final int width = image.width;
                final int height = image.height;
                PixelColor pixel = new PixelColor(0, 0, 0, 128);
                for (int y = height / 2; y < height; ++y) {
                    for (int x = 0; x < width; ++x) {
                        image.putPixel(x, y, pixel);
                    }
                }
                return image;
            };
            break;
    }
    // set raster operation and return raster
    rasterOptions.setOperation(rasterOperation);
    return new Raster(rasterOptions);
}
Also used : RasterOptions(ol.source.RasterOptions) ImageData(ol.ImageData) Raster(ol.source.Raster) PixelColor(ol.PixelColor)

Aggregations

Raster (ol.source.Raster)2 Collection (ol.Collection)1 Coordinate (ol.Coordinate)1 ImageData (ol.ImageData)1 Map (ol.Map)1 MapOptions (ol.MapOptions)1 PixelColor (ol.PixelColor)1 View (ol.View)1 Base (ol.layer.Base)1 Image (ol.layer.Image)1 LayerOptions (ol.layer.LayerOptions)1 Tile (ol.layer.Tile)1 Osm (ol.source.Osm)1 RasterOptions (ol.source.RasterOptions)1 XyzOptions (ol.source.XyzOptions)1