shrug-l: Coordinate Display in AGS 9.3

Sandell, Keith M. sandell.keith at mail.dc.state.fl.us
Tue Nov 18 15:54:24 EST 2008


Skipped content of type multipart/alternative-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.dep.state.fl.us/pipermail/shrug-l/attachments/20081118/c84c73af/warning.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Coord Conv.ziz
Type: application/octet-stream
Size: 5503 bytes
Desc: Coord Conv.ziz
Url : http://lists.dep.state.fl.us/pipermail/shrug-l/attachments/20081118/c84c73af/CoordConv.obj
-------------- next part --------------
Default.aspx ------------------------------------------------------------------------

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <!--Add Update Panel and hidden inputs-->
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
             <ContentTemplate>
            <input id="extTop" runat="server" name="top" style="width: 43px; height: 22px" type="hidden" />
            <input id="extLeft" runat="server" name="left" style="width: 48px; height: 22px" type="hidden" />
            <input id="extBottom" runat="server" name="bottom" style="width: 40px; height: 22px" type="hidden" />
            <input id="extRight" runat="server" name="right" style="width: 48px; height: 22px" type="hidden" />&nbsp;
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>

Default.aspx.vb----------------------------------------------------------------------

Private Sub UpdateExtentValuesUsingGeometryService()
    Dim ws As GeometryService.Geometry_GeometryServer = New GeometryService.Geometry_GeometryServer()
    Dim srIn As GeometryService.SpatialReference
    'Change input spatial reference here: http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jsapi_start.htm#jsapi/spatialreference.htm
    srIn = ws.FindSRByWKID(Nothing, 3087, -1, True, True)
    Dim srOut As GeometryService.SpatialReference
    'Change output spatial reference here: same page as above
    srOut = ws.FindSRByWKID(Nothing, 4269, -1, True, True)
    Dim inGeom() As GeometryService.Geometry = {Nothing}
    Dim extC As ESRI.ArcGIS.ADF.Web.Geometry.Envelope = Map1.Extent
    Dim extCurrent As GeometryService.EnvelopeN = New GeometryService.EnvelopeN()
    extCurrent.XMin = extC.XMin
    extCurrent.YMin = extC.YMin
    extCurrent.XMax = extC.XMax
    extCurrent.YMax = extC.YMax
    inGeom.SetValue(extCurrent, 0)
    Dim outGeom() As GeometryService.Geometry = {Nothing}
    outGeom = ws.Project(srIn, srOut, False, Nothing, Nothing, inGeom)
    Dim extProjected As GeometryService.EnvelopeN
    extProjected = TryCast(outGeom.GetValue(0), GeometryService.EnvelopeN) 'should only be one ...
    Me.extLeft.Value = extProjected.XMin
    Me.extBottom.Value = extProjected.YMin
    Me.extTop.Value = extProjected.YMax
    Me.extRight.Value = extProjected.XMax

End Sub


Protected Sub Map1_ExtentChanged(ByVal sender As Object, ByVal args As ESRI.ArcGIS.ADF.Web.UI.WebControls.ExtentEventArgs) Handles Map1.ExtentChanged
    UpdateExtentValuesUsingGeometryService()
End Sub

Display_measure.js------------------------------------------------------------------

// Handler for MeasurePoint clicks
function MapCoordsClick(geom, evtArgs) {
	var geomString = '';
	var type = '';
    removeMeasureGraphic();
    var style = null; 
	if(ESRI.ADF.Geometries.Point.isInstanceOfType(geom)) {
		//Get point click in decimal degrees, change decimal precision set to 6 in next line.
        var coordString = getCoordsDD(geom.get_x(),geom.get_y(),6); //function is in "WebMapApp.js"
        var ddCoords = coordString.split("|");
        var ddX = ddCoords[0];
        var ddY = ddCoords[1];
		geomString = ddX+":"+ddY; // geom.toString(':');
		type = 'point';
		style = new ESRI.ADF.Graphics.MarkerSymbol("images/crosshair.png",6,6);
	}
	else if(ESRI.ADF.Geometries.Polyline.isInstanceOfType(geom)) {
		geomString = geom.getPath(0).toString('|',':');
		type = 'polyline';
		style = new ESRI.ADF.Graphics.LineSymbol("black",2);
	}
	else if(ESRI.ADF.Geometries.Polygon.isInstanceOfType(geom)) {
		geomString = geom.getRing(0).toString('|',':');
		type = 'polygon';
		style = new ESRI.ADF.Graphics.FillSymbol("black","black",2);	
		style.set_opacity(0.2);	
	}
	m_measureGraphicFeature = $create(ESRI.ADF.Graphics.GraphicFeature,
		        {"id": "MeasurePointIcon","geometry":geom,"symbol":style});
	map.addGraphic(m_measureGraphicFeature);        
	coordString = geomString;
	  	
	m_measureLastCoords = m_measureCoords;
	m_measureCoords = "";
	var argument = 'ControldID='+map.get_id()+'&EventArg='+type+'&coords='+geomString+'&VectorMode=measure';	
    if (checkForFormElement(document, 0, "MeasureUnits")) argument += "&MeasureUnits=" + document.forms[0].MeasureUnits.value;
    if (checkForFormElement(document, 0, "AreaUnits")) argument += "&AreaUnits=" + document.forms[0].AreaUnits.value;
    if (checkForFormElement(document, 0, "MapUnits")) argument += "&MapUnits=" + document.forms[0].MapUnits.options[document.forms[0].MapUnits.selectedIndex].value;

	var context = this;
	eval(measureVectorCallbackFunctionString);
}

