MCPcopy Create free account
hub / github.com/StephanGeorg/staticmaps / determineExtent

Method determineExtent

src/staticmaps.js:149–213  ·  view source on GitHub ↗

* calculate common extent of all current map features

(zoom)

Source from the content-addressed store, hash-verified

147 * calculate common extent of all current map features
148 */
149 determineExtent(zoom) {
150 const extents = [];
151
152 // Add bbox to extent
153 if (this.center && this.center.length >= 4) extents.push(this.center);
154
155 // add bounds to extent
156 if (this.bounds.length) {
157 this.bounds.forEach((bound) => extents.push(bound.extent()));
158 }
159
160 // Add polylines and polygons to extent
161 if (this.lines.length) {
162 this.lines.forEach((line) => {
163 extents.push(line.extent());
164 });
165 }
166 if (this.multipolygons.length) {
167 this.multipolygons.forEach((multipolygon) => {
168 extents.push(multipolygon.extent());
169 });
170 }
171
172 // Add circles to extent
173 if (this.circles.length) {
174 this.circles.forEach((circle) => {
175 extents.push(circle.extent());
176 });
177 }
178
179 // Add marker to extent
180 for (let i = 0; i < this.markers.length; i++) {
181 const marker = this.markers[i];
182 const e = [marker.coord[0], marker.coord[1]];
183
184 if (!zoom) {
185 extents.push([
186 marker.coord[0],
187 marker.coord[1],
188 marker.coord[0],
189 marker.coord[1],
190 ]);
191 continue;
192 }
193
194 // # consider dimension of marker
195 const ePx = marker.extentPx();
196 const x = geoutils.lonToX(e[0], zoom);
197 const y = geoutils.latToY(e[1], zoom);
198
199 extents.push([
200 geoutils.xToLon(x - parseFloat(ePx[0]) / this.tileSize, zoom),
201 geoutils.yToLat(y + parseFloat(ePx[1]) / this.tileSize, zoom),
202 geoutils.xToLon(x + parseFloat(ePx[2]) / this.tileSize, zoom),
203 geoutils.yToLat(y - parseFloat(ePx[3]) / this.tileSize, zoom),
204 ]);
205 }
206

Callers 2

renderMethod · 0.95
calculateZoomMethod · 0.95

Calls 2

extentPxMethod · 0.80
extentMethod · 0.45

Tested by

no test coverage detected