﻿// 9.3 Beta Ext Issue fix - commented out to test against 9.3 final
//ESRI.ADF.UI.MapBase.prototype._removePendingStackStartingWith = function(id,removeImg,suppressEvent) {
 //  Array.forEach(this._requestStack, function(imgid,index,arr) {if(imgid.startsWith(id)) { this._removePendingStack(imgid,removeImg,suppressEvent); }},this);
//}; 

// ========================================================================
//9.3 final release -- fix for Bergmann Identify tool
ESRI.ADF.Graphics.__AdfGraphicsLayer.parseJsonLayer = function(json,map) {
	/// <summary>
	/// Helper method for parsing a GraphicsLayer serialized on the server,
	/// into a ESRI.ADF.Graphics.GraphicFeatureGroup.
	/// </summary>
	var obj = Sys.Serialization.JavaScriptSerializer.deserialize(json);
	var name = map.get_id() + '_' + obj.tableName;
	var type = obj.type;
	var rows = obj.rows;
	var titleTemplate = obj.title;
	var contentTemplate = obj.contents;
	var opacity = (obj.opacity || obj.opacity===0?obj.opacity:1);
	var visible = (obj.visible!==false);
	var enableCallout = false; // (obj.enableCallout!==false);
	var layer = null;
	var ftype = ESRI.ADF.Geometries.Geometry;
	var symbol = null;
	var selectedSymbol = null;
	var highlightSymbol = null;	
	if(type === 'featureGraphicsLayer')
	{
		switch(obj.featureType) {
			case 'point':
				type = ESRI.ADF.Geometries.Point;
				break;
			case 'line':
				type = ESRI.ADF.Geometries.Line;
				break;
			case 'polygon':
				type = ESRI.ADF.Geometries.Polygon;
				break;
			default:
		}
		symbol = ESRI.ADF.Graphics.__AdfGraphicsLayer._parseSymbol(obj.symbol);
		if(obj.selectedSymbol) { selectedSymbol = ESRI.ADF.Graphics.__AdfGraphicsLayer._parseSymbol(obj.selectedSymbol); }
		if(obj.highlightSymbol) { highlightSymbol = ESRI.ADF.Graphics.__AdfGraphicsLayer._parseSymbol(obj.highlightSymbol); }
	}
	layer = $find(name);
	if(layer) { 
		map.removeGraphic(layer);
		layer.clear();
		layer.set_visible(visible);
		layer.set_symbol(symbol);
		layer.set_selectedSymbol(selectedSymbol);
		layer.set_highlightSymbol(highlightSymbol);
	}
	else {
		layer = $create(ESRI.ADF.Graphics.GraphicFeatureGroup,{"id":name,"visible":visible,"symbol":symbol,"selectedSymbol":selectedSymbol,"highlightSymbol":highlightSymbol});
	}
	if(opacity!==null) { layer.set_opacity(opacity); }
	for(var idx in rows) {
	    // Ext JS bug fix
	    if (rows[idx].geometry)
	    {
		    var gfx = ESRI.ADF.Graphics.__AdfGraphicsLayer._parseRow(rows[idx],name);
		    layer.add(gfx);
		}
	}
	if(enableCallout) {
		var id = '__ESRI_WebADF_gfxLayerCallout_' + name;
		var callout = $find(id);
		if(!callout) {
			callout = $create(ESRI.ADF.UI.MapTips,{"animate":false,"hoverTemplate":titleTemplate,"contentTemplate":contentTemplate,"id":id});
		}
		else {
			callout.set_hoverTemplate(titleTemplate);
			callout.set_contentTemplate(contentTemplate);
		}
		layer.set_mapTips(callout);
	}
	else {
		var callout = layer.get_mapTips();
		if(callout) {
			layer.set_mapTips(null);
			callout.dispose();
		}
	}
	if(!ESRI.ADF.Graphics.__mapZoomEvent) {
		ESRI.ADF.Graphics.__mapZoomEvent = {};
		ESRI.ADF.Graphics._mapMouseOver = function(sender,args) {
			if(ESRI.ADF.Graphics._currentMouseHighlightElement) {
				ESRI.ADF.Graphics._currentMouseHighlightElement.set_highlight(false);
				ESRI.ADF.Graphics._currentMouseHighlightElement = null;
			}
			if(!args.element.get_highlight()) { //only highlight if not already highlighted
				args.element.set_highlight(true);
				ESRI.ADF.Graphics._currentMouseHighlightElement = args.element;
			}
		};
		ESRI.ADF.Graphics._mapMouseOut = function(sender,args) {
			if(ESRI.ADF.Graphics._currentMouseHighlightElement === args.element) { //Only un-highlight if a mouseover event highlighted it
				args.element.set_highlight(false);
				ESRI.ADF.Graphics._currentMouseHighlightElement = null;
			}
		};
	}
	layer.add_mouseOver(ESRI.ADF.Graphics._mapMouseOver);
	layer.add_mouseOut(ESRI.ADF.Graphics._mapMouseOut);
	if(!ESRI.ADF.Graphics.__mapZoomEvent[map.get_id()]) {
		ESRI.ADF.Graphics.__mapZoomEvent[map.get_id()] = true; //ensures we only hook up the event once
		map.add_zoomStart(function() {
			if(ESRI.ADF.Graphics._currentMouseHighlightElement) {
				 ESRI.ADF.Graphics._currentMouseHighlightElement.set_highlight(false);
				ESRI.ADF.Graphics._currentMouseHighlightElement=null;
			}
		});
	}
	return layer;
}; 

// END - 9.3 final release -- fix for Bergmann Identify tool
// ========================================================================