Skip to content

Commit

Permalink
Ensure the bbox input is in the correct form
Browse files Browse the repository at this point in the history
  • Loading branch information
markstuart committed Nov 15, 2023
1 parent 9383084 commit 89fdd39
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions ckanext/spatial/public/js/spatial_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down Expand Up @@ -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) {
$('<input type="hidden" />').attr({'id': item, 'name': item}).appendTo(form);
}
});
// Add necessary field to the search form if not already created
if ($("#" + bbox_input_id).length === 0) {
$('<input type="hidden" />').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');
Expand Down

0 comments on commit 89fdd39

Please sign in to comment.