ym4r 0.4.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +40 -243
- data/lib/ym4r/google_maps.rb +3 -8
- data/lib/ym4r/google_maps/geocoding.rb +80 -1
- data/lib/ym4r/google_maps/{tiler/image_tiler.rb → image_tiler.rb} +0 -0
- data/lib/ym4r/google_maps/{tiler/wms_tiler.rb → wms_tiler.rb} +0 -0
- data/lib/ym4r/yahoo_maps.rb +0 -1
- data/rakefile.rb +3 -3
- data/test/test_geocoding.rb +4 -4
- data/test/test_gm_geocoding.rb +28 -0
- data/tools/tile_image.rb +2 -1
- data/tools/tile_wms.rb +4 -3
- metadata +9 -28
- data/lib/ym4r/google_maps/control.rb +0 -66
- data/lib/ym4r/google_maps/geocoding/geocoding.rb +0 -80
- data/lib/ym4r/google_maps/helper.rb +0 -22
- data/lib/ym4r/google_maps/javascript/clusterer.js +0 -444
- data/lib/ym4r/google_maps/javascript/geoRssOverlay.js +0 -107
- data/lib/ym4r/google_maps/javascript/markerGroup.js +0 -104
- data/lib/ym4r/google_maps/javascript/wms-gs.js +0 -69
- data/lib/ym4r/google_maps/layer.rb +0 -115
- data/lib/ym4r/google_maps/map.rb +0 -158
- data/lib/ym4r/google_maps/mapping.rb +0 -126
- data/lib/ym4r/google_maps/overlay.rb +0 -187
- data/lib/ym4r/google_maps/point.rb +0 -36
- data/lib/ym4r/yahoo_maps/flash.rb +0 -7
- data/lib/ym4r/yahoo_maps/flash/latlon.rb +0 -18
- data/lib/ym4r/yahoo_maps/flash/map.rb +0 -74
- data/lib/ym4r/yahoo_maps/flash/mapping.rb +0 -71
- data/lib/ym4r/yahoo_maps/flash/marker.rb +0 -43
- data/lib/ym4r/yahoo_maps/flash/overlay.rb +0 -44
- data/lib/ym4r/yahoo_maps/flash/tool.rb +0 -30
- data/lib/ym4r/yahoo_maps/flash/widget.rb +0 -33
- data/test/test_google_maps.rb +0 -75
@@ -1,107 +0,0 @@
|
|
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 adress:
|
8
|
-
// http://brainoff.com/gmaps/mgeorss.html
|
9
|
-
//
|
10
|
-
// Modified and bundled with YM4R in accordance with the following
|
11
|
-
// license:
|
12
|
-
//
|
13
|
-
// This work is public domain
|
14
|
-
|
15
|
-
function GeoRssOverlay(rssurl,icon,proxyurl){
|
16
|
-
this.rssurl = rssurl;
|
17
|
-
this.icon = icon;
|
18
|
-
this.proxyurl = proxyurl;
|
19
|
-
this.request = false;
|
20
|
-
this.markers = [];
|
21
|
-
}
|
22
|
-
|
23
|
-
GeoRssOverlay.prototype = new GOverlay();
|
24
|
-
|
25
|
-
GeoRssOverlay.prototype.initialize=function(map) {
|
26
|
-
this.map = map;
|
27
|
-
this.load();
|
28
|
-
}
|
29
|
-
|
30
|
-
GeoRssOverlay.prototype.redraw = function(force){
|
31
|
-
//nothing to do : the markers are already taken care of
|
32
|
-
}
|
33
|
-
|
34
|
-
GeoRssOverlay.prototype.remove = function(){
|
35
|
-
for(var i= 0, len = this.markers.length ; i< len; i++){
|
36
|
-
this.map.removeOverlay(this.markers[i]);
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
GeoRssOverlay.prototype.copy = function(){
|
41
|
-
var oCopy = new GeoRssOVerlay(this.rssurl,this.icon,this.proxyurl);
|
42
|
-
oCopy.markers = [];
|
43
|
-
for(var i = 0 , len = this.markers.length ;i < len ; i++){
|
44
|
-
oCopy.markers.push(this.markers[i].copy());
|
45
|
-
}
|
46
|
-
return oCopy;
|
47
|
-
}
|
48
|
-
|
49
|
-
GeoRssOverlay.prototype.load=function() {
|
50
|
-
if (this.request != false) {
|
51
|
-
return;
|
52
|
-
}
|
53
|
-
this.request = GXmlHttp.create();
|
54
|
-
if (this.proxyurl != undefined) {
|
55
|
-
this.request.open("GET",this.proxyurl + '?q=' + encodeURIComponent(this.rssurl),true);
|
56
|
-
} else {
|
57
|
-
this.request.open("GET",this.rssurl, true);
|
58
|
-
}
|
59
|
-
var m = this;
|
60
|
-
this.request.onreadystatechange = function() {
|
61
|
-
m.callback();
|
62
|
-
}
|
63
|
-
this.request.send(null);
|
64
|
-
}
|
65
|
-
|
66
|
-
GeoRssOverlay.prototype.callback = function() {
|
67
|
-
if (this.request.readyState == 4) {
|
68
|
-
if (this.request.status == "200") {
|
69
|
-
var xmlDoc = this.request.responseXML;
|
70
|
-
var items = xmlDoc.documentElement.getElementsByTagName("item");
|
71
|
-
for (var i = 0; i < items.length; i++) {
|
72
|
-
try {
|
73
|
-
var marker = this.createMarker(items[i]);
|
74
|
-
this.markers.push(marker);
|
75
|
-
this.map.addOverlay(marker);
|
76
|
-
} catch (e) {
|
77
|
-
}
|
78
|
-
}
|
79
|
-
}
|
80
|
-
this.request = false;
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
|
-
GeoRssOverlay.prototype.createMarker = function(item) {
|
85
|
-
var title = item.getElementsByTagName("title")[0].childNodes[0].nodeValue;
|
86
|
-
var description = item.getElementsByTagName("description")[0].childNodes[0].nodeValue;
|
87
|
-
var link = item.getElementsByTagName("link")[0].childNodes[0].nodeValue;
|
88
|
-
|
89
|
-
/* namespaces are handled by spec in moz, not in ie */
|
90
|
-
if (navigator.userAgent.toLowerCase().indexOf("msie") < 0) {
|
91
|
-
var lat = item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","lat")[0].childNodes[0].nodeValue;
|
92
|
-
var lng = item.getElementsByTagNameNS("http://www.w3.org/2003/01/geo/wgs84_pos#","long")[0].childNodes[0].nodeValue;
|
93
|
-
} else {
|
94
|
-
var lat = item.getElementsByTagName("geo:lat")[0].childNodes[0].nodeValue;
|
95
|
-
var lng = item.getElementsByTagName("geo:long")[0].childNodes[0].nodeValue;
|
96
|
-
}
|
97
|
-
|
98
|
-
var point = new GLatLng(parseFloat(lat), parseFloat(lng));
|
99
|
-
var marker = new GMarker(point,{'title': title});
|
100
|
-
var html = "<a href=\"" + link + "\">" + title + "</a><p/>" + description;
|
101
|
-
|
102
|
-
GEvent.addListener(marker, "click", function() {
|
103
|
-
marker.openInfoWindowHtml(html);
|
104
|
-
});
|
105
|
-
|
106
|
-
return marker;
|
107
|
-
}
|
@@ -1,104 +0,0 @@
|
|
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 ; Should only be used AFTER the group overlay has been added to the map
|
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
|
-
//Check if I can just send the click event to the marker
|
65
|
-
GEvent.trigger(marker,"click");
|
66
|
-
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
70
|
-
//Activate (or deactivate depending on the argument) the GMarkerGroup
|
71
|
-
GMarkerGroup.prototype.activate = function(active){
|
72
|
-
active = (active == undefined) ? true : active;
|
73
|
-
if(!active){
|
74
|
-
if(this.active){
|
75
|
-
if(this.map != undefined){
|
76
|
-
for(var i = 0 , len = this.markers.length; i < len; i++){
|
77
|
-
this.map.removeOverlay(this.markers[i])
|
78
|
-
}
|
79
|
-
for(var id in this.markersById){
|
80
|
-
this.map.removeOverlay(this.markersById[id]);
|
81
|
-
}
|
82
|
-
}
|
83
|
-
this.active = false;
|
84
|
-
}
|
85
|
-
}else{
|
86
|
-
if(!this.active){
|
87
|
-
if(this.map != undefined){
|
88
|
-
for(var i = 0 , len = this.markers.length; i < len; i++){
|
89
|
-
this.map.addOverlay(this.markers[i]);
|
90
|
-
}
|
91
|
-
for(var id in this.markersById){
|
92
|
-
this.map.addOverlay(this.markersById[id]);
|
93
|
-
}
|
94
|
-
}
|
95
|
-
this.active = true;
|
96
|
-
}
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
//Deactivate the Group Overlay (convenience method)
|
101
|
-
GMarkerGroup.prototype.deactivate = function(){
|
102
|
-
this.activate(false);
|
103
|
-
}
|
104
|
-
|
@@ -1,69 +0,0 @@
|
|
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
|
-
}
|
@@ -1,115 +0,0 @@
|
|
1
|
-
module Ym4r
|
2
|
-
module GoogleMaps
|
3
|
-
#Map types of the map
|
4
|
-
class GMapType
|
5
|
-
include MappingObject
|
6
|
-
|
7
|
-
G_NORMAL_MAP = Variable.new("G_NORMAL_MAP")
|
8
|
-
G_SATELLITE_MAP = Variable.new("G_SATELLITE_MAP")
|
9
|
-
G_HYBRID_MAP = Variable.new("G_HYBRID_MAP")
|
10
|
-
|
11
|
-
attr_accessor :layers, :name, :projection, :options
|
12
|
-
|
13
|
-
def initialize(layers, name, projection = GMercatorProjection.new,options = {})
|
14
|
-
@layers = layers
|
15
|
-
@name = name
|
16
|
-
@projection = projection
|
17
|
-
@options = options
|
18
|
-
end
|
19
|
-
|
20
|
-
def create
|
21
|
-
"new GMapType(#{MappingObject.javascriptify_variable(Array(layers))}, #{MappingObject.javascriptify_variable(projection)}, #{MappingObject.javascriptify_variable(name)}, #{MappingObject.javascriptify_variable(options)})"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class GMercatorProjection
|
26
|
-
include MappingObject
|
27
|
-
|
28
|
-
attr_accessor :n
|
29
|
-
|
30
|
-
def initialize(n = nil)
|
31
|
-
@n = n
|
32
|
-
end
|
33
|
-
|
34
|
-
def create
|
35
|
-
if n.nil?
|
36
|
-
return "G_NORMAL_MAP.getProjection()"
|
37
|
-
else
|
38
|
-
"new GMercatorProjection(#{@n})"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class GTileLayer
|
44
|
-
include MappingObject
|
45
|
-
|
46
|
-
attr_accessor :opacity, :zoom_inter, :copyright, :format
|
47
|
-
|
48
|
-
def initialize(zoom_inter = 0..17, copyright= {'prefix' => '', 'copyright_texts' => [""]}, opacity = 1.0, format = "png")
|
49
|
-
@opacity = opacity
|
50
|
-
@zoom_inter = zoom_inter
|
51
|
-
@copyright = copyright
|
52
|
-
@format = format.to_s
|
53
|
-
end
|
54
|
-
|
55
|
-
def create
|
56
|
-
"addPropertiesToLayer(new GTileLayer(new GCopyrightCollection(\"\"),#{zoom_inter.begin},#{zoom_inter.end}),#{get_tile_url},function(a,b) {return #{MappingObject.javascriptify_variable(@copyright)};}\n,function() {return #{@opacity};},function(){return #{@format == "png"};})"
|
57
|
-
end
|
58
|
-
|
59
|
-
#for subclasses to implement
|
60
|
-
def get_tile_url
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
#Represents a pre tiled layer, taking images directly from a server, without using a server script.
|
65
|
-
class PreTiledLayer < GTileLayer
|
66
|
-
attr_accessor :base_url
|
67
|
-
|
68
|
-
def initialize(base_url = "/public/tiles", copyright = {'prefix' => '', 'copyright_texts' => [""]}, zoom_inter = 0..17, opacity = 1.0,format = "png")
|
69
|
-
super(zoom_inter, copyright, opacity,format)
|
70
|
-
@base_url = base_url
|
71
|
-
end
|
72
|
-
|
73
|
-
#returns the code to determine the url to fetch the tile. Follows the convention adopted by the tiler: {base_url}/tile_{b}_{a.x}_{a.y}.{format}
|
74
|
-
def get_tile_url
|
75
|
-
"function(a,b,c) { return '#{@base_url}/tile_' + b + '_' + a.x + '_' + a.y + '.#{format}';}"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
#Represents a pretiled layer (it actually does not really matter where the tiles come from). Calls an action on the server to get back the tiles. It can be used, for example, to return default tiles when the requested tile is not present.
|
80
|
-
class PreTiledLayerFromAction < PreTiledLayer
|
81
|
-
def get_tile_url
|
82
|
-
"function(a,b,c) { return '#{base_url}?x=' + a.x + '&y=' + a.y + '&z=' + b;}"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
#needs to include the JavaScript file wms-gs.js for this to work
|
87
|
-
#see http://docs.codehaus.org/display/GEOSDOC/Google+Maps
|
88
|
-
class WMSLayer < GTileLayer
|
89
|
-
attr_accessor :base_url, :layers, :styles, :merc_proj, :use_geographic
|
90
|
-
|
91
|
-
def initialize(base_url, layers, styles = "", copyright = {'prefix' => '', 'copyright_texts' => [""]}, use_geographic = false, merc_proj = :mapserver, zoom_inter = 0..17, opacity = 1.0,format= "png")
|
92
|
-
super(zoom_inter, copyright, opacity,format)
|
93
|
-
@base_url = base_url
|
94
|
-
@layers = layers
|
95
|
-
@styles = styles
|
96
|
-
@merc_proj = if merc_proj == :mapserver
|
97
|
-
"54004"
|
98
|
-
elsif merc_proj == :geoserver
|
99
|
-
"41001"
|
100
|
-
else
|
101
|
-
merc_proj.to_s
|
102
|
-
end
|
103
|
-
@use_geographic = use_geographic
|
104
|
-
end
|
105
|
-
|
106
|
-
def get_tile_url
|
107
|
-
"getTileUrlForWMS"
|
108
|
-
end
|
109
|
-
|
110
|
-
def create
|
111
|
-
"addWMSPropertiesToLayer(#{super},#{MappingObject.javascriptify_variable(@base_url)},#{MappingObject.javascriptify_variable(@layers)},#{MappingObject.javascriptify_variable(@styles)},#{MappingObject.javascriptify_variable(format)},#{MappingObject.javascriptify_variable(@merc_proj)},#{MappingObject.javascriptify_variable(@use_geographic)})"
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
data/lib/ym4r/google_maps/map.rb
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
module Ym4r
|
2
|
-
module GoogleMaps
|
3
|
-
#The Ruby-space class representing the Google Maps API class GMap2.
|
4
|
-
class GMap
|
5
|
-
include MappingObject
|
6
|
-
|
7
|
-
#A constant containing the declaration of the VML namespace, necessary to display polylines under IE.
|
8
|
-
VML_NAMESPACE = "xmlns:v=\"urn:schemas-microsoft-com:vml\""
|
9
|
-
|
10
|
-
#The id of the DIV that will contain the map in the HTML page.
|
11
|
-
attr_reader :container
|
12
|
-
|
13
|
-
#By default the map in the HTML page will be globally accessible with the name +map+.
|
14
|
-
def initialize(container, variable = "map")
|
15
|
-
@container = container
|
16
|
-
@variable = variable
|
17
|
-
@init = []
|
18
|
-
@init_end = [] #for stuff that must be initialized at the end (controls)
|
19
|
-
@init_begin = [] #for stuff that must be initialized at the beginning (center + zoom)
|
20
|
-
@global_init = []
|
21
|
-
end
|
22
|
-
|
23
|
-
#Deprecated. Use the static version instead.
|
24
|
-
def header(with_vml = true)
|
25
|
-
GMap.header(:with_vml => with_vml)
|
26
|
-
end
|
27
|
-
|
28
|
-
#Outputs the header necessary to use the Google Maps API. By default, it also outputs a style declaration for VML elements (can be changed with the option <tt>:with_vml</tt>). You can also pass a host with the <tt>:host</tt> option: If you use Rails, you should pass <tt>:host => @request.host</tt>. This host must have a corresponding API key in the config.yml file. If you don't care about multiple hosts or want to manage the keys yourself, you should not pass the <tt>:host</tt> option and the config.yml should only contain a single API key.
|
29
|
-
def self.header(options = {})
|
30
|
-
options[:with_vml] = true unless options.has_key?(:with_vml)
|
31
|
-
if options.has_key?(:host)
|
32
|
-
api_key = API_KEY[options[:host]]
|
33
|
-
else
|
34
|
-
api_key = API_KEY
|
35
|
-
end
|
36
|
-
a = "<script src=\"http://maps.google.com/maps?file=api&v=2&key=#{api_key}\" type=\"text/javascript\"></script>\n"
|
37
|
-
a << "<style type=\"text/css\">\n v\:* { behavior:url(#default#VML);}\n</style>" if options[:with_vml]
|
38
|
-
a
|
39
|
-
end
|
40
|
-
|
41
|
-
#Outputs the <div id=...></div> which has been configured to contain the map
|
42
|
-
def div
|
43
|
-
"<div id=\"#{@container}\"></div>"
|
44
|
-
end
|
45
|
-
|
46
|
-
#Outputs a style declaration setting the dimensions of the DIV container of the map. This info can also be set manually in a CSS.
|
47
|
-
def header_width_height(width,height)
|
48
|
-
"<style type=\"text/css\">\n##{@container} { height: #{height}px;\n width: #{width}px;\n}\n</style>"
|
49
|
-
end
|
50
|
-
|
51
|
-
#Records arbitrary JavaScript code and outputs it during initialization inside the +load+ function.
|
52
|
-
def record_init(code)
|
53
|
-
@init << code
|
54
|
-
end
|
55
|
-
|
56
|
-
#Initializes the controls: you can pass a hash with keys <tt>:small_map</tt>, <tt>:large_map</tt>, <tt>:small_zoom</tt>, <tt>:scale</tt>, <tt>:map_type</tt> and <tt>:overview_map</tt> and a boolean value as the value (usually true, since the control is not displayed by default)
|
57
|
-
def control_init(controls = {})
|
58
|
-
@init_end << add_control(GSmallMapControl.new) if controls[:small_map]
|
59
|
-
@init_end << add_control(GLargeMapControl.new) if controls[:large_map]
|
60
|
-
@init_end << add_control(GSmallZoomControl.new) if controls[:small_zoom]
|
61
|
-
@init_end << add_control(GScaleControl.new) if controls[:scale]
|
62
|
-
@init_end << add_control(GMapTypeControl.new) if controls[:map_type]
|
63
|
-
@init_end << add_control(GOverviewMapControl.new) if controls[:overview_map]
|
64
|
-
end
|
65
|
-
|
66
|
-
#Initializes the initial center and zoom of the map. +center+ can be both a GLatLng object or a 2-float array.
|
67
|
-
def center_zoom_init(center, zoom)
|
68
|
-
if center.is_a?(GLatLng)
|
69
|
-
@init_begin << set_center(center,zoom)
|
70
|
-
else
|
71
|
-
@init_begin << set_center(GLatLng.new(center),zoom)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
#Initializes the map by adding an overlay (marker or polyline).
|
76
|
-
def overlay_init(overlay)
|
77
|
-
@init << add_overlay(overlay)
|
78
|
-
end
|
79
|
-
|
80
|
-
#Sets up a new map type. If +add+ is false, all the other map types of the map are wiped out. If +set+ is true, the current map type for the map is set to +map_type+. If you want to access the map type in other methods, you should declare the map type first.
|
81
|
-
def map_type_init(map_type, add = true)
|
82
|
-
unless add
|
83
|
-
@init << get_map_types.set_property(:length,0)
|
84
|
-
end
|
85
|
-
@init << add_map_type(map_type)
|
86
|
-
end
|
87
|
-
|
88
|
-
#Locally declare a MappingObject with variable name "name"
|
89
|
-
def declare_init(variable, name)
|
90
|
-
@init << variable.declare(name)
|
91
|
-
end
|
92
|
-
|
93
|
-
#Records arbitrary JavaScript code and outputs it during initialization outside the +load+ function (ie globally).
|
94
|
-
def record_global_init(code)
|
95
|
-
@global_init << code
|
96
|
-
end
|
97
|
-
|
98
|
-
#Deprecated. Use icon_global_init instead.
|
99
|
-
def icon_init(icon , name)
|
100
|
-
icon_global_init(icon , name)
|
101
|
-
end
|
102
|
-
|
103
|
-
#Initializes an icon and makes it globally accessible through the JavaScript variable of name +variable+.
|
104
|
-
def icon_global_init(icon , name)
|
105
|
-
declare_global_init(icon,name)
|
106
|
-
end
|
107
|
-
|
108
|
-
#Declares the overlay globally with name +name+
|
109
|
-
def overlay_global_init(overlay,name)
|
110
|
-
declare_global_init(overlay,name)
|
111
|
-
@init << add_overlay(overlay)
|
112
|
-
end
|
113
|
-
|
114
|
-
#Globally declare a MappingObject with variable name "name"
|
115
|
-
def declare_global_init(variable,name)
|
116
|
-
@global_init << variable.declare(name)
|
117
|
-
end
|
118
|
-
|
119
|
-
#Outputs the initialization code for the map. By default, it outputs the script tags, performs the initialization in reponse to the onload event of the window and makes the map globally available.
|
120
|
-
def to_html(options = {})
|
121
|
-
no_load = options[:no_load]
|
122
|
-
no_script_tag = options[:no_script_tag]
|
123
|
-
no_declare = options[:no_declare]
|
124
|
-
no_global = options[:no_global]
|
125
|
-
|
126
|
-
html = ""
|
127
|
-
html << "<script type=\"text/javascript\">\n" if !no_script_tag
|
128
|
-
#put the functions in a separate javascript file to be included in the page
|
129
|
-
html << "function addInfoWindowToMarker(marker,info){\nGEvent.addListener(marker, \"click\", function() {\nmarker.openInfoWindowHtml(info);\n});\nreturn marker;\n}\n"
|
130
|
-
html << "function addInfoWindowTabsToMarker(marker,info){\nGEvent.addListener(marker, \"click\", function() {\nmarker.openInfoWindowTabsHtml(info);\n});\nreturn marker;\n}\n"
|
131
|
-
html << "function addPropertiesToLayer(layer,getTile,copyright,opacity,isPng){\nlayer.getTileUrl = getTile;\nlayer.getCopyright = copyright;\nlayer.getOpacity = opacity;\nlayer.isPng = isPng;\nreturn layer;\n}\n"
|
132
|
-
html << "function addOptionsToIcon(icon,options){\nfor(var k in options){\nicon[k] = options[k];\n}\nreturn icon;\n}\n"
|
133
|
-
html << @global_init * "\n"
|
134
|
-
html << "var #{@variable};\n" if !no_declare and !no_global
|
135
|
-
html << "window.onload = function() {\nif (GBrowserIsCompatible()) {\n" if !no_load
|
136
|
-
if !no_declare and no_global
|
137
|
-
html << "#{declare(@variable)}\n"
|
138
|
-
else
|
139
|
-
html << "#{assign_to(@variable)}\n"
|
140
|
-
end
|
141
|
-
html << @init_begin * "\n"
|
142
|
-
html << @init * "\n"
|
143
|
-
html << @init_end * "\n"
|
144
|
-
html << "\n}\n}\n" if !no_load
|
145
|
-
html << "window.onunload = GUnload;\n"
|
146
|
-
html << "</script>" if !no_script_tag
|
147
|
-
html
|
148
|
-
end
|
149
|
-
|
150
|
-
#Outputs in JavaScript the creation of a GMap2 object
|
151
|
-
def create
|
152
|
-
"new GMap2(document.getElementById(\"#{@container}\"))"
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|