Skip to content

Commit

Permalink
Merge pull request #2154 from WikiWatershed/arr/tiny-compare-maps
Browse files Browse the repository at this point in the history
Compare View Revamp: wire up maps and modification popovers
  • Loading branch information
Alice Rottersman committed Aug 21, 2017
2 parents 7f7a542 + cc6656f commit e860700
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 9 deletions.
16 changes: 16 additions & 0 deletions src/mmw/js/src/compare/templates/compareDescriptionPopover.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% if is_pre_columbian %}
<h3 class="compare-no-mod-title">{{name}}</h3>
<p>
Lorem ipsum this scenario shows the tr55 model results under pre columbian conditions...
</p>
{% elif is_current_conditions %}
<h3 class="compare-no-mod-title">{{name}}</h3>
<p>
Lorem ipsum this is the model run under current conditions
</p>
{% else %}
<h3 class="compare-no-mod-title">No modifications</h3>
<p>
To add modifications, close this modal and select "Land cover" or "Conservation practices" lorem ipsum dolor sit
</p>
{% endif %}
23 changes: 23 additions & 0 deletions src/mmw/js/src/compare/templates/compareModificationsPopover.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% macro modificationsTable(caption, modifications) %}
<table class="compare-modifications-table">
{% if modifications.length > 0 %}
<h5>{{ caption }}</h5>
{% endif %}
<tbody>
{% for mod in modifications %}
<tr>
<td class="modification-value">
{{ modConfigUtils.getHumanReadableShortName(mod.get('value')) }}
</td>
<td class="modification-area">
+{{ mod.get('area').toFixed(1) }} {{ mod.get('units') }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endmacro %}

<h3>Modifications</h3>
{{ modificationsTable('Land Cover', landCovers) }}
{{ modificationsTable('Conservation Practices', conservationPractices) }}
4 changes: 2 additions & 2 deletions src/mmw/js/src/compare/templates/compareScenarioItem.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div class="compare-mapplaceholder"></div>
<h3><span class="scenario-badge"></span> {{ name }}</h3>
<div class="compare-map-container" role="button" data-html="true" data-toggle="popover"></div>
<div class="compare-scenario-title"><span class="scenario-badge"></span> {{ name }}</div>
69 changes: 68 additions & 1 deletion src/mmw/js/src/compare/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ var _ = require('lodash'),
compareScenariosTmpl = require('./templates/compareScenarios.html'),
compareScenarioTmpl = require('./templates/compareScenario.html'),
compareModelingTmpl = require('./templates/compareModeling.html'),
compareModificationsTmpl = require('./templates/compareModifications.html');
compareModificationsTmpl = require('./templates/compareModifications.html'),
compareModificationsPopoverTmpl = require('./templates/compareModificationsPopover.html'),
compareDescriptionPopoverTmpl = require('./templates/compareDescriptionPopover.html');

var CompareWindow2 = Marionette.LayoutView.extend({
template: compareWindow2Tmpl,
Expand Down Expand Up @@ -158,9 +160,74 @@ var InputsView = Marionette.LayoutView.extend({
},
});

var CompareModificationsPopoverView = Marionette.ItemView.extend({
// model: ModificationsCollection
template: compareModificationsPopoverTmpl,

templateHelpers: function() {
return {
conservationPractices: this.model.filter(function(modification) {
return modification.get('name') === 'conservation_practice';
}),
landCovers: this.model.filter(function(modification) {
return modification.get('name') === 'landcover';
}),
modConfigUtils: modConfigUtils
};
}
});

var CompareDescriptionPopoverView = Marionette.ItemView.extend({
// model: ScenarioModel
template: compareDescriptionPopoverTmpl,
className: 'compare-no-mods-popover'
});

var ScenarioItemView = Marionette.ItemView.extend({
className: 'compare-column',
template: compareScenarioItemTmpl,

ui: {
'mapContainer': '.compare-map-container',
},

onShow: function() {
var mapView = new coreViews.MapView({
model: new coreModels.MapModel({
'areaOfInterest': App.currentProject.get('area_of_interest'),
'areaOfInterestName': App.currentProject.get('area_of_interest_name'),
}),
el: this.ui.mapContainer,
addZoomControl: false,
addLocateMeButton: false,
addSidebarToggleControl: false,
showLayerAttribution: false,
initialLayerName: App.getLayerTabCollection().getCurrentActiveBaseLayerName(),
layerTabCollection: new coreModels.LayerTabCollection(),
interactiveMode: false,
});
mapView.updateAreaOfInterest();
mapView.updateModifications(this.model.get('modifications'));
mapView.fitToModificationsOrAoi();
mapView.render();
},

onRender: function() {
var modifications = this.model.get('modifications'),
popOverView = modifications.length > 0 ?
new CompareModificationsPopoverView({
model: modifications
}) :
new CompareDescriptionPopoverView({
model: this.model
});

this.ui.mapContainer.popover({
placement: 'bottom',
trigger: 'hover focus',
content: popOverView.render().el
});
}
});

var ScenariosRowView = Marionette.CollectionView.extend({
Expand Down
10 changes: 10 additions & 0 deletions src/mmw/js/src/core/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,16 @@ var MapView = Marionette.ItemView.extend({
}
},

fitToModificationsOrAoi: function() {
var modificationsBounds = this._modificationsLayer.getBounds();

if (modificationsBounds.isValid()) {
this._leafletMap.fitBounds(modificationsBounds, { reset: true });
} else {
this.fitToAoi();
}
},

updateCurrentZoomLevel: function(layer) {
var layerMaxZoom = layer.options.maxZoom,
map = this,
Expand Down
33 changes: 27 additions & 6 deletions src/mmw/sass/pages/_compare.scss
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ $compare-chart-table-height: calc(100vh - #{$height-lg} - #{$compare-footer-heig
margin-top: 20px;
max-width: 1200px;
max-height: calc(100% - 20px);
-webkit-font-smoothing: antialiased;

@media screen and (max-width: 1300px) {
max-width: 1000px;
Expand Down Expand Up @@ -505,7 +506,7 @@ $compare-chart-table-height: calc(100vh - #{$height-lg} - #{$compare-footer-heig
min-width: 120px;
width: 120px;

h3 {
.compare-scenario-title {
font-size: $font-size-h5;
font-weight: 400;
}
Expand Down Expand Up @@ -557,11 +558,31 @@ $compare-chart-table-height: calc(100vh - #{$height-lg} - #{$compare-footer-heig
}
}

.compare-mapplaceholder {
height: 90px;
background-color: #aaa;
margin-bottom: 10px;
width: 120px;
.compare-map-container {
cursor: pointer !important;
height: 90px;
background-color: #aaa;
margin-bottom: 10px;
width: 120px;
}

.compare-modifications-table {
font-size: $font-size-h5;
width: 100%;
.modification-value {
padding-right: 12px;
}
.modification-area {
color: $brand-primary;
text-align: right;
}
}

.compare-no-mods-popover {
width: 189px;
> .compare-no-mod-title {
margin-bottom: 2px;
}
}

.compare-inputs {
Expand Down

0 comments on commit e860700

Please sign in to comment.