-
Notifications
You must be signed in to change notification settings - Fork 6
/
map.html
54 lines (49 loc) · 2.1 KB
/
map.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Quick Start Guide Example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<script type="text/javascript" src="qrc:///qtwebchannel/qwebchannel.js"></script>
</head>
<body onload="initialize()" style="margin:0;padding:0;height:100%;width:100%">
<div id="mapid" style="height:100%; width:100%;position:absolute;"></div>
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script>
// Initialise web page
function initialize() {
initialize_qt(function() {
// connect to a signal
qmlLeaflet.setCenterMap.connect(function(latitude, longitude) {
if (typeof qmlLeaflet !== 'undefined') {
centerMap(qmlLeaflet.latitude, qmlLeaflet.longitude);
}
});
});
}
// Initialise connection to QT C++
function initialize_qt(callback) {
if (typeof qt != 'undefined') new QWebChannel(qt.webChannelTransport, function(channel) {
// To make the object known globally, assign it to the window object, i.e.:
window.qmlLeaflet = channel.objects.qmlLeaflet;
callback();
});
}
// function, can be called from C++ or from Javascript
function centerMap(lat, lng) {
if (map.getCenter().lat != lat && map.getCenter().lng != lng) {
map.setView([lat, lng], map.zoom);
}
}
var map = L.map('mapid').setView([51.505, -0.09], 13);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpandmbXliNDBjZWd2M2x6bDk3c2ZtOTkifQ._QA7i5Mpkd_m30IGElHziw', {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'mapbox.streets'
}).addTo(map);
</script>
</body>
</html>