Select to view content in your preferred language

Zoom to Dynamic Service (Projected State Plane) extents overlayed on NatGeo Basemap

809
2
04-18-2013 02:52 PM
HeathClark
Occasional Contributor
I am overlaying a dynamic service (WKID:3566) on the National Geographic basemap and would like to auto-zoom to the extents of the dynamic service. If the dynamic service was in WGS84 and not State Plane, the esri.geometry.geographicToWebMercator() function would get me the correct extent.  However, since the dynamic service is in STP, I need other ideas.  Some examples of mixing the traditional "basemaps" with real-world data in local systems (STP) and how to manage Query/Find results whose geometry spatialreference is based on the underlying service (STP) would be helpful and may guide my solution.  Maybe it isn't possible, be nice to know before I spend another day hacking code that ultimately doesn't yield a good result.
0 Kudos
2 Replies
JeffJacobson
Frequent Contributor
You can use the Proj4js library to project the extent from 3566 to 3857.
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Heath,

You could also do this using a Geometry service.  A geometry service will allow you to project coordinates.  Ex:

dojo.require("dojo.parser");

function extent(){
        var URL = "http://server:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer/project?";
        
        var spatRef1 = 3566 //WKID for NAD_1983_StatePlane_Utah_Central
        var spatRef2 = 3857 //WKID for Web Mercator
        var transformation = 1188 //WKID for esriSRGeoTransformation_NAD1983_To_WGS1984_1
        
        var xMin = layer.fullExtent.xmin;
        var yMin = layer.fullExtent.ymin;
        var xMax = layer.fullExtent.xmax;
        var yMax = layer.fullExtent.ymax;
               
        var geometries = "inSR=" + spatRef1 + "&outSR=" + spatRef2 + '&geometries='
            + '{"geometryType":"esriGeometryEnvelope",'
            + '"geometries":[{"xmin":' + xMin + ',"ymin":' + yMin + ',"xmax":' + xMax + ',"ymax":' + yMax + '}]}'
            + '&transformation=' + transformation
            + '&transformForward=true'
            + '&f=pjson'
        
        var geometryURL = URL + geometries;        
        
        var xmlHttp = null;

        xmlHttp = new XMLHttpRequest();
        xmlHttp.open( "GET", geometryURL, false );
        xmlHttp.send( null )
        
        var jsonResponse = JSON.parse(xmlHttp.responseText);
        geom = jsonResponse.geometries[0];
        layerExtent = new esri.geometry.Extent({"xmin":geom.xmin,"ymin":geom.ymin,"xmax":geom.xmax,"ymax":geom.ymax,"spatialReference":{"wkid":102100}});
       
        map.setExtent(layerExtent);
    }
0 Kudos