diff --git a/tomcat/webapps/Trawl/infoWindow.js b/tomcat/webapps/Trawl/infoWindow.js new file mode 100644 index 0000000000000000000000000000000000000000..66e5876d7fe9fc52e27097ab66baa111d34f9a0c --- /dev/null +++ b/tomcat/webapps/Trawl/infoWindow.js @@ -0,0 +1,31 @@ +//*This code references the info window google maps API +//https://developers.google.com/maps/documentation/javascript/infowindows + +// Displays markers on a map centred at the Laurentian Great Lakes +// When the user clicks the marker, an info window opens + +function initMap(lati, longi,info) { + for(int i=0; i < lati.length; i++){ + + // Generate map centred at Great Lakes + var map = new google.maps.Map(document.getElementById('map'), { + zoom: 5.5, + center: {lat: 45.0349575, lng: -88.6941305}; + }); + + // Set info window contents to input string + var contentString = info[i]; + var infowindow = new google.maps.InfoWindow({ + content: contentString + }); + + // Plot points + var marker = new google.maps.Marker({ + position: {lat: lati[i], lng: longi[i]} , + map: map, + }); + marker.addListener('click', function() { + infowindow.open(map, marker); + }); + } +} \ No newline at end of file diff --git a/tomcat/webapps/Trawl/map.js b/tomcat/webapps/Trawl/map.js new file mode 100644 index 0000000000000000000000000000000000000000..e128b9d293807a6ceb10ee8140f2b068cd237bee --- /dev/null +++ b/tomcat/webapps/Trawl/map.js @@ -0,0 +1,69 @@ +//*This code references the google heat maps API +//https://developers.google.com/maps/documentation/javascript/examples/layer-heatmap + +// This example requires the Visualization library. Include the libraries=visualization +// parameter when you first load the API. For example: +// <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=visualization"> + +var map, heatmap; + +// Generate map +function initMap(longi,lati) { + map = new google.maps.Map(document.getElementById('map'), { + zoom: 13, + center: {lat: 37.775, lng: -122.434}, + mapTypeId: 'satellite' + }); + + heatmap = new google.maps.visualization.HeatmapLayer({ + data: getPoints(longi,lati), + map: map + }); +} + +// Check if a heatmap already exists +function toggleHeatmap() { + heatmap.setMap(heatmap.getMap() ? null : map); +} + +// Initialize colour scheme for heatmap gradient +function changeGradient() { + var gradient = [ + ‘rgba(0, 255, 255, 0)’, + ‘rgba(0, 255, 255, 1)’, + ‘rgba(0, 191, 255, 1)’, + ‘rgba(0, 127, 255, 1)’, + ‘rgba(0, 63, 255, 1)’, + ‘rgba(0, 0, 255, 1)’, + ‘rgba(0, 0, 223, 1)’, + ‘rgba(0, 0, 191, 1)’, + ‘rgba(0, 0, 159, 1)’, + ‘rgba(0, 0, 127, 1)’, + ‘rgba(0, 63, 91, 1)’, + ‘rgba(0, 127, 63, 1)’, + ‘rgba(0, 191, 10, 1)’, + ‘rgba(0, 255, 0, 1)’ + ] + heatmap.set('gradient', heatmap.get('gradient') ? null : gradient); +} + +// Set heatmap radius about each point +function changeRadius() { + heatmap.set('radius', heatmap.get('radius') ? null : 20); +} + +// Set opacity of colours +function changeOpacity() { + heatmap.set('opacity', heatmap.get('opacity') ? null : 0.2); +} + + +// Input latitude and longitude into map points +function getPoints(latitude, longitude) { + var result = []; + for (int i = 0 ; i < latitude.length ; i++) { + result.push( new google.maps.LatLng(latitude[i], longitude[i])); + } + + return result; +} \ No newline at end of file diff --git a/tomcat/webapps/Trawl/map.jsp b/tomcat/webapps/Trawl/map.jsp new file mode 100644 index 0000000000000000000000000000000000000000..ab0c63eb64b4b2a1bb9a49de3fe24bc1d8d27cfd --- /dev/null +++ b/tomcat/webapps/Trawl/map.jsp @@ -0,0 +1,49 @@ +<%@ page import="java.util.*, data.Record, model.TrawlExpert, search.BST, search.BasicSearchResult,data.BioTree,data.TaxonNode" %> +<%@page import="org.json.simple.JSONArray"%> +<%@page import="org.json.simple.JSONObject"%> +<%@page import="org.json.simple.parser.JSONParser"%> + +<% + // Sample result data containing an iterable of records + TrawlExpert te = (TrawlExpert)request.getServletContext().getAttribute("trawl"); + BasicSearchResult result = te.rangeSearch(2, 1960, 2016); + + + + JSONParser parser = new JSONParser(); + + // Initialize JSON Object and Arrays + JSONObject js = new JSONObject(); + JSONArray longitude = new JSONArray(); + JSONArray latitude = new JSONArray(); + JSONArray name = new JSONArray(); + JSONArray date = new JSONArray(); + JSONArray count = new JSONArray(); + + + // Update value of each JSON Object/Array at the same index as the corresponding Record in Result input + for (Record r: result.results()){ + longitude.add(r.getLongitude()); + latitude.add(r.getLatitude()); + name.add(BioTree.getTaxonRecord(r.getTaxonId()).getName()); + JSONObject dateobj = new JSONObject(); + dateobj.put("year",r.getDate().getYear()); + dateobj.put("month",r.getDate().getMonth()); + dateobj.put("day",r.getDate().getDay()); + date.add(r.getDate()); + count.add(r.getCount()); + } + + // Insert JSON Array and Objects into main Object + js.put("latitude", latitude); + js.put("longitude", longitude); + js.put("name", name); + js.put("date", date); + js.put("individual count", count); + js.put("time", result.time()); + + + out.print(js.toJSONString()); +%> + + \ No newline at end of file