Select to view content in your preferred language

eMapSwitcherWidget modify forcescaleonswitch behaviour

608
4
Jump to solution
08-16-2012 12:01 PM
RhettZufelt
MVP Notable Contributor
Hi Robert,

I have one layer that has the forscaleonswitch enabled and is working fine.  However, it just changes scale, and I would like it to also change extent when this basemap is changed.
Is it possible to code a "centroid" or something along with the scale to that it also snaps back to where I want it (basically, back to initialextent).

I am only using this option on one of my basemaps, so it doesn't matter if it is layer specific or not, so could hard code into the mxml if I knew what/where.

Thanks again,

R_
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Rhett,

    Just remember I will not always be willing to do the coding for you.

In the dispatchChangeBasemapEvent function:

if(basemapList.getItemAt(basemapSelectionComponent.selectedIndex).forcescaleonswitch && map.scale < basemapList.getItemAt(basemapSelectionComponent.selectedIndex).forcescaleonswitch){                     map.scale = basemapList.getItemAt(basemapSelectionComponent.selectedIndex).forcescaleonswitch;                     if(basemapList.getItemAt(basemapSelectionComponent.selectedIndex).label == "myspecialbasemap"){                         map.centerAt(new MapPoint(x,y, map.spatialReference));                     }                 }


and in the basemapButtonBar_changeHandler function:
                if(basemapList.getItemAt(event.newIndex).forcescaleonswitch && map.scale < basemapList.getItemAt(event.newIndex).forcescaleonswitch){                     map.scale = basemapList.getItemAt(event.newIndex).forcescaleonswitch;                     if(basemapList.getItemAt(basemapSelectionComponent.selectedIndex).label == "myspecialbasemap"){                         map.centerAt(new MapPoint(x,y, map.spatialReference));                     }                 }

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Rhett,

    Just remember I will not always be willing to do the coding for you.

In the dispatchChangeBasemapEvent function:

if(basemapList.getItemAt(basemapSelectionComponent.selectedIndex).forcescaleonswitch && map.scale < basemapList.getItemAt(basemapSelectionComponent.selectedIndex).forcescaleonswitch){                     map.scale = basemapList.getItemAt(basemapSelectionComponent.selectedIndex).forcescaleonswitch;                     if(basemapList.getItemAt(basemapSelectionComponent.selectedIndex).label == "myspecialbasemap"){                         map.centerAt(new MapPoint(x,y, map.spatialReference));                     }                 }


and in the basemapButtonBar_changeHandler function:
                if(basemapList.getItemAt(event.newIndex).forcescaleonswitch && map.scale < basemapList.getItemAt(event.newIndex).forcescaleonswitch){                     map.scale = basemapList.getItemAt(event.newIndex).forcescaleonswitch;                     if(basemapList.getItemAt(basemapSelectionComponent.selectedIndex).label == "myspecialbasemap"){                         map.centerAt(new MapPoint(x,y, map.spatialReference));                     }                 }
0 Kudos
RhettZufelt
MVP Notable Contributor
That did the trick, thanks again.

However, I have noticed a quirk in the widget now.  I have a layer set with forcescaleonswitch="250000".

If I am zoomed in beyond that and change to my forcescale layer, it will automatically change the scale to my 1:250000.

However, if I am zoomed OUT from there (1:500000) the forcescale does not seem to take affect.  I don't see a forcescale layer on your example page to test.

Here is the interesting part, I see this happening "before" I make any changes to the mxml.  Then, I made the changes that you gave me.
The weird thing is that the new code to center at my MapPoint seems to work if I'm zoomed in or OUT from my forcescale setting, but the scale only changes if I am zoomed in from my forcescale setting.
So, if I'm zoomed in and change  the basemap, it will center on my x,y, AND change the scale.
If I'm zoomed out and change the basemap, it will center on my x,y, and NOT change the scale.

Hope this makes sense, and thanks yet again,

R_
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhett,

  The forcescaleonswitch is only designed to work if your current map scale is less then the value set in the forcescaleonswitch it will not work the other direction as this would cause your map to never be able to leave the set scale when that base map is selected.
0 Kudos
RhettZufelt
MVP Notable Contributor
Guess that would kind of defeat the utility of it 🙂

Thanks again for the help,

R_
0 Kudos