Last active
August 28, 2017 07:42
-
-
Save ramiroaznar/9ceae053bb7ca718802a7d5081c5cefb to your computer and use it in GitHub Desktop.
CARTO.js and Backbone.js simple app
This file contains 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 app = app || {}; | |
/* -- Map View --- */ | |
var MapView = Backbone.View.extend({ | |
el: '#mapView', | |
initialize: function(){ | |
this.query = $('#query').text(); | |
this.style = $('#style').text(); | |
this.map = L.map( | |
'map', | |
{ | |
zoomControl: false, | |
center: [43, 40], | |
zoom: 3 | |
}); | |
this.basemap = L.tileLayer( | |
'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_nolabels/{z}/{x}/{y}.png', | |
{attribution: 'CARTO'} | |
).addTo(this.map); | |
this.render(); | |
}, | |
render: function(){ | |
cartodb.createLayer(this.map, { | |
user_name: 'ramirocartodb', | |
type: 'cartodb', | |
sublayers: [{ | |
sql: this.query, | |
cartocss: this.style | |
}] | |
},{ | |
https: true | |
}) | |
.addTo(this.map); | |
} | |
}); | |
var mapView = new MapView(); |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>CARTO.js and Backbone.js simple app</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> | |
<link rel="shortcut icon" href="https://cartodb.com/assets/favicon.ico" /> | |
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
<style> | |
html, body, #map, #mapView { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<script type="text/cartocss" id="style"> | |
#layer { | |
polygon-opacity: 0.5; | |
polygon-fill: ramp([name], cartocolor(Bold), category(6)); | |
line-width: 2; | |
line-color: ramp([name], cartocolor(Bold), category(6)); | |
line-opacity: 0.4; | |
line-offset: -1; | |
} | |
</script> | |
<script type="text/sql" id="query"> | |
SELECT * FROM continents | |
</script> | |
<div id="mapView"> | |
<div id="map"></div> | |
</div> | |
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment