繁体   English   中英

当我逐个删除每个标记时,如何在Google Map V3 Marker上添加自定义动画?

[英]How to add custom animation on Google Map V3 Marker when I drop each marker one by one?

这是我在谷歌地图V3上逐一删除每个标记的简单工作示例。 当标记添加到Google Map时,我设置了Drop Animation。

但我想使用任何Javascript Stuff或其他库自定义Drop with Fade Animation?

谷歌在命名空间中有这个选项我们可以在命名空间中添加自定义动画选项吗?

  • google.maps.Animation.DROP
  • google.maps.Animation.BOUNCE
  • google.maps.Animation.CUSTOM_FADE(有可能吗?)

我的Google地图V3工作代码

<!DOCTYPE html>
<html> 
<head> 
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> 
  <title>Google Maps Multiple Markers</title> 
  <script src="http://maps.google.com/maps/api/js?sensor=false" 
          type="text/javascript"></script>
</head> 
<body>
  <div id="map" style="width: 500px; height: 400px;"></div>

  <script type="text/javascript">
    var locations = [
      ['Bondi Beach', -33.890542, 151.274856, 4],
      ['Coogee Beach', -33.923036, 151.259052, 5],
      ['Cronulla Beach', -34.028249, 151.157507, 3],
      ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
      ['Maroubra Beach', -33.950198, 151.259302, 1]
    ];

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 10,
      center: new google.maps.LatLng(-33.92, 151.25),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    function marker(i) {
        if (i > locations.length) return;

        var marker;

        marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            animation: google.maps.Animation.DROP,
            map: map
            });

        var t=setTimeout("marker("+(i+1)+")",500);
    }
    marker(0);

  </script>
</body>
</html>

这是我走了多远。 Google Maps API在http://maps.gstatic.com/cat_js/intl/en_us/mapfiles/api-3/14/4/%7Bcommon,map,util,marker%7D内部的页面上添加了CSS关键帧代码段.js文件

在页面内部看起来像这样

@-webkit-keyframes _gm2657 {
0 % {
    -webkit-transform: translate3d(0px, 0px, 0); -webkit-animation-timing-function: ease-out;
}
50 % {
    -webkit-transform: translate3d(0px, -20px, 0); -webkit-animation-timing-function: ease-in ;
}
100 % {
    -webkit-transform: translate3d(0px, 0px, 0); -webkit-animation-timing-function: ease-out;
}

}

那里的函数被压缩为

function uJ(a, b) {
var c = [];
c[A]("@-webkit-keyframes ", b, " {\\n");
K(a.b, function (a) {
    c[A](100 * a[$k], "% { ");
    c[A]("-webkit-transform: translate3d(", a[Fv][0], "px,", a[Fv][1], "px,0); ");
    c[A]("-webkit-animation-timing-function: ", a.wa, "; ");
    c[A]("}\\n")
});
c[A]("}\\n");
return c[Mc]("")
}

我现在不能再深入研究如何破解这个对象了。

麻烦的是我不知道他们是如何构建关键帧动画名称的。 我从上面的文件中得到了ad="_gm"+l[B](1E4*l[Qb]()) ,但是好运跟踪那个回到l [B]是什么或者是什么对象1E4 * l等于或如何定义Qb。

我的下一个路线是刮取包含@ -webkit-keyframes _gm的脚本标签的HTML,并查看提取使用的数字,然后使用它来编写自己的关键帧动画,并希望谷歌地图使用您注入的CSS而不是自己的。

沿着这些方向,我写了一个小jQuery方法来搜索所有具有部分匹配“_gm”的样式属性的div。

var poll;
var ntrvl = setInterval(function () {
    poll = $("div[style*=' _gm']");
    if (poll.length > 0) {
        craftNewAnimation(poll.css('-webkit-animation-name'));
        clearInterval(ntrvl);
    }

}, 10);

function craftNewAnimation(name) {
    console.log(name);
    var markup = ['<style>',
        '@-webkit-keyframes ' + name + ' {',
        '0%{ opacity: 0; }',
        '100%{ opacity: 1; }',
        '}',
        '</style'
    ];
    $('body').append(markup.join(""));
}

http://jsbin.com/uJAdaJA/3/edit

由于某种原因,它不会取代它检测到的第一个动画。 并且可能有其他方法可以获得这个神奇的关键帧名称,而不需要那么多黑客攻击。

祝好运。

    var locations = [
      ['Surat', 21.205386, 72.847301, 4],
      ['Mumbai', 19.068789, 72.870265, 5]
    ];

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 7,
      center: new google.maps.LatLng(20.120783, 71.8517917),
      mapTypeId: google.maps.MapTypeId.ROADMAP,

    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map,
        draggable:true,
        animation: google.maps.Animation.DROP,
        animation: google.maps.Animation.BOUNCE,    
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
        var bounds = new google.maps.LatLngBounds();
// in the marker-drawing loop:
bounds.extend(pos);
// after the loop:
map.fitBounds(bounds);

您可以使用Google的丰富标记实用程序 ,它允许您使用html元素作为标记。 现在您可以根据需要为元素提供css动画,例如使用daneden的Animate.css

一个例子:

    var pictureLabel = document.createElement("img");
    pictureLabel.src = YOUR_SOURCE;
    pictureLabel.width = SOME_WIDTH;
    pictureLabel.height = SOME_HEIGHT;
    // daneden even got the exact animation your'e looking for :)
    pictureLabel.className = pictureLabel.className + " animated fadeInDown";

    var marker = new RichMarker({
    position: new google.maps.LatLng(YOUR_LAT, YOUR_LNG),
        map: YOUR_MAP,
        content: pictureLabel
    });

如果您使用谷歌的丰富标记,请不要忘记使用它的点击错误修复!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM