Skip to content

Commit 8cc27d3

Browse files
committed
WIP add google map tiles layer
1 parent c5e1cba commit 8cc27d3

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/instance/methods/layer.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Import source types, layer types, and formats.
22
import VectorSource from 'ol/source/Vector';
33
import Cluster from 'ol/source/Cluster';
4+
import Google from 'ol/source/Google';
45
import TileArcGISRest from 'ol/source/TileArcGISRest';
56
import TileWMS from 'ol/source/TileWMS';
67
import XYZ from 'ol/source/XYZ';
@@ -103,6 +104,28 @@ function addGeoJSONLayer({
103104
return layer;
104105
}
105106

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+
106129
// Add a Tile ArcGIS MapServer layer to the map.
107130
function addTileArcGISMapServerLayer({
108131
title = 'arcgis-tile', url, params, visible = true, base = false, attribution = '', crossOrigin = null,
@@ -226,6 +249,12 @@ export default function addLayer(type, opts = {}) {
226249
}
227250
layer = addGeoJSONLayer(opts);
228251
}
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+
}
229258
if (type.toLowerCase() === 'arcgis-tile') {
230259
if (!opts.url) {
231260
throw new Error('Missing a ArcGIS MapServer url.');

0 commit comments

Comments
 (0)