|
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Tiled Map Test</title>
- </head>
- <body>
- <script src="node_modules/protobufjs/dist/protobuf.min.js"></script>
- <script>
- var MapProtoRoot = null;
-
- var root = new protobuf.Root();
- root.resolvePath = function(origin, target) {
- console.log("origin: ", origin, 'target: ', target)
- if (origin === "") {
- return target
- } else {
- return "proto/" + target
- }
- };
-
- root.load("proto/map.proto",
- function (err, root) {
- if (root) {
- MapProtoRoot = root.lookup("ns_map_proto.MeshMap");
-
- if (MapProtoRoot) {
- var xhr = new XMLHttpRequest();
- xhr.open(
- /* method */ "GET",
- /* file */ "http://172.22.51.49:8880/test-data/v2.1.0/20596467.proto",
- /* async */ true
- );
- xhr.responseType = "arraybuffer";
- xhr.onload = function(evt) {
- var msg = MapProtoRoot.decode(new Uint8Array(xhr.response));
- console.log(JSON.stringify(msg, null, 4)); // Correctly decoded
- }
- xhr.send(null)
- }
- }
- });
- </script>
- </body>
- </html>
|