本文整理汇总了Python中geoplotlib.core.BatchPainter.sprites方法的典型用法代码示例。如果您正苦于以下问题:Python BatchPainter.sprites方法的具体用法?Python BatchPainter.sprites怎么用?Python BatchPainter.sprites使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geoplotlib.core.BatchPainter
的用法示例。
在下文中一共展示了BatchPainter.sprites方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MarkersLayer
# 需要导入模块: from geoplotlib.core import BatchPainter [as 别名]
# 或者: from geoplotlib.core.BatchPainter import sprites [as 别名]
class MarkersLayer(BaseLayer):
def __init__(self, data, marker, f_tooltip=None, marker_preferred_size=32):
"""
Draw markers
:param data: data access object
:param marker: full filename of the marker image
:param f_tooltip: function to generate a tooltip on mouseover
:param marker_preferred_size: size in pixel for the marker images
"""
self.data = data
self.f_tooltip = f_tooltip
self.marker_preferred_size = float(marker_preferred_size)
self.marker = pyglet.image.load(marker)
self.marker.anchor_x = self.marker.width / 2
self.marker.anchor_y = self.marker.height / 2
self.scale = self.marker_preferred_size / max(self.marker.width, self.marker.height)
self.hotspots = HotspotManager()
def invalidate(self, proj):
self.painter = BatchPainter()
x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat'])
if self.f_tooltip:
for i in range(0, len(x)):
record = {k: self.data[k][i] for k in self.data.keys()}
self.hotspots.add_rect(x[i] - self.marker_preferred_size/2,
y[i] - self.marker_preferred_size/2,
self.marker_preferred_size,
self.marker_preferred_size,
self.f_tooltip(record))
self.painter.sprites(self.marker, x, y, self.scale)
def draw(self, proj, mouse_x, mouse_y, ui_manager):
self.painter.batch_draw()
picked = self.hotspots.pick(mouse_x, mouse_y)
if picked:
ui_manager.tooltip(picked)
def bbox(self):
return BoundingBox.from_points(lons=self.data['lon'], lats=self.data['lat'])