Pergunta

I'm new to ESRI's JavaSCript API and am very impressed by its ease of use and speed. As part of a interactive data portal I have users enter latitude and longitude as decimal degrees as part of a spatial query to return State, County and FIPs. That part works just fine, but as an added feature I want to draw a dot graphic on an existing map showing the entered coordinates location (DONE) then Center and Zoom to said point at some reasonable scale.

The centerAndZoom method is the logical choice here, but it doesn't seem to be working. My sense is that the Map needs to be refreshed but I can't seem to figure this one out.

I'm sure I'm missing something fundamental here; Thanks in advance for your time!

function DrawPointAndZoom() {

    // Get currently entered lat/long.
    var lat = $('#SiteLatitude').attr('value');
    var long = $('#SiteLongitude').attr('value');

    var latLongPoint = new esri.geometry.Point(long, lat, new esri.SpatialReference({ wkid: 4326 }));

    //Draw point
    var symbol = new esri.symbol.SimpleMarkerSymbol().setSize(8).setColor(new dojo.Color([255, 0, 0]));
    var graphic = new esri.Graphic(latLongPoint, symbol);


    var infoTemplate1 = new esri.InfoTemplate();
    infoTemplate1.setTitle("point1");
    infoTemplate1.setContent("test point 1");

    graphic.setInfoTemplate(infoTemplate1);

    map.graphics.add(graphic);
    map.centerAndZoom(latLongPoint, 15);
}
Foi útil?

Solução

95% of the time, anything that doesn't work with a Point in the JS API is due to the spatialreference being wrong. :)

Check that your map's SR (map.spatialreference.wkid) is the same as the point's (4326, as you've defined it here.) You may need to use everyone's favourite function, geographicToWebMercator if the map is using one of its usual Web Mercator coordinate systems.


Edited with details from Tony's comment/answer:

var webMercPoint = esri.geometry.geographicToWebMercator(latLongPoint)
   {Missing code here}
map.centerAndZoom(webMercPoint, 15);

Outras dicas

Yes! thanks for taking the time to respond. I went down that hole yesterday and tried it with a webMercatorPoint... and viola it worked!

var webMercPoint = esri.geometry.geographicToWebMercator(latLongPoint)
   {Missing code here}
map.centerAndZoom(webMercPoint, 15);

Much Appreciated!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top