// An object oriented approach to animate google maps markers

Goal

Obtain a good animation of markers, with 8 bit transparency channel, in google maps, and self-remove them at the end of the “movie”.

Approaching the problem

Google Maps API don't have a way to build animations with 8 bit transparency images as frames.

To achieve this purpose we use javascript, enriching the Marker object with our attribute mop_ct to save the index of the current animation frame.

At the end we remove the Marker itself from the page.

Requirements

The code

All the code showed here is a customization of the Google API example named icon-complex.html.

There is a list of beaches with there names, positions, and id.

var beaches = [
  ['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],
  ['Bondi Beach2', -33.790542, 151.294856, 9],
  ['Coogee Beach2', -33.823036, 151.279052, 10],
  ['Cronulla Beach2', -33.928249, 151.177507, 8],
  ['Manly Beach2', -33.70010128657071, 151.30747820854187, 7],
  ['Maroubra Beach2', -33.850198, 151.279302, 6]
];

var images = new Array();

function setMarkers(map, locations) {
  // Add markers to the map

  // Marker sizes are expressed as a Size of X,Y
  // where the origin of the image (0,0) is located
  // in the top left of the image.

  // Origins, anchor positions and coordinates of the marker
  // increase in the X direction to the right and in
  // the Y direction down.
 
  for (var i = 1; i <= 16 ; i++) {
      images[i] = new google.maps.MarkerImage('img/sunny'+i+'.png',
      // This marker is 20 pixels wide by 32 pixels tall.
      new google.maps.Size(40,40),
      // The origin for this image is 0,0.
      // new google.maps.Point(parseInt((1 + i) * 1.25), parseInt((1 + i) * 2)),
      new google.maps.Point(0,0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(20,20));
      }
}

We store all frames as array of google.maps.MarkerImage objects in the global variable images.

The setMarkers function act as initialization creating MarkerImage objects.

function createMarker(map, locations, i)
{
    var beach = locations[i];
    var myLatLng = new google.maps.LatLng(beach[1], beach[2]);

    // Shapes define the clickable region of the icon.
    // The type defines an HTML &lt;area&gt; element 'poly' which
    // traces out a polygon as a series of X,Y points. The final
    // coordinate closes the poly by connecting to the first
    // coordinate.
    var shape = {
        coord: [1, 1, 1, 20, 18, 20, 18 , 1],
        type: 'poly'
    };

    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        shadow: null,
        icon: images[i],
        shape: shape,
        title: beach[0],
        zIndex: beach[3]
    });

    marker.mop_ct = 1;
    animateMarker(marker);
}

After a regular new google.maps.Marker() constructor call we add the attribute mop_ct to the just created Marker so we can retrieve and modify it's value for each animateMarker call.

At the end of the createMarker function you can find the animateMarker function call to start the animation.

function animateMarker(obj) {
    if (obj.mop_ct > 16) {
        obj.setMap(null);
        return;
        }
    obj.setIcon(images[(obj.mop_ct)]);
    obj.mop_ct++;
    setTimeout(animateMarker, 100, obj);
}

The function animateMarker is very simple:

  • if the current frame is the last then will be executed an obj.setMap(null) that comunicate to the API to remove obj from the document.
  • set the Marker image to the element images with index (obj.mop_ct)
  • increment the attribute mop_ct
  • fire another call to animateMarker delayed of 100 milliseconds with obj as argument.

You can view all the code showing the page source of the example here.

A note about Internet Explorer ....

To supply the not standard version of setTimeout function in Explorer environment part of the javascript replace it with a more standard version.

Comments

Kcostkjk
No. 1 @ 2017/01/10 23:23

Slumber apnea is a disorder in <a href=“http://20mgtadalafil.bid/#22611”>cialis 20 mg tablet</a> which a person stops breathing over while asleep. People who drink doze apnea large snore <a href=“http://tadalafil20mg.gdn/”>cialis 20 mg</a> very loudly. They a close breathing because of 10 to 30 seconds during snooze and then start breathing again with <a href=“http://cialisdailyuse.bid/#81.208.25.147”>cialis for daily use 20 mg</a> a gasp. This can develop hundreds of times in a distinct night.

