Stephan Bösch-Plepelits
6 years ago
4 changed files with 109 additions and 3 deletions
@ -0,0 +1,26 @@ |
|||
#### Font Awesome Icons |
|||
Font Awesome 4 is included in OpenStreetBrowser, therefore you can use, e.g.: |
|||
```html |
|||
<i class="fa fa-compass" aria-hidden="true"></i> |
|||
``` |
|||
|
|||
You can use normal CSS to modify its look, e.g. |
|||
```html |
|||
<i style="color: red;" class="fa fa-compass" aria-hidden="true"></i> |
|||
``` |
|||
|
|||
#### Mapbox Maki Icons |
|||
Mapbox Maki Icons 4 are also included in OpenStreetBrowser. They can be accessed as images with protocol 'maki', e.g.: |
|||
```html |
|||
<img src="maki:park"> |
|||
``` |
|||
|
|||
This will include the park-15.svg icon. Mapbox Maki icons come in two sizes: 11 and 15. Default is 15, if you want to use 11 pass the size parameter with value 11: |
|||
```html |
|||
<img src="maki:park?size=11"> |
|||
``` |
|||
|
|||
You can pass SVG options to the icon to modify its look. Note that every icon is a path: |
|||
```html |
|||
<img src="maki:park?size=11&fill=red&stroke=black&stroke-width=0.5"> |
|||
``` |
@ -0,0 +1,57 @@ |
|||
var loadClash = {} |
|||
var cache = {} |
|||
|
|||
function applyOptions (code, options) { |
|||
var style = '' |
|||
|
|||
for (var k in options) { |
|||
if (k !== 'size') { |
|||
style += k + ':' + options[k] + ';' |
|||
} |
|||
} |
|||
|
|||
return code.replace('path d=', 'path style="' + style + '" d=') |
|||
} |
|||
|
|||
function maki (file, options, callback) { |
|||
var id |
|||
var size = options.size || 15 |
|||
|
|||
var m = file.match(/^(.*)\-(11|15)/) |
|||
if (!m) { |
|||
file += '-' + size |
|||
} |
|||
|
|||
var url = (typeof openstreetbrowserPrefix === 'undefined' ? './' : openstreetbrowserPrefix) + |
|||
'node_modules/@mapbox/maki/icons/' + file + '.svg' |
|||
|
|||
if (file in cache) { |
|||
return callback(null, 'data:image/svg+xml;utf8,' + applyOptions(cache[file], options)) |
|||
} |
|||
|
|||
if (file in loadClash) { |
|||
loadClash[file].push([ options, callback ]) |
|||
return |
|||
} else { |
|||
loadClash[file] = [ [ options, callback ] ] |
|||
} |
|||
|
|||
var req = new XMLHttpRequest() |
|||
req.addEventListener('load', function () { |
|||
if (req.status !== 200) { |
|||
loadClash[file].forEach(p => p[1](req.statusText, null)) |
|||
delete loadClash[file] |
|||
return |
|||
} |
|||
|
|||
cache[file] = req.responseText |
|||
|
|||
loadClash[file].forEach(p => p[1](null, 'data:image/svg+xml;utf8,' + applyOptions(cache[file], p[0]))) |
|||
delete loadClash[file] |
|||
return |
|||
}) |
|||
req.open('GET', url) |
|||
req.send() |
|||
} |
|||
|
|||
module.exports = maki |
Write
Preview
Loading…
Cancel
Save
Reference in new issue