From 9e805dcd4c31c101ab0620abdce3df0157046a08 Mon Sep 17 00:00:00 2001 From: John Hauck Date: Wed, 17 Jan 2024 09:05:29 -0700 Subject: [PATCH 1/3] mapView only --- src/components.d.ts | 8 + .../crowdsource-reporter.tsx | 147 ++++-------------- src/components/crowdsource-reporter/readme.md | 67 +++----- src/components/map-card/readme.md | 2 - src/demos/crowdsource-reporter.html | 141 +++++++++++------ 5 files changed, 159 insertions(+), 206 deletions(-) diff --git a/src/components.d.ts b/src/components.d.ts index 2341ea0f9..a4550f9a1 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -253,6 +253,10 @@ export namespace Components { * IMapInfo[]: array of map infos (name and id) */ "mapInfos": IMapInfo[]; + /** + * esri/views/MapView: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html + */ + "mapView": __esri.MapView; /** * string: The word(s) to display in the reports submit button */ @@ -2218,6 +2222,10 @@ declare namespace LocalJSX { * IMapInfo[]: array of map infos (name and id) */ "mapInfos"?: IMapInfo[]; + /** + * esri/views/MapView: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html + */ + "mapView"?: __esri.MapView; /** * string: The word(s) to display in the reports submit button */ diff --git a/src/components/crowdsource-reporter/crowdsource-reporter.tsx b/src/components/crowdsource-reporter/crowdsource-reporter.tsx index 03d242032..a984f2790 100644 --- a/src/components/crowdsource-reporter/crowdsource-reporter.tsx +++ b/src/components/crowdsource-reporter/crowdsource-reporter.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Component, Element, Host, h, Prop, VNode, State, Listen } from "@stencil/core"; +import { Component, Element, Host, h, Prop, VNode, State, Watch } from "@stencil/core"; import { IMapChange, IMapInfo, ISearchConfiguration, theme } from "../../utils/interfaces"; import { getLocaleComponentStrings } from "../../utils/locale"; import CrowdsourceReporter_T9n from "../../assets/t9n/crowdsource-reporter/resources.json"; @@ -79,6 +79,11 @@ export class CrowdsourceReporter { */ @Prop() loginTitle: string; + /** + * esri/views/MapView: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html + */ + @Prop() mapView: __esri.MapView; + /** * string: The word(s) to display in the reports submit button */ @@ -145,11 +150,6 @@ export class CrowdsourceReporter { */ @State() _mapInfo: IMapInfo; - /** - * __esri.MapView: Stores the current map view - */ - @State() _mapView: __esri.MapView; - /** * boolean: When true the application will be in mobile mode, controls the mobile or desktop view */ @@ -217,6 +217,16 @@ export class CrowdsourceReporter { // //-------------------------------------------------------------------------- + /** + * Called each time the mapView prop is changed. + */ + @Watch("mapView") + async mapViewWatchHandler(): Promise { + await this.mapView.when(async () => { + await this.setMapView(); + }); + } + //-------------------------------------------------------------------------- // // Methods (public) @@ -229,18 +239,6 @@ export class CrowdsourceReporter { // //-------------------------------------------------------------------------- - /** - * Listen for mapChanged event to be fired then store the new mapView so components will be updated - */ - @Listen("mapChanged", { target: "window" }) - async mapChanged( - evt: CustomEvent - ): Promise { - this._mapChange = evt.detail; - await this._mapChange.mapView.when(async () => { - await this.setMapView(); - }); - } //-------------------------------------------------------------------------- // // Functions (lifecycle) @@ -267,26 +265,23 @@ export class CrowdsourceReporter { * Renders the component. */ render() { - let validConfiguration = true; + // const validConfiguration = true; //Check if webMap id is configured - if(!this.mapInfos || this.mapInfos.length<=0 || (this.mapInfos?.length>0 && !this.mapInfos[0]?.id)){ - validConfiguration = false - } + // if(!this.mapInfos || this.mapInfos.length<=0 || (this.mapInfos?.length>0 && !this.mapInfos[0]?.id)){ + // validConfiguration = false + // } return (
- {validConfiguration && - - {this._getReporter()} - {this._getMapNode()} - - } - {!validConfiguration && + + {this._getReporter()} + + {/* {!validConfiguration &&
{this._translations.error}
{ this._translations.invalidConfigurationErrorMsg}
- } + } */}
); @@ -315,7 +310,7 @@ export class CrowdsourceReporter { case "feature-details": renderLists.push(this.getFeatureDetailsFlowItem()); break; - + } }); let sidePanelClass = "side-panel"; @@ -326,7 +321,7 @@ export class CrowdsourceReporter { const themeClass = this.theme === "dark" ? "calcite-mode-dark" : "calcite-mode-light"; return ( - {this._mapView + {this.mapView ? {renderLists?.length > 0 && renderLists} @@ -354,7 +349,7 @@ export class CrowdsourceReporter { @@ -429,7 +424,7 @@ export class CrowdsourceReporter { { @@ -472,76 +467,14 @@ export class CrowdsourceReporter { ); } - /** - * Get the map node based for the current layout options - * @returns the map node - * @protected - */ - protected _getMapNode(): VNode { - let mapContainerClass = "overflow-hidden map-container"; - if (this._isMobile) { - if (this._sidePanelCollapsed) { - mapContainerClass += " map-container-mobile"; - } - } else { - mapContainerClass += " height-full"; - } - - return ( -
-
); - } - - /** - * Get the current map info (configuration details) when maps change - * @param id Id of the map to be returned - * @returns IMapInfo for the provided id - * @protected - */ - protected getMapInfo(id: string): IMapInfo { - let mapInfo: IMapInfo; - this.mapInfos.some(mi => { - if (mi.id === id) { - mapInfo = mi; - return true; - } - }) - return { ...mapInfo }; - } - /** * Set the current map info when maps change * @protected */ protected async setMapView(): Promise { - this._mapInfo = this.getMapInfo(this._mapChange.id); - this._mapView = this._mapChange.mapView; - this.initMapZoom(); - this._mapView.popupEnabled = false; + this.mapView.popupEnabled = false; if (this._defaultCenter && this._defaultLevel) { - await this._mapView.goTo({ + await this.mapView.goTo({ center: this._defaultCenter, zoom: this._defaultLevel }); @@ -550,22 +483,6 @@ export class CrowdsourceReporter { } } - /** - * Add/remove zoom tools based on enableZoom prop - * @protected - */ - protected initMapZoom(): void { - if (!this.enableZoom) { - this._mapView.ui.remove("zoom"); - } else if (this.enableZoom) { - this._mapView.ui.add({ - component: "zoom", - position: "top-left", - index: 0 - }); - } - } - /** * Fetches the component's translations * @returns Promise when complete diff --git a/src/components/crowdsource-reporter/readme.md b/src/components/crowdsource-reporter/readme.md index ad50893ce..777a6742f 100644 --- a/src/components/crowdsource-reporter/readme.md +++ b/src/components/crowdsource-reporter/readme.md @@ -7,27 +7,28 @@ ## Properties -| Property | Attribute | Description | Type | Default | -| ------------------------- | --------------------------- | ------------------------------------------------------------------------------------- | ---------------------- | ----------- | -| `defaultWebmap` | `default-webmap` | string: Item ID of the web map that should be selected by default | `string` | `""` | -| `description` | `description` | string: The text that will display under the title on the landing page | `string` | `undefined` | -| `enableAnonymousAccess` | `enable-anonymous-access` | boolean: When true the anonymous users will be allowed to submit reports and comments | `boolean` | `undefined` | -| `enableAnonymousComments` | `enable-anonymous-comments` | boolean: When true the anonymous users will be allowed to submit comments | `boolean` | `undefined` | -| `enableComments` | `enable-comments` | boolean: When true the user will be allowed to submit comments | `boolean` | `undefined` | -| `enableHome` | `enable-home` | boolean: when true the home widget will be available | `boolean` | `true` | -| `enableLogin` | `enable-login` | boolean: When true the user will be provided a login page | `boolean` | `undefined` | -| `enableNewReports` | `enable-new-reports` | boolean: When true the user will be allowed to submit new reports | `boolean` | `undefined` | -| `enableSearch` | `enable-search` | boolean: when true the search widget will be available | `boolean` | `true` | -| `enableZoom` | `enable-zoom` | boolean: when true the zoom widget will be available | `boolean` | `true` | -| `layers` | -- | string[]: list of layer ids | `string[]` | `undefined` | -| `loginTitle` | `login-title` | string: The text that will display at the top of the landing page | `string` | `undefined` | -| `mapInfos` | -- | IMapInfo[]: array of map infos (name and id) | `IMapInfo[]` | `[]` | -| `reportButtonText` | `report-button-text` | string: The word(s) to display in the reports submit button | `string` | `undefined` | -| `reportSubmittedMessage` | `report-submitted-message` | string: The message to display when the report has been submitted | `string` | `undefined` | -| `reportsHeader` | `reports-header` | string: The word(s) to display in the reports header | `string` | `undefined` | -| `searchConfiguration` | -- | ISearchConfiguration: Configuration details for the Search widget | `ISearchConfiguration` | `undefined` | -| `showComments` | `show-comments` | boolean: When true the comments from all users will be visible | `boolean` | `undefined` | -| `theme` | `theme` | theme: "light" \| "dark" theme to be used | `"dark" \| "light"` | `"light"` | +| Property | Attribute | Description | Type | Default | +| ------------------------- | --------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------- | ----------- | +| `defaultWebmap` | `default-webmap` | string: Item ID of the web map that should be selected by default | `string` | `""` | +| `description` | `description` | string: The text that will display under the title on the landing page | `string` | `undefined` | +| `enableAnonymousAccess` | `enable-anonymous-access` | boolean: When true the anonymous users will be allowed to submit reports and comments | `boolean` | `undefined` | +| `enableAnonymousComments` | `enable-anonymous-comments` | boolean: When true the anonymous users will be allowed to submit comments | `boolean` | `undefined` | +| `enableComments` | `enable-comments` | boolean: When true the user will be allowed to submit comments | `boolean` | `undefined` | +| `enableHome` | `enable-home` | boolean: when true the home widget will be available | `boolean` | `true` | +| `enableLogin` | `enable-login` | boolean: When true the user will be provided a login page | `boolean` | `undefined` | +| `enableNewReports` | `enable-new-reports` | boolean: When true the user will be allowed to submit new reports | `boolean` | `undefined` | +| `enableSearch` | `enable-search` | boolean: when true the search widget will be available | `boolean` | `true` | +| `enableZoom` | `enable-zoom` | boolean: when true the zoom widget will be available | `boolean` | `true` | +| `layers` | -- | string[]: list of layer ids | `string[]` | `undefined` | +| `loginTitle` | `login-title` | string: The text that will display at the top of the landing page | `string` | `undefined` | +| `mapInfos` | -- | IMapInfo[]: array of map infos (name and id) | `IMapInfo[]` | `[]` | +| `mapView` | -- | esri/views/MapView: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html | `MapView` | `undefined` | +| `reportButtonText` | `report-button-text` | string: The word(s) to display in the reports submit button | `string` | `undefined` | +| `reportSubmittedMessage` | `report-submitted-message` | string: The message to display when the report has been submitted | `string` | `undefined` | +| `reportsHeader` | `reports-header` | string: The word(s) to display in the reports header | `string` | `undefined` | +| `searchConfiguration` | -- | ISearchConfiguration: Configuration details for the Search widget | `ISearchConfiguration` | `undefined` | +| `showComments` | `show-comments` | boolean: When true the comments from all users will be visible | `boolean` | `undefined` | +| `theme` | `theme` | theme: "light" \| "dark" theme to be used | `"dark" \| "light"` | `"light"` | ## Dependencies @@ -35,7 +36,6 @@ ### Depends on - calcite-shell -- calcite-notice - calcite-panel - calcite-flow - calcite-loader @@ -45,13 +45,11 @@ - [layer-list](../layer-list) - [feature-list](../feature-list) - [info-card](../info-card) -- [map-card](../map-card) ### Graph ```mermaid graph TD; crowdsource-reporter --> calcite-shell - crowdsource-reporter --> calcite-notice crowdsource-reporter --> calcite-panel crowdsource-reporter --> calcite-flow crowdsource-reporter --> calcite-loader @@ -61,8 +59,6 @@ graph TD; crowdsource-reporter --> layer-list crowdsource-reporter --> feature-list crowdsource-reporter --> info-card - crowdsource-reporter --> map-card - calcite-notice --> calcite-icon calcite-panel --> calcite-action calcite-panel --> calcite-action-menu calcite-panel --> calcite-scrim @@ -82,6 +78,7 @@ graph TD; layer-list --> calcite-list layer-list --> calcite-list-item layer-list --> calcite-icon + calcite-notice --> calcite-icon calcite-list --> calcite-scrim calcite-list --> calcite-stack calcite-list --> calcite-filter @@ -119,24 +116,6 @@ graph TD; calcite-alert --> calcite-icon calcite-alert --> calcite-chip calcite-chip --> calcite-icon - map-card --> map-picker - map-card --> map-tools - map-picker --> calcite-button - map-picker --> calcite-tooltip - map-picker --> calcite-action-bar - map-picker --> calcite-list - map-picker --> calcite-list-item - calcite-action-bar --> calcite-action-group - calcite-action-group --> calcite-action-menu - calcite-action-group --> calcite-action - map-tools --> basemap-gallery - map-tools --> map-search - map-tools --> map-legend - map-tools --> map-fullscreen - map-tools --> floor-filter - map-tools --> calcite-action - map-tools --> calcite-icon - map-tools --> calcite-tooltip style crowdsource-reporter fill:#f9f,stroke:#333,stroke-width:4px ``` diff --git a/src/components/map-card/readme.md b/src/components/map-card/readme.md index 97fda650d..02af7cb89 100644 --- a/src/components/map-card/readme.md +++ b/src/components/map-card/readme.md @@ -45,7 +45,6 @@ ### Used by - [crowdsource-manager](../crowdsource-manager) - - [crowdsource-reporter](../crowdsource-reporter) ### Depends on @@ -93,7 +92,6 @@ graph TD; map-tools --> calcite-icon map-tools --> calcite-tooltip crowdsource-manager --> map-card - crowdsource-reporter --> map-card style map-card fill:#f9f,stroke:#333,stroke-width:4px ``` diff --git a/src/demos/crowdsource-reporter.html b/src/demos/crowdsource-reporter.html index 1afa7d54c..c2eb4fc8c 100644 --- a/src/demos/crowdsource-reporter.html +++ b/src/demos/crowdsource-reporter.html @@ -22,9 +22,34 @@ | limitations under the License. --> @@ -37,64 +62,90 @@ - - + +
+ From d3e874d5cfb3c59e5810de8e1366d9071e184503 Mon Sep 17 00:00:00 2001 From: John Hauck Date: Wed, 17 Jan 2024 13:10:53 -0700 Subject: [PATCH 2/3] add isMobile prop --- src/components.d.ts | 8 +++ .../crowdsource-reporter.css | 27 -------- .../crowdsource-reporter.tsx | 68 ++++++++----------- src/components/crowdsource-reporter/readme.md | 1 + 4 files changed, 39 insertions(+), 65 deletions(-) diff --git a/src/components.d.ts b/src/components.d.ts index a4550f9a1..a066aaf63 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -241,6 +241,10 @@ export namespace Components { * boolean: when true the zoom widget will be available */ "enableZoom": boolean; + /** + * boolean: When true the application will be in mobile mode, controls the mobile or desktop view + */ + "isMobile": boolean; /** * string[]: list of layer ids */ @@ -2210,6 +2214,10 @@ declare namespace LocalJSX { * boolean: when true the zoom widget will be available */ "enableZoom"?: boolean; + /** + * boolean: When true the application will be in mobile mode, controls the mobile or desktop view + */ + "isMobile"?: boolean; /** * string[]: list of layer ids */ diff --git a/src/components/crowdsource-reporter/crowdsource-reporter.css b/src/components/crowdsource-reporter/crowdsource-reporter.css index 72e3a2463..da65e6c5e 100644 --- a/src/components/crowdsource-reporter/crowdsource-reporter.css +++ b/src/components/crowdsource-reporter/crowdsource-reporter.css @@ -63,30 +63,3 @@ .error-msg{ padding: 10px; } - -@media screen and (max-width: 600px) { - .map-container { - left: 0; - height: 50%; - width: 100%; - } - - .map-container-mobile { - height: calc(100% - 100px); - } - - .side-panel { - padding: 2px; - width: 100%; - height: 50%; - position: absolute; - top: 50%; - left: 0; - z-index: 60; - } - - .collapsed-side-panel { - top: calc(100% - 100px); - height: 100px; - } -} diff --git a/src/components/crowdsource-reporter/crowdsource-reporter.tsx b/src/components/crowdsource-reporter/crowdsource-reporter.tsx index a984f2790..b4a960943 100644 --- a/src/components/crowdsource-reporter/crowdsource-reporter.tsx +++ b/src/components/crowdsource-reporter/crowdsource-reporter.tsx @@ -44,6 +44,11 @@ export class CrowdsourceReporter { */ @Prop() description: string; + /** + * boolean: When true the application will be in mobile mode, controls the mobile or desktop view + */ + @Prop() isMobile: boolean; + /** * boolean: When true the anonymous users will be allowed to submit reports and comments */ @@ -150,11 +155,6 @@ export class CrowdsourceReporter { */ @State() _mapInfo: IMapInfo; - /** - * boolean: When true the application will be in mobile mode, controls the mobile or desktop view - */ - @State() _isMobile = false; - /** * string[]: Reporter flow items list */ @@ -217,6 +217,16 @@ export class CrowdsourceReporter { // //-------------------------------------------------------------------------- + /** + * Called each time the mapView prop is changed. + */ + @Watch("isMobile") + async isMobileWatchHandler(): Promise { + if (this.isMobile) { + this._sidePanelCollapsed = false; + } + } + /** * Called each time the mapView prop is changed. */ @@ -252,36 +262,18 @@ export class CrowdsourceReporter { */ async componentWillLoad(): Promise { await this._getTranslations(); - const mediaQueryList = window.matchMedia("screen and (max-width: 600px)"); - this._isMobile = mediaQueryList.matches; - //on change update the state for is mobile and the sidePanelCollapsed - mediaQueryList.onchange = (e) => { - this._isMobile = e.matches; - this._sidePanelCollapsed = false; - } } /** * Renders the component. */ render() { - // const validConfiguration = true; - //Check if webMap id is configured - // if(!this.mapInfos || this.mapInfos.length<=0 || (this.mapInfos?.length>0 && !this.mapInfos[0]?.id)){ - // validConfiguration = false - // } return (
{this._getReporter()} - {/* {!validConfiguration && - -
{this._translations.error}
-
{ this._translations.invalidConfigurationErrorMsg}
-
- } */}
); @@ -315,7 +307,7 @@ export class CrowdsourceReporter { }); let sidePanelClass = "side-panel"; //in case of mobile handle for collapsed styles of the panel - if (this._isMobile && this._sidePanelCollapsed) { + if (this.isMobile && this._sidePanelCollapsed) { sidePanelClass += " collapsed-side-panel"; } const themeClass = this.theme === "dark" ? "calcite-mode-dark" : "calcite-mode-light"; @@ -337,12 +329,12 @@ export class CrowdsourceReporter { */ protected getLayerListFlowItem(): Node { return ( - - {this._hasValidLayers && } - {this._hasValidLayers && } - {this._isMobile && this.getActionToExpandCollapsePanel()} + + {this._hasValidLayers && } + {this._hasValidLayers && } + {this.isMobile && this.getActionToExpandCollapsePanel()} {this._hasValidLayers && this.enableNewReports && {this.reportButtonText} } @@ -412,12 +404,12 @@ export class CrowdsourceReporter { */ protected getFeatureListFlowItem(layerId: string, layerName: string): Node { return ( - - - - {this._isMobile && this.getActionToExpandCollapsePanel()} + + + + {this.isMobile && this.getActionToExpandCollapsePanel()} {this.enableNewReports && {this.reportButtonText} } @@ -440,8 +432,8 @@ export class CrowdsourceReporter { */ protected getFeatureDetailsFlowItem(): Node { return ( - - {this._isMobile && this.getActionToExpandCollapsePanel()} + + {this.isMobile && this.getActionToExpandCollapsePanel()} Date: Wed, 17 Jan 2024 14:18:07 -0700 Subject: [PATCH 3/3] css update --- .../crowdsource-reporter/crowdsource-reporter.css | 9 +++++++-- .../crowdsource-reporter/crowdsource-reporter.tsx | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/crowdsource-reporter/crowdsource-reporter.css b/src/components/crowdsource-reporter/crowdsource-reporter.css index da65e6c5e..bce60a699 100644 --- a/src/components/crowdsource-reporter/crowdsource-reporter.css +++ b/src/components/crowdsource-reporter/crowdsource-reporter.css @@ -21,7 +21,7 @@ } .width-full { - width: 100%; + width: 100% !important; } .width-0 { @@ -29,7 +29,7 @@ } .height-full { - height: 100%; + height: 100% !important; } .height-0 { @@ -63,3 +63,8 @@ .error-msg{ padding: 10px; } + +.collapsed-side-panel { + top: calc(100% - 55px); + height: 54px; +} diff --git a/src/components/crowdsource-reporter/crowdsource-reporter.tsx b/src/components/crowdsource-reporter/crowdsource-reporter.tsx index b4a960943..eff4b6d78 100644 --- a/src/components/crowdsource-reporter/crowdsource-reporter.tsx +++ b/src/components/crowdsource-reporter/crowdsource-reporter.tsx @@ -312,7 +312,7 @@ export class CrowdsourceReporter { } const themeClass = this.theme === "dark" ? "calcite-mode-dark" : "calcite-mode-light"; return ( - + {this.mapView ? {renderLists?.length > 0 && renderLists}