1

Continuing the issue opened here:

Link to another URL permalink in Leaflet

I found some code, that may help me to establish a link to another url permalink from the leaflet map:

https://raw.githubusercontent.com/MapBBCode/mapbbcode/master/src/controls/PermalinkAttribution.js

The library is the "PermalinkAttribution". Inside this file important is:

 for (var i in this._attributions) {
        if (this._attributions[i]) {
            // make permalink for openstreetmap
            if( i.indexOf('/openstreetmap.org') > 0 || 
 i.indexOf('/www.openstreetmap.org') > 0 ) {
                var permalink = 'http://www.openstreetmap.org/#map= 
 {zoom}/{lat}/{lon}';
                i = i.replace(/(['"])http[^'"]+openstreetmap.org[^'"]* 
  (['"])/, '$1' + permalink + '$2');
                if( this._map.options.attributionEditLink ) {
                    var editlink = permalink.replace('#', 'edit#');
                    i = i.replace(/(openstreetmap.org[^'"]*(['"])[^>]*>[^<]+ 
  <\/a>)/, '$1 (<a href=$2' + editlink + '$2 target=$2osmedit$2>Edit</a>)');
                }
            }
            var latlng = this._map.getCenter();
            i = i.replace(/\{zoom\}/g, this._map.getZoom()).replace(/\ 
  {lat\}/g, L.Util.formatNum(latlng.lat, 4)).replace(/\{lon\}/g, 
  L.Util.formatNum(latlng.lng, 4));
            attribs.push(i);
        }
    }

but so far major problem for me was how to add it on the map.

I tried:

   L.Control.Attribution.extend({}).addTo(map);

   L.Control.PermalinkAttribution{}).addTo(map);

but nothing works.

Console says:

throw new Error('Map container not found.');

and I have no button on my map shown.

Does anyone knows how to attach the permalink attribution to the leaflet map?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.