From e85ec4846888b8fde1aab083130ec6ee8f7db987 Mon Sep 17 00:00:00 2001 From: Emux <devemux86@gmail.com> Date: Fri, 17 Jun 2016 15:14:07 +0300 Subject: [PATCH] ViewController: moveTo respects Viewport limits, fixes #12 --- vtm/src/org/oscim/map/ViewController.java | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/vtm/src/org/oscim/map/ViewController.java b/vtm/src/org/oscim/map/ViewController.java index 3494f74a..17b3a303 100644 --- a/vtm/src/org/oscim/map/ViewController.java +++ b/vtm/src/org/oscim/map/ViewController.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 devemux86 + * + * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). + * + * 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 <http://www.gnu.org/licenses/>. + */ package org.oscim.map; import static org.oscim.utils.FastMath.clamp; @@ -89,6 +105,17 @@ public class ViewController extends Viewport { mPos.x -= 1; while (mPos.x < 0) mPos.x += 1; + + /* limit longitude */ + if (mPos.x > mMaxX) + mPos.x = mMaxX; + else if (mPos.x < mMinX) + mPos.x = mMinX; + /* limit latitude */ + if (mPos.y > mMaxY) + mPos.y = mMaxY; + else if (mPos.y < mMinY) + mPos.y = mMinY; } private Point applyRotation(double mx, double my) {