|
1 |
| -import { CRS } from 'leaflet'; |
2 |
| -import STAC from './src/models/stac'; |
| 1 | +import { Collection, Item } from './src/models/stac'; |
3 | 2 | import Utils from './src/utils';
|
4 | 3 |
|
5 | 4 | const USGS_ATTRIBUTION = 'USGS Astrogeology';
|
6 |
| -const WMS = 'LWMSTileLayer'; |
7 |
| -const XYZ = 'LTileLayer'; |
| 5 | +const WMS = 'TileWMS'; |
| 6 | +const XYZ = 'XYZ'; |
8 | 7 |
|
| 8 | +// All options (except for 'is') follow the OpenLayers options for the respective source class. |
| 9 | +// Projections (except for EPSG:3857 and EPSG:4326) must be listed in the `crs` array in the config.js. |
| 10 | +// |
| 11 | +// There's a layerCreated callback that can be used to modify the layer and source after it has been created: |
| 12 | +// async layerCreated(Layer layer, Source source) => Layer |
9 | 13 | const BASEMAPS = {
|
10 |
| - earth: { |
11 |
| - url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', |
12 |
| - name: 'OpenStreetMap', |
13 |
| - is: XYZ, |
14 |
| - attribution: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors.' |
15 |
| - }, |
16 |
| - europa: { |
17 |
| - baseUrl: 'https://planetarymaps.usgs.gov/cgi-bin/mapserv?map=/maps/jupiter/europa_simp_cyl.map', |
18 |
| - is: WMS, |
19 |
| - name: 'USGS Europa', |
20 |
| - attribution: USGS_ATTRIBUTION, |
21 |
| - crs: CRS.EPSG4326, |
22 |
| - format: 'image/png', |
23 |
| - layers: 'GALILEO_VOYAGER' |
24 |
| - }, |
25 |
| - mars: { |
26 |
| - baseUrl: 'https://planetarymaps.usgs.gov/cgi-bin/mapserv?map=/maps/mars/mars_simp_cyl.map', |
27 |
| - is: WMS, |
28 |
| - name: 'USGS Mars', |
29 |
| - attribution: USGS_ATTRIBUTION, |
30 |
| - crs: CRS.EPSG4326, |
31 |
| - format: 'image/png', |
32 |
| - layers: 'MDIM21' |
33 |
| - }, |
34 |
| - moon: { |
35 |
| - baseUrl: 'https://planetarymaps.usgs.gov/cgi-bin/mapserv?map=/maps/earth/moon_simp_cyl.map', |
36 |
| - is: WMS, |
37 |
| - name: 'USGS Moon', |
38 |
| - attribution: USGS_ATTRIBUTION, |
39 |
| - crs: CRS.EPSG4326, |
40 |
| - format: 'image/png', |
41 |
| - layers: 'LROC_WAC' |
42 |
| - } |
| 14 | + earth: [ |
| 15 | + { |
| 16 | + url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', |
| 17 | + is: XYZ, |
| 18 | + title: 'OpenStreetMap', |
| 19 | + attributions: '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors.', |
| 20 | + projection: "EPSG:3857" |
| 21 | + } |
| 22 | + ], |
| 23 | + europa: [ |
| 24 | + { |
| 25 | + url: 'https://planetarymaps.usgs.gov/cgi-bin/mapserv?map=/maps/jupiter/europa_simp_cyl.map', |
| 26 | + is: WMS, |
| 27 | + title: 'USGS Europa', |
| 28 | + attributions: USGS_ATTRIBUTION, |
| 29 | + projection: 'EPSG:4326', |
| 30 | + params: { |
| 31 | + FORMAT: 'image/png', |
| 32 | + LAYERS: 'GALILEO_VOYAGER' |
| 33 | + } |
| 34 | + }, |
| 35 | + ], |
| 36 | + mars: [ |
| 37 | + { |
| 38 | + url: 'https://planetarymaps.usgs.gov/cgi-bin/mapserv?map=/maps/mars/mars_simp_cyl.map', |
| 39 | + is: WMS, |
| 40 | + title: 'USGS Mars', |
| 41 | + attributions: USGS_ATTRIBUTION, |
| 42 | + projection: 'EPSG:4326', |
| 43 | + params: { |
| 44 | + FORMAT: 'image/png', |
| 45 | + LAYERS: 'MDIM21' |
| 46 | + } |
| 47 | + } |
| 48 | + ], |
| 49 | + moon: [ |
| 50 | + { |
| 51 | + url: 'https://planetarymaps.usgs.gov/cgi-bin/mapserv?map=/maps/earth/moon_simp_cyl.map', |
| 52 | + is: WMS, |
| 53 | + title: 'USGS Moon', |
| 54 | + attributions: USGS_ATTRIBUTION, |
| 55 | + projection: 'EPSG:4326', |
| 56 | + params: { |
| 57 | + FORMAT: 'image/png', |
| 58 | + LAYERS: 'LROC_WAC' |
| 59 | + } |
| 60 | + } |
| 61 | + ], |
43 | 62 | };
|
44 | 63 |
|
45 |
| -/** |
46 |
| - * @typedef BasemapOptions |
47 |
| - * @type {Object} |
48 |
| - * @property {string} is Component: LWMSTileLayer or LTileLayer |
49 |
| - * @see https://vue2-leaflet.netlify.app/components/ |
50 |
| - */ |
51 |
| - |
52 | 64 | /**
|
53 | 65 | *
|
54 | 66 | * @param {Object} stac The STAC object
|
55 |
| - * @param {Object} map The Leaflet map object |
56 | 67 | * @param {Object} i18n Vue I18N object
|
57 | 68 | * @returns {Array.<BasemapOptions>}
|
58 | 69 | */
|
59 |
| -export default function configureBasemap(stac, map, i18n) { |
60 |
| - let targets = ['earth']; |
61 |
| - if (stac instanceof STAC) { |
62 |
| - if (stac.isCollection() && Utils.isObject(stac.summaries) && Array.isArray(stac.summaries['ssys:targets'])) { |
63 |
| - targets = stac.summaries['ssys:targets']; |
64 |
| - } |
65 |
| - else if (stac.isCollection() && Array.isArray(stac['ssys:targets'])) { |
66 |
| - targets = stac['ssys:targets']; |
67 |
| - } |
68 |
| - else if (stac.isItem() && Array.isArray(stac.properties['ssys:targets'])) { |
69 |
| - targets = stac.properties['ssys:targets']; |
70 |
| - } |
| 70 | +export default function configureBasemap(stac, i18n) { |
| 71 | + let targets; |
| 72 | + if (stac instanceof Collection) { |
| 73 | + targets = stac.getSummary('ssys:targets'); |
| 74 | + } |
| 75 | + if (!targets) { |
| 76 | + targets = stac.getMetadata('ssys:targets'); |
| 77 | + } |
| 78 | + if (!targets) { |
| 79 | + targets = ['earth']; |
71 | 80 | }
|
72 | 81 |
|
73 |
| - return targets.map(target => BASEMAPS[target.toLowerCase()]); |
| 82 | + let layers = []; |
| 83 | + for (const target of targets) { |
| 84 | + const maps = BASEMAPS[target.toLowerCase()]; |
| 85 | + if (!Array.isArray(maps)) { |
| 86 | + continue; |
| 87 | + } |
| 88 | + layers = layers.concat(maps); |
| 89 | + } |
| 90 | + return layers; |
74 | 91 | };
|
0 commit comments