﻿
// ############################################################
// GetFeatureInfo
// ############################################################
function GetFeatureInfo(featureName, featureKey) {
    var feaInfo = new FeatureInfo();

    // Create a new XMLHttpRequest object...
    var xmlHttp = GetXMLHttpRequest();
    var sessionId = _SESSION_ID;
    var mapDefinition = _MAP_DEFINITION;

    // Send the request...
    xmlHttp.open("GET", "../MapGuide/AjaxApi.aspx?sessionId=" + sessionId + "&mapDefinition=" + mapDefinition + "&featureName=" + featureName + "&featureKey=" + featureKey + "&command=FETCH_FEATURE_INFO", false);
    xmlHttp.send(null);

    // Parse the response...
    if (xmlHttp.responseXML) {
        var xmlDoc = xmlHttp.responseXML.documentElement;
        try {
            feaInfo.Type = xmlDoc.getElementsByTagName('Type')[0].firstChild.data;
            feaInfo.CentroidX = xmlDoc.getElementsByTagName('CentroidX')[0].firstChild.data;
            feaInfo.CentroidY = xmlDoc.getElementsByTagName('CentroidY')[0].firstChild.data;
            feaInfo.SelectionPointX = xmlDoc.getElementsByTagName('SelectionPointX')[0].firstChild.data;
            feaInfo.SelectionPointY = xmlDoc.getElementsByTagName('SelectionPointY')[0].firstChild.data;
            feaInfo.ZoomToScale = xmlDoc.getElementsByTagName('ZoomToScale')[0].firstChild.data;
            feaInfo.LayerName = xmlDoc.getElementsByTagName('LayerName')[0].firstChild.data;
        }
        catch (e) {
            ;
        }
    }

    return feaInfo;
}

// ############################################################
// DisplayFeatureTooltip
// ############################################################
function DisplayFeatureTooltip(layerId, featureKey, x, y) {
    // Create a new XMLHttpRequest object...
    var xmlHttp = GetXMLHttpRequest();

    // Define the response handler...
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            var tooltip = xmlHttp.responseText;

//            window.top.GetMapViewerFrame().frames.item("mapFrame").hlData.ttip = tooltip;
//            window.top.GetMapViewerFrame().frames.item("mapFrame").DisplayHyperlinkTip(x + window.top.GetMapViewerFrame().frames.item("mapFrame").mapPosX, y);
            window.top.GetMapViewerFrame().frames["mapFrame"].hlData.ttip = tooltip;
            window.top.GetMapViewerFrame().frames["mapFrame"].DisplayHyperlinkTip(x + window.top.GetMapViewerFrame().frames["mapFrame"].mapPosX, y);
        }
    }

    var sessionId = _SESSION_ID;
    var mapDefinition = _MAP_DEFINITION;

    // Make the request...
    xmlHttp.open("GET", "../MapGuide/AjaxApi.aspx?sessionId=" + sessionId + "&mapDefinition=" + mapDefinition + "&layerId=" + layerId + "&featureKey=" + featureKey + "&command=FETCH_TOOLTIP", true);
    xmlHttp.send(null);

}

