dletz2112

How to center map after extent is declared - JavaScript API

Discussion created by dletz2112 on Nov 27, 2012
Latest reply on Nov 28, 2012 by dletz2112
Hello, I have a basemap zoomed into Harris County, Texas with the following code:

        function init() {


            var initialExtent = new esri.geometry.Extent({

                "xmin": -10679597.979853602,
                "ymin": 3465380.1480138917,
                "xmax": -10557604.482710624,
                "ymax": 3504286.5954109943,
                "spatialReference": {
                    "wkid": 102100
                }
            });

            map = new esri.Map("map", { extent: initialExtent });

            //Base Map Layer
            var baseMapLayer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
            map.addLayer(baseMapLayer);


However, the map is not exactly centered where I want it. I know there is a method named centerAt(point) that will do this, but whenever i try using it by supplying the lat/lon of my center point in that method, I end up on the other side of the world, or no map at all--I suspect it defaults to (0,0) off of the west coast of Africa.

            //TRY TO CENTER THE MAP USING THE LAT/LON
           // var mygeo = esri.geometry.geographicToWebMercator(new esri.geometry.Point(29.818008, -95.423178, new esri.SpatialReference({ wkid: 102100 })));
            var mylat = 29.818008;
            var mylong = -95.423178;

            var CenPoint = new esri.geometry.Point({ "x": mylat, "y": mylong, " spatialReference": { " wkid": 102100 } });


            map = new esri.Map("map", {
                extent: initialExtent,
                infoWindow: popup
            });

            map.centerAt(CenPoint);

Can yiou tell me what i am doing wrong/

Many thanks for your help.

Outcomes