@@ -63,37 +63,27 @@ export default (function () {
6363 this . onClick ( this . location ) ;
6464 } ) ;
6565 }
66+ const point = this . getProjection ( ) . fromLatLngToDivPixel ( this . position ) ;
67+ if ( point ) {
68+ const southWest = this . map . getBounds ( ) . getSouthWest ( ) ;
69+ const northEast = this . map . getBounds ( ) . getNorthEast ( ) ;
70+ const sw = this . getProjection ( ) . fromLatLngToDivPixel ( southWest ) ;
71+ const ne = this . getProjection ( ) . fromLatLngToDivPixel ( northEast ) ;
72+
73+ const mapWidth = ne . x - sw . x ;
74+ const mapHeight = sw . y - ne . y ;
75+ // factor depends on the marker size
76+ const widthRatio = 45 / mapWidth ;
77+ const heightRatio = 45 / mapHeight ;
78+ div . style . width = `${ mapWidth * widthRatio } px` ;
79+ div . style . height = `${ mapHeight * heightRatio } px` ;
80+
81+ div . style . left = point . x + 'px' ;
82+ div . style . top = point . y + 'px' ;
83+ }
6684
6785 this . getPanes ( ) . overlayMouseTarget . appendChild ( div ) ;
6886
69- const changeBound = ( ) => {
70- // Position the overlay
71- if ( ! this . getProjection ( ) ) {
72- return ;
73- }
74- const point = this . getProjection ( ) . fromLatLngToDivPixel ( this . position ) ;
75- const sw = this . getProjection ( ) . fromLatLngToDivPixel (
76- this . map . getBounds ( ) . getSouthWest ( )
77- ) ;
78- const ne = this . getProjection ( ) . fromLatLngToDivPixel (
79- this . map . getBounds ( ) . getNorthEast ( )
80- ) ;
81- if ( point ) {
82- div . style . left = `${ point . x } px` ;
83- div . style . top = `${ point . y } px` ;
84- let width = ne . x - sw . x ;
85- let height = sw . y - ne . y ;
86- // factor depends on the marker size, circle has its own width
87- const ratio1 = 45 / width ;
88- const ratio2 = 45 / height ;
89- height *= ratio2 ; // Reset height to match scaled image
90- width *= ratio1 ;
91- div . style . width = `${ width } px` ;
92- div . style . height = `${ height } px` ;
93- }
94- } ;
95- changeBound ( ) ;
96- google . maps . event . addListener ( this . map , 'idle' , changeBound ) ;
9787 } ;
9888
9989 CustomMarker . prototype . remove = function ( ) {
0 commit comments