pavanpuligandla

Unable to get latlang values returned by javascript on server side

Discussion created by pavanpuligandla on Apr 7, 2013
Hello All,

I'm having an ArcGIS map and when i click on the save button by entering details, I'm calling a javascript function which checks for whether the input lat lang values are inside/outside the state or not. On save button click event, I'm calling a function that returns the latlang values fall under the state or not. That function is linked to 8 other chained javascript functions.

Before getting the result from the javascript, my server side page is getting loaded. How to return the value from this function? Please help me out. Below is the code;

QuerString("", "", Coordinates, flag);


function QuerString(wherecond, layerid, coordinates, flag) {

    wherecon = wherecond;
    querylayer = layerid;
    var str = NOMLOC;

    if (flag == false) {
        showpod = false;
    }
    else {
        showpod = true;
    }

    if (wherecond.indexOf(str) != -1) {
        qtrqtrflag = true;
        latlongpoint = null;
    }
    else {
        latlongpoint = "";
    }

    if (coordinates == "") {
        return ShowPOD(wherecond, layerid);
    }
    else {
        GetMapPoint(coordinates);
    }
}


function GetMapPoint(coordinates) {

    var gsvc = new esri.tasks.GeometryService("http://wsiedngissrvr/WSIPL/rest/services/Geometry/GeometryServer");
    var m_mapPoint = new Array(1);
    m_mapPoint[0] = null;

    if (coordinates != null) {
        var strCoordinates = coordinates.toString().split(":");

        strCoorSys = strCoordinates[0];
        if (strCoorSys == "GCS") {
            var strLat = strCoordinates[1];
            var strLong = strCoordinates[2];
            var strDatum = strCoordinates[3];

            var latTokens = strLat.toString().split(",");

            _LatDeg = parseInt(latTokens[0]);
            _LatMin = parseInt(latTokens[1]);
            _LatSec = parseFloat(latTokens[2]);

            var langTokens = strLong.toString().split(",");

            _LongDeg = parseInt(langTokens[0]);
            _LongMin = parseInt(langTokens[1]);
            _LongSec = parseFloat(langTokens[2]);


            var latutude = ConvertDMSToDD(_LatDeg, _LatMin, _LatSec, "latitude");
            var longitude = ConvertDMSToDD(_LongDeg, _LongMin, _LongSec, "longitude");

            if (strDatum == "83") {
                m_mapPoint = new esri.geometry.Point(longitude, latutude, new esri.SpatialReference({ wkid: 4269 }));
            }
            else {
                m_mapPoint = new esri.geometry.Point(longitude, latutude, new esri.SpatialReference({ wkid: 4267 }));
            }
            GetState(m_mapPoint);

        }
        if (strCoorSys == "LatLong") {
            var strdatum = strCoordinates[1];
            var strUnits = strCoordinates[2];
            var strLat = strCoordinates[3];
            var strLong = strCoordinates[4];

            if (strLong.match(/^-\d+$/)) {
                strLong = strLong;
            }
            else {
                strLong = strLong * -1;
            }
            m_mapPoint = new esri.geometry.Point(parseFloat(strLong), parseFloat(strLat), new esri.SpatialReference({ wkid: 4269 }));

            GetState(m_mapPoint);

        }
        if (strCoorSys == "UTM") {
            var strdatum = strCoordinates[1];
            var strUnits = strCoordinates[2];
            var strUtmZone = strCoordinates[3];
            var strEasting = strCoordinates[4];
            var strNorthing = strCoordinates[5];

            if (strdatum == "83" && strUnits == "M") {

                var UTMMtsE83 = parseFloat(strEasting.replace(/,/g, ""));
                var UTMMtsN83 = parseFloat(strNorthing.replace(/,/g, ""));

                if (strUtmZone == "12") {
                    m_mapPoint[0] = new esri.geometry.Point(UTMMtsN83, UTMMtsE83, new esri.SpatialReference({ wkid: 26912 }));
                }
                else {
                    m_mapPoint[0] = new esri.geometry.Point(UTMMtsN83, UTMMtsE83, new esri.SpatialReference({ wkid: 26913 }));
                }

            }
            if (strdatum == "83" && strUnits == "U") {

                var UTMMtsE83 = ConvertFeetToMeter(parseFloat(strEasting.replace(/,/g, "")));
                var UTMMtsN83 = ConvertFeetToMeter(parseFloat(strNorthing.replace(/,/g, "")));

                if (strUtmZone == "12") {
                    m_mapPoint[0] = new esri.geometry.Point(UTMMtsN83, UTMMtsE83, new esri.SpatialReference({ wkid: 26912 }));
                }
                else {
                    m_mapPoint[0] = new esri.geometry.Point(UTMMtsN83, UTMMtsE83, new esri.SpatialReference({ wkid: 26913 }));
                }

            }
            if (strdatum == "27" && strUnits == "U") {

                var UTMMtsE27 = ConvertFeetToMeter(parseFloat(strEasting.replace(/,/g, "")));
                var UTMMtsN27 = ConvertFeetToMeter(parseFloat(strNorthing.replace(/,/g, "")));

                if (strUtmZone == "12") {
                    m_mapPoint[0] = new esri.geometry.Point(UTMMtsN27, UTMMtsE27, new esri.SpatialReference({ wkid: 26712 }));
                }
                else {
                    m_mapPoint[0] = new esri.geometry.Point(UTMMtsN27, UTMMtsE27, new esri.SpatialReference({ wkid: 26713 }));
                }
            }
            if (strdatum == "27" && strUnits == "M") {

                var UTMMtsE27 = parseFloat(strEasting.replace(/,/g, ""));
                var UTMMtsN27 = parseFloat(strNorthing.replace(/,/g, ""));

                if (strUtmZone == "12") {
                    m_mapPoint[0] = new esri.geometry.Point(UTMMtsN27, UTMMtsE27, new esri.SpatialReference({ wkid: 26712 }));
                }
                else {
                    m_mapPoint[0] = new esri.geometry.Point(UTMMtsN27, UTMMtsE27, new esri.SpatialReference({ wkid: 26713 }));
                }
            }

            if (m_mapPoint[0] != null) {
                var resultparams = null;
                if (strdatum == "83") {
                    var outSR = new esri.SpatialReference({ wkid: 4269 });
                }
                else {
                    var outSR = new esri.SpatialReference({ wkid: 4267 });
                }
                resultparams = convertMMappointToMapPoint(m_mapPoint, outSR);
                gsvc.project(resultparams, GetState);
            }
        }

        if (strCoorSys == "SPCS") {

            var strdatum = strCoordinates[1];
            var strUnits = strCoordinates[2];
            var strSpcsZone = strCoordinates[3];
            var strSpcsX = strCoordinates[4];
            var strSpcsY = strCoordinates[5];

            if (strdatum == "83" && strUnits == "M") {

                var WCSMtsN = parseFloat(strSpcsX.replace(/,/g, ""));
                var WCSMtsE = parseFloat(strSpcsY.replace(/,/g, ""));

                if (strSpcsZone == "E") {
                    m_mapPoint[0] = new esri.geometry.Point(WCSMtsN, WCSMtsE, new esri.SpatialReference({ wkid: 32155 }));
                }
                else if (strSpcsZone == "EC") {
                    m_mapPoint[0] = new esri.geometry.Point(WCSMtsN, WCSMtsE, new esri.SpatialReference({ wkid: 32156 }));
                }
                else if (strSpcsZone == "W") {
                    m_mapPoint[0] = new esri.geometry.Point(WCSMtsN, WCSMtsE, new esri.SpatialReference({ wkid: 32158 }));
                }
                else {
                    m_mapPoint[0] = new esri.geometry.Point(WCSMtsN, WCSMtsE, new esri.SpatialReference({ wkid: 32157 }));
                }

            }
            if (strdatum == "83" && strUnits == "U") {

                var WCSMtsN = ConvertFeetToMeter(parseFloat(strSpcsX.replace(/,/g, "")));
                var WCSMtsE = ConvertFeetToMeter(parseFloat(strSpcsY.replace(/,/g, "")));

                if (strSpcsZone == "E") {
                    m_mapPoint[0] = new esri.geometry.Point(WCSMtsN, WCSMtsE, new esri.SpatialReference({ wkid: 102755 }));
                }
                else if (strSpcsZone == "EC") {
                    m_mapPoint[0] = new esri.geometry.Point(WCSMtsN, WCSMtsE, new esri.SpatialReference({ wkid: 102756 }));
                }
                else if (strSpcsZone == "W") {
                    m_mapPoint[0] = new esri.geometry.Point(WCSMtsN, WCSMtsE, new esri.SpatialReference({ wkid: 102758 }));
                }
                else {
                    m_mapPoint[0] = new esri.geometry.Point(WCSMtsN, WCSMtsE, new esri.SpatialReference({ wkid: 102757 }));
                }
            }

            if (m_mapPoint[0] != null) {
                var resultparams = null;
                if (strdatum == "83") {
                    var outSR = new esri.SpatialReference({ wkid: 4269 });
                }
                else {
                    var outSR = new esri.SpatialReference({ wkid: 4267 });
                }
                resultparams = convertMMappointToMapPoint(m_mapPoint, outSR);
                gsvc.project(resultparams, GetState);
            }
        }
    }

    return m_mapPoint;

}


function GetPlssdataForLatLong(latlongpoint) {

    if (latlongpoint != null) {
        if (document.getElementById('ddlGWControlORPArea') != null) {
            GetGWAreasFeature(latlongpoint);
        }
        GetLadDescFeature(latlongpoint);
        GetCounty(latlongpoint);
        GetZipCodeFeature(latlongpoint);
        GetDistrictFeature(latlongpoint);

    }
    else {
        document.getElementById("txtpod").Text = "Coordinates specified are falling outside the State.";
        document.getElementById('hfPlssError').value = "Coordinates specified are falling outside the State";        
    }
}

Outcomes