Zoom in Zoom out control

994
6
Jump to solution
06-07-2012 10:26 PM
PramodHarithsa1
Occasional Contributor II
Hi,
I have two external button for zoomin and zoom out.
on click of zoomin button i am using
map.centerAndZoom()
function.
But it doesnt work for me.
i want the extent to be maximixed and minimized..

when use this,
map.centerAndZoom((0,0),1)
map.centerAndZoom((0,0),2)

map centers to one position.. how do i make it dynamic..
i.e., on click on button it should keep zooming in.. and similarly the zoom out button as well

what other functions for the same can i manifest?
0 Kudos
1 Solution

Accepted Solutions
HemingZhu
Occasional Contributor III
Hi,
I have two external button for zoomin and zoom out.
on click of zoomin button i am using
map.centerAndZoom()
function.
But it doesnt work for me.
i want the extent to be maximixed and minimized..

when use this,
map.centerAndZoom((0,0),1)
map.centerAndZoom((0,0),2)

map centers to one position.. how do i make it dynamic..
i.e., on click on button it should keep zooming in.. and similarly the zoom out button as well

what other functions for the same can i manifest?


Try this:
For ZoomIn Button:
var extent=map.extent;
map.setExtent(extent.expand(0.5));
For ZoomOut Button:
var extent=map.extent;
map.setExtent(extent.expand(2));

View solution in original post

0 Kudos
6 Replies
derekswingley1
Frequent Contributor
If you're using a tiled service, you can get the map's level, add or subtract one from it depending on which button is clicked and pass that as the second argument to centerAndZoom.

If you're not using a tiled service, centerAndZoom probably isn't what you want. Rather, try building a new extent and using map.setExtent. More info about using extents:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/intro_extents.htm
0 Kudos
PramodHarithsa1
Occasional Contributor II
If you're using a tiled service, you can get the map's level, add or subtract one from it depending on which button is clicked and pass that as the second argument to centerAndZoom.

If you're not using a tiled service, centerAndZoom probably isn't what you want. Rather, try building a new extent and using map.setExtent. More info about using extents:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/intro_extents.htm


I have a tiled service layer as well as a DynamicMapServiceLayer in the map..
for the location attribute i tried something like (map.extent.xmin+map.extent.xmax)/2 and similarly for y parameter.. but it didn't work for me.
I just want the + and - functionality of zoom slider into buttons i have defined!
0 Kudos
PramodHarithsa1
Occasional Contributor II
With Reference to the doc.,
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm

How are the constants ZOOM_IN and ZOOM_OUT used?
0 Kudos
HemingZhu
Occasional Contributor III
Hi,
I have two external button for zoomin and zoom out.
on click of zoomin button i am using
map.centerAndZoom()
function.
But it doesnt work for me.
i want the extent to be maximixed and minimized..

when use this,
map.centerAndZoom((0,0),1)
map.centerAndZoom((0,0),2)

map centers to one position.. how do i make it dynamic..
i.e., on click on button it should keep zooming in.. and similarly the zoom out button as well

what other functions for the same can i manifest?


Try this:
For ZoomIn Button:
var extent=map.extent;
map.setExtent(extent.expand(0.5));
For ZoomOut Button:
var extent=map.extent;
map.setExtent(extent.expand(2));
0 Kudos
PramodHarithsa1
Occasional Contributor II
Try this:
For ZoomIn Button:
var extent=map.extent;
map.setExtent(extent.expand(0.5));
For ZoomOut Button:
var extent=map.extent;
map.setExtent(extent.expand(2));


Thanks a lot Zhu, That worked for me..
where can i get such methods described? I was looking here http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp_start.htm
0 Kudos
HemingZhu
Occasional Contributor III
Thanks a lot Zhu, That worked for me..
where can i get such methods described? I was looking here http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp_start.htm


Under API Reference Tab looking for Geometry -> Extent.
0 Kudos