Skip to content

Commit

Permalink
Enhanced external map support.
Browse files Browse the repository at this point in the history
  • Loading branch information
hamiltoncj committed Oct 16, 2019
1 parent 5009157 commit 15c8b43
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 15 deletions.
Binary file modified doc/settings3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion mapProviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
['MapQuest Map', 'https://www.mapquest.com/latlng/@LAT@,@LON@?centerOnResults=1&zoom=@Z@', 'https://www.mapquest.com/latlng/@LAT@,@LON@?centerOnResults=1&zoom=@Z@'],
['MapQuest Aerial', 'https://www.mapquest.com/latlng/@LAT@,@LON@?centerOnResults=1&maptyp=sat&zoom=@Z@', 'https://www.mapquest.com/latlng/@LAT@,@LON@?centerOnResults=1&maptyp=sat&zoom=@Z@'],
['Mapillary Street', 'https://www.mapillary.com/app/?lat=@LAT@&lng=@LON@&z=@Z@&mapStyle=mapbox_streets', 'https://www.mapillary.com/app/?lat=@LAT@&lng=@LON@&z=@Z@&mapStyle=mapbox_streets'],
['Mapillary Aerial', 'https://www.mapillary.com/app/?lat=@LAT@&lng=@LON@&z=@Z@&mapStyle=mapbox_satellite', 'https://www.mapillary.com/app/?lat=@LAT@&lng=@LON@&z=@Z@&mapStyle=mapbox_satellite']
['Mapillary Aerial', 'https://www.mapillary.com/app/?lat=@LAT@&lng=@LON@&z=@Z@&mapStyle=mapbox_satellite', 'https://www.mapillary.com/app/?lat=@LAT@&lng=@LON@&z=@Z@&mapStyle=mapbox_satellite'],
['iD Editor ESRI World Imagery', 'https://preview.ideditor.com/master/#background=EsriWorldImagery&disable_features=boundaries&map=@Z@/@LAT@/@LON@&overlays=BANO&photo_overlay=mapillary-map-features', 'https://preview.ideditor.com/master/#background=EsriWorldImagery&disable_features=boundaries&map=@Z@/@LAT@/@LON@&overlays=BANO&photo_overlay=mapillary-map-features'],
['iD Editor OpenTopoMap', 'https://preview.ideditor.com/master/#background=OpenTopoMap&disable_features=boundaries&map=@Z@/@LAT@/@LON@&overlays=BANO&photo_overlay=mapillary-map-features','https://preview.ideditor.com/master/#background=OpenTopoMap&disable_features=boundaries&map=@Z@/@LAT@/@LON@&overlays=BANO&photo_overlay=mapillary-map-features']
]


Expand Down
3 changes: 2 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name=Lat Lon Tools
qgisMinimumVersion=3.0
description=Tools to capture and zoom to coordinates using decimal, DMS, WKT, GeoJSON, MGRS, UTM, and Plus Codes formats. Provides external map support, point digitizing tools, and coordinate conversion tools.
version=3.3.6
version=3.3.7
author=C Hamilton
[email protected]
about=
Expand All @@ -27,6 +27,7 @@ icon=images/copyicon.png
experimental=False
deprecated=False
changelog=
3.3.7 - Enhanced Show in External Map capabilities
3.3.6 - Rename some of the tools for clarity.
3.3.5 - Enabled snapping with the Show in External Map tool.
3.3.4 - Bug fix
Expand Down
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Some of the functions can be accessed from the ***Lat Lon Tools*** toolbar. If f

* <img src="images/copyicon.png" alt="Copy/Display coordinate"> ***Copy/Display Coordinate*** - This captures coordinates onto the clipboard when the user clicks on the map, using the standard Google Map format or a format specified in ***Settings***. If the user specifies a **Tab** separator, then the coordinate can be pasted into a spreadsheet in separate columns. While this tool is selected, the coordinate the mouse is over is shown in the lower left-hand corner either in **decimal degrees**, **DMS**, **MGRS**, **Standard UTM**, **Plus Codes**, **WKT POINT**, or **GeoJSON** notation depending on the **Settings**. By default it uses the geographic Latitude and Longitude to snapshot the coordinate, but this can be configured in **Settings** to use the project CRS or any other projection desired. See the **Settings** section for more details on the all the possibilities. An additional prefix or suffix can be added to the coordinate and is configured in **Settings**. If snapping is enabled under QGIS ***Project->Snapping Options...*** menu, then *Copy/Display Coordinate* will snap to any close vector vertices according to the parameters set in the snapping options.

