如何通过Leaflet在GeoJSON图层上添加归因?


10

我需要在传单地图上使用GeoJSON图层。这是我的代码示例:

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

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

一切正常。

现在,我想在图层上添加归因,但如何?


我在[这里] [1]收到了回复。我已经尝试过,并且工作正常。[1]:stackoverflow.com/questions/25664516/...
切萨雷

您能否将问题标记为已回答?(gis.stackexchange.com/help/self-answer
托马斯乙

Answers:


4

从此处的堆栈溢出的答案中复制:https : //stackoverflow.com/questions/25664516/leaflet-how-to-add-an-attribution-on-a-geojson-layer

引用:

默认情况下不支持此功能,但是您可以在实例上添加getAttribution()方法,如下所示:http : //bl.ocks.org/tmcw/05c7d1164a9e62e67e6d

提供的示例js代码为:

<script>
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'; };
gj.addTo(map);
</script>
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.