Skip to content

Commit 71dfdf2

Browse files
committed
Pre-select collection extents when adding new collections to model builder.
1 parent c416e1f commit 71dfdf2

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/components/VisualEditor.vue

+11
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ export default {
9696
watch: {
9797
processes() {
9898
this.registerProcesses();
99+
},
100+
collections() {
101+
this.registerCollections();
99102
}
100103
},
101104
methods: {
@@ -121,6 +124,7 @@ export default {
121124
this.blocks.run("#" + this.id, this.editable);
122125
123126
this.registerProcesses();
127+
this.registerCollections();
124128
this.makeCallbackArguments();
125129
this.insertProcessGraph(this.value, false);
126130
}
@@ -178,6 +182,13 @@ export default {
178182
this.makeCallbackArguments();
179183
},
180184
185+
registerCollections() {
186+
this.blocks.unregisterCollectionDefaults();
187+
for(var i in this.collections) {
188+
this.blocks.registerCollectionDefaults(this.collections[i]);
189+
}
190+
},
191+
181192
registerProcesses() {
182193
this.blocks.unregisterProcesses();
183194
for(var i in this.processes) {

src/components/blocks/blocks.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ var Blocks = function(errorHandler = null, openParameterEditor = null, openSchem
6060
// Blocks types
6161
this.moduleTypes = {};
6262

63+
// Collection default values
64+
this.collectionDefaults = {};
65+
6366
// Instances
6467
this.blocks = {};
6568

@@ -302,7 +305,13 @@ Blocks.prototype.getPositionForPageXY = function(x, y) {
302305
*/
303306
Blocks.prototype.addCollection = function(name, x = null, y = null)
304307
{
305-
return this.addBlock('load_collection', 'process', x, y, {id: name, spatial_extent: null, temporal_extent: null});
308+
var spatialExtent = null;
309+
var temporalExtent = null;
310+
if (typeof this.collectionDefaults[name] === 'object') {
311+
spatialExtent = this.collectionDefaults[name].spatialExtent;
312+
temporalExtent = this.collectionDefaults[name].temporalExtent;
313+
}
314+
return this.addBlock('load_collection', 'process', x, y, {id: name, spatial_extent: spatialExtent, temporal_extent: temporalExtent});
306315
};
307316

308317
Blocks.prototype.addProcess = function(name, x = null, y = null)
@@ -343,6 +352,10 @@ Blocks.prototype.addBlock = function(name, type, x, y, values = {})
343352
return block;
344353
};
345354

355+
Blocks.prototype.unregisterCollectionDefaults = function() {
356+
this.collectionDefaults = {};
357+
}
358+
346359
Blocks.prototype.unregisterProcesses = function() {
347360
this.moduleTypes['process'] = {};
348361
}
@@ -351,6 +364,23 @@ Blocks.prototype.unregisterCallbackArguments = function() {
351364
this.moduleTypes['callback-arguments'] = {};
352365
}
353366

367+
Blocks.prototype.registerCollectionDefaults = function(collection) {
368+
try {
369+
var hasZ = collection.extent.spatial.length > 4;
370+
this.collectionDefaults[collection.id] = {
371+
spatialExtent: {
372+
west: collection.extent.spatial[0],
373+
east: collection.extent.spatial[hasZ ? 3 : 2],
374+
south: collection.extent.spatial[1],
375+
north: collection.extent.spatial[hasZ ? 4 : 3]
376+
},
377+
temporalExtent: collection.extent.temporal
378+
};
379+
} catch (error) {
380+
console.log(error);
381+
}
382+
};
383+
354384
/**
355385
* Registers a new block type
356386
*/

0 commit comments

Comments
 (0)