Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I got a problem for the scale line when I using openlayer to show my "star map". Basically, I give a set of 2D coodinates (X,Y) for each star, and generate the map using map server. Now the map can be correctly shown, but when I add scaleline control, I found the scaleline always starts at 500000000KM which is not correct. And the correct scale should be 5400KM, which if I directly use mapserver CGI, it show correctly. Hope anyone can help me out!

Here is mapfile : MAP NAME "starmap1" PROJECTION "init=epsg:4326" END UNITS meters IMAGETYPE PNG EXTENT -31230139.51 -8267352.329 36978851.96 9060799.858 SIZE 800 600

Here is my javascript (using Geoext ):

    panel = new GeoExt.MapPanel({
    renderTo: "mappanel",
    map: { maxExtent: new OpenLayers.Bounds(-31230139.510000,-25170977.043091,
        maxResolution: 85367.949274,
        numZoomLevels:40} ,
        width: 800,
        height: 600,
        floating: true,
        x: 70,
        y: 350
   panel.map.addControl(new OpenLayers.Control.ScaleLine());

Thanks zhizhuo

share|improve this question
add comment

1 Answer 1

the problem you have came up against is about projection problem. you can modify it when adding this to your mapOptions:

projection: new OpenLayers.Projection('EPSG:900913'),
displayProjection: new OpenLayers.Projection('EPSG:4326')

if you change them with each other, you can get 100.000 times greater result..

i hope it helps you....

share|improve this answer
thanks for the reply. I tried to add two options above, but mapserver return error msg "SRS must valid for all request layer" . Can I ask why you suggest to project EPSG:900913 , but my mapfile using epsg:4326? Sorry, I am a newbie in this field. –  zzz May 15 '12 at 8:14
it calculates the scale line with metric way. ok if it is problem, get olControlScaleLine class element and divide it to 100.000 for real result... –  Aragon May 15 '12 at 8:25
I notice the error because no definition for 900913 in /usr/share/proj/epsg file. I add the definition, and error disappears. And I try to change my mapfile "PROJECTION "init=epsg:900913" END ", the map can show correctly, but scaleline still the same as the old version, and the scale are not correct. Need more help... thank you –  zzz May 15 '12 at 8:33
I think now the scale is 100000 times more than the real one. –  zzz May 15 '12 at 8:38
Dear Aragon, can you tell how to "get olControlScaleLine class element and divide it to 100.000 for real result..."? I know I can get the value in this way: var sl=new OpenLayers.Control.ScaleLine(); alert(sl.div.firstChild.innerHTML); –  zzz May 15 '12 at 9:01
show 2 more comments

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.