Skip to content

Commit

Permalink
chore: rename parsedData by features.
Browse files Browse the repository at this point in the history
Because parsedData are instances of Feature or FeatureCollection.

FileSource.parsedData is deprecated replace by FileSource.features.
  • Loading branch information
gchoqueux committed Oct 1, 2020
1 parent 148ef0b commit 4cd963d
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Converter/textureConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {

extentDestination.as(CRS.formatToEPSG(layer.crs), extentTexture);
texture = Feature2Texture.createTextureFromFeature(data, extentTexture, 256, layer.style, backgroundColor);
texture.parsedData = data;
texture.features = data;
texture.extent = extentDestination;
} else if (data.isTexture) {
texture = data;
Expand Down
6 changes: 3 additions & 3 deletions src/Core/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,14 +783,14 @@ class View extends THREE.EventDispatcher {

for (const materialLayer of tile.object.material.getLayers(layers)) {
for (const texture of materialLayer.textures) {
if (!texture.parsedData) {
if (!texture.features) {
continue;
}

precision = CRS.isMetricUnit(texture.parsedData.crs) ? precisions.M : precisions.D;
precision = CRS.isMetricUnit(texture.features.crs) ? precisions.M : precisions.D;

result[materialLayer.id] = result[materialLayer.id].concat(
FeaturesUtils.filterFeaturesUnderCoordinate(coordinates, texture.parsedData, precision));
FeaturesUtils.filterFeaturesUnderCoordinate(coordinates, texture.features, precision));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Layer/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class Layer extends THREE.EventDispatcher {
data = Promise.resolve(this.convert(feature, to));
} else {
data = this.source.loadData(from, this.parsingOptions)
.then(parsedData => this.convert(parsedData, to), (err) => {
.then(feat => this.convert(feat, to), (err) => {
throw err;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/ShapefileParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import GeoJsonParser from 'Parser/GeoJsonParser';
* crsOut: view.tileLayer.extent.crs,
* });
* }).then(function _(geojson) {
* var source = new FileSource({ parsedData: geojson });
* var source = new FileSource({ features: geojson });
* var layer = new ColorLayer('velib', { source });
* view.addLayer(layer);
* });
Expand Down
8 changes: 4 additions & 4 deletions src/Process/LayeredMaterialNodeProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ function refinementCommandCancellationFn(cmd) {
return !cmd.requester.material.visible;
}

function buildCommand(view, layer, extentsSource, extentsDestination, requester, parsedData) {
function buildCommand(view, layer, extentsSource, extentsDestination, requester, features) {
return {
view,
layer,
extentsSource,
extentsDestination,
requester,
parsedData,
features,
priority: materialCommandQueuePriorityFunction(requester.material),
earlyDropFunction: refinementCommandCancellationFn,
};
Expand Down Expand Up @@ -152,8 +152,8 @@ export function updateLayeredMaterialNodeImagery(context, layer, node, parent) {
}

node.layerUpdateState[layer.id].newTry();
const parsedData = nodeLayer.textures.map(t => layer.isValidData(t.parsedData));
const command = buildCommand(context.view, layer, extentsSource, extentsDestination, node, parsedData);
const features = nodeLayer.textures.map(t => layer.isValidData(t.features));
const command = buildCommand(context.view, layer, extentsSource, extentsDestination, node, features);

return context.scheduler.execute(command).then(
(result) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/DataSourceProvider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
executeCommand(command) {
const layer = command.layer;
const features = command.parsedData || [];
const features = command.features || [];
const src = command.extentsSource;
const dst = command.extentsDestination || src;

Expand Down
45 changes: 25 additions & 20 deletions src/Source/FileSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ext = new Extent('EPSG:4326', [0, 0, 0, 0]);
* <li>fetch the file, and give the data to the source using the `fetchedData`
* property.</li>
* <li>fetch the file, parse it and git the parsed data to the source using the
* `parsedData` property.</li>
* `features` property.</li>
* </ul>
* See the examples below for real use cases.
*
Expand All @@ -25,7 +25,7 @@ const ext = new Extent('EPSG:4326', [0, 0, 0, 0]);
* internally for optimisation.
* @property {*} fetchedData - Once the file has been loaded, the resulting data
* is stored in this property.
* @property {*} parsedData - Once the file has been loaded and parsed, the
* @property {*} features - Once the file has been loaded and parsed, the
* resulting data is stored in this property.
*
* @example <caption>Simple: create a source, a layer, and let iTowns taking
Expand Down Expand Up @@ -88,10 +88,10 @@ const ext = new Extent('EPSG:4326', [0, 0, 0, 0]);
* withNormal: false,
* withAltitude: false,
* });
* }).then(function _(parsedData) {
* }).then(function _(features) {
* ariege.source = new itowns.FileSource({
* crs: 'EPSG:4326',
* parsedData,
* features,
* });
*
* return view.addLayer(ariegeLayer);
Expand All @@ -101,43 +101,48 @@ class FileSource extends Source {
/**
* @param {Object} source - An object that can contain all properties of a
* FileSource and {@link Source}. Only `crs` is mandatory, but if it
* presents in `parsedData` under the property `crs`, it is fine.
* presents in `features` under the property `crs`, it is fine.
*
* @constructor
*/
constructor(source) {
/* istanbul ignore next */
if (source.parsedData) {
console.warn('FileSource parsedData parameter is deprecated, use features instead of.');
source.features = source.features || source.parsedData;
}
/* istanbul ignore next */
if (source.projection) {
console.warn('FileSource projection parameter is deprecated, use crs instead.');
source.crs = source.crs || source.projection;
}
if (!source.crs) {
if (source.parsedData && source.parsedData.crs) {
source.crs = source.parsedData.crs;
if (source.features && source.features.crs) {
source.crs = source.features.crs;
} else {
throw new Error('source.crs is required in FileSource');
}
}

if (!source.url && !source.fetchedData && !source.parsedData) {
throw new Error(`url, fetchedData and parsedData are not set in
if (!source.url && !source.fetchedData && !source.features) {
throw new Error(`url, fetchedData and features are not set in
FileSource; at least one needs to be present`);
}

// the fake url is for when we use the fetchedData or parsedData mode
// the fake url is for when we use the fetchedData or features mode
source.url = source.url || 'fake-file-url';
super(source);

this.isFileSource = true;

this.fetchedData = source.fetchedData;
if (!this.fetchedData && !source.parsedData) {
if (!this.fetchedData && !source.features) {
this.whenReady = this.fetcher(this.urlFromExtent(), this.networkOptions).then((f) => {
this.fetchedData = f;
});
} else if (source.parsedData) {
this._parsedDatasCaches[source.parsedData.crs] = new Cache();
this._parsedDatasCaches[source.parsedData.crs].setByArray(Promise.resolve(source.parsedData), [0]);
} else if (source.features) {
this._featuresCaches[source.features.crs] = new Cache();
this._featuresCaches[source.features.crs].setByArray(Promise.resolve(source.features), [0]);
}

this.whenReady.then(() => this.fetchedData);
Expand All @@ -151,13 +156,13 @@ class FileSource extends Source {

onLayerAdded(options) {
super.onLayerAdded(options);
let parsedData = this._parsedDatasCaches[options.crsOut].getByArray([0]);
if (!parsedData) {
let features = this._featuresCaches[options.crsOut].getByArray([0]);
if (!features) {
options.buildExtent = true;
parsedData = this.parser(this.fetchedData, options);
this._parsedDatasCaches[options.crsOut].setByArray(parsedData, [0]);
features = this.parser(this.fetchedData, options);
this._featuresCaches[options.crsOut].setByArray(features, [0]);
}
parsedData.then((data) => {
features.then((data) => {
this.extent = data.extent;
if (data.isFeatureCollection) {
data.setParentStyle(options.style);
Expand All @@ -174,7 +179,7 @@ class FileSource extends Source {
* @return {FeatureCollection|Texture} The parsed data.
*/
loadData(extent, options) {
return this._parsedDatasCaches[options.crsOut].getByArray([0]);
return this._featuresCaches[options.crsOut].getByArray([0]);
}

extentInsideLimit(extent) {
Expand Down
26 changes: 13 additions & 13 deletions src/Source/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Source {
this.crs = source.crs;
this.attribution = source.attribution;
this.whenReady = Promise.resolve();
this._parsedDatasCaches = {};
this._featuresCaches = {};
if (source.extent && !(source.extent.isExtent)) {
this.extent = new Extent(this.crs, source.extent);
} else {
Expand Down Expand Up @@ -165,23 +165,23 @@ class Source {
* @return {FeatureCollection|Texture} The parsed data.
*/
loadData(extent, options) {
const cache = this._parsedDatasCaches[options.crsOut];
const cache = this._featuresCaches[options.crsOut];
// try to get parsed data from cache
let parsedData = cache.getByArray(this.requestToKey(extent));
if (!parsedData) {
let features = cache.getByArray(this.requestToKey(extent));
if (!features) {
// otherwise fetch/parse the data
parsedData = cache.setByArray(fetchSourceData(this, extent).then(fetchedData => this.parser(fetchedData, options),
features = cache.setByArray(fetchSourceData(this, extent).then(fetchedData => this.parser(fetchedData, options),
err => this.handlingError(err)), this.requestToKey(extent));
/* istanbul ignore next */
if (this.onParsedFile) {
parsedData.then((feature) => {
this.onParsedFile(feature);
features.then((feat) => {
this.onParsedFile(feat);
console.warn('Source.onParsedFile was deprecated');
return feature;
return feat;
});
}
}
return parsedData;
return features;
}

/**
Expand All @@ -191,8 +191,8 @@ class Source {
*/
onLayerAdded(options) {
// Added new cache by crs
if (!this._parsedDatasCaches[options.crsOut]) {
this._parsedDatasCaches[options.crsOut] = new Cache();
if (!this._featuresCaches[options.crsOut]) {
this._featuresCaches[options.crsOut] = new Cache();
}
}

Expand All @@ -203,10 +203,10 @@ class Source {
*/
onLayerRemoved(options = {}) {
// delete unused cache
const unusedCache = this._parsedDatasCaches[options.unusedCrs];
const unusedCache = this._featuresCaches[options.unusedCrs];
if (unusedCache) {
unusedCache.clear();
delete this._parsedDatasCaches[options.unusedCrs];
delete this._featuresCaches[options.unusedCrs];
}
}

Expand Down

0 comments on commit 4cd963d

Please sign in to comment.