def routeFrom(self, fromWhere): """Route from somewhere to this POI""" if fromWhere == 'currentPosition': # route from current position to this POI pos = modrana.get('pos', None) if pos: (fromLat, fromLon) = pos # clear old route (if any) and route to the point modrana.sendMessage( 'route:clearRoute|md:route:route:type=ll2ll;fromLat=%f;fromLon=%f;toLat=%f;toLon=%f;' % (fromLat, fromLon, self.lat, self.lon))
def routeFrom(self, fromWhere): """Route from somewhere to this POI""" if fromWhere == 'currentPosition': # route from current position to this POI pos = modrana.get('pos', None) if pos: (fromLat, fromLon) = pos # clear old route (if any) and route to the point modrana.sendMessage( 'route:clearRoute|md:route:route:type=ll2ll;fromLat=%f;fromLon=%f;toLat=%f;toLon=%f;' % (fromLat, fromLon, self.lat, self.lon) )
def wrapper(*args, **kwargs): start = True # check if the kwargs trigger is enabled if conditional: start = kwargs.get("gps") # check if GPS usage is enabled in modRana gpsEnabled = modrana.get('GPSEnabled') if start and gpsEnabled: location = modrana.m.get('location') if location: location.start_location() return function(*args, **kwargs)
def wrapper(*args, **kwargs): start = True # check if the kwargs trigger is enabled if conditional: start = kwargs.get("gps") # check if GPS usage is enabled in modRana gpsEnabled = modrana.get('GPSEnabled') if start and gpsEnabled: location = modrana.m.get('location') if location: location.startLocation() return function(*args, **kwargs)
def locateCurrentPosition(controller=None): """Try to locate current position and return it when done or time out""" result = None sleepTime = 0.5 # in seconds pos = modrana.get('pos', None) fix = modrana.get('fix', 1) # check if GPS usage is explicitly disabled in modRana gpsEnabled = modrana.get('GPSEnabled') if gpsEnabled == False: if pos: modrana.notify("GPS OFF, using last known position", 5000) return Point(*pos) else: modrana.notify("GPS OFF, no last known position", 5000) return None if fix > 1 and pos: return Point(*pos) # fix found, return it at once # check if GPS hardware has been enabled location = modrana.m.get("location") if not location.enabled: # location usage has not be disabled but location # has not been started, so start location location.start_location() # wait for the fix startTimestamp = time.time() elapsed = 0 if controller: controller.status = "GPS fix in progress" while elapsed < constants.LOCATION_TIMEOUT: pos = modrana.get('pos', None) fix = modrana.get('fix', 1) if fix > 1 and pos: break time.sleep(sleepTime) elapsed = time.time() - startTimestamp if fix > 1 and pos: # got GPS fix ? return Point(*pos) else: # no GPS lock pos = modrana.get("pos") if pos: modrana.notify("no fix, using last known position", 5000) return Point(*pos) else: modrana.notify("failed to get GPS fix", 5000) return None
def locateCurrentPosition(controller=None): """Try to locate current position and return it when done or time out""" result = None sleepTime = 0.5 # in seconds pos = modrana.get('pos', None) fix = modrana.get('fix', 1) # check if GPS usage is explicitly disabled in modRana gpsEnabled = modrana.get('GPSEnabled') if gpsEnabled == False: if pos: modrana.notify("GPS OFF, using last known position", 5000) return Point(*pos) else: modrana.notify("GPS OFF, no last known position", 5000) return None if fix > 1 and pos: return Point(*pos) # fix found, return it at once # check if GPS hardware has been enabled location = modrana.m.get("location") if not location.enabled: # location usage has not be disabled but location # has not been started, so start location location.startLocation() # wait for the fix startTimestamp = time.time() elapsed = 0 if controller: controller.status = "GPS fix in progress" while elapsed < constants.LOCATION_TIMEOUT: pos = modrana.get('pos', None) fix = modrana.get('fix', 1) if fix > 1 and pos: break time.sleep(sleepTime) elapsed = time.time() - startTimestamp if fix > 1 and pos: # got GPS fix ? return Point(*pos) else: # no GPS lock pos = modrana.get("pos") if pos: modrana.notify("no fix, using last known position", 5000) return Point(*pos) else: modrana.notify("failed to get GPS fix", 5000) return None
def _saveTileForURL(self, lzxy): """save a tile for url created from its coordinates""" url = tiles.getTileUrl(lzxy) goAhead = False redownload = int(modrana.get('batchRedownloadAvailableTiles', False)) # TODO: use constants for the ENUM if not redownload: # does the the file exist ? # -> don't download it if it does goAhead = not self._storeTiles.tileExists2(lzxy, fromThread=True) elif redownload == 1: # redownload all goAhead = True elif redownload == 2: # update # only download tiles in the area that already exist goAhead = self._storeTiles.tileExists2(lzxy, fromThread=True) if goAhead: # if the file does not exist request = self._connPool.request('get', url) size = int(request.getheaders()['content-length']) content = request.data # The tileserver sometimes returns a HTML error page # instead of the tile, which is then saved instead of the tile an # users are then confused why tiles they have downloaded don't show up. # To raise a proper error on this behaviour, we check the tiles magic number # and if is not an image we raise the TileNotImageException. # TODO: does someone supply non-bitmap/SVG tiles ? if utils.isTheStringAnImage(content): #its an image, save it self._storeTiles.automaticStoreTile(content, lzxy) else: # its not ana image, raise exception raise TileNotImageException(url) return size # something was actually downloaded and saved else: return False # nothing was downloaded
def _maxThreads(self): return int(modrana.get('maxDlThreads', constants.DEFAULT_THREAD_COUNT_AUTOMATIC_TILE_DOWNLOAD))
def _maxThreads(self): return int(modrana.get('maxSizeThreads', constants.DEFAULT_THREAD_COUNT_BATCH_SIZE_CHECK))
def _maxThreads(self): return modrana.get('maxDlThreads', 5)