@@ -57,6 +57,7 @@ angular.module('ngMap', []);
5757 var objs = obj . map [ groupName ] ;
5858 for ( var name in objs ) {
5959 if ( objs [ name ] === obj ) {
60+ console . log ( 'Deleting' , groupName , obj ) ;
6061 google . maps . event . clearInstanceListeners ( obj ) ;
6162 delete objs [ name ] ;
6263 }
@@ -360,6 +361,9 @@ angular.module('ngMap', []);
360361 var position = options . position ;
361362 mapController . map . controls [ google . maps . ControlPosition [ position ] ] . push ( customControlEl ) ;
362363
364+ element . bind ( '$destroy' , function ( ) {
365+ mapController . deleteObject ( 'customControls' , customControlEl ) ;
366+ } ) ;
363367 } ;
364368
365369 var customControl = function ( Attr2MapOptions , _$compile_ , _NgMap_ ) {
@@ -412,6 +416,7 @@ angular.module('ngMap', []);
412416
413417 this . el = document . createElement ( 'div' ) ;
414418 this . el . style . display = 'inline-block' ;
419+ this . el . style . visibility = "hidden" ;
415420 this . visible = true ;
416421 for ( var key in options ) { /* jshint ignore:line */
417422 this [ key ] = options [ key ] ;
@@ -446,10 +451,15 @@ angular.module('ngMap', []);
446451 position && ( this . position = position ) ; /* jshint ignore:line */
447452 if ( this . getProjection ( ) && typeof this . position . lng == 'function' ) {
448453 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 ) ;
453463 }
454464 } ;
455465
@@ -506,7 +516,7 @@ angular.module('ngMap', []);
506516 /**
507517 * build a custom marker element
508518 */
509- var removedEl = element [ 0 ] . parentElement . removeChild ( element [ 0 ] ) ;
519+ element [ 0 ] . style . display = 'none' ;
510520 console . log ( "custom-marker options" , options ) ;
511521 var customMarker = new CustomMarker ( options ) ;
512522
@@ -515,11 +525,11 @@ angular.module('ngMap', []);
515525 customMarker . setContent ( orgHtml , scope ) ;
516526 } ) ;
517527
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 ;
520530 customMarker . addClass ( 'custom-marker' ) ;
521531 customMarker . addClass ( classNames ) ;
522- console . log ( 'customMarker' , customMarker ) ;
532+ console . log ( 'customMarker' , customMarker , 'classNames' , classNames ) ;
523533
524534 if ( ! ( options . position instanceof google . maps . LatLng ) ) {
525535 NgMap . getGeoLocation ( options . position ) . then (
@@ -2901,9 +2911,11 @@ angular.module('ngMap', []);
29012911 var deleteMap = function ( mapCtrl ) {
29022912 var len = Object . keys ( mapControllers ) . length - 1 ;
29032913 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+ }
29072919 //delete mapCtrl.map;
29082920 delete mapControllers [ mapId ] ;
29092921 } ;
0 commit comments