A little new to javascript maps/Gmap3... I am trying to show markers on a map one by one using google map DROP animation. The animation is working fine. Here is my JS
var ll = [];
var JSONData;
var pathData = [];
var tick = 10;
$(document).ready(function() {
$('#ctl00_ContentPlaceHolder1_rewind').button();
$('#ctl00_ContentPlaceHolder1_play').button();
$('#ctl00_ContentPlaceHolder1_stop').button();
$('#ctl00_ContentPlaceHolder1_forward').button();
});
function pageLoad(sender, args) {
$('#ctl00_ContentPlaceHolder1_rewind').button();
$('#ctl00_ContentPlaceHolder1_play').button();
$('#ctl00_ContentPlaceHolder1_stop').button();
$('#ctl00_ContentPlaceHolder1_forward').button();
}
function showEmptyMap() {
$('#mapDiv').gmap3({
map: {
options: {
mapTypeId: google.maps.MapTypeId.TERRAIN,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
scrollwheel: true,
streetViewControl: true
}
},
clear: {}
});
$('#mapDiv').gmap3();
}
function designMap(JSONData) {
for (var i = 0; i < JSONData.length; i++) {
// ll[i] = '{latLng:\'[' + data[i].lastlatitude + ',' + data[i].lastlongitude + ']\',data:\'' + data[i].lastaddress + '\'}';
ll[i] = { latLng: [JSONData[i].latitude, JSONData[i].longitude], data: JSONData[i].data, options: { icon: JSONData[i].iconImage} };
pathData[i] = [JSONData[i].latitude, JSONData[i].longitude];
}
$('#mapDiv').gmap3({ clear: {} });
$('#mapDiv').gmap3({
map: {
options: {
mapTypeId: google.maps.MapTypeId.TERRAIN,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
scrollwheel: true,
streetViewControl: true
}
},
polyline: {
options: {
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2,
path: [pathData]
}
},
autofit: {}
});
plotPoint(JSONData);
}
function plotPoint(JSONPassed) {
for (var k = JSONPassed.length - 1; k >= 0; k--) {
var m = new google.maps.LatLng(JSONPassed[k].latitude, JSONPassed[k].longitude);
(function(n) {
var image = JSONPassed[k].iconImage;
var HTML = JSONPassed[k].data;
setTimeout(function() {
alert(image);
addMarker(n, image,HTML);
}, k * 500);
} (m));
}
}
function addMarker(m, image,data) {
var map = $('#mapDiv').gmap3('get');
var marker = new google.maps.Marker({
position: m,
map: map,
draggable: false,
animation: google.maps.Animation.DROP,
icon: image,
clickable: true
});
marker.info = new google.maps.InfoWindow({
content: data
});
google.maps.event.addListener(marker, 'click', function() {
marker.info.open(map, marker);
});
}
I want to create a pause button on which the map animation should stop and on clicking it again it should resume. How should i proceed.??? :(
I tried setting the interval to a huge value but it didnt work as expected... :(
Okey, I managed to program it.. I made own code so it could be simpler to use/understand also by other users: try copypasting this code into new file and test it with your browser:
But basically what I did is to generate actual positions in different method than where animating is taking place and also use values such as
animatedMarkers = 0;
to keep reference how many number of markers we are added and continue execution based on that when we have paused between. I also added markers to array so it benefits you in many ways when you later start adding more functionality top of them. Cheers.