Event Listeners  -  ExtentEvent or stop the ZoomEvent

2297
3
02-07-2011 07:09 AM
AmyRamsdell
New Contributor III
Using Flex 2.2, a 9.3.1 ags service for some feature layers, and both the esri topo and bing as baselayers

I need to center the map based on a user click location when the user subsequently zooms in using the navigation control - either the zoomslider or a mousewheel zoom in. So for instance, the user clicks a graphic in the feature layer to show an infoWindow. Then the user uses the zoom bar to zoom in. On the zoom in, I want to recenter the map to that original click location. I can't seem to zoom the map correctly to that point

If I center the map in the extentchangehandler, that event is fired before the baselayer updateEvents and what happens is the featurelayers get centered correctly but the basemap (the esri topo or the bing map shifts). If I center the map in the UpdateEnd event on the basemaps, the basemap shifts back to the center and aligns with the feature layers but this is an extra map extent change that should be unnecessary.

What I would like to do is either figure out what I am doing wrong in the extent change handler, that seems to throw the basemap off or better yet, I would like to add a listener on the zoomevent and change the zoom in event to a new center (based on a user click location). I can't seem to change the event or stop it at all to create my own zoom event.

I have added a listener on the map - tried both ways

//in the loadHandler :  
mainMap.addEventListener(ZoomEvent.ZOOM_START, onZoomStart, true, 999, false);

//and in the map tag 
<esri:Map id="mainMap" 
zoomStart="onZoomStart(event), true, 999"


in the onZoomStart function I tried first to recenter the zoom in :
event.extent.centerAt(infoWindowClickLocation);


that didn't work so I just tried to see it I could stop the ZoomEvent with
event.stopImmediatePropagation(); and  event.stopPropagation();


which didn't work either.

Any ideas or better way of zooming to click position (using the map navigation controls and not at the same time as the click) ?
Tags (2)
0 Kudos
3 Replies
DasaPaddock
Esri Regular Contributor
If I center the map in the extentchangehandler, that event is fired before the baselayer updateEvents and what happens is the featurelayers get centered correctly but the basemap (the esri topo or the bing map shifts).


What is your code here? This would be the recommended solution since canceling or changing the zoom is not supported.

Another option may be to extend Map and override the extent setter where you could change the extent before calling: super.extent = newExtent;
0 Kudos
AmyRamsdell
New Contributor III
Here it is in the extent handler. I attached a picture of what is happening. You can't exactly tell from picture cause I cut it out, but the yellow line is supposed to hug the shoreline. The click location, where I clicked on that yellow line, is in fact in the center of the map however the basemap is shifted. The same is true for the esri topo base map I am using. The feature layer mode is onDemand.

mainMap.infoWindow.hide();
layerSTATES.visible = (mainMap.level <= LEVEL_BOUNDARY_STATE) ? true : false;

//COUNTY VISIBILITY
if (mainMap.level >= LEVEL_BOUNDARY_COUNTY && mainMap.level <= LEVEL_BOUNDARY_BEACHES)
   layerCOUNTIES.visible = true;
else {
 if (zoomedtoCountiesLevel)
            {
   layerCOUNTIES.visible = true;
    layerSTATES.visible = false
 }
 else {
    layerCOUNTIES.visible = false;
 }
}
    
layerSTORET.visible = (mainMap.level >= LEVEL_BOUNDARY_STORET_STATIONS) ? true : false;
layerBEACHES_LN.visible = (mainMap.level >= LEVEL_BOUNDARY_BEACHES) ? true : false;
    
if (!zoomedtoCountiesLevel && !zoomedtoFeatureId)
{
      mainMap.removeEventListener(ExtentEvent.EXTENT_CHANGE, extentChangeHandler);
      if (zoomToClickLocation != null)
 mainMap.centerAt(zoomToClickLocation);
}

zoomedtoCountiesLevel = false;
zoomedtoFeatureId = false;
0 Kudos
AmyRamsdell
New Contributor III
Thanks Dasa!  Extending the map and overriding the extent setter did the trick!
0 Kudos