项目作者: makana

项目描述 :
Small library to use FontAwesome 5 SVG icons as Leaflet markers.
高级语言: TypeScript
项目地址: git://github.com/makana/leaflet-fontawesome.git
创建时间: 2020-06-06T13:15:47Z
项目社区:https://github.com/makana/leaflet-fontawesome

开源协议:MIT License

下载


leaflet-fontawesome

Small library to use FontAwesome 5 SVG icons as Leaflet markers.

Screenshot

Usage

  1. import { library } from '@fortawesome/fontawesome-svg-core';
  2. import { faMapMarker, faTrain, faTheaterMasks, faSquare, faLandmark, faWater, faMapMarkerAlt } from '@fortawesome/free-solid-svg-icons';
  3. import { faIcon, faLayer, faMarker, defaults } from 'leaflet-fontawesome';
  4. // add the default marker to the library!
  5. library.add(faMapMarker);
  6. // or add it as default
  7. defaults({
  8. marker: faMapMarker,
  9. markerColor: 'chocolate',
  10. });
  11. // Create a simple colored marker with inverted symbol
  12. L.marker(latLng, {
  13. icon: faMarker(faTrain),
  14. }).addTo(map);
  15. // Create a colored marker with custom options
  16. L.marker(latLng, {
  17. icon: faMarker({
  18. icon: faTheaterMasks,
  19. markerColor: 'darkgreen',
  20. }),
  21. }).addTo(map);
  22. // Create a layered icon with text
  23. L.marker(latLng, {
  24. icon: faLayer({
  25. iconSize: [24, 24],
  26. layers: [
  27. {
  28. icon: faSquare,
  29. styles: {
  30. color: 'royalblue',
  31. },
  32. },
  33. // Text
  34. {
  35. text: 'P',
  36. styles: {
  37. color: 'white',
  38. 'font-weight': '900',
  39. },
  40. transform: {
  41. size: 12,
  42. },
  43. },
  44. // Counter
  45. {
  46. text: 20,
  47. position: 'top-right',
  48. },
  49. ],
  50. }),
  51. }).addTo(map);
  52. // Create a custom icon
  53. L.marker(latLng, {
  54. icon: faIcon({
  55. iconSize: [32, 32],
  56. icon: faLandmark,
  57. styles: {
  58. color: 'purple',
  59. },
  60. }),
  61. }).addTo(map);
  62. // Create a marker with custom options
  63. L.marker(latLng, {
  64. icon: faMarker({
  65. markerColor: 'ivory',
  66. icon: faWater,
  67. styles: {
  68. color: 'dodgerblue'
  69. },
  70. }),
  71. }).addTo(map);
  72. // Create a custom marker without symbol
  73. L.marker(latLng, {
  74. icon: faMarker({
  75. iconSize: [24, 24],
  76. marker: faMapMarkerAlt,
  77. markerColor: 'crimson',
  78. }),
  79. }).addTo(map);
  80. // Create a custom marker
  81. L.marker(latLng, {
  82. icon: faLayer({
  83. iconSize: [32, 32],
  84. iconAnchor: [16, 32],
  85. layers: [
  86. {
  87. icon: faMapMarker,
  88. styles: {
  89. color: 'chocolate',
  90. },
  91. },
  92. {
  93. icon: faTrain,
  94. inverse: true,
  95. transform: {
  96. size: 7,
  97. y: -2,
  98. },
  99. },
  100. ],
  101. }),
  102. }).addTo(map);

Fix CSS

If you are using FontAwesome Layers with text, it will happen that the text is behind the marker.
This is due to CSS from Leaflet that sets the z-index of all SVG elements within the map to 200.
To fix this, include the following CSS into your document.

  1. .leaflet-map-pane .leaflet-fontawesome-icon svg {
  2. z-index: unset;
  3. }