Reputation: 1
I am trying to add an icon in place of 'E'. I have searched the documentation of OpenLayers, but I didn't find one. Any advice would be greatly appreciated.
this.map = new Map({
controls: defaultControls({ attribution: false, rotate: false }).extend([
new FullScreen(),
new ZoomToExtent({
extent: zoomToCenter,
label: 'E',
tipLabel: 'Zoom Extent'
})
Upvotes: 0
Views: 339
Reputation: 59
Building off of answers by @barbsan and @Luc Chevallier.
If we want to use, for example, a font-awesome icon for the 'label', we can do like so:
var customLabel = document.createElement("i");
cusomLabel.className = "fas fa-expand"; // font-awesome v6.4.0 free
// include with <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
this.map = new Map({
controls: defaultControls({ attribution: false, rotate: false }).extend([
new FullScreen(),
new ZoomToExtent({
extent: zoomToCenter,
label: customLabel,
tipLabel: 'Zoom Extent'
})
Upvotes: 0
Reputation: 21
I know this is an old question but as I encounter a similar issue I'll try to give a complete answer for future readers.
As @barbsan said, you can pass an HTMLElement to label witch is not a simple string containing some HTML tags but an object that you must either get from the DOM or create like so :
var customLabel = document.createElement('span');
//Do your DOM manip here to add classes or innerHtml
this.map = new Map({
controls: defaultControls({ attribution: false, rotate: false }).extend([
new FullScreen(),
new ZoomToExtent({
extent: zoomToCenter,
label: customLabel,
tipLabel: 'Zoom Extent'
})
})
Upvotes: 2