Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
Add 6 types of Bing Maps to Mapping options
Requires Bing API - but free to signup and does not need billing info/VISA
Change to requests for image download for compatibility
  • Loading branch information
ghawken committed Jan 31, 2020
1 parent e340ceb commit ce58eb5
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 10 deletions.
2 changes: 1 addition & 1 deletion iFindFriendsMini.indigoPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>1.0.2</string>
<string>1.0.3</string>
<key>ServerApiVersion</key>
<string>2.0</string>
<key>CFBundleDisplayName</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
<Option value="arcgisWorldImagery">ArcGis World Imagery</Option>
<Option value="arcgisWorldStreetMap">ArcGis World Street Map</Option>
<Option value="maps.six">maps.six.nsw.gov.au NSW Au Satellite Maps</Option>
<Option value="BingRoad">Bing Road Maps</Option>
<Option value="BingSatellite">Bing Aerial with Label Maps</Option>
<Option value="BingSatelliteWO">Bing Aerial without Label Maps</Option>
<Option value="BingGray">Bing Grayscale Road Maps</Option>
<Option value="BingBirdsEye">Bing BirdsEye Maps (if available)</Option>
<Option value="BingCanvasLight">Bing Road Maps - Lighter Version</Option>
</List>
</Field>

Expand Down Expand Up @@ -115,6 +121,20 @@
</Label>
</Field>
<Field id="googlesep1" type="separator" visibleBindingId="mapType" visibleBindingValue="google"/>

<Field id="bingsep2" type="separator" visibleBindingId="mapType" visibleBindingValue="BingRoad,BingSatellite,BingGray,BingBirdsEye,BingCanvasLight,BingSatelliteWO"/>
<Field id="BingAPI" type="textfield" tooltip="BING Mapping API Key" defaultValue="" visibleBindingId="mapType" visibleBindingValue="BingRoad,BingSatellite,BingGray,BingBirdsEye,BingCanvasLight,BingSatelliteWO" >
<Label>Enter Bing Mapping API Here:</Label><Label/>
<Description>Bing API Key for Mapping</Description>
</Field>
<Field id="bingAPIWarning" type="label" alignText="right" visibleBindingId="mapType" visibleBindingValue="BingRoad,BingSatellite,BingGray,BingBirdsEye,BingCanvasLight,BingSatelliteWO" >
<Label>Bing API usage may incur costs, use at own risk...
Unlike Google does not need billing details to use free account

</Label>
</Field>
<Field id="bingsep1" type="separator" visibleBindingId="mapType" visibleBindingValue="BingRoad,BingSatellite,BingGray,BingBirdsEye,BingCanvasLight,BingSatelliteWO"/>

<Field id="travelTime" type="textfield" tooltip="Time to travel 1 kilometer" defaultValue="">
<Label>Meters/Second for Travel calculation:</Label><Label/>
<Description>Enter travel speed for approx travel time calculations in meters/second eg. 16.7 m/s = 60km/hr</Description>
Expand Down
89 changes: 80 additions & 9 deletions iFindFriendsMini.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,13 @@ def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs):
self.configVerticalMap = self.pluginPrefs.get('verticalMap', "600")
self.useMaps = self.pluginPrefs.get('useMaps',False)
self.mapType = self.pluginPrefs.get('mapType', "openstreetmap")
if self.mapType == None:
self.useMaps = False
self.configHorizontalMap = self.pluginPrefs.get('horizontalMap', "600")
self.configZoomMap = self.pluginPrefs.get('ZoomMap', "15")
self.datetimeFormat = self.pluginPrefs.get('datetimeFormat','%c')
self.googleAPI = self.pluginPrefs.get('googleAPI','')