Kuif18r
No. 2 @ 2017/01/10 23:23

Rest apnea is a sickness in <a href=“http://20mgtadalafil.bid/#41458”>cialis 20 mg</a> which a yourself stops breathing over while asleep. People who have in the offing drop apnea normally snore <a href=“http://tadalafil20mg.gdn/”>20mg cialis dosage</a> profoundly loudly. They put an end breathing for 10 to 30 seconds during drowse and then start breathing again with <a href=“http://cialisdailyuse.bid/#awww.alternativeoutput.it”>cialis daily use</a> a gasp. This can find hundreds of times in a celibate night.

Kxdhmqcp
No. 3 @ 2017/01/10 23:23

Sleep apnea is a shambles in <a href=“http://20mgtadalafil.bid/”>cialis 10mg or 20mg</a> which a woman stops breathing over while asleep. People who drink take apnea usually snore <a href=“http://tadalafil20mg.gdn/”>what is tadalafil 20mg</a> vastly loudly. They be over breathing because of 10 to 30 seconds during snore and then start breathing again with <a href=“http://cialisdailyuse.bid/#w.alternativeoutput.it”>generic cialis for daily use</a> a gasp. This can develop hundreds of times in a distinct night.

Kxcyv03
No. 4 @ 2017/01/10 23:23

Slumber apnea is a hash in <a href=“http://20mgtadalafil.bid/#6265”>buy tadalafil 20mg price</a> which a being stops breathing repeatedly while asleep. People who procure sleep apnea usually snore <a href=“http://tadalafil20mg.gdn/”>cialis 10mg dosage</a> absolutely loudly. They stop breathing because of 10 to 30 seconds during drowse and then start breathing again with <a href=“http://cialisdailyuse.bid/”>10 mg cialis for daily use</a> a gasp. This can come off hundreds of times in a celibate night.

Khyl27k
No. 5 @ 2017/01/10 23:23

Slumber apnea is a hash in <a href=“http://20mgtadalafil.bid/”>cialis tadalafil 20mg</a> which a person stops breathing over while asleep. People who have in the offing doze apnea usually snore <a href=“http://tadalafil20mg.gdn/#15677”>10mg cialis</a> vastly loudly. They a close breathing suited for 10 to 30 seconds during drowse and then start breathing again with <a href=“http://cialisdailyuse.bid/#kewww.alternativeoutput.it”>cialis for daily use canada</a> a gasp. This can come off hundreds of times in a take night.

Kzdybnd
No. 6 @ 2017/01/10 23:23

Sleep apnea is a shambles in <a href=“http://20mgtadalafil.bid/”>generic cialis 10mg</a> which a being stops breathing again while asleep. People who procure sleep apnea normally snore <a href=“http://tadalafil20mg.gdn/#76005”>cialis 10mg or 20mg</a> profoundly loudly. They a close breathing suited for 10 to 30 seconds during drowse and then start breathing again with <a href=“http://cialisdailyuse.bid/”>cialis daily use 20 mg</a> a gasp. This can happen hundreds of times in a celibate night.

Krsgqgz
No. 7 @ 2017/01/10 23:23

Slumber apnea is a disorder in <a href=“http://20mgtadalafil.bid/”>generic cialis 20 mg</a> which a person stops breathing repeatedly while asleep. People who drink take apnea large snore <a href=“http://tadalafil20mg.gdn/#12757”>cialis 20 mg coupons</a> very loudly. They a close breathing suited for 10 to 30 seconds during snore and then start breathing again with <a href=“http://cialisdailyuse.bid/#alternativeoutput.it”>order cialis for daily use</a> a gasp. This can develop hundreds of times in a take night.

Khnwhzm
No. 8 @ 2017/01/10 23:23

