Skip to content

Commit 147b406

Browse files
committed
generalize raster-specific language and variable names; disable resolution customization for vectors
1 parent 408097a commit 147b406

File tree

3 files changed

+25
-44
lines changed

3 files changed

+25
-44
lines changed

clipping-service/app/app.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -269,31 +269,13 @@ def clip_app():
269269

270270
@app.route("/clip", methods=['POST'])
271271
def clip():
272-
#data = flask.request.json
273-
#source_raster = data['file_url']
274-
#target_bbox = data['target_bbox']
275-
#target_epsg = data['target_epsg']
276-
277-
#SOURCE_LOGGER.info(f"Clipping {source_raster} to {target_bbox}")
278-
279-
#for i in range(11):
280-
# time.sleep(1)
281-
# print(f"logging progress {i*10}%")
282-
# SOURCE_LOGGER.info(f"Progress: {i*10}%")
283-
#SOURCE_LOGGER.info("Done!")
284-
285-
#return jsonify({
286-
# 'status': 'success',
287-
# 'message': 'Clipping finished'
288-
#})
289-
290272
parameters = request.get_json()
291273
app.logger.info(parameters)
292274

293275
if not parameters['file_url'].startswith(TRUSTED_BUCKET):
294276
app.logger.error("Invalid source file, not in the known bucket: %s",
295277
parameters['file_url'])
296-
raise ValueError("Invalid COG provided.")
278+
raise ValueError("Invalid source file provided.")
297279

298280
source_file_type = parameters['layer_type']
299281
if source_file_type not in [RASTER, VECTOR]:

src/ckanext-mappreview/ckanext/mappreview/assets/js/mappreview.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -764,25 +764,19 @@ ckan.module("mappreview", function ($, _) {
764764
<i class="fa-solid fa-xmark"></i>
765765
</button>
766766
</div>`
767-
var rasters = [];
768-
// for (const layer of config.layers) {
769-
// if (layer.type === "raster") {
770-
// rasters.push(layer);
771-
// }
772-
// }
767+
var layers = [];
773768
for (const layer of config.layers) {
774-
console.log(layer.type);
775-
rasters.push(layer);
769+
layers.push(layer);
776770
}
777-
if (rasters.length == 0) {
771+
if (layers.length == 0) {
778772
this._container.innerHTML = `
779773
<button type="button"
780774
class="btn btn-outline-secondary"
781775
disabled
782-
title="At this time, clipping only works with raster layers.">
776+
title="No layers to clip.">
783777
Clipping is disabled
784778
</button>`;
785-
} else if (rasters.length == 1) {
779+
} else if (layers.length == 1) {
786780
this._container.innerHTML = `
787781
<button type="button"
788782
class="btn btn-secondary"
@@ -794,24 +788,29 @@ ckan.module("mappreview", function ($, _) {
794788
this._container.getElementsByTagName('button')[0].addEventListener('click', function() {
795789
// when the 'clip to this bounding box' button is selected, set an attribute of the button
796790
document.getElementById(clip_button_id).setAttribute(
797-
'layer-name', rasters[0].name);
791+
'layer-name', layers[0].name);
798792
document.getElementById(clip_button_id).setAttribute(
799-
'layer-url', rasters[0].url);
793+
'layer-url', layers[0].url);
800794
document.getElementById(clip_button_id).setAttribute(
801-
'layer-type', rasters[0].type);
802-
selected_layer = rasters[0].name;
803-
natcapClipLayer(rasters[0].name);
795+
'layer-type', layers[0].type);
796+
selected_layer = layers[0].name;
797+
natcapClipLayer(layers[0].name);
798+
799+
// setting custom resolution only makes sense for rasters
800+
if (layers[0].type == "vector") {
801+
document.getElementById('natcapClipPixelSize').style.display = 'none';
802+
}
804803
});
805804
} else {
806-
var raster_string = "";
807-
for (const raster_layer of rasters) {
808-
raster_string += `
805+
var clip_layer_string = "";
806+
for (const clip_layer of layers) {
807+
clip_layer_string += `
809808
<li>
810809
<a class="dropdown-item
811810
href="#"
812-
layer-name='${raster_layer.name}'
813-
layer-url=${raster_layer.url}>
814-
${raster_layer.name}
811+
layer-name='${clip_layer.name}'
812+
layer-url=${clip_layer.url}>
813+
${clip_layer.name}
815814
</a>
816815
</li>\n`
817816
}
@@ -825,7 +824,7 @@ ckan.module("mappreview", function ($, _) {
825824
Clip this layer
826825
</button>
827826
<ul class="dropdown-menu">
828-
${raster_string}
827+
${clip_layer_string}
829828
</ul>
830829
</div>
831830
${progress_modal_trigger_button}

src/ckanext-mappreview/ckanext/mappreview/templates/package/snippets/mappreview.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ <h1 class="modal-title" id="progress-modal-label">
2828
<!-- Start modal body -->
2929
<div class="modal-body">
3030
<div id="natcapClipInitOptions">
31-
<h3>Warp/reproject the clipped raster?</h3>
31+
<h3>Warp/reproject the clipped layer?</h3>
3232
<p>
3333
The layer will be clipped to the bounding box you
3434
selected on the globe, and will keep its original
@@ -76,7 +76,7 @@ <h3>Warp/reproject the clipped raster?</h3>
7676
class="col-form-label"></label>
7777
</div>
7878
</div>
79-
<div class="row">
79+
<div class="row" id="natcapClipPixelSize">
8080
<div class="col-sm p-2">
8181
<input class="form-check-input"
8282
type="checkbox"

0 commit comments

Comments
 (0)