* <img src="images/mapicon.png" alt="Show in External Map"> ***Show in External Map*** - With this tool, the user can click on the QGIS map which launches an external browser and displays the location on an external map. Currently Open Street Map, Google Maps, MapQuest, and Bing Maps are supported. Google Earth is supported if it is installed on the system. The desired map can be configured in **Settings**. A temporary marker can be displayed on the map at the location clicked on. To turn this on go to **Settings**. If snapping is enabled, then the clicked location will snap to any close vector vertices according to the parameters set in the snapping options.
* <img src="images/mapicon.png" alt="Show in External Map"> ***Show in External Map*** - With this tool, the user can click on the QGIS map which launches an external browser and displays the location on an external map. The left and right mouse buttons can be configured to show different maps. Currently Open Street Map, Google Maps, MapQuest, Mapillary, Open Street Map iD Editor, and Bing Maps are supported. Google Earth is supported if it is installed on the system. The desired maps can be configured in **Settings**. A temporary marker can be displayed on the map at the location clicked on. To turn this on go to **Settings**. If snapping is enabled, then the clicked location will snap to any close vector vertices according to the parameters set in the snapping options.

* <img src="images/zoomicon.png" alt="Zoom-to"> ***Zoom to Coordinate*** - With this tool, type or paste a coordinate into the text area and hit **Enter**. QGIS centers the map on the coordinate, highlights the location and creates a temporary marker at the location. The marker can be removed with the <img src="doc/cleartool.jpg" alt="Clear marker"> button. If the default **WGS 84** (EPSG:4326 - latitude/longitude) coordinate system is specified, ***Zoom to Coordinate*** can interpret **decimal degrees**, **DMS**, **WKT POINT**, **Standard UTM**, **MGRS**, **Plus Codes**, or **GeoJSON** coordinates. It can also zoom to any other projection when configured in **Settings**. The ***Coordinate Order*** in ***Settings*** dictates whether the order is latitude followed by longitude (Y,X) or longitude followed by latitude (X,Y). By default the order is "Latitude, Longitude", the format used by Google Maps. Pressing the <img src="doc/zoomtool.jpg" alt="Zoom button"> also causes QGIS to zoom to that location.<br /><div style="text-align:center"><img src="doc/zoomto.jpg" alt="Zoom to Latitude, Longitude"></div><br />The following are acceptable coordinate formats when the ***Settings*** **Zoom to Coordinate Type** is set to ***WGS 84 (Latitude & Longitude)***. When the letters "N, S, E, W" are used, then the coordinate order is not important. These letters can be used before or after the coordinates. As long as the coordinate is understandable, punctuation, spaces, and &deg; ' " are optional. In these examples "d" represents degree digits, "m" minutes, and "s" seconds. Here are some example input formats:

Expand Down Expand Up @@ -189,7 +189,7 @@ The order in which the coordinates are parsed in the ***Zoom to Latitude, Longit

<div style="text-align:center"><img src="doc/settings3.jpg" alt="External Map Settings"></div>

You can ***Select an External Map Provider***. The options are:
You can ***Select an External Map Provider for Left Mouse***. The options are:

* **OSM** - Open Street Map
* **Google Map**
Expand All @@ -200,8 +200,12 @@ You can ***Select an External Map Provider***. The options are:
* **MapQuest Aerial**
* **Mapillary Street**
* **Mapillary Aerial**
* **iD Editor ESRI World Imagery**
* **iD Editor OpenTopoMap**
* **Google Earth** - (This only works if it is installed on your system)

***Select an External Map Provider for Right Mouse*** has the same set of options. These correspond to the left and right mouse buttons.

***Map Hints*** are desired attributes you would like to see in the resulting map.

* **Show placemark** - When checked the external map shows a placemark at the location clicked on in the QGIS map. If this is not checked then the external map centers itself around clicked location, but will not display the placemark.
Expand Down
30 changes: 22 additions & 8 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def readSettings(self):
### EXTERNAL MAP ###
self.showPlacemark = int(qset.value('/LatLonTools/ShowPlacemark', Qt.Checked))
self.mapProvider = int(qset.value('/LatLonTools/MapProvider', 0))
self.mapProviderRight = int(qset.value('/LatLonTools/MapProviderRight', 0))
self.mapZoom = int(qset.value('/LatLonTools/MapZoom', 13))
self.externalMapShowLocation = int(qset.value('/LatLonTools/ExternMapShowClickedLocation', Qt.Unchecked))

Expand All @@ -57,22 +58,31 @@ def readSettings(self):
self.converterDelimiter = qset.value('/LatLonTools/ConverterDelimiter', ', ')
self.converterDdmmssDelimiter = qset.value('/LatLonTools/ConverterDdmmssDelimiter', ', ')

def googleEarthMapProvider(self):
if self.mapProvider >= len(mapProviders.MAP_PROVIDERS):
return True
def googleEarthMapProvider(self, button=0):
if button == 2:
if self.mapProviderRight >= len(mapProviders.MAP_PROVIDERS):
return True
else:
if self.mapProvider >= len(mapProviders.MAP_PROVIDERS):
return True
return False

