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

Bjoern Platzen bplatzen at sosnetz.de
Tue Jul 8 09:57:20 EDT 2003


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