Select to view content in your preferred language

centerAndZoom is still not work in 2.0?

2425
5
05-05-2010 09:12 PM
by Anonymous User
Not applicable
I just tested centerAndZoom base 2.0 version, but it still looks like not work well.....
Any comment?

Regards,

Bing
5 Replies
KellyHutchins
Esri Frequent Contributor
Can you provide details on the type of issues you are seeing with centerAndZoom at 2.0?



I just tested centerAndZoom base 2.0 version, but it still looks like not work well.....
Any comment?

Regards,

Bing
0 Kudos
by Anonymous User
Not applicable
I mean map.centerAndZoom(pMapPoint,5) does't work

i have to map.centerAt(pMapPoint); map.setLevel(5);

Am i correct?

Regards,

Bing
DerekSwingley
Regular Contributor
It works:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title> Topographic Map</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.0/js/dojo/dijit/themes/tundra/tundra.css">
    <style>
      html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
    </style>
    <script type="text/javascript">var djConfig = {parseOnLoad: true};</script>
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0"></script>
    <script type="text/javascript">
      dojo.require("dijit.layout.BorderContainer");
      dojo.require("dijit.layout.ContentPane");
      dojo.require("esri.map");
      var map;

      function init() {
        var initExtent = new esri.geometry.Extent({"xmin":-13635568,"ymin":4541606,"xmax":-13625430,"ymax":4547310,"spatialReference":{"wkid":102100}});
        map = new esri.Map("map",{extent:initExtent});
        //Add the topographic layer to the map. View the ArcGIS Online site for services http://arcgisonline/home/search.html?t=content&f=typekeywords:service    
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
        map.addLayer(basemap);
        
        //resize the map when the browser resizes - view the 'Resizing and repositioning the map' section in
        //the following help topic for more details http://help.esri.com/EN/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/inside_guidelines.htm
        var resizeTimer;
        dojo.connect(map, 'onLoad', function(theMap) {
          dojo.connect(dijit.byId('map'), 'resize', function() {  //resize the map if the div is resized
            clearTimeout(resizeTimer);
            resizeTimer = setTimeout( function() {
              map.resize();
              map.reposition();
            }, 500);
          });
          dojo.connect(map, 'onClick', function(evt) {
             map.centerAndZoom(evt.mapPoint, map.getLevel()+1); 
          });
        });
      }

      dojo.addOnLoad(init);
    </script>
  </head>
  
  <body class="tundra">
    <div dojotype="dijit.layout.BorderContainer" design="headline" gutters="false"
    style="width: 100%; height: 100%; margin: 0;">
      <div id="map" dojotype="dijit.layout.ContentPane" region="center" style="overflow:hidden;">
      </div>
    </div>
  </body>

</html>
0 Kudos
DavidPuckett
Regular Contributor
I'm having the same problem I have seen reported in this post and others. I think it has to do with having both tiled and dynamic layers in the same map. IE simply ignores the method and Firefox offsets the dynamic layer from the tiled layer (among other things). I've seen work arounds but they aren't working for me. Is this a known problem\bug? I'd really like to hear some official word.

Here's what I've got:
2 tiled base map services (map and aerial)
1 dynamic operations map service layer
Call centerAndZoom and pass in a  point and a zoom level (targeting the tiled service level)
map.centerAndZoom(addressPoint, 11);

I have also tried call centerAt followed by setLevel but I only get the results of the setLevel (i.e. zoomed appropriately but not at the correction location).
map.centerAt(addressPoint);
map.setLevel(10);

Finally I tried creating a new extent and calling the setExtent method of the map:
xMin = addressPoint.x - 1000;
yMin = addressPoint.y - 1000;
xMax = addressPoint.x + 1000;
yMax = addressPoint.y + 1000;
   
var newExtent = new esri.geometry.Extent(xMin, yMin, xMax, yMax, map.spatialReference);
map.setExtent(newExtent);

None of these provided a solution. Anyone have a solution here and can we get an official word on what's happening with this method?

Thanks
0 Kudos
Mindaugas_ižas
Emerging Contributor
try
xMin = addressPoint.x - 1000;
yMin = addressPoint.y - 1000;
xMax = addressPoint.x -- 1000;
yMax = addressPoint.y -- 1000;

I found this solution somwhere in forums and it looks that it works
0 Kudos