package de.fhpotsdam.unfolding;

import processing.core.PApplet;

import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.geo.Location;
import de.fhpotsdam.unfolding.utils.MapUtils;

/**
 * Combines tween-map with zoom restriction. Mark Hester sent that as a bug.
 * 
 * If tweening is on and zoom is restricted, users can zoom further anyway (or it jumps around).
 *
 */
public class ZoomRangeTweenMap extends PApplet {

	UnfoldingMap map;
	Location loc1 = new Location(50, 10);
	Location loc2 = new Location(40, 20);
	
	int minZoomLevel = 8;
	int maxZoomLevel = 11;

	public void setup() {
		size(800, 600, OPENGL);

		map = new UnfoldingMap(this);
		map.zoomAndPanTo(new Location(52.5f, 13.4f), 10);
		map.setZoomRange(minZoomLevel, maxZoomLevel);
		
		map.setTweening(true);

		MapUtils.createDefaultEventDispatcher(this, map);
	}

	public void draw() {
		background(0);
		
//		if (map.getZoomLevel() < minZoomLevel) {
//			map.zoomToLevel(minZoomLevel);
//		}
//		else if (map.getZoomLevel() > maxZoomLevel) {
//			map.zoomToLevel(maxZoomLevel);
//		}
		
		map.draw();
	}


}

@@ -61,53 +61,8 @@
 let;
-%0A%0Aimport de.fhpotsdam.unfolding.UnfoldingMap;
 %0Aimp
@@ -233,108 +233,128 @@
 bug.
-%0A * %0A * If tweening is on and zoom is restricted, users can zoom further anyway (or it jumps around)
+ See%0A * https://github.com/tillnagel/unfolding/issues/53%0A * %0A * If tweening is on and zoom is restricted, it still works
 .%0A *
@@ -505,17 +505,16 @@
 0, 20);%0A
-%09
 %0A%09int mi
@@ -655,16 +655,20 @@
 ndPanTo(
+10, 
 new Loca
@@ -685,20 +685,16 @@
 , 13.4f)
-, 10
 );%0A%09%09map
@@ -736,18 +736,16 @@
 Level);%0A
-%09%09
 %0A%09%09map.s
@@ -862,15 +862,39 @@
 0);%0A
+%0A
 %09%09
-%0A
 //
-%09%09
+ Not needed anymore!%0A%09%09// 
 if (
@@ -922,37 +922,37 @@
 minZoomLevel) %7B%0A
-//%09%09%09
+%09%09// 
 map.zoomToLevel(
@@ -970,18 +970,20 @@
 l);%0A
-//%09%09%7D%0A//%09%09
+%09%09// %7D%0A%09%09// 
 else
@@ -1028,13 +1028,13 @@
 ) %7B%0A
-//%09%09%09
+%09%09// 
 map.
@@ -1064,16 +1064,15 @@
 l);%0A
-//%09%09%7D%0A%09%09
+%09%09// %7D%0A
 %0A%09%09m
@@ -1086,11 +1086,10 @@
 ();%0A%09%7D%0A%0A
-%0A
 %7D%0A

Test app issue #53. This is fixed since a while. Zoom restriction now sets in before the map is drawn.