@@ -23,6 +23,7 @@ export const overlayViewControlledPropTypes = {
23
23
getPixelPositionOffset : PropTypes . func ,
24
24
position : PropTypes . object ,
25
25
children : PropTypes . node ,
26
+ bounds : PropTypes . object ,
26
27
// NOTICE!!!!!!
27
28
//
28
29
// Only expose those with getters & setters in the table as controlled props.
@@ -95,17 +96,33 @@ export default class OverlayViewCreator extends Component {
95
96
overlayView . _positionContainerElement = function _positionContainerElement ( ) {
96
97
let left ;
97
98
let top ;
98
- const position = this . _getPixelPosition ( ) ;
99
- if ( position ) {
100
- let { x, y } = position ;
101
- const offset = this . _getOffset ( ) ;
102
- if ( offset ) {
103
- x += offset . x ;
104
- y += offset . y ;
99
+ const offset = this . _getOffset ( ) ;
100
+ if ( this . get ( `bounds` ) ) {
101
+ const bounds = this . _getPixelBounds ( ) ;
102
+ if ( bounds ) {
103
+ const { sw, ne } = bounds ;
104
+ if ( offset ) {
105
+ sw . x += offset . x ;
106
+ ne . y += offset . y ;
107
+ }
108
+ left = sw . x + `px` ;
109
+ top = ne . y + `px` ;
110
+ this . _containerElement . style . width = ( ne . x - sw . x ) + `px` ;
111
+ this . _containerElement . style . height = ( sw . y - ne . y ) + `px` ;
112
+ }
113
+ } else {
114
+ const position = this . _getPixelPosition ( ) ;
115
+ if ( position ) {
116
+ let { x, y } = position ;
117
+ if ( offset ) {
118
+ x += offset . x ;
119
+ y += offset . y ;
120
+ }
121
+ left = x + `px` ;
122
+ top = y + `px` ;
105
123
}
106
- left = x + `px` ;
107
- top = y + `px` ;
108
124
}
125
+
109
126
this . _containerElement . style . left = left ;
110
127
this . _containerElement . style . top = top ;
111
128
} ;
@@ -114,7 +131,6 @@ export default class OverlayViewCreator extends Component {
114
131
const projection = this . getProjection ( ) ;
115
132
let position = this . get ( `position` ) ;
116
133
invariant ( ! ! position , `OverlayView requires a position/defaultPosition in your props instead of %s` , position ) ;
117
-
118
134
if ( projection && position ) {
119
135
if ( ! ( position instanceof google . maps . LatLng ) ) {
120
136
position = new google . maps . LatLng ( position . lat , position . lng ) ;
@@ -123,6 +139,24 @@ export default class OverlayViewCreator extends Component {
123
139
}
124
140
} ;
125
141
142
+ overlayView . _getPixelBounds = function _getPixelBounds ( ) {
143
+ const projection = this . getProjection ( ) ;
144
+ let bounds = this . get ( `bounds` ) ;
145
+ invariant ( ! ! bounds , `OverlayView requires a bounds in your props instead of %s` , bounds ) ;
146
+ if ( projection && bounds ) {
147
+ if ( ! ( bounds instanceof google . maps . LatLngBounds ) ) {
148
+ bounds = new google . maps . LatLngBounds (
149
+ new google . maps . LatLng ( bounds . ne . lat , bounds . ne . lng ) ,
150
+ new google . maps . LatLng ( bounds . sw . lat , bounds . sw . lng )
151
+ ) ;
152
+ }
153
+ return {
154
+ sw : projection . fromLatLngToDivPixel ( this . bounds . getSouthWest ( ) ) ,
155
+ ne : projection . fromLatLngToDivPixel ( this . bounds . getNorthEast ( ) ) ,
156
+ } ;
157
+ }
158
+ } ;
159
+
126
160
overlayView . _getOffset = function _getOffset ( ) {
127
161
// Allows the component to control the visual position of the OverlayView
128
162
// relative to the LatLng pixel position.
0 commit comments