/** * Fusion.Widget.Maptip2 * * $Id: $ * * Portions copyright (c) 2007, DM Solutions Group Inc. * Portions copyright (c) 2008, ENPLAN * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ /******************************************************************** * Class: Fusion.Widget.Maptip * * Displays tooltips over the map when the mouse is hovered for some * time. On the MapGuide platform, you must configure tooltips for * each layer using Studio or Web Studio by editing the LayerDefinition * Settings and specifying an expression for the tooltip. MapServer users * can instead specify which attribute fields in the layer are to be used * for the maptip text and optional hyperlink. * * * Delay (optional) * * This is the delay, in milliseconds, that the user must keep the mouse * in the same position in order for the maptip to appear. The default, * if not specified, is 350 milliseconds. * * Layer * * -MapGuide(optional, multiple): This is the name of a layer from the MapDefinition * to get the tooltip from. If no Layer elements are specified, then all layers * will be queried and the top-most one will be displayed. Multiple Layer * tags can be added, allowing tooltips to come from different layers. * * -Mapserver(required): This is the name of a layer from the MapFile whose attributes * will be used to populate the maptip text. Mapserver only supports a single layer. * If more than one layer is specified, only the first will be used. * * Textfield (required for MapServer only) * * Field to use for the maptip text for MapServer-based Fusion installs. * Since this is not specified server-side, as in MapGuide, it must be * declared here. * * Linkfield (optional for MapServer only) * * Field to use for the maptip hyperlink target URL on MapServer fusion installs. * As with Textfield above, it must be declared here if needed. * * **********************************************************************/ Fusion.Widget.Maptip2 = OpenLayers.Class(Fusion.Widget, { oCurrentPosition: null, oMapTipPosition: null, nTimer: null, delay: null, aLayers: null, bOverTip: false, textField: null, linkField: null, customURL: null, sWinFeatures : 'menubar=no,location=no,resizable=no,status=no', initializeWidget: function(widgetTag){ // console.log("maptipStarted"); // Object.inheritFrom(this, Fusion.Widget.prototype, [widgetTag, true]); var json = widgetTag.extension; this.sTarget = json.Target ? json.Target[0] : "MaptipWindow"; if (json.WinFeatures) { this.sWinFeatures = json.WinFeatures[0]; } this.delay = json.Delay ? parseInt(json.Delay[0]) : 350; this.nTolerance = json.Tolerance ? parseInt(json.Tolerance[0]) : 2; this.aLayers = []; if (json.Layer) { for (var i=0; i"); if (h != '') { var linkDiv = document.createElement('div'); var a = document.createElement('a'); a.innerHTML = t; a.href = 'javascript:void(0)'; a.url = h; a.onclick = this.openLink.bindAsEventListener(a); linkDiv.appendChild(a); contentDiv.appendChild(linkDiv); empty = false; } else { contentDiv.innerHTML = t; empty = false; } } if (!empty) { this.domObj.style.visibility = 'hidden'; this.domObj.style.display = 'block'; var size = Element.getCoordinates(this.domObj); // 5 pixels offset added to clear the div from the mouse var mapOffsetX = this.getMap()._oDomObj.offsets[0]; var mapOffsetY= this.getMap()._oDomObj.offsets[1]; this.domObj.style.top = (this.oCurrentPosition.y ) + 'px'; this.domObj.style.left = (this.oCurrentPosition.x )+ 'px'; if (!window.opera) { contentDiv.appendChild(this.iframe); var size = Element.getContentBoxSize(this.domObj); this.iframe.style.width = size.width + "px"; this.iframe.style.height = size.height + "px"; } this.domObj.style.visibility = 'visible'; //console.log("maptip visible"); } else { this.hideMaptip(); } } else { this.bIsVisible = false; this.hideMaptip(); } }, hideMaptip: function() { //console.log('hideMaptip'); this.bIsVisible = false; this.hideTimer = window.setTimeout(this._hide.bind(this),10); }, _hide: function() { //console.log('maptip _hide'); this.hideTimer = null; this.domObj.style.display = 'none'; //this.oMapTipPosition = null; }, mouseOverTip: function() { //console.log('mouseOverTip'); window.clearTimeout(this.nHideTimer); this.nHideTimer = null; this.bOverTip = true; }, mouseOutTip: function() { //console.log('mouseOutTip'); this.nHideTimer = window.setTimeout(this.hideMaptip.bind(this), 250); this.bOverTip = false; }, openLink : function(evt) { var url = this.url; var taskPaneTarget = Fusion.getWidgetById(this.sTarget); if ( taskPaneTarget ) { taskPaneTarget.setContent(url); } else { var pageElement = $(this.sTarget); if ( pageElement ) { pageElement.src = url; } else { window.open(url, this.sTarget, this.sWinFeatures); } } OpenLayers.Event.stop(evt, true); return false; } } );