1

I got a problem for the scale line when I using OpenLayers to show my "star map".

Basically, I give a set of 2D coordinates (X,Y) for each star, and generate the map using MapServer. 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. The correct scale should be 5400KM, which if I directly use MapServer CGI, it show correctly.

Hope anyone can help me out.

Here is map file:

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,
        36978851.960000,25964424.572091),  
        maxResolution: 85367.949274,
        numZoomLevels:40} ,
        width: 800,
        height: 600,
        floating: true,
        x: 70,
        y: 350
    });

panel.map.zoomToMaxExtent();
panel.map.addControl(new OpenLayers.Control.ScaleLine());
2

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....

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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