[英]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地圖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.