マップの GUI 表現の作成に取り組んでいますが、キャンバスを正しくスケーリングするのに問題があります。私は現在、ドブロブニク市の地図を作成しており、ドブロブニク内のすべての地点の緯度は北緯 42 度から北緯 43 度、経度は東経 18 度から東経 19 度です。ウィンドウの左上隅が座標 (42,19) で、右下隅が (43, 18) になるようにキャンバスを設定する方法があるかどうか疑問に思っていました。どんな助けでも大歓迎です。
1078 次
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 に答える