AnsweredAssumed Answered

Getting MGRS from a selected graphic

Question asked by farschr on Jun 18, 2015
Latest reply on Jun 19, 2015 by LDanzinger-esristaff

I'm trying to get the MGRS string for a selected graphic in a graphic layer. I thought it would be fairly straight forward, but I'm getting an empty string from the toMgrs() call. I have two cases - Case A using 'var' for the Point, and Case B using 'property' for Point. When I try using project() on the point, I get a null. I appreciate any help. Here's the code:

        onFindGraphicsComplete: {

            unselectGraphic(selectedGraphicID)
            if (graphicIDs.length > 0) {
                selectedGraphicID = graphicIDs[0]
                selectGraphic(selectedGraphicID)
                if (isGraphicSelected(selectedGraphicID)) {

 

                    var selectedGraphic = graphic(selectedGraphicID);
// Case A: (using 'var')
                    var dummyPoint1 = selectedGraphic.geometry;
                    console.log("X_X: ", dummyPoint1.x, ", Y_Y: ", dummyPoint1.y);
//                    var dummyPoint2 = dummyPoint1.project(mainMap.spatialReference);
//                    console.log("X_X_X: ", dummyPoint2.x, ", Y_Y_Y: ", dummyPoint2.y);
                    console.log("MGRS: ", dummyPoint1.toMgrs(0, 10, false, false));
// Case B: (using 'property Point dummyPoint1_property', property Point dummyPoint2_property)
                    /*
                    dummyPoint1_property = selectedGraphic.geometry;
                    console.log("X_X: ", dummyPoint1_property.x, ", Y_Y: ", dummyPoint1_property.y);
                    dummyPoint2_property = dummyPoint1_property.project(mainMap.spatialReference);
                    console.log("X_X_X: ", dummyPoint2_property.x, ", Y_Y_Y: ", dummyPoint2_property.y);
                    console.log("MGRS: ", dummyPoint2_property.toMgrs(1, 10, false, false));
                    */
                }
            }
        }

Outcomes