Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
27 jpm 1
// (c)2007 Mapstraction Team- http://mapstraction.com
2
 
3
function $m() { var elements = new Array(); for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string')
4
element = document.getElementById(element); if (arguments.length == 1)
5
return element; elements.push(element);}
6
return elements;}
7
function loadScript(src,callback) { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = src; if (callback) { var evl=new Object(); evl.handleEvent=function (e){callback();}; script.addEventListener('load',evl,true);}
8
document.getElementsByTagName("head")[0].appendChild(script); return;}
9
function convertLatLonXY_Yahoo(point,level){ var size = 1 << (26 - level); var pixel_per_degree = size / 360.0; var pixel_per_radian = size / (2 * Math.PI); var origin = new YCoordPoint(size / 2 , size / 2); var answer = new YCoordPoint(); answer.x = Math.floor(origin.x + point.lon * pixel_per_degree); var sin = Math.sin(point.lat * Math.PI / 180.0); answer.y = Math.floor(origin.y + 0.5 * Math.log((1 + sin) / (1 - sin)) * -pixel_per_radian); return answer;}
10
function loadStyle(href) { var link = document.createElement('link'); link.type = 'text/css'; link.rel = 'stylesheet'; link.href = href; document.getElementsByTagName("head")[0].appendChild(link); return;}
11
function getStyle(el, prop) { var y; if (el.currentStyle)
12
y = el.currentStyle[prop]; else if (window.getComputedStyle)
13
y = window.getComputedStyle( el, '').getPropertyValue(prop); return y;}
14
function lonToMetres (lon,lat) { return lon * 111200 * Math.cos(lat * (Math.PI/180));}
15
function metresToLon(m,lat) { return m / (111200*Math.cos(lat * (Math.PI/180)));}
16
function getDegreesFromGoogleZoomLevel (pixels,zoom)
17
{ return (360*pixels) / (Math.pow(2,zoom+8));}
18
function getGoogleZoomLevelFromDegrees (pixels,degrees)
19
{ return logN ((360*pixels)/degrees, 2) - 8;}
20
function logN (number,base)
21
{ return Math.log(number) / Math.log(base);}
22
function Mapstraction(element,api,debug) { this.api = api; this.maps = new Object(); this.currentElement = $m(element); this.eventListeners = new Array(); this.markers = new Array(); this.layers = new Array(); this.polylines = new Array(); this.images = new Array(); this.loaded = new Object(); this.onload = new Object(); if(debug == true)
23
{ this.debug = true
24
}
25
else
26
{ this.debug = false
27
}
28
this.svn_revision_string = '$Revision: 173 $'; this.addControlsArgs = new Object(); if (this.currentElement)
29
{ this.addAPI($m(element),api);}
30
}
31
Mapstraction.prototype.swap = function(element,api) { if (this.api == api) { return;}
32
var center = this.getCenter(); var zoom = this.getZoom(); this.currentElement.style.visibility = 'hidden'; this.currentElement.style.display = 'none'; this.currentElement = $m(element); this.currentElement.style.visibility = 'visible'; this.currentElement.style.display = 'block'; this.api = api; if (this.maps[this.api] == undefined) { this.addAPI($m(element),api); this.setCenterAndZoom(center,zoom); for (var i=0; i<this.markers.length; i++) { this.addMarker( this.markers[i], true);}
33
for (var i=0; i<this.polylines.length; i++) { this.addPolyline( this.polylines[i], true);}
34
}else{ this.setCenterAndZoom(center,zoom);}
35
this.addControls(this.addControlsArgs);}
36
Mapstraction.prototype.addAPI = function(element,api) { me = this; this.loaded[api] = false; this.onload[api] = new Array(); switch (api) { case 'yahoo':
37
if (YMap) { this.maps[api] = new YMap(element); YEvent.Capture(this.maps[api],EventsList.MouseClick,function(event,location) { me.clickHandler(location.Lat,location.Lon,location,me) }); YEvent.Capture(this.maps[api],EventsList.changeZoom,function() { me.moveendHandler(me) }); YEvent.Capture(this.maps[api],EventsList.endPan,function() { me.moveendHandler(me) }); this.loaded[api] = true;}
38
else { alert('Yahoo map script not imported');}
39
break; case 'google':
40
if (GMap2) { if (GBrowserIsCompatible()) { this.maps[api] = new GMap2(element); GEvent.addListener(this.maps[api], 'click', function(marker,location) { if ( location ) { me.clickHandler(location.y,location.x,location,me);}
41
}); GEvent.addListener(this.maps[api], 'moveend', function() {me.moveendHandler(me)}); this.loaded[api] = true;}
42
else { alert('browser not compatible with Google Maps');}
43
}
44
else { alert('Google map script not imported');}
45
break; case 'microsoft':
46
if (VEMap) { element.style.position='relative'; var msft_width = parseFloat(getStyle($m(element),'width')); var msft_height = parseFloat(getStyle($m(element),'height')); var ffv = 0; var ffn = "Firefox/"; var ffp = navigator.userAgent.indexOf(ffn); if (ffp != -1) ffv = parseFloat(navigator.userAgent.substring(ffp+ffn.length)); if (ffv >= 1.5) { Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }
47
}
48
this.maps[api] = new VEMap(element.id); this.maps[api].LoadMap(); this.maps[api].AttachEvent("onclick", function(e) { me.clickHandler(e.view.LatLong.Latitude, e.view.LatLong.Longitude, me);}); this.maps[api].AttachEvent("onchangeview", function(e) {me.moveendHandler(me)}); this.resizeTo(msft_width, msft_height); this.loaded[api] = true;}
49
else { alert('Virtual Earth script not imported');}
50
break; case 'openlayers':
51
this.maps[api] = new OpenLayers.Map( element.id, { maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), maxResolution:156543, numZoomLevels:18, units:'meters', projection: "EPSG:41001"
52
} ); this.layers['osmmapnik'] = new OpenLayers.Layer.TMS( 'OSM Mapnik', [ "http://a.tile.openstreetmap.org/", "http://b.tile.openstreetmap.org/", "http://c.tile.openstreetmap.org/" ], { type:'png', getURL: function (bounds) { var res = this.map.getResolution(); var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w)); var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h)); var z = this.map.getZoom(); var limit = Math.pow(2, z); if (y < 0 || y >= limit) { return null;} else { x = ((x % limit) + limit) % limit; var path = z + "/" + x + "/" + y + "." + this.type; var url = this.url; if (url instanceof Array) { url = this.selectUrl(path, url);}
53
return url + path;}
54
}, displayOutsideMaxExtent: true
55
} ); this.layers['osm'] = new OpenLayers.Layer.TMS( 'OSM', [ "http://a.tah.openstreetmap.org/Tiles/tile.php/", "http://b.tah.openstreetmap.org/Tiles/tile.php/", "http://c.tah.openstreetmap.org/Tiles/tile.php/" ], { type:'png', getURL: function (bounds) { var res = this.map.getResolution(); var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w)); var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h)); var z = this.map.getZoom(); var limit = Math.pow(2, z); if (y < 0 || y >= limit) { return null;} else { x = ((x % limit) + limit) % limit; var path = z + "/" + x + "/" + y + "." + this.type; var url = this.url; if (url instanceof Array) { url = this.selectUrl(path, url);}
56
return url + path;}
57
}, displayOutsideMaxExtent: true
58
} ); this.maps[api].addLayer(this.layers['osmmapnik']); this.maps[api].addLayer(this.layers['osm']); this.loaded[api] = true; break; case 'openstreetmap':
59
if (GMap2) { if (GBrowserIsCompatible()) { this.maps[api] = new GMap2(element); GEvent.addListener(this.maps[api], 'click', function(marker,location) { if ( location ) { me.clickHandler(location.y,location.x,location,me);}
60
}); GEvent.addListener(this.maps[api], 'moveend', function() {me.moveendHandler(me)}); var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90,-180), new GLatLng(90,180)), 0, "copyleft"); var copyrightCollection = new GCopyrightCollection('OSM'); copyrightCollection.addCopyright(copyright); var tilelayers = new Array(); tilelayers[0] = new GTileLayer(copyrightCollection, 1, 18); tilelayers[0].getTileUrl = function (a, b) { return "http://tile.openstreetmap.org/"+b+"/"+a.x+"/"+a.y+".png";}; tilelayers[0].isPng = function() { return true;}; tilelayers[0].getOpacity = function() { return 1.0;}
61
var custommap = new GMapType(tilelayers, new GMercatorProjection(19), "OSM", {errorMessage:"More OSM coming soon"}); this.maps[api].addMapType(custommap); this.loaded[api] = true; var myPoint = new LatLonPoint(50.6805,-1.4062505); this.setCenterAndZoom(myPoint, 11); this.maps[api].setMapType(custommap);}
62
else { alert('browser not compatible with Google Maps');}
63
}
64
else { alert('Google map script not imported');}
65
break; case 'multimap':
66
this.maps[api] = new MultimapViewer( element ); this.maps[api].addEventHandler( 'click', function(eventType, eventTarget, arg1, arg2, arg3) { if (arg1) { me.clickHandler(arg1.lat, arg1.lon, me);}
67
}); this.maps[api].addEventHandler( 'changeZoom', function(eventType, eventTarget, arg1, arg2, arg3) { me.moveendHandler(me);}); this.maps[api].addEventHandler( 'endPan', function(eventType, eventTarget, arg1, arg2, arg3) { me.moveendHandler(me);}); this.loaded[api] = true; break; case 'map24':
68
if (Map24) { Map24.loadApi(["core_api","wrapper_api"] , function() { Map24.MapApplication.init
69
( { NodeName: element.id, MapType: "Static" } ); me.maps[api] = Map24.MapApplication.Map; Map24.MapApplication.Map.addListener('Map24.Event.MapClick', function(e) { me.clickHandler(e.Coordinate.Latitude/60, e.Coordinate.Longitude/60, me); e.stop();} ); Map24.MapApplication.Map.addListener("MapPanStop", function(e) { me.moveendHandler(me);} ); var client=Map24.MapApplication.Map.MapClient['Static']; me.loaded[api] = true; for (var i = 0; i < me.onload[api].length; i++) { me.onload[api][i]();}
70
}, "2.0.1247" );} else { alert('map24 api not loaded');}
71
break; case 'mapquest':
72
myself = this; MQInitOverlays( function() { myself.loaded[api] = true; myself.maps[api] = new MQTileMap(element); for (var i = 0; i < myself.onload[api].length; i++) { myself.onload[api][i]();}
73
}); break; case 'freeearth':
74
this.maps[api] = new FE.Map($m(element)); myself = this; this.maps[api].onLoad = function() { myself.freeEarthLoaded = true; myself.loaded[api] = true; for (var i = 0; i < myself.onload[api].length; i++) { myself.onload[api][i]();}
75
}
76
this.maps[api].load(); break; default:
77
if(this.debug)
78
alert(api + ' not supported by mapstraction');}
79
}
80
Mapstraction._getScriptLocation=function(){ var scriptLocation=""; var SCRIPT_NAME = "mapstraction.js"; var scripts=document.getElementsByTagName('script'); for(var i=0; i<scripts.length; i++) { var src=scripts[i].getAttribute('src'); if(src) { var index=src.lastIndexOf(SCRIPT_NAME); if((index>-1)&&(index+SCRIPT_NAME.length==src.length)){scriptLocation=src.slice(0,-SCRIPT_NAME.length); break;}
81
}
82
}
83
return scriptLocation;}
84
Mapstraction.writeInclude = function(api, key, version) { var jsfiles=new Array(); var allScriptTags=""; var host=Mapstraction._getScriptLocation()+"lib/"; switch(api) { case 'google':
85
if(version == null) { version = "2";}
86
jsfiles.push('http://maps.google.com/maps?file=api&v=' + version + '&key=' + key); break; case "microsoft":
87
if(version == null) { version = "v3";}
88
jsfiles.push('http://dev.virtualearth.net/mapcontrol/' + version + '/mapcontrol.js'); break; case "yahoo":
89
if(version == null) { version = "3.0";}
90
jsfiles.push('http://api.maps.yahoo.com/ajaxymap?v='+ version + '&appid=' + key); break; case "openlayers":
91
jsfiles.push('http://openlayers.org/api/OpenLayers.js'); break; case "multimap":
92
if(version == null) { version = "1.2";}
93
jsfiles.push('http://developer.multimap.com/API/maps/' + version + '/' + key); break; case "map24":
94
jsfiles.push('http://api.maptp.map24.com/ajax?appkey=' + key); break; case "mapquest":
95
if(version == null) { version = "5.1";}
96
jsfiles.push('http://btilelog.access.mapquest.com/tilelog/transaction?transaction=script&key=' + key + '&ipr=true&itk=true&v=' + version); jsfiles.push('mapquest-js/mqcommon.js'); jsfiles.push('mapquest-js/mqutils.js'); jsfiles.push('mapquest-js/mqobjects.js'); jsfiles.push('mapquest-js/mqexec.js'); break; case "freeearth":
97
jsfiles.push('http://freeearth.poly9.com/api.js');}
98
for(var i=0; i<jsfiles.length; i++) { if(/MSIE/.test(navigator.userAgent)||/Safari/.test(navigator.userAgent)) { var currentScriptTag = jsfiles[i]; allScriptTags += currentScriptTag;} else { var s=document.createElement("script"); s.src=jsfiles[i]; s.type="text/javascript"; var h=document.getElementsByTagName("head").length ? document.getElementsByTagName("head")[0] : document.body; h.appendChild(s);}
99
}
100
if(allScriptTags) document.write(allScriptTags);}
101
Mapstraction.prototype.isLoaded = function(api){ if(api == null)
102
api = this.api; return this.loaded[api];}
103
Mapstraction.prototype.setDebug = function(debug){ if(debug != null)
104
return this.debug = debug; else
105
return this.debug;}
106
Mapstraction.prototype.resizeTo = function(width,height){ if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.resizeTo(width,height);} ); return;}
107
switch (this.api) { case 'yahoo':
108
this.maps[this.api].resizeTo(new YSize(width,height)); break; case 'google':
109
case 'openstreetmap':
110
this.currentElement.style.width = width; this.currentElement.style.height = height; this.maps[this.api].checkResize(); break; case 'openlayers':
111
this.currentElement.style.width = width; this.currentElement.style.height = height; this.maps[this.api].updateSize(); break; case 'microsoft':
112
this.maps[this.api].Resize(width, height); break; case 'multimap':
113
this.currentElement.style.width = width; this.currentElement.style.height = height; this.maps[this.api].resize(); break; case 'mapquest':
114
this.currentElement.style.width = width; this.currentElement.style.height = height; this.maps[this.api].setSize(new MQSize(width, height)); break; case 'map24':
115
Map24.MapApplication.Map.Canvas['c'].resizeTo(width,height); break;}
116
}
117
Mapstraction.prototype.clickHandler = function(lat,lon, me) { for(var i = 0; i < this.eventListeners.length; i++) { if(this.eventListeners[i][1] == 'click') { this.eventListeners[i][0](new LatLonPoint(lat,lon));}
118
}
119
}
120
Mapstraction.prototype.moveendHandler = function(me) { for(var i = 0; i < this.eventListeners.length; i++) { if(this.eventListeners[i][1] == 'moveend') { this.eventListeners[i][0]();}
121
}
122
}
123
Mapstraction.prototype.addEventListener = function(type, func) { var listener = new Array(); listener.push(func); listener.push(type); this.eventListeners.push(listener); switch (this.api) { case 'openlayers':
124
this.maps[this.api].events.register(type, this, func); break;}
125
}
126
Mapstraction.prototype.addControls = function( args ) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addControls(args);} ); return;}
127
var map = this.maps[this.api]; this.addControlsArgs = args; switch (this.api) { case 'google':
128
case 'openstreetmap':
129
if (this.controls) { while (ctl = this.controls.pop()) { map.removeControl(ctl);}
130
} else { this.controls = new Array();}
131
c = this.controls; if ( args.zoom || args.pan ) { if ( args.zoom == 'large' ) { c.unshift(new GLargeMapControl()); map.addControl(c[0]);} else { c.unshift(new GSmallMapControl()); map.addControl(c[0]);}
132
}
133
if ( args.scale ) { c.unshift(new GScaleControl()); map.addControl(c[0]);}
134
if (this.api != "openstreetmap") { if ( args.overview ) { c.unshift(new GOverviewMapControl()); map.addControl(c[0]);}
135
if ( args.map_type ) { c.unshift(new GMapTypeControl()); map.addControl(c[0]);}
136
}
137
break; case 'yahoo':
138
if ( args.pan ) map.addPanControl(); else map.removePanControl(); if ( args.zoom == 'large' ) map.addZoomLong(); else if ( args.zoom == 'small' ) map.addZoomShort(); else map.removeZoomScale(); break; case 'openlayers':
139
for (var i = map.controls.length; i>1; i--) { map.controls[i-1].deactivate(); map.removeControl(map.controls[i-1]);}
140
if ( args.pan ) { map.addControl(new OpenLayers.Control.PanZoomBar());}
141
else { }
142
if ( args.zoom == 'large' ) { map.addControl(new OpenLayers.Control.PanZoomBar());}
143
else if ( args.zoom == 'small' ) { map.addControl(new OpenLayers.Control.ZoomBox());}
144
else map.addControl(new OpenLayers.Control.ZoomBox()); if ( args.overview ) { map.addControl(new OpenLayers.Control.OverviewMap());}
145
if ( args.map_type ) { map.addControl(new OpenLayers.Control.LayerSwitcher());}
146
break; case 'multimap':
147
pan_zoom_widget = "MM"; if (args.zoom && args.zoom == "small") { pan_zoom_widget = pan_zoom_widget + "Small";}
148
if (args.pan) { pan_zoom_widget = pan_zoom_widget + "Pan";}
149
if (args.zoom) { pan_zoom_widget = pan_zoom_widget + "Zoom";}
150
pan_zoom_widget = pan_zoom_widget + "Widget"; if (pan_zoom_widget != "MMWidget") { eval(" map.addWidget( new " + pan_zoom_widget + "() );");}
151
if ( args.map_type ) { map.addWidget( new MMMapTypeWidget() );}
152
if ( args.overview ) { map.addWidget( new MMOverviewWidget() );}
153
break; case 'mapquest':
154
if (this.controls) { while (ctl = this.controls.pop()) { map.removeControl(ctl);}
155
} else { this.controls = new Array();}
156
c = this.controls; if ( args.pan ) { c.unshift(new MQPanControl()); map.addControl(c[0], new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,0)));}
157
if ( args.zoom == 'large' ) { c.unshift(new MQLargeZoomControl()); map.addControl(c[0], new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,0)));}
158
else if ( args.zoom == 'small' ) { c.unshift(new MQZoomControl()); map.addControl(c[0], new MQMapCornerPlacement(MQMapCorner.BOTTOM_LEFT, new MQSize(0,0)));}
159
if ( args.map_type ) { c.unshift(new MQViewControl()); map.addControl(c[0], new MQMapCornerPlacement(MQMapCorner.TOP_RIGHT, new MQSize(0,0)));}
160
break;}
161
}
162
Mapstraction.prototype.addSmallControls = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addSmallControls();} ); return;}
163
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
164
map.addPanControl(); map.addZoomShort(); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'small'; break; case 'google':
165
case 'openstreetmap':
166
map.addControl(new GSmallMapControl()); this.addControlsArgs.zoom = 'small'; break; case 'openlayers':
167
map.addControl(new OpenLayers.Control.ZoomBox()); map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); break; case 'multimap':
168
smallPanzoomWidget = new MMSmallPanZoomWidget(); map.addWidget( smallPanzoomWidget ); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'small'; break; case 'mapquest':
169
map.addControl(new MQZoomControl(map)); map.addControl(new PanControl(map)); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'small'; break;}
170
}
171
Mapstraction.prototype.addLargeControls = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addLargeControls();} ); return;}
172
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
173
map.addPanControl(); map.addZoomLong(); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'large'; break; case 'openlayers':
174
map.addControl(new OpenLayers.Control.PanZoomBar()); break; case 'google':
175
map.addControl(new GMapTypeControl()); map.addControl(new GOverviewMapControl()) ; this.addControlsArgs.overview = true; this.addControlsArgs.map_type = true; case 'openstreetmap':
176
map.addControl(new GLargeMapControl()); map.addControl(new GScaleControl()) ; this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'large'; this.addControlsArgs.scale = true; break; case 'multimap':
177
panzoomWidget = new MMPanZoomWidget(); map.addWidget( panzoomWidget ); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'large'; break; case 'mapquest':
178
map.addControl(new MQLargeZoomControl(map)); map.addControl(new PanControl(map)); map.addControl(new MQViewControl(map)); this.addControlsArgs.pan = true; this.addControlsArgs.zoom = 'large'; this.addControlsArgs.map_type = true; break;}
179
}
180
Mapstraction.prototype.addMapTypeControls = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addMapTypeControls();} ); return;}
181
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
182
map.addTypeControl(); break; case 'google':
183
case 'openstreetmap':
184
map.addControl(new GMapTypeControl()); break; case 'multimap':
185
map.addWidget( new MMMapTypeWidget() ); break; case 'mapquest':
186
map.addControl(new MQViewControl(map)); break; case 'openlayers':
187
map.addControl( new OpenLayers.Control.LayerSwitcher({'ascending':false}) ); break;}
188
}
189
Mapstraction.prototype.dragging = function(on) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.dragging(on);} ); return;}
190
var map = this.maps[this.api]; switch (this.api) { case 'google':
191
case 'openstreetmap':
192
if (on) { map.enableDragging();} else { map.disableDragging();}
193
break; case 'yahoo':
194
if (on) { map.enableDragMap();} else { map.disableDragMap();}
195
break; case 'multimap':
196
if (on) { map.setOption("drag","dragmap");} else { map.setOption("drag","");}
197
break; case 'mapquest':
198
map.enableDragging(on); break;}
199
}
200
Mapstraction.prototype.setCenterAndZoom = function(point, zoom) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.setCenterAndZoom(point, zoom);} ); return;}
201
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
202
var yzoom = 18 - zoom; map.drawZoomAndCenter(point.toYahoo(),yzoom); break; case 'google':
203
case 'openstreetmap':
204
map.setCenter(point.toGoogle(), zoom); break; case 'microsoft':
205
map.SetCenterAndZoom(point.toMicrosoft(),zoom); break; case 'openlayers':
206
map.setCenter(point.toOpenLayers(), zoom); break; case 'multimap':
207
map.goToPosition( new MMLatLon( point.lat, point.lng ) ); map.setZoomFactor( zoom ); break; case 'map24':
208
var newSettings = new Object(); newSettings.Latitude = point.lat*60; newSettings.Longitude = point.lon*60; var client = map.MapClient['Static']; var dLon = getDegreesFromGoogleZoomLevel
209
(client.getCanvasSize().Width,zoom); newSettings.MinimumWidth = lonToMetres (dLon, point.lat); Map24.MapApplication.center ( newSettings ); break; case 'mapquest':
210
map.setCenter(new MQLatLng( point.lat, point.lng ), zoom - 3 ); break; case 'freeearth':
211
if (this.freeEarthLoaded) { map.setTargetLatLng( point.toFreeEarth() );} else { myself = this; this.freeEarthOnLoad.push( function() { myself.setCenterAndZoom(point);} );}
212
break; default:
213
if(this.debug)
214
alert(this.api + ' not supported by Mapstraction.setCenterAndZoom');}
215
}
216
Mapstraction.prototype.addMarker = function(marker,old) { var map = this.maps[this.api]; marker.mapstraction = this; marker.api = this.api; marker.map = this.maps[this.api]; if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addMarker(marker, old);} ); return;}
217
switch (this.api) { case 'yahoo':
218
var ypin = marker.toYahoo(); marker.setChild(ypin); map.addOverlay(ypin); if (! old) { this.markers.push(marker);}
219
break; case 'google':
220
case 'openstreetmap':
221
var gpin = marker.toGoogle(); marker.setChild(gpin); map.addOverlay(gpin); if (! old) { this.markers.push(marker);}
222
break; case 'microsoft':
223
var mpin = marker.toMicrosoft(); marker.setChild(mpin); map.AddPushpin(mpin); if (! old) { this.markers.push(marker);}
224
break; case 'openlayers':
225
if (!this.layers['markers'])
226
{ this.layers['markers'] = new OpenLayers.Layer.Markers("markers"); map.addLayer(this.layers['markers']);}
227
var olmarker = marker.toOpenLayers(); marker.setChild(olmarker); this.layers['markers'].addMarker(olmarker); if (! old) { this.markers.push(marker);}
228
break; case 'multimap':
229
var mmpin = marker.toMultiMap(); marker.setChild(mmpin); map.addOverlay(mmpin); if (! old) { this.markers.push(marker);}
230
break; case 'map24':
231
var m24pin = marker.toMap24(); marker.setChild(m24pin); m24pin.commit(); if (! old) { this.markers.push(marker);}
232
break; case 'mapquest':
233
var mqpin = marker.toMapQuest(); marker.setChild(mqpin); map.addPoi(mqpin); if (! old) { this.markers.push(marker);}
234
break; case 'freeearth':
235
var fepin = marker.toFreeEarth(); marker.setChild(fepin); map.addOverlay(fepin); if (! old) { this.markers.push(marker);}
236
break; default:
237
if(this.debug)
238
alert(this.api + ' not supported by Mapstraction.addMarker');}
239
}
240
Mapstraction.prototype.addMarkerWithData = function(marker,data) { marker.addData(data); this.addMarker(marker);}
241
Mapstraction.prototype.addPolylineWithData = function(polyline,data) { polyline.addData(data); this.addPolyline(polyline);}
242
Mapstraction.prototype.removeMarker = function(marker) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.removeMarker(marker);} ); return;}
243
var map = this.maps[this.api]; var tmparray = new Array(); while(this.markers.length > 0){ current_marker = this.markers.pop(); if(marker == current_marker) { switch (this.api) { case 'google':
244
case 'openstreetmap':
245
map.removeOverlay(marker.proprietary_marker); break; case 'yahoo':
246
map.removeOverlay(marker.proprietary_marker); break; case 'microsoft':
247
map.DeletePushpin(marker.pinID); break; case 'multimap':
248
map.removeOverlay(marker.proprietary_marker); break; case 'mapquest':
249
map.removePoi(marker.proprietary_marker); break; case 'map24':
250
marker.proprietary_marker.remove(); break; case 'openlayers':
251
this.layers['markers'].removeMarker(marker.proprietary_marker); marker.proprietary_marker.destroy(); break;}
252
marker.onmap = false; break;} else { tmparray.push(current_marker);}
253
}
254
this.markers = this.markers.concat(tmparray);}
255
Mapstraction.prototype.removeAllMarkers = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.removeAllMarkers();} ); return;}
256
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
257
map.removeMarkersAll(); break; case 'google':
258
case 'openstreetmap':
259
map.clearOverlays(); break; case 'microsoft':
260
map.DeleteAllPushpins(); break; case 'multimap':
261
map.removeAllOverlays(); break; case 'mapquest':
262
map.removeAllPois(); break; case 'map24':
263
var current_marker; while(this.markers.length > 0) { current_marker = this.markers.pop(); current_marker.proprietary_marker.remove();}
264
break; case 'openlayers':
265
this.layers['markers'].clearMarkers(); break; default:
266
if(this.debug)
267
alert(this.api + ' not supported by Mapstraction.removeAllMarkers');}
268
this.markers = new Array();}
269
Mapstraction.prototype.addPolyline = function(polyline,old) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addPolyline(polyline,old);} ); return;}
270
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
271
ypolyline = polyline.toYahoo(); polyline.setChild(ypolyline); map.addOverlay(ypolyline); if(!old) {this.polylines.push(polyline);}
272
break; case 'google':
273
case 'openstreetmap':
274
gpolyline = polyline.toGoogle(); polyline.setChild(gpolyline); map.addOverlay(gpolyline); if(!old) {this.polylines.push(polyline);}
275
break; case 'microsoft':
276
mpolyline = polyline.toMicrosoft(); polyline.setChild(mpolyline); map.AddPolyline(mpolyline); if(!old) {this.polylines.push(polyline);}
277
break; case 'openlayers':
278
if(this.debug)
279
alert(this.api + ' not supported by Mapstraction.addPolyline'); break; case 'multimap':
280
mmpolyline = polyline.toMultiMap(); polyline.setChild(mmpolyline); map.addOverlay( mmpolyline ); if(!old) {this.polylines.push(polyline);}
281
break; case 'mapquest':
282
mqpolyline = polyline.toMapQuest(); polyline.setChild(mqpolyline); map.addOverlay( mqpolyline ); if(!old) {this.polylines.push(polyline);}
283
break; case 'map24':
284
var m24polyline = polyline.toMap24(); polyline.setChild(m24polyline); m24polyline.commit(); if(!old) {this.polylines.push(polyline);}
285
break; default:
286
if(this.debug)
287
alert(this.api + ' not supported by Mapstraction.addPolyline');}
288
}
289
Mapstraction.prototype.removePolyline = function(polyline) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.removePolyline(polyline);} ); return;}
290
var map = this.maps[this.api]; var tmparray = new Array(); while(this.polylines.length > 0){ current_polyline = this.polylines.pop(); if(polyline == current_polyline) { switch (this.api) { case 'google':
291
case 'openstreetmap':
292
map.removeOverlay(polyline.proprietary_polyline); break; case 'yahoo':
293
map.removeOverlay(polyline.proprietary_polyline); break; case 'microsoft':
294
map.DeletePolyline(polyline.pllID); break; case 'multimap':
295
polyline.proprietary_polyline.remove(); break; case 'mapquest':
296
map.removeOverlay(polyline.proprietary_polyline); break; case 'map24':
297
polyline.proprietary_polyline.remove(); break;}
298
polyline.onmap = false; break;} else { tmparray.push(current_polyline);}
299
}
300
this.polylines = this.polylines.concat(tmparray);}
301
Mapstraction.prototype.removeAllPolylines = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.removeAllPolylines();} ); return;}
302
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
303
for(var i = 0, length = this.polylines.length;i < length;i++){ map.removeOverlay(this.polylines[i].proprietary_polyline);}
304
break; case 'google':
305
case 'openstreetmap':
306
for(var i = 0, length = this.polylines.length;i < length;i++){ map.removeOverlay(this.polylines[i].proprietary_polyline);}
307
break; case 'microsoft':
308
map.DeleteAllPolylines(); break; case 'multimap':
309
for(var i = 0, length = this.polylines.length;i < length;i++){ this.polylines[i].proprietary_polyline.remove();}
310
break; case 'mapquest':
311
map.removeAllOverlays(); break; case 'map24':
312
var current_polyline; while(this.polylines.length > 0) { current_polyline = this.polylines.pop(); current_polyline.proprietary_polyline.remove();}
313
break; default:
314
if(this.debug)
315
alert(this.api + ' not supported by Mapstraction.removeAllPolylines');}
316
this.polylines = new Array();}
317
Mapstraction.prototype.getCenter = function() { if(this.loaded[this.api] == false) { return null;}
318
var map = this.maps[this.api]; var point = undefined; switch (this.api) { case 'yahoo':
319
var pt = map.getCenterLatLon(); point = new LatLonPoint(pt.Lat,pt.Lon); break; case 'google':
320
case 'openstreetmap':
321
var pt = map.getCenter(); point = new LatLonPoint(pt.lat(),pt.lng()); break; case 'openlayers':
322
var pt = map.getCenter(); point = new LatLonPoint(pt.lat, pt.lon); break; case 'microsoft':
323
var pt = map.GetCenter(); point = new LatLonPoint(pt.Latitude,pt.Longitude); break; case 'multimap':
324
var pt = map.getCurrentPosition(); point = new LatLonPoint(pt.y, pt.x); break; case 'mapquest':
325
var pt = map.getCenter(); point = new LatLonPoint(pt.getLatitude(), pt.getLongitude()); break; case 'map24':
326
var pt = map.MapClient['Static'].getCurrentMapView().getCenter(); point = new LatLonPoint(pt.Y/60,pt.X/60); break; default:
327
if(this.debug)
328
alert(this.api + ' not supported by Mapstraction.getCenter');}
329
return point;}
330
Mapstraction.prototype.setCenter = function(point) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.setCenter(point);} ); return;}
331
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
332
map.panToLatLon(point.toYahoo()); break; case 'google':
333
case 'openstreetmap':
334
map.setCenter(point.toGoogle()); break; case 'openlayers':
335
map.setCenter(point.toOpenLayers()); break; case 'microsoft':
336
map.SetCenter(point.toMicrosoft()); break; case 'multimap':
337
map.goToPosition(point.toMultiMap()); break; case 'mapquest':
338
map.setCenter(point.toMapQuest()); break; case 'freeearth':
339
if (this.freeEarthLoaded) { map.setTargetLatLng( point.toFreeEarth() );} else { myself = this; this.freeEarthOnLoad.push( function() { myself.setCenterAndZoom(point);} );}
340
break; case 'map24':
341
var mv = map.MapClient['Static'].getCurrentMapView(); var newSettings = new Object(); newSettings.MinimumWidth = lonToMetres
342
(mv.LowerRight.Longitude - mv.TopLeft.Longitude, (mv.LowerRight.Latitude+mv.TopLeft.Latitude)/2); newSettings.Latitude = point.lat*60; newSettings.Longitude = point.lon*60; Map24.MapApplication.center(newSettings); break; default:
343
if(this.debug)
344
alert(this.api + ' not supported by Mapstraction.setCenter');}
345
}
346
Mapstraction.prototype.setZoom = function(zoom) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.setZoom(zoom);} ); return;}
347
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
348
var yzoom = 18 - zoom; map.setZoomLevel(yzoom); break; case 'google':
349
case 'openstreetmap':
350
map.setZoom(zoom); break; case 'openlayers':
351
map.zoomTo(zoom); break; case 'microsoft':
352
map.SetZoomLevel(zoom); break; case 'multimap':
353
map.setZoomFactor(zoom); break; case 'mapquest':
354
map.setZoomLevel(zoom - 3); break; case 'map24':
355
var point = this.getCenter(); var newSettings = new Object(); newSettings.Latitude = point.lat*60; newSettings.Longitude = point.lon*60; var client = map.MapClient['Static']; var dLon = getDegreesFromGoogleZoomLevel
356
(client.getCanvasSize().Width,zoom); newSettings.MinimumWidth = lonToMetres (dLon, point.lat); Map24.MapApplication.center ( newSettings ); break; default:
357
if(this.debug)
358
alert(this.api + ' not supported by Mapstraction.setZoom');}
359
}
360
Mapstraction.prototype.autoCenterAndZoom = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.autoCenterAndZoom();} ); return;}
361
var lat_max = -90; var lat_min = 90; var lon_max = -180; var lon_min = 180; for (var i=0; i<this.markers.length; i++) {; lat = this.markers[i].location.lat; lon = this.markers[i].location.lon; if (lat > lat_max) lat_max = lat; if (lat < lat_min) lat_min = lat; if (lon > lon_max) lon_max = lon; if (lon < lon_min) lon_min = lon;}
362
for (i=0; i<this.polylines.length; i++) { for (j=0; j<this.polylines[i].points.length; j++) { lat = this.polylines[i].points[j].lat; lon = this.polylines[i].points[j].lon; if (lat > lat_max) lat_max = lat; if (lat < lat_min) lat_min = lat; if (lon > lon_max) lon_max = lon; if (lon < lon_min) lon_min = lon;}
363
}
364
this.setBounds( new BoundingBox(lat_min, lon_min, lat_max, lon_max) );}
365
Mapstraction.prototype.centerAndZoomOnPoints = function(points) { var bounds = new BoundingBox(points[0].lat,points[0].lon,points[0].lat,points[0].lon); for (var i=1, len = points.length ; i<len; i++) { bounds.extend(points[i]);}
366
this.setBounds(bounds);}
367
Mapstraction.prototype.getZoom = function() { if(this.loaded[this.api] == false) { myself = this; return -1;}
368
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
369
return 18 - map.getZoomLevel(); case 'google':
370
case 'openstreetmap':
371
return map.getZoom(); case 'openlayers':
372
return map.zoom; case 'microsoft':
373
return map.GetZoomLevel(); case 'multimap':
374
return map.getZoomFactor(); case 'mapquest':
375
return map.getZoomLevel() + 3; case 'map24':
376
var mv = map.MapClient['Static'].getCurrentMapView(); var dLon = (mv.LowerRight.Longitude - mv.TopLeft.Longitude) / 60; var width = map.MapClient['Static'].getCanvasSize().Width; var zoom = getGoogleZoomLevelFromDegrees (width,dLon); return Math.round(zoom); default:
377
if(this.debug)
378
alert(this.api + ' not supported by Mapstraction.getZoom');}
379
}
380
Mapstraction.prototype.getZoomLevelForBoundingBox = function( bbox ) { if(this.loaded[this.api] == false) { myself = this; return -1;}
381
var map = this.maps[this.api]; var ne = bbox.getNorthEast(); var sw = bbox.getSouthWest(); switch (this.api) { case 'google':
382
case 'openstreetmap':
383
var gbox = new GLatLngBounds( sw.toGoogle(), ne.toGoogle() ); var zoom = map.getBoundsZoomLevel( gbox ); return zoom; break; case 'openlayers':
384
var olbox = bbox.toOpenLayers(); var zoom = map.getZoomForExtent(olbox); break; case 'multimap':
385
var mmlocation = map.getBoundsZoomFactor( sw.toMultiMap(), ne.toMultiMap() ); var zoom = mmlocation.zoom_factor(); return zoom; break; case 'map24':
386
var dLon = ne.lon - sw.lon; var width = map.MapClient['Static'].getCanvasSize().Width; var zoom = getGoogleZoomLevelFromDegrees (width,dLon); return Math.round(zoom); break; default:
387
if(this.debug)
388
alert( this.api + ' not supported by Mapstraction.getZoomLevelForBoundingBox' );}
389
}
390
Mapstraction.ROAD = 1; Mapstraction.SATELLITE = 2; Mapstraction.HYBRID = 3; Mapstraction.prototype.setMapType = function(type) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.setMapType(type);} ); return;}
391
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
392
switch(type) { case Mapstraction.ROAD:
393
map.setMapType(YAHOO_MAP_REG); break; case Mapstraction.SATELLITE:
394
map.setMapType(YAHOO_MAP_SAT); break; case Mapstraction.HYBRID:
395
map.setMapType(YAHOO_MAP_HYB); break; default:
396
map.setMapType(YAHOO_MAP_REG);}
397
break; case 'google':
398
case 'openstreetmap':
399
switch(type) { case Mapstraction.ROAD:
400
map.setMapType(G_NORMAL_MAP); break; case Mapstraction.SATELLITE:
401
map.setMapType(G_SATELLITE_MAP); break; case Mapstraction.HYBRID:
402
map.setMapType(G_HYBRID_MAP); break; default:
403
map.setMapType(G_NORMAL_MAP);}
404
break; case 'microsoft':
405
switch(type) { case Mapstraction.ROAD:
406
map.SetMapStyle(Msn.VE.MapStyle.Road); break; case Mapstraction.SATELLITE:
407
map.SetMapStyle(Msn.VE.MapStyle.Aerial); break; case Mapstraction.HYBRID:
408
map.SetMapStyle(Msn.VE.MapStyle.Hybrid); break; default:
409
map.SetMapStyle(Msn.VE.MapStyle.Road);}
410
break; case 'multimap':
411
maptypes = map.getAvailableMapTypes(); maptype = -1; for (var i = 0; i < maptypes.length; i++) { switch (maptypes[i]) { case MM_WORLD_MAP:
412
if (type == Mapstraction.ROAD) { maptype = maptypes[i];}
413
default_type = maptypes[i]; break; case MM_WORLD_AERIAL:
414
if (type == Mapstraction.SATELLITE) { maptype = maptypes[i];}
415
break; case MM_WORLD_HYBRID:
416
if (type == Mapstraction.HYBRID) { maptype = maptypes[i];}
417
break;}
418
}
419
if (maptype == -1) { maptype = default_type;}
420
map.setMapType(maptype); break; case 'mapquest':
421
switch (type) { case Mapstraction.ROAD:
422
map.setMapType("map"); break; case Mapstraction.SATELLITE:
423
map.setMapType("sat"); break; case Mapstraction.HYBRID:
424
map.setMapType("hyb"); break;}
425
break; default:
426
if(this.debug)
427
alert(this.api + ' not supported by Mapstraction.setMapType');}
428
}
429
Mapstraction.prototype.getMapType = function() { if(this.loaded[this.api] == false) { myself = this; return -1;}
430
var map = this.maps[this.api]; var type; switch (this.api) { case 'yahoo':
431
type = map.getCurrentMapType(); switch(type) { case YAHOO_MAP_REG:
432
return Mapstraction.ROAD; break; case YAHOO_MAP_SAT:
433
return Mapstraction.SATELLITE; break; case YAHOO_MAP_HYB:
434
return Mapstraction.HYBRID; break; default:
435
return null;}
436
break; case 'google':
437
case 'openstreetmap':
438
type = map.getCurrentMapType(); switch(type) { case G_NORMAL_MAP:
439
return Mapstraction.ROAD; break; case G_SATELLITE_MAP:
440
return Mapstraction.SATELLITE; break; case G_HYBRID_MAP:
441
return Mapstraction.HYBRID; break; default:
442
return null;}
443
break; case 'microsoft':
444
type = map.GetMapStyle(); switch(type) { case Msn.VE.MapStyle.Road:
445
return Mapstraction.ROAD; break; case Msn.VE.MapStyle.Aerial:
446
return Mapstraction.SATELLITE; break; case Msn.VE.MapStyle.Hybrid:
447
return Mapstraction.HYBRID; break; default:
448
return null;}
449
break; case 'multimap':
450
maptypes = map.getAvailableMapTypes(); type = map.getMapType(); switch(type) { case MM_WORLD_MAP:
451
return Mapstraction.ROAD; break; case MM_WORLD_AERIAL:
452
return Mapstraction.SATELLITE; break; case MM_WORLD_HYBRID:
453
return Mapstraction.HYBRID; break; default:
454
return null;}
455
break; case 'mapquest':
456
type = map.getMapType(); switch(type) { case "map":
457
return Mapstraction.ROAD; break; case "sat":
458
return Mapstraction.SATELLITE; break; case "hyb":
459
return Mapstraction.HYBRID; break; default:
460
return null;}
461
break; default:
462
if(this.debug)
463
alert(this.api + ' not supported by Mapstraction.getMapType');}
464
}
465
Mapstraction.prototype.getBounds = function () { if(this.loaded[this.api] == false) { return null;}
466
var map = this.maps[this.api]; switch (this.api) { case 'google':
467
case 'openstreetmap':
468
var gbox = map.getBounds(); var sw = gbox.getSouthWest(); var ne = gbox.getNorthEast(); return new BoundingBox(sw.lat(), sw.lng(), ne.lat(), ne.lng()); break; case 'openlayers':
469
var olbox = map.calculateBounds(); break; case 'yahoo':
470
var ybox = map.getBoundsLatLon(); return new BoundingBox(ybox.LatMin, ybox.LonMin, ybox.LatMax, ybox.LonMax); break; case 'microsoft':
471
var mbox = map.GetMapView(); var nw = mbox.TopLeftLatLong; var se = mbox.BottomRightLatLong; return new BoundingBox(se.Latitude,nw.Longitude,nw.Latitude,se.Longitude); break; case 'multimap':
472
var mmbox = map.getMapBounds(); var sw = mmbox.getSouthWest(); var ne = mmbox.getNorthEast(); return new BoundingBox(sw.lat, sw.lon, ne.lat, ne.lon); break; case 'mapquest':
473
var mqbox = map.getMapBounds(); var se = mqbox.getLowerRightLatLng(); var nw = mqbox.getUpperLeftLatLng(); return new BoundingBox(se.lat, nw.lon, nw.lat, se.lon); break; case 'map24':
474
var mv = map.MapClient['Static'].getCurrentMapView(); var se = mv.LowerRight; var nw = mv.TopLeft; return new BoundingBox (se.Latitude/60, nw.Longitude/60, nw.Latitude/60, se.Longitude/60 ); break; default:
475
if(this.debug)
476
alert(this.api + ' not supported by Mapstraction.getBounds');}
477
}
478
Mapstraction.prototype.setBounds = function(bounds){ if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.setBounds(bounds);} ); return;}
479
var map = this.maps[this.api]; var sw = bounds.getSouthWest(); var ne = bounds.getNorthEast(); switch (this.api) { case 'google':
480
case 'openstreetmap':
481
var gbounds = new GLatLngBounds(new GLatLng(sw.lat,sw.lon),new GLatLng(ne.lat,ne.lon)); map.setCenter(gbounds.getCenter(), map.getBoundsZoomLevel(gbounds)); break; case 'openlayers':
482
var bounds = new OpenLayers.Bounds(); bounds.extend(new LatLonPoint(sw.lat,sw.lon).toOpenLayers()); bounds.extend(new LatLonPoint(ne.lat,ne.lon).toOpenLayers()); map.zoomToExtent(bounds); break; case 'yahoo':
483
if(sw.lon > ne.lon)
484
sw.lon -= 360; var center = new YGeoPoint((sw.lat + ne.lat)/2, (ne.lon + sw.lon)/2); var container = map.getContainerSize(); for(var zoom = 1 ; zoom <= 17 ; zoom++){ var sw_pix = convertLatLonXY_Yahoo(sw,zoom); var ne_pix = convertLatLonXY_Yahoo(ne,zoom); if(sw_pix.x > ne_pix.x)
485
sw_pix.x -= (1 << (26 - zoom)); if(Math.abs(ne_pix.x - sw_pix.x)<=container.width
486
&& Math.abs(ne_pix.y - sw_pix.y) <= container.height){ map.drawZoomAndCenter(center,zoom); break;}
487
}
488
break; case 'microsoft':
489
map.SetMapView([new VELatLong(sw.lat,sw.lon),new VELatLong(ne.lat,ne.lon)]); break; case 'multimap':
490
var mmlocation = map.getBoundsZoomFactor( sw.toMultiMap(), ne.toMultiMap() ); var center = new LatLonPoint(mmlocation.coords.lat, mmlocation.coords.lon); this.setCenterAndZoom(center, mmlocation.zoom_factor); break; case 'mapquest':
491
if(this.debug)
492
alert(this.api + ' not supported by Mapstraction.setBounds'); break; case 'freeearth':
493
var center = new LatLonPoint((sw.lat + ne.lat)/2, (ne.lon + sw.lon)/2); this.setCenter(center); break; case 'map24':
494
var settings = new Object(); settings.Latitude = ((sw.lat+ne.lat) / 2) * 60; settings.Longitude = ((sw.lon+ne.lon) / 2) * 60; settings.MinimumWidth = lonToMetres
495
(ne.lon-sw.lon, (ne.lat+sw.lat)/2); Map24.MapApplication.center ( settings ); break; default:
496
if(this.debug)
497
alert(this.api + ' not supported by Mapstraction.setBounds');}
498
}
499
Mapstraction.prototype.addImageOverlay = function(id, src, opacity, west, south, east, north) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addImageOverlay(id, src, opacity, west, south, east, north);} ); return;}
500
var map = this.maps[this.api]; var b = document.createElement("img"); b.style.display = 'block'; b.setAttribute('id',id); b.setAttribute('src',src); b.style.position = 'absolute'; b.style.zIndex = 1; b.setAttribute('west',west); b.setAttribute('south',south); b.setAttribute('east',east); b.setAttribute('north',north); switch (this.api) { case 'google':
501
case 'openstreetmap':
502
map.getPane(G_MAP_MAP_PANE).appendChild(b); this.setImageOpacity(id, opacity); this.setImagePosition(id); GEvent.bind(map, "zoomend", this, function(){this.setImagePosition(id)}); GEvent.bind(map, "moveend", this, function(){this.setImagePosition(id)}); break; case 'multimap':
503
map.getContainer().appendChild(b); this.setImageOpacity(id, opacity); this.setImagePosition(id); me = this; map.addEventHandler( 'changeZoom', function(eventType, eventTarget, arg1, arg2, arg3) { me.setImagePosition(id);}); map.addEventHandler( 'drag', function(eventType, eventTarget, arg1, arg2, arg3) { me.setImagePosition(id);}); map.addEventHandler( 'endPan', function(eventType, eventTarget, arg1, arg2, arg3) { me.setImagePosition(id);}); break; default:
504
b.style.display = 'none'; if(this.debug)
505
alert(this.api + "not supported by Mapstraction.addImageOverlay not supported"); break;}
506
}
507
Mapstraction.prototype.setImageOpacity = function(id, opacity) { if(opacity<0){opacity=0;} if(opacity>=100){opacity=100;}
508
var c=opacity/100; var d=document.getElementById(id); if(typeof(d.style.filter)=='string'){d.style.filter='alpha(opacity:'+opacity+')';}
509
if(typeof(d.style.KHTMLOpacity)=='string'){d.style.KHTMLOpacity=c;}
510
if(typeof(d.style.MozOpacity)=='string'){d.style.MozOpacity=c;}
511
if(typeof(d.style.opacity)=='string'){d.style.opacity=c;}
512
}
513
Mapstraction.prototype.setImagePosition = function(id) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.setImagePosition(id);} ); return;}
514
var map = this.maps[this.api]; var x = document.getElementById(id); var d; var e; switch (this.api) { case 'google':
515
case 'openstreetmap':
516
d = map.fromLatLngToDivPixel(new GLatLng(x.getAttribute('north'), x.getAttribute('west'))); e = map.fromLatLngToDivPixel(new GLatLng(x.getAttribute('south'), x.getAttribute('east'))); break; case 'multimap':
517
d = map.geoPosToContainerPixels(new MMLatLon(x.getAttribute('north'), x.getAttribute('west'))); e = map.geoPosToContainerPixels(new MMLatLon(x.getAttribute('south'), x.getAttribute('east'))); break;}
518
x.style.top=d.y+'px'; x.style.left=d.x+'px'; x.style.width=e.x-d.x+'px'; x.style.height=e.y-d.y+'px';}
519
Mapstraction.prototype.addOverlay = function(url, autoCenterAndZoom) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.addOverlay(url);} ); return;}
520
var map = this.maps[this.api]; switch (this.api) { case 'yahoo':
521
map.addOverlay(new YGeoRSS(url)); break; case 'openstreetmap':
522
case 'google':
523
var geoXML = new GGeoXml(url); map.addOverlay(geoXML, function() { if(autoCenterAndZoom) { geoXML.gotoDefaultViewport(map);}
524
}); break; case 'microsoft':
525
var veLayerSpec = new VELayerSpecification(); veLayerSpec.Type = VELayerType.GeoRSS; veLayerSpec.ID = 1; veLayerSpec.LayerSource = url; veLayerSpec.Method = 'get'; map.AddLayer(veLayerSpec); break; case 'multimap':
526
break; case 'freeearth':
527
if (this.freeEarthLoaded) { var ferss = new FE.GeoRSS(url); map.addOverlay(ferss);} else { myself = this; this.freeEarthOnLoad.push( function() { myself.addOverlay(url);} );}
528
break; default:
529
if(this.debug)
530
alert(this.api + ' not supported by Mapstraction.addGeoRSSOverlay');}
531
}
532
Mapstraction.prototype.addTileLayer = function(tile_url, opacity, copyright_text, min_zoom, max_zoom) { if(!tile_url)
533
return; if (! this.tileLayers) { this.tileLayers = [];}
534
if(!opacity)
535
opacity = 0.6; if(!copyright_text)
536
copyright_text = "Mapstraction"; if(!min_zoom)
537
min_zoom = 1; if(!max_zoom)
538
max_zoom = 18; console.log(this.api); switch (this.api) { case 'google':
539
case 'openstreetmap':
540
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(-90,-180), new GLatLng(90,180)), 0, "copyleft"); var copyrightCollection = new GCopyrightCollection(copyright_text); copyrightCollection.addCopyright(copyright); var tilelayers = new Array(); tilelayers[0] = new GTileLayer(copyrightCollection, min_zoom, max_zoom); tilelayers[0].isPng = function() { return true;}; tilelayers[0].getOpacity = function() { return opacity;}
541
tilelayers[0].getTileUrl = function (a, b) { url = tile_url; url = url.replace(/\{Z\}/,b); url = url.replace(/\{X\}/,a.x); url = url.replace(/\{Y\}/,a.y); return url
542
}; tileLayerOverlay = new GTileLayerOverlay(tilelayers[0]); this.tileLayers.push( [tile_url, tileLayerOverlay, true] ); this.maps[this.api].addOverlay(tileLayerOverlay); break;}
543
return tileLayerOverlay;}
544
Mapstraction.prototype.toggleTileLayer = function(tile_url) { switch (this.api) { case 'google':
545
case 'openstreetmap':
546
for (var f=0; f<this.tileLayers.length; f++) { if(this.tileLayers[f][0] == tile_url) { if(this.tileLayers[f][2]) { this.maps[this.api].removeOverlay(this.tileLayers[f][1]); this.tileLayers[f][2] = false;} else { this.maps[this.api].addOverlay(this.tileLayers[f][1]); this.tileLayers[f][2] = true;}
547
}
548
}
549
break;}
550
}
551
Mapstraction.prototype.addFilter = function(field, operator, value) { if (! this.filters) { this.filters = [];}
552
this.filters.push( [field, operator, value] );}
553
Mapstraction.prototype.removeFilter = function(field, operator, value) { if (! this.filters) { return;}
554
var del; for (var f=0; f<this.filters.length; f++) { if (this.filters[f][0] == field &&
555
(! operator || (this.filters[f][1] == operator && this.filters[f][2] == value))) { this.filters.splice(f,1); f--;}
556
}
557
}
558
Mapstraction.prototype.toggleFilter = function(field, operator, value) { if (! this.filters) { this.filters = [];}
559
var found = false; for (var f=0; f<this.filters.length; f++) { if (this.filters[f][0] == field && this.filters[f][1] == operator && this.filters[f][2] == value) { this.filters.splice(f,1); f--; found = true;}
560
}
561
if (! found) { this.addFilter(field, operator, value);}
562
}
563
Mapstraction.prototype.removeAllFilters = function() { this.filters = [];}
564
Mapstraction.prototype.doFilter = function() { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.doFilter();} ); return;}
565
var map = this.maps[this.api]; if (this.filters) { switch (this.api) { case 'multimap':
566
var mmfilters = []; for (var f=0; f<this.filters.length; f++) { mmfilters.push( new MMSearchFilter( this.filters[f][0], this.filters[f][1], this.filters[f][2] ));}
567
map.setMarkerFilters( mmfilters ); map.redrawMap(); break; default:
568
var vis; for (var m=0; m<this.markers.length; m++) { vis = true; for (var f=0; f<this.filters.length; f++) { if (! this.applyFilter(this.markers[m], this.filters[f])) { vis = false;}
569
}
570
if (vis) { this.markers[m].show();} else { this.markers[m].hide();}
571
}
572
break;}
573
}
574
}
575
Mapstraction.prototype.applyFilter = function(o, f) { var vis = true; switch (f[1]) { case 'ge':
576
if (o.getAttribute( f[0] ) < f[2]) { vis = false;}
577
break; case 'le':
578
if (o.getAttribute( f[0] ) > f[2]) { vis = false;}
579
break; case 'eq':
580
if (o.getAttribute( f[0] ) != f[2]) { vis = false;}
581
break;}
582
return vis;}
583
Mapstraction.prototype.getAttributeExtremes = function(field) { var min; var max; for (var m=0; m<this.markers.length; m++) { if (! min || min > this.markers[m].getAttribute(field)) { min = this.markers[m].getAttribute(field);}
584
if (! max || max < this.markers[m].getAttribute(field)) { max = this.markers[m].getAttribute(field);}
585
}
586
for (var p=0; m<this.polylines.length; m++) { if (! min || min > this.polylines[p].getAttribute(field)) { min = this.polylines[p].getAttribute(field);}
587
if (! max || max < this.polylines[p].getAttribute(field)) { max = this.polylines[p].getAttribute(field);}
588
}
589
return [min, max];}
590
Mapstraction.prototype.getMap = function() { return this.maps[this.api];}
591
function LatLonPoint(lat,lon) { this.lat = lat; this.lon = lon; this.lng = lon;}
592
LatLonPoint.prototype.toYahoo = function() { return new YGeoPoint(this.lat,this.lon);}
593
LatLonPoint.prototype.toGoogle = function() { return new GLatLng(this.lat,this.lon);}
594
LatLonPoint.prototype.toOpenLayers = function() { var ollon = this.lon * 20037508.34 / 180; var ollat = Math.log(Math.tan((90 + this.lat) * Math.PI / 360)) / (Math.PI / 180); ollat = ollat * 20037508.34 / 180; return new OpenLayers.LonLat(ollon, ollat);}
595
LatLonPoint.prototype.fromOpenLayers = function() { var lon = (this.lon / 20037508.34) * 180; var lat = (this.lat / 20037508.34) * 180; lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2); this.lon = lon; this.lat = lat;}
596
LatLonPoint.prototype.toMicrosoft = function() { return new VELatLong(this.lat,this.lon);}
597
LatLonPoint.prototype.toMultiMap = function() { return new MMLatLon(this.lat, this.lon);}
598
LatLonPoint.prototype.toMapQuest = function() { return new MQLatLng(this.lat, this.lon);}
599
LatLonPoint.prototype.toFreeEarth = function() { return new FE.LatLng(this.lat,this.lon);}
600
LatLonPoint.prototype.toMap24 = function() { return new Map24.Point (this.lon,this.lat);}
601
LatLonPoint.prototype.toString = function() { return this.lat + ', ' + this.lon;}
602
LatLonPoint.prototype.distance = function(otherPoint) { var d,dr; with (Math) { dr = 0.017453292519943295; d = cos(otherPoint.lon*dr - this.lon*dr) * cos(otherPoint.lat*dr - this.lat*dr); return acos(d)*6378.137;}
603
return -1;}
604
LatLonPoint.prototype.equals = function(otherPoint) { return this.lat == otherPoint.lat && this.lon == otherPoint.lon;}
605
function BoundingBox(swlat, swlon, nelat, nelon) { this.sw = new LatLonPoint(swlat, swlon); this.ne = new LatLonPoint(nelat, nelon);}
606
BoundingBox.prototype.getSouthWest = function() { return this.sw;}
607
BoundingBox.prototype.getNorthEast = function() { return this.ne;}
608
BoundingBox.prototype.isEmpty = function() { return this.ne == this.sw;}
609
BoundingBox.prototype.contains = function(point){ return point.lat >= this.sw.lat && point.lat <= this.ne.lat && point.lon>= this.sw.lon && point.lon <= this.ne.lon;}
610
BoundingBox.prototype.toSpan = function() { return new LatLonPoint( Math.abs(this.sw.lat - this.ne.lat), Math.abs(this.sw.lon - this.ne.lon) );}
611
BoundingBox.prototype.extend = function(point) { if(this.sw.lat > point.lat)
612
this.sw.lat = point.lat; if(this.sw.lon > point.lon)
613
this.sw.lon = point.lon; if(this.ne.lat < point.lat)
614
this.ne.lat = point.lat; if(this.ne.lon < point.lon)
615
this.ne.lon = point.lon; return;}
616
function Marker(point) { this.gmarker=null; this.location = point; this.onmap = false; this.proprietary_marker = false; this.attributes = new Array(); this.pinID = "mspin-"+new Date().getTime()+'-'+(Math.floor(Math.random()*Math.pow(2,16)));}
617
Marker.prototype.setChild = function(some_proprietary_marker) { this.proprietary_marker = some_proprietary_marker; this.onmap = true
618
}
619
Marker.prototype.setLabel = function(labelText) { this.labelText = labelText;}
620
Marker.prototype.addData = function(options){ if(options.label)
621
this.setLabel(options.label); if(options.infoBubble)
622
this.setInfoBubble(options.infoBubble); if(options.icon) { if(options.iconSize)
623
this.setIcon(options.icon, new Array(options.iconSize[0], options.iconSize[1])); else
624
this.setIcon(options.icon); if(options.iconAnchor)
625
this.setIconAnchor(new Array(options.iconAnchor[0], options.iconAnchor[1]));}
626
if(options.iconShadow) { if(options.iconShadowSize)
627
this.setShadowIcon(options.iconShadow, new Array(options.iconShadowSize[0], options.iconShadowSize[1])); else
628
this.setIcon(options.iconShadow);}
629
if(options.infoDiv)
630
this.setInfoDiv(options.infoDiv[0],options.infoDiv[1]); if(options.draggable)
631
this.setDraggable(options.draggable); if(options.hover)
632
this.setHover(options.hover); if(options.hoverIcon)
633
this.setHoverIcon(options.hoverIcon); if(options.openBubble)
634
this.openBubble(); if(options.date)
635
this.setAttribute( 'date', eval(options.date) ); if(options.category)
636
this.setAttribute( 'category', options.category );}
637
Marker.prototype.setInfoBubble = function(infoBubble) { this.infoBubble = infoBubble;}
638
Marker.prototype.setInfoDiv = function(infoDiv,div){ this.infoDiv = infoDiv; this.div = div;}
639
Marker.prototype.setIcon = function(iconUrl, iconSize, iconAnchor){ this.iconUrl = iconUrl; if(iconSize)
640
this.iconSize = iconSize; if(iconAnchor)
641
this.iconAnchor = iconAnchor;}
642
Marker.prototype.setIconSize = function(iconSize){ if(iconSize)
643
this.iconSize = iconSize;}
644
Marker.prototype.setIconAnchor = function(iconAnchor){ if(iconAnchor)
645
this.iconAnchor = iconAnchor;}
646
Marker.prototype.setShadowIcon = function(iconShadowUrl, iconShadowSize){ this.iconShadowUrl = iconShadowUrl; if(iconShadowSize)
647
this.iconShadowSize = iconShadowSize;}
648
Marker.prototype.setHoverIcon = function(hoverIconUrl){ this.hoverIconUrl = hoverIconUrl;}
649
Marker.prototype.setDraggable = function(draggable) { this.draggable = draggable;}
650
Marker.prototype.setHover = function(hover) { this.hover = hover;}
651
Marker.prototype.changeIcon = function(iconUrl) { if (this.proprietary_marker) { this.proprietary_marker.setImage(iconUrl);}
652
}
653
Marker.prototype.revertIcon = function() { this.changeIcon(this.iconUrl);}
654
Marker.prototype.toYahoo = function() { var ymarker; if(this.iconUrl) { ymarker = new YMarker(this.location.toYahoo (),new YImage(this.iconUrl));} else { ymarker = new YMarker(this.location.toYahoo());}
655
if(this.iconSize) { ymarker.size = new YSize(this.iconSize[0], this.iconSize[1]);}
656
if(this.labelText) { ymarker.addLabel(this.labelText);}
657
if(this.infoBubble) { var theInfo = this.infoBubble; var event_action; if(this.hover) { event_action = EventsList.MouseOver;}
658
else { event_action = EventsList.MouseClick;}
659
YEvent.Capture(ymarker, event_action, function() { ymarker.openSmartWindow(theInfo);});}
660
if(this.infoDiv) { var theInfo = this.infoDiv; var div = this.div; var event_div; if(this.hover) { event_action = EventsList.MouseOver;}
661
else { event_action = EventsList.MouseClick;}
662
YEvent.Capture(ymarker, event_action, function() { document.getElementById(div).innerHTML = theInfo;});}
663
return ymarker;}
664
Marker.prototype.toGoogle = function() { if(this.gmarker) {return this.gmarker;} var options = new Object(); if(this.labelText) { options.title = this.labelText;}
665
if(this.iconUrl){ var icon = new GIcon(G_DEFAULT_ICON,this.iconUrl); if(this.iconSize) { icon.iconSize = new GSize(this.iconSize[0], this.iconSize[1]); var anchor; if(this.iconAnchor) { anchor = new GPoint(this.iconAnchor[0], this.iconAnchor[1]);}
666
else { anchor = new GPoint(this.iconSize[0]/2, this.iconSize[1]/2);}
667
icon.iconAnchor = anchor;}
668
if(this.iconShadowUrl) { icon.shadow = this.iconShadowUrl; if(this.iconShadowSize) { icon.shadowSize = new GSize(this.iconShadowSize[0], this.iconShadowSize[1]);}
669
}
670
options.icon = icon;}
671
if(this.draggable){ options.draggable = this.draggable;}
672
this.gmarker = new GMarker( this.location.toGoogle(),options); var gmarker = this.gmarker; if(this.infoBubble) { var theInfo = this.infoBubble; var event_action; if(this.hover) { event_action = "mouseover";}
673
else { event_action = "click";}
674
GEvent.addListener(this.gmarker, event_action, function() { gmarker.openInfoWindowHtml(theInfo, {maxWidth: 100});});}
675
if(this.hoverIconUrl) { GEvent.addListener(this.gmarker, "mouseover", function() { gmarker.setImage(this.hoverIconUrl);}); GEvent.addListener(this.gmarker, "mouseout", function() {gmarker.setImage(this.iconUrl);});}
676
if(this.infoDiv){ var theInfo = this.infoDiv; var div = this.div; var event_action; if(this.hover) { event_action = "mouseover";}
677
else { event_action = "click";}
678
GEvent.addListener(this.gmarker, event_action, function() { document.getElementById(div).innerHTML = theInfo;});}
679
return this.gmarker;}
680
Marker.prototype.toOpenLayers = function() { if(this.iconSize) { var size = new OpenLayers.Size(this.iconSize[0], this.iconSize[1]);}
681
else
682
{ var size = new OpenLayers.Size(15,20);}
683
if(this.iconAnchor)
684
{ var anchor = new OpenLayers.Pixel(this.iconAnchor[0], this.iconAnchor[1]);}
685
else
686
{ anchor = new OpenLayers.Pixel(-(size.w/2), -size.h);}
687
if(this.iconUrl) { var icon = new OpenLayers.Icon(this.iconUrl, size, anchor);}
688
else
689
{ var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.png', size, anchor);}
690
var marker = new OpenLayers.Marker(this.location.toOpenLayers(), icon); return marker;}
691
Marker.prototype.toMicrosoft = function() { var pin = new VEPushpin(this.pinID,this.location.toMicrosoft(), this.iconUrl,this.labelText,this.infoBubble); return pin;}
692
Marker.prototype.toMap24 = function() { var ops = new Object(); ops.Longitude = this.location.lon*60; ops.Latitude = this.location.lat*60; if(this.infoBubble) { ops.TooltipContent = this.infoBubble;}
693
if(this.labelText) { }
694
ops.LogoURL = this.iconUrl ? this.iconUrl :
695
"http://www.free-map.org.uk/images/marker.png"; ops.TooltipLayout = Map24.MapObject.LAYOUT_BUBBLE; if(this.hover) { ops.TooltipOpen = "OnMouseOver";} else { ops.TooltipOpen = "OnClick";}
696
var m24Location = new Map24.Location ( ops ); return m24Location;}
697
Marker.prototype.toMultiMap = function() { if (this.iconUrl) { var icon = new MMIcon(this.iconUrl); icon.iconSize = new MMDimensions(32, 32); var mmmarker = new MMMarkerOverlay( this.location.toMultiMap(), {'icon' : icon} );} else { var mmmarker = new MMMarkerOverlay( this.location.toMultiMap());}
698
if(this.labelText){ }
699
if(this.infoBubble) { mmmarker.setInfoBoxContent(this.infoBubble);}
700
if(this.infoDiv) { }
701
for (var key in this.attributes) { mmmarker.setAttribute(key, this.attributes[ key ]);}
702
return mmmarker;}
703
Marker.prototype.toMapQuest = function() { var mqmarker = new MQPoi( this.location.toMapQuest() ); if(this.iconUrl){ var mqicon = new MQMapIcon(); mqicon.setImage(this.iconUrl,32,32,true,false); mqmarker.setIcon(mqicon);}
704
if(this.labelText) { mqmarker.setInfoTitleHTML( this.labelText );}
705
if(this.infoBubble) { mqmarker.setInfoContentHTML( this.infoBubble );}
706
if(this.infoDiv){ var theInfo = this.infoDiv; var div = this.div; MQEventManager.addListener(mqmarker, "click", function() { document.getElementById(div).innerHTML = theInfo;});}
707
return mqmarker;}
708
Marker.prototype.toFreeEarth = function() { var feicon; if (this.iconUrl) { feicon = new FE.Icon(this.iconUrl);} else { feicon = new FE.Icon("http://freeearth.poly9.com/images/bullmarker.png");}
709
var femarker = new FE.Pushpin( this.location.toFreeEarth(), feicon); if(this.infoBubble) { var theBubble = this.infoBubble; FE.Event.addListener(femarker, 'click', function() { femarker.openInfoWindowHtml( theBubble, 200, 100 );} );}
710
if(this.infoDiv) { var theInfo = this.infoDiv; var div = this.div; FE.Event.addListener(femarker, 'click', function() { document.getElementById(div).innerHTML = theInfo;});}
711
return femarker;}
712
Marker.prototype.setAttribute = function(key,value) { this.attributes[key] = value;}
713
Marker.prototype.getAttribute = function(key) { return this.attributes[key];}
714
Marker.prototype.openBubble = function() { if(this.mapstraction.loaded[this.api] == false) { var my_marker = this; this.mapstraction.onload[this.api].push( function() { my_marker.openBubble();} ); return;}
715
if( this.api) { switch (this.api) { case 'yahoo':
716
var ypin = this.proprietary_marker; ypin.openSmartWindow(this.infoBubble); break; case 'google':
717
case 'openstreetmap':
718
var gpin = this.proprietary_marker; gpin.openInfoWindowHtml(this.infoBubble); break; case 'microsoft':
719
var pin = this.proprietary_marker; var el = $m(this.pinID + "_" + this.maps[this.api].GUID).onmouseover; setTimeout(el, 1000); break; case 'multimap':
720
this.proprietary_marker.openInfoBox(); break; case 'mapquest':
721
this.proprietary_marker.setRolloverEnabled(false); this.proprietary_marker.showInfoWindow(); this.proprietary_marker.setRolloverEnabled(true); break;}
722
} else { alert('You need to add the marker before opening it');}
723
}
724
Marker.prototype.hide = function() { if (this.api) { switch (this.api) { case 'google':
725
case 'openstreetmap':
726
this.proprietary_marker.hide(); break; case 'openlayers':
727
this.proprietary_marker.display(false); break; case 'yahoo':
728
this.proprietary_marker.hide(); break; case 'map24':
729
this.proprietary_marker.hide(); break; case 'multimap':
730
this.proprietary_marker.setVisibility(false); break; case 'mapquest':
731
this.proprietary_marker.setVisible(false); break; default:
732
if(this.debug)
733
alert(this.api + "not supported by Marker.hide");}
734
}
735
}
736
Marker.prototype.show = function() { if (this.api) { switch (this.api) { case 'google':
737
case 'openstreetmap':
738
this.proprietary_marker.show(); break; case 'openlayers':
739
this.proprietary_marker.display(true); break; case 'map24':
740
this.proprietary_marker.show(); break; case 'yahoo':
741
this.proprietary_marker.unhide(); break; case 'multimap':
742
this.proprietary_marker.setVisibility(true); break; case 'mapquest':
743
this.proprietary_marker.setVisible(true); break; default:
744
if(this.debug)
745
alert(this.api + "not supported by Marker.show");}
746
}
747
}
748
function Polyline(points) { this.points = points; this.attributes = new Array(); this.onmap = false; this.proprietary_polyline = false; this.pllID = "mspll-"+new Date().getTime()+'-'+(Math.floor(Math.random()*Math.pow(2,16)));}
749
Polyline.prototype.addData = function(options){ if(options.color)
750
this.setColor(options.color); if(options.width)
751
this.setWidth(options.width); if(options.opacity)
752
this.setIcon(options.opacity); if(options.date)
753
this.setAttribute( 'date', eval(options.date) ); if(options.category)
754
this.setAttribute( 'category', options.category );}
755
Polyline.prototype.setChild = function(some_proprietary_polyline) { this.proprietary_polyline = some_proprietary_polyline; this.onmap = true;}
756
Polyline.prototype.setColor = function(color){ this.color = (color.length==7 && color[0]=="#") ? color.toUpperCase() : color;}
757
Polyline.prototype.setWidth = function(width){ this.width = width;}
758
Polyline.prototype.setOpacity = function(opacity){ this.opacity = opacity;}
759
Polyline.prototype.toYahoo = function() { var ypolyline; var ypoints = []; for (var i = 0, length = this.points.length ; i< length; i++){ ypoints.push(this.points[i].toYahoo());}
760
ypolyline = new YPolyline(ypoints,this.color,this.width,this.opacity); return ypolyline;}
761
Polyline.prototype.toGoogle = function() { var gpolyline; var gpoints = []; for (var i = 0, length = this.points.length ; i< length; i++){ gpoints.push(this.points[i].toGoogle());}
762
gpolyline = new GPolyline(gpoints,this.color,this.width,this.opacity); return gpolyline;}
763
Polyline.prototype.toMap24 = function() { var m24polyline; var m24longs = ""; var m24lats = ""; for (var i=0; i<this.points.length; i++) { if(i) { m24longs += "|"; m24lats += "|";}
764
m24longs += (this.points[i].lon*60); m24lats += (this.points[i].lat*60);}
765
m24polyline = new Map24.Polyline({ Longitudes: m24longs, Latitudes: m24lats, Color: this.color || "black", Width: this.width || 3
766
}); return m24polyline;}
767
Polyline.prototype.toMicrosoft = function() { var mpolyline; var mpoints = []; for (var i = 0, length = this.points.length ; i< length; i++){ mpoints.push(this.points[i].toMicrosoft());}
768
var color; var opacity = this.opacity ||1.0; if(this.color){ color = new VEColor(parseInt(this.color.substr(1,2),16),parseInt(this.color.substr(3,2),16),parseInt(this.color.substr(5,2),16), opacity);}else{ color = new VEColor(0,255,0, opacity);}
769
mpolyline = new VEPolyline(this.pllID,mpoints,color,this.width); return mpolyline;}
770
Polyline.prototype.toMultiMap = function() { var mmpolyline; var mmpoints = []; for (var i = 0, length = this.points.length ; i< length; i++){ mmpoints.push(this.points[i].toMultiMap());}
771
mmpolyline = new MMPolyLineOverlay(mmpoints, this.color, this.opacity, this.width, false, undefined); return mmpolyline;}
772
Polyline.prototype.toMapQuest = function() { var mqpolyline = new MQLineOverlay(); mqpolyline.setColor(this.color||"red"); mqpolyline.setBorderWidth(this.width || 3); mqpolyline.setKey("Line"); mqpolyline.setColorAlpha(this.opacity); var mqpoints = new MQLatLngCollection(); for (var i = 0, length = this.points.length ; i< length; i++){ mqpoints.add(this.points[i].toMapQuest());}
773
mqpolyline.setShapePoints(mqpoints); return mqpolyline;}
774
Polyline.prototype.toFreeEarth = function() { var fepoints = new Array(); for (var i = 0, length = this.points.length ; i< length; i++){ fepoints.push(this.points[i].toFreeEarth());}
775
var fepolyline = new FE.Polyline(fepoints, this.color || '0xff0000', this.width || 1, this.opacity || 1); return fepolyline;}
776
Polyline.prototype.setAttribute = function(key,value) { this.attributes[key] = value;}
777
Polyline.prototype.getAttribute = function(key) { return this.attributes[key];}
778
Polyline.prototype.show = function() { if (this.api) { }
779
}
780
Polyline.prototype.hide = function() { if (this.api) { }
781
}
782
Mapstraction.prototype.showRoute = function(route) { if(this.loaded[this.api] == false) { myself = this; this.onload[this.api].push( function() { myself.showRoute(route);} ); return;}
783
var map = this.maps[this.api]; switch (this.api) { case 'mapquest':
784
map.addRouteHighlight(route['bounding_box'],"http://map.access.mapquest.com",route['session_id'],true); break; default:
785
if(this.debug)
786
alert(api + ' not supported by Mapstration.showRoute'); break;}
787
}