Here's an example that I have of loading geojson from a WFS service: http://maps.gcc.tas.gov.au/dogexerciseareas.html
This is another example loading topojson (similar, but different): http://agl.pw/examples/NRM_Regions/map.html
Here's some simple code I use to load a layer:
var myLayer = L.geoJson().addTo(map);
$.getJSON("data/buildings.json", function(json) {
myLayer.addData(json);
});
Then you can do interactivity and styling with something like this:
success : function (response) {
DogExerciseAreas = L.geoJson(response, {
style: function (feature) {
return {
stroke: false,
fillColor: 'FFFFFF',
fillOpacity: 0
};
},
onEachFeature: function (feature, layer) {
popupOptions = {maxWidth: 200};
layer.bindPopup("<b>Site name:</b> " + feature.properties.sitename +
"<br><b>Dog Exercise: </b>" + feature.properties.dog_exercise +
"<br><br>Please ensure that tidy up after your dog. Dogs must be kept under effective control at all times."
,popupOptions);
}
}).addTo(map);
}
EDIT: an example from the leaflet website on styling points (from here http://leafletjs.com/examples/geojson.html):
var geojsonMarkerOptions = {
radius: 8,
fillColor: "#ff7800",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
};
L.geoJson(someGeojsonFeature, {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, geojsonMarkerOptions);
}
}).addTo(map);
EDIT2: Added a solution to this problem. See here: https://gist.github.com/alexgleith/7112515
All you need to do now is edit the bit where it says 'popupContent' to add your bit and change the code to load data from the file.
Finally got an answer on github:
Internally, Leaflet transforms EPSG:4326 coordinates to pixel coordinates. These pixel coordinates are the EPSG:3857 coordinates divided by a power of 2 (and then rounded).
It might be possible to fetch some of these coordinates (look at methods like L.Map.latLngToLayerPoint
) and then multiply stuff given the zoom level, but beware of rounding errors.
So my assumption EPSG:3857 is the default was wrong.
Best Answer
Leaflet expects GeoJSON to be in EPSG:4326. In fact, the entire API uses 4326 (lat/lng), so you are good to go without any reprojection.
If you need to reproject GeoJSON, you could look at https://github.com/perliedman/reproject.