self.BingAPI = self.pluginPrefs.get('BingAPI','')
self.travelTime = self.pluginPrefs.get('travelTime','16.7')
self.deviceNeedsUpdated = ''
self.openStore = self.pluginPrefs.get('openStore',False)
Expand Down Expand Up @@ -332,6 +334,7 @@ def closedPrefsConfigUi(self, valuesDict, userCancelled):
self.configZoomMap = valuesDict.get('ZoomMap', "15")
self.datetimeFormat = valuesDict.get('datetimeFormat', '%c')
self.googleAPI = valuesDict.get('googleAPI', '')
self.BingAPI = valuesDict.get('BingAPI','')
self.openStore = valuesDict.get('openStore', False)
self.updateFrequency = float(valuesDict.get('updateFrequency', "24")) * 60.0 * 60.0
# If plugin config menu closed update the time for check. Will apply after first change.
Expand Down Expand Up @@ -1173,12 +1176,27 @@ def refreshDataForDev(self, dev, follow):
dev.updateStateImageOnServer(indigo.kStateImageSel.SensorOff)
return

def requestSaveUrl(self, url, file):
try:
self.logger.debug("Saving url"+url+" as file:"+file)
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}

r = requests.get(url, headers=headers, stream=True, timeout=10)
with open(file, 'wb') as f:
for chunk in r.iter_content():
f.write(chunk)
except:
self.logger.exception("Exception in saveURL Requests")


def godoMapping(self, latitude, longitude, dev):

self.logger.debug(u"godoMapping() method called.")
try:
if not self.useMaps:
self.logger.debug("UseMaps not enabled. Returning.")
if self.debugmaps:
self.logger.debug("UseMaps not enabled. Returning.")
return

MAChome = os.path.expanduser("~") + "/"
Expand All @@ -1191,21 +1209,31 @@ def godoMapping(self, latitude, longitude, dev):
if dev.states['mapUpdateNeeded']:
self.logger.debug(u'update Map Happening as device moved..')
drawUrl = self.urlGenerate(latitude ,longitude ,self.googleAPI, int(self.configHorizontalMap), int(self.configVerticalMap), int(self.configZoomMap), dev)
if self.debugmaps:
self.logger.debug(u'drawURL 0=:'+unicode(drawUrl[0]))

if self.debugmaps:
webbrowser.open_new(drawUrl[0])
#webbrowser.open_new(drawUrl[1])
fileMap = "curl --output '" + file + "' --url '" + drawUrl[0] + "'"
os.system(fileMap)

#fileMap = "curl --output '" + file + "' --url '" + drawUrl[0] + "'"
#os.system(fileMap)

self.requestSaveUrl(drawUrl[0],file)


self.logger.debug('Saving Map...' + file)

filename = 'All_device.jpg'
file = folderLocation + filename
# Generate URL for All Maps - if using Google; not with openstreetmap
if self.mapType=='google':
drawUrlall = self.urlAllGenerate(self.googleAPI, int(self.configHorizontalMap), int(self.configVerticalMap), int(self.configZoomMap))
fileMap = "curl --output '" + file + "' --url '" + drawUrlall + "'"
os.system(fileMap)
self.logger.debug('Saving Map...' + file)
#fileMap = "curl --output '" + file + "' --url '" + drawUrlall + "'"
#os.system(fileMap)
self.requestSaveUrl(drawUrlall, file)
if self.debugmaps:
self.logger.debug('Saving Map...' + file)

dev.updateStateOnServer('mapUpdateNeeded',value=False)

