Skip to content
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

feat(arcgis): convert link to rest format #338

Merged
merged 5 commits into from
Jan 9, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/components/layers-panel/layers-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { useState } from "react";
import styled, { css } from "styled-components";
import { load } from "@loaders.gl/core";
import { forEach, load } from "@loaders.gl/core";

Check warning on line 8 in src/components/layers-panel/layers-panel.tsx

View workflow job for this annotation

GitHub Actions / Linter

'forEach' is defined but never used
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


import {
LayerExample,
Expand Down Expand Up @@ -197,11 +197,33 @@

useClickOutside([warningNode], () => setShowExistedError(false));

const convertUrlToRestFormat = (url: string): string => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to src\utils\url-utils.ts. Add a test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

let urlRest = "https://www.arcgis.com/sharing/rest/content/items/";
const urlObject = new URL(url);

let param: string | null = null;
for (const paramName of ["id", "webscene", "layers"]) {
param = urlObject.searchParams.get(paramName);
if (param) {
break;
}
}
if (param) {
urlRest += param + "/data";
} else {
// The url cannot be converted. Use it "as is".
return url;
}
return urlRest;
};

const handleInsertLayer = (layer: {
name: string;
url: string;
token?: string;
}) => {
layer.url = convertUrlToRestFormat(layer.url);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it really work for layers? We were about doing it for scenes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


const existedLayer = layers.some(
(exisLayer) => exisLayer.url.trim() === layer.url.trim()
);
Expand Down Expand Up @@ -253,6 +275,8 @@
url: string;
token?: string;
}) => {
scene.url = convertUrlToRestFormat(scene.url);

const existedScene = layers.some(
(exisLayer) => exisLayer.url.trim() === scene.url.trim()
);
Expand Down