Skip to content

Commit

Permalink
Added an ArcGIS tile source and added an opacity property to Layer.
Browse files Browse the repository at this point in the history
  • Loading branch information
ageery committed Jun 22, 2016
1 parent 8a2df9a commit 0f13b8f
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.wicketstuff.openlayers3.examples;

import java.util.Arrays;
import java.util.Collection;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
Expand All @@ -18,6 +20,7 @@
import org.wicketstuff.openlayers3.api.layer.Tile;
import org.wicketstuff.openlayers3.api.overlay.Overlay;
import org.wicketstuff.openlayers3.api.source.tile.Osm;
import org.wicketstuff.openlayers3.api.source.tile.TileArcGISRest;
import org.wicketstuff.openlayers3.api.source.tile.XYZ;
import org.wicketstuff.openlayers3.api.util.Color;
import org.wicketstuff.openlayers3.component.Marker;
Expand All @@ -34,25 +37,27 @@
public class MarkerPage extends BasePage {

private static final String MA_ORTHO_URL = "http://tiles.arcgis.com/tiles/hGdibHYSPO59RG1h/arcgis/rest/services/USGS_Orthos_2013_2014/MapServer/tile/{z}/{y}/{x}";
private static final String MA_OPEN_SPACE_URL = "http://gisprpxy.itd.state.ma.us/arcgisserver/rest/services/AGOL/OpenSpaceLevProt/MapServer";

private enum LayerOption {
STREET,
SATELLITE;
SATELLITE,
OPEN_SPACE;
}

private static class LayerSelectedModel extends LoadableDetachableModel<Boolean> {

private IModel<LayerOption> model;
private LayerOption layerOption;
private Collection<LayerOption> layerOption;

public LayerSelectedModel(IModel<LayerOption> model, LayerOption layerOption) {
public LayerSelectedModel(IModel<LayerOption> model, LayerOption... layerOption) {
this.model = model;
this.layerOption = layerOption;
this.layerOption = Arrays.asList(layerOption);
}

@Override
protected Boolean load() {
return layerOption.equals(model.getObject());
return layerOption.contains(model.getObject());
}

}
Expand Down Expand Up @@ -89,8 +94,18 @@ public MarkerPage() {

// MA ortho-imagery layer
new XYZ().setUrl(MA_ORTHO_URL),
// visible when the layer selector is satellite
new LayerSelectedModel(model, LayerOption.SATELLITE))),
// visible when the layer selector is satellite or open space
new LayerSelectedModel(model, LayerOption.OPEN_SPACE, LayerOption.SATELLITE)),

// a new tile layer with the open space map of Noho
new Tile("Open Space",

// MA open space layer
new TileArcGISRest().setUrl(MA_OPEN_SPACE_URL),
// visible when the layer selector is open space
new LayerSelectedModel(model, LayerOption.OPEN_SPACE))
// fractional opacity so we can see the base map underneath
.setOpacityModel(Model.of(.5))),

// list of overlays
Arrays.<Overlay>asList(
Expand Down Expand Up @@ -122,7 +137,8 @@ public MarkerPage() {
// layer selector -- refresh the map's layers on change
form.add(new FormGroup("layer")
.add(new BootstrapSelect<>("layerSelector", model,
new ListModel<>(Arrays.asList(LayerOption.values())))
new ListModel<>(Arrays.asList(LayerOption.values())),
new EnumChoiceRenderer<LayerOption>())
.setLabel(Model.of("Layer"))
.add(new AjaxFormComponentUpdatingBehavior("change") {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LayerOption.STREET=Street
LayerOption.SATELLITE=Satellite
LayerOption.OPEN_SPACE=Open Space
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public abstract class Layer extends JavascriptObject implements Serializable {

private IModel<Boolean> visibleModel;
private IModel<? extends Number> opacityModel;

/**
* Creates a new Layer.
Expand Down Expand Up @@ -52,22 +53,53 @@ public void onUpdate(AjaxRequestTarget target) {
if (visibleModel != null) {
target.appendJavaScript(getJsId() + ".setVisible(" + visibleModel.getObject() + ")");
}
if (opacityModel != null) {
target.appendJavaScript(getJsId() + ".setOpacity(" + opacityModel.getObject() + ")");
}
}

/**
* @return the model of the visibility of the layer
*/
protected IModel<Boolean> getVisibleModel() {
public IModel<Boolean> getVisibleModel() {
return visibleModel;
}

/**
* @param visibleModel visible model to set
* @return this
*/
public Layer setVisibleModel(IModel<Boolean> visibleModel) {
this.visibleModel = visibleModel;
return this;
}

/**
* @return the model of the opacity of the layer
*/
public IModel<? extends Number> getOpacityModel() {
return opacityModel;
}

/**
* @param opacityModel opacity model to set
* @return this
*/
public Layer setOpacityModel(IModel<? extends Number> opacityModel) {
this.opacityModel = opacityModel;
return this;
}

/**
* Callback for detaching any resources (e.g., models).
*/
public void detach() {
if (visibleModel != null) {
visibleModel.detach();
}
if (opacityModel != null) {
opacityModel.detach();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.wicketstuff.openlayers3.api.source.tile;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.google.common.base.Joiner;

/**
* Provides an object that models an ESRI ArcGIS tile end-point.
* <p/>
* Example: <code>new TileArcGISRest().setUrl("http://www.orthos.dhses.ny.gov/arcgis/rest/services/Latest/MapServer")</code>
* <p/>
* @see <a href="http://openlayers.org/en/latest/apidoc/ol.source.TileArcGISRest.html">http://openlayers.org/en/latest/apidoc/ol.source.TileArcGISRest.html</a>
*/
public class TileArcGISRest extends TileSource implements Serializable {

private String url;

@Override
public String getJsType() {
return "ol.source.TileArcGISRest";
}

@Override
public String renderJs() {
List<String> list = new ArrayList<>();
list.add("'url': '" + getUrl() + "'");
return "{" + Joiner.on(", ").join(list) + "}";
}

public String getUrl() {
return url;
}

public TileArcGISRest setUrl(String url) {
this.url = url;
return this;
}

}

0 comments on commit 0f13b8f

Please sign in to comment.