Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update third party layer: Minissas #3720

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bims/static/img/download-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bims/static/img/occurrences-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bims/static/img/taxa-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bims/static/img/upload-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified bims/static/img/users-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 54 additions & 24 deletions bims/static/js/views/control_panel/third_party_layer_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ define(['shared', 'backbone', 'underscore', 'jqueryUi',
miniSASSSelected: false,
inWARDSelected: false,
fetchingInWARDSData: false,
fetchingMiniSASS: false,
inWARDSStationsUrl: "/bims_proxy/https://inwards.award.org.za/app_json/wq_stations.php",
miniSASSUrl: "/bims_proxy/https://minisass.sta.do.kartoza.com/monitor/observations/",
events: {
'click .close-button': 'closeClicked',
'click .update-search': 'updateSearch',
Expand Down Expand Up @@ -39,6 +41,22 @@ define(['shared', 'backbone', 'underscore', 'jqueryUi',
image: image
});
},
miniSASSStyleFunction: function (feature) {
let properties = feature.getProperties();
let color = 'gray';
if (properties['color']) {
color = properties['color'];
} else {
color = '#1dc6c0';
}
let image = new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({color: color})
});
return new ol.style.Style({
image: image
});
},
addInWARDSLayer: function () {
this.inWARDSLayer = new ol.layer.Vector({
source: null,
Expand All @@ -48,44 +66,56 @@ define(['shared', 'backbone', 'underscore', 'jqueryUi',
this.map.addLayer(this.inWARDSLayer);
},
addMiniSASSLayer: function () {
let options = {
url: '/bims_proxy/http://minisass.org/geoserver/wms',
params: {
name: 'MiniSASS',
layers: 'miniSASS:minisass_observations',
format: 'image/png',
getFeatureFormat: 'text/html'
}
};
this.miniSASSLayer = new ol.layer.Tile({
source: new ol.source.TileWMS(options)
this.miniSASSLayer = new ol.layer.Vector({
source: null,
style: this.miniSASSStyleFunction
});
this.miniSASSLayer.setVisible(false);
this.map.addLayer(this.miniSASSLayer);
Shared.Dispatcher.trigger(
'layers:renderLegend',
options['params']['layers'],
options['params']['name'],
options['url'],
options['params']['layers'],
false
);
},
toggleMiniSASSLayer: function (e) {
let self = this;
this.miniSASSSelected = $(e.target).is(":checked");
if (this.miniSASSSelected) {
this.miniSASSLayer.setVisible(true);
// Move layer to top
this.map.removeLayer(this.miniSASSLayer);
this.map.getLayers().insertAt(this.map.getLayers().getLength(), this.miniSASSLayer);
let mapLegend = $('#map-legend');
mapLegend.find(`[data-name='${this.miniSASSLayer.getSource().getParams()['layers']}']`).show();
if (!mapLegend.is('visible')) {
Shared.Dispatcher.trigger('map:showMapLegends');

// Show fetching message
if (!this.fetchingMiniSASS) {
let fetchingMessage = $('<span class="fetching" style="font-size: 10pt; font-style: italic"> (fetching)</span>');
$(e.target).parent().find('.label').append(fetchingMessage);

$.ajax({
type: 'GET',
url: this.miniSASSUrl,
success: function (data) {
let geojson = {
"type": "FeatureCollection",
"features": []
}
for(let observation of data){
let coordinate = [parseFloat(observation.longitude), parseFloat(observation.latitude)];
let properties = observation;
delete properties.longitude;
delete properties.latitude;
let feature = {"type": "Feature", "geometry": {"type": "Point", "coordinates": coordinate}, "properties": properties}
geojson.features.push(feature);
}
let source = new ol.source.Vector({
features: (
new ol.format.GeoJSON({featureProjection: 'EPSG:3857'})
).readFeatures(geojson, {featureProjection: 'EPSG:3857'})
});
self.miniSASSLayer.setSource(source);
$(e.target).parent().find('.fetching').remove();
}
})
this.fetchingMiniSASS = true;
}
} else {
this.miniSASSLayer.setVisible(false);
$('#map-legend').find(`[data-name='${this.miniSASSLayer.getSource().getParams()['layers']}']`).hide();
}
},
toggleInward: function (e) {
Expand Down
4 changes: 2 additions & 2 deletions bims/templates/map_page/search-panel-templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -628,13 +628,13 @@ <h5 class="modal-title" id="${modalId}Label">Save Polygon</h5>
<div class="row-title">
<input type="checkbox" value="MiniSASS"
class="mini-sass-check">
MiniSASS
<span class="label">MiniSASS</span>
</div>
<small class="text-muted">
MiniSASS is a citizen science tool which can be
used by anyone to monitor the health of a river.
The data are served with permission from <a
href="http://www.minisass.org/en/">http://www.minisass.org/en/</a>,
href="https://minisass.org/">https://minisass.org/</a>,
and further information about the tool is available
via this website.
</small>
Expand Down
Loading