Make static functions and self reference for helper

This commit is contained in:
Chris Pham
2018-02-03 14:02:23 -08:00
parent 0cbd593380
commit 10c9dc8451
2 changed files with 9 additions and 7 deletions

View File

@@ -1,14 +1,15 @@
import PIL.Image import PIL.Image
class MapHelper(object): class MapHelper(object):
def __init__(self):
return
def new_image(self, width, height): @staticmethod
def new_image(width, height):
return PIL.Image.new('RGBA', (width, height)) return PIL.Image.new('RGBA', (width, height))
def fast_round(self, value, precision): @staticmethod
def fast_round(value, precision):
return int(value * 10 ** precision) / 10. ** precision return int(value * 10 ** precision) / 10. ** precision
def pixels_to_degrees(self, pixels, zoom): @staticmethod
def pixels_to_degrees(pixels, zoom):
return pixels * 2 ** (21-zoom) return pixels * 2 ** (21-zoom)

View File

@@ -55,7 +55,7 @@ class GMapsStitcher(object):
def __init__(self, width, height, def __init__(self, width, height,
latitude, longitude, zoom, latitude, longitude, zoom,
maptype, radius_meters=None, num_tiles=4, debug=False): maptype, radius_meters=None, num_tiles=4, debug=False):
helper = MapHelper.MapHelper() self.helper = MapHelper.MapHelper()
self.latitude = latitude self.latitude = latitude
self.longitude = longitude self.longitude = longitude
self.start_latitude = latitude self.start_latitude = latitude
@@ -66,9 +66,10 @@ class GMapsStitcher(object):
self.maptype = maptype self.maptype = maptype
self.radius_meters = radius_meters self.radius_meters = radius_meters
self.num_tiles = num_tiles self.num_tiles = num_tiles
self.display_image = helper.new_image(width, height) self.display_image = self.helper.new_image(width, height)
self.debug = debug self.debug = debug
# Get the big image here # Get the big image here
self._fetch() self._fetch()
self.center_display(latitude, longitude) self.center_display(latitude, longitude)