Skip to content

Instantly share code, notes, and snippets.

@cspanring
Created November 10, 2013 02:18
Show Gist options
  • Select an option

  • Save cspanring/7392812 to your computer and use it in GitHub Desktop.

Select an option

Save cspanring/7392812 to your computer and use it in GitHub Desktop.
Ember CartoDB Leaflet Example
App = Ember.Application.create();
App.IndexView = Ember.View.extend({
cartoDbUser: 'cspanring',
cartoDbSql: 'SELECT * FROM cambridge_neighborhoods',
cartoDbCartoCss: '#cambridge_neighborhoods { \
polygon-fill: yellow; \
polygon-opacity: 0.2; \
line-width: 2; \
line-color: yellow; \
line-opacity: 1; \
}',
didInsertElement: function() {
var view = this,
map = L.map(this.$('#map').get(0)).setView([42.373611, -71.110556], 12);
L.tileLayer('http://{s}.tile.stamen.com/toner-background/{z}/{x}/{y}.png', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
subdomains: 'abcd',
minZoom: 0,
maxZoom: 20
}).addTo(map);
cartodb.Tiles.getTiles({
user_name: view.get('cartoDbUser'),
sublayers: [{
sql: view.get('cartoDbSql'),
cartocss: view.get('cartoDbCartoCss')
}]
}, function(tiles, err) {
if(tiles === null) return;
L.tileLayer(tiles.tiles[0], {
attribution: 'City of Cambridge, MA',
minZoom: 9,
maxZoom: 12
}).addTo(map);
});
}
});
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Testing Ember.js CartoDB integration" />
<meta charset="utf-8">
<title>Ember CartoDB Leaflet Example</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<script type="text/x-handlebars">
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<div id="map"></div>
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/tags/v1.1.2/ember.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.2.07-dev/cartodb.core.uncompressed.js"></script>
<script src="app.js"></script>
</body>
</html>
body {
margin:0;
padding:0;
}
#map {
position:absolute;
top:0;
bottom:0;
width:100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment