Centre map

1639
10
03-13-2012 06:37 AM
CliveSwan
Occasional Contributor II
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
Occasional Contributor II
Hi,

I created a centerMap function, below. It does not do anything???
Any suggestions what or why it is not working??

>>>>>>>>>>>>>>>>>>>
function recenterMap(selectedItemExtent) {
  map.centerAt(selectedItemExtent);
}
0 Kudos
HemingZhu
Occasional Contributor III
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);


Change graphic.attributes.OBJECTID === foundItem[0] to graphic.attributes.OBJECTID === foundItem
0 Kudos
CliveSwan
Occasional Contributor II
Hi Zhu,

I changed the line as you suggested to:
Change graphic.attributes.OBJECTID === foundItem[0] to graphic.attributes.OBJECTID === foundItem

The map does not recenter where the user clicks???
It does not move or recenter???
0 Kudos
HemingZhu
Occasional Contributor III
Hi Zhu,

I changed the line as you suggested to:
Change graphic.attributes.OBJECTID === foundItem[0] to graphic.attributes.OBJECTID === foundItem

The map does not recenter where the user clicks???
It does not move or recenter???


map.centerAt is only for point. if your graphic's geometry is of polyline or polygon. you might have to use var selectedItemExtent = selectedItem.geometry.getExtent(); map.setExtent(selectedItemExtent);
0 Kudos
CliveSwan
Occasional Contributor II
Hi Zhu,

I am selecting a Point feature. I amended the code as you suggested, clicked on various points, the map does not recenter??
Is the code above clear enough??

Any other suggestions??
0 Kudos
CliveSwan
Occasional Contributor II
Hi,

I have the imageWindow appearing in the UpperLeft window.
I want to move the imageWindow to the UpperRight.

I added the following, does not move the imageWindow to UpperRight??

>>>>>>>>>>>>>>
show: function(location) {
    // Is location specified in map coordinates?
    if (location.spatialReference) {
      location = this.map.toScreen(location);
    map.infoWindow.show(location, InfoWindow.ANCHOR_UPPERRIGHT);
    }
   
    // Position 10x10 pixels away from the
    // requested location
///    dojo.style(this.domNode, {
///      left: (location.x + 10) + "px",
///      top: (location.y + 10) + "px"
///    });

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

I commented out the Position 10px, imageWindow on the edge did not show fully.

Any suggestions, to get the Anchor working??
0 Kudos
CliveSwan
Occasional Contributor II
I edited the addIdentifyResultsToMap function.

I added two lines (below)
map.infoWindow.setFixedAnchor(infoWindow.ANCHOR_UPPERRIGHT);
map.infoWindow.show(infoWindow.ANCHOR_UPPERRIGHT);

I get an error "addIdentifyResultsToMap error, details: [object error]

Any suggestions??

>>>>>>>>>>>>>>>>>>
if(tc.hasChildren()) {
                tc.domNode.style.display = 'block';
                tc.domNode.style.visibility = 'visible';
                tc.startup();
                tc.resize();

                map.infoWindow.setTitle("Identify Results");
                map.infoWindow.setContent(tc.domNode);
                map.infoWindow.resize(360, 200);
                map.infoWindow.show(event.screenPoint, map.getInfoWindowAnchor(event.screenPoint));
               
                map.infoWindow.setFixedAnchor(infoWindow.ANCHOR_UPPERRIGHT);
                map.infoWindow.show(infoWindow.ANCHOR_UPPERRIGHT);

                flushThis("tabs");
                setCursorByID("map", "default");
            }
            hideLoading();
0 Kudos
CliveSwan
Occasional Contributor II
I have used the same syntex for the show(map.getInfoWindowAnchor) and setFixedAnchor

I do not get an error with show() line.
I get an error with setFixedAnchor() line??

map.infoWindow.show(event.screenPoint, map.getInfoWindowAnchor(event.screenPoint));
/// SET THE POSITION OF THE IMAGEWINDOW - UPPER RIGHT
map.infoWindow.setFixedAnchor(map.infoWindow.ANCHOR_UPPERRIGHT);

I have copied an example from the examples and still get an error??
map.infoWindow.setFixedAnchor(esri.dijit.InfoWindow.ANCHOR_UPPERRIGHT);


Can anyone spot an error??
0 Kudos
CliveSwan
Occasional Contributor II
Got the map.centre working.

The code below in the function addIdentifyResultsToMap(idResults, event)

              /// 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