Newer
Older
import * as L from 'leaflet';
import {Location} from '../nshmp-lib/geo';
import {MapBaseLayer} from './map-baselayer.model';
/** Location transform */
export type LocationTransform = (location: Location) => Location;
/**
* Esri raster base layers for Leaflet.
*
* https://doc.arcgis.com/en/data-appliance/latest/maps/directory-maps-data.htm
*/
export function baseLayers(): Record<MapBaseLayer, L.TileLayer> {
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const baseLayers: Record<MapBaseLayer, L.TileLayer> = {
/* Esri world hillshade */
[MapBaseLayer.HILLSHADE]: L.tileLayer(
`${ARCGIS_URL_START}Elevation/World_Hillshade${ARCGIS_URL_END}`,
{
...OPTIONS,
attribution:
'Esri, USGS, NGA, NASA, CGIAR, N Robinson, NCEAS, NLS, OS, NMA, ' +
'Geodatastyrelsen, Rijkswaterstaat, GSA, Geoland, FEMA, Intermap, ' +
'and the GIS user community',
id: MapBaseLayer.HILLSHADE,
}
),
/* Esri world hillshade */
[MapBaseLayer.HILLSHADE_DARK]: L.tileLayer(
`${ARCGIS_URL_START}Elevation/World_Hillshade_Dark${ARCGIS_URL_END}`,
{
...OPTIONS,
attribution:
'Esri, USGS, NGA, NASA, CGIAR, N Robinson, NCEAS, NLS, OS, NMA, ' +
'Geodatastyrelsen, Rijkswaterstaat, GSA, Geoland, FEMA, Intermap, ' +
'and the GIS user community',
id: MapBaseLayer.HILLSHADE_DARK,
}
),
/* Esri world ocean */
[MapBaseLayer.OCEAN]: L.tileLayer(
`${ARCGIS_URL_START}Ocean/World_Ocean_Base${ARCGIS_URL_END}`,
{
...OPTIONS,
attribution: 'Esri, Garmin, GEBCO, NOAA NGDC, and other contributors',
id: MapBaseLayer.OCEAN,
maxZoom: 10,
}
),
/* Esri world physical map */
[MapBaseLayer.PHYSICAL]: L.tileLayer(
`${ARCGIS_URL_START}World_Physical_Map${ARCGIS_URL_END}`,
{
...OPTIONS,
attribution: 'U.S. National Park Service',
id: MapBaseLayer.PHYSICAL,
maxZoom: 8,
}
),
[MapBaseLayer.SATELLITE]: L.tileLayer(
`${ARCGIS_URL_START}World_Imagery${ARCGIS_URL_END}`,
{
...OPTIONS,
attribution:
'Esri, Maxar, Earthstar Geographics, and the GIS User Community',
id: MapBaseLayer.SATELLITE,
}
),
[MapBaseLayer.USGS_TOPO]: L.tileLayer(
'https://basemap.nationalmap.gov/arcgis/rest/services/USGSTopo/MapServer/tile/{z}/{y}/{x}',
attribution: `Esri, USGS | Esri, TomTom, FAO, NOAA, USGS | USGS The National Map: National Boundaries
Dataset, 3DEP Elevation Program, Geographic Names Information System, National Hydrography
Dataset, National Land Cover Database, National Structures Dataset, and National
Transportation Dataset; USGS Global Ecosystems; U.S. Census Bureau TIGER/Line data;
USFS Road data; Natural Earth Data; U.S. Department of State HIU; NOAA National
Centers for Environmental Information. Data refreshed February, 2025.`,
id: MapBaseLayer.USGS_TOPO,
}
/**
* Returns a specific Esri raster base layer.
*/
export function baseLayer(baseLayer: MapBaseLayer): L.TileLayer {
}
/**
* Transform coordinates in a Feature Collection.
*
* @param featureCollection The feature collection
* @param transform The transform function to use
*/
export function transformCoordinates(
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
for (const feature of featureCollection.features) {
const geometry = feature.geometry;
switch (geometry.type) {
case 'LineString': {
geometry.coordinates = geometry.coordinates.map(coord =>
transformCoordinate(coord, transform)
);
break;
}
case 'MultiLineString': {
geometry.coordinates = geometry.coordinates.map(position =>
position.map(coord => transformCoordinate(coord, transform))
);
break;
}
case 'MultiPoint': {
geometry.coordinates = geometry.coordinates.map(coord =>
transformCoordinate(coord, transform)
);
break;
}
case 'MultiPolygon': {
geometry.coordinates = geometry.coordinates.map(positions =>
positions.map(position =>
position.map(coord => transformCoordinate(coord, transform))
)
);
break;
}
case 'Point': {
geometry.coordinates = transformCoordinate(
geometry.coordinates,
transform
);
break;
}
case 'Polygon': {
geometry.coordinates = geometry.coordinates.map(position =>
position.map(coord => transformCoordinate(coord, transform))
);
break;
}
}
}
return featureCollection;
}
const ARCGIS_URL_START =
'https://services.arcgisonline.com/arcgis/rest/services/';
const ARCGIS_URL_END = '/MapServer/tile/{z}/{y}/{x}';
const OPTIONS: L.MapOptions = {
maxZoom: 16,
};
function transformCoordinate(
coordinates: number[],
transform: LocationTransform
): number[] {
const longitude = coordinates[0];
const latitude = coordinates[1];
const location = transform({
latitude,
longitude,
});
return [location.longitude, location.latitude];
}