Measure.ascx.vb----------------------------------------------------------------------

Public Function ProcessMeasureRequest(ByVal queryString As NameValueCollection) As String
    If m_mapFunctionality Is Nothing Then GetMeasureResource()

    Dim o As Object = Session("MeasureMapUnits")
    If Not (o Is Nothing) Then
        m_mapUnits = CType([Enum].Parse(GetType(MapUnit), o.ToString()), MapUnit)
    ElseIf m_startMapUnits = MapUnit.Resource_Default Then
        m_mapUnits = GetResourceDefaultMapUnit()
    Else
        m_mapUnits = m_startMapUnits
    End If
    Dim eventArg As String = queryString("EventArg").ToLower()
    Dim vectorAction As String = queryString("VectorMode").ToLower()
    Dim coordPairs(), xys() As String
    Dim coordString As String = queryString("coords")
    If coordString Is Nothing And coordString.Length = 0 Then
        coordString = ""
    End If

    coordPairs = coordString.Split(Char.Parse("|"))
    Dim mapUnitString As String = queryString("MapUnits")
    Dim forceRefresh As Boolean = (queryString("refresh") = "true")
    If mapUnitString Is Nothing Then mapUnitString = ""
    If mapUnitString.Length > 0 Then
        m_mapUnits = CType([Enum].Parse(GetType(MapUnit), mapUnitString), MapUnit)
    End If
    Session("MeasureMapUnits") = m_mapUnits
    Dim measureUnitString As String = queryString("MeasureUnits")
    If measureUnitString Is Nothing Then measureUnitString = ""
    If measureUnitString.Length > 0 Then m_measureUnits = CType([Enum].Parse(GetType(MeasureUnit), measureUnitString), MeasureUnit)
    Dim areaUnitstring As String = queryString("AreaUnits")
    If areaUnitstring Is Nothing Then areaUnitstring = ""
    If areaUnitstring.Length > 0 Then m_areaUnits = CType([Enum].Parse(GetType(AreaUnit), areaUnitstring), AreaUnit)
    Dim response As String = Nothing
    Dim points As New PointCollection()
    Dim dPoints As New PointCollection()
    Dim distances As New ArrayList()
    Dim totalDistance As Double = 0
    Dim segmentDistance As Double = 0
    Dim area As Double = 0
    Dim perimeter As Double = 0
    Dim roundFactor As Double = Math.Pow(10, m_numberDecimals)
    Dim xD, yD, tempDist, tempDist2, tempArea, x1, x2, y1, y2 As Double
    Dim transformationParameters As TransformationParams = m_map.GetTransformationParams(TransformationDirection.ToMap)
    If (vectorAction = "measure") Then

        If Not coordPairs Is Nothing And coordPairs.Length > 1 Then
            For cp As Integer = 0 To coordPairs.Length - 1
                xys = coordPairs(cp).Split(Char.Parse(":"))
                points.Add(New Point(Convert.ToDouble(xys(0), System.Globalization.CultureInfo.InvariantCulture), Convert.ToDouble(xys(1), System.Globalization.CultureInfo.InvariantCulture)))
                If cp > 0 Then
                    ' check for duplicate points from double click.... Firefox will send coords for both clicks, causing segmentDistance to be zero.
                    If (Not points(cp - 1).X = points(cp).X OrElse Not points(cp - 1).Y = points(cp).Y) Then
                        If m_mapUnits = MapUnit.Degrees Then
                            ' use great circle formula
                            tempDist = DegreeToFeetDistance(points(cp - 1).X, points(cp - 1).Y, points(cp).X, points(cp).Y)
                            y1 = DegreeToFeetDistance(points(cp).X, points(cp).Y, points(cp).X, 0)
                            x1 = DegreeToFeetDistance(points(cp).X, points(cp).Y, 0, points(cp).Y)
                            dPoints.Add(New Point(x1, y1))
                            segmentDistance = ConvertUnits(tempDist, MapUnit.Feet, m_measureUnits)
                        Else
                            ' get third side of triangle for distance
                            xD = Math.Abs(points(cp).X - points(cp - 1).X)
                            yD = Math.Abs(points(cp).Y - points(cp - 1).Y)
                            tempDist = Math.Sqrt(Math.Pow(xD, 2) + Math.Pow(yD, 2))
                            segmentDistance = ConvertUnits(tempDist, m_mapUnits, m_measureUnits)
                        End If
                        distances.Add(segmentDistance)
                        totalDistance += segmentDistance
                        segmentDistance = Math.Round(segmentDistance * roundFactor) / roundFactor
                        totalDistance = Math.Round(totalDistance * roundFactor) / roundFactor
                    End If
                Else
                    If (m_mapUnits = MapUnit.Degrees) Then
                        y1 = DegreeToFeetDistance(points(cp).X, points(cp).Y, points(cp).X, 0)
                        x1 = DegreeToFeetDistance(points(cp).X, points(cp).Y, 0, points(cp).Y)
                        dPoints.Add(New Point(x1, y1))
                    End If
                End If
            Next
        End If
        If (eventArg = "polygon") Then
            If (points.Count > 2 OrElse forceRefresh) Then
                If (m_mapUnits = MapUnit.Degrees) Then
                    tempDist = DegreeToFeetDistance(points(points.Count - 1).X, points(points.Count - 1).Y, points(0).X, points(0).Y)
                    tempDist2 = ConvertUnits(tempDist, MapUnit.Feet, m_measureUnits)
                    distances.Add(tempDist2)
                    dPoints.Add(dPoints(0))
                Else
                    xD = Math.Abs(points(points.Count - 1).X - points(0).X)
                    yD = Math.Abs(points(points.Count - 1).Y - points(0).Y)
                    tempDist = Math.Sqrt(Math.Pow(xD, 2) + Math.Pow(yD, 2))
                    tempDist2 = ConvertUnits(tempDist, m_mapUnits, m_measureUnits)
                    distances.Add(tempDist2)
                End If
                points.Add(points(0))
                perimeter = totalDistance + tempDist2
                ' add area calculation
                tempArea = 0
                Dim mUnits As MapUnit = m_mapUnits
                Dim xDiff As Double = 0
                Dim yDiff As Double = 0
                If (m_mapUnits = MapUnit.Degrees) Then
                    points = dPoints
                    mUnits = MapUnit.Feet
                End If
                For j As Integer = 0 To points.Count - 2
                    x1 = Convert.ToDouble(points(j).X, System.Globalization.CultureInfo.InvariantCulture)
                    x2 = Convert.ToDouble(points(j + 1).X, System.Globalization.CultureInfo.InvariantCulture)
                    y1 = Convert.ToDouble(points(j).Y, System.Globalization.CultureInfo.InvariantCulture)
                    y2 = Convert.ToDouble(points(j + 1).Y, System.Globalization.CultureInfo.InvariantCulture)
                    xDiff = x2 - x1
                    yDiff = y2 - y1
                    tempArea += x1 * yDiff - y1 * xDiff
                Next
                tempArea = Math.Abs(tempArea) / 2
                area = ConvertAreaUnits(tempArea, mUnits, m_areaUnits)
                perimeter = Math.Round(perimeter * roundFactor) / roundFactor
                area = Math.Round(area * roundFactor) / roundFactor
            Else
                response = String.Format("<table cellspacing='0' ><tr><td>Perimeter: </td><td align='right' id='tdperimiter'> 0</td><td >{0}</td></tr><tr><td>Area:</td><td align='right' id='tdarea'>0 </td><td>{1}</td></tr></table>", WriteMeasureUnitDropdown(), WriteAreaUnitDropdown())
            End If

        ElseIf (eventArg = "polyline") Then
            If points.Count < 3 OrElse forceRefresh Then
                response = String.Format("<table cellspacing='0' ><tr><td>Segment: </td><td align='right' id='tdsegment'>{0} </td><td>{1}</td></tr><tr><td>Total Length:</td><td align='right' id='tdtotaldistance'>{2} </td><td>{3}</td></tr></table>", segmentDistance, m_measureUnits.ToString(), totalDistance, WriteMeasureUnitDropdown())
            End If
        ElseIf (eventArg = "point" And coordPairs.Length > 0) Then
            xys = coordPairs(0).Split(Char.Parse(":"))
            'Modified the code below to prevent rounding of decimal places
            '  response = String.Format("<table cellspacing='0' ><tr><td>X Coordinate:</td><td align='right' dir='ltr'>{0}</td></tr><tr><td>Y Coordinate:</td><td align='right' dir='ltr'>{1}</td></tr></table>", (Math.Round(Convert.ToDouble(xys(0), System.Globalization.CultureInfo.InvariantCulture) * roundFactor) / roundFactor).ToString(), (Math.Round(Convert.ToDouble(xys(1), System.Globalization.CultureInfo.InvariantCulture) * roundFactor) / roundFactor).ToString())
            response = String.Format("<table cellspacing='0' ><tr><td>Longitude:</td><td align='right' dir='ltr'>{0}</td></tr><tr><td>Latitude:</td><td align='right' dir='ltr'>{1}</td></tr></table>", xys(0).ToString(), xys(1).ToString())
            'END
        End If
    End If
    Dim coll As CallbackResultCollection = New CallbackResultCollection()
    coll.Add(New CallbackResult("", "", "invoke", "measureComplete", _
     New Object() {response, m_id, area, perimeter, segmentDistance, totalDistance}))
    Return coll.ToString()
