@@ -57,6 +57,7 @@ angular.module('ngMap', []);
57
57
var objs = obj . map [ groupName ] ;
58
58
for ( var name in objs ) {
59
59
if ( objs [ name ] === obj ) {
60
+ console . log ( 'Deleting' , groupName , obj ) ;
60
61
google . maps . event . clearInstanceListeners ( obj ) ;
61
62
delete objs [ name ] ;
62
63
}
@@ -360,6 +361,9 @@ angular.module('ngMap', []);
360
361
var position = options . position ;
361
362
mapController . map . controls [ google . maps . ControlPosition [ position ] ] . push ( customControlEl ) ;
362
363
364
+ element . bind ( '$destroy' , function ( ) {
365
+ mapController . deleteObject ( 'customControls' , customControlEl ) ;
366
+ } ) ;
363
367
} ;
364
368
365
369
var customControl = function ( Attr2MapOptions , _$compile_ , _NgMap_ ) {
@@ -412,6 +416,7 @@ angular.module('ngMap', []);
412
416
413
417
this . el = document . createElement ( 'div' ) ;
414
418
this . el . style . display = 'inline-block' ;
419
+ this . el . style . visibility = "hidden" ;
415
420
this . visible = true ;
416
421
for ( var key in options ) { /* jshint ignore:line */
417
422
this [ key ] = options [ key ] ;
@@ -446,10 +451,15 @@ angular.module('ngMap', []);
446
451
position && ( this . position = position ) ; /* jshint ignore:line */
447
452
if ( this . getProjection ( ) && typeof this . position . lng == 'function' ) {
448
453
var posPixel = this . getProjection ( ) . fromLatLngToDivPixel ( this . position ) ;
449
- var x = Math . round ( posPixel . x - ( this . el . offsetWidth / 2 ) ) ;
450
- var y = Math . round ( posPixel . y - this . el . offsetHeight - 10 ) ; // 10px for anchor
451
- this . el . style . left = x + "px" ;
452
- this . el . style . top = y + "px" ;
454
+ //delayed left/top calculation. with/height are not set instantly
455
+ var _this = this ;
456
+ $timeout ( function ( ) {
457
+ var x = Math . round ( posPixel . x - ( _this . el . offsetWidth / 2 ) ) ;
458
+ var y = Math . round ( posPixel . y - _this . el . offsetHeight - 10 ) ; // 10px for anchor
459
+ _this . el . style . left = x + "px" ;
460
+ _this . el . style . top = y + "px" ;
461
+ _this . el . style . visibility = "visible" ;
462
+ } , 300 ) ;
453
463
}
454
464
} ;
455
465
@@ -506,7 +516,7 @@ angular.module('ngMap', []);
506
516
/**
507
517
* build a custom marker element
508
518
*/
509
- var removedEl = element [ 0 ] . parentElement . removeChild ( element [ 0 ] ) ;
519
+ element [ 0 ] . style . display = 'none' ;
510
520
console . log ( "custom-marker options" , options ) ;
511
521
var customMarker = new CustomMarker ( options ) ;
512
522
@@ -515,11 +525,11 @@ angular.module('ngMap', []);
515
525
customMarker . setContent ( orgHtml , scope ) ;
516
526
} ) ;
517
527
518
- customMarker . setContent ( removedEl . innerHTML , scope ) ;
519
- var classNames = removedEl . firstElementChild . className ;
528
+ customMarker . setContent ( element [ 0 ] . innerHTML , scope ) ;
529
+ var classNames = element [ 0 ] . firstElementChild . className ;
520
530
customMarker . addClass ( 'custom-marker' ) ;
521
531
customMarker . addClass ( classNames ) ;
522
- console . log ( 'customMarker' , customMarker ) ;
532
+ console . log ( 'customMarker' , customMarker , 'classNames' , classNames ) ;
523
533
524
534
if ( ! ( options . position instanceof google . maps . LatLng ) ) {
525
535
NgMap . getGeoLocation ( options . position ) . then (
@@ -2901,9 +2911,11 @@ angular.module('ngMap', []);
2901
2911
var deleteMap = function ( mapCtrl ) {
2902
2912
var len = Object . keys ( mapControllers ) . length - 1 ;
2903
2913
var mapId = mapCtrl . map . id || len ;
2904
- mapCtrl . map . controls . forEach ( function ( ctrl ) {
2905
- ctrl . clear ( ) ;
2906
- } ) ;
2914
+ if ( typeof mapCtrl . map . controls != "undefined" ) {
2915
+ mapCtrl . map . controls . forEach ( function ( ctrl ) {
2916
+ ctrl . clear ( ) ;
2917
+ } ) ;
2918
+ }
2907
2919
//delete mapCtrl.map;
2908
2920
delete mapControllers [ mapId ] ;
2909
2921
} ;
0 commit comments