﻿
// ############################################################
// SelectAndZoomToSingleFeature
// ############################################################
// NOT CURRENTLY BEING USED IN BGIS APP (BOB - 10/20/2009)
function SelectAndZoomToSingleFeature(featureName, featureKey) {
    // Create a new XMLHttpRequest object...
    var xmlHttp = GetXMLHttpRequest();
    var sessionId = _SESSION_ID;
    var mapDefinition = _MAP_DEFINITION;

    // Define the response handler...
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            // Select the feature on the server side...
            var selectionXML = xmlHttp.responseText;
            if (selectionXML.length > 0) {
                // Zoom to the selected feature...
                var featureInfo = GetFeatureInfo(featureName, featureKey);

                var x1 = String(parseFloat(featureInfo.SelectionPointX) - 2);
                var y1 = String(parseFloat(featureInfo.SelectionPointY) - 2);
                var x2 = String((parseFloat(featureInfo.SelectionPointX) - 2) + 4);
                var y2 = String((parseFloat(featureInfo.SelectionPointY) - 2) + 4);

                RequestPointSelection(x1, y1, x2, y2, false, featureInfo.LayerName);

                if (featureInfo.ZoomToScale.toUpperCase() == "AUTO") {
                    // Zoom other feature types to the default scale...
                    GetMapFrame().ZoomSelection();
                }
                else {
                    // Zoom points to a fixed scale...
                    //These both work, however, you need to cast the parameters as float with MGE2010...
                    //GetMapFrame().ZoomToView(parseFloat(featureInfo.CentroidX), parseFloat(featureInfo.CentroidY), parseFloat(featureInfo.ZoomToScale), 1);
                    GetMapFrame().GotoView(parseFloat(featureInfo.CentroidX), parseFloat(featureInfo.CentroidY), parseFloat(featureInfo.ZoomToScale), true, true);
                    
                }
            }
            else {
                alert("Unable to zoom to the selected feature.");
            }
        }
    }

    // Make the request...
    xmlHttp.open("GET", "../MapGuide/AjaxApi.aspx?sessionId=" + sessionId + "&mapDefinition=" + mapDefinition + "&featureName=" + featureName + "&featureKey=" + featureKey + "&command=SELECT_ONE_FEATURE", true);
    xmlHttp.send(null);
}

// ############################################################
// SelectSingleFeature
// ############################################################
function SelectSingleFeature(featureName, featureKey) {
    // Create a new XMLHttpRequest object...
    var xmlHttp = GetXMLHttpRequest();
    var sessionId = _SESSION_ID;
    var mapDefinition = _MAP_DEFINITION;
    // Define the response handler...
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4) {
            // Select the feature on the server side...
            var selectionXML = xmlHttp.responseText;
            if (selectionXML.length > 0) {
                // Zoom to the selected feature...
                var featureInfo = GetFeatureInfo(featureName, featureKey);

                var x1 = String(parseFloat(featureInfo.SelectionPointX) - 2);
                var y1 = String(parseFloat(featureInfo.SelectionPointY) - 2);
                var x2 = String((parseFloat(featureInfo.SelectionPointX) - 2) + 4);
                var y2 = String((parseFloat(featureInfo.SelectionPointY) - 2) + 4);

                RequestPointSelection(x1, y1, x2, y2, false, featureInfo.LayerName);
            }
            else {
                alert("Unable to select the feature.");
            }
        }
    }

    // Make the request...
    xmlHttp.open("GET", "../MapGuide/AjaxApi.aspx?sessionId=" + sessionId + "&mapDefinition=" + mapDefinition + "&featureName=" + featureName + "&featureKey=" + featureKey + "&command=SELECT_ONE_FEATURE", true);
    xmlHttp.send(null);
}

// ############################################################
// SelectSingleFeatureSynchronously
// ############################################################
function SelectSingleFeatureSynchronously(featureName, featureKey) {
    // Create a new XMLHttpRequest object...
    var xmlHttp = GetXMLHttpRequest();
    var sessionId = _SESSION_ID;
    var mapDefinition = _MAP_DEFINITION;
    
    // Make the request...
    xmlHttp.open("GET", "../MapGuide/AjaxApi.aspx?sessionId=" + sessionId + "&mapDefinition=" + mapDefinition + "&featureName=" + featureName + "&featureKey=" + featureKey + "&command=SELECT_ONE_FEATURE", false);
    xmlHttp.send(null);

    if (xmlHttp.readyState == 4) {
        if (xmlHttp.responseXML) {
            // Select the feature on the server side...
            var selectionXML = xmlHttp.responseText;
            if (selectionXML.length > 0) {
                // Zoom to the selected feature...
                var featureInfo = GetFeatureInfo(featureName, featureKey);

                var x1 = String(parseFloat(featureInfo.SelectionPointX) - 2);
                var y1 = String(parseFloat(featureInfo.SelectionPointY) - 2);
                var x2 = String((parseFloat(featureInfo.SelectionPointX) - 2) + 4);
                var y2 = String((parseFloat(featureInfo.SelectionPointY) - 2) + 4);

                RequestPointSelection(sessionId, x1, y1, x2, y2, false, featureInfo.LayerName);
            }
            else {
                alert("Unable to select the feature.");
            }
        }
    }
}

