获取我在 mapbox 中点击的标记的样式

get the style of the marker I clicked on in mapbox

我正在尝试获取我单击的图标的样式,以便获取其翻译值。 我这样做是因为我想创建一个 div,它在地图上的位置与点击的图标相同。 到目前为止,这是我的网站: http://www.david-halfon.com/radio/index.html

基本上,每次有人按下黄色圆圈时,它周围应该会出现一个div。

这是单击图标时发生的事件的代码:

locale.on('click', function(e) {
    $("#music").attr("src", prop.Url);
    $(".player").show();
    play();
    sendWithAjax(prop.Country, prop.City);
    $("h1").html(prop.Station);
    $("h2").html(prop.Country);
    $("h3").html(prop.City);
    //console.log($(this).css("transform"));
    //console.log($(this).attr("style"));

    console.log($(this));

    setTimeout(function(){ $("h4").html(globalVar);}, 500);

    $(".plusB").show();
    $(".shareB").show();

    map1.setView(locale.getLatLng(), 4);
    playNow = prop.Station;
    playNowCountry = prop.Country
    playNowCity = prop.City;

});  

这些评论是我迄今为止尝试过的,但它似乎不起作用。

当我尝试 consloe.log(this) 我得到 'undefined'.

谢谢!!

您没有得到预期的 $(this).css(...) 信息的原因是 this 不是常规的 DOM 对象,因为它使用 Firebug 很明显地出现了:

你想从中获取样式的<img>包含在这个对象的_icon成员中,所以你可以使用例如:

console.log($(this._icon).css('transform'));
console.log($(this._icon).attr('style'));
// and so on

这种方式(在您的网站上使用 Firebug 进行测试)效果很好。

顺便说一句,我不明白为什么点击事件针对这个对象而不是 <img>...

顺便说一句,这个网站是个好主意:酷!