-
Notifications
You must be signed in to change notification settings - Fork 875
feat: add custom tile provider settings for Geometry Viewer #10142
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
Open
NivGreenstein
wants to merge
12
commits into
pgadmin-org:master
Choose a base branch
from
NivGreenstein:feat/geometry-viewer-settings
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5d88b2c
feat: add geometry viewer tile provider preferences
NivGreenstein e3aa0ca
feat: support custom geometry viewer tile layers
NivGreenstein ab2db7e
test: cover geometry viewer tile provider helpers
NivGreenstein 3983559
docs: document geometry viewer tile provider settings
NivGreenstein feb9222
fix: sanitize custom tile provider name
NivGreenstein 8380aeb
fix: show custom tile warning inline
NivGreenstein 974d9ee
fix: allow longer tile provider URLs
NivGreenstein 5cc2441
fix: stabilize geometry base layer keys
NivGreenstein 69726fb
fix: preserve preference control handlers
NivGreenstein 641a067
fix: handle malformed binary path preferences
NivGreenstein 9dae1af
fix: preserve cleared keyboard shortcuts
NivGreenstein 15cece5
fix: await preference reset follow-up actions
NivGreenstein 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
120 changes: 120 additions & 0 deletions
120
web/pgadmin/tools/sqleditor/static/js/components/sections/GeometryViewerUtils.js
This file contains hidden or 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,120 @@ | ||
| ///////////////////////////////////////////////////////////// | ||
| // | ||
| // pgAdmin 4 - PostgreSQL Tools | ||
| // | ||
| // Copyright (C) 2013 - 2026, The pgAdmin Development Team | ||
| // This software is released under the PostgreSQL Licence | ||
| // | ||
| ////////////////////////////////////////////////////////////// | ||
| import { CRS } from 'leaflet'; | ||
| import DOMPurify from 'dompurify'; | ||
| import gettext from 'sources/gettext'; | ||
|
|
||
| const DEFAULT_MAX_ZOOM = 18; | ||
| const OSM_ATTRIBUTION = '© <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>'; | ||
| const CARTODB_ATTRIBUTION = OSM_ATTRIBUTION | ||
| + ', © <a href="http://cartodb.com/attributions" target="_blank">CartoDB</a>'; | ||
|
|
||
| // Builds the custom tile provider config from the sqleditor module | ||
| // preferences, or null when the URL preference is blank (feature disabled). | ||
| // A non-blank but unusable URL yields {invalid: true} so the caller can | ||
| // surface a message and fall back to the default layers. | ||
| export function getCustomTileProvider(prefs) { | ||
| const url = (prefs?.custom_tile_url ?? '').trim(); | ||
| if (!url) { | ||
| return null; | ||
| } | ||
| if (!/^https?:\/\//.test(url) || !url.includes('{x}') | ||
| || !url.includes('{y}') || !url.includes('{z}')) { | ||
| return { invalid: true }; | ||
| } | ||
| const crs = prefs.custom_tile_crs || 'EPSG:3857'; | ||
| return { | ||
| url: url, | ||
| name: DOMPurify.sanitize((prefs.custom_tile_name ?? '').trim() || gettext('Custom')), | ||
| crs: crs, | ||
| attribution: DOMPurify.sanitize(prefs.custom_tile_attribution || ''), | ||
| maxZoom: prefs.custom_tile_max_zoom ?? DEFAULT_MAX_ZOOM, | ||
| isDefaultCrs: crs === 'EPSG:3857', | ||
| }; | ||
| } | ||
|
|
||
| // Returns the Leaflet CRS the map must be created with. Tiles (and thus the | ||
| // custom provider) only apply to SRID 4326 data; anything else renders on a | ||
| // blank Cartesian plane as before. The provider CRS string is resolved | ||
| // dynamically against Leaflet's CRS namespace ('EPSG:4326' -> CRS.EPSG4326), | ||
| // falling back to Web Mercator for unknown codes. | ||
| export function getMapCrs(selectedSRID, provider) { | ||
| if (selectedSRID !== 4326) { | ||
| return CRS.Simple; | ||
| } | ||
| if (!provider || provider.invalid) { | ||
| return CRS.EPSG3857; | ||
| } | ||
| const crs = CRS[provider.crs.replace(':', '')]; | ||
| return crs?.code ? crs : CRS.EPSG3857; | ||
| } | ||
|
|
||
| // Returns the base layer configs for the LayersControl. Built-in layers are | ||
| // all Web Mercator tiled, so they are only offered when no custom provider | ||
| // is set or the custom provider is Web Mercator too; a custom provider in | ||
| // any other CRS can only be combined with the empty layer. | ||
| export function getBaseLayers(provider) { | ||
| const hasProvider = Boolean(provider) && !provider.invalid; | ||
| const layers = [{ | ||
| name: gettext('Empty'), | ||
| url: '', | ||
| checked: false, | ||
| }]; | ||
|
|
||
| if (!hasProvider || provider.isDefaultCrs) { | ||
| layers.push({ | ||
| name: gettext('Street'), | ||
| url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', | ||
| maxZoom: 19, | ||
| attribution: OSM_ATTRIBUTION, | ||
| checked: !hasProvider, | ||
| }, { | ||
| name: gettext('Topography'), | ||
| url: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', | ||
| maxZoom: 17, | ||
| attribution: OSM_ATTRIBUTION | ||
| + ', © <a href="http://viewfinderpanoramas.org" target="_blank">SRTM</a>' | ||
| + ', © <a href="https://opentopomap.org" target="_blank">OpenTopoMap</a>', | ||
| checked: false, | ||
| }, { | ||
| name: gettext('Gray Style'), | ||
| url: 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}{r}.png', | ||
| maxZoom: 19, | ||
| attribution: CARTODB_ATTRIBUTION, | ||
| subdomains: 'abcd', | ||
| checked: false, | ||
| }, { | ||
| name: gettext('Light Color'), | ||
| url: 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/rastertiles/voyager/{z}/{x}/{y}{r}.png', | ||
| maxZoom: 19, | ||
| attribution: CARTODB_ATTRIBUTION, | ||
| subdomains: 'abcd', | ||
| checked: false, | ||
| }, { | ||
| name: gettext('Dark Matter'), | ||
| url: 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}{r}.png', | ||
| maxZoom: 19, | ||
| attribution: CARTODB_ATTRIBUTION, | ||
| subdomains: 'abcd', | ||
| checked: false, | ||
| }); | ||
| } | ||
|
|
||
| if (hasProvider) { | ||
| layers.push({ | ||
| name: provider.name, | ||
| url: provider.url, | ||
| maxZoom: provider.maxZoom, | ||
| attribution: provider.attribution, | ||
| checked: true, | ||
| }); | ||
| } | ||
|
|
||
| return layers; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.