Skip to content

Instantly share code, notes, and snippets.

@hampelm
Created April 23, 2015 15:17
Show Gist options
  • Select an option

  • Save hampelm/29b3437c96954718ab30 to your computer and use it in GitHub Desktop.

Select an option

Save hampelm/29b3437c96954718ab30 to your computer and use it in GitHub Desktop.
Display tiles from features table
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/app.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
</head>
<body>
<h1>Hello, world!</h1>
<div id="hover"></div>
<div id="map"></div>
<script type="text/template" id="styles">
Map { background-color: rgba(0,0,0,0); }
#localdata {
[GEOMETRY = LineString] {
line-width: 2;
[zoom >= 15] {
line-width: 5;
}
[zoom >= 16] {
line-width: 7;
}
[zoom >= 18] {
line-width: 9;
}
line-color: <%= color %>;
line-opacity: 1;
}
[GEOMETRY = Polygon],[GEOMETRY = MultiPolygon] {
[zoom >= 14] {
line-color: <%= color %>;
line-width:0.5;
line-opacity:0.5;
}
polygon-fill: <%= color %>;
polygon-opacity:0.85;
}
[GEOMETRY=Point] {
marker-line-width: 1;
marker-width: <% if (pointSize !== undefined) { %> <%= pointSize * 2 / 3%> <% } else { %> 12 <% }%>;
[zoom >= 16] {
marker-line-width: 2;
marker-width: <% if (pointSize !== undefined) { %> <%= pointSize %> <% } else { %> 18 <% }%>;
}
marker-type: ellipse;
marker-line-color: <%= color %>;
marker-fill: <%= color %>;
marker-fill-opacity: 0.9;
marker-line-opacity: 1;
}
}
</script>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.5.0/lodash.js"></script>
<script src="js/leaflet.utfgrid.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
/*globals L, cartodb: true */
$(function(){
var map = L.map('map').setView([42.42, -83.02 ], 16);
var baseLayer = L.tileLayer('http://a.tiles.mapbox.com/v3/matth.map-zmpggdzn/{z}/{x}/{y}.png');
map.addLayer(baseLayer);
// var featureLayer = L.tileLayer('http://localhost:3001/features/tiles/{z}/{x}/{y}.png');
// map.addLayer(featureLayer);
var styles = $('#styles').html();
var template = _.template(styles);
var layerDef = {
query: {
type: 'parcels'
},
select: {},
styles: template({
color: '#6e6663',
pointSize: 18
})
};
$.ajax({
url: 'https://localhost:4334/features/tile.json',
type: 'POST',
dataType: 'json',
cache: false,
contentType: 'application/json',
data: JSON.stringify(layerDef)
}).done(function(data) {
console.log("Got posted feature data", data);
var featureLayer = L.tileLayer('https:' + data.tiles[0]);
map.addLayer(featureLayer);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment