Skip to content

Commit 3981ee2

Browse files
committed
Merge pull request #2031 from Vizzuality/disposable/urthecast
Disposable/urthecast
2 parents 65f3e6c + 4d3d55d commit 3981ee2

File tree

129 files changed

+3198
-856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+3198
-856
lines changed
Loading
Loading

app/assets/javascripts/abstract/layer/CanvasLayerClass.js

+15-17
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,31 @@ define([
8383
},
8484

8585
_drawCanvasImage: function(canvasData) {
86-
var canvas = canvasData.canvas;
87-
var image = canvasData.image;
88-
var x = canvasData.x;
89-
var y = canvasData.y;
90-
var z = canvasData.z;
86+
"use asm";
87+
var canvas = canvasData.canvas,
88+
ctx = canvas.getContext('2d'),
89+
image = canvasData.image,
90+
zsteps = this._getZoomSteps(canvasData.z) |0; // force 32bit int type
9191

92-
var ctx = canvas.getContext('2d');
93-
var zsteps = this._getZoomSteps(z);
92+
ctx.clearRect(0, 0, 256, 256); // this will allow us to sum up the dots when the timeline is running
9493

9594
if (zsteps < 0) {
9695
ctx.drawImage(image, 0, 0);
97-
} else {
98-
ctx.imageSmoothingEnabled = false;
96+
} else { // over the maxzoom, we'll need to scale up each tile
97+
98+
ctx.imageSmoothingEnabled = false; // disable pic enhancement
9999
ctx.mozImageSmoothingEnabled = false;
100-
ctx.webkitImageSmoothingEnabled = false;
101100

102-
var srcX = 256 / Math.pow(2, zsteps) * (x % Math.pow(2, zsteps));
103-
var srcY = 256 / Math.pow(2, zsteps) * (y % Math.pow(2, zsteps));
104-
var srcW = 256 / Math.pow(2, zsteps);
105-
var srcH = 256 / Math.pow(2, zsteps);
101+
// tile scaling
102+
var srcX = (256 / Math.pow(2, zsteps) * (canvasData.x % Math.pow(2, zsteps))) |0,
103+
srcY = (256 / Math.pow(2, zsteps) * (canvasData.y % Math.pow(2, zsteps))) |0,
104+
srcW = (256 / Math.pow(2, zsteps)) |0,
105+
srcH = (256 / Math.pow(2, zsteps)) |0;
106106

107-
ctx.clearRect(0, 0, 256, 256);
108107
ctx.drawImage(image, srcX, srcY, srcW, srcH, 0, 0, 256, 256);
109108
}
110-
111109
var I = ctx.getImageData(0, 0, canvas.width, canvas.height);
112-
this.filterCanvasImgdata(I.data, canvas.width, canvas.height, z);
110+
this.filterCanvasImgdata(I.data, canvas.width, canvas.height, canvasData.z);
113111
ctx.putImageData(I, 0, 0);
114112
},
115113

app/assets/javascripts/abstract/layer/CartoDbCanvasLayerClass.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
define([
2-
'moment',
2+
'moment', 'handlebars',
33
'abstract/layer/CanvasLayerClass', 'helpers/canvasCartoCSSHelper',
44
'map/services/CartoDbLayerService',
55
'text!map/queries/default_cartodb_canvas.sql.hbs'
66
], function(
7-
moment,
7+
moment, Handlebars,
88
CanvasLayerClass, canvasCartoCSSHelper,
99
CartoDbLayerService,
1010
SQL
@@ -47,7 +47,7 @@ define([
4747
_getSQL: function() {
4848
var template = Handlebars.compile(SQL),
4949
sql = template({
50-
table: 'umd_alerts_agg'
50+
table: 'umd_alerts_agg_rast'
5151
});
5252

5353
return sql;

app/assets/javascripts/abstract/layer/ImageLayerClass.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
define([
77
'underscore',
88
'uri',
9-
'abstract/layer/OverlayLayerClass'
9+
'abstract/layer/OverlayLayerClass',
1010
], function(_, UriTemplate, OverlayLayerClass) {
1111

1212
'use strict';
@@ -19,6 +19,7 @@ define([
1919

2020
init: function(layer, options, map) {
2121
this.tiles = {};
22+
this.layer_slug = layer.slug;
2223
this._super(layer, options, map);
2324
},
2425

@@ -30,7 +31,7 @@ define([
3031

3132
_getParams: function() {
3233
var params = {};
33-
if (window.location.search.contains('&hresolution=') && window.location.search.indexOf('=', window.location.search.indexOf('&hresolution=') + 13) !== -1) {
34+
if (window.location.search.contains('hresolution=') && window.location.search.indexOf('=', window.location.search.indexOf('hresolution=') + 11) !== -1) {
3435
var params_new_url = {};
3536
var parts = location.search.substring(1).split('&');
3637
for (var i = 0; i < parts.length; i++) {
@@ -62,6 +63,10 @@ define([
6263
* @return {div} div Tile div
6364
*/
6465
getTile: function(coord, zoom, ownerDocument) {
66+
var zoomLT7 = (zoom < 7);
67+
if(zoomLT7) {
68+
if (this.layer_slug == 'urthe') {return;}
69+
}
6570
var zsteps = this._getZoomSteps(zoom);
6671

6772
var url = this._getUrl.apply(this,
@@ -104,7 +109,6 @@ define([
104109
},
105110

106111
_getUrl: function(x, y, z, params) {
107-
108112
return new UriTemplate(this.options.urlTemplate).fillFromObject({
109113
x: x,
110114
y: y,

app/assets/javascripts/abstract/layer/OverlayLayerClass.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
define([
77
'Class',
88
'underscore',
9+
'mps',
910
'map/views/layers/CustomInfowindow'
10-
], function(Class, _, CustomInfowindow) {
11+
], function(Class, _, mps, CustomInfowindow) {
1112

1213
'use strict';
1314

@@ -26,6 +27,13 @@ define([
2627
this.name = layer.slug;
2728
this.tileSize = new google.maps.Size(256, 256);
2829
this.options = _.extend({}, this.defaults, this.options || {});
30+
this.setListeners();
31+
},
32+
33+
setListeners: function() {
34+
mps.subscribe('Infowindow/close', _.bind(function(){
35+
this.removeMultipolygon();
36+
}, this ))
2937
},
3038

3139
addLayer: function(position, success) {
@@ -34,6 +42,10 @@ define([
3442
if (this.options.infowindow && this.options.interactivity) {
3543
this.setInfowindow(layer);
3644
}
45+
if (!!this.options.infowindowImagelayer) {
46+
this.addClick();
47+
}
48+
3749
success();
3850
}, this));
3951

@@ -42,6 +54,7 @@ define([
4254
removeLayer: function() {
4355
var overlayIndex = this._getOverlayIndex();
4456
this.removeInfowindow();
57+
this.removeMultipolygon();
4558
if (overlayIndex > -1) {
4659
google.maps.event.clearListeners(this.map, 'click');
4760
this.map.overlayMapTypes.setAt(overlayIndex, null);
@@ -86,6 +99,12 @@ define([
8699
}
87100
},
88101

102+
removeMultipolygon: function() {
103+
if (!!this.multipolygon) {
104+
this.map.data.remove(this.multipolygon);
105+
}
106+
},
107+
89108
_getOverlayIndex: function() {
90109
var index = -1;
91110

app/assets/javascripts/abstract/layer/WMSLayerClass.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,16 @@ define([
147147
var infoWindowOptions = {
148148
offset: [0, 100],
149149
infowindowData: {
150-
name: data.features[0].attributes['tis.nombre'],
151-
country: data.features[0].attributes['tis.pais'],
152-
status: data.features[0].attributes['tis.leyenda'],
150+
name: data.features[0].attributes['tis.nombre']|| data.features[0].attributes['nombre'],
151+
country: data.features[0].attributes['tis.pais']|| data.features[0].attributes['pais'],
152+
status: data.features[0].attributes['tis.leyenda']|| data.features[0].attributes['situacion'],
153153
date_create: data.features[0].attributes['tis.fecha_norma'],
154-
area_ha: data.features[0].attributes['tis.area_oficial_ha'].toLocaleString(),
154+
area_ha: data.features[0].attributes['tis.area_oficial_ha']|| data.features[0].attributes['area_oficial_ha'],
155155
category:data.features[0].attributes['tis.categoria'],
156156
source: data.features[0].attributes['tis.fuente'],
157+
company: data.features[0].attributes['cia'],
158+
substance: data.features[0].attributes['tipo_minerio'],
159+
157160
}
158161
}
159162
this.infowindow = new CustomInfowindow(this.location.latlng, this.map, infoWindowOptions);

app/assets/javascripts/abstract/timeline/TimelineYearClass.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ define([
249249
.tickSize(0)
250250
.tickPadding(0)
251251
.tickFormat(_.bind(function(d) {
252-
return (d == 2000 && this.name == 'prodes') ? String('1997-2000') : String(d);
253-
// return String(d);
252+
// return (d == 2000 && this.name == 'prodes') ? String('1997-2000') : String(d);
253+
return String(d);
254254
}, this ))
255255

256256
this.svg.append('g')

app/assets/javascripts/connect.js

+13-37
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,21 @@
1-
/**
2-
* Application entry point.
3-
*/
41
require([
5-
'jquery',
6-
'underscore',
7-
'Class',
8-
'backbone',
9-
'handlebars',
10-
'mps',
11-
'views/HeaderView',
12-
'views/FooterView',
13-
'views/SourceMobileFriendlyView',
14-
'views/SourceWindowView',
15-
'views/FeedbackModalView',
16-
'connect/views/UserFormView'
17-
], function($, _, Class, Backbone, Handlebars, mps, HeaderView, FooterView, SourceMobileFriendlyView,SourceWindowView, FeedbackModalView, UserFormView) {
18-
'use strict';
19-
20-
var ConnectPage = Class.extend({
2+
'backbone', 'underscore',
3+
'connect/routers/UserRouter'
4+
], function(Backbone, _, UserRouter) {
215

22-
$el: $('body'),
6+
'use strict';
237

24-
init: function() {
25-
this._initViews();
26-
},
8+
var router = new UserRouter();
9+
Backbone.history.start({pushState: true});
2710

28-
/**
29-
* Initialize Landing Views.
30-
*/
31-
_initViews: function() {
32-
//shared
33-
new HeaderView();
34-
new FooterView();
35-
new SourceMobileFriendlyView();
36-
new SourceWindowView();
37-
new FeedbackModalView();
11+
// Force nav links to navigate, rather than doing a browser page
12+
// reload
13+
$('#user-profile-nav').on('click', 'a', function(event) {
14+
event.preventDefault();
15+
var root = location.protocol + '//' + location.host + '/',
16+
href = _.last($(this).prop('href').split(root));
3817

39-
new UserFormView();
40-
}
18+
router.navigate(href, {trigger: true});
4119
});
4220

43-
new ConnectPage();
44-
4521
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
define([
2+
'backbone',
3+
'connect/models/Subscription'
4+
], function(Backbone, Subscription) {
5+
6+
'use strict';
7+
8+
var Subscriptions = Backbone.Collection.extend({
9+
model: Subscription,
10+
11+
url: window.gfw.config.GFW_API_HOST + '/v2/subscriptions',
12+
13+
sync: function(method, model, options) {
14+
options || (options = {});
15+
16+
if (!options.crossDomain) {
17+
options.crossDomain = true;
18+
}
19+
20+
if (!options.xhrFields) {
21+
options.xhrFields = {withCredentials:true};
22+
}
23+
24+
return Backbone.sync.call(this, method, model, options);
25+
}
26+
});
27+
28+
return Subscriptions;
29+
30+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
define([
2+
'backbone'
3+
], function(Backbone) {
4+
5+
'use strict';
6+
7+
var Subscription = Backbone.Model.extend({
8+
idAttribute: 'key',
9+
10+
sync: function(method, model, options) {
11+
options || (options = {});
12+
13+
if (!options.crossDomain) {
14+
options.crossDomain = true;
15+
}
16+
17+
if (!options.xhrFields) {
18+
options.xhrFields = {withCredentials:true};
19+
}
20+
21+
return Backbone.sync.call(this, method, model, options);
22+
}
23+
});
24+
25+
return Subscription;
26+
27+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
define([
2+
'jquery', 'backbone', 'underscore',
3+
'map/models/UserModel',
4+
'connect/views/UserFormView',
5+
'connect/views/SubscriptionListView'
6+
], function($, Backbone, _, User, UserFormView, SubscriptionListView) {
7+
8+
'use strict';
9+
10+
var UserRouter = Backbone.Router.extend({
11+
12+
el: $('#profile'),
13+
14+
routes: {
15+
'*path': 'showView'
16+
},
17+
18+
initialize: function() {
19+
this.checkLoggedIn();
20+
this.setupNavbar();
21+
},
22+
23+
checkLoggedIn: function() {
24+
this.user = new User();
25+
this.user.fetch().fail(function() {
26+
location.href = '/';
27+
});
28+
},
29+
30+
setupNavbar: function() {
31+
// Force nav links to navigate, rather than doing a browser page
32+
// reload
33+
var context = this;
34+
$('#user-profile-nav').on('click', 'a', function(event) {
35+
event.preventDefault();
36+
var root = location.protocol + '//' + location.host + '/',
37+
href = _.last($(this).prop('href').split(root));
38+
39+
context.navigate(href, {trigger: true});
40+
});
41+
},
42+
43+
availableViews: {
44+
'my_gfw': UserFormView,
45+
'subscriptions': SubscriptionListView
46+
},
47+
48+
showView: function(routeName) {
49+
var viewName = _.last(_.compact(routeName.split('/')));
50+
51+
this.subViews = this.subViews || {};
52+
if (this.subViews[viewName] === undefined) {
53+
var View = this.availableViews[viewName];
54+
if (View === undefined) { return; }
55+
56+
this.subViews[viewName] = new View();
57+
this.subViews[viewName].render();
58+
}
59+
60+
this.el.html(this.subViews[viewName].el);
61+
this.subViews[viewName].delegateEvents();
62+
}
63+
64+
});
65+
66+
return UserRouter;
67+
68+
});

0 commit comments

Comments
 (0)