Skip to content

Commit

Permalink
added new methods to add OSMBuildingLayer, reorganized libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Candan Eylul Kilsedar committed Jul 14, 2017
1 parent 53d157c commit 4e91b57
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 45 deletions.
7 changes: 5 additions & 2 deletions example/index.js
Expand Up @@ -41,7 +41,10 @@ define(['libraries/WebWorldWind/src/WorldWind', 'src/OSMBuildingLayer'],
/* osmMilan.add();
osmMilan.zoom(); */
// var osmNewYork = new OSMBuildingLayer(worldWindow, [40.6998, -74.0232, 40.74, -73.97], configuration);
var osmNewYork = new OSMBuildingLayer(worldWindow, [40.70, -74.03, 40.72, -74.0], configuration);
osmNewYork.add();
var osmNewYork = new OSMBuildingLayer(worldWindow, configuration);
osmNewYork.addByBoundingBox([40.70, -74.03, 40.72, -74.0]);
osmNewYork.zoom();
/* var osmMilan = new OSMBuildingLayer(worldWindow, [45.18, 9.48, 45.19, 9.53], configuration);
osmMilan.add();
osmMilan.zoom(); */
});
5 changes: 2 additions & 3 deletions src/GeoJSONParserTriangulation.js
@@ -1,13 +1,12 @@
/**
* @exports GeoJSONParserTriangulation
*/
define(['libraries/WebWorldWind/src/WorldWind',
'libraries/WebWorldWind/src/formats/geojson/GeoJSONParser',
define(['libraries/WebWorldWind/src/formats/geojson/GeoJSONParser',
'libraries/WebWorldWind/src/geom/Position',
'libraries/WebWorldWind/src/shapes/TriangleMesh',
'src/shapes/BuildingShape',
'earcut'],
function (WorldWind, GeoJSONParser, Position, TriangleMesh, BuildingShape, earcut) {
function (GeoJSONParser, Position, TriangleMesh, BuildingShape, earcut) {
"use strict";

/**
Expand Down
10 changes: 3 additions & 7 deletions src/GeoJSONParserTriangulationOSM.js
@@ -1,13 +1,9 @@
/**
* @exports GeoJSONParserTriangulationOSM
*/
define(['libraries/WebWorldWind/src/WorldWind',
'libraries/WebWorldWind/src/geom/Position',
'libraries/WebWorldWind/src/shapes/TriangleMesh',
'src/GeoJSONParserTriangulation',
'src/shapes/BuildingShape',
'earcut'],
function (WorldWind, Position, TriangleMesh, GeoJSONParserTriangulation, BuildingShape, earcut) {
define(['src/GeoJSONParserTriangulation',
'src/shapes/BuildingShape'],
function (GeoJSONParserTriangulation, BuildingShape) {
"use strict";

/**
Expand Down
36 changes: 26 additions & 10 deletions src/OSMBuildingLayer.js
@@ -1,13 +1,12 @@
/**
* @exports OSMBuildingLayer
*/
define(['libraries/WebWorldWind/src/WorldWind',
'libraries/WebWorldWind/src/cache/MemoryCache',
define(['libraries/WebWorldWind/src/cache/MemoryCache',
'src/OSMLayer',
'src/GeoJSONParserTriangulationOSM',
'jquery',
'osmtogeojson'],
function (WorldWind, MemoryCache, OSMLayer, GeoJSONParserTriangulationOSM, $, osmtogeojson) {
function (MemoryCache, OSMLayer, GeoJSONParserTriangulationOSM, $, osmtogeojson) {
"use strict";

/**
Expand All @@ -16,11 +15,10 @@ define(['libraries/WebWorldWind/src/WorldWind',
* @constructor
* @classdesc Fetches OSM buildings, converts them to GeoJSON, and adds them to the WorldWindow.
* @param {WorldWindow} worldWindow The WorldWindow where the OSMBuildingLayer is added to.
* @param {Float[]} boundingBox It defines the bounding box of the OSM data for the OSMLayer. The order of coordinates of the bounding box is "x1, y1, x2, y2".
* @param {Object} configuration Configuration is used to set the attributes of {@link ShapeAttributes}. Four more attributes can be defined, which are "extrude", "heatmap", "altitude" and "altitudeMode".
*/
var OSMBuildingLayer = function (worldWindow, boundingBox, configuration) {
OSMLayer.call(this, worldWindow, boundingBox, configuration);
var OSMBuildingLayer = function (worldWindow, configuration) {
OSMLayer.call(this, worldWindow, configuration);
this.type = "way";
this.tag = "building";
this._geometryCache = new MemoryCache(30000, 24000);
Expand Down Expand Up @@ -95,13 +93,17 @@ define(['libraries/WebWorldWind/src/WorldWind',
};

/**
* Using the boundingBox of the OSMBuildingLayer, fetches the OSM building data using Overpass API, converts it to GeoJSON using osmtogeojson API,
* adds the GeoJSON data to the WorldWindow using the {@link GeoJSONParserTriangulationOSM}.
* Using the boundingBox fetches the OSM building data using Overpass API, converts it to GeoJSON using osmtogeojson API,
* adds the GeoJSON to the WorldWindow using the {@link GeoJSONParserTriangulationOSM}.
* It also sets the boundingBox of the {@link OSMLayer}.
* @param {Float[]} boundingBox It defines the bounding box of the OSM data to add.
*/
OSMBuildingLayer.prototype.add = function () {
OSMBuildingLayer.prototype.addByBoundingBox = function (boundingBox) {

var boundingBox = this.boundingBox;
this.boundingBox = boundingBox;
var worldWindow = this.worldWindow;
/* var dc = this.worldWindow.drawContext;
console.log("dc.globe --> " + dc.globe); */
var _self = this;

var data = '[out:json][timeout:25];';
Expand Down Expand Up @@ -138,5 +140,19 @@ define(['libraries/WebWorldWind/src/WorldWind',
});
};

/**
*
*/
OSMBuildingLayer.prototype.addByFile = function (path) {

};

/**
*
*/
OSMBuildingLayer.prototype.addByURL = function (path) {

};

return OSMBuildingLayer;
});
57 changes: 34 additions & 23 deletions src/OSMLayer.js
@@ -1,7 +1,9 @@
/**
* @exports OSMLayer
*/
define(['libraries/WebWorldWind/src/WorldWind'], function (WorldWind) {
define(['libraries/WebWorldWind/src/error/ArgumentError',
'libraries/WebWorldWind/src/util/Logger'],
function (ArgumentError, Logger) {
"use strict";

/**
Expand All @@ -10,13 +12,12 @@ define(['libraries/WebWorldWind/src/WorldWind'], function (WorldWind) {
* @constructor
* @classdesc Sets the properties and functions viable for any OSM data. It is intended to be an abstract class, only to be extended for specific OSM data.
* @param {WorldWindow} worldWindow The WorldWindow where the OSMLayer is added to.
* @param {Float[]} boundingBox It defines the bounding box of the OSM data for the OSMLayer.
* @param {Object} configuration Configuration is used to set the attributes of {@link PlacemarkAttributes} or {@link ShapeAttributes}.
*/
var OSMLayer = function (worldWindow, boundingBox, configuration) {
var OSMLayer = function (worldWindow, configuration) {
this._worldWindow = worldWindow;
this._boundingBox = boundingBox;
this._configuration = configuration;
this._boundingBox = null;
this._type = null;
this._tag = null;
};
Expand All @@ -33,17 +34,6 @@ define(['libraries/WebWorldWind/src/WorldWind'], function (WorldWind) {
return this._worldWindow;
}
},
/**
* It defines the bounding box of the OSM data for the OSMLayer. The order of coordinates of the bounding box is "x1, y1, x2, y2".
* @memberof OSMLayer.prototype
* @type {Float[]}
* @readonly
*/
boundingBox: {
get: function() {
return this._boundingBox;
}
},
/**
* Configuration is used to set the attributes of {@link PlacemarkAttributes} if the geometry is Point or MultiPoint; or of {@link ShapeAttributes} otherwise.
* @memberof OSMLayer.prototype
Expand All @@ -57,6 +47,19 @@ define(['libraries/WebWorldWind/src/WorldWind'], function (WorldWind) {
this._configuration = configuration;
}
},
/**
* It defines the bounding box of the OSM data for the OSMLayer. The order of coordinates of the bounding box is "x1, y1, x2, y2".
* @memberof OSMLayer.prototype
* @type {Float[]}
*/
boundingBox: {
get: function() {
return this._boundingBox;
},
set: function(boundingBox) {
this._boundingBox = boundingBox;
}
},
/**
* The type of the OSM data. It can be "node", "way", or "relation".
* @memberof OSMLayer.prototype
Expand Down Expand Up @@ -113,16 +116,24 @@ define(['libraries/WebWorldWind/src/WorldWind'], function (WorldWind) {
/**
* Zooms to the OSMLayer, by setting the center of the viewport to the center of the bounding box.
* It uses an arbitrary value for the range of {@link LookAtNavigator}.
* @throws {ArgumentError} If boundingBox of the layer is null.
*/
OSMLayer.prototype.zoom = function () {
var boundingBox = this.boundingBox;
var centerX = (boundingBox[0] + boundingBox[2])/2;
var centerY = (boundingBox[1] + boundingBox[3])/2;
this.worldWindow.navigator.lookAtLocation.latitude = centerX;
this.worldWindow.navigator.lookAtLocation.longitude = centerY;
// console.log(centerX + ", " + centerY);
this.worldWindow.navigator.range = 1e4; // Should be automatically calculated.
this.worldWindow.redraw();
if (this.boundingBox != null) {
var boundingBox = this.boundingBox;
var centerX = (boundingBox[0] + boundingBox[2])/2;
var centerY = (boundingBox[1] + boundingBox[3])/2;
this.worldWindow.navigator.lookAtLocation.latitude = centerX;
this.worldWindow.navigator.lookAtLocation.longitude = centerY;
// console.log(centerX + ", " + centerY);
this.worldWindow.navigator.range = 1e4; // Should be automatically calculated.
this.worldWindow.redraw();
}
else {
throw new ArgumentError(
Logger.logMessage(Logger.LEVEL_SEVERE, "OSMLayer", "zoom", "The bounding box of the layer is null.")
);
}
};

return OSMLayer;
Expand Down

0 comments on commit 4e91b57

Please sign in to comment.