issue setting initial extent

1249
9
09-26-2017 03:48 PM
YueZhou1
New Contributor

I am able to set initial extent with wkid 102100

var map = new Map({ basemap: "topo" });

var extent = new Extent({

    xmin: -8499854.09025499,

    ymin: 4383842.034757545,

    xmax: -8429713.995449727,

    ymax: 4422987.654383438,

    spatialReference: 102100 });

var view = new MapView({

  container: "viewDiv",

  map: map,

  extent: extent });

but I won't be able to set initial extent correctly with other wkid, like

var extent = new Extent({

    xmin: 940000.0000547133,

    ymin: 1160000.0002149716,

    xmax: 1100000.0002790727,

    ymax: 1370000.0002149716,

    spatialReference: 102671 })

});

0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus

Yue,

Because you are using a standard esri basemap the mapViews WKID is 102100 and the map does not automatically re-project the extent from other WKIDs to the maps WKID so you are limited to Extents that are 102100/3857 and 4326 (4326 works because the API can re-project that clientside).

ThomasSolow
Occasional Contributor III

Additionally, you can use GeometryService.project in order to go from your spatial reference of choice to Web Mercator or WGS84.  This sends an HTTP request to an Esri geometry service, so it's not done in the client.

YueZhou1
New Contributor

If I need to add graphics later, do I also project their geometries to WGS84? Will it have big impact on the performance? Thanks!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Any graphics added should be in the same WKID as the maps, so yes. As far as impact to performance there will be not be much at all the Geometry service is a pretty fast round trip to the server depending on the number of graphics.

YueZhou1
New Contributor

Hopefully it's my last question of this topic: if my customers also provides me the latitude and longitude, can I assume their spatial reference is Web Mercator or WGS84?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Yue,

   Lat and Lon would Normally mean WGS84 WebMercator uses meters

0 Kudos
ThomasSolow
Occasional Contributor III

Yes, you'll need to use .project to convert non-WGS84/Web Mercator geometries to WGS84 or Web Mercator if you're using an esri basemap.

This will have a significant impact on performance as project is behind an HTTP request. Depending on your use case this might be a concern or not.

If you're adding a static number of graphics to the view/a layer as part of your app then you could just project them all ahead of time and add the graphics with their projected geometries.  If users need the ability to add new graphics in your preferred spatial reference at run time, then you'll have to project them using the geometry service in order to add them.

YueZhou1
New Contributor

Your replies are very helpful. 

 

I have an additional question: can I add a MapImageLayer which use non-WGS84?

Thanks!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Yue, yes you can as the MapImageLayer will request the returned image form the server to be projected in the same wild as the map is in.