如何在传单中使用可怕的图标库

时间:2019-06-17 06:08:55

标签: javascript leaflet markers

我正在尝试将精美的图标库与传单一起使用。我包括了这些库以及如下所示的引导程序:

<link rel="stylesheet" href="~/lib/leaflet/leaflet.css" />
<link rel="stylesheet" href="~/lib/Leaflet.awesome-markers/leaflet.awesome- 
markers.css" />
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font- 
awesome.css" rel="stylesheet">
<link 
 href="http://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" 
rel="stylesheet">
<script src="~/lib/leaflet/leaflet.js"></script>
<script src="~/lib/Leaflet.awesome-markers/leaflet.awesome-markers.js"> 
</script>


var mymap = L.map('Lmap').setView([41.607116, 2.286993], 10);

L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    maxZoom: 18,
    fadeAnimation: false,
    zoomAnimation: false,
    markerZoomAnimation: false,
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
}).addTo(mymap);


var redMarker = L.AwesomeMarkers.icon({
    icon: 'coffee',
    markerColor: 'red'
});

var yellowMarker = L.AwesomeMarkers.icon({
    icon: 'star',
    markerColor: 'orange'
});

var greenMarker = L.AwesomeMarkers.icon({
    icon: 'spinner',
    markerColor: 'green'
});

    var markers = [
    L.marker([41.349412, 2.151421], {
        title: 'Martainer',
        id: '1',
        icon: redMarker
    }).addTo(mymap).bindPopup('<b>Localización: </b> Martainer' + '<br /><b>Tipo: </b> Contador de ejes'),
    L.marker([41.580323, 2.285579], {
        title: 'Granollers',
        id: '5',
        icon: greenMarker
    }).addTo(mymap).bindPopup('<b>Localización: </b> Granollers' + '<br /><b>Tipo: </b> Contador de ejes'),
    L.marker([42.858531, -2.682275], {
        title: 'Vitoria',
        id: '7',
        icon: yellowMarker
    }).addTo(mymap).bindPopup('<b>Localización: </b> Vitoria' + '<br /><b>Tipo: </b> Contador de ejes')
]

我的问题是我只看到一些图标,例如房屋或开始... 我希望看到所有据说可以使用的图标。为什么我不能使用例如火车?我该怎么做?我应该将这些图标下载到我的项目中吗? 我正在按照以下步骤操作: https://github.com/sigma-geosistemas/Leaflet.awesome-markers 谢谢

1 个答案:

答案 0 :(得分:2)

尝试将属性prefix添加为fa

注意prefix默认为glyphicon

var mymap = L.map('Lmap').setView([41.607116, 2.286993], 10);

L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  maxZoom: 18,
  fadeAnimation: false,
  zoomAnimation: false,
  markerZoomAnimation: false,
  attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
}).addTo(mymap);


var redMarker = L.AwesomeMarkers.icon({
  icon: 'coffee',
  markerColor: 'red',
  prefix: 'fa'
});

var yellowMarker = L.AwesomeMarkers.icon({
  icon: 'train',
  markerColor: 'orange',
  prefix: 'fa'
});

var greenMarker = L.AwesomeMarkers.icon({
  icon: 'spinner',
  markerColor: 'green',
  prefix: 'fa',
  spin: true
});

var markers = [
  L.marker([41.349412, 2.151421], {
    title: 'Martainer',
    id: '1',
    icon: redMarker
  }).addTo(mymap).bindPopup('<b>Localización: </b> Martainer' + '<br /><b>Tipo: </b> Contador de ejes'),
  L.marker([41.580323, 2.285579], {
    title: 'Granollers',
    id: '5',
    icon: greenMarker
  }).addTo(mymap).bindPopup('<b>Localización: </b> Granollers' + '<br /><b>Tipo: </b> Contador de ejes'),
  L.marker([42.858531, -2.682275], {
    title: 'Vitoria',
    id: '7',
    icon: yellowMarker
  }).addTo(mymap).bindPopup('<b>Localización: </b> Vitoria' + '<br /><b>Tipo: </b> Contador de ejes')
]
#Lmap {
  position: absolute;
  top: 35px;
  left: 0;
  width: 100%;
  height: 80%
}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.min.js"></script>

<div id="Lmap"></div>