| 
									
										
										
										
											2018-03-08 21:53:00 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							|  |  |  | import QtQuick 2.6 | 
					
						
							|  |  |  | import QtPositioning 5.3 | 
					
						
							|  |  |  | import org.subsurfacedivelog.mobile 1.0 | 
					
						
							| 
									
										
										
										
											2018-09-27 22:09:26 +02:00
										 |  |  | import org.kde.kirigami 2.4 as Kirigami | 
					
						
							| 
									
										
										
										
											2018-03-08 21:53:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | Kirigami.Page { | 
					
						
							|  |  |  | 	id: mapPage | 
					
						
							|  |  |  | 	objectName: "MapPage" | 
					
						
							|  |  |  | 	title: qsTr("Map") | 
					
						
							|  |  |  | 	leftPadding: 0 | 
					
						
							|  |  |  | 	topPadding: 0 | 
					
						
							|  |  |  | 	rightPadding: 0 | 
					
						
							|  |  |  | 	bottomPadding: 0 | 
					
						
							| 
									
										
										
										
											2018-04-02 22:48:23 +03:00
										 |  |  | 	property bool firstRun: true | 
					
						
							| 
									
										
										
										
											2019-10-05 20:27:05 -07:00
										 |  |  | 	width: rootItem.colWidth | 
					
						
							| 
									
										
										
										
											2018-03-08 21:53:00 +02:00
										 |  |  | 	MapWidget { | 
					
						
							|  |  |  | 		id: mapWidget | 
					
						
							|  |  |  | 		anchors.fill: parent | 
					
						
							|  |  |  | 		onSelectedDivesChanged: { | 
					
						
							|  |  |  | 			if (list.length === 0) { | 
					
						
							|  |  |  | 				console.warn("main.qml: onSelectedDivesChanged(): received empty list!") | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			var id = list[0] // only single dive selection is supported
 | 
					
						
							|  |  |  | 			var idx = diveModel.getIdxForId(id) | 
					
						
							|  |  |  | 			if (idx === -1) { | 
					
						
							|  |  |  | 				console.warn("main.qml: onSelectedDivesChanged(): cannot find list index for dive id:", id) | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			diveList.setCurrentDiveListIndex(idx, true) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-02 22:51:59 +03:00
										 |  |  | 		Component.onCompleted: { | 
					
						
							|  |  |  | 			mapWidget.map.zoomLevel = mapWidget.map.defaultZoomOut | 
					
						
							|  |  |  | 			mapWidget.map.center = mapWidget.map.defaultCenter | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-03-08 21:53:00 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function reloadMap() { | 
					
						
							|  |  |  | 		mapWidget.mapHelper.reloadMapLocations() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-25 20:46:12 +02:00
										 |  |  | 	function centerOnDiveSite(ds) { | 
					
						
							|  |  |  | 		if (!ds) { | 
					
						
							|  |  |  | 			console.warn("main.qml: centerOnDiveSite(): dive site is undefined!") | 
					
						
							| 
									
										
										
										
											2018-03-08 21:53:00 +02:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-02 22:48:23 +03:00
										 |  |  | 		// on firstRun, hard pan/center the map to the desired location so that
 | 
					
						
							|  |  |  | 		// we don't start at an arbitrary location such as [0,0] or London.
 | 
					
						
							|  |  |  | 		if (firstRun) { | 
					
						
							| 
									
										
										
										
											2018-10-25 20:46:12 +02:00
										 |  |  | 			var coord = mapWidget.mapHelper.getCoordinates(ds) | 
					
						
							| 
									
										
										
										
											2018-04-02 22:48:23 +03:00
										 |  |  | 			centerOnLocationHard(coord.latitude, coord.longitude) | 
					
						
							|  |  |  | 			firstRun = false | 
					
						
							| 
									
										
										
										
											2018-10-25 20:46:12 +02:00
										 |  |  | 		} // continue here as centerOnDiveSite() also does marker selection.
 | 
					
						
							|  |  |  | 		mapWidget.mapHelper.centerOnDiveSite(ds) | 
					
						
							| 
									
										
										
										
											2018-03-08 21:53:00 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function centerOnLocation(lat, lon) { | 
					
						
							| 
									
										
										
										
											2018-04-02 22:48:23 +03:00
										 |  |  | 		if (firstRun) { | 
					
						
							|  |  |  | 			centerOnLocationHard(lat, lon) | 
					
						
							|  |  |  | 			firstRun = false | 
					
						
							|  |  |  | 			return // no need to animate via centerOnCoordinate().
 | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-03-08 21:53:00 +02:00
										 |  |  | 		mapWidget.map.centerOnCoordinate(QtPositioning.coordinate(lat, lon)) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-04-02 22:48:23 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	function centerOnLocationHard(lat, lon) { | 
					
						
							|  |  |  | 		mapWidget.map.zoomLevel = mapWidget.map.defaultZoomIn | 
					
						
							|  |  |  | 		mapWidget.map.center = QtPositioning.coordinate(lat, lon) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-08 21:53:00 +02:00
										 |  |  | } |