Select to view content in your preferred language

basemap or featurelayer which one sets projection

810
3
07-03-2012 05:32 AM
LuciHawkins
Frequent Contributor
Hi All,

I have been playing around with trying to load data from a config.txt file

I am using the Basemap Gallery for my background maps and I am also loading several dynamic map service layers.  It seemed as though the projection was being set from the first feature layer loaded and not the first basemap loaded. 

But, upon investigation it seems as though I am getting different projections based upon the method used to set the map extent.  Can someone explain to me what the difference is between the two methods below because when I use Method 1 everything lines up properly, but, when I use Method 2 my Basemaps are fine, but my dynamic feature layers are over in Africa...

Method 1:

All of the below is in my default.html file

var initExtent = new esri.geometry.Extent({"xmin":-9654356.83267948,"ymin":3553252.14612359,"xmax":-9631845.86180353,"ymax":3569377.06341259,"spatialReference":{"wkid":102100}});

map = new esri.Map("map", {
    extent: initExtent,
    slider: true,
    lods: lods,
    infoWindow: popup
   });


Method 2:

This is config.txt

{
'DefaultExtent' : "-9654356.83267948, 3553252.14612359, -9631845.86180353, 3569377.06341259"
}

This is in my default.html file

var mapExtent = responseObject.DefaultExtent;
var mapExtent2 = mapExtent.split(',');

map = new esri.Map("map", {
    slider: true,
    lods: lods,
    infoWindow: popup
   });

map.setExtent(new esri.geometry.Extent(parseFloat(mapExtent2[0]), parseFloat(mapExtent2[1]), parseFloat(mapExtent2[2]), parseFloat(mapExtent2[3]),  new esri.SpatialReference({ wkid: 102100 })));


Thanks,

Luci
0 Kudos
3 Replies
JeffPace
MVP Alum
Its set by the first layer added (even if you dont explicitly call it, i.e. basemap gallery).  I would hate to think my app was "picking" for me, and would try to find a way to explicitly set it .
0 Kudos
LuciHawkins
Frequent Contributor
Okay.  What is the difference between the above 2 methods?  In the first, everything is fine.  The dynamic layers (wkid 2238) seem to be reprojecting on the fly just fine.

Using the second method, my dynamic layers do not project on the fly and are in Africa instead of Florida.

Thanks!

Luci
0 Kudos
JeffPace
MVP Alum
In method 2 you are setting the extent, you are not setting the spatial reference.

I would try alerting (map.spatialReference.wkid) and my guess is it will be wrong.

Try

map.spatialReference = = new esri.SpatialReference({wkid:102100});
prior to your map.setExtent line
0 Kudos