0

i have a problem that i want to zoom to place using esri javascript api

i have this class from esriGetStarted javascript

function zoomToPlace(lon, lat, scale) {
          mapDeferred.centerAndZoom([lon, lat], scale);
      }

i have tried to zoom to place using this html element :

<a href="#place" class="buttonStyle" onclick="javascript:zoomToPlace('118.12', '-5.52', '9');">zoom to place </a>

but it never work untill now, please help me how to zoom to place, or may be is there alternative.

Vikash Pandey
  • 5,407
  • 6
  • 41
  • 42
yozawiratama
  • 4,209
  • 12
  • 58
  • 106
  • What API version are you using? `centerAndZoom([lon,lat], scale)` only works in v3.3+. Also, have got a TiledMapService layer or a DynamicMapService layer? You will get different results from your `scale` argument depending on which one is in use. – Juffy Apr 09 '13 at 05:27

2 Answers2

1

You may be having spatial reference issues (first port of call for any error with a mapping engine :) ). My code from an existing project converts the coordinates to web mercator before attempting to zoom to it:

var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(lon, lat));
_map.centerAndZoom(pt, scale);
Juffy
  • 1,220
  • 13
  • 22
0

Not sure if this will help, but there is a Locate Widget in the ESRI API:

require(["esri/dijit/LocateButton"],

geoLocate = new LocateButton({
            map: map
        }, "LocateButton");
        geoLocate.startup();
nkjt
  • 7,825
  • 9
  • 22
  • 28
BretW
  • 199
  • 10