From c320a589c0dcbbd8451e1059ad5edf5bd606e109 Mon Sep 17 00:00:00 2001 From: Mark Stuart Date: Mon, 13 Nov 2023 13:23:41 +1300 Subject: [PATCH] Ensure the bbox input is in the correct form --- ckanext/spatial/public/js/spatial_query.js | 32 ++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/ckanext/spatial/public/js/spatial_query.js b/ckanext/spatial/public/js/spatial_query.js index 76b23c47..dc417aeb 100644 --- a/ckanext/spatial/public/js/spatial_query.js +++ b/ckanext/spatial/public/js/spatial_query.js @@ -133,7 +133,7 @@ this.ckan.module('spatial-query', function ($, _) { map.removeLayer(module.extentLayer); } module.extentLayer = extentLayer = e.layer; - $('#ext_bbox').val(extentLayer.getBounds().toBBoxString()); + module.ext_bbox_input.val(extentLayer.getBounds().toBBoxString()); map.addLayer(extentLayer); element.find('.btn-primary').removeClass('disabled').addClass('btn-primary'); }); @@ -197,33 +197,31 @@ this.ckan.module('spatial-query', function ($, _) { // Is there an existing box from a previous search? _setPreviousBBBox: function(map, zoom=true) { - previous_bbox = this._getParameterByName('ext_bbox'); + let module = this; + previous_bbox = module._getParameterByName('ext_bbox'); if (previous_bbox) { - $('#ext_bbox').val(previous_bbox); - this.extentLayer = this._drawExtentFromCoords(previous_bbox.split(',')) - map.addLayer(this.extentLayer); + module.ext_bbox_input.val(previous_bbox); + module.extentLayer = module._drawExtentFromCoords(previous_bbox.split(',')) + map.addLayer(module.extentLayer); if (zoom) { - map.fitBounds(this.extentLayer.getBounds(), {"animate": false, "padding": [20, 20]}); + map.fitBounds(module.extentLayer.getBounds(), {"animate": false, "padding": [20, 20]}); } } else { - map.fitBounds(this.options.default_extent, {"animate": false}); + map.fitBounds(module.options.default_extent, {"animate": false}); } - }, _onReady: function() { let module = this; let map; - let form = $(".search-form"); - - var buttons; + let form = $('#dataset-search-form'); + let bbox_input_id = 'ext_bbox'; - // Add necessary fields to the search form if not already created - $(['ext_bbox']).each(function(index, item){ - if ($("#" + item).length === 0) { - $('').attr({'id': item, 'name': item}).appendTo(form); - } - }); + // Add necessary field to the search form if not already created + if ($("#" + bbox_input_id).length === 0) { + $('').attr({'id': bbox_input_id, 'name': bbox_input_id}).appendTo(form); + } + module.ext_bbox_input = $('#dataset-search-form #ext_bbox'); // OK map time this.mainMap = map = this._createMap('dataset-map-container');