Skip to content

Commit

Permalink
CARTO: Don't hardcode mime-types (#8076)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer committed Aug 23, 2023
1 parent 9c36f1d commit 768bab2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
14 changes: 2 additions & 12 deletions modules/carto/src/layers/carto-tile-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,9 @@ export default class CartoTileLayer<ExtraProps extends {} = {}> extends MVTLayer
return Promise.reject('Invalid URL');
}

let loadOptions = this.getLoadOptions();
const {fetch, formatTiles} = this.props;
const loadOptions = this.getLoadOptions();
const {fetch} = this.props;
const {signal} = tile;

// The backend doesn't yet support our custom mime-type, so force it here
// TODO remove once backend sends the correct mime-type
if (formatTiles === TILE_FORMATS.BINARY) {
loadOptions = {
...loadOptions,
mimeType: 'application/vnd.carto-vector-tile'
};
}

return fetch(url, {propName: 'data', layer: this, loadOptions, signal});
}

Expand Down
3 changes: 1 addition & 2 deletions modules/carto/src/layers/h3-tile-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ export default class H3TileLayer<DataT = any, ExtraPropsT extends {} = {}> exten
maxZoom: maxresolution,
loadOptions: {
...this.getLoadOptions(),
cartoSpatialTile: {scheme: 'h3'},
mimeType: 'application/vnd.carto-spatial-tile'
cartoSpatialTile: {scheme: 'h3'}
}
})
];
Expand Down
3 changes: 1 addition & 2 deletions modules/carto/src/layers/quadbin-tile-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export default class QuadbinTileLayer<
maxZoom,
loadOptions: {
...this.getLoadOptions(),
cartoSpatialTile: {scheme: 'quadbin'},
mimeType: 'application/vnd.carto-spatial-tile'
cartoSpatialTile: {scheme: 'quadbin'}
}
})
];
Expand Down
3 changes: 3 additions & 0 deletions test/modules/carto/mock-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ function mockFetchMapsV2() {
export function mockFetchMapsV3() {
const fetch = globalThis.fetch;
globalThis.fetch = (url, {headers}) => {
if (url.indexOf('formatTiles=binary') !== -1) {
headers = {...headers, 'Content-Type': 'application/vnd.carto-vector-tile'};
}
return Promise.resolve({
json: () => {
if (url.indexOf('format=tilejson') !== -1) {
Expand Down

0 comments on commit 768bab2

Please sign in to comment.