Commit fe1c497e authored by Clément Igonet's avatar Clément Igonet

osm2x3d with 2D tile.

parent 391141ed
This diff is collapsed.
This diff is collapsed.
var fs = require('fs');
var assert = require('assert');
var geoJsonToX3d = require('./GeoJsonToX3d.js');
var x3dOS = fs.createWriteStream('target/ESB_light.x3d');
//var ref = require('./resources/ESB_light_x3d.json', "utf8");
//var refScene = require('./resources/ESB_light_Scene_x3d.json', "utf8");
var geoJsonBlock = require("./resources/ESB_light_geoJson.json");
onBuilding = function (x3dBuildingData) {
// console.log(JSON.stringify(x3dBuildingData));
process.stdout.write("GeoJsonToX3djson assertion 1...");
assert.equal(JSON.stringify(ref), JSON.stringify(x3dBuildingData), "message");
process.stdout.write("OK\n");
};
x3dOS.on('finish', function () {
process.stdout.write("GeoJsonToX3djson assertion 2...");
var result = require('./target/ESB_light_x3d.json', "utf8");
assert.equal(JSON.stringify(refScene), JSON.stringify(result), "message");
process.stdout.write("OK\n");
});
geoJsonToX3d.convert(geoJsonBlock, x3dOS, onBuilding);
This diff is collapsed.
......@@ -2,7 +2,6 @@ var util = require('util');
var stream = require('stream');
var RGBColor = require('rgbcolor');
var expat = require('node-expat');
function getRGB(osmColor) {
if (osmColor) {
var hexRGB = /^#?([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})$/i.exec(osmColor);
......@@ -58,6 +57,27 @@ function removeBuilding(id) {
}
}
function createGroundBlock(minlat, minlon, maxlat, maxlon, url) {
"use strict";
var bounds = {
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': [[
[+minlon, +minlat], [+maxlon, +minlat],
[+maxlon, +maxlat], [+minlon, +maxlat]]]
},
'properties': {
'type': 'bounds'
}
};
if (url) {
// 'url': 'http://a.tile.openstreetmap.org/' + zoom + '/' + x + '/' + y + '.png',
bounds['properties']['tile'] = url;
}
return bounds;
}
var geoGroundBlock = {
"type": "Feature",
"geometry": {
......@@ -65,7 +85,7 @@ var geoGroundBlock = {
"coordinates": [[[-73.9860386, 40.7487894], [-73.9860386, 40.7487894], [-73.9860386, 40.7487894], [-73.9860386, 40.7487894]]]
},
"properties": {
"type": "ground"
"tile": 'http://a.tile.openstreetmap.org/zoom/x/y.png',
}
};
var geoBldPart = {
......@@ -105,8 +125,7 @@ var geoBld = {
"name": "Empire State Building"
}
};
function convert(onConvert) {
function convert(options, onConvert) {
"use strict";
var xmlStream = new expat.Parser('UTF-8');
xmlStream.on('error', function (error) {
......@@ -121,7 +140,14 @@ function convert(onConvert) {
var way = {};
var relation = {};
xmlStream.on('startElement', function (name, attributes) {
if (name === 'node') {
if (name === 'bounds') {
var bounds = createGroundBlock(
+attributes.minlat, +attributes.minlon,
+attributes.maxlat, +attributes.maxlon,
((options && options.tile) ? options.tile : null));
// console.log(JSON.stringify(bounds));
blocks[blocks.length] = bounds;
} else if (name === 'node') {
var id = attributes.id;
var lat = attributes.lat;
var lon = attributes.lon;
......@@ -151,7 +177,7 @@ function convert(onConvert) {
} else if (attributes.k === 'building:levels') {
way.bldLevels = attributes.v;
} else if (attributes.k === 'building:min_level') {
way.bldMinLevel = attributes.V;
way.bldMinLevel = attributes.v;
} else if (attributes.k === 'height') {
way.osmBldPartHeight = heightToMeter(attributes.v);
} else if (attributes.k === 'min_height') {
......@@ -270,13 +296,14 @@ function convert(onConvert) {
}
onRelation = false;
} else if (name === 'osm') {
if (onConvert !== undefined) {
onConvert(blocks);
}
// if (onConvert !== undefined) {
onConvert(blocks);
// }
// tile ground
}
});
return xmlStream;
}
// Functions which will be available to external callers
exports.convert = convert;
"use strict";
var os = require('os');
var stream = require('stream');
var util = require('util');
// Java Style Sheet Language, implementation 1
// convert X3D JSON format to X3D XML
var content = '';
// read content into buffer
//process.stdin.resume();
//process.stdin.on('data', function(buf) { content += buf.toString(); });
//
function toString(el, indent, writeStream) {
if (writeStream === undefined) {
console.error('writeStream undefined')
return;
}
var child;
var key;
var attrs;
if (typeof el === 'string') {
writeStream.write((indent + el));
return result;
}
if (el.key) {
key = el.key;
}
if (el.attributes && el.attributes.length > 0) {
attrs = " " + el.attributes.join(" ");
}
if (el.children && typeof key !== 'undefined' && typeof attrs !== 'undefined') {
writeStream.write(indent + "<" + key + attrs + ">\n");
} else if (el.children && typeof key !== 'undefined') {
writeStream.write(indent + "<" + key + ">\n");
} else if (typeof key !== 'undefined' && typeof attrs !== 'undefined') {
writeStream.write(indent + "<" + key + attrs + "/>\n");
} else if (typeof key !== 'undefined') {
writeStream.write(indent + "<" + key + "/>\n");
}
for (child in el) {
if (child === "children") {
toString(el[child], indent + " ", writeStream);
} else {
if (isNaN(parseInt(child))) {
} else {
toString(el[child], indent + "", writeStream);
}
}
}
if (el.children && typeof key !== 'undefined') {
writeStream.write(indent + "</" + key + ">\n");
}
}
function ConvertChildren(object, parentkey) {
var key;
var children = [];
for (key in object) {
if (typeof object[key] === 'object') {
var el = ConvertToX3D(object[key], key);
children.push(el);
}
}
return children;
}
function ConvertToX3D(object, parentkey) {
var key;
var localArray = [];
var isArray = false;
var arrayOfStrings = false;
var attributes = [];
var children = [];
for (key in object) {
if (isNaN(parseInt(key))) {
isArray = false;
} else {
isArray = true;
}
if (isArray) {
if (typeof object[key] === 'number') {
localArray.push(object[key]);
} else if (typeof object[key] === 'string') {
localArray.push(object[key]);
arrayOfStrings = true;
} else if (typeof object[key] === 'boolean') {
localArray.push(object[key]);
} else if (typeof object[key] === 'object') {
var el = ConvertToX3D(object[key], key);
children.push(el);
} else {
console.log("Unknown type found in array " + typeof object[key]);
}
} else if (typeof object[key] === 'object') {
if (key.substr(0, 1) === '@') {
var el = ConvertToX3D(object[key], key);
for (var attr in el.attributes) {
attributes.push(el.attributes[attr]);
}
} else if (key.substr(0, 1) === '-') {
children.push(ConvertChildren(object[key], key));
} else {
var el = ConvertToX3D(object[key], key);
el.key = key;
children.push(el);
}
} else if (typeof object[key] === 'number') {
attributes.push(key.substr(1) + "='" + object[key] + "'");
} else if (typeof object[key] === 'string') {
if (key === '#comment') {
children.push('<!--' + object[key] + '-->');
} else {
attributes.push(key.substr(1) + "='" + object[key] + "'");
}
} else if (typeof object[key] === 'boolean') {
attributes.push(key.substr(1) + "='" + object[key] + "'");
} else {
console.log("Unknown type found in object " + typeof object[key]);
}
}
if (isArray) {
if (parentkey.substr(0, 1) === '@') {
if (arrayOfStrings) {
arrayOfStrings = false;
attributes.push(parentkey.substr(1) + "='&quot;" + localArray.join('&quot; &quot;') + "&quot;'");
} else {
attributes.push(parentkey.substr(1) + "='" + localArray.join(" ") + "'");
}
}
isArray = false;
}
return {attributes: attributes, children: children};
}
//
//process.stdin.on('end', function() {
// var json = JSON.parse(content);
//console.log('<?xml version="1.0" encoding="UTF-8"?>');
//console.log('<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.3//EN" "http://www.web3d.org/specifications/x3d-3.3.dtd"><X3D><Scene>');
// var el = ConvertToX3D(json, "", "");
// printElement(el, "");
//console.log('</Scene></X3D>');
//});
function convert(object, writeStream) {
var json = ConvertToX3D(object['X3D']['Scene'], "");
var result = '';
result += '<?xml version="1.0" encoding="UTF-8"?>\n';
result += '<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.2//EN" "http://www.web3d.org/specifications/x3d-3.2.dtd">\n';
result += '<X3D profile="Interchange" version="3.2" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.2.xsd">\n';
result += ' <Scene>\n';
if (writeStream) {
writeStream.write(result);
}
// console.log(JSON.stringify(object))
// console.log(JSON.stringify(json))
//{
// "X3D": {
// "@profile": "Immersive",
// "@version": 3.3,
// "@xsd:noNamespaceSchemaLocation": "http://www.web3d.org/specifications/x3d-3.3.xsd",
// "Scene": {
result += toString(json, " ", writeStream);
var endResult = '';
endResult += (' </Scene>\n');
endResult += ('</X3D>\n');
if (writeStream) {
writeStream.write(endResult);
}
return result + endResult;
}
exports.convert = convert;
{
"name": "osm2x3d",
"description": "osm2x3d ==============",
"version": "0.0.7",
"dependencies": {
"sax": "",
"body-parser": "~1.0.0",
"rgbcolor": "0.0.4"
},
"main": "./osmx3d.js",
"scripts": {
"test": "osm2x3dTester.sh"
},
"author": "Clement IGONET <clement@igonet.fr>",
"keywords": [],
"repository": {
"type": "git",
"url": "git@git.framasoft.org:pizaninja/OpenEarthView.git"
},
"devDependencies": {},
"license": "LGPL-3.0"
"name": "osm2x3d",
"description": "osm2x3d ==============",
"version": "0.0.7",
"dependencies": {
"sax": "",
"body-parser": "~1.0.0",
"rgbcolor": "0.0.4",
"node-xml-compare": ""
},
"main": "./osmx3d.js",
"scripts": {
"test": "osm2x3dTester.sh"
},
"author": "Clement IGONET <clement@igonet.fr>",
"keywords": [],
"repository": {
"type": "git",
"url": "git@git.framasoft.org:pizaninja/OpenEarthView.git"
},
"devDependencies": {},
"license": "LGPL-3.0"
}
This diff is collapsed.
This diff is collapsed.
"use strict";
// 'http://www.web3d.org/specifications/x3d-namespace'
// Load X3D JSON into web page
function ConvertChildren(object, indent, parentkey, element) {
var key;
for (key in object) {
if (typeof object[key] === 'object') {
ConvertToX3DOM(object[key], indent, key, element);
}
}
}
function ConvertToX3DOM(object, indent, parentkey, element) {
var key;
var localArray = [];
var isArray = false;
var arrayOfStrings = false;
for (key in object) {
if (isNaN(parseInt(key))) {
isArray = false;
} else {
isArray = true;
}
if (isArray) {
if (typeof object[key] === 'number') {
localArray.push(object[key]);
} else if (typeof object[key] === 'string') {
localArray.push(object[key]);
arrayOfStrings = true;
} else if (typeof object[key] === 'boolean') {
localArray.push(object[key]);
} else if (typeof object[key] === 'object') {
ConvertToX3DOM(object[key], indent, key, element);
} else {
console.log("Unknown type found in array " + typeof object[key]);
}
} else if (typeof object[key] === 'object') {
if (key.substr(0, 1) === '@') {
ConvertToX3DOM(object[key], indent, key, element);
} else if (key.substr(0, 1) === '-') {
ConvertChildren(object[key], indent, key, element);
} else {
var createKey = key;
var child = document.createElement(createKey);
ConvertToX3DOM(object[key], indent, key, child);
element.appendChild(child);
}
} else if (typeof object[key] === 'number') {
element.setAttribute(key.substr(1), object[key]);
} else if (typeof object[key] === 'string') {
if (key !== '#comment') {
element.setAttribute(key.substr(1), object[key]);
}
} else if (typeof object[key] === 'boolean') {
element.setAttribute(key.substr(1), object[key]);
} else {
console.log("Unknown type found in object " + typeof object[key]);
}
}
if (isArray) {
if (parentkey.substr(0, 1) === '@') {
if (arrayOfStrings) {
arrayOfStrings = false;
if (parentkey === '@url') {
var url;
for (url in localArray) {
/*
if (localArray[url].indexOf("..") === 0) {
localArray[url] = '/'+localArray[url].substring(3);
} else if (localArray[url].indexOf("http://") < 0) {
localArray[url] = '/'+localArray[url];
}
*/
// console.log(localArray[url]);
}
}
element.setAttribute(parentkey.substr(1), '"' + localArray.join('" "') + '"');
} else {
element.setAttribute(parentkey.substr(1), localArray.join(" "));
}
}
isArray = false;
}
return element;
}
function loadX3DJS(selector, json) {
var element = document.querySelector(selector);
if (element === null) {
console.log("selector found nothing in document", selector);
} else {
ConvertToX3DOM(json, "", "", element);
x3dom.reload();
}
}
//function loadX3DJSON(selector, url) {
// $.getJSON(url, function (json) {
// loadX3DJS(selector, json);
// })
// .fail(function (jqXHR, textStatus, errorThrown) {
// alert('getJSON request failed! ' + textStatus + ' ' + errorThrown);
// });
//}
{
"name": "openEarthView",
"authors": [
"Clément Igonet <clement@igonet.fr>"
],
"description": "Open Earth View web site",
"main": "index.html",
"moduleType": [
"node"
],
"keywords": [
"x3d",
"x3dom",
"osm"
],
"license": "MIT",
"homepage": "http://wiki.openstreetmap.org/wiki/Open_Earth_View",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"bower-x3dom": "master"
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
[{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[-73.9862797, 40.7481926], [-73.9852939, 40.7481926], [-73.9852939, 40.7486022], [-73.9862797, 40.7486022]]]
},
"properties": {
"type": "bounds"
}
}, {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
......@@ -10,6 +19,7 @@
"id": "137425131",
"type": "buildingPart",
"minHeight": "20",
"minLevel": "5",
"color": "rgb(245, 245, 220)",
"levels": "20",
"height": "75"
......@@ -37,6 +47,7 @@
"id": "137425128",
"type": "buildingPart",
"minHeight": "90",
"minLevel": "24",
"color": "rgb(245, 245, 220)",
"levels": "29",
"height": "115"
......@@ -64,6 +75,7 @@
"id": "137425127",
"type": "buildingPart",
"minHeight": "115",
"minLevel": "29",
"color": "rgb(245, 245, 220)",
"levels": "71",
"height": "255"
......@@ -91,6 +103,7 @@
"id": "137425129",
"type": "buildingPart",
"minHeight": "255",
"minLevel": "71",
"color": "rgb(245, 245, 220)",
"levels": "80",
"height": "290"
......@@ -226,6 +239,7 @@
"id": "137425133",
"type": "buildingPart",
"minHeight": "75",
"minLevel": "20",
"color": "rgb(245, 245, 220)",
"levels": "24",
"height": "90"
......
This diff is collapsed.
This diff is collapsed.
......@@ -11,11 +11,16 @@
<!-- cf x3dom/test/regression-suite/test/cases/billboard/billboard.html -->
<div id="x3dContainer">
<x3d id="x3dElement" showstat="false" showlog="true" height="400px" width="800px">
<Scene id="scene">
<x3d id="x3dElement" showstat="false" showlog="true" height="800px" width="1000px">
<scene id="scene">
<!--<viewpoint position="-1.94639 1.79771 -2.89271" orientation="0.03886 0.99185 0.12133 3.75685"></viewpoint>-->
<!--<inline nameSpaceName="myX3d" url="result.x3d"></inline>-->
<inline nameSpaceName="myX3d" url="resources/ESB_light.x3d"></inline>
</Scene>
<!--<inline url="resources/ESB_light.x3d"></inline>-->
<!--<inline url="resources/ESB19.x3d"></inline>-->
<!--<inline url="resources/ESB19.x3d"></inline>-->
<!--<inline url="resources/ESB18.x3d"></inline>-->
<inline url="resources/ESB17.x3d"></inline>
</scene>
</x3d>
</div>
</body>
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Open Earth View</title>
<link rel="stylesheet" type="text/css" href="bower_components/bower-x3dom/x3dom.css">
<script type="text/javascript" src="bower_components/bower-x3dom/x3dom-full.js"></script>
</head>
<body id="body">
<div id="headerInfo">Open Earth View</div>
<!-- cf x3dom/test/regression-suite/test/cases/billboard/billboard.html -->
<div id="x3dContainer">
<x3d id="x3dElement" showstat="false" showlog="true" height="800px" width="1000px">
<scene id="scene">
<!--<viewpoint position="-1.94639 1.79771 -2.89271" orientation="0.03886 0.99185 0.12133 3.75685"></viewpoint>-->
<!--<inline nameSpaceName="myX3d" url="result.x3d"></inline>-->
<!--<inline url="resources/ESB_light.x3d"></inline>-->
<!--<inline url="resources/ESB19.x3d"></inline>-->
<!--<inline url="resources/ESB19_old.x3d"></inline>-->
<inline url="resources/ESB17_old.x3d"></inline>
</scene>
</x3d>
</div>
</body>
</html>
var fs = require('fs');
var assert = require('assert');
var geoJsonToX3dJson = require('./GeoJsonToX3dJson.js');
var ref = require('./resources/ESB_light_x3d.json', "utf8");
var geoJsonToX3dJson = require('../../lib/GeoJsonToX3dJson.js');
var ref = require('../resources/ESB_light_x3d.json', "utf8");
var geoJsonBlock = require("./resources/ESB_light_geoJson.json");
var geoJsonBlock = require("../resources/ESB_light_geoJson.json");
onConvert = function (x3dJsonScene) {
process.stdout.write("GeoJsonToX3djson assertion 1...");
// console.log(JSON.stringify(x3dJsonScene));
assert.deepEqual(JSON.stringify(ref), JSON.stringify(x3dJsonScene), "message");
process.stdout.write("OK\n");
};
geoJsonToX3dJson.convert(geoJsonBlock, [-73.9862797, 40.7481926], onConvert);
var options = {
'origin': [-73.9862797, 40.7481926],
'loD': 4
}
geoJsonToX3dJson.convert(geoJsonBlock, options, onConvert);
var fs = require('fs');
var assert = require('assert');
var osmToGeoJson = require('./OsmToGeoJson.js');
var ref = require("./resources/ESB_light_geoJson.json");
var osmToGeoJson = require('../../lib/OsmToGeoJson.js');
var ref = require("../resources/ESB_light_geoJson.json");
onConvert = function (geoJson) {
var onConvert = function (geoJson) {
process.stdout.write("OsmToGeoJson assertion 1...");
// console.log(JSON.stringify(geoJson));
assert.deepEqual(geoJson, ref, "message");
process.stdout.write("OK\n");
}
var osmToGeoOS = osmToGeoJson.convert(onConvert);
var fileIS = fs.createReadStream('./resources/ESB_light.osm');
fileIS.pipe(osmToGeoOS);
var osmToGeoWS = osmToGeoJson.convert(null, onConvert);
var fileRS = fs.createReadStream('../resources/ESB_light.osm');
fileRS.pipe(osmToGeoWS);
var fs = require('fs');
var assert = require('assert');
var X3dJsonToX3d = require('../../lib/X3dJsonToX3d.js');
var xmlcompare = require('node-xml-compare');
var stream = require('stream');
var ref = fs.readFileSync('../resources/ESB_light.x3d', 'utf8');
var x3dJson = require('../resources/ESB_light_x3d.json');
var result = '';
var writable = new stream.Writable({
write: function (chunk, encoding, next) {
result += chunk.toString();
next()
}
});
//var outputStream = fs.createWriteStream('./target/ESB_light.x3d');
process.stdout.write("X3dJsonToX3d assertion 1...");
X3dJsonToX3d.convert(x3dJson, writable);
//console.log(result);
assert.strictEqual(result, ref.toString(), "message");
process.stdout.write("OK\n");
......@@ -2,4 +2,5 @@
node OsmToGeoJsonTester.js
node GeoJsonToX3dJsonTester.js
node X3dJsonToX3dTester.js
var http = require('http');
var url = require('url');
var querystring = require('querystring');
var osmToGeoJson = require('./OsmToGeoJson.js');
var geoJsonToX3dJson = require('./GeoJsonToX3dJson.js');
var osmToGeoJson = require('./lib/OsmToGeoJson.js');
var geoJsonToX3dJson = require('./lib/GeoJsonToX3dJson.js');
var x3dJsonToX3d = require('./lib/X3dJsonToX3d.js')