Select to view content in your preferred language

Custom map center

2350
13
03-02-2018 06:04 AM
EvelynHernandez
Frequent Contributor

Hello.

I want to know if there is a way to move the center of the map when querying a little bit.

Iam querying some feature (just 1 result) and im doing this for showing it in the center of the map.

    map.centerAndZoom(featureSet.features[0].geometry.getExtent().getCenter(),20);

In my app when i do this i have a problem on visualization, thats why i want to move it to the right a little bit.

This is what i obtain: (See the blue line on the screen)

The red container is over the map, thats why when i do the center i got that.

this is what i want to get:

Thanks in advice

0 Kudos
13 Replies
RobertScheitlin__GISP
MVP Emeritus

Evelyn,

featureSet.features[0].geometry

Is a line or a polygon right? If it is a point then a point does not have an extent.

0 Kudos
EvelynHernandez
Frequent Contributor

A point, thats why.

So how should i do the offset with a point?

Thanks in advice

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Evelyn,

   The Point Class in the JS API has an offset method as well.

https://developers.arcgis.com/javascript/3/jsapi/point-amd.html#offset 

So your code would look like this instead:

map.centerAndZoom(featureSet.features[0].geometry.offset(10,0), 20);
HoriaTudosie
Frequent Contributor

Check the geometry type for the feature. 

When is Point, get the current extent of the map and offset that instead!

(I think you should considering that for whatever geometry, but is up to you to consider it.)

0 Kudos