|
1 | 1 | // Import source types, layer types, and formats. |
2 | 2 | import VectorSource from 'ol/source/Vector'; |
3 | 3 | import Cluster from 'ol/source/Cluster'; |
| 4 | +import Google from 'ol/source/Google'; |
4 | 5 | import TileArcGISRest from 'ol/source/TileArcGISRest'; |
5 | 6 | import TileWMS from 'ol/source/TileWMS'; |
6 | 7 | import XYZ from 'ol/source/XYZ'; |
@@ -103,6 +104,28 @@ function addGeoJSONLayer({ |
103 | 104 | return layer; |
104 | 105 | } |
105 | 106 |
|
| 107 | +// Add a Google Map Tiles layer to the map. |
| 108 | +function addGoogleMapTilesLayer({ |
| 109 | + title = 'google-map-tiles', key, mapType = 'satellite', language = 'en-US', region = 'US', apiOptions = null, visible = true, base = false, |
| 110 | +}) { |
| 111 | + const source = new Google({ |
| 112 | + key, |
| 113 | + mapType, |
| 114 | + language, |
| 115 | + region, |
| 116 | + apiOptions, |
| 117 | + scale: 'scaleFactor2x', |
| 118 | + highDpi: true, |
| 119 | + }); |
| 120 | + const layer = new TileLayer({ |
| 121 | + title, |
| 122 | + source, |
| 123 | + visible, |
| 124 | + type: base ? 'base' : 'normal', |
| 125 | + }); |
| 126 | + return layer; |
| 127 | +} |
| 128 | + |
106 | 129 | // Add a Tile ArcGIS MapServer layer to the map. |
107 | 130 | function addTileArcGISMapServerLayer({ |
108 | 131 | title = 'arcgis-tile', url, params, visible = true, base = false, attribution = '', crossOrigin = null, |
@@ -226,6 +249,12 @@ export default function addLayer(type, opts = {}) { |
226 | 249 | } |
227 | 250 | layer = addGeoJSONLayer(opts); |
228 | 251 | } |
| 252 | + if (type.toLowerCase() === 'google') { |
| 253 | + if (!opts.key) { |
| 254 | + throw new Error('Missing a Google Map Tiles API key.'); |
| 255 | + } |
| 256 | + layer = addGoogleMapTilesLayer(opts); |
| 257 | + } |
229 | 258 | if (type.toLowerCase() === 'arcgis-tile') { |
230 | 259 | if (!opts.url) { |
231 | 260 | throw new Error('Missing a ArcGIS MapServer url.'); |
|
0 commit comments