MCPcopy
hub / github.com/google-map-react/google-map-react / getBounds

Method getBounds

src/lib/geo/index.js:109–150  ·  view source on GitHub ↗
(margins, roundFactor)

Source from the content-addressed store, hash-verified

107 }
108
109 getBounds(margins, roundFactor) {
110 const bndT = (margins && margins[0]) || 0;
111 const bndR = (margins && margins[1]) || 0;
112 const bndB = (margins && margins[2]) || 0;
113 const bndL = (margins && margins[3]) || 0;
114
115 if (
116 this.getWidth() - bndR - bndL > 0 &&
117 this.getHeight() - bndT - bndB > 0
118 ) {
119 const topLeftCorner = this.transform_.pointLocation(
120 Point.convert({
121 x: bndL - this.getWidth() / 2,
122 y: bndT - this.getHeight() / 2,
123 })
124 );
125 const bottomRightCorner = this.transform_.pointLocation(
126 Point.convert({
127 x: this.getWidth() / 2 - bndR,
128 y: this.getHeight() / 2 - bndB,
129 })
130 );
131
132 let res = [
133 topLeftCorner.lat,
134 topLeftCorner.lng, // NW
135 bottomRightCorner.lat,
136 bottomRightCorner.lng, // SE
137 bottomRightCorner.lat,
138 topLeftCorner.lng, // SW
139 topLeftCorner.lat,
140 bottomRightCorner.lng, // NE
141 ];
142
143 if (roundFactor) {
144 res = res.map((r) => Math.round(r * roundFactor) / roundFactor);
145 }
146 return res;
147 }
148
149 return [0, 0, 0, 0];
150 }
151}

Callers 1

GoogleMapClass · 0.80

Calls 3

getWidthMethod · 0.95
getHeightMethod · 0.95
pointLocationMethod · 0.80

Tested by

no test coverage detected