Created
May 30, 2017 15:51
-
-
Save alasarr/3e8068af4ce9e37fb02dfd48fe243c07 to your computer and use it in GitHub Desktop.
Infowindow CARTO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="cartodb-popup v2"> | |
<a href="#close" class="cartodb-popup-close-button close">x</a> | |
<div class="cartodb-popup-content-wrapper"> | |
<div class="cartodb-popup-content"> | |
<% if (data.terrunit!='no_unit') { %> | |
<h4><%= data.terrunit=='delegaciones' ? Utils.tr('Delegación') : Utils.tr('Colonia') %></h4> | |
<p><%= data.name %><p> | |
<% } %> | |
<h4><%= data.indicator %></h4> | |
<p class="big"><%= Utils.nbf(data.do_value,{decimals: 0}) %></p> | |
<% for (let o of data.data_values) { | |
for (let i in o){ %> | |
<h4><%= map[i] %></h4> | |
<p><%= Utils.nbf(o[i],{decimals: 0}) %></p> | |
<% } | |
} %> | |
</div> | |
</div> | |
<div class="cartodb-popup-tip-container"></div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var popupTemplate = require('./template.html'); | |
cdb.vis.Vis.addInfowindow(App.mapView.getNativeMap(), sublayer, ['do_value','data_values','name','terrunit'], | |
{sanitizeTemplate:false}).model.set({ | |
template : o => { | |
o = Object.assign({ | |
data_values: '[]', | |
do_value: null, | |
name: null | |
},o) | |
o.data_values = JSON.parse(o.data_values); | |
o.indicator = this.model.get('name'); | |
return popupTemplate({data: o, Utils: Utils, map: map}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example shows how to create an InfoWindow using Underscore template.
We need to use a function Utils.nbf. This function formats the number based on users' locale configuration. For example:
// locale en_ES
Utils.nbf(1000.89) = 1.000,89
// locale en_EN
Utils.nbf(1000.89) = 1,000.89
Utils.tr translates an string to the language of the user (If the language it's supported)