From aac225e24ea8763f056595179c43e904a537cd5d Mon Sep 17 00:00:00 2001 From: Dimas Date: Fri, 25 Aug 2023 12:19:57 +0700 Subject: [PATCH 1/4] Show point in the wetland site form --- bims/static/css/site_form.css | 44 +++++++++++++++++++++++++++ bims/static/js/wetland_site.js | 36 +++++++++++++--------- bims/templates/wetland_site_form.html | 23 +++++++++++--- 3 files changed, 83 insertions(+), 20 deletions(-) diff --git a/bims/static/css/site_form.css b/bims/static/css/site_form.css index e506a90f7..42535c892 100644 --- a/bims/static/css/site_form.css +++ b/bims/static/css/site_form.css @@ -25,6 +25,17 @@ body { padding-bottom: 15px; } +/* Loading overlay styles */ +#loading { + position: absolute; + width: 600px; + height: 400px; + background: rgba(255, 255, 255, 0.8); + text-align: center; + line-height: 400px; + font-size: 24px; +} + #update-coordinate { margin-top: 2px; } @@ -85,3 +96,36 @@ label.error { color: white; font-size: 10pt; } + + +/* Loading overlay styles */ +#map-loading { + display: none; + color: #444444; + position: absolute; + width: 100%; + max-height: 500px; + height: 500px; + background: rgba(255, 255, 255, 0.8); + line-height: 500px; + font-size: 24px; + top: 0; + left: 0; + z-index: 999; + justify-content: center; +} +#map-loading .loading-text { + width: 300px; +} +#map-loading .loading-text::after { + display: inline-block; + animation: dotty steps(1,end) 1s infinite; + content: ''; +} +@keyframes dotty { + 0% { content: ''; } + 25% { content: '.'; } + 50% { content: '..'; } + 75% { content: '...'; } + 100% { content: ''; } +} diff --git a/bims/static/js/wetland_site.js b/bims/static/js/wetland_site.js index 6317b3dce..7a4dcc555 100644 --- a/bims/static/js/wetland_site.js +++ b/bims/static/js/wetland_site.js @@ -38,7 +38,14 @@ let mapReady = (map) => { map.un('click', mapOnClicked); - const getFeature = (layerSource, renderResult) => { + const getFeature = (layerSource, coordinates, renderResult) => { + let _coordinates = ol.proj.transform(coordinates, 'EPSG:3857', 'EPSG:4326'); + if (markerSource) { + markerSource.clear(); + } + $('#latitude').val(''); + $('#longitude').val(''); + return new Promise((resolve, reject) => { $.ajax({ type: 'POST', @@ -67,16 +74,8 @@ let mapReady = (map) => { map.getView().fit(bbox, {size: map.getSize()}); if (renderResult) { - - let centroidX = (bbox[0] + bbox[2]) / 2; - let centroidY = (bbox[1] + bbox[3]) / 2; - - let transformedCoordinate = ol.proj.transform([centroidX, centroidY], 'EPSG:3857', 'EPSG:4326'); - let longitude = transformedCoordinate[0]; - let latitude = transformedCoordinate[1]; - - $('#latitude').val(latitude); - $('#longitude').val(longitude); + $('#latitude').val(_coordinates[1]); + $('#longitude').val(_coordinates[0]); $('#fetch-river-name').attr('disabled', false); $('#fetch-geomorphological-zone').attr('disabled', false); @@ -101,11 +100,13 @@ let mapReady = (map) => { }); $('#site-geometry').val(convertedGeojsonStr); - vectorLayer.getSource().clear() - vectorLayer.getSource().addFeatures(olFeature); + // vectorLayer.getSource().clear() + // vectorLayer.getSource().addFeatures(olFeature); wetlandData = feature['properties']; $('#additional-data').val(JSON.stringify(wetlandData)); $('#river_name').val(wetlandData['name'] ? wetlandData['name'] : '-'); + + moveMarkerOnTheMap(_coordinates[1], _coordinates[0], false); } } resolve(features); @@ -128,7 +129,8 @@ let mapReady = (map) => { ); layerSource += '&QUERY_LAYERS=' + wmsLayerName; const zoomLevel = map.getView().getZoom(); - getFeature(layerSource, zoomLevel > 10).then(function(features) { + $('#map-loading').css('display', 'flex'); + getFeature(layerSource, e.coordinate,zoomLevel > 10).then(function(features) { if (features.length > 0 && zoomLevel <= 10) { let bbox = features[0]['bbox']; let centroidX = (bbox[0] + bbox[2]) / 2; @@ -142,7 +144,11 @@ let mapReady = (map) => { {'INFO_FORMAT': 'application/json'} ); layerSource += '&QUERY_LAYERS=' + wmsLayerName; - getFeature(layerSource, true) + getFeature(layerSource, e.coordinate, true).then(function (f) { + $('#map-loading').hide(); + }) + } else { + $('#map-loading').hide(); } }).catch(function(error) { // handle any errors diff --git a/bims/templates/wetland_site_form.html b/bims/templates/wetland_site_form.html index 116bf6c71..dca2f5eb0 100644 --- a/bims/templates/wetland_site_form.html +++ b/bims/templates/wetland_site_form.html @@ -31,6 +31,15 @@ margin-bottom: 10px; width: 272px; } + + #site-map { + width: 100%; + max-height: 500px; + height: 500px; + padding-bottom: 15px; + position: relative; /* set to relative to properly position the overlay */ + } + {% endblock %} @@ -64,7 +73,13 @@

