[Mapserver-users] MapScript: map-Y coordinate is always wrong while map-X is right

Bjoern Platzen bplatzen at sosnetz.de
Wed Jul 9 03:05:51 EDT 2003


Hi all,

I found the final problem...

It was not only the functions, that calculated, it was as well the 
parameters, I called the functions with:

self.mapXY = self._click2map(float(self.webargs['img.x']), 
float(self.webargs['img.x']), self.mapExtent)
                   ^^^^^^^

But I still got one question:
The map is initialized with an extend from the mapfile 
(2542000 5664000 2557000 5679000)
The mapserv-cgi returns [mapext] = 2542091.670667 5664091.670667 
2556908.329333 5678908.329333.
I think the returned value is the imgext, right?

So, can I get the imgext in MapScript or will I have to set the inital 
EXTENT in the mapfile to the visible extent? This would mean, that I 
would have to test each mapfile with the cgi to get the correct 
EXTENT-values, wich I can't believe...

Thanks in advance,

Bjoern.


Am Dienstag, 8. Juli 2003 15:57 schrieb Bjoern Platzen:
> Hello List,
>
> maybe I'm just to blind, but I can't figure out, what is going wrong.
>
> I wrote a small Program using PythonMapscript.
>
> I'm calculating the following to get the Map-Coordinates from the
> Click-Coordinates (where clickX and clickY come as img.x and img.y
> from a HTML-form, Extend is the [mapext]):
>
> def _click2map(self,clickX, clickY, Extend):
>     '''Uebersetze Klick-Koordinaten in Kartenkoordinaten'''
>     Extend = Extend.split(" ")
>
>     cx = (float(Extend[2])-float(Extend[0]))/(self.mymap.width-1)
>     cy = (float(Extend[3])-float(Extend[1]))/(self.mymap.height-1)
>
>     xMap = float(currentExtend[0])+cx*clickX
>     yMap = float(currentExtend[1])+cy*clickY
>
>     return (xMap,yMap)
>
> I took the function from a PerlMapScript Example. But it doesn't work
> for me. The yMap is always wrong while the xMap is always right...
>
> Maybe this comes because I have a mistake in my function that
> calculates the Extend (mapext):
>
> def _newExtend(self, Extend, zoomdir=0, zoomsize=1):
>
>     currentExtend = Extend.split(" ")
>
>     if zoomdir == 0:
>         zoom = 1
>     else:
>         zoom = zoomsize * zoomdir
>         if zoom < 0:
>             zoom = 1.0/abs(zoom)
>
>     cx = self.mapXY[0]
>     cy = self.mapXY[1]
>
>     he = float(currentExtend[2])-float(currentExtend[0])
>     wi = float(currentExtend[3])-float(currentExtend[1])
>
>     self.mymap.extent.maxx = cx + (he/zoom)/2
>     self.mymap.extent.minx = cx - (he/zoom)/2
>     self.mymap.extent.maxy = cy + (wi/zoom)/2
>     self.mymap.extent.miny = cy - (wi/zoom)/2
>     return 1
>
> The imgext is calculated this way:
>
> def _imageExtend(self):
>     '''Finde den tatsaechlich sichtbaren Extent heraus'''
>     loleft = self._click2map(0,self.mymap.height,self.mapExtent)
>     upright = self._click2map(self.mymap.width,0,self.mapExtent)
>     Ext = str(loleft[0])+" "+str(loleft[1])+" "+str(upright[0])+"
> "+str(upright[1])
>     return Ext
>
> I hope, that there is anyone on the list, who can push me in the
> right direction.
>
> Thanks in advance,
>
> Bjoern

-- 
small office solutions
info at sosnetz.de  -  http://www.sosnetz.de




More information about the mapserver-users mailing list