Skip to content

Instantly share code, notes, and snippets.

@edouard-lopez
Last active August 29, 2015 14:03
Show Gist options
  • Save edouard-lopez/5223435b5d5a04d7d6e0 to your computer and use it in GitHub Desktop.
Save edouard-lopez/5223435b5d5a04d7d6e0 to your computer and use it in GitHub Desktop.
PAV dataviz
'use strict';
// Your source tile layer extent, expressed in local projection
var bbox = [700000, 6325197, 1060000, 6617738];
// Maximum resolution in meters per pixel (largest area side / tile size).
var maxResolution = 1406.25;
// Scale for each level
var scale = function(zoom) {
return 1 / (maxResolution / Math.pow(2, zoom));
};
// Coordinate to grid transformation matrix
var transformation = new L.Transformation(1, -bbox[0], -1, bbox[3]);
// Official Spatial Reference from http://www.spatialreference.org/ref/epsg/2154/
var crs = L.CRS.proj4js('EPSG:2154',
'+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs',
transformation);
crs.scale = scale; // required by Leaflet 0.4
var map = L.map('map', {
crs: crs,
scale: scale,
center: new L.LatLng(44.8442, -0.5933), // Universal Lat/Lng
zoom: 1,
minZoom: 0,
maxZoom: 18,
attribution: '© <a href="http://metadata.lacub.fr/geosource/apps/search/?uuid=1f8a4be0-900e-4eab-9dcf-55cd9f0a1aed">La CUB</a>'
});
// // Location of tiles (see next paragraph)
new L.tileLayer(
// 'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png',
'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
{
id: 'edouard-lopez.ik52o4kd',
continuousWorld: true, // very important
}
).addTo(map);
d3.json('scripts/emplacements-pav.geo.json', function (geojson) {
var geojson = {
"type": "Feature",
"properties": {
"name": "Coors Field",
"amenity": "Baseball Stadium",
"popupContent": "This is where the Rockies play!"
},
"geometry": {
"type": "Point",
"coordinates": [-0.5933, 44.8442],
}
};
console.log(geojson);
L.Proj.geoJson(geojson).addTo(map);
// L.geoJson(geojson).addTo(map);
});
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@edouard-lopez
Copy link
Author

I ended preprocessing the data to convert them to WSG84 projection:

ogr2ogr -f GeoJSON \
    -t_srs EPSG:4326 \
    -lco COORDINATE_PRECISION=2 \
    -select "GID, IDENT, MDATE"  \
output.geo.json input.shp

I recommend too read this –french– article: Convertir un shapefile en GeoJSON pour Leaflet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment