Permalink
Browse files

Added scribble vector tiles examples (Using giCentre's handy lib)

  • Loading branch information...
1 parent 4bbcb34 commit 08d0b4eb9fd3e98b77c402c7d4ce503f68a6655a @tillnagel committed Jun 30, 2015
@@ -1,74 +0,0 @@
-package de.fhpotsdam.unfolding.examples.data.vectortiles;
-
-import java.util.List;
-
-import processing.core.PApplet;
-import de.fhpotsdam.unfolding.UnfoldingMap;
-import de.fhpotsdam.unfolding.geo.Location;
-import de.fhpotsdam.unfolding.marker.AbstractShapeMarker;
-import de.fhpotsdam.unfolding.marker.Marker;
-import de.fhpotsdam.unfolding.utils.DebugDisplay;
-import de.fhpotsdam.unfolding.utils.GeoUtils;
-import de.fhpotsdam.unfolding.utils.MapUtils;
-
-/**
- * Displays markers of a single vector tile.
- *
- * Click on the map to load all buildings of vector tile for the area.
- */
-public class ScribbledVectorTilesApp extends PApplet {
-
- UnfoldingMap map;
- DebugDisplay debugDisplay;
- VectorTilesUtils vectorTilesUtils;
-
- String featureLayer = "buildings";
-
- public void setup() {
- size(800, 600, OPENGL);
-
- map = new UnfoldingMap(this, "myMap");
- map.zoomAndPanTo(16, new Location(52.501, 13.395));
- MapUtils.createDefaultEventDispatcher(this, map);
-
- debugDisplay = new DebugDisplay(this, map);
-
- vectorTilesUtils = new VectorTilesUtils(this, map);
- List<Marker> markers = vectorTilesUtils.loadMarkersForScreenPos(featureLayer, width / 2, height / 2);
- map.addMarkers(markers);
- }
-
- public void draw() {
- map.draw();
- debugDisplay.draw();
- }
-
- public void mouseClicked() {
- map.getDefaultMarkerManager().clearMarkers();
- //List<Marker> markers = vectorTilesUtils.loadMarkersForScreenPos(featureLayer, mouseX, mouseY);
- List<Marker> markers = vectorTilesUtils.loadMarkersForCurrentMapView(featureLayer);
- map.addMarkers(markers);
- }
-
- public void mouseMoved() {
- Location mouseLocation = map.getLocation(mouseX, mouseY);
- List<Marker> markers = map.getMarkers();
- for (Marker marker : markers) {
-
- marker.setStrokeColor(color(221, 221, 221));
-
- // Neither polyMarker.getCentroid() nor GeoUtils.getCentroid(m.locations) return correct centroid.
- Location centroid = GeoUtils.getEuclideanCentroid(((AbstractShapeMarker) marker).getLocations());
-
- // Shade based on distance
- float dist = (float) centroid.getDistance(mouseLocation);
- if (dist < 0.3) {
- float colorValue = map(dist, 0, 0.3f, 0, 238);
- marker.setColor(color(238, colorValue, colorValue, 200));
- } else {
- marker.setColor(color(238, 238, 235));
- }
- }
- }
-
-}
@@ -0,0 +1,91 @@
+package de.fhpotsdam.unfolding.examples.data.vectortiles;
+
+import java.util.List;
+
+import processing.core.PApplet;
+import de.fhpotsdam.unfolding.UnfoldingMap;
+import de.fhpotsdam.unfolding.examples.interaction.snapshot.CircularMapSnapshot;
+import de.fhpotsdam.unfolding.examples.interaction.snapshot.MapSnapshot;
+import de.fhpotsdam.unfolding.geo.Location;
+import de.fhpotsdam.unfolding.marker.Marker;
+import de.fhpotsdam.unfolding.utils.GeoUtils;
+import de.fhpotsdam.unfolding.utils.MapUtils;
+import de.fhpotsdam.unfolding.utils.ScreenPosition;
+
+public class SelectBuildingsApp extends PApplet {
+
+ UnfoldingMap map;
+
+ VectorTilesUtils vectorTilesUtils;
+ String featureLayer = "buildings";
+
+ Location[] boundingBox;
+ MapSnapshot mapSnapshot = null;
+
+ public void setup() {
+ size(800, 600, OPENGL);
+
+ map = new UnfoldingMap(this, 0, 0, 600, 600);
+
+ map.zoomAndPanTo(16, new Location(52.501, 13.395));
+ MapUtils.createDefaultEventDispatcher(this, map);
+ map.setZoomRange(10, 19);
+
+ vectorTilesUtils = new VectorTilesUtils(this, map);
+ List<Marker> markers = vectorTilesUtils.loadMarkersForScreenPos(featureLayer, width / 2, height / 2);
+ map.addMarkers(markers);
+ }
+
+ public void draw() {
+ background(0);
+ map.draw();
+
+ if (mapSnapshot != null)
+ mapSnapshot.draw(620, 20, 200, 200);
+
+ if (boundingBox != null) {
+ ScreenPosition nwPos = map.getScreenPosition(boundingBox[0]);
+ ScreenPosition sePos = map.getScreenPosition(boundingBox[1]);
+ stroke(0, 255, 0, 200);
+ noFill();
+ rect(nwPos.x, nwPos.y, sePos.x - nwPos.x, sePos.y - nwPos.y);
+ }
+ }
+
+ public void mouseClicked() {
+ List<Marker> markers = map.getMarkers();
+ for (Marker marker : markers)
+ marker.setHidden(true);
+
+ Marker hitMarker = map.getFirstHitMarker(mouseX, mouseY);
+ if (hitMarker != null) {
+
+ map.zoomAndPanToFit(GeoUtils.getLocations(hitMarker));
+ map.draw();
+
+ boundingBox = GeoUtils.getBoundingBox(GeoUtils.getLocations(hitMarker));
+
+ mapSnapshot = new CircularMapSnapshot(this, map, 300, 5);
+ mapSnapshot.snapshot(map, 0, 0, 600, 600);
+
+ mapSnapshot.draw(0, 0, 600, 600);
+
+ hitMarker.setHidden(false);
+ println(hitMarker.getStringProperty("name"));
+ }
+ }
+
+ public void keyPressed() {
+ if (key == 't') {
+ List<Marker> markers = map.getMarkers();
+ for (Marker marker : markers)
+ marker.setHidden(false);
+ }
+
+ if (key == 's') {
+ mapSnapshot = new CircularMapSnapshot(this);
+ mapSnapshot.snapshot(map);
+ }
+ }
+
+}
@@ -0,0 +1,78 @@
+package de.fhpotsdam.unfolding.examples.data.vectortiles;
+
+import java.util.List;
+
+import processing.core.PApplet;
+import processing.core.PImage;
+import de.fhpotsdam.unfolding.UnfoldingMap;
+import de.fhpotsdam.unfolding.geo.Location;
+import de.fhpotsdam.unfolding.mapdisplay.OpenGLMapDisplay;
+import de.fhpotsdam.unfolding.mapdisplay.shaders.MapDisplayShader;
+import de.fhpotsdam.unfolding.mapdisplay.shaders.MaskedMapDisplayShader;
+import de.fhpotsdam.unfolding.marker.Marker;
+import de.fhpotsdam.unfolding.marker.SimplePolygonMarker;
+import de.fhpotsdam.unfolding.utils.MapUtils;
+import de.fhpotsdam.unfolding.utils.ScreenPosition;
+
+public class SelectedBuildingsMaskApp extends PApplet {
+
+ UnfoldingMap map;
+ MapDisplayShader mapDisplayShader;
+
+ VectorTilesUtils vectorTilesUtils;
+ String featureLayer = "buildings";
+
+ Marker selectedMarker = null;
+
+ public void setup() {
+ size(400, 400, OPENGL);
+
+ map = new UnfoldingMap(this);
+ MapUtils.createDefaultEventDispatcher(this, map);
+ map.zoomAndPanTo(16, new Location(52.501, 13.395));
+ map.setZoomRange(10, 19);
+
+ vectorTilesUtils = new VectorTilesUtils(this, map);
+ List<Marker> markers = vectorTilesUtils.loadMarkersForScreenPos(featureLayer, width / 2, height / 2);
+ map.addMarkers(markers);
+
+ PImage maskImage = loadImage("test/mask-circular.png");
+ mapDisplayShader = new MaskedMapDisplayShader(this, 400, 400, maskImage);
+ ((OpenGLMapDisplay) map.mapDisplay).setMapDisplayShader(mapDisplayShader);
+ }
+
+ public void draw() {
+ background(0);
+ map.draw();
+ g.resetShader();
+
+ if (selectedMarker != null) {
+ SimplePolygonMarker polygonMarker = (SimplePolygonMarker) selectedMarker;
+ strokeWeight(1);
+ stroke(28,102,120);
+ fill(116,188,157);
+ beginShape();
+ for (Location location : polygonMarker.getLocations()) {
+ ScreenPosition pos = map.getScreenPosition(location);
+ vertex(pos.x, pos.y);
+ }
+ endShape();
+ }
+ }
+
+ public void keyPressed() {
+ if (key == 'l') {
+ List<Marker> markers = vectorTilesUtils.loadMarkersForScreenPos(featureLayer, mouseX, mouseY);
+ map.addMarkers(markers);
+ }
+ }
+
+ public void mouseClicked() {
+ List<Marker> markers = map.getMarkers();
+ for (Marker marker : markers)
+ marker.setHidden(true);
+
+ selectedMarker = map.getFirstHitMarker(mouseX, mouseY);
+ }
+
+}
@@ -0,0 +1,73 @@
+package de.fhpotsdam.unfolding.examples.data.vectortiles;
+
+import java.util.List;
+
+import org.gicentre.handy.HandyRenderer;
+
+import processing.core.PConstants;
+import processing.core.PGraphics;
+import de.fhpotsdam.unfolding.geo.Location;
+import de.fhpotsdam.unfolding.marker.SimplePolygonMarker;
+import de.fhpotsdam.unfolding.utils.MapPosition;
+
+public class SketchyPolygonMarker extends SimplePolygonMarker {
+
+ HandyRenderer handy = null;
+
+ public SketchyPolygonMarker(List<Location> locations) {
+ super(locations);
+ }
+
+ public void draw(PGraphics pg, List<MapPosition> mapPositions) {
+ handy.setGraphics(pg);
+
+ pg.pushStyle();
+
+ // Here you should do your custom drawing
+ pg.strokeWeight(2);
+ pg.stroke(209, 89, 237);
+ pg.fill(180, 127);
+
+ handy.beginShape();
+ for (MapPosition pos : mapPositions) {
+ handy.vertex(pos.x, pos.y);
+ }
+ handy.endShape();
+
+ pg.popStyle();
+ }
+
+ public void draw(PGraphics pg, List<MapPosition> mapPositions, List<List<MapPosition>> ringMapPositionsArray) {
+
+ pg.pushStyle();
+
+ // Here you should do your custom drawing
+ pg.strokeWeight(2);
+ pg.stroke(209, 89, 237);
+ pg.fill(180, 127);
+
+ handy.beginShape();
+
+ // Main shape (outline)
+ for (MapPosition pos : mapPositions) {
+ handy.vertex(pos.x, pos.y);
+ }
+
+ // Interior rings
+// for (List<MapPosition> interiorRing : ringMapPositionsArray) {
+// handy.beginContour();
+// for (MapPosition pos : interiorRing) {
+// handy.vertex(pos.x, pos.y);
+// }
+// handy.endContour();
+// }
+
+ handy.endShape();
+
+ pg.popStyle();
+ }
+
+ public void setHandyRenderer(HandyRenderer handy) {
+ this.handy = handy;
+ }
+}
Oops, something went wrong.

0 comments on commit 08d0b4e

Please sign in to comment.