Skip to content

Commit 83b3dc7

Browse files
authored
Merge pull request #119 from dfpc-coe/serverParts
Basemap ServerParts
2 parents a1d15f1 + 6dbdfed commit 83b3dc7

4 files changed

Lines changed: 44 additions & 12 deletions

File tree

lib/types/basemap.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
import { Type } from '@sinclair/typebox';
22

3+
/**
4+
* Type Schema for Basemap Map Source Configuration
5+
* Compatible with Mobile Atlas Creator (MOBAC) Custom XML Map Sources
6+
* @link https://mobac.sourceforge.io/wiki/index.php/Custom_XML_Map_Sources
7+
*/
8+
39
export const BasemapMapSource = Type.Object({
410
name: Type.Object({
511
_text: Type.String()
6-
}),
12+
}, { description: 'The name of the map source' }),
713
minZoom: Type.Object({
814
_text: Type.Integer()
9-
}),
15+
}, { description: 'The minimum zoom level provided by the map source' }),
1016
maxZoom: Type.Object({
1117
_text: Type.Integer()
12-
}),
18+
}, { description: 'The maximum zoom level provided by the map source' }),
1319
tileType: Type.Object({
1420
_text: Type.String()
15-
}),
21+
}, { description: 'The image type provided by the map source' }),
1622
tileUpdate: Type.Optional(Type.Object({
1723
_text: Type.String({
1824
default: 'None'
1925
})
20-
})),
26+
}, { description: 'The server capabilities for conditional downloading of new/updated tiles' })),
2127
url: Type.Optional(Type.Object({
2228
_text: Type.String()
23-
})),
29+
}, { description: 'The URL for the tiles of the map source' })),
30+
invertYCoordinate: Type.Optional(Type.Object({
31+
_text: Type.String()
32+
}, { description: 'Inverts the y coordinate so that it starts south' })),
2433
backgroundColor: Type.Optional(Type.Object({
2534
_text: Type.String()
26-
})),
35+
}, { description: 'The background color of a map' })),
36+
ignoreErrors: Type.Optional(Type.Object({
37+
_text: Type.Boolean()
38+
}, { description: 'Handling of missing tiles' })),
39+
serverParts: Type.Optional(Type.Object({
40+
_text: Type.Optional(Type.String())
41+
}, { description: 'Use multiple servers for the map source' }))
2742
})
2843

2944
export default Type.Object({

lib/xml/basemap.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,20 @@ export class Basemap extends XMLDocument<BasemapType> {
3333
tileType: string | undefined;
3434
tileUpdate: string | undefined;
3535
backgroundColor: string | undefined;
36+
serverParts: string | undefined;
3637
} {
3738
if (!this.raw.customMapSource) throw new Err(400, null, 'Unknown Basemap Type');
3839
if (!this.raw.customMapSource.url) throw new Err(400, null, 'Unknown Basemap Type - Missing URL');
39-
40+
4041
return {
4142
name: this.raw.customMapSource.name ? this.raw.customMapSource.name._text : undefined,
4243
url: this.raw.customMapSource.url._text,
4344
minZoom: this.raw.customMapSource.minZoom ? Number(this.raw.customMapSource.minZoom._text) : undefined,
4445
maxZoom: this.raw.customMapSource.maxZoom ? Number(this.raw.customMapSource.maxZoom._text) : undefined,
4546
tileType: this.raw.customMapSource.tileType ? this.raw.customMapSource.tileType._text : undefined,
4647
tileUpdate: this.raw.customMapSource.tileUpdate ? this.raw.customMapSource.tileUpdate._text : undefined,
47-
backgroundColor: this.raw.customMapSource.backgroundColor ? this.raw.customMapSource.backgroundColor._text : undefined
48+
backgroundColor: this.raw.customMapSource.backgroundColor ? this.raw.customMapSource.backgroundColor._text : undefined,
49+
serverParts: this.raw.customMapSource.serverParts ? this.raw.customMapSource.serverParts._text : undefined,
4850
}
4951
}
5052
}

test/basemaps.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,25 @@ for (const fixturename of await fs.readdir(new URL('./basemaps/', import.meta.ur
99
const fixture = String(await fs.readFile(path.join(path.parse(fileURLToPath(import.meta.url)).dir, 'basemaps/', fixturename)));
1010
const container = await Basemap.parse(fixture);
1111

12-
t.ok(container.raw.customMapSource.name._text.length)
12+
t.ok(container.raw.customMapSource.name._text.length, 'Ensure raw xml name exists')
1313

1414
const json = container.to_json();
15-
t.ok(json.name && json.name.length);
15+
t.ok(json.name && json.name.length, 'Ensure JSON name exists');
16+
t.ok(json.url && json.url.length, 'Ensure JSON url exists');
17+
t.ok(typeof json.minZoom === 'number', 'Ensure JSON minZoom is a number');
18+
t.ok(typeof json.maxZoom === 'number', 'Ensure JSON maxZoom is a number');
19+
t.ok(typeof json.tileType === 'string' && json.tileType.length, 'Ensure JSON tileType is a string');
20+
21+
t.deepEqual(Object.keys(json), [
22+
'name',
23+
'url',
24+
'minZoom',
25+
'maxZoom',
26+
'tileType',
27+
'tileUpdate',
28+
'backgroundColor',
29+
'serverParts'
30+
], 'Ensure JSON keys match expected structure')
1631

1732
t.end();
1833
});

test/basemaps/opentopomap.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
<tileUpdate>IfNoneMatch</tileUpdate>
88
<serverParts>a b c</serverParts>
99
<url>https://{$serverpart}.tile.opentopomap.org/{$z}/{$x}/{$y}.png</url>
10-
</customMapSource>
10+
</customMapSource>

0 commit comments

Comments
 (0)