Scale Bar Overlay Concern

3091
6
12-05-2013 10:26 AM
StephenBaier
New Contributor III
I don't know if anyone else has noticed, but the Scale Bar Overlay for the JMap seems incorrect / misleading. The Scale Bar shows a 0 to n distance, such as 0 to 1 km, based on the zoom of the map. The bar is always broken into 8 sections and should show 1/8th of the overall distance, but they instead appear to show one tenth of the overall distance.

I noticed the issue by drawing out a line that is exactly 200m long, traveling directly East to West. Placing the line next to the 1 km Scale Bar, it is exactly two hashes long. Either the implementation of the bar is incorrectly only showing 8 hashes, when it should be showing 10, or the Scale Bar is highly misleading or incorrect altogether.

Anyone else noticed this? Is this a known issue?
0 Kudos
6 Replies
JeremieJoalland1
Occasional Contributor II
I guess the Scalebar is true only for West-East center line... then depending on your current Map Spatial Reference, your can have distortion going North or South of the map... so you should calculate your horizontal line distance at the (vertical) middle of the map screen.
0 Kudos
StephenBaier
New Contributor III
I guess the Scalebar is true only for West-East center line... then depending on your current Map Spatial Reference, your can have distortion going North or South of the map... so you should calculate your horizontal line distance at the (vertical) middle of the map screen.


I don't quite understand what you mean. Are you implying the Scale Bar is only correct at the Equator? I thought that might be true, but it appeared to change size, even at the same scale, when moving my viewing window North-South.
0 Kudos
MarkBaird
Esri Regular Contributor
I've noted the concerns and we will look into this.

Will let you know what we find.

Thanks for the feedback

Mark
0 Kudos
MarkBaird
Esri Regular Contributor
I want to report back on this issue.

We have investigated what is happening on the scale bar and have found that when using the web mercator projection there is an inaccuracy as suggested.

This has now been fixed and will be available in the next release.  However as this is a toolkit component and we make the code available anyway I'm quite happy to make the fix available if anyone is interested.

For information, the next release is likely to be available before the Palm Springs Developer Summit.
0 Kudos
StephenBaier
New Contributor III
Thanks for looking into the issue! I am definitely interested in having the fix ASAP.

Cheers
0 Kudos
MarkBaird
Esri Regular Contributor
The fix is needed on the scalebar overlay. In the existing method calcMapResolutionInMetres(), add the following 2 lines for map with linear units.

// FIX for Scalebar issue with linear Spatial References
// This is then multiplied by the cosine of latitude to get a more accurate number
// of metres per degree.
getExtentCentre(map);
_resolutionInMetres *= Math.cos(getExtentCentreLatitude(map.getSpatialReference()));


   /**
     * Convert the current map resolution to a resolution in metres per pixel.
     * This is used when calculating the scalebar sizes.
     *
     * @param map
     *            Convert the current resolution of this map.
     */
    private void calcMapResolutionInMetres(JMap map) {
      _resolutionInMetres = map.getResolution();

        if (_mapUnits.getUnitType() != UnitType.LINEAR) {
             // We have angular units and want to convert to metres. We do
             // this by taking our resolution per pixel in degrees and
             // multiplying it by the number of metres in a degree at the
             // equator (111200). This is then multiplied by the cosine of
             // our latitude to get a more accurate number of metres per
             // degree. We can then use this number to convert our degrees
             // per pixel to a metres per pixel value.
             getExtentCentre(map);
             _resolutionInMetres = Unit.convertUnits(_resolutionInMetres,
                    _mapUnits, Unit.create(AngularUnit.Code.DEGREE))
                    * 111200
                    * Math.cos(getExtentCentreLatitude(map
                            .getSpatialReference()));
         } else {
             // we have linear units so this is a simple conversion.
             LinearUnit linearUnit = (LinearUnit) _mapUnits;
             _resolutionInMetres = linearUnit
                    .convertToMeters(_resolutionInMetres);
            // FIX for Scalebar issue with linear Spatial References
            // This is then multiplied by the cosine of latitude to get a more accurate number
            // of metres per degree.
            getExtentCentre(map);
            _resolutionInMetres *= Math.cos(getExtentCentreLatitude(map.getSpatialReference()));
        }
    }


Let me know if this works better.

Mark
0 Kudos