/*---------------- FILE HEADER --------------------------------------- This file is part of Geoide. Copyright (C) 2005-2006 by: IDgis B.V. http://www.idgis.nl This library 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 2.1 of the License, or (at your option) any later version. This library 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 library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: Herman Assink IDgis bv P.O. Box 15 7450 AA Holten The Netherlands E-Mail: herman.assink@idgis.nl * @version 1.4.0 * @author IDgis team * ------------------------------------------------------------------------*/ import nl.idgis.giclient.geoma.LineString; import nl.idgis.giclient.geoma.Point; import nl.idgis.giclient.gps.GPSconnector; import nl.idgis.giclient.gui.mapviewer.MapViewer; import nl.idgis.giclient.util.Pixel; import nl.idgis.giclient.gps.GPSListener; import nl.idgis.giclient.GIClient; import nl.idgis.giclient.gis.Map; import nl.idgis.giclient.geoma.Envelope; import nl.idgis.giclient.gis.GIS; import nl.idgis.giclient.framework.FrameWork; class nl.idgis.giclient.gui.mapviewer.MapGPSSymbol implements GPSListener { private var mapViewer:MapViewer = null; private var gpsConnector:GPSconnector = null; private var theSymbol:MovieClip = null; private var previousPosition:Point = null; private var previousPosTime:Date = null; private var scaleSpeedFactor:Number = 500; private var wasInside:Boolean = false; public function MapGPSSymbol(mapViewer:MapViewer){ this.gpsConnector = GPSconnector.getInstance(); if (gpsConnector != null) { gpsConnector.addGPSListener(this); } this.mapViewer = mapViewer; this.previousPosTime = new Date(); } public function onGPSevent():Void { draw(); } private function draw():Void { var pos:Point = gpsConnector.getPosition(); var gism:GIS = mapViewer.ruler.getGIS(); var extent:Envelope = gism.getCurrentCentreScale().toEnvelope(mapViewer.mapWidth, mapViewer.mapHeight, gism.getCoordPixFactor()); var inExtent:Boolean = false; if (pos.getX() >= extent.getMinX() && pos.getX() <= extent.getMaxX() && pos.getY() >= extent.getMinY() && pos.getY() <= extent.getMaxY()) { inExtent = true; } else { this.wasInside = false; } if (pos == null || !inExtent) { //return if no valid position if (theSymbol != null) { theSymbol.removeMovieClip(); theSymbol = null; } return; } var pix:Pixel = mapViewer.point2Pixel(pos.getX(), pos.getY()); var currentPosTime:Date = new Date(); var dxPosition:Number = Math.abs(pos.getX() - previousPosition.getX()); var dyPosition:Number = Math.abs(pos.getY() - previousPosition.getY()); if ( (pix.getX() > 0 && pix.getX() <= mapViewer.mapWidth && pix.getY() > 0 && pix.getY() <= mapViewer.mapHeight )) { if (this.theSymbol == null) { theSymbol = this.mapViewer.attachMovie("GPSPointer", "gpsSymbol", this.mapViewer.getNextHighestDepth(), null); } theSymbol._x = pix.getX(); theSymbol._y = pix.getY(); theSymbol._rotation = gpsConnector.getTrack(); } else { theSymbol.removeMovieClip(); theSymbol = null; } var deltaDistance:Number = Math.sqrt(Math.pow(dxPosition, 2) + Math.pow(dyPosition, 2)); var deltaTime:Number = (currentPosTime.valueOf() - previousPosTime.valueOf()) / 1000; var speed:Number = deltaDistance / deltaTime; var newScale:Number = 500 + (speed * scaleSpeedFactor); // GPS in map border? if ((pix.getX() < mapViewer.mapWidth * 0.1 || pix.getX() > (mapViewer.mapWidth - (mapViewer.mapWidth * 0.1)) || pix.getY() < mapViewer.mapHeight * 0.1 || pix.getY() > (mapViewer.mapHeight - (mapViewer.mapHeight * 0.1)))) { if (this.wasInside && deltaDistance > 2) { gism.setCurrentCentreScale(pos.getX(), pos.getY(), newScale); } } else { this.wasInside = true; } previousPosition = pos; previousPosTime = currentPosTime; } }