From 2a1904fbb95614b5f7189cccb95ee305fe9c48e3 Mon Sep 17 00:00:00 2001 From: Candan Eylul Kilsedar Date: Thu, 6 Jul 2017 11:55:09 +0200 Subject: [PATCH] added cache for the OSMBuildingLayer --- src/OSMBuildingLayer.js | 54 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/OSMBuildingLayer.js b/src/OSMBuildingLayer.js index f2b0a5a..99bd3f8 100644 --- a/src/OSMBuildingLayer.js +++ b/src/OSMBuildingLayer.js @@ -1,7 +1,13 @@ /** * @exports OSMBuildingLayer */ -define(['libraries/WebWorldWind/src/WorldWind', 'src/OSMLayer', 'src/GeoJSONParserTriangulation', 'jquery', 'osmtogeojson'], function (WorldWind, OSMLayer, GeoJSONParserTriangulation, $, osmtogeojson) { +define(['libraries/WebWorldWind/src/WorldWind', + 'libraries/WebWorldWind/src/cache/MemoryCache', + 'src/OSMLayer', + 'src/GeoJSONParserTriangulation', + 'jquery', + 'osmtogeojson'], + function (WorldWind, MemoryCache, OSMLayer, GeoJSONParserTriangulation, $, osmtogeojson) { "use strict"; /** @@ -17,10 +23,55 @@ define(['libraries/WebWorldWind/src/WorldWind', 'src/OSMLayer', 'src/GeoJSONPars OSMLayer.call(this, worldWindow, boundingBox, configuration); this.type = "way"; this.tag = "building"; + this._geometryCache = new MemoryCache(30000, 24000); + this._propertiesCache = new MemoryCache(50000, 40000); }; OSMBuildingLayer.prototype = Object.create(OSMLayer.prototype); + Object.defineProperties (OSMBuildingLayer.prototype, { + /** + * The cache for the geometry of each feature of the OSMBuildingLayer. + * @memberof OSMBuildingLayer.prototype + * @type {MemoryCache} + */ + geometryCache: { + get: function() { + return this._geometryCache; + }, + set: function(geometryCache) { + this._geometryCache = geometryCache; + } + }, + /** + * The cache for the properties of each feature of the OSMBuildingLayer. + * @memberof OSMBuildingLayer.prototype + * @type {MemoryCache} + */ + propertiesCache: { + get: function() { + return this._propertiesCache; + }, + set: function(propertiesCache) { + this._propertiesCache = propertiesCache; + } + } + }); + + OSMBuildingLayer.prototype.cache = function(dataOverpassGeoJSON) { + // console.log(JSON.stringify(dataOverpassGeoJSON)); + for (var featureIndex = 0; featureIndex < dataOverpassGeoJSON.features.length; featureIndex++) { + this.geometryCache.putEntry(dataOverpassGeoJSON.features[featureIndex].id, dataOverpassGeoJSON.features[featureIndex].geometry, Object.keys(dataOverpassGeoJSON.features[featureIndex].geometry).length); + this.propertiesCache.putEntry(dataOverpassGeoJSON.features[featureIndex].id, dataOverpassGeoJSON.features[featureIndex].properties, Object.keys(dataOverpassGeoJSON.features[featureIndex].properties).length); + /* console.log(Object.keys(dataOverpassGeoJSON.features[featureIndex].geometry).length); + console.log(dataOverpassGeoJSON.features[featureIndex].geometry); + console.log(Object.keys(dataOverpassGeoJSON.features[featureIndex].properties).length); + console.log(dataOverpassGeoJSON.features[featureIndex].properties); */ + } + /* console.log(this.geometryCache); + console.log(this.propertiesCache); */ + }; + /** * Sets the attributes of {@link ShapeAttributes} and three more attributes defined specifically for OSMBuildingLayer, which are "extrude", "altitude" and "altitudeMode". * @param {GeoJSONGeometry} geometry An object containing the geometry of the OSM data in GeoJSON format for the OSMBuildingLayer. @@ -69,6 +120,7 @@ define(['libraries/WebWorldWind/src/WorldWind', 'src/OSMLayer', 'src/GeoJSONPars // console.log("dataOverpass --> " + JSON.stringify(dataOverpass)); // var dataOverpassGeoJSON = osmtogeojson(dataOverpass, {flatProperties: true, polygonFeatures: {"building": true}}); var dataOverpassGeoJSON = osmtogeojson(dataOverpass); + _self.cache(dataOverpassGeoJSON); var dataOverpassGeoJSONString = JSON.stringify(dataOverpassGeoJSON); // console.log("dataOverpassGeoJSONString --> " + dataOverpassGeoJSONString); // console.log("dataOverpassGeoJSON.features.length (number of polygons) --> " + dataOverpassGeoJSON.features.length);