0

我正在创建地图的 GUI 表示,但无法正确缩放画布。我目前正在绘制杜布罗夫尼克市的地图,杜布罗夫尼克市内的所有点的纬度都在 42N 到 43N 之间,经度在 18E 到 19E 之间。我想知道是否有办法设置 Canvas 使窗口的左上角是坐标 (42,19) 而右下角是 (43, 18)?任何帮助深表感谢。

4

1 回答 1

3

你不能,据我所知,没有内置的方法可以做到这一点。但是您当然可以实现自己的画布来完成这项工作。

就像是:

class GeoCanvas(Tk.Canvas):
    def __init__(self, master, uperleftcoords, bottomrightcoords, **kwargs):
        Canvas.__init__(self, master, **kwargs)

        self.minLat = uperleftcoords.getLat()
        self.maxLong = uperleftcoords.getLong()

        self.maxLat = bottomrightcoords.getLat()
        self.minLong = bottomrightcoords.getLong()

        self.width = **kwargs["width"]
        self.height= **kwargs["height"]

        self.geoWidth = self.maxLat - self.minLat
        self.geoHeight= self.maxLong - self.minLong

    def fromLatLong2pixels(self, coords):
        """ Convert a latitude/longitude coord to a pixel coordinate use it for every point you want to draw."""
        if ( not self.minLat <= coords.getLat() <= self.maxLat) or (not self.minLong <= coords.getLong() <= self.laxLong ):
            return None
        else:
            deltaLat = coords.getLat() - self.minLat
            deltaLong= coords.getLong()- self.minLong

            latRatio = deltaLat / self.geoWidth
            longRatio= deltaLong/ self.geoHeight

            x = latRation * self.width
            y = longRatio * self.height

            return x,y

然后,您可以覆盖用于将每个纬度/经度坐标转换为画布上的点的绘图方法。

于 2015-03-16T15:43:56.030 回答