End Function

WebMapApp.js--------------------------------------------------------------------------

function MapCoordsMouseMove(sender, args) {
    var coords = args.coordinate;
    var roundFactor = Math.pow(10, arcgisWebApp.CoordsDecimals);
// show status bar coords in decimal degrees    
    var origX = coords.get_x();
    var origY =  coords.get_y();
    var coordString = getCoordsDD(origX,origY); //function is below ...
    var ddCoords = coordString.split("|");
    var ddX = ddCoords[0]; //(Math.round(ddCoords[0]*roundFactor)/roundFactor);
    var ddY = ddCoords[1]; //(Math.round(ddCoords[1]*roundFactor)/roundFactor);
    origX =  (Math.round(origX*roundFactor)/roundFactor);
    origY = (Math.round(origY*roundFactor)/roundFactor); 
   // window.status = (Math.round(ddX*roundFactor)/roundFactor)+ ", " + (Math.round(ddY * roundFactor)/roundFactor); 
      window.status = "Longitude:" + ddX + ", " + "Latitude:" + ddY; 
}

//function to convert coords from projected coordinate system to DD (check UpdateExtentValues sub in Default.aspx.vb for origin spatial reference)
function getCoordsDD(origX, origY, decimalPlaces) {
 //read the coordinate values stored (from the server) for the current extent
    var left = document.getElementById("extLeft");
    var right = document.getElementById("extRight");
    var bottom = document.getElementById("extBottom");
    var top = document.getElementById("extTop");

    //Current extent from map 
    var currentExtentTop = parseFloat(top.value); 
    var currentExtentRight = parseFloat(right.value); 
    var currentExtentBottom = parseFloat(bottom.value); 
    var currentExtentLeft = parseFloat(left.value); 

    var map = $find('Map1');
    var ratioX = (currentExtentRight - currentExtentLeft)/(map.get_extent().get_xmax() - map.get_extent().get_xmin())
    var ratioY = (currentExtentTop - currentExtentBottom)/(map.get_extent().get_ymax() - map.get_extent().get_ymin())
    var longitude = currentExtentLeft + (origX-map.get_extent().get_xmin())*ratioX;
    var latitude = currentExtentBottom + (origY-map.get_extent().get_ymin())*ratioY;
    
     if (!decimalPlaces) { decimalPlaces = 6; } //default to 3 if not specified
    //determine the number of digits in the integer portion of the longitude/latitude
    numLongDigits = String(parseInt( String( Math.abs(longitude) ) ) ).length;
    numLatDigits = String(parseInt( String( Math.abs(latitude) ) ) ).length;
    latitude = latitude.toPrecision(numLatDigits + decimalPlaces); 
    longitude = longitude.toPrecision(numLongDigits + decimalPlaces); 
   
    var ddCoords = longitude + "|" + latitude;
    return ddCoords;     
}


END----------------------------------------------------------------------------






More information about the SHRUG-L mailing list