Below is a map of the world. This map centered on the location of Miles' office and provides a
- helpful marker to ensure that you don't miss it.
+ helpful marker to ensure that you don't miss it. Use the layer drop-down to toggle between
+ the street layer and the satellite layer.
+
+
[MARKER]
diff --git a/openlayers3-parent/openlayers3-examples/src/main/java/org/wicketstuff/openlayers3/examples/MarkerPage.java b/openlayers3-parent/openlayers3-examples/src/main/java/org/wicketstuff/openlayers3/examples/MarkerPage.java
index c3dfeb37f1..aae787e697 100644
--- a/openlayers3-parent/openlayers3-examples/src/main/java/org/wicketstuff/openlayers3/examples/MarkerPage.java
+++ b/openlayers3-parent/openlayers3-examples/src/main/java/org/wicketstuff/openlayers3/examples/MarkerPage.java
@@ -2,7 +2,13 @@
import java.util.Arrays;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
+import org.apache.wicket.model.util.ListModel;
import org.wicketstuff.annotation.mount.MountPath;
import org.wicketstuff.openlayers3.DefaultOpenLayersMap;
import org.wicketstuff.openlayers3.api.Map;
@@ -12,30 +18,57 @@
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.XYZ;
import org.wicketstuff.openlayers3.api.util.Color;
import org.wicketstuff.openlayers3.component.Marker;
import org.wicketstuff.openlayers3.examples.base.BasePage;
+import de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapForm;
+import de.agilecoders.wicket.core.markup.html.bootstrap.form.FormGroup;
+import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect;
+
/**
* Provides a page with a mpa that includes a marker.
*/
@MountPath("/marker")
public class MarkerPage extends BasePage {
- /**
- * Marker over Miles' office.
- */
- private Marker marker;
+ 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}";
- @Override
- protected void onInitialize() {
- super.onInitialize();
+ private enum LayerOption {
+ STREET,
+ SATELLITE;
+ }
- // create and add our marker
- add(marker = new Marker("marker", Model.of(new Color("#4169E1"))));
+ private static class LayerSelectedModel extends LoadableDetachableModel
{
+
+ private IModel model;
+ private LayerOption layerOption;
+
+ public LayerSelectedModel(IModel model, LayerOption layerOption) {
+ this.model = model;
+ this.layerOption = layerOption;
+ }
+
+ @Override
+ protected Boolean load() {
+ return layerOption.equals(model.getObject());
+ }
+
+ }
+
+ public MarkerPage() {
+ super();
+
+ // model of the selected layer
+ final IModel model = Model.of(LayerOption.STREET);
+
+ // create and add our marker over Miles' office
+ Marker marker = new Marker("marker", Model.of(new Color("#4169E1")));
+ add(marker);
// create and add our marker
- add(new DefaultOpenLayersMap("map",
+ final DefaultOpenLayersMap map = new DefaultOpenLayersMap("map",
// create the model for our map
Model.of(new Map(
@@ -43,11 +76,21 @@ protected void onInitialize() {
// list of layers
Arrays.asList(
- // a new tile layer with the map of the world
+ // a new tile layer with the street map of Noho
new Tile("Streets",
// a new web map service tile layer
- new Osm())),
+ new Osm(),
+ // visible when the layer selector is street
+ new LayerSelectedModel(model, LayerOption.STREET)),
+
+ // a new tile layer with the satellite map of Noho
+ new Tile("Ortho",
+
+ // MA ortho-imagery layer
+ new XYZ().setUrl(MA_ORTHO_URL),
+ // visible when the layer selector is satellite
+ new LayerSelectedModel(model, LayerOption.SATELLITE))),
// list of overlays
Arrays.asList(
@@ -69,6 +112,27 @@ protected void onInitialize() {
new LongLat(-72.638382, 42.313181, "EPSG:4326").transform(View.DEFAULT_PROJECTION),
// zoom level for the view
- 16)))));
+ 16))));
+ add(map);
+
+ // form for changing the layer
+ Form form = new BootstrapForm<>("form", model);
+ add(form);
+
+ // 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())))
+ .setLabel(Model.of("Layer"))
+ .add(new AjaxFormComponentUpdatingBehavior("change") {
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target) {
+ map.updateLayers(target);
+ }
+
+ })));
+
}
+
}
diff --git a/openlayers3-parent/openlayers3/src/main/java/org/wicketstuff/openlayers3/OpenLayersMap.java b/openlayers3-parent/openlayers3/src/main/java/org/wicketstuff/openlayers3/OpenLayersMap.java
index 632a84d6f4..c33326acfa 100644
--- a/openlayers3-parent/openlayers3/src/main/java/org/wicketstuff/openlayers3/OpenLayersMap.java
+++ b/openlayers3-parent/openlayers3/src/main/java/org/wicketstuff/openlayers3/OpenLayersMap.java
@@ -31,28 +31,25 @@ public abstract class OpenLayersMap extends GenericPanel