Skip to content

Commit f4ef371

Browse files
committed
Add crossOrigin option to raster layer types #204
1 parent adb2bc1 commit f4ef371

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010

1111
- Add snapshot control to download and print map. #202
12+
- Add crossOrigin option to raster layer types. #204
1213

1314
## [v2.3.0] - 2024-05-07
1415

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ const wmsOpts = {
180180
VERSION: '1.1.1',
181181
},
182182
visible: true, // defaults to true
183-
base: false // defaults to false
183+
base: false, // defaults to false
184+
crossOrigin: null, // defaults to null
184185
};
185186
const wmsLayer = myMap.addLayer('wms', wmsOpts);
186187

@@ -189,7 +190,8 @@ const arcGISTileOpts = {
189190
title: 'StateCityHighway_USA', // defaults to 'arcgis-tile'
190191
url: 'https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer', // REQUIRED!
191192
visible: true, // defaults to true
192-
base: false // defaults to false
193+
base: false, // defaults to false
194+
crossOrigin: null, // defaults to null
193195
};
194196
const arcGISTileLayer = myMap.addLayer('arcgis-tile', arcGISTileOpts);
195197

@@ -198,7 +200,8 @@ const xyzOpts = {
198200
title: 'mapbox', // defaults to 'xyz'
199201
url: 'https://api.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?access_token=[APIKEY]', // REQUIRED!
200202
visible: true, // defaults to true
201-
base: false // defaults to false
203+
base: false, // defaults to false
204+
crossOrigin: null, // defaults to null
202205
};
203206
const xyzLayer = myMap.addLayer('xyz', xyzOpts);
204207

@@ -221,6 +224,13 @@ const clusterLayer = myMap.addLayer('cluster', clusterOpts);
221224

222225
The method returns a reference to the newly created layer for later use.
223226

227+
All raster layer types have an optional `crossOrigin` option that sets the
228+
`crossorigin` attribute for loaded images. You must provide a `crossOrigin`
229+
value if you want to allow access to pixel data with the canvas renderer.
230+
This is required for the `snapshot` behavior to save images from the canvas.
231+
See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image
232+
for more detail.
233+
224234
#### Layer groups
225235

226236
Layers can optionally be placed inside layer groups. Simply provide a `group`

src/instance/methods/layer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,14 @@ function addGeoJSONLayer({
105105

106106
// Add a Tile ArcGIS MapServer layer to the map.
107107
function addTileArcGISMapServerLayer({
108-
title = 'arcgis-tile', url, params, visible = true, base = false, attribution = '',
108+
title = 'arcgis-tile', url, params, visible = true, base = false, attribution = '', crossOrigin = null,
109109
}) {
110110
const attributions = [attribution];
111111
const source = new TileArcGISRest({
112112
url,
113113
params,
114114
attributions,
115+
crossOrigin,
115116
});
116117
const layer = new TileLayer({
117118
title,
@@ -146,13 +147,14 @@ function addWKTLayer({
146147

147148
// Add a WMS tile layer to the map.
148149
function addWMSTileLayer({
149-
title = 'wms', url, params, visible = true, base = false, attribution = '',
150+
title = 'wms', url, params, visible = true, base = false, attribution = '', crossOrigin = null,
150151
}) {
151152
const attributions = [attribution];
152153
const source = new TileWMS({
153154
url,
154155
params,
155156
attributions,
157+
crossOrigin,
156158
});
157159
const layer = new TileLayer({
158160
title,
@@ -165,13 +167,14 @@ function addWMSTileLayer({
165167

166168
// Add an XYZ tile layer to the map.
167169
function addXYZTileLayer({
168-
title = 'xyz', url, tileSize = 256, visible = true, base = false, attribution = '',
170+
title = 'xyz', url, tileSize = 256, visible = true, base = false, attribution = '', crossOrigin = null,
169171
}) {
170172
const attributions = [attribution];
171173
const source = new XYZ({
172174
url,
173175
tileSize,
174176
attributions,
177+
crossOrigin,
175178
});
176179
const layer = new TileLayer({
177180
title,

0 commit comments

Comments
 (0)