I need to use a GeoJSON Layer on my Leaflet map. Here is a sample of my code:

function onEachFeature(feature, layer) {
    if (feature.properties && feature.properties.popupContent) {

myGeoJsonLayer = L.geoJson(data, {
    pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, geojsonMarkerOptions);
    onEachFeature: onEachFeature
TOC.addOverlay(myGeoJsonLayer, "My GeoJSON Layer");

All is working.

Now I'd like to add an attribution on my layer but how?


1 Answer 1


Copied from the answer on Stack Overflow here: https://stackoverflow.com/questions/25664516/leaflet-how-to-add-an-attribution-on-a-geojson-layer


By default this isn't supported, but you can tack a getAttribution() method on an instance like so: http://bl.ocks.org/tmcw/05c7d1164a9e62e67e6d

The example js code provided is:

L.mapbox.accessToken = 'pk.eyJ1IjoidG1jdyIsImEiOiJIZmRUQjRBIn0.lRARalfaGHnPdRcc-7QZYQ';
var map = L.mapbox.map('map', 'examples.map-i86nkdio').setView([40, -74.50], 9);
var gj = L.geoJson();
gj.getAttribution = function() { return 'foo bar'; };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.