[Talk-GB] OpenHants - doing something with the Hants CC data in the meantime

Chris Hill osm at raggedred.net
Sat Jun 9 10:54:26 BST 2012


On 09/06/12 00:02, Rob Nickerson wrote:
>
> Fantastic use of the data Nick!
>
> Is there any guides for how to do something similar? I was trying to 
> visualise the Natural England data using Leaflet but failed miserably 
> as the shapefile is too big. Your website appears to load just the bit 
> needed. Would I be able to use some of your code?
>
One way to only display the data for the area you are displaying is to 
use AJAX. Leaflet will give you the bounds of the currently displayed 
area, you can get this whenever the map is scrolled or zoomed (with an 
event) and fire off an ajax request for the data for that area. Your 
ajax request needs to be responded to by something, such as PHP, CGI, 
ASP or whatever, that can look up the data for that area, wrap it up in 
a useful form and send it to the browser to redraw that area. I use JSON 
since the JavaScript in your browser handles this well. For vectors it 
is useful to use GeoJSON - Leaflet handles this very well.

On the server side I would load the shapefiles into a database - it 
depends what you use on your server - I use MySQL since my cheap and 
cheerful host provides PHP & MySQL. This all works with both Leaflet and 
OpenLayers - I generally prefer Leaflet.

I wrote blog post [1] [2] about using markers and there is a similar 
piece on Switch 2 OSM [3]. maybe Nick would like to write up his vector 
display too.

[1] http://chris-osm.blogspot.co.uk/2011/05/leaflet.html
[2] http://chris-osm.blogspot.co.uk/2012/03/more-gb-postcode-goodness.html
[3] http://switch2osm.org/using-tiles/getting-started-with-leaflet/

-- 
Cheers, Chris
user: chillly




More information about the Talk-GB mailing list