') .append($(' ') .append($(' ') .attr('type', 'checkbox') .attr('checked', 'checked') .attr('id', name) .attr('fq',data.fq) .addClass('layerFacet') .addClass('leaflet-control-layers-selector') ) ) .append($(' ') .append($('') .addClass('legendColour') .attr('style', "background-color:rgb("+ red +","+ green +","+ blue + ");") ) .append($('') .addClass('legendItemName') .html((nameLabel.indexOf("[") == -1) ? nameLabel : name) ) ) ); } function rgbToHex(redD, greenD, blueD){ var red = parseInt(redD); var green = parseInt(greenD); var blue = parseInt(blueD); var rgb = blue | (green << 8) | (red << 16); return rgb.toString(16); } function getRecordInfo(){ // http://biocache.ala.org.au/ws/occurrences/c00c2f6a-3ae8-4e82-ade4-fc0220529032 //console.log("MAP_VAR.query", MAP_VAR.query); $.ajax({ url: "https://biocache-ws.ala.org.au/ws/occurrences/info" + MAP_VAR.query, //jsonp: "callback", //dataType: "jsonp", success: function(response) { } }); } /** * Zooms map to either spatial search or from WMS data bounds */ function fitMapToBounds() { // Don't run for spatial searches, which have their own fitBounds() method if (true || !isSpatialRadiusSearch()) { // inactive if // all other searches (non-spatial) // do webservice call to get max extent of WMS data var jsonUrl = "https://biocache-ws.ala.org.au/ws/mapping/bounds.json" + MAP_VAR.query; $.getJSON(jsonUrl, function(data) { if (data.length == 4) { //console.log("data", data); var sw = L.latLng(data[1],data[0]); var ne = L.latLng(data[3],data[2]); //console.log("sw", sw.toString()); var dataBounds = L.latLngBounds(sw, ne); //var centre = dataBounds.getCenter(); var mapBounds = MAP_VAR.map.getBounds(); if (mapBounds && mapBounds.contains(sw) && mapBounds.contains(ne) && dataBounds) { // data bounds is smaller than the default map bounds/view, so zoom into fit data MAP_VAR.map.fitBounds(dataBounds); if (MAP_VAR.map.getZoom() > 15) { MAP_VAR.map.setZoom(15); } } else if (!mapBounds.contains(dataBounds) && !mapBounds.intersects(dataBounds)) { // if data is not present in the default map bounds/view, then zoom to data MAP_VAR.map.fitBounds(dataBounds); if (MAP_VAR.map.getZoom() > 3) { MAP_VAR.map.setZoom(3); } } else if (MAP_VAR.zoomOutsideScopedRegion) { // if data is present in default map view but also outside that area, then zoom to data bounds // as long as zoomOutsideScopedRegion is true, otherwise keep default zoom/bounds // fitBounds is async so we set a one time only listener to detect change MAP_VAR.map.once('zoomend', function() { //console.log("zoomend", MAP_VAR.map.getZoom()); if (MAP_VAR.map.getZoom() < 2) { MAP_VAR.map.setView(L.latLng(0, 24), 2); // zoom level 2 and centered over africa } }); MAP_VAR.map.fitBounds(dataBounds); } MAP_VAR.map.invalidateSize(); } }); } } /** * Spatial searches from Explore Your Area - draw a circle representing * the radius boundary for the search. * * Note: this function has a dependency on purl.js: * https://github.com/allmarkedup/purl */ function drawCircleRadius() { if (isSpatialRadiusSearch()) { // spatial search from EYA var lat = $.url().param('lat'); var lng = $.url().param('lon'); var radius = $.url().param('radius'); var latLng = L.latLng(lat, lng); var circleOpts = { weight: 1, color: 'white', opacity: 0.5, fillColor: '#222', // '#2C48A6' fillOpacity: 0.2 } L.Icon.Default.imagePath = "/static/js/leaflet/images"; var popupText = "Centre of spatial search with radius of null km"; var circle = L.circle(latLng, radius * 1030, circleOpts); circle.addTo(MAP_VAR.map); MAP_VAR.map.fitBounds(circle.getBounds()); // make circle the centre of the map, not the points L.marker(latLng, {title: popupText}).bindPopup(popupText).addTo(MAP_VAR.map); MAP_VAR.map.invalidateSize(); } } /** * Returns true for a lat/lon/radius (params) style search * * @returns {boolean} */ function isSpatialRadiusSearch() { var returnBool = false; var lat = $.url().param('lat'); var lng = $.url().param('lon'); var radius = $.url().param('radius'); if (lat && lng && radius) { returnBool = true; } return returnBool } /** * http://stackoverflow.com/questions/3916191/download-data-url-file */ function downloadPolygon() { var uri = "data:text/html,", name = "polygon.txt"; var link = document.createElement("a"); link.download = name; link.href = uri; //console.log("downloadPolygon",link); document.body.appendChild(link); link.click(); // Cleanup the DOM document.body.removeChild(link); delete link; return false; }