protected override void NewTitle(string title) { if (!String.IsNullOrEmpty(title)) { double newLat, newLong, newZoom; bool modified = false; // Incoming title should look like "6, (-27.15, 151.25)" // That is Zoom, then lat, long pair // We remove the brackets and split on the commas title = title.Replace("(", ""); title = title.Replace(")", ""); string[] parts = title.Split(new char[] { ',' }); if (Double.TryParse(parts[0], out newZoom) && newZoom != zoom) { zoom = newZoom; modified = true; } if (Double.TryParse(parts[1], NumberStyles.Float, CultureInfo.InvariantCulture, out newLat) && Double.TryParse(parts[2], NumberStyles.Float, CultureInfo.InvariantCulture, out newLong) && (newLat != latitude || newLong != longitude)) { Center = new Models.Map.Coordinate(newLat, newLong); modified = true; } if (modified && ViewChanged != null) { ViewChanged.Invoke(this, EventArgs.Empty); } } }
/// <summary>Show the map</summary> public void ShowMap(List <Models.Map.Coordinate> coordinates, List <string> locNames, double zoom, Models.Map.Coordinate center) { string html = @"<!DOCTYPE html> <html> <meta charset=""UTF-8""> <head> <link rel=""stylesheet"" href=""https://unpkg.com/[email protected]/dist/leaflet.css"" integrity=""sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="" crossorigin=""""/> <!-- Make sure you put this AFTER Leaflet's CSS --> <script type=""text/javascript"" src=""https://unpkg.com/[email protected]/dist/leaflet.js"" integrity=""sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="" crossorigin=""""></script> </head> <body> <!--Make sure you put this AFTER Leaflet's CSS --> <div id='mapid' style='position:fixed; top:0; bottom:0; left:0; right:0;' ></div>"; html += @" <script> var locations = ["; for (int i = 0; i < coordinates.Count; i++) { html += "[" + coordinates[i].Latitude.ToString(CultureInfo.InvariantCulture) + ", " + coordinates[i].Longitude.ToString(CultureInfo.InvariantCulture) + ", '" + locNames[i] + "']"; if (i < coordinates.Count - 1) { html += ','; } } html += "];" + Environment.NewLine; html += " var mymap = L.map('mapid', {"; html += "center: new L.LatLng(" + center.Latitude.ToString(CultureInfo.InvariantCulture) + ", " + center.Longitude.ToString(CultureInfo.InvariantCulture) + ")"; html += ", zoom: " + zoom.ToString(CultureInfo.InvariantCulture); html += "});"; html += @" mymap.zoomDelta = 0.1; L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoiZXJpY3p1cmNoZXIiLCJhIjoiY2s5YzE2d3liMDBkMDNmbnN2cXhxOHQ2dCJ9.qN8AvphLYMMFSVHKbi7EAg', { 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>', tileSize: 512, zoomOffset: -1, id: 'mapbox/outdoors-v11' }).addTo(mymap); L.control.scale({metric: true, imperial: false, updateWhenIdle: true}).addTo(mymap); var marker, i; for (i = 0; i<locations.length; i++) { L.marker(locations[i]).addTo(mymap).bindPopup('<b>' + locations[i][2] + '</b><br>Latitude: ' + locations[i][0] + '<br>Longitude: ' + locations[i][1]); } function SetTitle() { var center = mymap.getCenter().wrap(); window.document.title = mymap.getZoom().toString() + ', (' + center.lat.toString() + ', ' + center.lng.toString() + ')'; } function SetZoom(newZoom) { mymap.setZoom(newZoom); } function SetCenter(lat, long) { var center = new L.LatLng(lat, long); mymap.panTo(center); } function HideZoomControls() { mymap.removeControl(mymap.zoomControl); } mymap.on('zoomend', SetTitle); mymap.on('moveend', SetTitle); var popup = L.popup(); </script> </body> </html>"; SetContents(html, false); }
/// <summary>Show the map</summary> public void ShowMap(List <Models.Map.Coordinate> coordinates, List <string> locNames, double zoom, Models.Map.Coordinate center) { string html = @"<!DOCTYPE html> <html> <meta charset=""UTF-8""> <head> <link rel=""stylesheet"" href=""https://unpkg.com/[email protected]/dist/leaflet.css"" integrity=""sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="" crossorigin=""""/> <script type=""text/javascript"" src=""https://unpkg.com/[email protected]/dist/leaflet.js"" integrity=""sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw=="" crossorigin=""""></script> </head> <body> <!--Make sure you put this AFTER Leaflet's CSS --> <div id='mapid' style='position:fixed; top:0; bottom:0; left:0; right:0;' ></div>"; html += @" <script> var locations = ["; for (int i = 0; i < coordinates.Count; i++) { html += "[" + coordinates[i].Latitude.ToString() + ", " + coordinates[i].Longitude.ToString() + ", '" + locNames[i] + "']"; if (i < coordinates.Count - 1) { html += ','; } } html += "];" + Environment.NewLine; html += " var mymap = L.map('mapid', {"; html += "center: new L.LatLng(" + center.Latitude.ToString() + ", " + center.Longitude.ToString() + ")"; html += ", zoom: " + zoom.ToString(); if (popupWindow != null) // Exporting to a report, so leave off the zoom control { html += ", zoomControl: false"; } html += "});"; html += @" mymap.zoomDelta = 0.1; L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiZXJpY3p1cmNoZXIiLCJhIjoiY2pmYzFxcnJ5MXZidjN1bXprdXRtZjd2aCJ9.BSxI0r_GNzUAZnbvmuHpHA', { 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.emerald' }).addTo(mymap); L.control.scale({metric: true, imperial: false, updateWhenIdle: true}).addTo(mymap); var marker, i; for (i = 0; i<locations.length; i++) { L.marker(locations[i]).addTo(mymap).bindPopup('<b>' + locations[i][2] + '</b><br>Latitude: ' + locations[i][0] + '<br>Longitude: ' + locations[i][1]); } function SetTitle() { window.document.title = mymap.getZoom().toString() + ', (' + mymap.getCenter().lat.toString() + ', ' + mymap.getCenter().lng.toString() + ')'; } function SetZoom(newZoom) { mymap.setZoom(newZoom); } function SetCenter(lat, long) { var center = new L.LatLng(lat, long); mymap.panTo(center); } mymap.on('zoomend', SetTitle); mymap.on('moveend', SetTitle); var popup = L.popup(); </script> </body> </html>"; SetContents(html, false); }