-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Maps] Add back removed logic copying feature properties for injected data #49400
Changes from 4 commits
07b71bc
58bbc7d
9dd6c2f
1c5089e
3789603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,9 +35,26 @@ export class GeojsonFileSource extends AbstractVectorSource { | |
applyGlobalQuery: DEFAULT_APPLY_GLOBAL_QUERY | ||
} | ||
|
||
static createDescriptor(name) { | ||
static createDescriptor(geoJson, name) { | ||
// Wrap feature as feature collection if needed | ||
let featureCollection; | ||
if (geoJson.type === 'FeatureCollection') { | ||
featureCollection = geoJson; | ||
} else if (geoJson.type === 'Feature') { | ||
featureCollection = { | ||
type: 'FeatureCollection', | ||
features: [geoJson] | ||
}; | ||
} else { // Missing or incorrect type | ||
featureCollection = { | ||
type: 'FeatureCollection', | ||
features: [] | ||
}; | ||
} | ||
|
||
return { | ||
type: GeojsonFileSource.type, | ||
__featureCollection: featureCollection, | ||
name | ||
}; | ||
} | ||
|
@@ -85,16 +102,9 @@ export class GeojsonFileSource extends AbstractVectorSource { | |
onPreviewSource(null); | ||
return; | ||
} | ||
const sourceDescriptor = GeojsonFileSource.createDescriptor(name); | ||
const sourceDescriptor = GeojsonFileSource.createDescriptor(geojsonFile, name); | ||
const source = new GeojsonFileSource(sourceDescriptor, inspectorAdapters); | ||
const featureCollection = (geojsonFile.type === 'Feature') | ||
? { | ||
type: 'FeatureCollection', | ||
features: [{ ...geojsonFile }] | ||
} | ||
: geojsonFile; | ||
|
||
onPreviewSource(source, { __injectedData: featureCollection }); | ||
onPreviewSource(source); | ||
}; | ||
}; | ||
|
||
|
@@ -125,6 +135,22 @@ export class GeojsonFileSource extends AbstractVectorSource { | |
); | ||
} | ||
|
||
async getGeoJsonWithMeta() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add a safety check here to check on the existence of You could also enforce that there's always an empty featureCollection for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I like that. Done! |
||
const copiedPropsFeatures = this._descriptor.__featureCollection.features | ||
.map(feature => ({ | ||
type: 'Feature', | ||
geometry: feature.geometry, | ||
properties: feature.properties ? { ...feature.properties } : {} | ||
})); | ||
return { | ||
data: { | ||
type: 'FeatureCollection', | ||
features: copiedPropsFeatures | ||
}, | ||
meta: {} | ||
}; | ||
} | ||
|
||
async getDisplayName() { | ||
return this._descriptor.name; | ||
} | ||
|
@@ -136,8 +162,4 @@ export class GeojsonFileSource extends AbstractVectorSource { | |
shouldBeIndexed() { | ||
return GeojsonFileSource.isIndexingSource; | ||
} | ||
|
||
isInjectedData() { | ||
return true; | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check that geoJson is not null here and
else if
statement