ym4r_gm 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,194 @@
1
+ // GeoRssOverlay: GMaps API extension to display a group of markers from
2
+ // a RSS feed
3
+ //
4
+ // Copyright 2006 Mikel Maron (email: mikel_maron yahoo com)
5
+ //
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
9
+ //
10
+ // Modified by Andrew Turner to add support for the GeoRss Simple vocabulary
11
+ //
12
+ // Modified and bundled with YM4R in accordance with the following
13
+ // license:
14
+ //
15
+ // This work is public domain
16
+
17
+ function GeoRssOverlay(rssurl,icon,proxyurl,options){
18
+ this.rssurl = rssurl;
19
+ this.icon = icon;
20
+ this.proxyurl = proxyurl;
21
+ if(options['visible'] == undefined)
22
+ this.visible = true;
23
+ else
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
29
+ this.request = false;
30
+ this.markers = [];
31
+ }
32
+
33
+ GeoRssOverlay.prototype = new GOverlay();
34
+
35
+ GeoRssOverlay.prototype.initialize=function(map) {
36
+ this.map = map;
37
+ this.load();
38
+ }
39
+
40
+ GeoRssOverlay.prototype.redraw = function(force){
41
+ //nothing to do : the markers are already taken care of
42
+ }
43
+
44
+ GeoRssOverlay.prototype.remove = function(){
45
+ for(var i= 0, len = this.markers.length ; i< len; i++){
46
+ this.map.removeOverlay(this.markers[i]);
47
+ }
48
+ }
49
+
50
+ GeoRssOverlay.prototype.showHide=function() {
51
+ if (this.visible) {
52
+ for (var i=0;i<this.markers.length;i++) {
53
+ this.map.removeOverlay(this.markers[i]);
54
+ }
55
+ this.visible = false;
56
+ } else {
57
+ for (var i=0;i<this.markers.length;i++) {
58
+ this.map.addOverlay(this.markers[i]);
59
+ }
60
+ this.visible = true;
61
+ }
62
+ }
63
+
64
+ GeoRssOverlay.prototype.showMarker = function(id){
65
+ var marker = this.markers[id];
66
+ if(marker != undefined){
67
+ GEvent.trigger(marker,"click");
68
+ }
69
+ }
70
+
71
+ GeoRssOverlay.prototype.copy = function(){
72
+ var oCopy = new GeoRssOVerlay(this.rssurl,this.icon,this.proxyurl);
73
+ oCopy.markers = [];
74
+ for(var i = 0 , len = this.markers.length ;i < len ; i++){
75
+ oCopy.markers.push(this.markers[i].copy());
76
+ }
77
+ return oCopy;
78
+ }
79
+
80
+ GeoRssOverlay.prototype.load=function() {
81
+ if (this.request != false) {
82
+ return;
83
+ }
84
+ this.request = GXmlHttp.create();
85
+ if (this.proxyurl != undefined) {
86
+ this.request.open("GET",this.proxyurl + '?q=' + encodeURIComponent(this.rssurl),true);
87
+ } else {
88
+ this.request.open("GET",this.rssurl, true);
89
+ }
90
+ var m = this;
91
+ this.request.onreadystatechange = function() {
92
+ m.callback();
93
+ }
94
+ this.request.send(null);
95
+ }
96
+
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){
102
+ //RSS
103
+ var items = xmlDoc.documentElement.getElementsByTagName("item");
104
+ }else if(xmlDoc.documentElement.getElementsByTagName("entry").length != 0){
105
+ //Atom
106
+ var items = xmlDoc.documentElement.getElementsByTagName("entry");
107
+ }
108
+ for (var i = 0, len = this.limitItems?Math.min(this.limitItems,items.length):items.length; i < len; i++) {
109
+ try {
110
+ var marker = this.createMarker(items[i],i);
111
+ this.markers.push(marker);
112
+ if(this.visible){
113
+ this.map.addOverlay(marker);
114
+ }
115
+ } catch (e) {
116
+ }
117
+ }
118
+ }
119
+ this.request = false;
120
+ }
121
+ }
122
+
123
+ GeoRssOverlay.prototype.createMarker = function(item,index) {
124
+
125
+ var title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
126
+ if(item.getElementsByTagName("description").length != 0){
127
+ //Rss
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){
130
+ //Atom
131
+ var description = item.getElementsByTagName("summary")[0].childNodes[0].nodeValue;
132
+ var link = item.getElementsByTagName("link")[0].attributes[0].nodeValue;
133
+ }
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){
137
+ //W3C Geo Vocabulary
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){
141
+
142
+ //Simple
143
+ var latlng = item.getElementsByTagNameNS("http://www.georss.org/georss","point")[0].childNodes[0].nodeValue.split(" ");
144
+ var lat = latlng[0];
145
+ var lng = latlng[1];
146
+ }
147
+ } else {
148
+
149
+ if(item.getElementsByTagName("geo:lat").length != 0){
150
+ //W3C Geo Vocabulary
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){
154
+ //Simple
155
+ var latlng = item.getElementsByTagName("georss:point")[0].childNodes[0].nodeValue.split(" ");
156
+ var lat = latlng[0];
157
+ var lng = latlng[1];
158
+ }
159
+ }
160
+
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;
164
+
165
+ if(this.contentDiv == undefined){
166
+ GEvent.addListener(marker, "click", function() {
167
+ marker.openInfoWindowHtml(html);
168
+ });
169
+ }else{
170
+ var contentDiv = this.contentDiv;
171
+ GEvent.addListener(marker, "click", function() {
172
+ document.getElementById(contentDiv).innerHTML = html;
173
+ });
174
+ }
175
+
176
+ if(this.listDiv != undefined){
177
+ var a = document.createElement('a');
178
+ a.innerHTML = title;
179
+ a.setAttribute("href","#");
180
+ var georss = this;
181
+ a.onclick = function(){
182
+ georss.showMarker(index);
183
+ return false;
184
+ };
185
+ var div = document.createElement('div');
186
+ if(this.listItemClass != undefined){
187
+ div.setAttribute("class",this.listItemClass);
188
+ }
189
+ div.appendChild(a);
190
+ document.getElementById(this.listDiv).appendChild(div);
191
+ }
192
+
193
+ return marker;
194
+ }
@@ -0,0 +1,114 @@
1
+ function GMarkerGroup(active, markers, markersById) {
2
+ this.active = active;
3
+ this.markers = markers || new Array();
4
+ this.markersById = markersById || new Object();
5
+ }
6
+
7
+ GMarkerGroup.prototype = new GOverlay();
8
+
9
+ GMarkerGroup.prototype.initialize = function(map) {
10
+ this.map = map;
11
+
12
+ if(this.active){
13
+ for(var i = 0 , len = this.markers.length; i < len; i++) {
14
+ this.map.addOverlay(this.markers[i]);
15
+ }
16
+ for(var id in this.markersById){
17
+ this.map.addOverlay(this.markersById[id]);
18
+ }
19
+ }
20
+ }
21
+
22
+ //If not already done (ie if not inactive) remove all the markers from the map
23
+ GMarkerGroup.prototype.remove = function() {
24
+ this.deactivate();
25
+ }
26
+
27
+ GMarkerGroup.prototype.redraw = function(force){
28
+ //Nothing to do : markers are already taken care of
29
+ }
30
+
31
+ //Copy the data to a new Marker Group
32
+ GMarkerGroup.prototype.copy = function() {
33
+ var overlay = new GMarkerGroup(this.active);
34
+ overlay.markers = this.markers; //Need to do deep copy
35
+ overlay.markersById = this.markersById; //Need to do deep copy
36
+ return overlay;
37
+ }
38
+
39
+ //Inactivate the Marker group and clear the internal content
40
+ GMarkerGroup.prototype.clear = function(){
41
+ //deactivate the map first (which removes the markers from the map)
42
+ this.deactivate();
43
+ //Clear the internal content
44
+ this.markers = new Array();
45
+ this.markersById = new Object();
46
+ }
47
+
48
+ //Add a marker to the GMarkerGroup ; Adds it now to the map if the GMarkerGroup is active
49
+ GMarkerGroup.prototype.addMarker = function(marker,id){
50
+ if(id == undefined){
51
+ this.markers.push(marker);
52
+ }else{
53
+ this.markersById[id] = marker;
54
+ }
55
+ if(this.active && this.map != undefined ){
56
+ this.map.addOverlay(marker);
57
+ }
58
+ }
59
+
60
+ //Open the info window (or info window tabs) of a marker
61
+ GMarkerGroup.prototype.showMarker = function(id){
62
+ var marker = this.markersById[id];
63
+ if(marker != undefined){
64
+ GEvent.trigger(marker,"click");
65
+ }
66
+ }
67
+
68
+ //Activate (or deactivate depending on the argument) the GMarkerGroup
69
+ GMarkerGroup.prototype.activate = function(active){
70
+ active = (active == undefined) ? true : active;
71
+ if(!active){
72
+ if(this.active){
73
+ if(this.map != undefined){
74
+ for(var i = 0 , len = this.markers.length; i < len; i++){
75
+ this.map.removeOverlay(this.markers[i])
76
+ }
77
+ for(var id in this.markersById){
78
+ this.map.removeOverlay(this.markersById[id]);
79
+ }
80
+ }
81
+ this.active = false;
82
+ }
83
+ }else{
84
+ if(!this.active){
85
+ if(this.map != undefined){
86
+ for(var i = 0 , len = this.markers.length; i < len; i++){
87
+ this.map.addOverlay(this.markers[i]);
88
+ }
89
+ for(var id in this.markersById){
90
+ this.map.addOverlay(this.markersById[id]);
91
+ }
92
+ }
93
+ this.active = true;
94
+ }
95
+ }
96
+ }
97
+
98
+ GMarkerGroup.prototype.centerAndZoomOnMarkers = function() {
99
+ if(this.map != undefined){
100
+ //merge markers and markersById
101
+ var tmpMarkers = this.markers.slice();
102
+ for (var id in this.markersById){
103
+ tmpMarkers.push(this.markersById[id]);
104
+ }
105
+ if(tmpMarkers.length > 0){
106
+ this.map.centerAndZoomOnMarkers(tmpMarkers);
107
+ }
108
+ }
109
+ }
110
+
111
+ //Deactivate the Group Overlay (convenience method)
112
+ GMarkerGroup.prototype.deactivate = function(){
113
+ this.activate(false);
114
+ }
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Call generic wms service for GoogleMaps v2
3
+ * John Deck, UC Berkeley
4
+ * Inspiration & Code from:
5
+ * Mike Williams http://www.econym.demon.co.uk/googlemaps2/ V2 Reference & custommap code
6
+ * Brian Flood http://www.spatialdatalogic.com/cs/blogs/brian_flood/archive/2005/07/11/39.aspx V1 WMS code
7
+ * Kyle Mulka http://blog.kylemulka.com/?p=287 V1 WMS code modifications
8
+ * http://search.cpan.org/src/RRWO/GPS-Lowrance-0.31/lib/Geo/Coordinates/MercatorMeters.pm
9
+ *
10
+ * Modified by Chris Holmes, TOPP to work by default with GeoServer.
11
+ *
12
+ * Bundled with YM4R with John Deck's permission.
13
+ * Slightly modified to fit YM4R.
14
+ * See johndeck.blogspot.com for the original version and for examples and instructions of how to use it.
15
+ */
16
+
17
+ var WGS84_SEMI_MAJOR_AXIS = 6378137.0; //equatorial radius
18
+ var WGS84_ECCENTRICITY = 0.0818191913108718138;
19
+ var DEG2RAD=0.0174532922519943;
20
+ var PI=3.14159267;
21
+
22
+ function dd2MercMetersLng(p_lng) {
23
+ return WGS84_SEMI_MAJOR_AXIS * (p_lng*DEG2RAD);
24
+ }
25
+
26
+ function dd2MercMetersLat(p_lat) {
27
+ var lat_rad = p_lat * DEG2RAD;
28
+ return WGS84_SEMI_MAJOR_AXIS * Math.log(Math.tan((lat_rad + PI / 2) / 2) * Math.pow( ((1 - WGS84_ECCENTRICITY * Math.sin(lat_rad)) / (1 + WGS84_ECCENTRICITY * Math.sin(lat_rad))), (WGS84_ECCENTRICITY/2)));
29
+ }
30
+
31
+ function addWMSPropertiesToLayer(tile_layer,base_url,layers,styles,format,merc_proj,use_geo){
32
+ tile_layer.format = format;
33
+ tile_layer.baseURL = base_url;
34
+ tile_layer.styles = styles;
35
+ tile_layer.layers = layers;
36
+ tile_layer.mercatorEpsg = merc_proj;
37
+ tile_layer.useGeographic = use_geo;
38
+ return tile_layer;
39
+ }
40
+
41
+ getTileUrlForWMS=function(a,b,c) {
42
+ var lULP = new GPoint(a.x*256,(a.y+1)*256);
43
+ var lLRP = new GPoint((a.x+1)*256,a.y*256);
44
+ var lUL = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lULP,b,c);
45
+ var lLR = G_NORMAL_MAP.getProjection().fromPixelToLatLng(lLRP,b,c);
46
+
47
+ if (this.useGeographic){
48
+ var lBbox=lUL.x+","+lUL.y+","+lLR.x+","+lLR.y;
49
+ var lSRS="EPSG:4326";
50
+ }else{
51
+ var lBbox=dd2MercMetersLng(lUL.x)+","+dd2MercMetersLat(lUL.y)+","+dd2MercMetersLng(lLR.x)+","+dd2MercMetersLat(lLR.y);
52
+ var lSRS="EPSG:" + this.mercatorEpsg;
53
+ }
54
+ var lURL=this.baseURL;
55
+ lURL+="?REQUEST=GetMap";
56
+ lURL+="&SERVICE=WMS";
57
+ lURL+="&VERSION=1.1.1";
58
+ lURL+="&LAYERS="+this.layers;
59
+ lURL+="&STYLES="+this.styles;
60
+ lURL+="&FORMAT=image/"+this.format;
61
+ lURL+="&BGCOLOR=0xFFFFFF";
62
+ lURL+="&TRANSPARENT=TRUE";
63
+ lURL+="&SRS="+lSRS;
64
+ lURL+="&BBOX="+lBbox;
65
+ lURL+="&WIDTH=256";
66
+ lURL+="&HEIGHT=256";
67
+ lURL+="&reaspect=false";
68
+ return lURL;
69
+ }
@@ -0,0 +1,117 @@
1
+ // JS helper functions for YM4R
2
+
3
+ function addInfoWindowToMarker(marker,info,options){
4
+ GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(info,options);});
5
+ return marker;
6
+ }
7
+
8
+ function addInfoWindowTabsToMarker(marker,info,options){
9
+ GEvent.addListener(marker, "click", function() {marker.openInfoWindowTabsHtml(info,options);});
10
+ return marker;
11
+ }
12
+
13
+ function addPropertiesToLayer(layer,getTile,copyright,opacity,isPng){
14
+ layer.getTileUrl = getTile;
15
+ layer.getCopyright = copyright;
16
+ layer.getOpacity = opacity;
17
+ layer.isPng = isPng;
18
+ return layer;
19
+ }
20
+
21
+ function addOptionsToIcon(icon,options){
22
+ for(var k in options){
23
+ icon[k] = options[k];
24
+ }
25
+ return icon;
26
+ }
27
+
28
+ function addCodeToFunction(func,code){
29
+ if(func == undefined)
30
+ return code;
31
+ else{
32
+ return function(){
33
+ func();
34
+ code();
35
+ }
36
+ }
37
+ }
38
+
39
+ function addGeocodingToMarker(marker,address){
40
+ marker.orig_initialize = marker.initialize;
41
+ orig_redraw = marker.redraw;
42
+ marker.redraw = function(force){}; //empty the redraw method so no error when called by addOverlay.
43
+ marker.initialize = function(map){
44
+ new GClientGeocoder().getLatLng(address,
45
+ function(latlng){
46
+ if(latlng){
47
+ marker.redraw = orig_redraw;
48
+ marker.orig_initialize(map); //init before setting point
49
+ marker.setPoint(latlng);
50
+ }//do nothing
51
+ });
52
+ };
53
+ return marker;
54
+ }
55
+
56
+
57
+
58
+ GMap2.prototype.centerAndZoomOnMarkers = function(markers) {
59
+ var bounds = new GLatLngBounds(markers[0].getPoint(),
60
+ markers[0].getPoint());
61
+ for (var i=1, len = markers.length ; i<len; i++) {
62
+ bounds.extend(markers[i].getPoint());
63
+ }
64
+
65
+ this.centerAndZoomOnBounds(bounds);
66
+ }
67
+
68
+ GMap2.prototype.centerAndZoomOnPoints = function(points) {
69
+ var bounds = new GLatLngBounds(points[0],
70
+ points[0]);
71
+ for (var i=1, len = points.length ; i<len; i++) {
72
+ bounds.extend(points[i]);
73
+ }
74
+
75
+ this.centerAndZoomOnBounds(bounds);
76
+ }
77
+
78
+ GMap2.prototype.centerAndZoomOnBounds = function(bounds) {
79
+ var center = bounds.getCenter();
80
+ this.setCenter(center, this.getBoundsZoomLevel(bounds));
81
+ }
82
+
83
+ //For full screen mode
84
+ function setWindowDims(elem) {
85
+ if (window.innerWidth){
86
+ elem.style.height = (window.innerHeight) + 'px;';
87
+ elem.style.width = (window.innerWidth) + 'px;';
88
+ }else if (document.body.clientWidth){
89
+ elem.style.width = (document.body.clientWidth) + 'px';
90
+ elem.style.height = (document.body.clientHeight) + 'px';
91
+ }
92
+ }
93
+
94
+ ManagedMarker = function(markers,minZoom,maxZoom) {
95
+ this.markers = markers;
96
+ this.minZoom = minZoom;
97
+ this.maxZoom = maxZoom;
98
+ }
99
+
100
+ //Add the markers and refresh
101
+ function addMarkersToManager(manager,managedMarkers){
102
+ for(var i = 0, length = managedMarkers.length; i < length;i++) {
103
+ mm = managedMarkers[i];
104
+ manager.addMarkers(mm.markers,mm.minZoom,mm.maxZoom);
105
+ }
106
+ manager.refresh();
107
+ return manager;
108
+ }
109
+
110
+
111
+ var INVISIBLE = new GLatLng(0,0); //almost always invisible
112
+
113
+ if(self.Event && Event.observe){
114
+ Event.observe(window, 'unload', GUnload);
115
+ }else{
116
+ window.onunload = GUnload;
117
+ }