]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Mapstraction/js/mxn.cloudmade.core.js
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / plugins / Mapstraction / js / mxn.cloudmade.core.js
1 mxn.register('cloudmade', {     
2
3     Mapstraction: {
4
5         init: function(element, api) {          
6             var me = this;              
7             var cloudmade = new CM.Tiles.CloudMade.Web({key: cloudmade_key});
8             this.maps[api] = new CM.Map(element, cloudmade);
9             this.loaded[api] = true;
10
11             CM.Event.addListener(this.maps[api], 'click', function(location,marker) {
12                 if ( marker && marker.mapstraction_marker ) {
13                     marker.mapstraction_marker.click.fire();
14                 }
15                 else if ( location ) {
16                     me.click.fire({'location': new mxn.LatLonPoint(location.lat(), location.lng())});
17                 }
18
19                 // If the user puts their own Google markers directly on the map
20                 // then there is no location and this event should not fire.
21                 if ( location ) {
22                     me.clickHandler(location.lat(),location.lng(),location,me);
23                 }
24             });
25         },
26
27         applyOptions: function(){
28             var map = this.maps[this.api];
29             if(this.options.enableScrollWheelZoom){
30               map.enableScrollWheelZoom();
31             }
32         },
33
34         resizeTo: function(width, height){      
35             this.maps[this.api].checkResize();
36         },
37
38         addControls: function( args ) {
39             var map = this.maps[this.api];
40
41             var c = this.addControlsArgs;
42             switch (c.zoom) {
43               case 'large':
44                 this.addLargeControls();
45               break;
46               case 'small':
47                 this.addSmallControls();
48               break;
49             }
50
51             if (c.map_type) {
52               this.addMapTypeControls();
53             }
54             if (c.scale) {
55               map.addControl(new CM.ScaleControl());
56               this.addControlsArgs.scale = true;
57             }
58         },
59
60         addSmallControls: function() {
61             var map = this.maps[this.api];
62             map.addControl(new CM.SmallMapControl());
63             this.addControlsArgs.zoom = 'small';
64         },
65
66         addLargeControls: function() {
67             var map = this.maps[this.api];
68             map.addControl(new CM.LargeMapControl());
69             this.addControlsArgs.zoom = 'large';
70         },
71
72         addMapTypeControls: function() {
73             var map = this.maps[this.api];
74
75             map.addControl(new CM.TileLayerControl());
76             this.addControlsArgs.map_type = true;
77         },
78
79         dragging: function(on) {
80             var map = this.maps[this.api];
81
82             if (on) {
83               map.enableDragging();
84             } else {
85               map.disableDragging();
86             }
87         },
88
89         setCenterAndZoom: function(point, zoom) { 
90             var map = this.maps[this.api];
91             var pt = point.toProprietary(this.api);
92             map.setCenter(pt, zoom);
93
94         },
95
96         addMarker: function(marker, old) {
97             var map = this.maps[this.api];
98             var pin = marker.toProprietary(this.api);
99             map.addOverlay(pin);
100             return pin;
101         },
102
103         removeMarker: function(marker) {
104             var map = this.maps[this.api];
105             marker.proprietary_marker.closeInfoWindow();
106             map.removeOverlay(marker.proprietary_marker);
107         },
108
109         removeAllMarkers: function() {
110             // Done in mxn.core.js
111         },
112
113         declutterMarkers: function(opts) {
114             var map = this.maps[this.api];
115
116             // TODO: Add provider code
117         },
118
119         addPolyline: function(polyline, old) {
120             var map = this.maps[this.api];
121             var pl = polyline.toProprietary(this.api);
122             map.addOverlay(pl);
123             return pl;
124         },
125
126         removePolyline: function(polyline) {
127             var map = this.maps[this.api];
128             map.removeOverlay(polyline.proprietary_polyline);
129         },
130
131         getCenter: function() {
132             var map = this.maps[this.api];
133             var pt = map.getCenter();
134
135             return new mxn.LatLonPoint(pt.lat(), pt.lng());
136         },
137
138         setCenter: function(point, options) {
139             var map = this.maps[this.api];
140             var pt = point.toProprietary(this.api);
141             if(options !== null && options.pan) { map.panTo(pt); }
142             else { map.setCenter(pt); }
143         },
144
145         setZoom: function(zoom) {
146             var map = this.maps[this.api];
147             map.setZoom(zoom);
148         },
149
150         getZoom: function() {
151             var map = this.maps[this.api];
152             return map.getZoom();
153         },
154
155         getZoomLevelForBoundingBox: function( bbox ) {
156             var map = this.maps[this.api];
157             // NE and SW points from the bounding box.
158             var ne = bbox.getNorthEast();
159             var sw = bbox.getSouthWest();
160
161             var zoom = map.getBoundsZoomLevel(new CM.LatLngBounds(sw.toProprietary(this.api), ne.toProprietary(this.api)));
162             return zoom;
163         },
164
165         setMapType: function(type) {
166             var map = this.maps[this.api];
167
168             // TODO: Are there any MapTypes for Cloudmade?
169
170             switch(type) {
171                 case mxn.Mapstraction.ROAD:
172                 // TODO: Add provider code
173                 break;
174                 case mxn.Mapstraction.SATELLITE:
175                 // TODO: Add provider code
176                 break;
177                 case mxn.Mapstraction.HYBRID:
178                 // TODO: Add provider code
179                 break;
180                 default:
181                 // TODO: Add provider code
182             }    
183         },
184
185         getMapType: function() {
186             var map = this.maps[this.api];
187
188             // TODO: Are there any MapTypes for Cloudmade?
189
190             return mxn.Mapstraction.ROAD;
191             //return mxn.Mapstraction.SATELLITE;
192             //return mxn.Mapstraction.HYBRID;
193
194         },
195
196         getBounds: function () {
197             var map = this.maps[this.api];
198
199             var box = map.getBounds();
200             var sw = box.getSouthWest();
201             var ne = box.getNorthEast();
202
203             return new mxn.BoundingBox(sw.lat(), sw.lng(), ne.lat(), ne.lng());
204         },
205
206         setBounds: function(bounds){
207             var map = this.maps[this.api];
208             var sw = bounds.getSouthWest();
209             var ne = bounds.getNorthEast();
210
211             map.zoomToBounds(new CM.LatLngBounds(sw.toProprietary(this.api), ne.toProprietary(this.api)));
212         },
213
214         addImageOverlay: function(id, src, opacity, west, south, east, north, oContext) {
215             var map = this.maps[this.api];
216
217             // TODO: Add provider code
218         },
219
220         setImagePosition: function(id, oContext) {
221             var map = this.maps[this.api];
222             var topLeftPoint; var bottomRightPoint;
223
224             // TODO: Add provider code
225
226         },
227
228         addOverlay: function(url, autoCenterAndZoom) {
229             var map = this.maps[this.api];
230
231             // TODO: Add provider code
232
233         },
234
235         addTileLayer: function(tile_url, opacity, copyright_text, min_zoom, max_zoom) {
236             var map = this.maps[this.api];
237
238             // TODO: Add provider code
239         },
240
241         toggleTileLayer: function(tile_url) {
242             var map = this.maps[this.api];
243
244             // TODO: Add provider code
245         },
246
247         getPixelRatio: function() {
248             var map = this.maps[this.api];
249
250             // TODO: Add provider code  
251         },
252
253         mousePosition: function(element) {
254             var map = this.maps[this.api];
255
256             // TODO: Add provider code  
257         }
258     },
259
260     LatLonPoint: {
261
262         toProprietary: function() {
263             var cll = new CM.LatLng(this.lat,this.lon);
264             return cll;
265         },
266
267         fromProprietary: function(point) {
268             return new mxn.LatLonPoint(point.lat(),point.lng());
269         }
270
271     },
272
273     Marker: {
274
275         toProprietary: function() {
276             var pt = this.location.toProprietary(this.api);
277             var options = {};
278
279             if (this.iconUrl) {
280               var cicon = new CM.Icon();
281               cicon.image = this.iconUrl;
282               if (this.iconSize) {
283                 cicon.iconSize = new CM.Size(this.iconSize[0], this.iconSize[1]);
284                 if (this.iconAnchor) {
285                   cicon.iconAnchor = new CM.Point(this.iconAnchor[0], this.iconAnchor[1]);
286                 }
287               }
288               if (this.iconShadowUrl) {
289                 cicon.shadow = this.iconShadowUrl;
290                 if (this.iconShadowSize) {
291                   cicon.shadowSize = new CM.Size(this.iconShadowSize[0], this.iconShadowSize[1]);
292                 }
293               }
294               options.icon = cicon;
295             }
296             if (this.labelText) {
297               options.title = this.labelText;
298             }
299             var cmarker = new CM.Marker(pt, options);
300
301             if (this.infoBubble) {
302               cmarker.bindInfoWindow(this.infoBubble);
303             }
304
305
306             return cmarker;
307         },
308
309         openBubble: function() {                
310             var pin = this.proprietary_marker;
311             pin.openInfoWindow(this.infoBubble);
312         },
313
314         hide: function() {
315             var pin = this.proprietary_marker;
316             pin.hide();
317         },
318
319         show: function() {
320             var pin = this.proprietary_marker;
321             pin.show();
322         },
323
324         update: function() {
325             // TODO: Add provider code
326         }
327
328     },
329
330     Polyline: {
331
332         toProprietary: function() {
333             var pts = [];
334             var poly;
335
336             for (var i = 0,  length = this.points.length ; i< length; i++){
337               pts.push(this.points[i].toProprietary(this.api));
338             }
339             if (this.closed || pts[0].equals(pts[pts.length-1])) {
340               poly = new CM.Polygon(pts, this.color, this.width, this.opacity, this.fillColor || "#5462E3", this.opacity || "0.3");
341             } else {
342               poly = new CM.Polyline(pts, this.color, this.width, this.opacity);
343             }
344             return poly;
345         },
346
347         show: function() {
348             this.proprietary_polyline.show();
349         },
350
351         hide: function() {
352             this.proprietary_polyline.hide();
353         }
354
355     }
356
357 });