Skip to content

Instantly share code, notes, and snippets.

@stoolrossa
Created February 2, 2014 11:20
Show Gist options
  • Save stoolrossa/8766821 to your computer and use it in GitHub Desktop.
Save stoolrossa/8766821 to your computer and use it in GitHub Desktop.
Node.js + Express + Leaflet + PostGIS View
%html
%head
%title LeanMap
%script{ type: 'text/javascript', src: 'javascripts/jquery-1.6.2.min.js' }
%script{ type: 'text/javascript', src: 'javascripts/leaflet.js' }
%link{ rel: 'stylesheet', href: 'javascripts/leaflet.css' }
%body
%div{ id: 'mapContainer', style: 'width: 800px; height: 600px;' }
:javascript
var map;
var cadastralLayer;
$(document).ready(function () {
map = new L.Map('mapContainer');
var url = 'http://{s}.tile.cloudmade.com/YOUR-API-KEY/997/256/{z}/{x}/{y}.png';
var copyright = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade';
var tileLayer = new L.TileLayer(url, {maxZoom: 20, attribution: copyright});
var startPosition = new L.LatLng(-27.43247,153.065654);
map.on('load', function(e) {
requestUpdatedCadastre(e.target.getBounds());
});
map.setView(startPosition, 19).addLayer(tileLayer);
map.on('moveend', function(e) {
requestUpdatedCadastre(e.target.getBounds());
});
});
function requestUpdatedCadastre(bounds) {
$.ajax(
{
type: 'POST',
url: '/RetrieveCadastre',
dataType: 'json',
data: JSON.stringify(bounds),
contentType: 'application/json; charset=utf-8',
success: function (result) {
parseResponseCadastre(result)
},
error: function (req, status, error) {
alert('Unable to get cadastral data');
}
});
}
function parseResponseCadastre(data) {
if (cadastralLayer != undefined)
{
map.removeLayer(cadastralLayer);
}
cadastralLayer = new L.GeoJSON();
cadastralLayer.on('featureparse', function(e) {
e.layer.setStyle({ color: '#003300', weight: 2, fill: true, fillColor: '#009933' });
});
cadastralLayer.addGeoJSON(data);
map.addLayer(cadastralLayer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment