当我将鼠标悬停在标记上时,如何更改某些标记的标记大小

时间:2017-09-04 07:28:02

标签: javascript php google-maps leaflet

我有一些Leaflet标记,我从数据库中解析它,但问题是,当我将鼠标悬停在它上面时,它会改变标记的大小,但是如果我将鼠标悬停在另一个标记上,则大小是相同的...我可不可以做?我是个菜鸟。谢谢!

        function addScoala1(){ 
   var scoala = JSON.parse('<?php echo json_encode($scoala) ?>');
   for(var i=0; i<scoala.length; i++) {
    var greenIcon = new L.Icon({
  iconUrl: 'https://static1.squarespace.com/static/540ed918e4b0daae9995d1d7/54ecab60e4b0feaa477dac5a/54ecab79e4b0c686e92227d7/1424796549381/university.png',
  shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
  iconSize: [35, 40],
  iconAnchor: [12, 41],
  popupAnchor: [1, -34],
  shadowSize: [10, 10]
});
    var marker = L.marker( [scoala[i]['latitudine'], scoala[i]['longitudine']], {icon: greenIcon}).addTo(groupA);
    marker.bindPopup( "<b>" + scoala[i]['scoala']+"</b><br>Detalii:" + scoala[i]['detalii'] + "<br />Telefon: " + scoala[i]['telefon']);
    L.Icon.Big = L.Icon.extend({
    options: {
    iconSize: new L.Point(44, 61),
    iconUrl: 'https://static1.squarespace.com/static/540ed918e4b0daae9995d1d7/54ecab60e4b0feaa477dac5a/54ecab79e4b0c686e92227d7/1424796549381/university.png',
  shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png'
}});

      var bigIcon = new L.Icon.Big();
      groupB.eachLayer(function (layer) {
      marker.on('mouseover', function (e) {
            this.openPopup();
            marker.setIcon(bigIcon);
    });
        marker.on('mouseout', function (e) {
            this.closePopup();
            marker.setIcon(greenIcon);
        });
      });

 }
  }

1 个答案:

答案 0 :(得分:0)

尝试使用resetStyle而不是重置以前的图标。 查看文档以获取详细信息:Leaflet API

 layer.on('mouseout', function (e) {
                this.closePopup();
                 marker.resetStyle(e.target);
                });
            }