Common_MapTips_VBNet\JavaScript\CoincidentFeatureFunctions.js
Copyright 2010 ESRI All rights reserved under the copyright laws of the United States and applicable international laws, treaties, and conventions. You may freely redistribute and use this sample code, with or without modification, provided you include the original copyright notice and use restrictions. See <a href="http://help.arcgis.com/en/sdk/10.0/usageRestrictions.htm">the use restrictions</a>. ESRI.ADF.Graphics.GraphicFeatureGroup.prototype.add_coincidentFeaturesMouseOver = function(handler) { this.get_events().addHandler('coincidentFeaturesMouseOver', handler); if (!this._coincidentFeatureMouseOverEnabled) { for (var i = 0; i < this.getFeatureCount(); i++) { this.get(i).add_mouseOver(this._raiseCoincidentFeaturesEvent); this.get(i)._parentGroupID = this.get_id(); } this._coincidentFeatureMouseOverEnabled = true; } } ESRI.ADF.Graphics.GraphicFeatureGroup.prototype.remove_coincidentFeaturesMouseOver = function(handler) { this.get_events().removeHandler('coincidentFeaturesMouseOver', handler); if (this._coincidentFeatureMouseOverEnabled) { for (var i = 0; i < this.getFeatureCount(); i++) { this.get(i).remove_mouseOver(this._raiseCoincidentFeaturesEvent); } this._coincidentFeatureMouseOverEnabled = false; } } ESRI.ADF.Graphics.GraphicFeatureGroup.prototype._raiseCoincidentFeaturesEvent = function(sender) { if (!sender._parentGroupID) return; if (!ESRI.ADF.Geometries.Point.isInstanceOfType(sender.get_geometry())) return; var graphicFeatureGroup = $find(sender._parentGroupID); var coincidentFeatures = graphicFeatureGroup.findCoincidentFeatures(sender); var eventArgs = { 'coincidentFeatures':coincidentFeatures } graphicFeatureGroup._raiseEvent('coincidentFeaturesMouseOver', eventArgs); } // Gets graphicFeatures from the passed-in graphicFeatureGroup that have centers that intersect the // symbol envelope of the passed-in graphicFeature ESRI.ADF.Graphics.GraphicFeatureGroup.prototype.findCoincidentFeatures = function (graphicFeature) { var coincidentFeatures = new Array(); // Get the envelope of the graphic feature's symbol var graphicFeatureEnvelope = graphicFeature.getScreenEnvelope(true); if (!graphicFeatureEnvelope) return; // Find the graphic features in the current graphicFeatureGroup that have centers within the // symbol envelope of the moused over feature for (var i = 0; i < this.getFeatureCount(); i++) { var targetGraphicFeature = this.get(i); // Get the envelope of the center of the loop feature var targetGraphicEnvelope = targetGraphicFeature.getScreenEnvelope(false); // If the symbol envelope of the passed-in feature and the center envelope of the loop // feature intersect, add the loop feature to the array of coincident features if (graphicFeatureEnvelope.intersects(targetGraphicEnvelope)) { if (targetGraphicFeature.get_id() == graphicFeature.get_id()) coincidentFeatures.splice(0, 0, targetGraphicFeature); else coincidentFeatures.push(targetGraphicFeature); } } return coincidentFeatures; } // Retrieves an envelope of either the graphicFeature's symbol or its center. // The bounds of the envelope are in screen pixels. ESRI.ADF.Graphics.GraphicFeature.prototype.getScreenEnvelope = function(getSymbolEnvelope) { var xMin; var xMax; var yMin; var yMax; // Check whether the passed-in graphicFeature has a symbol defined. If so, use it to determine the // envelope. If not, use the graphicFeature's HTML DOM element. var symbol = this.get_symbol(); if (symbol) { // use the graphic feature's ADF MarkerSymbol var symbolWidth = symbol.get_width(); var symbolHeight = symbol.get_height(); if (getSymbolEnvelope) { // Get the bounds for the graphic feature's symbol xMin = symbol.offsetX; xMax = symbol.offsetX + symbolWidth; yMin = symbol.offsetY; yMax = symbol.offsetY + symbolHeight; } else { // Get the graphic feature's center point xMin = symbol.offsetX + (symbolWidth / 2); xMax = symbol.offsetX + (symbolWidth / 2); yMin = symbol.offsetX + (symbolHeight / 2); yMax = symbol.offsetX + (symbolHeight / 2); } } else { // use the graphic feature's HTML DOM element var graphicElement = this.get_graphicReference(); if (!graphicElement) return; var graphicElementWidth = graphicElement.offsetWidth; var graphicElementHeight = graphicElement.offsetHeight; if (getSymbolEnvelope) { // Get the bounds for the graphic feature's symbol xMin = graphicElement.offsetLeft; xMax = graphicElement.offsetLeft + graphicElementWidth; yMin = graphicElement.offsetTop; yMax = graphicElement.offsetTop + graphicElementHeight; } else { // Get the graphic feature's center point xMin = graphicElement.offsetLeft + (graphicElementWidth / 2); xMax = graphicElement.offsetLeft + (graphicElementWidth / 2); yMin = graphicElement.offsetTop + (graphicElementHeight / 2); yMax = graphicElement.offsetTop + (graphicElementHeight / 2); } } // Return an envelope with the calculated bounds return new ESRI.ADF.Geometries.Envelope(xMin, yMin, xMax, yMax); }