use of ol.layer.Base in project gwt-ol3 by TDesjardins.
the class AnimationExample 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 an 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();
view.setCenter(transformedMidPoint);
view.setZoom(16);
// create the map
MapOptions mapOptions = new MapOptions();
mapOptions.setLoadTilesWhileAnimating(true);
mapOptions.setTarget(exampleId);
mapOptions.setView(view);
Collection<Base> lstLayer = new Collection<Base>();
lstLayer.push(osmLayer);
mapOptions.setLayers(lstLayer);
Map map = new Map(mapOptions);
// add some controls
map.addControl(new ScaleLine());
MousePositionOptions mousePositionOptions = new MousePositionOptions();
ProjectionOptions projectionOptions = new ProjectionOptions();
projectionOptions.setCode(DemoConstants.EPSG_4326);
mousePositionOptions.setProjection(new Projection(projectionOptions));
MousePosition mousePosition = new MousePosition(mousePositionOptions);
mousePosition.setCoordinateFormat(Coordinate.createStringXY(5));
map.addControl(mousePosition);
Coordinate tvTowerCoordinate = Projection.transform(new Coordinate(13.409, 52.52), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
Coordinate pplaceCoordinate = Projection.transform(new Coordinate(13.377, 52.509), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
Coordinate zooCoordinate = Projection.transform(new Coordinate(13.338, 52.508), DemoConstants.EPSG_4326, DemoConstants.EPSG_3857);
final List<Coordinate> coordinates = Arrays.asList(transformedMidPoint, tvTowerCoordinate, pplaceCoordinate, zooCoordinate);
Scheduler.get().scheduleFixedPeriod(() -> {
int index = getNextIndex(coordinates.size());
AnimationOptions panAnimationOptions = new AnimationOptions();
panAnimationOptions.setDuration(2000);
// Switch this to rotate the animation while animating.
// panAnimationOptions.setRotation(view.getRotation() + 2 * Math.PI);
panAnimationOptions.setCenter(coordinates.get(index));
view.animate(panAnimationOptions);
AnimationOptions zoomOutAnimationOptions = new AnimationOptions();
zoomOutAnimationOptions.setDuration(1000);
zoomOutAnimationOptions.setResolution(view.getResolution() + 4);
AnimationOptions zoomInAnimationOptions = new AnimationOptions();
zoomInAnimationOptions.setDuration(1000);
zoomInAnimationOptions.setResolution(view.getResolution());
view.animate(zoomOutAnimationOptions, zoomInAnimationOptions);
return true;
}, 6000);
}
use of ol.layer.Base in project gwt-ol3 by TDesjardins.
the class OLUtil method getZoomLevel.
/**
* Gets the current zoomlevel of the given {@link Map}.
* @param map
* {@link Map}
* @return zoomlevel on success, else {@link Double#NaN}
*/
public static double getZoomLevel(Map map) {
View v = map.getView();
// try to get zoom
double z = getZoom(v);
if (!Double.isNaN(z)) {
return z;
}
// zoom is undefined, so check resolution
double zoomResolution = v.getResolution();
// walk layers to find resolution
CollectionWrapper<Base> layers = new CollectionWrapper<Base>(map.getLayers());
for (Base l : layers) {
// get source if layer instance has it
Source source = l.get("source");
if (source != null) {
// try to get a tilegrid from the source
TileGrid tg = getTileGrid(source);
if (tg != null) {
// check resolutions
double[] resolutions = tg.getResolutions();
if (resolutions != null) {
double dPreviousResolution = 0;
for (int i = 0; i < resolutions.length; i++) {
// resolutions are sorted in descending order, so
// compare with actual one
double resolution = resolutions[i];
if (resolution <= zoomResolution) {
if (i > 1) {
// calculate the delta of the resolution
// compared to the current and the previous
// zoomlevel
double delta = (resolution - zoomResolution) / (dPreviousResolution - resolution);
// adjust the integer zoomlevel to the delta
return i + delta;
} else {
return 0;
}
}
dPreviousResolution = resolution;
}
}
}
}
}
return Double.NaN;
}
use of ol.layer.Base 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("© <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);
}
use of ol.layer.Base 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());
}
Aggregations