-
+
+ +
+
Checking Wetland Data
+
+
+ {% if update %}
@@ -94,16 +109,14 @@

-
-
From 8161fba001eea788c991baf6a566f2b4937f6d0d Mon Sep 17 00:00:00 2001 From: Dimas Date: Fri, 25 Aug 2023 13:56:29 +0700 Subject: [PATCH 2/4] Make update coordinate works --- bims/static/js/wetland_site.js | 255 ++++++++++++++------------ bims/templates/wetland_site_form.html | 6 + 2 files changed, 143 insertions(+), 118 deletions(-) diff --git a/bims/static/js/wetland_site.js b/bims/static/js/wetland_site.js index 7a4dcc555..66251fb69 100644 --- a/bims/static/js/wetland_site.js +++ b/bims/static/js/wetland_site.js @@ -1,23 +1,155 @@ let wetlandData = null; +let wmsSource = null; +let wmsLayer = null; +let wmsLayerName = 'kartoza:nwm6_beta_v3_20230714'; + +updateCoordinate = function (zoomToMap = true) { + try { + let latitude = parseFloat($('#latitude').val()); + let longitude = parseFloat($('#longitude').val()); + let _coordinates = ol.proj.transform([longitude, latitude], 'EPSG:4326', 'EPSG:3857'); + mapClicked(_coordinates); + } catch (e) { + return false; + } +}; + +const getFeature = (layerSource, coordinates, renderResult) => { + let _coordinates = ol.proj.transform(coordinates, 'EPSG:3857', 'EPSG:4326'); + if (markerSource) { + markerSource.clear(); + } + $('#latitude').val(''); + $('#longitude').val(''); + + return new Promise((resolve, reject) => { + $.ajax({ + type: 'POST', + url: '/get_feature/', + data: { + 'layerSource': layerSource + }, + success: function (result) { + const data = result['feature_data']; + let objectData = {}; + if (data.constructor === Object) { + objectData = data; + } else { + try { + objectData = JSON.parse(data); + } catch (e) { + console.log(e); + reject(e); + return; + } + } + let features = objectData['features']; + if (features.length > 0) { + const feature = features[0]; + const bbox = feature['bbox']; + + map.getView().fit(bbox, {size: map.getSize()}); + if (renderResult) { + $('#latitude').val(_coordinates[1]); + $('#longitude').val(_coordinates[0]); + + $('#fetch-river-name').attr('disabled', false); + $('#fetch-geomorphological-zone').attr('disabled', false); + $('#wetland-site-code').attr('disabled', false); + + $('#site_code').val(''); + $('#geomorphological_zone').val(''); + + let olFeature = new ol.format.GeoJSON().readFeatures(feature); + + const format = new ol.format.GeoJSON(); + const featureObj = format.readFeature(feature, { + dataProjection: 'EPSG:3857', + featureProjection: 'EPSG:3857' + }) + const geometry = featureObj.getGeometry(); + geometry.transform('EPSG:3857', 'EPSG:4326'); + + const convertedGeojsonStr = format.writeFeature(featureObj, { + dataProjection: 'EPSG:4326', + featureProjection: 'EPSG:4326' + }); + + $('#site-geometry').val(convertedGeojsonStr); + // vectorLayer.getSource().clear() + // vectorLayer.getSource().addFeatures(olFeature); + wetlandData = feature['properties']; + $('#additional-data').val(JSON.stringify(wetlandData)); + $('#river_name').val(wetlandData['name'] ? wetlandData['name'] : '-'); + + moveMarkerOnTheMap(_coordinates[1], _coordinates[0], false); + } + } + resolve(features); + }, + error: function (err) { + console.log(err); + reject(err); + } + }); + }); +}; + + +let mapClicked = (coordinate) => { + if (!wmsLayer) return; + + let view = map.getView(); + let layerSource = wmsLayer.getSource().getGetFeatureInfoUrl( + coordinate, + view.getResolution(), + view.getProjection(), + {'INFO_FORMAT': 'application/json'} + ); + layerSource += '&QUERY_LAYERS=' + wmsLayerName; + const zoomLevel = map.getView().getZoom(); + $('#map-loading').css('display', 'flex'); + getFeature(layerSource, coordinate,zoomLevel > 10).then(function(features) { + if (features.length > 0 && zoomLevel <= 10) { + let bbox = features[0]['bbox']; + let centroidX = (bbox[0] + bbox[2]) / 2; + let centroidY = (bbox[1] + bbox[3]) / 2; + let point = [centroidX, centroidY]; + + layerSource = wmsLayer.getSource().getGetFeatureInfoUrl( + point, + view.getResolution(), + view.getProjection(), + {'INFO_FORMAT': 'application/json'} + ); + layerSource += '&QUERY_LAYERS=' + wmsLayerName; + getFeature(layerSource, coordinate, true).then(function (f) { + $('#map-loading').hide(); + }) + } else { + $('#map-loading').hide(); + } + }).catch(function(error) { + // handle any errors + }); +} let mapReady = (map) => { // Add wetland layer let geoserverWms = 'https://maps.kartoza.com/geoserver/wms' - let wmsLayerName = 'kartoza:nwm6_beta_v3_20230714'; // Create a new WMS source - let wmsSource = new ol.source.TileWMS({ + wmsSource = new ol.source.TileWMS({ url: geoserverWms, params: {'LAYERS': wmsLayerName}, serverType: 'geoserver', }); // Create a new tile layer with the WMS source - let wmsLayer = new ol.layer.Tile({ + wmsLayer = new ol.layer.Tile({ source: wmsSource }); - let view = map.getView(); let vectorLayer = new ol.layer.Vector({ source: new ol.source.Vector(), @@ -38,121 +170,8 @@ let mapReady = (map) => { map.un('click', mapOnClicked); - const getFeature = (layerSource, coordinates, renderResult) => { - let _coordinates = ol.proj.transform(coordinates, 'EPSG:3857', 'EPSG:4326'); - if (markerSource) { - markerSource.clear(); - } - $('#latitude').val(''); - $('#longitude').val(''); - - return new Promise((resolve, reject) => { - $.ajax({ - type: 'POST', - url: '/get_feature/', - data: { - 'layerSource': layerSource - }, - success: function (result) { - const data = result['feature_data']; - let objectData = {}; - if (data.constructor === Object) { - objectData = data; - } else { - try { - objectData = JSON.parse(data); - } catch (e) { - console.log(e); - reject(e); - return; - } - } - let features = objectData['features']; - if (features.length > 0) { - const feature = features[0]; - const bbox = feature['bbox']; - - map.getView().fit(bbox, {size: map.getSize()}); - if (renderResult) { - $('#latitude').val(_coordinates[1]); - $('#longitude').val(_coordinates[0]); - - $('#fetch-river-name').attr('disabled', false); - $('#fetch-geomorphological-zone').attr('disabled', false); - $('#wetland-site-code').attr('disabled', false); - - $('#site_code').val(''); - $('#geomorphological_zone').val(''); - - let olFeature = new ol.format.GeoJSON().readFeatures(feature); - - const format = new ol.format.GeoJSON(); - const featureObj = format.readFeature(feature, { - dataProjection: 'EPSG:3857', - featureProjection: 'EPSG:3857' - }) - const geometry = featureObj.getGeometry(); - geometry.transform('EPSG:3857', 'EPSG:4326'); - - const convertedGeojsonStr = format.writeFeature(featureObj, { - dataProjection: 'EPSG:4326', - featureProjection: 'EPSG:4326' - }); - - $('#site-geometry').val(convertedGeojsonStr); - // vectorLayer.getSource().clear() - // vectorLayer.getSource().addFeatures(olFeature); - wetlandData = feature['properties']; - $('#additional-data').val(JSON.stringify(wetlandData)); - $('#river_name').val(wetlandData['name'] ? wetlandData['name'] : '-'); - - moveMarkerOnTheMap(_coordinates[1], _coordinates[0], false); - } - } - resolve(features); - }, - error: function (err) { - console.log(err); - reject(err); - } - }); - }); - }; - - map.on('click', function(e) { - let layerSource = wmsLayer.getSource().getGetFeatureInfoUrl( - e.coordinate, - view.getResolution(), - view.getProjection(), - {'INFO_FORMAT': 'application/json'} - ); - layerSource += '&QUERY_LAYERS=' + wmsLayerName; - const zoomLevel = map.getView().getZoom(); - $('#map-loading').css('display', 'flex'); - getFeature(layerSource, e.coordinate,zoomLevel > 10).then(function(features) { - if (features.length > 0 && zoomLevel <= 10) { - let bbox = features[0]['bbox']; - let centroidX = (bbox[0] + bbox[2]) / 2; - let centroidY = (bbox[1] + bbox[3]) / 2; - let point = [centroidX, centroidY]; - - layerSource = wmsLayer.getSource().getGetFeatureInfoUrl( - point, - view.getResolution(), - view.getProjection(), - {'INFO_FORMAT': 'application/json'} - ); - layerSource += '&QUERY_LAYERS=' + wmsLayerName; - getFeature(layerSource, e.coordinate, true).then(function (f) { - $('#map-loading').hide(); - }) - } else { - $('#map-loading').hide(); - } - }).catch(function(error) { - // handle any errors - }); + mapClicked(e.coordinate); }); } diff --git a/bims/templates/wetland_site_form.html b/bims/templates/wetland_site_form.html index dca2f5eb0..6d4cd6dd2 100644 --- a/bims/templates/wetland_site_form.html +++ b/bims/templates/wetland_site_form.html @@ -120,6 +120,12 @@

class="form-control form-control-sm" style="height: 100%" value="{{ location_site_long }}" {% if update %}{% if not allow_to_edit %}disabled{% endif %}{% endif %} required>

+
+ +
From d203d00fae627a8bd7b23bb0c866853512686f31 Mon Sep 17 00:00:00 2001 From: Dimas Date: Fri, 25 Aug 2023 16:42:02 +0700 Subject: [PATCH 3/4] Update form --- .../send_notification_to_validator.py | 3 -- bims/enums/ecosystem_type.py | 20 +++++++++++ ...ationsite_hydrogeomorphic_type_and_more.py | 35 +++++++++++++++++++ bims/models/location_site.py | 32 +++++++++++++++-- bims/static/js/wetland_site.js | 5 +-- bims/templates/wetland_site_form.html | 35 ++++++++----------- bims/views/location_site.py | 17 ++++++++- 7 files changed, 117 insertions(+), 30 deletions(-) create mode 100644 bims/migrations/0347_locationsite_hydrogeomorphic_type_and_more.py diff --git a/bims/api_views/send_notification_to_validator.py b/bims/api_views/send_notification_to_validator.py index 7492fe44c..a37714194 100644 --- a/bims/api_views/send_notification_to_validator.py +++ b/bims/api_views/send_notification_to_validator.py @@ -1,15 +1,12 @@ # coding=utf-8 from braces.views import LoginRequiredMixin from django.core.mail import send_mail -from django.db.models import Q from django.http import JsonResponse, HttpResponse -from django.contrib.auth.models import Permission from django.contrib.sites.models import Site from django.conf import settings from django.contrib import messages from rest_framework.views import APIView from rest_framework import status -from geonode.people.models import Profile from bims.models import LocationSite from bims.models.survey import Survey diff --git a/bims/enums/ecosystem_type.py b/bims/enums/ecosystem_type.py index 28e2344ee..86c3ccc78 100644 --- a/bims/enums/ecosystem_type.py +++ b/bims/enums/ecosystem_type.py @@ -17,3 +17,23 @@ (HYDROPERIOD_SATURATED, HYDROPERIOD_SATURATED), (HYDROPERIOD_DRY, HYDROPERIOD_DRY), ) + +HYDROGEOMORPHIC_NONE = '-' +HYDROGEOMORPHIC_FLOODPLAIN = 'Floodplain' +HYDROGEOMORPHIC_CHANNELLED_VALLEY_BOTTOM = 'Channelled valley-bottom' +HYDROGEOMORPHIC_UNCHANNELLED_VALLEY_BOTTOM = 'Unchannelled valley-bottom' +HYDROGEOMORPHIC_SEEP = 'Seep' +HYDROGEOMORPHIC_DEPRESSION = 'Depression' +HYDROGEOMORPHIC_WETLAND_FLAT = 'Wetland flat' +HYDROGEOMORPHIC_UNKNOWN = 'Unknown' + +HYDROGEOMORPHIC_CHOICES = ( + (HYDROGEOMORPHIC_NONE, HYDROGEOMORPHIC_NONE), + (HYDROGEOMORPHIC_FLOODPLAIN, HYDROGEOMORPHIC_FLOODPLAIN), + (HYDROGEOMORPHIC_CHANNELLED_VALLEY_BOTTOM, HYDROGEOMORPHIC_CHANNELLED_VALLEY_BOTTOM), + (HYDROGEOMORPHIC_UNCHANNELLED_VALLEY_BOTTOM, HYDROGEOMORPHIC_UNCHANNELLED_VALLEY_BOTTOM), + (HYDROGEOMORPHIC_SEEP, HYDROGEOMORPHIC_SEEP), + (HYDROGEOMORPHIC_DEPRESSION, HYDROGEOMORPHIC_DEPRESSION), + (HYDROGEOMORPHIC_WETLAND_FLAT, HYDROGEOMORPHIC_WETLAND_FLAT), + (HYDROGEOMORPHIC_UNKNOWN, HYDROGEOMORPHIC_UNKNOWN), +) diff --git a/bims/migrations/0347_locationsite_hydrogeomorphic_type_and_more.py b/bims/migrations/0347_locationsite_hydrogeomorphic_type_and_more.py new file mode 100644 index 000000000..aa45fd504 --- /dev/null +++ b/bims/migrations/0347_locationsite_hydrogeomorphic_type_and_more.py @@ -0,0 +1,35 @@ +# Generated by Django 4.1.10 on 2023-08-25 09:27 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('bims', '0346_alter_bimsdocument_authors_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='locationsite', + name='hydrogeomorphic_type', + field=models.CharField(blank=True, default='', max_length=128, null=True), + ), + migrations.AddField( + model_name='locationsite', + name='user_hydrogeomorphic_type', + field=models.CharField(blank=True, choices=[('-', '-'), ('Floodplain', 'Floodplain'), ('Channelled valley-bottom', 'Channelled valley-bottom'), ('Unchannelled valley-bottom', 'Unchannelled valley-bottom'), ('Seep', 'Seep'), ('Depression', 'Depression'), ('Wetland flat', 'Wetland flat'), ('Unknown', 'Unknown')], default='-', max_length=128, null=True), + ), + migrations.AddField( + model_name='locationsite', + name='user_wetland_name', + field=models.CharField(blank=True, default='', max_length=256, null=True), + ), + migrations.AddField( + model_name='locationsite', + name='wetland_name', + field=models.CharField(blank=True, default='', max_length=256, null=True), + ), + ] diff --git a/bims/models/location_site.py b/bims/models/location_site.py index a1247c232..7543c03b5 100644 --- a/bims/models/location_site.py +++ b/bims/models/location_site.py @@ -24,7 +24,9 @@ from bims.models.location_context import LocationContext from bims.models.location_context_group import LocationContextGroup from bims.utils.decorator import prevent_recursion -from bims.enums.ecosystem_type import ECOSYSTEM_TYPE_CHOICES +from bims.enums.ecosystem_type import ( + ECOSYSTEM_TYPE_CHOICES, HYDROGEOMORPHIC_NONE, HYDROGEOMORPHIC_CHOICES +) LOGGER = logging.getLogger(__name__) @@ -180,6 +182,31 @@ class LocationSite(DocumentLinksMixin, AbstractValidation): default='', null=True ) + wetland_name = models.CharField( + max_length=256, + blank=True, + default='', + null=True + ) + user_wetland_name = models.CharField( + max_length=256, + blank=True, + default='', + null=True + ) + hydrogeomorphic_type = models.CharField( + max_length=128, + blank=True, + default='', + null=True + ) + user_hydrogeomorphic_type = models.CharField( + max_length=128, + blank=True, + null=True, + default=HYDROGEOMORPHIC_NONE, + choices=HYDROGEOMORPHIC_CHOICES + ) @property def location_site_identifier(self): @@ -200,8 +227,7 @@ def get_centroid(self): """ Getting centroid of location site """ if ( - self.geometry_point and - self.location_type.allowed_geometry == 'POINT' + self.geometry_point ): return self.geometry_point else: diff --git a/bims/static/js/wetland_site.js b/bims/static/js/wetland_site.js index 66251fb69..7038f38e0 100644 --- a/bims/static/js/wetland_site.js +++ b/bims/static/js/wetland_site.js @@ -21,6 +21,7 @@ const getFeature = (layerSource, coordinates, renderResult) => { } $('#latitude').val(''); $('#longitude').val(''); + $('#hydrogeomorphic_type').val(''); return new Promise((resolve, reject) => { $.ajax({ @@ -58,7 +59,6 @@ const getFeature = (layerSource, coordinates, renderResult) => { $('#wetland-site-code').attr('disabled', false); $('#site_code').val(''); - $('#geomorphological_zone').val(''); let olFeature = new ol.format.GeoJSON().readFeatures(feature); @@ -80,7 +80,8 @@ const getFeature = (layerSource, coordinates, renderResult) => { // vectorLayer.getSource().addFeatures(olFeature); wetlandData = feature['properties']; $('#additional-data').val(JSON.stringify(wetlandData)); - $('#river_name').val(wetlandData['name'] ? wetlandData['name'] : '-'); + $('#river_name').val(wetlandData['name'] ? wetlandData['name'] : ''); + $('#hydrogeomorphic_type').val(wetlandData['hgm_type'] ? wetlandData['hgm_type'] : ''); moveMarkerOnTheMap(_coordinates[1], _coordinates[0], false); } diff --git a/bims/templates/wetland_site_form.html b/bims/templates/wetland_site_form.html index 6d4cd6dd2..acbd7241b 100644 --- a/bims/templates/wetland_site_form.html +++ b/bims/templates/wetland_site_form.html @@ -129,22 +129,22 @@

-
-
- + placeholder="" value="{% if user_wetland_name %}{{ user_wetland_name }}{% else %}{% endif %}" >
@@ -182,28 +182,21 @@

-
- Hydrogeomorphic Type +
+ - -
-
- + placeholder="" value="{{ hydrogeomorphic_type }}" readonly>
+
+ class="col-sm-2 col-form-label col-form-label">User Hydrogeomorphic Type
- + {% for geo in hydrogeomorphic_type_category %} + {% endfor %}
diff --git a/bims/views/location_site.py b/bims/views/location_site.py index 4fcfc5146..d01bccf13 100644 --- a/bims/views/location_site.py +++ b/bims/views/location_site.py @@ -34,6 +34,7 @@ from sass.models import River from bims.utils.jsonify import json_loads_byteified from bims.serializers.survey_serializer import SurveySerializer +from bims.enums.ecosystem_type import HYDROGEOMORPHIC_CHOICES def handle_location_site_post_data( @@ -61,6 +62,11 @@ def handle_location_site_post_data( wetland_id = post_data.get('wetland_id', None) ecosystem_type = post_data.get('ecosystem_type', '') + wetland_name = post_data.get('wetland_name', '') + user_wetland_name = post_data.get('user_wetland_name', '') + hydrogeomorphic_type = post_data.get('hydrogeomorphic_type', '') + user_hydrogeomorphic_type = post_data.get('user_hydrogeomorphic_type', '') + if site_geometry and 'geometry' in site_geometry: try: site_geometry_data = json.loads(site_geometry) @@ -136,7 +142,11 @@ def handle_location_site_post_data( 'legacy_river_name': user_river_name, 'legacy_site_code': legacy_site_code, 'date_created': date, - 'ecosystem_type': ecosystem_type + 'ecosystem_type': ecosystem_type, + 'wetland_name': wetland_name, + 'user_wetland_name': user_wetland_name, + 'hydrogeomorphic_type': hydrogeomorphic_type, + 'user_hydrogeomorphic_type': user_hydrogeomorphic_type } if site_geometry: post_dict['geometry_multipolygon'] = site_geometry @@ -301,6 +311,7 @@ def get_context_data(self, **kwargs): context['geomorphological_zone_category'] = [ (g.name, g.value) for g in GEOMORPHOLOGICAL_ZONE_CATEGORY_ORDER ] + context['hydrogeomorphic_type_category'] = HYDROGEOMORPHIC_CHOICES context['ecosystem_type'] = self.request.GET.get('type', '') try: context['bing_key'] = ( @@ -362,6 +373,10 @@ class LocationSiteFormUpdateView(LocationSiteFormView): def additional_context_data(self): context_data = dict() context_data['location_site_lat'] = self.location_site.latitude + context_data['user_wetland_name'] = self.location_site.user_wetland_name + context_data['wetland_name'] = self.location_site.wetland_name + context_data['hydrogeomorphic_type'] = self.location_site.hydrogeomorphic_type + context_data['user_hydrogeomorphic_type'] = self.location_site.user_hydrogeomorphic_type context_data['location_site_long'] = self.location_site.longitude context_data['site_code'] = self.location_site.site_code context_data['site_description'] = self.location_site.site_description From 4286c6077fe1232031ff2653d33297d2746d6813 Mon Sep 17 00:00:00 2001 From: Dimas Date: Sun, 27 Aug 2023 14:07:19 +0700 Subject: [PATCH 4/4] Fix update wetland --- bims/static/js/non_requirejs/site_form.js | 5 +++-- bims/static/js/wetland_site.js | 23 ++++++++++++++++++++--- bims/templates/fbis/navigation_bar.html | 2 +- bims/templates/wetland_site_form.html | 3 ++- bims/views/location_site.py | 1 + 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/bims/static/js/non_requirejs/site_form.js b/bims/static/js/non_requirejs/site_form.js index 64a9eb090..cbcb5e092 100644 --- a/bims/static/js/non_requirejs/site_form.js +++ b/bims/static/js/non_requirejs/site_form.js @@ -337,7 +337,7 @@ let addMarkerToMap = (lat, lon, zoomToMap = true) => { anchor: [0.55, 43], anchorXUnits: 'fraction', anchorYUnits: 'pixels', - opacity: 0.75, + opacity: 1, src: '/static/img/map-marker.png' })) }); @@ -348,10 +348,11 @@ let addMarkerToMap = (lat, lon, zoomToMap = true) => { map.addLayer(new ol.layer.Vector({ source: markerSource, style: markerStyle, + zIndex: 1000 })); if (zoomToMap) { map.getView().setCenter(locationSiteCoordinate); - map.getView().setZoom(6); + map.getView().setZoom(14); } if (allowToEdit) { document.getElementById('update-site-code').disabled = false; diff --git a/bims/static/js/wetland_site.js b/bims/static/js/wetland_site.js index 7038f38e0..b16b47464 100644 --- a/bims/static/js/wetland_site.js +++ b/bims/static/js/wetland_site.js @@ -3,10 +3,17 @@ let wmsSource = null; let wmsLayer = null; let wmsLayerName = 'kartoza:nwm6_beta_v3_20230714'; +if (window.wetlandData) { + wetlandData = window.wetlandData; +} + updateCoordinate = function (zoomToMap = true) { try { let latitude = parseFloat($('#latitude').val()); let longitude = parseFloat($('#longitude').val()); + if (!latitude || !longitude) { + return false; + } let _coordinates = ol.proj.transform([longitude, latitude], 'EPSG:4326', 'EPSG:3857'); mapClicked(_coordinates); } catch (e) { @@ -30,6 +37,7 @@ const getFeature = (layerSource, coordinates, renderResult) => { data: { 'layerSource': layerSource }, + timeout: 5000, success: function (result) { const data = result['feature_data']; let objectData = {}; @@ -89,7 +97,11 @@ const getFeature = (layerSource, coordinates, renderResult) => { resolve(features); }, error: function (err) { - console.log(err); + if(err.status === 0){ + alert("The site is unreachable at the moment."); + } else { + alert("An error occurred: " + err.statusText); + } reject(err); } }); @@ -110,6 +122,7 @@ let mapClicked = (coordinate) => { layerSource += '&QUERY_LAYERS=' + wmsLayerName; const zoomLevel = map.getView().getZoom(); $('#map-loading').css('display', 'flex'); + $('#update-coordinate').attr('disabled', true); getFeature(layerSource, coordinate,zoomLevel > 10).then(function(features) { if (features.length > 0 && zoomLevel <= 10) { let bbox = features[0]['bbox']; @@ -126,9 +139,11 @@ let mapClicked = (coordinate) => { layerSource += '&QUERY_LAYERS=' + wmsLayerName; getFeature(layerSource, coordinate, true).then(function (f) { $('#map-loading').hide(); + $('#update-coordinate').attr('disabled', false); }) } else { $('#map-loading').hide(); + $('#update-coordinate').attr('disabled', false); } }).catch(function(error) { // handle any errors @@ -187,15 +202,17 @@ wetlandSiteCodeButton.click(function () { let siteCode = wetlandData['quaternary'].substring(0, 4); - let wetlandName = $('#river_name').val() !== '-' ? $('#river_name').val() : ''; + let wetlandName = $('#wetland_name').val() !== '-' ? $('#wetland_name').val() : ''; if (!wetlandName) { - wetlandName = $('#user_river_name').val() + wetlandName = $('#user_wetland_name').val() } if (wetlandName) { wetlandName = '-' + wetlandName.substring(0, 4); } + console.log('wetlandName', wetlandName) + siteCode += wetlandName; let url = '/api/get-site-code/?user_site_code=' + siteCode; diff --git a/bims/templates/fbis/navigation_bar.html b/bims/templates/fbis/navigation_bar.html index 13b2072de..7b7a8df4c 100644 --- a/bims/templates/fbis/navigation_bar.html +++ b/bims/templates/fbis/navigation_bar.html @@ -128,7 +128,7 @@
Add Site diff --git a/bims/templates/wetland_site_form.html b/bims/templates/wetland_site_form.html index acbd7241b..b34cd4397 100644 --- a/bims/templates/wetland_site_form.html +++ b/bims/templates/wetland_site_form.html @@ -23,6 +23,7 @@ const locationSiteLong = '{{ location_site_long }}'; const allowToEdit = {% if update %}{% if allow_to_edit %}true{% else %}false{% endif %}{% else %}true{% endif %}; let siteId = null; + {% if additional_data %}window.wetlandData = {{ additional_data | safe }};{% endif %}