-
Notifications
You must be signed in to change notification settings - Fork 378
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
Finalise shareKeys #5055
Finalise shareKeys #5055
Conversation
export function isInitDataPromise( | ||
initSource: InitSource | ||
): initSource is InitDataPromise { | ||
return ( | ||
initSource && | ||
Object.prototype.toString.call(initSource) === "[object Promise]" | ||
); | ||
} | ||
|
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.
Used for v7-v8 catalog converting
addedByUser( | ||
<BaseModel>catalogMember.terria.getModelById(BaseModel, containerId), | ||
{ depth: depth + 1 } | ||
) | ||
addedByUser(catalogMember.terria.getModelById(BaseModel, containerId), { | ||
depth: depth + 1 | ||
}) |
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.
Removed bad <BaseModel>
typing here
@@ -1026,7 +1051,8 @@ export default class Terria { | |||
let existingReference = this.getModelById(MagdaReference, id); | |||
if (existingReference === undefined) { | |||
existingReference = new MagdaReference(id, this); | |||
this.addModel(existingReference); | |||
// Add model with terria aspects shareKeys | |||
this.addModel(existingReference, aspects?.terria?.shareKeys); |
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.
For magda root group sharekeys
lib/Models/Terria.ts
Outdated
const loadInitSource = createTransformer( | ||
(initSource: InitSource): Promise<JsonObject | undefined> => { | ||
let promise: Promise<JsonValue | undefined>; | ||
|
||
async (initSource: InitSource): Promise<JsonObject | undefined> => { | ||
let jsonValue: JsonValue | undefined; | ||
if (isInitUrl(initSource)) { | ||
promise = loadJson5(initSource.initUrl); | ||
jsonValue = await loadJson5(initSource.initUrl); | ||
} else if (isInitOptions(initSource)) { | ||
promise = initSource.options.reduce((previousOptionPromise, option) => { | ||
return previousOptionPromise | ||
.then(json => { | ||
if (json === undefined) { | ||
return loadInitSource(option); | ||
} | ||
return json; | ||
}) | ||
.catch(_ => { | ||
await initSource.options.reduce(async (previousOptionPromise, option) => { | ||
try { | ||
const json = await previousOptionPromise; | ||
if (json === undefined) { | ||
return loadInitSource(option); | ||
}); | ||
} | ||
return json; | ||
} catch (_) { | ||
return loadInitSource(option); | ||
} | ||
}, Promise.resolve<JsonObject | undefined>(undefined)); | ||
} else { | ||
promise = Promise.resolve(initSource.data); | ||
} else if (isInitData(initSource)) { | ||
jsonValue = initSource.data; | ||
} else if (isInitDataPromise(initSource)) { | ||
jsonValue = (await initSource).data; | ||
} | ||
|
||
return promise.then(jsonValue => { | ||
if (isJsonObject(jsonValue)) { | ||
return jsonValue; | ||
} | ||
return undefined; | ||
}); | ||
if (jsonValue && isJsonObject(jsonValue)) { | ||
return jsonValue; | ||
} | ||
return undefined; |
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.
Asyncified + added support for InitDataPromise
- which is just a Promise
which resolves to InitData
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.
Still reviewing this
@@ -288,7 +288,7 @@ class GetCapabilitiesStratum extends LoadableStratum( | |||
if (!isDefined(this.catalogGroup.uniqueId)) { | |||
return; | |||
} | |||
return `${this.catalogGroup.uniqueId}/${layer.Name || layer.Title}`; | |||
return `${this.catalogGroup.uniqueId}/${layer.Title}`; |
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.
Revert WMS id to match v7
// If we legends need scaling, this is the only way to do it :/ | ||
// See https://stackoverflow.com/questions/7699621/display-image-at-50-of-its-native-size | ||
// or https://stackoverflow.com/questions/35711807/display-high-dpi-image-at-50-scaling-using-just-css | ||
resizeLegendImage( | ||
evt: SyntheticEvent<HTMLObjectElement>, | ||
onImageLoad( | ||
evt: SyntheticEvent<HTMLImageElement>, | ||
legend: Model<LegendTraits> | ||
) { | ||
if (!isDefined(legend.imageScaling) || legend.imageScaling === 1) return; | ||
const image = evt.target as HTMLObjectElement; | ||
image.style.display = "none"; | ||
image.style.maxWidth = "none"; | ||
|
||
image.style.width = `${legend.imageScaling * image.offsetWidth}px`; | ||
if (evt.type === "error") { | ||
return; | ||
} | ||
|
||
image.style.display = "initial"; | ||
|
||
// If legend need scaling, this is the only way to do it :/ | ||
// See https://stackoverflow.com/questions/7699621/display-image-at-50-of-its-native-size | ||
// or https://stackoverflow.com/questions/35711807/display-high-dpi-image-at-50-scaling-using-just-css | ||
|
||
image.style.width = `${(legend.imageScaling ?? 1) * image.offsetWidth}px`; | ||
// Must set maxWidth *after* setting width, as it may change offsetWidth | ||
image.style.maxWidth = "100%"; | ||
} |
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.
Refactored this to hide if an image request gives error response.
@@ -58,7 +58,7 @@ | |||
"@vx/tooltip": "^0.0.193-alpha.2", | |||
"babel-loader": "^8.0.5", | |||
"babel-plugin-jsx-control-statements": "^4.0.0", | |||
"catalog-converter": "^0.0.2-alpha.3", | |||
"catalog-converter": "^0.0.2-alpha.4", |
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 depends on TerriaJS/catalog-converter#32
|
Co-authored-by: Stephen Davies <steve9164@gmail.com>
Co-authored-by: Stephen Davies <steve9164@gmail.com>
Co-authored-by: Stephen Davies <steve9164@gmail.com>
// Geoserver fontColor must be a hex value | ||
// enable if we can ensure a dark background | ||
const fontColor = terriaTheme.textLight.split("#")?.[1]; | ||
// Geoserver fontColor must be a hex value - use `textLight` theme colour | ||
let fontColor = terriaTheme.textLight.split("#")?.[1]; | ||
if (isDefined(fontColor)) { | ||
legendOptions += `;fontColor:0x${ | ||
terriaTheme.textLight.split("#")[1] | ||
}`; | ||
// If fontColor is a 3-character hex -> turn into 6 | ||
if (fontColor.length === 3) { | ||
fontColor = `${fontColor[0]}${fontColor[0]}${fontColor[1]}${fontColor[1]}${fontColor[2]}${fontColor[2]}`; | ||
} | ||
legendOptions += `;fontColor:0x${fontColor}`; |
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.
If textLight
is #fff
- Geoserver gives us a blue legend ?!
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.
Tests pass locally
Finalise
shareKeys
Fixes ##4774
See https://github.com/TerriaJS/terriajs/blob/next/architecture/0005-root-group-ids-and-shareKeys.md for background
V7 catalog support
Partially fixes #4897
This replaces https://github.com/TerriaJS/terrace/pull/158
Adds
v7initializationUrls
to terria config. It will convert catalogs to v8 and print messages to console.For example:
ShareKeys support for root group of Magda map config
To map
map-config-de-australia
to the root group (now"/"
) you can add ashareKey
like so:ShareKeys support for dynamic groups
See ADR for more info - https://github.com/TerriaJS/terriajs/blob/77a25b6967281e1f6189ccf54d77b2974730d4e1/architecture/0006-dynamic-groups-and-shareKeys.md
Change how WMS group sets
id
for itemsTo mimic v7. See https://github.com/TerriaJS/terriajs/blob/77a25b6967281e1f6189ccf54d77b2974730d4e1/architecture/0006-dynamic-groups-and-shareKeys.md#wms-group
Other small changes
InitDataPromise
toInitSources
modelIdShareKeysMap
map -model.id
->shareKeys
object
instead ofimg
- sometimes it was showing html error responsesChecklist