Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
arjxn-py committed Jan 8, 2025
1 parent c84119d commit 3ff2c78
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const useGetProperties = ({
throw new Error('Source not found');
}

const data = await model.readFile(source.parameters?.path, 'GeoJSONSource');
const data = await model.readFile(
source.parameters?.path,
'GeoJSONSource'
);

if (!data) {
throw new Error('Failed to read GeoJSON data');
Expand Down
5 changes: 4 additions & 1 deletion packages/base/src/formbuilder/objectform/geojsonsource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ export class GeoJSONSourcePropertiesForm extends BaseForm {
let valid = false;
if (path) {
try {
const geoJSONData = await this.props.model.readFile(path, 'GeoJSONSource');
const geoJSONData = await this.props.model.readFile(
path,
'GeoJSONSource'
);
valid = this._validate(geoJSONData);
if (!valid) {
error = `"${path}" is not a valid GeoJSON file`;
Expand Down
26 changes: 20 additions & 6 deletions packages/base/src/mainview/mainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,10 @@ export class MainView extends React.Component<IProps, IStates> {
case 'GeoJSONSource': {
const data =
source.parameters?.data ||
(await this._model.readFile(source.parameters?.path, 'GeoJSONSource'));
(await this._model.readFile(
source.parameters?.path,
'GeoJSONSource'
));

const format = new GeoJSON({
featureProjection: this._Map.getView().getProjection()
Expand All @@ -449,11 +452,17 @@ export class MainView extends React.Component<IProps, IStates> {
const parameters = source.parameters as IShapefileSource;

let geojson: any;
if (parameters?.path?.startsWith('http://') || parameters?.path?.startsWith('https://')) {
if (
parameters?.path?.startsWith('http://') ||
parameters?.path?.startsWith('https://')
) {
geojson = await this._loadShapefileAsGeoJSON(parameters.path);
} else {
// Handle local files using the model's readFile method
geojson = await this._model.readFile(parameters.path, 'ShapefileSource');
geojson = await this._model.readFile(
parameters.path,
'ShapefileSource'
);
}

const geojsonData = Array.isArray(geojson) ? geojson[0] : geojson;
Expand Down Expand Up @@ -500,10 +509,16 @@ export class MainView extends React.Component<IProps, IStates> {

let imageUrl: string;

if (sourceParameters.url.startsWith('http://') || sourceParameters.url.startsWith('https://')) {
if (
sourceParameters.url.startsWith('http://') ||
sourceParameters.url.startsWith('https://')
) {
imageUrl = sourceParameters.url;
} else {
imageUrl = await this._model.readFile(sourceParameters.url, 'ImageSource');
imageUrl = await this._model.readFile(
sourceParameters.url,
'ImageSource'
);
}

newSource = new Static({
Expand Down Expand Up @@ -546,7 +561,6 @@ export class MainView extends React.Component<IProps, IStates> {
newSource.set('id', id);
console.log('Adding source', id, newSource);


// _sources is a list of OpenLayers sources
this._sources[id] = newSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ const FilterComponent = (props: IFilterComponentProps) => {
break;
}
case 'GeoJSONSource': {
const data = await model?.readFile(source.parameters?.path, 'GeoJSONSource');
const data = await model?.readFile(
source.parameters?.path,
'GeoJSONSource'
);
data?.features.forEach((feature: GeoJSONFeature1) => {
feature.properties &&
addFeatureValue(feature.properties, aggregatedProperties);
Expand Down
19 changes: 14 additions & 5 deletions packages/schema/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,10 @@ export class JupyterGISModel implements IJupyterGISModel {
throw new Error('ContentsManager is not initialized.');
}

const absolutePath = PathExt.resolve(PathExt.dirname(this._filePath), filepath);
const absolutePath = PathExt.resolve(
PathExt.dirname(this._filePath),
filepath
);

try {
const file = await this._contentsManager.get(absolutePath, {
Expand All @@ -340,12 +343,14 @@ export class JupyterGISModel implements IJupyterGISModel {
}

case 'ShapefileSource': {
const arrayBuffer = await this._stringToArrayBuffer(file.content as string);
const arrayBuffer = await this._stringToArrayBuffer(
file.content as string
);
const geojson = await shp(arrayBuffer);
return geojson;
}

case'ImageSource': {
case 'ImageSource': {
if (typeof file.content === 'string') {
// Convert base64 to a data URL
const mimeType = this._getMimeType(filepath);
Expand Down Expand Up @@ -387,7 +392,9 @@ export class JupyterGISModel implements IJupyterGISModel {
case 'svg':
return 'image/svg+xml';
default:
console.warn(`Unknown file extension: ${extension}, defaulting to 'application/octet-stream'`);
console.warn(
`Unknown file extension: ${extension}, defaulting to 'application/octet-stream'`
);
return 'application/octet-stream';
}
}
Expand All @@ -398,7 +405,9 @@ export class JupyterGISModel implements IJupyterGISModel {
* @returns An ArrayBuffer.
*/
private async _stringToArrayBuffer(content: string): Promise<ArrayBuffer> {
const base64Response = await fetch(`data:application/octet-stream;base64,${content}`);
const base64Response = await fetch(
`data:application/octet-stream;base64,${content}`
);
return await base64Response.arrayBuffer();
}

Expand Down

0 comments on commit 3ff2c78

Please sign in to comment.