1 // GeoRssOverlay: GMaps API extension to display a group of markers from
4 // Copyright 2006 Mikel Maron (email: mikel_maron yahoo com)
6 // The original version of this code is called MGeoRSS and can be found
7 // at the following address:
8 // http://brainoff.com/gmaps/mgeorss.html
10 // Modified by Andrew Turner to add support for the GeoRss Simple vocabulary
12 // Modified and bundled with YM4R in accordance with the following
15 // This work is public domain
17 function GeoRssOverlay(rssurl,icon,proxyurl,options){
20 this.proxyurl = proxyurl;
21 if(options['visible'] == undefined)
24 this.visible = options['visible'];
25 this.listDiv = options['listDiv']; //ID of the item list DIV
26 this.contentDiv = options['contentDiv']; //ID of the content DIV
27 this.listItemClass = options['listItemClass']; //Class of the list item DIV
28 this.limitItems = options['limit']; //Maximum number of displayed entries
33 GeoRssOverlay.prototype = new GOverlay();
35 GeoRssOverlay.prototype.initialize=function(map) {
40 GeoRssOverlay.prototype.redraw = function(force){
41 //nothing to do : the markers are already taken care of
44 GeoRssOverlay.prototype.remove = function(){
45 for(var i= 0, len = this.markers.length ; i< len; i++){
46 this.map.removeOverlay(this.markers[i]);
50 GeoRssOverlay.prototype.showHide=function() {
52 for (var i=0;i<this.markers.length;i++) {
53 this.map.removeOverlay(this.markers[i]);
57 for (var i=0;i<this.markers.length;i++) {
58 this.map.addOverlay(this.markers[i]);
64 GeoRssOverlay.prototype.showMarker = function(id){
65 var marker = this.markers[id];
66 if(marker != undefined){
67 GEvent.trigger(marker,"click");
71 GeoRssOverlay.prototype.copy = function(){
72 var oCopy = new GeoRssOVerlay(this.rssurl,this.icon,this.proxyurl);
74 for(var i = 0 , len = this.markers.length ;i < len ; i++){
75 oCopy.markers.push(this.markers[i].copy());
80 GeoRssOverlay.prototype.load=function() {
81 if (this.request != false) {
84 this.request = GXmlHttp.create();
85 if (this.proxyurl != undefined) {
86 this.request.open("GET",this.proxyurl + '?q=' + encodeURIComponent(this.rssurl),true);
88 this.request.open("GET",this.rssurl, true);
91 this.request.onreadystatechange = function() {
94 this.request.send(null);
97 GeoRssOverlay.prototype.callback = function() {
98 if (this.request.readyState == 4) {
99 if (this.request.status == "200") {
100 var xmlDoc = this.request.responseXML;
101 if(xmlDoc.documentElement.getElementsByTagName("item").length != 0){
103 var items = xmlDoc.documentElement.getElementsByTagName("item");
104 }else if(xmlDoc.documentElement.getElementsByTagName("entry").length != 0){
106 var items = xmlDoc.documentElement.getElementsByTagName("entry");
108 for (var i = 0, len = this.limitItems?Math.min(this.limitItems,items.length):items.length; i < len; i++) {
110 var marker = this.createMarker(items[i],i);
111 this.markers.push(marker);
113 this.map.addOverlay(marker);
119 this.request = false;
123 GeoRssOverlay.prototype.createMarker = function(item,index) {
125 var title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
126 if(item.getElementsByTagName("description").length != 0){
128 var description = item.getElementsByTagName("description")[0].childNodes[0].nodeValue;
129 var link = item.getElementsByTagName("link")[0].childNodes[0].nodeValue; }else if(item.getElementsByTagName("summary").length != 0){
131 var description = item.getElementsByTagName("summary")[0].childNodes[0].nodeValue;
132 var link = item.getElementsByTagName("link")[0].attributes[0].nodeValue;
134 /* namespaces are handled by spec in moz, not in ie */
135 if (navigator.userAgent.toLowerCase().indexOf("msie") < 0) {
136 if(item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","lat").length != 0){
138 var lat = item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","lat")[0].childNodes[0].nodeValue;
139 var lng = item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","long")[0].childNodes[0].nodeValue;
140 }else if(item.getElementsByTagNameNS("http://www.georss.org/georss","point").length != 0){
143 var latlng = item.getElementsByTagNameNS("http://www.georss.org/georss","point")[0].childNodes[0].nodeValue.split(" ");
149 if(item.getElementsByTagName("geo:lat").length != 0){
151 var lat = item.getElementsByTagName("geo:lat")[0].childNodes[0].nodeValue;
152 var lng = item.getElementsByTagName("geo:long")[0].childNodes[0].nodeValue;
153 }else if(item.getElementsByTagName("georss:point").length != 0){
155 var latlng = item.getElementsByTagName("georss:point")[0].childNodes[0].nodeValue.split(" ");
161 var point = new GLatLng(parseFloat(lat), parseFloat(lng));
162 var marker = new GMarker(point,{'title': title});
163 var html = "<a href=\"" + link + "\">" + title + "</a><p/>" + description;
165 if(this.contentDiv == undefined){
166 GEvent.addListener(marker, "click", function() {
167 marker.openInfoWindowHtml(html);
170 var contentDiv = this.contentDiv;
171 GEvent.addListener(marker, "click", function() {
172 document.getElementById(contentDiv).innerHTML = html;
176 if(this.listDiv != undefined){
177 var a = document.createElement('a');
179 a.setAttribute("href","#");
181 a.onclick = function(){
182 georss.showMarker(index);
185 var div = document.createElement('div');
186 if(this.listItemClass != undefined){
187 div.setAttribute("class",this.listItemClass);
190 document.getElementById(this.listDiv).appendChild(div);