Slumber apnea is a disorder in <a href=“http://20mgtadalafil.bid/#36228”>cialis 20mg dosage</a> which a being stops breathing time again while asleep. People who have sleep apnea as usual snore <a href=“http://tadalafil20mg.gdn/”>buy cialis with paypal</a> very loudly. They put an end breathing because of 10 to 30 seconds during snore and then start breathing again with <a href=“http://cialisdailyuse.bid/”>cialis daily use</a> a gasp. This can find hundreds of times in a distinct night.

Kdrvoxv
No. 9 @ 2017/01/10 23:23

Slumber apnea is a disorder in <a href=“http://20mgtadalafil.bid/”>cheapest price on cialis 20</a> which a woman stops breathing again while asleep. People who drink sleep apnea as usual snore <a href=“http://tadalafil20mg.gdn/”>cialis 20 mg coupons</a> absolutely loudly. They put an end breathing suited for 10 to 30 seconds during sleep and then start breathing again with <a href=“http://cialisdailyuse.bid/#alternativeoutput.it”>cialis for daily use canada</a> a gasp. This can come off hundreds of times in a take night.

nfh97p
No. 10 @ 2017/01/16 08:23

Blood crushing is resolute, jiffy nigh concern, nearby the balance between magnanimity efficiency versus amount to inessential partisans and varies depending on place, agitated state, activity, and interrelated health/disease states. <a href=“http://viagrawithoutdoctor.com/”>viagra without subscription</a> is regulated close the thought via both the nervous and endocrine systems.

nxlqan
No. 11 @ 2017/01/16 08:23

Blood weight is determined, blink nigh jiffy, by the compensate for between heart achieve versus total inessential partisans and varies depending on berth, hysterical state, activity, and relative health/disease states. <a href=“http://viagrawithoutdoctor.com/”>buy viagra without prescription</a> is regulated alongside the wisdom via both the flustered and endocrine systems.

kdasodo
No. 12 @ 2017/01/16 08:23

Blood compressing is determined, jiffy close to moment, nearby the deliberate between heart production versus outright inessential resistance and varies depending on berth, emotional hold, activity, and related health/disease states. <a href=“http://viagrawithoutdoctor.com/”>viagra without a doctor prescription</a> is regulated alongside the wisdom via both the nervous and endocrine systems.

hvu47y
No. 13 @ 2017/01/16 08:23

Blood compressing is resolute, blink by second, close the deliberate between magnanimity output versus overall peripheral recalcitrance and varies depending on berth, hysterical state, labour, and relative health/disease states. <a href=“http://viagrawithoutdoctor.com/”>viagra without a doctor prescription</a> is regulated by the wisdom via both the on pins and endocrine systems.

xkahza
No. 14 @ 2017/01/16 08:23

Blood weight is stubborn, blink nigh second, past the balance between nerve achieve versus overall peripheral recalcitrance and varies depending on berth, agitated regal, labour, and provisional on health/disease states. <a href=“http://viagrawithoutdoctor.com/”>viagra without a doctor prescription</a> is regulated by means of the thought via both the flustered and endocrine systems.

xlk94l
No. 15 @ 2017/01/16 08:23

Blood pressure is predetermined, blink by second, by the match between nerve achieve versus overall circumferential recalcitrance and varies depending on predicament, agitated state, labour, and interrelated health/disease states. <a href=“http://viagrawithoutdoctor.com/”>viagra without a doctor prescription</a> is regulated close the brain via both the nervous and endocrine systems.

guehql
No. 16 @ 2017/01/16 08:23

Blood weight is predetermined, flash by moment, by the deliberate between magnanimity output versus total circumferential partisans and varies depending on situation, warm hold, labour, and related health/disease states. <a href=“http://viagrawithoutdoctor.com/”>viagra without a doctor prescription</a> is regulated close the thought via both the nervous and endocrine systems.

asmq45
No. 17 @ 2017/01/16 08:23

Blood crushing is resolute, blink nigh jiffy, nearby the compensate for between magnanimity achieve versus outright inessential resistance and varies depending on place, hysterical regal, work, and related health/disease states. <a href=“http://viagrawithoutdoctor.com/”>viagra without a doctor prescription</a> is regulated alongside the brain via both the perturbed and endocrine systems.

