@@ -77,6 +77,17 @@ if (typeof Extras == "undefined" || !Extras)
77
77
this . metadataLineViewName = "detailed" ;
78
78
this . thumbnailColumnWidth = 200 ;
79
79
this . rowClassName = "alf-detail" ;
80
+
81
+ var me = this ;
82
+
83
+ YAHOO . Bubbling . on ( "gmapsScriptLoaded" , function onGmapsScriptLoaded ( ) {
84
+ me . scriptLoaded = true ;
85
+ if ( this . renderedView == true )
86
+ {
87
+ me . renderView . call ( me , me . scope ) ;
88
+ }
89
+ } ) ;
90
+
80
91
return this ;
81
92
} ;
82
93
@@ -143,7 +154,7 @@ if (typeof Extras == "undefined" || !Extras)
143
154
YAHOO . util . Dom . setStyle ( scope . id + this . parentElementIdSuffix , 'display' , 'none' ) ;
144
155
YAHOO . util . Dom . setStyle ( this . mapDiv , 'display' , 'none' ) ;
145
156
Dom . removeClass ( scope . id + this . parentElementIdSuffix , "documents-geo" ) ;
146
- } ,
157
+ }
147
158
148
159
} ) ;
149
160
@@ -225,6 +236,12 @@ if (typeof Extras == "undefined" || !Extras)
225
236
Dom . addClass ( matchedEl , 'alf-hover' ) ;
226
237
viewRendererInstance . onEventHighlightRow ( scope , event , matchedEl ) ;
227
238
} , 'div.' + this . rowClassName , this ) ;
239
+
240
+ // Async load the Google Maps API. Need to do this, as it breaks the YUI Loader otherwise
241
+ var script = document . createElement ( "script" ) ;
242
+ script . type = "text/javascript" ;
243
+ script . src = window . location . protocol + "//maps.google.com/maps/api/js?sensor=false&callback=Extras.DocumentListGeoViewRenderer.onGMapsScriptLoad" ;
244
+ document . body . appendChild ( script ) ;
228
245
} ;
229
246
230
247
/**
@@ -238,87 +255,92 @@ if (typeof Extras == "undefined" || !Extras)
238
255
*/
239
256
Extras . DocumentListGeoViewRenderer . prototype . renderView = function DL_GVR_renderView ( scope , sRequest , oResponse , oPayload )
240
257
{
241
- YAHOO . util . Dom . setStyle ( scope . id + this . parentElementIdSuffix , 'display' , '' ) ;
242
- Dom . addClass ( scope . id + this . parentElementIdSuffix , "documents-geo" ) ;
243
-
244
- var mapId = scope . id + this . parentElementIdSuffix + "-map" ,
245
- mapDiv = Dom . get ( mapId ) ;
246
-
247
- var container = Dom . get ( scope . id + this . parentElementIdSuffix ) ;
248
- var oRecordSet = scope . widgets . dataTable . getRecordSet ( ) ;
249
-
250
- scope . widgets . dataTable . onDataReturnInitializeTable . call ( scope . widgets . dataTable , sRequest , oResponse , oPayload ) ;
251
-
252
- if ( ! this . mapDiv )
253
- {
254
- mapDiv = document . createElement ( "div" ) ;
255
- Dom . setAttribute ( mapDiv , "id" , mapId ) ;
256
- Dom . addClass ( mapDiv , "map" ) ;
257
- Dom . setStyle ( mapDiv , "height" , "" + ( ( window . innerHeight || document . documentElement . offsetHeight || document . body . offsetHeight ) - 310 ) + "px" ) ;
258
- Dom . get ( scope . id + this . parentElementIdSuffix ) . appendChild ( mapDiv ) ;
259
- this . mapDiv = mapDiv ;
260
- }
261
- else
258
+ this . renderedView = true ;
259
+ this . scope = scope ;
260
+ if ( this . scriptLoaded == true )
262
261
{
263
- YAHOO . util . Dom . setStyle ( this . mapDiv , 'display' , '' ) ;
264
- }
265
-
266
- if ( ! this . map )
267
- {
268
- var center = ( this . center || "" ) . split ( "," ) ;
269
- if ( center . length == 1 )
262
+ YAHOO . util . Dom . setStyle ( scope . id + this . parentElementIdSuffix , 'display' , '' ) ;
263
+ Dom . addClass ( scope . id + this . parentElementIdSuffix , "documents-geo" ) ;
264
+
265
+ var mapId = scope . id + this . parentElementIdSuffix + "-map" ,
266
+ mapDiv = Dom . get ( mapId ) ;
267
+
268
+ var container = Dom . get ( scope . id + this . parentElementIdSuffix ) ;
269
+ var oRecordSet = scope . widgets . dataTable . getRecordSet ( ) ;
270
+
271
+ scope . widgets . dataTable . onDataReturnInitializeTable . call ( scope . widgets . dataTable , sRequest , oResponse , oPayload ) ;
272
+
273
+ if ( ! this . mapDiv )
274
+ {
275
+ mapDiv = document . createElement ( "div" ) ;
276
+ Dom . setAttribute ( mapDiv , "id" , mapId ) ;
277
+ Dom . addClass ( mapDiv , "map" ) ;
278
+ Dom . setStyle ( mapDiv , "height" , "" + ( ( window . innerHeight || document . documentElement . offsetHeight || document . body . offsetHeight ) - 310 ) + "px" ) ;
279
+ Dom . get ( scope . id + this . parentElementIdSuffix ) . appendChild ( mapDiv ) ;
280
+ this . mapDiv = mapDiv ;
281
+ }
282
+ else
270
283
{
271
- center = [ 51 , 0 ] ;
284
+ YAHOO . util . Dom . setStyle ( this . mapDiv , 'display' , '' ) ;
272
285
}
273
286
274
- this . _renderMap ( scope , mapId , {
275
- center : {
276
- lat : center [ 0 ] ,
277
- lng : center [ 1 ]
287
+ if ( ! this . map )
288
+ {
289
+ var center = ( this . center || "" ) . split ( "," ) ;
290
+ if ( center . length == 1 )
291
+ {
292
+ center = [ 51 , 0 ] ;
278
293
}
279
- } ) ;
280
- }
281
-
282
- this . _removeAllMarkers ( ) ;
283
-
284
- var galleryItemTemplate = Dom . get ( scope . id + '-geo-item-template' ) ,
285
- galleryItem = null ;
286
-
287
- var oRecord , record , i , j ;
288
- for ( i = 0 , j = oRecordSet . getLength ( ) ; i < j ; i ++ )
289
- {
290
- oRecord = oRecordSet . getRecord ( i ) ;
291
- record = oRecord . getData ( ) ;
292
-
293
- // Append a gallery item div
294
- var galleryItemId = this . getRowItemId ( oRecord ) ;
295
- galleryItem = galleryItemTemplate . cloneNode ( true ) ;
296
- Dom . removeClass ( galleryItem , 'hidden' ) ;
297
- galleryItem . setAttribute ( 'id' , galleryItemId ) ;
298
- container . appendChild ( galleryItem ) ;
294
+
295
+ this . _renderMap ( scope , mapId , {
296
+ center : {
297
+ lat : center [ 0 ] ,
298
+ lng : center [ 1 ]
299
+ }
300
+ } ) ;
301
+ }
299
302
300
- var galleryItemDetailDiv = this . getRowItemDetailElement ( galleryItem ) ;
301
- var galleryItemActionsDiv = this . getRowItemActionsElement ( galleryItem ) ;
303
+ this . _removeAllMarkers ( ) ;
302
304
303
- // Suffix of the content actions div id must match the onEventHighlightRow target id
304
- galleryItemActionsDiv . setAttribute ( 'id' , scope . id + '-actions-' + galleryItemId ) ;
305
+ var galleryItemTemplate = Dom . get ( scope . id + '-geo-item-template' ) ,
306
+ galleryItem = null ;
307
+
308
+ var oRecord , record , i , j ;
309
+ for ( i = 0 , j = oRecordSet . getLength ( ) ; i < j ; i ++ )
310
+ {
311
+ oRecord = oRecordSet . getRecord ( i ) ;
312
+ record = oRecord . getData ( ) ;
313
+
314
+ // Append a gallery item div
315
+ var galleryItemId = this . getRowItemId ( oRecord ) ;
316
+ galleryItem = galleryItemTemplate . cloneNode ( true ) ;
317
+ Dom . removeClass ( galleryItem , 'hidden' ) ;
318
+ galleryItem . setAttribute ( 'id' , galleryItemId ) ;
319
+ container . appendChild ( galleryItem ) ;
320
+
321
+ var galleryItemDetailDiv = this . getRowItemDetailElement ( galleryItem ) ;
322
+ var galleryItemActionsDiv = this . getRowItemActionsElement ( galleryItem ) ;
323
+
324
+ // Suffix of the content actions div id must match the onEventHighlightRow target id
325
+ galleryItemActionsDiv . setAttribute ( 'id' , scope . id + '-actions-' + galleryItemId ) ;
305
326
306
- // Details div ID
307
- galleryItemDetailDiv . setAttribute ( 'id' , scope . id + '-details-' + galleryItemId ) ;
327
+ // Details div ID
328
+ galleryItemDetailDiv . setAttribute ( 'id' , scope . id + '-details-' + galleryItemId ) ;
308
329
309
- var properties = record . jsNode . properties ;
330
+ var properties = record . jsNode . properties ;
310
331
311
- // create a marker in the given location and add it to the map
312
- if ( properties [ "cm:latitude" ] && properties [ "cm:longitude" ] )
313
- {
314
- this . _addMarker ( {
315
- lat : properties [ "cm:latitude" ] ,
316
- lng : properties [ "cm:longitude" ] ,
317
- title : record . displayName ,
318
- galleryItemDetailDivId : scope . id + '-details-' + galleryItemId
319
- } ) ;
320
- }
321
- } ;
332
+ // create a marker in the given location and add it to the map
333
+ if ( properties [ "cm:latitude" ] && properties [ "cm:longitude" ] )
334
+ {
335
+ this . _addMarker ( {
336
+ lat : properties [ "cm:latitude" ] ,
337
+ lng : properties [ "cm:longitude" ] ,
338
+ title : record . displayName ,
339
+ galleryItemDetailDivId : scope . id + '-details-' + galleryItemId
340
+ } ) ;
341
+ }
342
+ } ;
343
+ }
322
344
} ;
323
345
324
346
/**
@@ -332,6 +354,7 @@ if (typeof Extras == "undefined" || !Extras)
332
354
*/
333
355
Extras . DocumentListGeoViewRenderer . prototype . _renderMap = function DL_GVR__renderMap ( scope , mapId , pObj )
334
356
{
357
+ /*
335
358
// set up the map
336
359
var center = pObj.center,
337
360
map = new L.Map(mapId).setView([center.lat, center.lng], this.zoomLevel);
@@ -350,6 +373,26 @@ if (typeof Extras == "undefined" || !Extras)
350
373
}, this);
351
374
352
375
this.map = map;
376
+ */
377
+ var me = this ,
378
+ center = pObj . center ;
379
+ var myLatlng = new google . maps . LatLng ( center . lat , center . lng ) ;
380
+ this . map = new google . maps . Map ( Dom . get ( mapId ) , {
381
+ center : myLatlng ,
382
+ zoom : this . zoomLevel ,
383
+ mapTypeId : this . mapTypeId != null ? this . mapTypeId : google . maps . MapTypeId . ROADMAP
384
+ } ) ;
385
+
386
+ // Update map settings as user preferences
387
+ google . maps . event . addListener ( this . map , "zoom_changed" , function ( ) {
388
+ me . _saveMapPreferences . call ( me , scope ) ;
389
+ } ) ;
390
+ google . maps . event . addListener ( this . map , "dragend" , function ( ) {
391
+ me . _saveMapPreferences . call ( me , scope ) ;
392
+ } ) ;
393
+ google . maps . event . addListener ( this . map , "maptypeid_changed" , function ( ) {
394
+ me . _saveMapPreferences . call ( me , scope ) ;
395
+ } ) ;
353
396
}
354
397
355
398
/**
@@ -362,12 +405,32 @@ if (typeof Extras == "undefined" || !Extras)
362
405
*/
363
406
Extras . DocumentListGeoViewRenderer . prototype . _addMarker = function DL_GVR__addMarker ( mObj )
364
407
{
408
+ /*
365
409
var marker = L.marker([mObj.lat, mObj.lng], {
366
410
title: mObj.title
367
411
}).addTo(this.map);
368
412
marker.bindPopup(Dom.get(mObj.galleryItemDetailDivId), { width: 400, maxWidth: 400 });
369
413
Alfresco.logger.debug("Binding popup to item ID " + mObj.galleryItemDetailDivId);
370
414
this.markers.push(marker);
415
+ */
416
+ var me = this , map = this . map ;
417
+ var latLng = new google . maps . LatLng ( mObj . lat , mObj . lng ) ;
418
+ var marker = new google . maps . Marker (
419
+ {
420
+ position : latLng ,
421
+ map : map ,
422
+ title : mObj . title
423
+ } ) ;
424
+ this . markers . push ( marker ) ;
425
+
426
+ var infowindow = new google . maps . InfoWindow ( {
427
+ content : Dom . get ( mObj . galleryItemDetailDivId ) ,
428
+ size : new google . maps . Size ( 50 , 50 )
429
+ } ) ;
430
+ google . maps . event . addListener ( marker , 'click' , function ( ) {
431
+ infowindow . open ( map , marker ) ;
432
+ me . selectedMarker = marker ;
433
+ } ) ;
371
434
}
372
435
373
436
/**
@@ -380,7 +443,8 @@ if (typeof Extras == "undefined" || !Extras)
380
443
{
381
444
for ( var i = 0 ; i < this . markers . length ; i ++ )
382
445
{
383
- this . map . removeLayer ( this . markers [ i ] ) ;
446
+ //this.map.removeLayer(this.markers[i]);
447
+ this . markers [ i ] . setMap ( null ) ;
384
448
}
385
449
}
386
450
@@ -393,33 +457,59 @@ if (typeof Extras == "undefined" || !Extras)
393
457
*/
394
458
Extras . DocumentListGeoViewRenderer . prototype . _saveMapPreferences = function DL_GVR__saveMapPreferences ( scope )
395
459
{
460
+ /*
461
+ // save map position and zoom levels
462
+ // when zooming leaflet fires both events, which leads to an exception being thrown from the repo
463
+ // therefore we must first check that the another event is not 'in progress' before attempting the save
396
464
this._savePreferenceValues(scope, {
397
465
zoom: this.map.getZoom(),
398
466
center: {
399
467
lat: this.map.getCenter().lat,
400
468
lng: this.map.getCenter().lng
401
469
}
402
470
});
471
+ */
472
+ this . _savePreferenceValues ( scope , {
473
+ zoom : this . map . getZoom ( ) ,
474
+ center : {
475
+ lat : this . map . getCenter ( ) . lat ( ) ,
476
+ lng : this . map . getCenter ( ) . lng ( )
477
+ } ,
478
+ mapTypeId : this . map . getMapTypeId ( )
479
+ } ) ;
403
480
}
404
481
405
482
/**
406
483
* Save preference values
407
484
*
408
485
* @method _savePreferenceValues
409
486
* @param scope {object} The DocumentList object
410
- * @param {object } pObj Setting values. Must define properties `center` and `zoom`.
487
+ * @param {object } pObj Setting values. Must define properties `center` and `zoom`, can define others .
411
488
* @private
412
489
*/
413
490
Extras . DocumentListGeoViewRenderer . prototype . _savePreferenceValues = function DL_GVR__savePreferenceValues ( scope , pObj )
414
491
{
415
- // save map position and zoom levels
416
- // when zooming leaflet fires both events, which leads to an exception being thrown from the repo
417
- // therefore we must first check that the another event is not 'in progress' before attempting the save
418
492
if ( this . savingPrefs == false )
419
493
{
420
494
this . savingPrefs = true ;
495
+ var prefValues = { } ;
496
+ for ( var k in pObj )
497
+ {
498
+ if ( k == "center" )
499
+ {
500
+ prefValues [ "center" ] = "" + pObj . center . lat + "," + pObj . center . lng ;
501
+ }
502
+ else if ( k == "zoom" )
503
+ {
504
+ prefValues [ "zoomLevel" ] = pObj . zoom ;
505
+ }
506
+ else
507
+ {
508
+ prefValues [ k ] = pObj [ k ] ;
509
+ }
510
+ }
421
511
Alfresco . logger . debug ( "Set " + PREFERENCES_DOCLIST + " to " + pObj . zoom ) ;
422
- scope . services . preferences . set ( PREFERENCES_DOCLIST , { zoomLevel : pObj . zoom , center : pObj . center . lat + "," + pObj . center . lng } , {
512
+ scope . services . preferences . set ( PREFERENCES_DOCLIST , prefValues , {
423
513
successCallback : {
424
514
fn : function ( ) {
425
515
this . savingPrefs = false ;
@@ -435,5 +525,10 @@ if (typeof Extras == "undefined" || !Extras)
435
525
} ) ;
436
526
}
437
527
}
528
+
529
+ Extras . DocumentListGeoViewRenderer . onGMapsScriptLoad = function DL_GVR_onGMapsScriptLoad ( e )
530
+ {
531
+ YAHOO . Bubbling . fire ( "gmapsScriptLoaded" ) ;
532
+ }
438
533
439
534
} ) ( ) ;
0 commit comments