diff --git a/docs/Changelog.md b/docs/Changelog.md
index 9ad1b8706..fb309a624 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -2,6 +2,7 @@
## New since 0.6.1
+- Group layer implementation [#860](https://github.com/mapsforge/mapsforge/issues/860)
- Allow resources without location prefixes in render themes [#847](https://github.com/mapsforge/mapsforge/issues/847)
- SVG symbols customization [#858](https://github.com/mapsforge/mapsforge/issues/858)
- Deprecate water tiles rendering [#640](https://github.com/mapsforge/mapsforge/issues/640)
diff --git a/mapsforge-map/src/main/java/org/mapsforge/map/layer/GroupLayer.java b/mapsforge-map/src/main/java/org/mapsforge/map/layer/GroupLayer.java
new file mode 100644
index 000000000..dc5c7aef2
--- /dev/null
+++ b/mapsforge-map/src/main/java/org/mapsforge/map/layer/GroupLayer.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2016 devemux86
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ */
+package org.mapsforge.map.layer;
+
+import org.mapsforge.core.graphics.Canvas;
+import org.mapsforge.core.model.BoundingBox;
+import org.mapsforge.core.model.LatLong;
+import org.mapsforge.core.model.Point;
+import org.mapsforge.map.model.DisplayModel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A layer which is a group of other layers.
+ */
+public class GroupLayer extends Layer {
+
+ /**
+ * The group of other layers.
+ */
+ public final List layers = new ArrayList<>();
+
+ public GroupLayer() {
+ super();
+ }
+
+ @Override
+ public void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
+ for (Layer layer : layers) {
+ layer.draw(boundingBox, zoomLevel, canvas, topLeftPoint);
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ for (Layer layer : layers) {
+ layer.onDestroy();
+ }
+ }
+
+ @Override
+ public boolean onLongPress(LatLong tapLatLong, Point layerXY, Point tapXY) {
+ for (int i = layers.size() - 1; i >= 0; i--) {
+ Layer layer = layers.get(i);
+ if (layer.onLongPress(tapLatLong, layerXY, tapXY)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean onTap(LatLong tapLatLong, Point layerXY, Point tapXY) {
+ for (int i = layers.size() - 1; i >= 0; i--) {
+ Layer layer = layers.get(i);
+ if (layer.onTap(tapLatLong, layerXY, tapXY)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public synchronized void setDisplayModel(DisplayModel displayModel) {
+ super.setDisplayModel(displayModel);
+ for (Layer layer : layers) {
+ layer.setDisplayModel(displayModel);
+ }
+ }
+}
diff --git a/mapsforge-samples-android/src/main/java/org/mapsforge/samples/android/PoiSearchViewer.java b/mapsforge-samples-android/src/main/java/org/mapsforge/samples/android/PoiSearchViewer.java
index b80fbbcc4..5abc5555a 100644
--- a/mapsforge-samples-android/src/main/java/org/mapsforge/samples/android/PoiSearchViewer.java
+++ b/mapsforge-samples-android/src/main/java/org/mapsforge/samples/android/PoiSearchViewer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 devemux86
+ * Copyright 2015-2016 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -25,6 +25,7 @@
import org.mapsforge.core.model.LatLong;
import org.mapsforge.core.model.Point;
import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
+import org.mapsforge.map.layer.GroupLayer;
import org.mapsforge.map.layer.Layer;
import org.mapsforge.map.layer.Layers;
import org.mapsforge.map.layer.overlay.Circle;
@@ -47,7 +48,7 @@
*/
public class PoiSearchViewer extends RenderTheme4 {
private static final String POI_FILE = Environment.getExternalStorageDirectory() + "/germany.poi";
- private static final String POI_CATEGORY = "Embassies";
+ private static final String POI_CATEGORY = "Restaurants";
private static final Paint CIRCLE = Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(128, 255, 0, 0), 0, Style.FILL);
@@ -71,7 +72,7 @@ private void onLongPress() {
// Clear overlays
Layers layers = this.mapView.getLayerManager().getLayers();
for (Layer layer : layers) {
- if (layer instanceof Circle) {
+ if (layer instanceof GroupLayer) {
layers.remove(layer);
}
}
@@ -120,19 +121,23 @@ protected void onPostExecute(Collection pointOfInterests) {
return;
}
+ GroupLayer groupLayer = new GroupLayer();
for (final PointOfInterest pointOfInterest : pointOfInterests) {
- Circle circle = new FixedPixelCircle(pointOfInterest.getLatLong(), 16, CIRCLE, null) {
+ final Circle circle = new FixedPixelCircle(pointOfInterest.getLatLong(), 16, CIRCLE, null) {
@Override
public boolean onTap(LatLong tapLatLong, Point layerXY, Point tapXY) {
- if (this.contains(layerXY, tapXY)) {
+ // GroupLayer does not have a position!
+ Point circleXY = activity.mapView.getMapViewProjection().toPixels(getPosition());
+ if (this.contains(circleXY, tapXY)) {
Toast.makeText(activity, pointOfInterest.getName(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
};
- activity.mapView.getLayerManager().getLayers().add(circle);
+ groupLayer.layers.add(circle);
}
+ activity.mapView.getLayerManager().getLayers().add(groupLayer);
activity.redrawLayers();
}
}