-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attribution control #642
Attribution control #642
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
export var AttributionButton = L.Control.extend({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks really clean imo. One suggestion is if it extends Leaflet's Attribution, you can extend Attribution directly and simply overwrite the functions you need changed. export var AttributionButton = L.Attribution.extend({... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't able to get that to work, feel free to make the suggested changes. |
||
options: { | ||
position: 'bottomright', | ||
prefix: '<a href="https://www.w3.org/community/maps4html/">Maps for HTML Community Group</a> <span aria-hidden="true">|</span> <a href="https://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>' | ||
}, | ||
|
||
initialize: function (options) { | ||
L.Util.setOptions(this, options); | ||
this._attributions = {}; | ||
}, | ||
|
||
onAdd: function (map) { | ||
map.attributionControl = this; | ||
this._container = L.DomUtil.create('details', 'leaflet-control-attribution'); | ||
L.DomEvent.disableClickPropagation(this._container); | ||
|
||
for (var i in map._layers) { | ||
if (map._layers[i].getAttribution) { | ||
this.addAttribution(map._layers[i].getAttribution()); | ||
} | ||
} | ||
|
||
this._update(); | ||
|
||
map.on('layeradd', this._addAttribution, this); | ||
|
||
return this._container; | ||
}, | ||
|
||
onRemove: function (map) { | ||
map.off('layeradd', this._addAttribution, this); | ||
}, | ||
|
||
_addAttribution: function (ev) { | ||
if (ev.layer.getAttribution) { | ||
this.addAttribution(ev.layer.getAttribution()); | ||
ev.layer.once('remove', function () { | ||
this.removeAttribution(ev.layer.getAttribution()); | ||
}, this); | ||
} | ||
}, | ||
|
||
setPrefix: function (prefix) { | ||
this.options.prefix = prefix; | ||
this._update(); | ||
return this; | ||
}, | ||
|
||
addAttribution: function (text) { | ||
if (!text) { return this; } | ||
|
||
if (!this._attributions[text]) { | ||
this._attributions[text] = 0; | ||
} | ||
this._attributions[text]++; | ||
|
||
this._update(); | ||
|
||
return this; | ||
}, | ||
|
||
removeAttribution: function (text) { | ||
if (!text) { return this; } | ||
|
||
if (this._attributions[text]) { | ||
this._attributions[text]--; | ||
this._update(); | ||
} | ||
|
||
return this; | ||
}, | ||
|
||
_update: function () { | ||
if (!this._map) { return; } | ||
|
||
var attribs = []; | ||
|
||
for (var i in this._attributions) { | ||
if (this._attributions[i]) { | ||
attribs.push(i); | ||
} | ||
} | ||
|
||
var prefixAndAttribs = []; | ||
|
||
if (this.options.prefix) { | ||
prefixAndAttribs.push(this.options.prefix); | ||
} | ||
if (attribs.length) { | ||
prefixAndAttribs.push(attribs.join(', ')); | ||
} | ||
|
||
this._container.innerHTML = '<summary title="Map data attribution"><svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 0 24 24" width="30px" fill="currentColor"><path d="M0 0h24v24H0z" fill="none"/><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/></svg></summary>' + '<div class="mapml-attribution-container">' + prefixAndAttribs.join(' <span aria-hidden="true">|</span> ') + '</div>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems that this is the only major difference between Leaflet's attribution control code and this version; maybe we could achieve the same effect by accessing the attributionControl._container property and performing this statement? |
||
|
||
} | ||
}); | ||
|
||
L.Map.mergeOptions({ | ||
attributionControl: true | ||
}); | ||
|
||
L.Map.addInitHook(function () { | ||
if (this.options.attributionControl) { | ||
new AttributionButton().addTo(this); | ||
} | ||
}); | ||
|
||
export var attributionButton = function (options) { | ||
return new AttributionButton(options); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,13 +224,12 @@ export class WebMap extends HTMLMapElement { | |
// there is a better configuration than that, but at this moment | ||
// I'm not sure how to approach that issue. | ||
// See https://github.com/Maps4HTML/MapML-Leaflet-Client/issues/24 | ||
fadeAnimation: true | ||
fadeAnimation: true, | ||
attributionControl: false | ||
}); | ||
this._addToHistory(); | ||
// the attribution control is not optional | ||
this._attributionControl = this._map.attributionControl.setPrefix('<a href="https://www.w3.org/community/maps4html/" title="W3C Maps for HTML Community Group">Maps4HTML</a> | <a href="https://leafletjs.com" title="A JS library for interactive maps">Leaflet</a>'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The leaflet object exposes the .getContainer() method to get a handle on their HTML. |
||
this._attributionControl.getContainer().setAttribute("role","group"); | ||
this._attributionControl.getContainer().setAttribute("aria-label","Map data attribution"); | ||
this._attributionControl = M.attributionButton().addTo(this._map); | ||
|
||
this.setControls(false,false,true); | ||
this._crosshair = M.crosshair().addTo(this._map); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may just be a personal preference but the button may fit the overall theme if it's dark on a light background rather than light on a dark background.
Feel free to resolve this conversation if the dark on a light background doesn't fit well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used dark on light initially, but felt better after trying light on dark. I can post screenshots of dark on light too, and we'll decide then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take your word for it, it probably has better contrast being light on dark anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to dark on light in c6420be. I think it is a better default, and once we've enabled customization (using CSS Parts or Custom properties) the theme color can easily be changed by developers.