Select to view content in your preferred language

Centre map

1815
10
03-13-2012 06:37 AM
CliveSwan
Frequent Contributor
Hi,

I want the map to centre the map, when the user clicks the map.
I have added a line to center the map, is not working??

The code is below, any suggestions???

>>>>>>>>>>>>>>>>>>>>>>>>>>>
//Zoom to the parcel when the user clicks a row
function onRowClickHandler(evt) {

    var foundItem = grid.getItem(evt.rowIndex).obj_ID;
    var selectedItem;

    dojo.forEach(map.graphics.graphics, function(graphic) {
        if((graphic.attributes) && graphic.attributes.OBJECTID === foundItem[0]) {
            selectedItem = graphic;

            switch (graphic.geometry.type) {
                case "point":
                    graphic.setSymbol(pictureMarkerSymbol);
                    break;
                case "polyline":
                    graphic.setSymbol(selectedLineSymbol);
                    break;
                case "polygon":
                    graphic.setSymbol(selectedPolySymbol);
                    break;
            }
        }
    });
    var selectedItemExtent = selectedItem._extent.expand(0.2);
    map.setExtent(selectedItemExtent);
    ///map.centerAndZoom(selectedItemExtent, 0.5);
    map.centerAt(selectedItemExtent);
0 Kudos
10 Replies
CliveSwan
Frequent Contributor
I added the following code in the addIdentifyResultsToMap(idResults, event) function.
This worked.

>>>>>>>>>>>>

             /// PAN & CENTRE MAP ON SELECTED POINT
                  map.infoWindow.show(event.screenPoint, map.getInfoWindowAnchor(event.screenPoint));
                  var centerPointScreen = map.toScreen(event.screenPoint);
             /// PAN MAP TO NEW centerpoint (in Map coordinates)
                 centerPoint = map.toMap(event.screenPoint);
                 map.centerAt(centerPoint);
             /// PAN & CENTRE MAP ON SELECTED POINT

>>>>>>>>>>>>
0 Kudos