├── LICENSE
├── README.md
└── examples
└── make_cereal.js
/LICENSE:
--------------------------------------------------------------------------------
1 | CC0 1.0 Universal
2 |
3 | Statement of Purpose
4 |
5 | The laws of most jurisdictions throughout the world automatically confer
6 | exclusive Copyright and Related Rights (defined below) upon the creator and
7 | subsequent owner(s) (each and all, an "owner") of an original work of
8 | authorship and/or a database (each, a "Work").
9 |
10 | Certain owners wish to permanently relinquish those rights to a Work for the
11 | purpose of contributing to a commons of creative, cultural and scientific
12 | works ("Commons") that the public can reliably and without fear of later
13 | claims of infringement build upon, modify, incorporate in other works, reuse
14 | and redistribute as freely as possible in any form whatsoever and for any
15 | purposes, including without limitation commercial purposes. These owners may
16 | contribute to the Commons to promote the ideal of a free culture and the
17 | further production of creative, cultural and scientific works, or to gain
18 | reputation or greater distribution for their Work in part through the use and
19 | efforts of others.
20 |
21 | For these and/or other purposes and motivations, and without any expectation
22 | of additional consideration or compensation, the person associating CC0 with a
23 | Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
24 | and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
25 | and publicly distribute the Work under its terms, with knowledge of his or her
26 | Copyright and Related Rights in the Work and the meaning and intended legal
27 | effect of CC0 on those rights.
28 |
29 | 1. Copyright and Related Rights. A Work made available under CC0 may be
30 | protected by copyright and related or neighboring rights ("Copyright and
31 | Related Rights"). Copyright and Related Rights include, but are not limited
32 | to, the following:
33 |
34 | i. the right to reproduce, adapt, distribute, perform, display, communicate,
35 | and translate a Work;
36 |
37 | ii. moral rights retained by the original author(s) and/or performer(s);
38 |
39 | iii. publicity and privacy rights pertaining to a person's image or likeness
40 | depicted in a Work;
41 |
42 | iv. rights protecting against unfair competition in regards to a Work,
43 | subject to the limitations in paragraph 4(a), below;
44 |
45 | v. rights protecting the extraction, dissemination, use and reuse of data in
46 | a Work;
47 |
48 | vi. database rights (such as those arising under Directive 96/9/EC of the
49 | European Parliament and of the Council of 11 March 1996 on the legal
50 | protection of databases, and under any national implementation thereof,
51 | including any amended or successor version of such directive); and
52 |
53 | vii. other similar, equivalent or corresponding rights throughout the world
54 | based on applicable law or treaty, and any national implementations thereof.
55 |
56 | 2. Waiver. To the greatest extent permitted by, but not in contravention of,
57 | applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
58 | unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
59 | and Related Rights and associated claims and causes of action, whether now
60 | known or unknown (including existing as well as future claims and causes of
61 | action), in the Work (i) in all territories worldwide, (ii) for the maximum
62 | duration provided by applicable law or treaty (including future time
63 | extensions), (iii) in any current or future medium and for any number of
64 | copies, and (iv) for any purpose whatsoever, including without limitation
65 | commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
66 | the Waiver for the benefit of each member of the public at large and to the
67 | detriment of Affirmer's heirs and successors, fully intending that such Waiver
68 | shall not be subject to revocation, rescission, cancellation, termination, or
69 | any other legal or equitable action to disrupt the quiet enjoyment of the Work
70 | by the public as contemplated by Affirmer's express Statement of Purpose.
71 |
72 | 3. Public License Fallback. Should any part of the Waiver for any reason be
73 | judged legally invalid or ineffective under applicable law, then the Waiver
74 | shall be preserved to the maximum extent permitted taking into account
75 | Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
76 | is so judged Affirmer hereby grants to each affected person a royalty-free,
77 | non transferable, non sublicensable, non exclusive, irrevocable and
78 | unconditional license to exercise Affirmer's Copyright and Related Rights in
79 | the Work (i) in all territories worldwide, (ii) for the maximum duration
80 | provided by applicable law or treaty (including future time extensions), (iii)
81 | in any current or future medium and for any number of copies, and (iv) for any
82 | purpose whatsoever, including without limitation commercial, advertising or
83 | promotional purposes (the "License"). The License shall be deemed effective as
84 | of the date CC0 was applied by Affirmer to the Work. Should any part of the
85 | License for any reason be judged legally invalid or ineffective under
86 | applicable law, such partial invalidity or ineffectiveness shall not
87 | invalidate the remainder of the License, and in such case Affirmer hereby
88 | affirms that he or she will not (i) exercise any of his or her remaining
89 | Copyright and Related Rights in the Work or (ii) assert any associated claims
90 | and causes of action with respect to the Work, in either case contrary to
91 | Affirmer's express Statement of Purpose.
92 |
93 | 4. Limitations and Disclaimers.
94 |
95 | a. No trademark or patent rights held by Affirmer are waived, abandoned,
96 | surrendered, licensed or otherwise affected by this document.
97 |
98 | b. Affirmer offers the Work as-is and makes no representations or warranties
99 | of any kind concerning the Work, express, implied, statutory or otherwise,
100 | including without limitation warranties of title, merchantability, fitness
101 | for a particular purpose, non infringement, or the absence of latent or
102 | other defects, accuracy, or the present or absence of errors, whether or not
103 | discoverable, all to the greatest extent permissible under applicable law.
104 |
105 | c. Affirmer disclaims responsibility for clearing rights of other persons
106 | that may apply to the Work or any use thereof, including without limitation
107 | any person's Copyright and Related Rights in the Work. Further, Affirmer
108 | disclaims responsibility for obtaining any necessary consents, permissions
109 | or other rights required for any use of the Work.
110 |
111 | d. Affirmer understands and acknowledges that Creative Commons is not a
112 | party to this document and has no duty or obligation with respect to this
113 | CC0 or use of the Work.
114 |
115 | For more information, please see
116 |
117 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # serialtiles-spec
2 |
3 | **serialtiles** is a specification for _streaming tile uploads_. This format
4 | makes it possible to transfer large tilesets from [MBTiles](https://github.com/mapbox/mbtiles-spec)
5 | or other sources in a streaming manner: this allows both the sender
6 | and receiver to process the upload without holding the entire thing in memory
7 | or waiting for completion.
8 |
9 | Unlike MBTiles, serialtiles is a text format, not a binary format: it is a
10 | transmission of [line-delimited JSON](https://en.wikipedia.org/wiki/JSON_Streaming#Line_delimited_JSON).
11 | Binary contents of tiles, like raster images and protocol buffer-encoded
12 | vectors, are [base64](https://en.wikipedia.org/wiki/Base64) encoded in
13 | order to be safe for this transport.
14 |
15 | ## Requirements Language
16 |
17 | The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
18 | "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this
19 | document are to be interpreted as described in [RFC2119].
20 |
21 | ## Definitions
22 |
23 | JavaScript Object Notation (JSON), and the terms object, name, value, array,
24 | number, true, false, and null are to be interpreted as defined in [RFC7159].
25 |
26 | ## Specification
27 |
28 | serialtiles is a stream and thus is documented in order that it appears. Any
29 | other order is invalid. serialtiles is a subset of [line-delimited JSON](https://en.wikipedia.org/wiki/JSON_Streaming#Line_delimited_JSON):
30 | each item is separated by a linebreak.
31 |
32 | ### Header
33 |
34 | The stream MUST begin with the literal text
35 |
36 | JSONBREAKFASTTIME
37 |
38 | This header declares that the stream contains serialtiles data.
39 |
40 | ### TileJSON
41 |
42 | The second item in the stream MUST be a valid [TileJSON](https://github.com/mapbox/tilejson-spec)
43 | object, stringified and wrapped in a JSON object under the member `tilejson`.
44 |
45 | ```json
46 | {"tilejson":"STRINGIFIED TILEJSON CONTENT"}
47 | ```
48 |
49 | ### Tiles
50 |
51 | Each tile is a JSON object that contains `z`, `x`, `y`, and `buffer` members.
52 | The `z` `x` and `y` members represent a Z/X/Y tile in the [slippy map tilenames](http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames)
53 | scheme, in the Web Mercator map projection.
54 |
55 | The `buffer` member contains tile data. The encoding of map data is as such:
56 |
57 | * Raster data, including PNG, JPEG, GIF, WebP is **base64 encoded**
58 | * Protocol buffer data, including [Mapbox Vector Tiles](https://www.mapbox.com/developers/vector-tiles/),
59 | is **gzip compressed** and then **base64 encoded**.
60 |
61 | ```json
62 | {"z":10,"x":1,"y":2,"buffer":""}
63 | ```
64 |
65 | ## Examples
66 |
67 | #### Vector Tiles (vector tile data)
68 |
69 | Serialtiles is often used to transfer [Mapbox Vector Tiles](https://www.mapbox.com/developers/vector-tiles/),
70 | which are [protocol buffer](https://github.com/google/protobuf)-encoded. These
71 | tiles are additionally required to be gzipped & base64-encoded for transmission
72 | through serialtiles because serialtiles is not a binary format.
73 |
74 | ```json
75 | JSONBREAKFASTTIME
76 | {"tilejson":"info object"}
77 | {"z":0,"x":0,"y":0,"buffer":"base64-encoded, gzipped tile data"}
78 | {"z":1,"x":0,"y":0,"buffer":"base64-encoded, gzipped tile data"}
79 | {"z":1,"x":1,"y":0,"buffer":"base64-encoded, gzipped tile data"}
80 | {"z":1,"x":0,"y":1,"buffer":"base64-encoded, gzipped tile data"}
81 | {"z":1,"x":1,"y":1,"buffer":"base64-encoded, gzipped tile data"}
82 | ```
83 |
84 | #### Raster Images (png, webp, gif, jpg)
85 |
86 | Unlike vector tiles, raster images are _not gzipped_: they are only
87 | base64 encoded.
88 |
89 | ```json
90 | JSONBREAKFASTTIME
91 | {"tilejson":"info object"}
92 | {"z":0,"x":0,"y":0,"buffer":"base64-encoded data"}
93 | {"z":1,"x":0,"y":0,"buffer":"base64-encoded data"}
94 | {"z":1,"x":1,"y":0,"buffer":"base64-encoded data"}
95 | {"z":1,"x":0,"y":1,"buffer":"base64-encoded data"}
96 | {"z":1,"x":1,"y":1,"buffer":"base64-encoded data"}
97 | ```
98 |
99 | ## Examples
100 |
101 | * [make_cereal](examples/make_cereal.js): example of generating serialtiles
102 | from node.js
103 |
104 | ## Implementations
105 |
106 | An unofficial list of implementations is
107 | maintained [in the wiki of the serialtiles-spec GitHub project](https://github.com/mapbox/serialtiles-spec/wiki/Implementations)
108 |
--------------------------------------------------------------------------------
/examples/make_cereal.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | /**
4 | * Usage:
5 | * Run `node make_cereal.js `
6 | */
7 |
8 | var zlib = require('zlib');
9 | var fs = require('fs');
10 | var inputFilePath = process.argv[2];
11 |
12 | fs.readFile(inputFilePath, function(err, dataBuffer) {
13 | if (err) throw err;
14 |
15 | var tilejson = {tilejson:'style info object'};
16 | var outputFilePath = inputFilePath + '.gz';
17 | var dataType = 'png';
18 | var z = 1;
19 | var x = 0;
20 | var y = 0;
21 |
22 | makeBreakfast(z, x, y, JSON.stringify(tilejson), dataType, dataBuffer, outputFilePath, function(err) {
23 | if (err) throw err;
24 | else console.log("Success!");
25 | });
26 | });
27 |
28 |
29 | function makeBreakfast(z, x, y, tilejson, dataType, data, outputFilePath, callback) {
30 | var validTypes = ['png', 'jpg', 'webp', 'gif', 'pbf'];
31 | if (validTypes.indexOf(dataType) === -1)
32 | return callback(new Error('You have to provide the right kind of data'));
33 |
34 | if (!Buffer.isBuffer(data))
35 | return callback(new Error('You have to provide your data as a binary buffer'));
36 |
37 | var oneTile = {
38 | z: z,
39 | x: x,
40 | y: y,
41 | buffer: ''
42 | };
43 |
44 | if (dataType === 'pbf') return zlib.gzip(data, encode);
45 | else encode(null, data);
46 |
47 | function encode(err, data) {
48 | oneTile.buffer = data.toString('base64');
49 |
50 | var outputFile = fs.createWriteStream(outputFilePath);
51 | var gzipStream = zlib.createGzip();
52 | gzipStream.pipe(outputFile);
53 |
54 | outputFile.on('finish', function() {
55 | callback(null, outputFilePath);
56 | });
57 |
58 | gzipStream.write('JSONBREAKFASTTIME\n');
59 | gzipStream.write(JSON.stringify(tilejson) + '\n');
60 | gzipStream.write(JSON.stringify(oneTile) + '\n');
61 | gzipStream.end();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------