<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="twitter2mapplet"
             description="Twitter of Mapplets"
             author="Yoshiori SHOJI"
             author_email="yoshiori@gmail.com"
             author_location="Tokyo, Japan"
             height="20">
  <Require feature="sharedmap"/>
</ModulePrefs>
<Content type="html"><![CDATA[
Twitter Public Timelines!!
<script>
var twitter2mapplet = {
    map: new GMap2(),
  	geocoder : new GClientGeocoder(),
    sinceId : 0,
    markers : new Array(),
	init : function()
	{
  		this.map.setZoom(2);
	},
    getPublicTimeline: function() 
    {
      _IG_FetchContent('http://twitter.com/statuses/public_timeline.json?since_id='+this.sinceId ,
        function (responseText) {
          var twitterObject = eval(responseText);
          for(var i = 0 ; i < twitterObject.length ; i++ ){
	        twitter2mapplet.showTwit(twitterObject[i]);
          }
        }
      );
      while(this.markers.length > 50){
          this.map.removeOverlay(this.markers.shift());
      }
      setTimeout(function(){twitter2mapplet.getPublicTimeline();} , 10000);
    },
    start : function(){
        this.init();
		this.getPublicTimeline();
    },
	showTwit : function (twitter)
	{
	  this.sinceId = this.sinceId < twitter.id ? twitter.id : this.sinceId;
	  var location = twitter.user.location;
	  this.geocoder.getLatLngAsync(
	    location,
	    function(latlng) {
	      if (latlng) {
			var marker = twitter2mapplet.createMarker(latlng, '<img src='+twitter.user.profile_image_url+'/>' 
																+ '<span style="font-weight : bolder">'
																+ twitter.user.screen_name + '</span>'
																+ '<br/>' + twitter.text );
			twitter2mapplet.markers.push(marker);
	        twitter2mapplet.map.addOverlay(marker);
	      }
	    }
	  );
	},
	createMarker : function(point, name) {
	  var marker = new GMarker(point);
	  GEvent.addListener(marker, "click", function() {
	    marker.openInfoWindowHtml(name);
	  });
	  return marker;
	}
};
twitter2mapplet.start();
</script>
]]></Content>
</Module>