00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 import matplotlib
00017 from objects.logic.common.logger import logger
00018 from objects.logic.common.exception import exception
00019 from matplotlib.toolkits.basemap import Basemap
00020
00021
00022 import pylab as p
00023
00024 matplotlib.interactive(False)
00025 matplotlib.use('WXAgg')
00026
00027
00028
00029
00030 class mainFrameMap():
00031 def __init__(self, figAxesWrapper):
00032 self.fig_axes = figAxesWrapper
00033
00034
00035
00036
00037
00038
00039 def createMap(self, mapDetail, drawCSBorders, drawRivers):
00040
00041 if mapDetail == True:
00042 res = 'l'
00043 else:
00044 res = 'c'
00045
00046 try:
00047 self.main_map = Basemap(-180.,-80.,180.,80.,\
00048 resolution=res,area_thresh=10000.,projection='merc',\
00049 lon_0=0.,lat_ts=20.,\
00050 ax=self.fig_axes.axes)
00051
00052
00053
00054 except IOError, mapCreationError:
00055 e = exception(str(mapCreationError ), True)
00056 raise e
00057
00058
00059 self.main_map.drawcoastlines(linewidth=0.5)
00060 if drawCSBorders == True:
00061 self.main_map.drawcountries()
00062 self.main_map.drawstates(linewidth=0.1)
00063
00064 if drawRivers == True:
00065 self.main_map.drawrivers(color='b',linewidth=0.05)
00066
00067 self.main_map.fillcontinents(color='beige')
00068 self.main_map.drawmapboundary()
00069
00070
00071
00072 def clearAllMapElements(self):
00073
00074 self.fig_axes.axes.lines = []
00075
00076 self.fig_axes.axes.texts = []
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 def draw(self, entityDict, displayer,
00087 showLines, showLabels,
00088 homeLon, homeLat):
00089
00090 lonList = list()
00091 latList = list()
00092
00093 markerList = list()
00094 lineList = list()
00095
00096 self.clearAllMapElements()
00097
00098
00099 textYOffsetMagicNum = int(self.fig_axes.getZoomFactor() / 100)
00100
00101 displayedItems = 0
00102
00103 for key, entList in entityDict.iteritems():
00104
00105
00106 if len(entList) > 1:
00107 displayedItems += len(entList)
00108 displayAttributes = displayer.getAttrFromList(entList)
00109 else:
00110 displayedItems += 1
00111 displayAttributes = displayer.getAttrFromEntity(entList[0])
00112
00113 longitude = key[0]
00114 latitude = key[1]
00115
00116 lonList.append(longitude)
00117 latList.append(latitude)
00118
00119 xMap,yMap = self.main_map((lonList), (latList))
00120 x,y = self.main_map((longitude), (latitude))
00121
00122 markerList.append(xMap)
00123 markerList.append(yMap)
00124
00125 markerList.append(displayAttributes["marker"])
00126
00127 lonList = list()
00128 latList = list()
00129
00130 if showLines == True:
00131
00132 line_x,line_y = self.main_map.gcpoints(homeLon, homeLat,longitude,latitude,2)
00133
00134 self.main_map.plot(line_x,line_y, "k" + displayAttributes["lineStyle"], linewidth=displayAttributes["lineWidth"],antialiased=True, alpha=displayAttributes["lineAlpha"])
00135
00136
00137 if showLabels == True:
00138 self.fig_axes.axes.text(x, y + textYOffsetMagicNum, displayAttributes["label"], fontsize=10,
00139 horizontalalignment='center')
00140
00141 self.main_map.plot(xMap, yMap, displayAttributes["marker"], markersize=displayAttributes["markerSize"], color=displayAttributes["markerColor"] )
00142
00143
00144
00145
00146
00147 selfX, selfY = self.main_map(homeLon, homeLat)
00148
00149 selfXLst= []
00150 selfYLst = []
00151 selfXLst.append(selfX)
00152 selfYLst.append(selfY)
00153 self.main_map.plot(selfXLst,selfYLst,'b^',label='', markersize=8)
00154
00155
00156 self.fig_axes.resetCurrentZoom()
00157
00158 return displayedItems
00159
00160
00161
00162
00163