def getMapProviderString(self, lat, lon):
if self.showPlacemark:
ms = mapProviders.MAP_PROVIDERS[self.mapProvider][2]
def getMapProviderString(self, lat, lon, button=0):
if button == 2:
if self.showPlacemark:
ms = mapProviders.MAP_PROVIDERS[self.mapProviderRight][2]
else:
ms = mapProviders.MAP_PROVIDERS[self.mapProviderRight][1]
else:
ms = mapProviders.MAP_PROVIDERS[self.mapProvider][1]
if self.showPlacemark:
ms = mapProviders.MAP_PROVIDERS[self.mapProvider][2]
else:
ms = mapProviders.MAP_PROVIDERS[self.mapProvider][1]
ms = ms.replace('@LAT@', str(lat))
ms = ms.replace('@LON@', str(lon))
ms = ms.replace('@Z@', str(self.mapZoom))
return ms


settings = Settings()


Expand Down Expand Up @@ -118,6 +128,7 @@ def __init__(self, lltools, iface, parent):

### EXTERNAL MAP ###
self.mapProviderComboBox.addItems(mapProviders.mapProviderNames())
self.mapProviderRComboBox.addItems(mapProviders.mapProviderNames())

### MULTI-ZOOM ###
self.multiZoomToProjectionComboBox.addItems(['WGS 84 (Latitude & Longitude)', 'Project CRS', 'Custom CRS', 'MGRS', 'Plus Codes', 'Standard UTM'])
Expand Down Expand Up @@ -187,6 +198,7 @@ def restoreDefaults(self):
### EXTERNAL MAP ###
self.showPlacemarkCheckBox.setCheckState(Qt.Checked)
self.mapProviderComboBox.setCurrentIndex(0)
self.mapProviderRComboBox.setCurrentIndex(0)
self.zoomSpinBox.setValue(13)
self.showLocationCheckBox.setCheckState(Qt.Unchecked)

Expand Down Expand Up @@ -301,6 +313,7 @@ def accept(self):
qset.setValue('/LatLonTools/ShowPlacemark', self.showPlacemarkCheckBox.checkState())
qset.setValue('/LatLonTools/ExternMapShowClickedLocation', self.showLocationCheckBox.checkState())
qset.setValue('/LatLonTools/MapProvider', int(self.mapProviderComboBox.currentIndex()))
qset.setValue('/LatLonTools/MapProviderRight', int(self.mapProviderRComboBox.currentIndex()))
qset.setValue('/LatLonTools/MapZoom', int(self.zoomSpinBox.value()))

### MULTI-ZOOM TO SETTINGS ###
Expand Down Expand Up @@ -420,6 +433,7 @@ def showEvent(self, e):
self.showPlacemarkCheckBox.setCheckState(settings.showPlacemark)
self.showLocationCheckBox.setCheckState(settings.externalMapShowLocation)
self.mapProviderComboBox.setCurrentIndex(settings.mapProvider)
self.mapProviderRComboBox.setCurrentIndex(settings.mapProviderRight)
self.zoomSpinBox.setValue(settings.mapZoom)

### MULTI-ZOOM CUSTOM QML STYLE ###
Expand Down
6 changes: 4 additions & 2 deletions showOnMapTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ def canvasPressEvent(self, event):
else:
self.removeMarker()

button = event.button()

canvasCRS = self.canvas.mapSettings().destinationCrs()
transform = QgsCoordinateTransform(canvasCRS, epsg4326, QgsProject.instance())
pt4326 = transform.transform(pt.x(), pt.y())
lat = pt4326.y()
lon = pt4326.x()
if settings.googleEarthMapProvider():
if settings.googleEarthMapProvider(button):
f = tempfile.NamedTemporaryFile(mode='w', suffix=".kml", delete=False)
f.write('<?xml version="1.0" encoding="UTF-8"?>')
f.write('<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">')
Expand All @@ -72,7 +74,7 @@ def canvasPressEvent(self, event):
webbrowser.open(f.name)
self.iface.messageBar().pushMessage("", "Viewing Coordinate %f,%f in Google Earth" % (lat, lon), level=Qgis.Info, duration=3)
else:
mapprovider = settings.getMapProviderString(lat, lon)
mapprovider = settings.getMapProviderString(lat, lon, button)
url = QUrl(mapprovider).toString()
webbrowser.open(url, new=2)
self.iface.messageBar().pushMessage("", "Viewing Coordinate %f,%f in external map" % (lat, lon), level=Qgis.Info, duration=3)
Expand Down
12 changes: 11 additions & 1 deletion ui/latLonSettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,23 @@ Standard UTM - Only Standard UTM coordinates
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Select an External Map Provider</string>
<string>Select an External Map Provider for Left Mouse</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mapProviderComboBox"/>
</item>
<item>
<widget class="QLabel" name="label_39">
<property name="text">
<string>Select an External Map Provider for Right Mouse</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="mapProviderRComboBox"/>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
Expand Down

0 comments on commit 15c8b43

Please sign in to comment.