var map; var baseMaps; //TODO verify good center var default_centerLatitude = 52; var default_centerLongitude = -97; var default_startZoom = 4; var default_localZoom = 14; var default_mapType = 'Roadmap'; var current_centerLatitude; var current_centerLongitude; var done_init = 0; var location_circle = L.circle(); var location_marker = L.marker(); var location_image = L.icon({ iconUrl: 'images/location_pin-v1.png', iconSize: [12,28], iconAnchor: [6,28] }); var layerA = 1; var layerB = 0; var layerR = 0; var layerT = 0; var layerM = 0; var layerO = 0; var pid = 0; var layerAMap; var layerBMap; var layerRMap; var layerTMap; var layerMMap; var layerOMap; // ===== Generate "link to this map" link function mapLink() { var layers = ''; if (layerA == 1) {layers += 'a';} if (layerB == 1) {layers += 'b';} if (layerR == 1) {layers += 'r';} if (layerT == 1) {layers += 't';} if (layerO == 1) {layers += 'o';} for (var map_label in baseMaps) { if (map.hasLayer(baseMaps[map_label])) { maptype = map_label; } } var a="cancellsites.html" + "?lat=" + map.getCenter().lat.toFixed(6) + "&lng=" + map.getCenter().lng.toFixed(6) + "&zoom=" + map.getZoom() + "&type=" + maptype + "&layers=" + layers + "&pid=" + pid; return a; } function makeLink() { var a = mapLink(); document.getElementById("maplink").innerHTML = 'Link to this MapMap Link'; } function goMapLink() { var a = mapLink(); location.href = a; } isValidCoordinate = function(position) { var error; var isValid; try { isValid = true; new Coordinates(position); return isValid; } catch (error) { isValid = false; return isValid; } }; // ===== Handle Search function LocationSearch() { if (!done_init) { return; } var address = document.getElementById("txt_locationsearch").value; if (address=='' || address=='Search' || address=='Location Search') { return; } // check if search string is coordinates if (isValidCoordinate(address)) { position = new Coordinates(address); map.setView([position.getLatitude(), position.getLongitude()], map.getZoom()); center = map.getCenter(); current_centerLatitude = center.lat; current_centerLongitude = center.lng; L.popup() .setLatLng([position.getLatitude(), position.getLongitude()]) .setContent(address) .openOn(map); } else { var url = 'https://nominatim.openstreetmap.org/search/'+address+'?format=json&limit=1&countrycodes=ca'; downloadUrlCors( url, function(data,rstatus) { if ((data != "") && (data != undefined)) { data = JSON.parse(data)[0]; } if ((data != "") && (data != undefined)) { map.setView([data.lat, data.lon], map.getZoom()); map.fitBounds([ [data.boundingbox[0], data.boundingbox[2]], [data.boundingbox[1], data.boundingbox[3]] ]); center = map.getCenter(); current_centerLatitude = center.lat; current_centerLongitude = center.lng; L.popup() .setLatLng([data.lat, data.lon]) .setContent(data.display_name) .openOn(map); } else { alert("Could not locate: " + address); } } ); } } function place_location_marker(lat,lng) { location_marker.remove(); location_marker = L.marker([lat, lng], { icon: location_image, draggable: true, title: 'Current Location' }).addTo(map); } function place_location_circle(lat,lng,accuracy) { location_circle.remove(); location_circle = L.circle([lat, lng], { radius: accuracy, color: '#4400FF', opacity: 0.6, fillColor: '#4400FF', fillOpacity: 0.11, interactive: false }).addTo(map); //hide the error circle if the marker is dragged location_marker.on('dragstart', function() { location_circle.remove(); }); } function setLocation(lat,lng,accuracy) { if (!done_init) { return; } current_centerLatitude = lat; current_centerLongitude = lng; zoom = default_localZoom; place_location_marker(lat,lng); place_location_circle(lat,lng,accuracy); bounds = location_circle.getBounds(); map.setZoom(zoom); map.fitBounds(bounds); /* TODO necessary? if (map.getZoom() > zoom) { map.setZoom(zoom); } map.panToBounds(bounds); */ } // ===== Center map by geolocation function findLocation() { if (!done_init) { return; } // Try W3C Geolocation if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { lat = position.coords.latitude; lng = position.coords.longitude; accuracy = position.coords.accuracy; setLocation(lat,lng,accuracy); },function() { //error function -- firefox won't currently call this if decision is deferred location_marker.remove(); location_circle.remove(); var r = confirm('No location information available right now,\nproceed with manual locating?'); if (r == true) { center = map.getCenter(); current_centerLatitude = center.lat; current_centerLongitude = center.lng; place_location_marker(current_centerLatitude, current_centerLongitude); } },{maximumAge:900000}); //options } else { //no geolocation location_marker.remove(); location_circle.remove(); var r = confirm('No location information available,\nproceed with manual locating?'); if (r == true) { center = map.getCenter(); current_centerLatitude = center.lat; current_centerLongitude = center.lng; place_location_marker(current_centerLatitude, current_centerLongitude); } } return false; } // ===== Auto resize the height of the map function changeHeight() { var hght; if (typeof self.innerHeight != 'undefined') { hght = self.innerHeight*0.60; } else { hght = document.documentElement.clientHeight*0.60; } document.getElementById("map_canvas").style.height=hght+"px"; } // ===== Toggle visibility of overlays function togglelayer(form) { if (!done_init) { return; } //should work for all now for (var i=0; iOpenStreetMap contributors'}); // update attribution from http://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer?f=pjson // no http2 support var Esri_WorldImagery = L.tileLayer('//server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', { attribution: 'Tiles © Esri — Source: Esri, DigitalGlobe, GeoEye, Earthstar Geographics, CNES/Airbus DS, USDA, USGS, AeroGRID, IGN, and the GIS User Community', minZoom: 0, maxZoom: 23 }); // no http2 support var terrain = L.tileLayer('//stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.{ext}', { attribution: 'Map tiles by Stamen Design, CC BY 3.0 — Map data © OpenStreetMap', subdomains: 'abcd', minZoom: 0, maxZoom: 18, ext: 'png' }); // no http2 support, redirected to https var OpenTopoMap = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', { attribution: 'Map data: © OpenStreetMap, SRTM | Map style: © OpenTopoMap (CC-BY-SA)', minZoom: 1 }); // update attribution from http://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer?f=pjson // no http2 support var Esri_WorldTopoMap = L.tileLayer('//server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}', { attribution: 'Tiles © Esri — Sources: Esri, HERE, Garmin, Intermap, increment P Corp., GEBCO, USGS, FAO, NPS, NRCAN, GeoBase, IGN, Kadaster NL, Ordnance Survey, Esri Japan, METI, Esri China (Hong Kong), swisstopo, © OpenStreetMap contributors, and the GIS User Community', minZoom: 0, maxZoom: 19 }); baseMaps = { "Roadmap": roadmap, "Satellite": Esri_WorldImagery, "Terrain": terrain, "Topo": OpenTopoMap, "Ersi Topo": Esri_WorldTopoMap, }; L.control.layers(baseMaps).addTo(map); // hide the loading image document.getElementById('loader_image').style.display = 'none'; changeHeight(); var lat = default_centerLatitude; var lng = default_centerLongitude; var zoom = default_startZoom; var maptype = default_mapType; // If there are any parameters at the end of the URL // they will be in location.search // looking something like "?lat=50&lng=-3&zoom=10&type=roadmap" // skip the first character, we are not interested in the "?" var query = location.search.substring(1); // split the rest at each "&" character to give a list of // "argname=value" pairs var pairs = query.split("&"); for (var i=0; i1) { layerA = 1; layerB = 0; layerR = 0; layerT = 0; layerM = 0; layerO = 0; } // set map properties map.setView([lat, lng], zoom); baseMaps[maptype].addTo(map); current_centerLatitude = lat; current_centerLongitude = lng; // ===== Layer overlays map.createPane('tower_tiles'); map.getPane('tower_tiles').style.zIndex = 300; var url; //var url_base = '//{s}.ertyu.org/steven_nikkel/tower-tile-server.png?x={x}&y={y}&z={z}'; var url_base = 'tower-tile-server.png?x={x}&y={y}&z={z}'; //var layerOpts = {subdomains: ['tiles0', 'tiles1'], tileSize: 512, pane: 'tower_tiles'}; var layerOpts = {tileSize: 512, pane: 'tower_tiles'}; // All url = url_base; layerAMap = L.tileLayer(url, layerOpts).addTo(map); // Bell url = url_base+'&pid=1'; layerBMap = L.tileLayer(url, layerOpts).addTo(map); // Rogers url = url_base+'&pid=3'; layerRMap = L.tileLayer(url, layerOpts).addTo(map); // Telus url = url_base+'&pid=4'; layerTMap = L.tileLayer(url, layerOpts).addTo(map); // Mike url = url_base+'&pid=5'; layerMMap = L.tileLayer(url, layerOpts).addTo(map); // Other url = url_base+'&pid={pid}'; //add our pid paramter layerOpts.pid = function() {return pid;}; layerOMap = L.tileLayer(url, layerOpts).addTo(map); if (!layerA) { layerAMap.remove(); } if (!layerB) { layerBMap.remove(); } if (!layerR) { layerRMap.remove(); } if (!layerT) { layerTMap.remove(); } if (!layerM) { layerMMap.remove(); } if (!layerO) { layerOMap.remove(); } // layer controls var layerinnerHTML = ''; document.getElementById("pid_options").innerHTML = layerinnerHTML; // update the controls to match status if (layerA != 1) { document.getElementById("layerAcontrol").checked = false; } if ((layerB != 1) ) { document.getElementById("layerBcontrol").checked = false; } if ((layerR != 1) ) { document.getElementById("layerRcontrol").checked = false; } if ((layerT != 1) ) { document.getElementById("layerTcontrol").checked = false; } if ((layerO != 1) ) { document.getElementById("layerOcontrol").checked = false; } // enable controls document.getElementById("layerAcontrol").disabled = false; document.getElementById("layerBcontrol").disabled = false; document.getElementById("layerRcontrol").disabled = false; document.getElementById("layerTcontrol").disabled = false; document.getElementById("layerOcontrol").disabled = false; // enable search document.getElementById("txt_locationsearch").disabled = false; document.getElementById("btn_locationsearch").disabled = false; // Make the link the first time when the page opens makeLink(); // Make the link again whenever the map changes map.on('baselayerchange', makeLink); map.on('moveend', makeLink); map.on('zoomend', makeLink); // resize map when browser is resized if (typeof window.addEventListener != 'undefined') { window.addEventListener("resize", changeHeight, false); } else if (typeof document.addEventListener != 'undefined') { document.addEventListener("resize", changeHeight, false); } else if (typeof window.attachEvent != 'undefined') { window.attachEvent("onresize", changeHeight); } // Watch for clicks to display info windows map.on('click', function(event) { var url="tower-point-server.php?" +"lat="+event.latlng.lat +"&lng="+event.latlng.lng +"&zoom="+map.getZoom() ; //if (layerA == 1) {url += "&pid=-1";} if (layerB == 1) {url += "&pid[]=1";} if (layerR == 1) {url += "&pid[]=3";} if (layerT == 1) {url += "&pid[]=4";} if (layerM == 1) {url += "&pid[]=5";} if (layerO == 1) {url += "&pid[]="+pid;} downloadUrl( url, function(data,rstatus) { if ((data != "") && (data != undefined)) { L.popup() .setLatLng(event.latlng) .setContent(data) .openOn(map); } } ); }); done_init = 1; } window.onload = init;