-
Notifications
You must be signed in to change notification settings - Fork 8
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
Popup utils and display issue #475
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b2187c4
update display
jmhauck 8981064
one more style update
jmhauck c5d9ffa
add popup utils
jmhauck 088fb3d
Merge branch 'develop' into mobile
jmhauck 8bf17f1
modal padding
jmhauck 28b6a13
Merge branch 'mobile' of https://github.com/Esri/solutions-components…
jmhauck ba1d8ed
honor visible fields
jmhauck 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** @license | ||
* Copyright 2022 Esri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { loadModules } from "./loadModules"; | ||
|
||
export class PopupUtils { | ||
|
||
/** | ||
* esri/arcade: https://developers.arcgis.com/javascript/latest/api-reference/esri-arcade.html | ||
*/ | ||
arcade: typeof import("esri/arcade"); | ||
|
||
/** | ||
* Get the popup title that honors arcade expressions | ||
* | ||
* @returns Promise resolving with the popup title | ||
* | ||
* @protected | ||
*/ | ||
public async getPopupTitle( | ||
graphic: __esri.Graphic | ||
): Promise<string> { | ||
if (!this.arcade) { | ||
await this._initModules() | ||
} | ||
let attributes = {}; | ||
for (const [key, value] of Object.entries(graphic.attributes)) { | ||
attributes = { | ||
...attributes, | ||
[`{${key.toUpperCase()}}`]: value | ||
}; | ||
} | ||
const layer = graphic.layer as __esri.FeatureLayer; | ||
const popupTitle = this._removeTags(layer?.popupTemplate?.title as string); | ||
if (popupTitle.includes("{expression/expr") && layer?.popupTemplate?.expressionInfos != null) { | ||
for (let i = 0; i < layer.popupTemplate?.expressionInfos.length; i++) { | ||
const info = layer.popupTemplate.expressionInfos[i]; | ||
const profile = { | ||
variables: [ | ||
{ | ||
name: "$feature", | ||
type: "feature" | ||
} | ||
] | ||
} as __esri.Profile; | ||
try { | ||
const arcadeExecutor = await this.arcade.createArcadeExecutor(info.expression, profile); | ||
const arcadeTitle = arcadeExecutor.execute({ $feature: graphic }); | ||
if (arcadeTitle != null || arcadeTitle !== "") { | ||
attributes[`{expression/${info.name}}`.toUpperCase()] = arcadeTitle; | ||
} | ||
} catch { | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
return popupTitle?.replace(/{.*?}/g, (placeholder: string) => { | ||
return attributes[placeholder.toUpperCase()] != null ? (attributes[placeholder.toUpperCase()] as string) : ""; | ||
}); | ||
} | ||
|
||
/** | ||
* Remove any tags from the title | ||
* | ||
* @returns title string without tags | ||
* | ||
* @protected | ||
*/ | ||
protected _removeTags(str: string): string { | ||
if (str == null || str === "") { | ||
return ""; | ||
} | ||
return str.toString().replace(/(<([^>]+)>)/gi, ""); | ||
} | ||
|
||
/** | ||
* Load esri javascript api modules | ||
* | ||
* @returns Promise resolving when function is done | ||
* | ||
* @protected | ||
*/ | ||
protected async _initModules(): Promise<void> { | ||
const [arcade] = await loadModules([ | ||
"esri/arcade" | ||
]); | ||
this.arcade = arcade; | ||
} | ||
|
||
} |
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.
Am I misreading this line? Expanded, I think that it is
And so It appears that this line is actually
and hideMap is irrelevant.