1 mxn.register('openlayers', {
5 init: function(element, api){
7 this.maps[api] = new OpenLayers.Map(
10 maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
14 projection: "EPSG:41001"
18 this.layers['osmmapnik'] = new OpenLayers.Layer.TMS(
21 "http://a.tile.openstreetmap.org/",
22 "http://b.tile.openstreetmap.org/",
23 "http://c.tile.openstreetmap.org/"
27 getURL: function (bounds) {
28 var res = this.map.getResolution();
29 var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
30 var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
31 var z = this.map.getZoom();
32 var limit = Math.pow(2, z);
33 if (y < 0 || y >= limit) {
36 x = ((x % limit) + limit) % limit;
37 var path = z + "/" + x + "/" + y + "." + this.type;
39 if (url instanceof Array) {
40 url = this.selectUrl(path, url);
45 displayOutsideMaxExtent: true
49 this.layers['osm'] = new OpenLayers.Layer.TMS(
52 "http://a.tah.openstreetmap.org/Tiles/tile.php/",
53 "http://b.tah.openstreetmap.org/Tiles/tile.php/",
54 "http://c.tah.openstreetmap.org/Tiles/tile.php/"
58 getURL: function (bounds) {
59 var res = this.map.getResolution();
60 var x = Math.round ((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
61 var y = Math.round ((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
62 var z = this.map.getZoom();
63 var limit = Math.pow(2, z);
64 if (y < 0 || y >= limit) {
67 x = ((x % limit) + limit) % limit;
68 var path = z + "/" + x + "/" + y + "." + this.type;
70 if (url instanceof Array) {
71 url = this.selectUrl(path, url);
76 displayOutsideMaxExtent: true
80 this.maps[api].addLayer(this.layers['osmmapnik']);
81 this.maps[api].addLayer(this.layers['osm']);
84 applyOptions: function(){
85 // var map = this.maps[this.api];
86 // var myOptions = [];
87 // if (this.options.enableDragging) {
88 // myOptions.draggable = true;
90 // if (this.options.enableScrollWheelZoom){
91 // myOptions.scrollwheel = true;
93 // map.setOptions(myOptions);
96 resizeTo: function(width, height){
97 this.currentElement.style.width = width;
98 this.currentElement.style.height = height;
99 this.maps[this.api].updateSize();
102 addControls: function( args ) {
103 var map = this.maps[this.api];
104 // FIXME: OpenLayers has a bug removing all the controls says crschmidt
105 for (var i = map.controls.length; i>1; i--) {
106 map.controls[i-1].deactivate();
107 map.removeControl(map.controls[i-1]);
109 if ( args.zoom == 'large' ) {
110 map.addControl(new OpenLayers.Control.PanZoomBar());
112 else if ( args.zoom == 'small' ) {
113 map.addControl(new OpenLayers.Control.ZoomPanel());
115 map.addControl(new OpenLayers.Control.PanPanel());
120 map.addControl(new OpenLayers.Control.PanPanel());
123 if ( args.overview ) {
124 map.addControl(new OpenLayers.Control.OverviewMap());
126 if ( args.map_type ) {
127 map.addControl(new OpenLayers.Control.LayerSwitcher());
131 addSmallControls: function() {
132 var map = this.maps[this.api];
133 this.addControlsArgs.pan = false;
134 this.addControlsArgs.scale = false;
135 this.addControlsArgs.zoom = 'small';
136 map.addControl(new OpenLayers.Control.ZoomBox());
137 map.addControl(new OpenLayers.Control.LayerSwitcher({
142 addLargeControls: function() {
143 var map = this.maps[this.api];
144 map.addControl(new OpenLayers.Control.PanZoomBar());
145 this.addControlsArgs.pan = true;
146 this.addControlsArgs.zoom = 'large';
149 addMapTypeControls: function() {
150 var map = this.maps[this.api];
151 map.addControl( new OpenLayers.Control.LayerSwitcher({
154 this.addControlsArgs.map_type = true;
157 setCenterAndZoom: function(point, zoom) {
158 var map = this.maps[this.api];
159 var pt = point.toProprietary(this.api);
160 map.setCenter(point.toProprietary(this.api), zoom);
163 addMarker: function(marker, old) {
164 var map = this.maps[this.api];
165 var pin = marker.toProprietary(this.api);
166 if (!this.layers['markers']) {
167 this.layers['markers'] = new OpenLayers.Layer.Markers('markers');
168 map.addLayer(this.layers['markers']);
170 this.layers['markers'].addMarker(pin);
175 removeMarker: function(marker) {
176 var map = this.maps[this.api];
177 var pin = marker.toProprietary(this.api);
178 this.layers['markers'].removeMarker(pin);
183 removeAllMarkers: function() {
184 var map = this.maps[this.api];
186 // TODO: Add provider code
189 declutterMarkers: function(opts) {
190 var map = this.maps[this.api];
192 // TODO: Add provider code
195 addPolyline: function(polyline, old) {
196 var map = this.maps[this.api];
197 var pl = polyline.toProprietary(this.api);
199 if (!this.layers['polylines']) {
200 this.layers['polylines'] = new OpenLayers.Layer.Vector('polylines');
201 map.addLayer(this.layers['polylines']);
203 polyline.setChild(pl);
204 this.layers['polylines'].addFeatures([pl]);
208 removePolyline: function(polyline) {
209 var map = this.maps[this.api];
210 var pl = polyline.toProprietary(this.api);
211 this.layers['polylines'].removeFeatures([pl]);
213 removeAllPolylines: function() {
214 var olpolylines = [];
215 for(var i = 0, length = this.polylines.length; i < length; i++){
216 olpolylines.push(this.polylines[i].toProprietary(this.api));
218 if (this.layers['polylines']) this.layers['polylines'].removeFeatures(olpolylines);
221 getCenter: function() {
222 var map = this.maps[this.api];
223 pt = map.getCenter();
224 return new mxn.LatLonPoint(pt.lat, pt.lon);
227 setCenter: function(point, options) {
228 var map = this.maps[this.api];
229 var pt = point.toProprietary(this.api);
234 setZoom: function(zoom) {
235 var map = this.maps[this.api];
239 getZoom: function() {
240 var map = this.maps[this.api];
244 getZoomLevelForBoundingBox: function( bbox ) {
245 var map = this.maps[this.api];
246 // throw 'Not implemented';
250 setMapType: function(type) {
251 var map = this.maps[this.api];
252 throw 'Not implemented (setMapType)';
255 getMapType: function() {
256 var map = this.maps[this.api];
257 // TODO: implement actual layer support
258 return mxn.Mapstraction.ROAD;
261 getBounds: function () {
262 var map = this.maps[this.api];
263 var olbox = map.calculateBounds();
264 return new mxn.BoundingBox(olbox.bottom, olbox.left, olbox.top, olbox.right);
267 setBounds: function(bounds){
268 var map = this.maps[this.api];
269 var sw = bounds.getSouthWest();
270 var ne = bounds.getNorthEast();
272 if(sw.lon > ne.lon) {
276 var obounds = new OpenLayers.Bounds();
278 obounds.extend(new mxn.LatLonPoint(sw.lat,sw.lon).toProprietary(this.api));
279 obounds.extend(new mxn.LatLonPoint(ne.lat,ne.lon).toProprietary(this.api));
280 map.zoomToExtent(obounds);
283 addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
284 var map = this.maps[this.api];
286 // TODO: Add provider code
289 setImagePosition: function(id, oContext) {
290 var map = this.maps[this.api];
291 var topLeftPoint; var bottomRightPoint;
293 // TODO: Add provider code
295 //oContext.pixels.top = ...;
296 //oContext.pixels.left = ...;
297 //oContext.pixels.bottom = ...;
298 //oContext.pixels.right = ...;
301 addOverlay: function(url, autoCenterAndZoom) {
302 var map = this.maps[this.api];
304 // TODO: Add provider code
308 addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
309 var map = this.maps[this.api];
311 // TODO: Add provider code
314 toggleTileLayer: function(tile_url) {
315 var map = this.maps[this.api];
317 // TODO: Add provider code
320 getPixelRatio: function() {
321 var map = this.maps[this.api];
323 // TODO: Add provider code
326 mousePosition: function(element) {
327 var map = this.maps[this.api];
329 // TODO: Add provider code
335 toProprietary: function() {
336 var ollon = this.lon * 20037508.34 / 180;
337 var ollat = Math.log(Math.tan((90 + this.lat) * Math.PI / 360)) / (Math.PI / 180);
338 ollat = ollat * 20037508.34 / 180;
339 return new OpenLayers.LonLat(ollon, ollat);
342 fromProprietary: function(olPoint) {
343 var lon = (olPoint.lon / 20037508.34) * 180;
344 var lat = (olPoint.lat / 20037508.34) * 180;
345 lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
354 toProprietary: function() {
355 var size, anchor, icon;
357 size = new OpenLayers.Size(this.iconSize[0], this.iconSize[1]);
360 size = new OpenLayers.Size(21,25);
363 if(this.iconAnchor) {
364 anchor = new OpenLayers.Pixel(this.iconAnchor[0], this.iconAnchor[1]);
367 // FIXME: hard-coding the anchor point
368 anchor = new OpenLayers.Pixel(-(size.w/2), -size.h);
372 icon = new OpenLayers.Icon(this.iconUrl, size, anchor);
375 icon = new OpenLayers.Icon('http://openlayers.org/dev/img/marker-gold.png', size, anchor);
377 var marker = new OpenLayers.Marker(this.location.toProprietary("openlayers"), icon);
379 if(this.infoBubble) {
380 var popup = new OpenLayers.Popup(null,
381 this.location.toProprietary("openlayers"),
382 new OpenLayers.Size(100,100),
385 popup.autoSize = true;
386 var theMap = this.map;
388 marker.events.register("mouseover", marker, function(event) {
389 theMap.addPopup(popup);
392 marker.events.register("mouseout", marker, function(event) {
394 theMap.removePopup(popup);
399 marker.events.register("mousedown", marker, function(event) {
402 theMap.removePopup(popup);
405 theMap.addPopup(popup);
413 if(this.hoverIconUrl) {
423 openBubble: function() {
424 // TODO: Add provider code
428 this.proprietary_marker.setOptions({visible:false});
432 this.proprietary_marker.setOptions({visible:true});
436 // TODO: Add provider code
443 toProprietary: function() {
448 strokeColor: this.color || "#000000",
449 strokeOpacity: this.opacity || 1,
450 strokeWidth: this.width || 1,
451 fillColor: this.fillColor || "#000000",
452 fillOpacity: this.getAttribute('fillOpacity') || 0.2
455 //TODO Handle closed attribute
457 for (var i = 0, length = this.points.length ; i< length; i++){
458 olpoint = this.points[i].toProprietary("openlayers");
459 olpoints.push(new OpenLayers.Geometry.Point(olpoint.lon, olpoint.lat));
464 ring = new OpenLayers.Geometry.LinearRing(olpoints);
467 ring = new OpenLayers.Geometry.LineString(olpoints);
470 olpolyline = new OpenLayers.Feature.Vector(ring, null, style);
476 throw 'Not implemented';
480 throw 'Not implemented';