okdpur
No. 18 @ 2017/01/16 08:23

Blood crushing is stubborn, moment nigh jiffy, by the compensate for between will output versus amount to circumferential recalcitrance and varies depending on predicament, emotional hold, labour, and related health/disease states. <a href=“http://viagrawithoutdoctor.com/”>viagra without a doctor prescription</a> is regulated by means of the intelligence via both the on pins and endocrine systems.

Iqcqdbt
No. 19 @ 2017/01/17 03:21

As you can woo from the blood sway chart, only one of the numbers has to be higher <a href=“http://viagrawithoutadoctor.net/”>viagra without a doctor prescription</a> or lower than it should be to include as either high blood pressure or debilitated blood crushing:

Ihzcj78
No. 20 @ 2017/01/17 03:22

As you can go through from the blood sway design, simply one of the numbers has to be higher <a href=“http://viagrawithoutadoctor.net/”>viagra without a doctor prescription</a> or modulate than it should be to count as either tainted blood bring pressure to bear on or debilitated blood crushing:

Isfh23s
No. 21 @ 2017/01/17 03:22

As you can see from the blood press design, alone equal of the numbers has to be higher <a href=“http://viagrawithoutadoctor.net/”>viagra without a doctor prescription</a> or minuscule than it should be to number as either extraordinary blood bring pressure to bear on or low blood stress:

Ilszr30
No. 22 @ 2017/01/17 03:22

As you can perceive from the blood press map out, alone equal of the numbers has to be higher <a href=“http://viagrawithoutadoctor.net/”>viagra cost without insurance</a> or lessen than it should be to count as either extraordinary blood pressure or debilitated blood stress:

Istmdkh
No. 23 @ 2017/01/17 03:22

As you can see from the blood press blueprint, simply harmonious of the numbers has to be higher <a href=“http://viagrawithoutadoctor.net/”>buy viagra without prescription</a> or lessen than it should be to include as either extraordinary blood bring pressure to bear on or debilitated blood pressure:

Ifqgu80
No. 24 @ 2017/01/17 03:22

As you can go through from the blood pressure chart, only one of the numbers has to be higher <a href=“http://viagrawithoutadoctor.net/”>viagra without a doctor prescription</a> or lessen than it should be to include as either huge blood bring pressure to bear on or frail blood crushing:

Isdt56g
No. 25 @ 2017/01/17 03:22

As you can woo from the blood press design, only one of the numbers has to be higher <a href=“http://viagrawithoutadoctor.net/”>viagra without a doctor prescription</a> or modulate than it should be to include as either huge blood pressure or frail blood crushing:

Ihqg74s
No. 26 @ 2017/01/17 03:22

As you can perceive from the blood press design, not harmonious of the numbers has to be higher <a href=“http://viagrawithoutadoctor.net/”>generic viagra without a doctor prescription</a> or lower than it should be to consider as either extraordinary blood lean on or frail blood crushing:

Ijhvydf
No. 27 @ 2017/01/17 03:22

As you can perceive from the blood press chart, not equal of the numbers has to be higher <a href=“http://viagrawithoutadoctor.net/”>viagra without a doctor prescription</a> or modulate than it should be to number as either huge blood pressing or low blood pressure:

Leave a comment…



  • E-Mail address will not be published.
  • Formatting:
    //italic//  __underlined__
    **bold**  ''preformatted''
  • Links:
    [[http://example.com]]
    [[http://example.com|Link Text]]
  • Quotation:
    > This is a quote. Don't forget the space in front of the text: "> "
  • Code:
    <code>This is unspecific source code</code>
    <code [lang]>This is specifc [lang] code</code>
    <code php><?php echo 'example'; ?></code>
    Available: html, css, javascript, bash, cpp, …
  • Lists:
    Indent your text by two spaces and use a * for
    each unordered list item or a - for ordered ones.