import nl.idgis.giclient.gis.GIS; import nl.idgis.giclient.gis.Layer; import nl.idgis.giclient.gis.WMLayer; import nl.idgis.giclient.webserviceconnector.wmsconnector.WMSConnector; import nl.idgis.giclient.io.XMLServer; import nl.idgis.giclient.template.CallbackCounter; import mx.utils.Delegate; /*---------------- 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 * ------------------------------------------------------------------------*/ /** * @author assinkhh */ class nl.idgis.giclient.gui.mapviewer.FeatureInfoMapTip { private var gis:GIS = null; private var parentMovie:MovieClip = null; private var maptipLayers:Array = null; private var busyCollectingMaptips:Boolean = false; private var maptipDelayIntervalID:Number = 0; private var lastX:Number = 0; private var lastY:Number = 0; private var maptipCancelled:Boolean = false; public function FeatureInfoMapTip(parentMovie:MovieClip, gis:GIS) { this.parentMovie = parentMovie; this.gis = gis; } public function addMaptip(x:Number, y:Number):Void { lastX = x; lastY = y; if (maptipDelayIntervalID != 0) { clearInterval(maptipDelayIntervalID); } maptipDelayIntervalID = setInterval(this, "requestMaptips", 1000); maptipCancelled = false; } public function cancelMaptip():Void { maptipCancelled = true; } private function requestMaptips():Void { if (busyCollectingMaptips) { return; } //trace("maptipDelayIntervalID = " + maptipDelayIntervalID); clearInterval(maptipDelayIntervalID); maptipDelayIntervalID = 0; if (maptipCancelled) { return; } busyCollectingMaptips = true; var layers:Array = gis.getVisibleLayers(); maptipLayers = new Array(); var noofMaptipLayers:Number = 0; var callbackCounter:CallbackCounter = new CallbackCounter(0, Delegate.create(this, selectMaptipFromGfiResponses)); for(var i:Number = 0; i < layers.length; i++) { var layer:Layer = Layer(layers[i]); if(layer instanceof WMLayer) { var wmLayer:WMLayer = WMLayer(layer); var connector:WMSConnector = WMSConnector(wmLayer.getMapConnector()); //trace("layer = " + wmLayer.getName() + " isQueryable = " + connector.isQueryable(wmLayer.getName()) + " hasMaptip = " + wmLayer.hasMaptip()); if (connector.isQueryable(wmLayer.getName()) && wmLayer.hasMaptip()) { var url:String = connector.getFeatureInfo(wmLayer, gis.getCurrentCentreScale(), Stage.width, Stage.height, gis, lastX, lastY); if(url != null) { var xmlServer:XMLServer = new XMLServer(url); xmlServer.load(wmLayer, "", {postproces: "maptip", callbackCounter: callbackCounter}); noofMaptipLayers += 1; maptipLayers.push(wmLayer); } } } } if (noofMaptipLayers > 0) { callbackCounter.setCounter(noofMaptipLayers); } else { busyCollectingMaptips = false; } } public function selectMaptipFromGfiResponses():Void { var tipToShow:String = null; busyCollectingMaptips = false; if (maptipCancelled) { return; } for(var i:Number = 0; i < maptipLayers.length; i++) { var wmLayer:WMLayer = WMLayer(maptipLayers[i]); if (wmLayer.getMaptip() != undefined && wmLayer.getMaptip().length > 0) { tipToShow = wmLayer.getMaptip(); break; } } //trace("tipToShow = " + tipToShow); if (tipToShow != undefined) { if (parentMovie["mapTip"] == null) { parentMovie.attachMovie("GeoideTip", "mapTip", 6, {displayShadow: true, faceColor: "0xffdaae", borderColor: "0x000000", useFade: true}); } parentMovie["mapTip"].displayText = tipToShow; parentMovie["mapTip"].displayToolTip(); } else { parentMovie["mapTip"].removeToolTip(); } } }