-
Notifications
You must be signed in to change notification settings - Fork 46
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
Support custom layer to Maps #150
Merged
junqiu-lei
merged 6 commits into
opensearch-project:feature/new-maps
from
junqiu-lei:custom_layer
Jan 4, 2023
+560
−45
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b2d5cd3
Support custom layer to Maps
junqiu-lei 3e349de
Add WMS protocol to custom layer
junqiu-lei d286a0d
Update beforeMbLayerId to addLayer
junqiu-lei 5efc7fb
Update WMS
junqiu-lei e6916b5
Update name
junqiu-lei 3412124
Update to use Form
junqiu-lei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
47 changes: 47 additions & 0 deletions
47
maps_dashboards/public/components/layer_config/custom_map_config/custom_map_config_panel.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,47 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { Fragment } from 'react'; | ||
import { EuiSpacer, EuiTabbedContent } from '@elastic/eui'; | ||
import { CustomLayerSpecification } from '../../../model/mapLayerType'; | ||
import { LayerBasicSettings } from '../layer_basic_settings'; | ||
import { CustomMapSource } from './custom_map_source'; | ||
|
||
interface Props { | ||
selectedLayerConfig: CustomLayerSpecification; | ||
setSelectedLayerConfig: Function; | ||
setIsUpdateDisabled: Function; | ||
isLayerExists: Function; | ||
} | ||
|
||
export const CustomMapConfigPanel = (props: Props) => { | ||
const newProps = { | ||
...props, | ||
}; | ||
|
||
const tabs = [ | ||
{ | ||
id: 'custom-map-source--id', | ||
name: 'Data', | ||
content: ( | ||
<Fragment> | ||
<EuiSpacer size="m" /> | ||
<CustomMapSource {...newProps} /> | ||
</Fragment> | ||
), | ||
}, | ||
{ | ||
id: 'settings--id', | ||
name: 'Settings', | ||
content: ( | ||
<Fragment> | ||
<EuiSpacer size="m" /> | ||
<LayerBasicSettings {...newProps} /> | ||
</Fragment> | ||
), | ||
}, | ||
]; | ||
return <EuiTabbedContent tabs={tabs} initialSelectedTab={tabs[0]} />; | ||
}; |
297 changes: 297 additions & 0 deletions
297
maps_dashboards/public/components/layer_config/custom_map_config/custom_map_source.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,297 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
import { EuiSpacer, EuiPanel, EuiForm, EuiFieldText, EuiSelect, EuiFormRow } from '@elastic/eui'; | ||
import { CustomLayerSpecification } from '../../../model/mapLayerType'; | ||
|
||
interface Props { | ||
selectedLayerConfig: CustomLayerSpecification; | ||
setSelectedLayerConfig: Function; | ||
setIsUpdateDisabled: Function; | ||
} | ||
|
||
export const CustomMapSource = ({ | ||
selectedLayerConfig, | ||
setSelectedLayerConfig, | ||
setIsUpdateDisabled, | ||
}: Props) => { | ||
const customMapTypeOptions = [ | ||
{ value: 'tms', text: 'Tile Map Service (TMS)' }, | ||
{ value: 'wms', text: 'Web Map Service (WMS)' }, | ||
]; | ||
|
||
const [customMapURL, setCustomMapURL] = useState<string>(''); | ||
const [customMapAttribution, setCustomMapAttribution] = useState<string>(''); | ||
const [customType, setCustomType] = useState(customMapTypeOptions[1].value); | ||
const [WMSLayers, setWMSLayers] = useState<string>(''); | ||
const [WMSVersion, setWMSVersion] = useState<string>(''); | ||
const [WMSFormat, setWMSFormat] = useState<string>(''); | ||
const [WMSStyles, setWMSStyles] = useState<string>(''); | ||
// CRS: Coordinate reference systems in WMS | ||
const [WMSCoordinateSystem, setWMSCoordinateSystem] = useState<string>(''); | ||
const [WMSBbox, setWMSBbox] = useState<string>(''); | ||
|
||
const onChangeCustomMapURL = (e: any) => { | ||
setCustomMapURL(e.target.value); | ||
setSelectedLayerConfig({ | ||
...selectedLayerConfig, | ||
source: { | ||
...selectedLayerConfig?.source, | ||
url: e.target.value, | ||
}, | ||
}); | ||
}; | ||
|
||
const onChangeCustomMapAttribution = (e: any) => { | ||
setCustomMapAttribution(e.target.value); | ||
setSelectedLayerConfig({ | ||
...selectedLayerConfig, | ||
source: { | ||
...selectedLayerConfig?.source, | ||
attribution: e.target.value, | ||
}, | ||
}); | ||
}; | ||
|
||
const onChangeCustomType = (e: any) => { | ||
setCustomType(e.target.value); | ||
setSelectedLayerConfig({ | ||
...selectedLayerConfig, | ||
source: { | ||
...selectedLayerConfig?.source, | ||
customType: e.target.value, | ||
}, | ||
}); | ||
}; | ||
|
||
const onChangeWMSLayers = (e: any) => { | ||
setWMSLayers(e.target.value); | ||
setSelectedLayerConfig({ | ||
...selectedLayerConfig, | ||
source: { | ||
...selectedLayerConfig?.source, | ||
layers: e.target.value, | ||
}, | ||
}); | ||
}; | ||
|
||
const onChangeWMSVersion = (e: any) => { | ||
setWMSVersion(e.target.value); | ||
setSelectedLayerConfig({ | ||
...selectedLayerConfig, | ||
source: { | ||
...selectedLayerConfig?.source, | ||
version: e.target.value, | ||
}, | ||
}); | ||
}; | ||
|
||
const onChangeWMSFormat = (e: any) => { | ||
setWMSFormat(e.target.value); | ||
setSelectedLayerConfig({ | ||
...selectedLayerConfig, | ||
source: { | ||
...selectedLayerConfig?.source, | ||
format: e.target.value, | ||
}, | ||
}); | ||
}; | ||
|
||
const onChangeWMSStyles = (e: any) => { | ||
setWMSStyles(e.target.value); | ||
setSelectedLayerConfig({ | ||
...selectedLayerConfig, | ||
source: { | ||
...selectedLayerConfig?.source, | ||
styles: e.target.value, | ||
}, | ||
}); | ||
}; | ||
|
||
const onChangeWMSCoordinateSystem = (e: any) => { | ||
setWMSCoordinateSystem(e.target.value); | ||
setSelectedLayerConfig({ | ||
...selectedLayerConfig, | ||
source: { | ||
...selectedLayerConfig?.source, | ||
crs: e.target.value, | ||
}, | ||
}); | ||
}; | ||
|
||
const onChangeWMSBbox = (e: any) => { | ||
setWMSBbox(e.target.value); | ||
setSelectedLayerConfig({ | ||
...selectedLayerConfig, | ||
source: { | ||
...selectedLayerConfig?.source, | ||
bbox: e.target.value, | ||
}, | ||
}); | ||
}; | ||
|
||
const isInvalidURL = (url: string): boolean => { | ||
if (url === '') return false; | ||
try { | ||
new URL(url); | ||
return false; | ||
} catch (e) { | ||
return true; | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
setCustomMapURL(selectedLayerConfig.source.url); | ||
setCustomType(selectedLayerConfig.source.customType); | ||
setCustomMapAttribution(selectedLayerConfig.source.attribution); | ||
if (selectedLayerConfig.source.customType === 'wms') { | ||
setWMSLayers(selectedLayerConfig.source.layers); | ||
setWMSVersion(selectedLayerConfig.source.version); | ||
setWMSFormat(selectedLayerConfig.source.format); | ||
setWMSStyles(selectedLayerConfig.source.styles); | ||
setWMSCoordinateSystem(selectedLayerConfig.source.crs); | ||
setWMSBbox(selectedLayerConfig.source.bbox); | ||
} | ||
}, [selectedLayerConfig]); | ||
|
||
useEffect(() => { | ||
setCustomMapAttribution(selectedLayerConfig.source.attribution); | ||
}, [selectedLayerConfig.source.attribution]); | ||
|
||
useEffect(() => { | ||
if (customType === 'wms') { | ||
setIsUpdateDisabled( | ||
customMapURL === '' || | ||
WMSLayers === '' || | ||
WMSVersion === '' || | ||
WMSFormat === '' || | ||
isInvalidURL(customMapURL) | ||
); | ||
} else { | ||
setIsUpdateDisabled(customMapURL === '' || isInvalidURL(customMapURL)); | ||
} | ||
}, [WMSFormat, WMSLayers, WMSVersion, customMapURL, customType, setIsUpdateDisabled]); | ||
|
||
return ( | ||
<div> | ||
<EuiPanel paddingSize="s"> | ||
<EuiForm> | ||
<EuiFormRow label="Custom type" helpText="Choose custom map type."> | ||
<EuiSelect | ||
options={customMapTypeOptions} | ||
value={customType} | ||
onChange={onChangeCustomType} | ||
fullWidth | ||
/> | ||
</EuiFormRow> | ||
</EuiForm> | ||
<EuiSpacer size="m" /> | ||
{selectedLayerConfig.source.customType === 'tms' && ( | ||
<EuiForm> | ||
<EuiFormRow | ||
label="TMS URL*" | ||
helpText="Raster tile map service URL." | ||
isInvalid={isInvalidURL(customMapURL)} | ||
error={isInvalidURL(customMapURL) ? 'Invalid URL' : undefined} | ||
> | ||
<EuiFieldText | ||
placeholder="https://www.example.com/tiles/{z}/{x}/{y}.png" | ||
value={customMapURL} | ||
onChange={onChangeCustomMapURL} | ||
isInvalid={isInvalidURL(customMapURL)} | ||
fullWidth={true} | ||
/> | ||
</EuiFormRow> | ||
<EuiSpacer size="m" /> | ||
<EuiFormRow | ||
label="TMS attribution" | ||
helpText="The attribution for this TMS layer, displayed at right-bottom map." | ||
> | ||
<EuiFieldText | ||
value={customMapAttribution} | ||
onChange={onChangeCustomMapAttribution} | ||
fullWidth={true} | ||
/> | ||
</EuiFormRow> | ||
</EuiForm> | ||
)} | ||
{selectedLayerConfig.source.customType === 'wms' && ( | ||
<EuiForm> | ||
<EuiFormRow | ||
label="WMS URL*" | ||
helpText="Web map service URL." | ||
isInvalid={isInvalidURL(customMapURL)} | ||
error={isInvalidURL(customMapURL) ? 'Invalid URL' : undefined} | ||
> | ||
<EuiFieldText | ||
placeholder="https://www.example.com/wms/dataset" | ||
value={customMapURL} | ||
onChange={onChangeCustomMapURL} | ||
isInvalid={isInvalidURL(customMapURL)} | ||
fullWidth={true} | ||
/> | ||
</EuiFormRow> | ||
<EuiSpacer size="m" /> | ||
<EuiFormRow | ||
label="WMS layers*" | ||
helpText="The names of the layers to be included in the map image. A comma separated list of layers to use." | ||
> | ||
<EuiFieldText value={WMSLayers} onChange={onChangeWMSLayers} fullWidth={true} /> | ||
</EuiFormRow> | ||
<EuiSpacer size="m" /> | ||
<EuiFormRow label="WMS version*" helpText="The version of the WMS supports."> | ||
<EuiFieldText value={WMSVersion} onChange={onChangeWMSVersion} fullWidth={true} /> | ||
</EuiFormRow> | ||
<EuiSpacer size="m" /> | ||
<EuiFormRow | ||
label="WMS format*" | ||
helpText="The format of the map image to be returned. The most common formats are 'image/png' and 'image/jpeg'." | ||
> | ||
<EuiFieldText value={WMSFormat} onChange={onChangeWMSFormat} fullWidth={true} /> | ||
</EuiFormRow> | ||
<EuiSpacer size="m" /> | ||
<EuiFormRow | ||
label="WMS CRS" | ||
helpText="The coordinate reference system (CRS) to be used for the map image." | ||
> | ||
<EuiFieldText | ||
value={WMSCoordinateSystem} | ||
onChange={onChangeWMSCoordinateSystem} | ||
fullWidth={true} | ||
/> | ||
</EuiFormRow> | ||
<EuiSpacer size="m" /> | ||
<EuiFormRow | ||
label="WMS bbox" | ||
helpText="The bounding box of the area to be included in the map image." | ||
> | ||
<EuiFieldText value={WMSBbox} onChange={onChangeWMSBbox} fullWidth={true} /> | ||
</EuiFormRow> | ||
<EuiSpacer size="m" /> | ||
<EuiFormRow | ||
label="WMS attribution" | ||
helpText="The attribution for this WMS layer, displayed at right-bottom map." | ||
> | ||
<EuiFieldText | ||
value={customMapAttribution} | ||
onChange={onChangeCustomMapAttribution} | ||
fullWidth={true} | ||
/> | ||
</EuiFormRow> | ||
<EuiSpacer size="m" /> | ||
<EuiFormRow | ||
label="WMS styles" | ||
helpText="The styles to be used for each of the layers in the map image." | ||
> | ||
<EuiFieldText value={WMSStyles} onChange={onChangeWMSStyles} fullWidth={true} /> | ||
</EuiFormRow> | ||
</EuiForm> | ||
)} | ||
<EuiSpacer size="s" /> | ||
</EuiPanel> | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Shall we include error message from exception?
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.
this function It's only used to validate it's a valid URL not to validate it's map URL, we would just use it for EuiFormErrorText: