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 // case mxn.Mapstraction.ROAD:
256 // map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
258 // case mxn.Mapstraction.SATELLITE:
259 // map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
261 // case mxn.Mapstraction.HYBRID:
262 // map.setMapTypeId(google.maps.MapTypeId.HYBRID);
265 // map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
269 getMapType: function() {
270 var map = this.maps[this.api];
271 // TODO: implement actual layer support
272 return mxn.Mapstraction.ROAD;
274 // var type = map.getMapTypeId();
276 // case google.maps.MapTypeId.ROADMAP:
277 // return mxn.Mapstraction.ROAD;
278 // case google.maps.MapTypeId.SATELLITE:
279 // return mxn.Mapstraction.SATELLITE;
280 // case google.maps.MapTypeId.HYBRID:
281 // return mxn.Mapstraction.HYBRID;
282 // //case google.maps.MapTypeId.TERRAIN:
283 // // return something;
289 getBounds: function () {
290 var map = this.maps[this.api];
291 var olbox = map.calculateBounds();
292 return new mxn.BoundingBox(olbox.bottom, olbox.left, olbox.top, olbox.right);
295 setBounds: function(bounds){
296 var map = this.maps[this.api];
297 var sw = bounds.getSouthWest();
298 var ne = bounds.getNorthEast();
300 if(sw.lon > ne.lon) {
304 var obounds = new OpenLayers.Bounds();
306 obounds.extend(new mxn.LatLonPoint(sw.lat,sw.lon).toProprietary(this.api));
307 obounds.extend(new mxn.LatLonPoint(ne.lat,ne.lon).toProprietary(this.api));
308 map.zoomToExtent(obounds);
311 addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
312 var map = this.maps[this.api];
314 // TODO: Add provider code
317 setImagePosition: function(id, oContext) {
318 var map = this.maps[this.api];
319 var topLeftPoint; var bottomRightPoint;
321 // TODO: Add provider code
323 //oContext.pixels.top = ...;
324 //oContext.pixels.left = ...;
325 //oContext.pixels.bottom = ...;
326 //oContext.pixels.right = ...;
329 addOverlay: function(url, autoCenterAndZoom) {
330 var map = this.maps[this.api];
332 // TODO: Add provider code
336 addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
337 var map = this.maps[this.api];
339 // TODO: Add provider code
342 toggleTileLayer: function(tile_url) {
343 var map = this.maps[this.api];
345 // TODO: Add provider code
348 getPixelRatio: function() {
349 var map = this.maps[this.api];
351 // TODO: Add provider code
354 mousePosition: function(element) {
355 var map = this.maps[this.api];
357 // TODO: Add provider code
363 toProprietary: function() {
364 var ollon = this.lon * 20037508.34 / 180;
365 var ollat = Math.log(Math.tan((90 + this.lat) * Math.PI / 360)) / (Math.PI / 180);
366 ollat = ollat * 20037508.34 / 180;
367 return new OpenLayers.LonLat(ollon, ollat);
370 fromProprietary: function(olPoint) {
371 var lon = (olPoint.lon / 20037508.34) * 180;
372 var lat = (olPoint.lat / 20037508.34) * 180;
373 lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
382 toProprietary: function() {
383 var size, anchor, icon;
385 size = new OpenLayers.Size(this.iconSize[0], this.iconSize[1]);
388 size = new OpenLayers.Size(21,25);
391 if(this.iconAnchor) {
392 anchor = new OpenLayers.Pixel(this.iconAnchor[0], this.iconAnchor[1]);
395 // FIXME: hard-coding the anchor point
396 anchor = new OpenLayers.Pixel(-(size.w/2), -size.h);
400 icon = new OpenLayers.Icon(this.iconUrl, size, anchor);
403 icon = new OpenLayers.Icon('http://openlayers.org/dev/img/marker-gold.png', size, anchor);
405 var marker = new OpenLayers.Marker(this.location.toProprietary("openlayers"), icon);
407 if(this.infoBubble) {
408 var popup = new OpenLayers.Popup(null,
409 this.location.toProprietary("openlayers"),
410 new OpenLayers.Size(100,100),
413 popup.autoSize = true;
414 var theMap = this.map;
416 marker.events.register("mouseover", marker, function(event) {
417 theMap.addPopup(popup);
420 marker.events.register("mouseout", marker, function(event) {
422 theMap.removePopup(popup);
427 marker.events.register("mousedown", marker, function(event) {
430 theMap.removePopup(popup);
433 theMap.addPopup(popup);
441 if(this.hoverIconUrl) {
451 openBubble: function() {
452 // TODO: Add provider code
456 this.proprietary_marker.setOptions({visible:false});
460 this.proprietary_marker.setOptions({visible:true});
464 // TODO: Add provider code
471 toProprietary: function() {
476 strokeColor: this.color || "#000000",
477 strokeOpacity: this.opacity || 1,
478 strokeWidth: this.width || 1,
479 fillColor: this.fillColor || "#000000",
480 fillOpacity: this.getAttribute('fillOpacity') || 0.2
483 //TODO Handle closed attribute
485 for (var i = 0, length = this.points.length ; i< length; i++){
486 olpoint = this.points[i].toProprietary("openlayers");
487 olpoints.push(new OpenLayers.Geometry.Point(olpoint.lon, olpoint.lat));
492 ring = new OpenLayers.Geometry.LinearRing(olpoints);
495 ring = new OpenLayers.Geometry.LineString(olpoints);
498 olpolyline = new OpenLayers.Feature.Vector(ring, null, style);
504 throw 'Not implemented';
508 throw 'Not implemented';