* Render static map with all map features that were added to map before
(center, zoom)
| 107 | * Render static map with all map features that were added to map before |
| 108 | */ |
| 109 | async render(center, zoom) { |
| 110 | if (!this.lines && !this.markers && !this.multipolygons && !(center && zoom)) { |
| 111 | throw new Error('Cannot render empty map: Add center || lines || markers || polygons.'); |
| 112 | } |
| 113 | |
| 114 | this.center = center; |
| 115 | this.zoom = zoom || this.calculateZoom(); |
| 116 | |
| 117 | const maxZoom = this.zoomRange.max; |
| 118 | if (maxZoom && this.zoom > maxZoom) this.zoom = maxZoom; |
| 119 | |
| 120 | if (center && center.length === 2) { |
| 121 | this.centerX = geoutils.lonToX(center[0], this.zoom); |
| 122 | this.centerY = geoutils.latToY(center[1], this.zoom); |
| 123 | } else { |
| 124 | // # get extent of all lines |
| 125 | const extent = this.determineExtent(this.zoom); |
| 126 | |
| 127 | // # calculate center point of map |
| 128 | const centerLon = (extent[0] + extent[2]) / 2; |
| 129 | const centerLat = (extent[1] + extent[3]) / 2; |
| 130 | |
| 131 | this.centerX = geoutils.lonToX(centerLon, this.zoom); |
| 132 | this.centerY = geoutils.latToY(centerLat, this.zoom); |
| 133 | } |
| 134 | |
| 135 | this.image = new Image(this.options); |
| 136 | |
| 137 | // Await this.drawLayer for each tile layer |
| 138 | await mapSeries(this.tileLayers, async (layer) => { |
| 139 | await this.drawLayer(layer); |
| 140 | }); |
| 141 | |
| 142 | await this.loadMarker(); |
| 143 | return this.drawFeatures(); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * calculate common extent of all current map features |
no test coverage detected