diff options
author | Pjotr Prins | 2020-10-26 08:46:11 +0000 |
---|---|---|
committer | Pjotr Prins | 2020-10-26 09:00:39 +0000 |
commit | 34d494f7a8d9b6348cbfec7196c631acab8818f9 (patch) | |
tree | 20aa071198c6ebf55151f387aa722602e987795d /bh20simplewebuploader | |
parent | 9745e79e71797bc445f193e8d1dafc5b805a7fc4 (diff) | |
download | bh20-seq-resource-34d494f7a8d9b6348cbfec7196c631acab8818f9.tar.gz bh20-seq-resource-34d494f7a8d9b6348cbfec7196c631acab8818f9.tar.lz bh20-seq-resource-34d494f7a8d9b6348cbfec7196c631acab8818f9.zip |
Improved map to show sequences in one view
Diffstat (limited to 'bh20simplewebuploader')
-rw-r--r-- | bh20simplewebuploader/static/main.css | 4 | ||||
-rw-r--r-- | bh20simplewebuploader/static/map.js | 53 |
2 files changed, 42 insertions, 15 deletions
diff --git a/bh20simplewebuploader/static/main.css b/bh20simplewebuploader/static/main.css index bc8acb0..bd51118 100644 --- a/bh20simplewebuploader/static/main.css +++ b/bh20simplewebuploader/static/main.css @@ -469,7 +469,11 @@ div.status { font-size: 20px; } +.my-custom-icon.my-custom-icon-0 { + background-color: red; +} .my-custom-icon.my-custom-icon-1 { + background-color: orange; } .my-custom-icon.my-custom-icon-2 { background-color: #FFFAF0; diff --git a/bh20simplewebuploader/static/map.js b/bh20simplewebuploader/static/map.js index dfe88f9..cabb63d 100644 --- a/bh20simplewebuploader/static/map.js +++ b/bh20simplewebuploader/static/map.js @@ -1,4 +1,10 @@ +/* + +Draws the map using Leaflet and OpenStreetmap + +drawMap() is the main function. +*/ var map = L.map( 'mapid', { center: [51.505, -0.09], // Default to U.S.A minZoom: 2, @@ -10,17 +16,21 @@ L.tileLayer( 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { subdomains: ['a','b','c'] }).addTo(map); +/* + * When a page gets rendered this function draws the map + */ function drawMap(){ var mymap = map; + // ---- fetch all counts fetch(scriptRoot + "api/getCountByGPS") .then(response => { console.log(response) return response.json(); }) .then(data => { - updateMapMarkers(data); + buildMapMarkers(data); }); document.getElementById("map_view").classList.remove("invisible"); @@ -28,10 +38,8 @@ function drawMap(){ } - - /* - * These functions updates the map with markers + * Register a marker with special attribute track # sequences */ seqMarker = L.Marker.extend({ @@ -42,26 +50,41 @@ seqMarker = L.Marker.extend({ } }); +/* + * Builds markers on the map. We use cluster groups to allow + * counts at different zoom levels. This function is called + * once on page loading. markerClusterGroup just handles it. + * Note the display is handled in CSS (main.css) as .my-custom-icon* + */ -function updateMapMarkers(data) { +function buildMapMarkers(data) { let markers = L.markerClusterGroup({ + singleMarkerMode: true, iconCreateFunction: function (cluster) { - var theseMarkers = cluster.getAllChildMarkers(); //// -- this is the array of each marker in the cluster. + // ---- add marker + // array of each marker in the cluster: + var theseMarkers = cluster.getAllChildMarkers(); + + // --- compute zoom level and set style sumCount = 0; for (var i = 0; i < theseMarkers.length; i++) { - // console.log(theseMarkers[i]); sumCount += theseMarkers[i].options.sequences; } - var digits = (sumCount + '').length; - - return L.divIcon({ - html: sumCount, - className: 'my-custom-icon my-custom-icon-'+digits, - }); - }, - }); + if (theseMarkers.length < 2) { + return L.divIcon({ + html: sumCount, + className: 'my-custom-icon my-custom-icon-0', + }) + } else { + var digits = (sumCount + '').length; + return L.divIcon({ + html: sumCount, + className: 'my-custom-icon my-custom-icon-'+digits, + }); + }}}); + // ---- Build the marker list for (let i = 0; i < data.length; i++) { let {"count": fastaCount, GPS, LocationLabel: label } = data[i]; let countSeq = Number(fastaCount); |