Expand Down Expand Up @@ -1433,6 +1461,7 @@ def urlGenerate(self, latitude, longitude, mapAPIKey, iHorizontal, iVertical, iZ
# Create Map url
mapCentre = 'center=' + str(latitude) + "," + str(longitude)


# Set size
if self.mapType=='google':
if iZoom < 0:
Expand All @@ -1447,6 +1476,15 @@ def urlGenerate(self, latitude, longitude, mapAPIKey, iHorizontal, iVertical, iZ
iVertical = 640
elif iVertical < 50:
iVertical = 50
mapAPIKey = self.googleAPI

if 'Bing' in self.mapType:
if iZoom < 0:
iZoom = 0
elif iZoom > 20:
iZoom = 20
mapAPIKey = self.BingAPI

mapZoom = 'zoom=' + str(iZoom)

mapSize = 'size=' + str(iHorizontal) + 'x' + str(iVertical)
Expand All @@ -1465,7 +1503,7 @@ def urlGenerate(self, latitude, longitude, mapAPIKey, iHorizontal, iVertical, iZ

mapOSM = 'http://staticmap.openstreetmap.de/staticmap.php?center='+str(latitude)+','+str(longitude)+'&'+str(mapZoom)+'&' + mapSize + '&markers='+str(latitude)+','+str(longitude)+','+str(mapLabel)

if self.mapType =='arcgisWorld2d' or self.mapType=='arcgisWorldImagery' or self.mapType=='arcgisWorldStreetMap' or self.mapType=='arcgisWorldImageryHybrid' or self.mapType=='maps.six':
if self.mapType =='arcgisWorld2d' or 'Bing' in self.mapType or self.mapType=='arcgisWorldImagery' or self.mapType=='arcgisWorldStreetMap' or self.mapType=='arcgisWorldImageryHybrid' or self.mapType=='maps.six':
latitude = float(latitude)
longitude = float(longitude)
# Fudge a similar zoom
Expand All @@ -1486,14 +1524,47 @@ def urlGenerate(self, latitude, longitude, mapAPIKey, iHorizontal, iVertical, iZ
mapWorld2d = 'http://maps.six.nsw.gov.au/arcgis/rest/services/public/NSW_Imagery/MapServer/export?bbox=' + str(
toplongitude) + ',' + str(toplatitude) + ',' + str(bottomlongitude) + ',' + str(
bottomlatitude) + '&bboxSR=4326' + '&size=' + str(iHorizontal) + ',' + str(iVertical) + '&f=image'
if 'Bing' in self.mapType:
mapWorld2d = 'http://bing.com/maps/embed?cp=' + str(latitude) + '~' + str(longitude) + "&h="+str(iVertical)+ "&w="+str(iHorizontal)
BingStatic = 'http://dev.virtualearth.net/REST/v1/Imagery/Map'

if 'Satellite' in self.mapType:
mapWorld2d = mapWorld2d + "&style=h"
if 'SatelliteWO' in self.mapType:
BingStatic = BingStatic + "/Aerial"
else:
BingStatic = BingStatic + "/AerialWithLabels"
elif 'Road' in self.mapType:
mapWorld2d = mapWorld2d + "&style=r"
BingStatic = BingStatic + '/Road'
elif 'Gray' in self.mapType:
mapWorld2d = mapWorld2d + "&style=r"
BingStatic = BingStatic + '/CanvasGray'
elif 'BirdsEye' in self.mapType:
mapWorld2d = mapWorld2d + "&style=h"
BingStatic = BingStatic + '/BirdsEye'
elif 'Canvas' in self.mapType:
mapWorld2d = mapWorld2d + "&style=r"
BingStatic = BingStatic + '/CanvasLight'

mapWorld2d= mapWorld2d + "&lvl="+str(iZoom)
BingStatic = BingStatic + '/'+ str(latitude) + "," + str(longitude) + "/" + str(iZoom)+ "?mapsize="+str(iHorizontal)+","+str(iVertical)
if 'Roads' in self.mapType or 'Canvas' in self.mapType:
BingStatic = BingStatic + '&mapLayer=Basemap,Buildings'
BingStatic = BingStatic + "&key="+self.BingAPI



if self.mapType=='google':
return customURL, urlmapGoogle
elif self.mapType=='openstreetmap':
return mapOSM, urlmapGoogle
elif self.mapType =='arcgisWorld2d' or self.mapType=='arcgisWorldImagery' or self.mapType=='arcgisWorldStreetMap' or self.mapType=='maps.six':
return mapWorld2d, urlmapGoogle

elif 'Bing' in self.mapType:
return BingStatic, mapWorld2d
else:
return 0,0


except Exception as e:
Expand Down

0 comments on commit ce58eb5

Please sign in to comment.