Select to view content in your preferred language

Show scale with coordinates

3772
21
02-23-2011 03:19 PM
DanielOchoa
Regular Contributor
The coordinate widget shows lat/long mouseover coordinates in the map, but can anyone advise on how to display map scale alongside the coordinates? Take a look here:

http://top100projects.ca/map/

or see the screen shot, attached.

Simple adjustment to the coordinate widget? Thanks!
Tags (2)
0 Kudos
21 Replies
RobertScheitlin__GISP
MVP Emeritus
Daniel,

Try this in the CoordinateWidget.mxml

            private function map_mouseMoveHandler(event:MouseEvent):void
            {
                const mapPoint:MapPoint = map.toMapFromStage(event.stageX, event.stageY);
                coords.text = m_func(mapPoint) + " Scale 1:" + map.scale.toString();
            }
0 Kudos
DanielOchoa
Regular Contributor
Rob,

That worked  - thanks! But its showing the scale in meters (e.g. 1:14567789.232567) instead of something like 1: 12,456,578 . Can you guide me as to what part of the code needs to change to have the scale show as standard instead of metric? Once again, you rock!

thanks,

~ D
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Daniel,

   The scale will be whatever the map's spatial reference is set to so if you are using ESRI basemaps than the map's SR is like web mercator which is meters. I guess you could do some standard math and convert meters to feet if that is what you are asking...
0 Kudos
DanielOchoa
Regular Contributor
The scale will be whatever the map's spatial reference is set to


Yea, I figured that might be the case, but I was wondering if there was a way in the code to force the output to show something different.  I'm still new at this, so I didnt know if you could adjust something under the map_loadHandler to reflect a different format.

But the "standard math" option sounds interesting...is there a way to code some conversion math into the coordinate mxml and compile so I can get what I'm looking for? 

Thanks again for the education....
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Daniel,

   Sure something like this:

            private function map_mouseMoveHandler(event:MouseEvent):void
            {
                const mapPoint:MapPoint = map.toMapFromStage(event.stageX, event.stageY);
                coords.text = m_func(mapPoint) + " Scale 1:" + String(map.scale * 3.2808398950131235);
            }

I can never remember if the right calculation is multiple or divide though.:o
0 Kudos
SteveWhitehead__GISP
Occasional Contributor
This is good. 

How do I remove the dozen or so decimal places in the scale?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Steve,

  Just add a numberformatter.

   private function map_mouseMoveHandler(event:MouseEvent):void
   {
    var nf:NumberFormatter = new NumberFormatter();
    nf.precision = 2;
    const mapPoint:MapPoint = map.toMapFromStage(event.stageX, event.stageY);
    coords.text = m_func(mapPoint) + " Scale 1:" + nf.format(map.scale * 3.2808398950131235);
   }
0 Kudos
SteveWhitehead__GISP
Occasional Contributor
Thank you!

Steve,

  Just add a numberformatter.

   private function map_mouseMoveHandler(event:MouseEvent):void
   {
    var nf:NumberFormatter = new NumberFormatter();
    nf.precision = 2;
    const mapPoint:MapPoint = map.toMapFromStage(event.stageX, event.stageY);
    coords.text = m_func(mapPoint) + " Scale 1:" + nf.format(map.scale * 3.2808398950131235);
   }
0 Kudos
philippschnetzer
Frequent Contributor
include this code:
map.addEventListener(MouseEvent.MOUSE_WHEEL, map_mouseMoveHandler);

directly under this line:
map.addEventListener(MouseEvent.MOUSE_MOVE, map_mouseMoveHandler);

and the scale will refresh when you zoom in and out.   Otherwise it is possible to zoom in and out and not have the scale refresh until you actually move the mouse pointer....
0 Kudos