-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): Add layers using wms and mvt (#694)
- Loading branch information
1 parent
4afa473
commit 5fe5126
Showing
10 changed files
with
347 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
web/src/beta/features/Editor/DataSourceManager/VectorTiles/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { FC } from "react"; | ||
|
||
import Button from "@reearth/beta/components/Button"; | ||
import generateRandomString from "@reearth/beta/utils/generate-random-string"; | ||
import { useT } from "@reearth/services/i18n"; | ||
|
||
import { DataProps } from ".."; | ||
import useHooks from "../hooks"; | ||
import { | ||
AddLayerWrapper, | ||
AssetWrapper, | ||
ColJustifyBetween, | ||
DeleteLayerIcon, | ||
Input, | ||
InputGroup, | ||
LayerWrapper, | ||
SubmitWrapper, | ||
} from "../utils"; | ||
|
||
const VectorTiles: FC<DataProps> = ({ sceneId, onSubmit, onClose }) => { | ||
const { | ||
urlValue, | ||
layerValue, | ||
layerInput, | ||
layers, | ||
setUrlValue, | ||
setLayerValue, | ||
handleAddLayer, | ||
handleDeleteLayer, | ||
handleLayerInput, | ||
} = useHooks(); | ||
|
||
const t = useT(); | ||
|
||
const handleSubmit = () => { | ||
onSubmit({ | ||
layerType: "simple", | ||
sceneId, | ||
title: generateRandomString(5), | ||
visible: true, | ||
config: { | ||
data: { | ||
url: urlValue !== "" ? urlValue : null, | ||
type: "mvt", | ||
layers: layers.length <= 1 ? layers[0] : layers, | ||
}, | ||
resource: { | ||
clampToGround: true, | ||
}, | ||
marker: { | ||
heightReference: "clamp", | ||
}, | ||
polygon: { | ||
heightReference: "clamp", | ||
}, | ||
polyline: { | ||
clampToGround: true, | ||
}, | ||
}, | ||
}); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<ColJustifyBetween> | ||
<AssetWrapper> | ||
<InputGroup | ||
label={t("Resource URL")} | ||
description={t("URL of the data source you want to add.")}> | ||
<Input | ||
type="text" | ||
placeholder="https://" | ||
value={urlValue} | ||
onChange={e => setUrlValue(e.target.value)} | ||
/> | ||
</InputGroup> | ||
<InputGroup | ||
label={t("Choose layer to add")} | ||
description={t("Layer of the data source you want to add.")}> | ||
{layers.map((layer: string, index: number) => ( | ||
<LayerWrapper key={index}> | ||
<Input type="text" placeholder={`${layer}`} disabled={true} /> | ||
<DeleteLayerIcon icon="bin" size={16} onClick={() => handleDeleteLayer(index)} /> | ||
</LayerWrapper> | ||
))} | ||
{(!layers.length || layerInput) && ( | ||
<LayerWrapper> | ||
<Input | ||
type="text" | ||
placeholder={t("layer name")} | ||
value={layerValue} | ||
onChange={e => setLayerValue(e.target.value)} | ||
onKeyDown={handleAddLayer} | ||
/> | ||
<DeleteLayerIcon disabled={true} icon="bin" size={16} /> | ||
</LayerWrapper> | ||
)} | ||
|
||
<AddLayerWrapper> | ||
<Button | ||
icon="plus" | ||
text={t("Layer")} | ||
buttonType="primary" | ||
size="small" | ||
onClick={handleLayerInput} | ||
disabled={!layerValue && !layers.length} | ||
/> | ||
</AddLayerWrapper> | ||
</InputGroup> | ||
</AssetWrapper> | ||
<SubmitWrapper> | ||
<Button | ||
text={t("Add to Layer")} | ||
buttonType="primary" | ||
size="medium" | ||
onClick={handleSubmit} | ||
disabled={!urlValue} | ||
/> | ||
</SubmitWrapper> | ||
</ColJustifyBetween> | ||
); | ||
}; | ||
|
||
export default VectorTiles; |
124 changes: 124 additions & 0 deletions
124
web/src/beta/features/Editor/DataSourceManager/WmsTiles/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { FC } from "react"; | ||
|
||
import Button from "@reearth/beta/components/Button"; | ||
import generateRandomString from "@reearth/beta/utils/generate-random-string"; | ||
import { useT } from "@reearth/services/i18n"; | ||
|
||
import { DataProps } from ".."; | ||
import useHooks from "../hooks"; | ||
import { | ||
AddLayerWrapper, | ||
AssetWrapper, | ||
ColJustifyBetween, | ||
DeleteLayerIcon, | ||
Input, | ||
InputGroup, | ||
LayerWrapper, | ||
SubmitWrapper, | ||
} from "../utils"; | ||
|
||
const WmsTiles: FC<DataProps> = ({ sceneId, onSubmit, onClose }) => { | ||
const { | ||
urlValue, | ||
layerValue, | ||
layerInput, | ||
layers, | ||
setUrlValue, | ||
setLayerValue, | ||
handleAddLayer, | ||
handleDeleteLayer, | ||
handleLayerInput, | ||
} = useHooks(); | ||
|
||
const t = useT(); | ||
|
||
const handleSubmit = () => { | ||
onSubmit({ | ||
layerType: "simple", | ||
sceneId, | ||
title: generateRandomString(5), | ||
visible: true, | ||
config: { | ||
data: { | ||
url: urlValue !== "" ? urlValue : null, | ||
type: "wms", | ||
layers: layers.length <= 1 ? layers[0] : layers, | ||
}, | ||
resource: { | ||
clampToGround: true, | ||
}, | ||
marker: { | ||
heightReference: "clamp", | ||
}, | ||
polygon: { | ||
heightReference: "clamp", | ||
}, | ||
polyline: { | ||
clampToGround: true, | ||
}, | ||
}, | ||
}); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<ColJustifyBetween> | ||
<AssetWrapper> | ||
<InputGroup | ||
label={t("Resource URL")} | ||
description={t("URL of the data source you want to add.")}> | ||
<Input | ||
type="text" | ||
placeholder="https://" | ||
value={urlValue} | ||
onChange={e => setUrlValue(e.target.value)} | ||
/> | ||
</InputGroup> | ||
<InputGroup | ||
label={t("Choose layer to add")} | ||
description={t("Layer of the data source you want to add.")}> | ||
{layers.map((layer: string, index: number) => ( | ||
<LayerWrapper key={index}> | ||
<Input type="text" placeholder={`${layer}`} disabled={true} /> | ||
<DeleteLayerIcon icon="bin" size={16} onClick={() => handleDeleteLayer(index)} /> | ||
</LayerWrapper> | ||
))} | ||
{(!layers.length || layerInput) && ( | ||
<LayerWrapper> | ||
<Input | ||
type="text" | ||
placeholder={t("layer name")} | ||
value={layerValue} | ||
onChange={e => setLayerValue(e.target.value)} | ||
onKeyDown={handleAddLayer} | ||
/> | ||
<DeleteLayerIcon disabled={true} icon="bin" size={16} /> | ||
</LayerWrapper> | ||
)} | ||
|
||
<AddLayerWrapper> | ||
<Button | ||
icon="plus" | ||
text={t("Layer")} | ||
buttonType="primary" | ||
size="small" | ||
onClick={handleLayerInput} | ||
disabled={!layerValue && !layers.length} | ||
/> | ||
</AddLayerWrapper> | ||
</InputGroup> | ||
</AssetWrapper> | ||
<SubmitWrapper> | ||
<Button | ||
text={t("Add to Layer")} | ||
buttonType="primary" | ||
size="medium" | ||
onClick={handleSubmit} | ||
disabled={!urlValue} | ||
/> | ||
</SubmitWrapper> | ||
</ColJustifyBetween> | ||
); | ||
}; | ||
|
||
export default WmsTiles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useState, KeyboardEvent } from "react"; | ||
|
||
export default () => { | ||
const [urlValue, setUrlValue] = useState(""); | ||
const [layerValue, setLayerValue] = useState(""); | ||
const [layers, setLayers] = useState<string[]>([]); | ||
const [layerInput, setLayerInput] = useState(false); | ||
|
||
const handleonAddLayer = () => { | ||
if (layerValue.trim() !== "") { | ||
const exist = layers.some((layer: string) => layer === layerValue); | ||
if (!exist) setLayers(prev => [...prev, layerValue]); | ||
setLayerValue(""); | ||
} | ||
}; | ||
|
||
const handleLayerInput = () => { | ||
handleonAddLayer(); | ||
setLayerInput(true); | ||
}; | ||
|
||
const handleAddLayer = (e: KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === "Enter") { | ||
handleonAddLayer(); | ||
setLayerInput(false); | ||
} | ||
}; | ||
|
||
const handleDeleteLayer = (idx: number) => { | ||
const updatedLayers = [...layers]; | ||
updatedLayers.splice(idx, 1); | ||
setLayers(updatedLayers); | ||
}; | ||
|
||
return { | ||
urlValue, | ||
layerInput, | ||
layerValue, | ||
layers, | ||
setLayerValue, | ||
setUrlValue, | ||
handleAddLayer, | ||
handleLayerInput, | ||
handleDeleteLayer, | ||
}; | ||
}; |
Oops, something went wrong.