Skip to content

Commit 1d9fcd3

Browse files
committed
Update index.tsx
1 parent 27baead commit 1d9fcd3

File tree

1 file changed

+35
-34
lines changed
  • samples/maps/geo-map/display-azure-imagery/src

1 file changed

+35
-34
lines changed

samples/maps/geo-map/display-azure-imagery/src/index.tsx

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,8 @@ import { MapUtils, MapRegion } from './MapUtils';
1616
IgrGeographicMapModule.register();
1717
IgrDataChartInteractivityModule.register();
1818

19-
const mapStyles: Record<string, { placeholder: string; azureStyle: AzureMapsImageryStyle }> = {
20-
Satellite: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_satellite.png", azureStyle: AzureMapsImageryStyle.Satellite },
21-
Road: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_road.png", azureStyle: AzureMapsImageryStyle.Road },
22-
DarkGrey: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_darkgrey.png", azureStyle: AzureMapsImageryStyle.DarkGrey },
23-
TerraOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_terra_overlay.png", azureStyle: AzureMapsImageryStyle.TerraOverlay },
24-
HybridRoadOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/AzureHybridRoad.png", azureStyle: AzureMapsImageryStyle.HybridRoadOverlay },
25-
HybridDarkGreyOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_hybriddarkgrey.png", azureStyle: AzureMapsImageryStyle.HybridDarkGreyOverlay },
26-
LabelsRoadOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_labelsroad.png", azureStyle: AzureMapsImageryStyle.LabelsRoadOverlay },
27-
LabelsDarkGreyOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_labelsdarkgrey.png", azureStyle: AzureMapsImageryStyle.LabelsDarkGreyOverlay },
28-
TrafficDelayOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_trafficdelay.png", azureStyle: AzureMapsImageryStyle.TrafficDelayOverlay },
29-
TrafficAbsoluteOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_absolute.png", azureStyle: AzureMapsImageryStyle.TrafficAbsoluteOverlay },
30-
TrafficReducedOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_light.png", azureStyle: AzureMapsImageryStyle.TrafficReducedOverlay },
31-
TrafficRelativeOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_relative.png", azureStyle: AzureMapsImageryStyle.TrafficRelativeDarkOverlay },
32-
WeatherInfraredOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_weather_Infrared_road.png", azureStyle: AzureMapsImageryStyle.WeatherInfraredOverlay },
33-
WeatherRadarOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_weather_radar.png", azureStyle: AzureMapsImageryStyle.WeatherRadarOverlay }
34-
};
35-
36-
const trafficWeatherStyles = [
37-
AzureMapsImageryStyle.TrafficDelayOverlay,
38-
AzureMapsImageryStyle.TrafficAbsoluteOverlay,
39-
AzureMapsImageryStyle.TrafficReducedOverlay,
40-
AzureMapsImageryStyle.TrafficRelativeDarkOverlay,
41-
AzureMapsImageryStyle.WeatherInfraredOverlay,
42-
AzureMapsImageryStyle.WeatherRadarOverlay
43-
];
44-
4519
export default class MapDisplayImageryAzure extends React.Component<any, any> {
46-
private geoMap?: IgrGeographicMap;
47-
private dialogRef?: IgrDialog;
48-
20+
4921
constructor(props: any) {
5022
super(props);
5123
this.state = { apiKey: "", styleName: "Satellite", mapVisible: false };
@@ -64,15 +36,15 @@ export default class MapDisplayImageryAzure extends React.Component<any, any> {
6436
}
6537

6638
render(): JSX.Element {
67-
const currentStyle = mapStyles[this.state.styleName];
39+
const currentStyle = this.mapStyles[this.state.styleName];
6840

6941
return (
7042
<div style={{ display: "flex", flexDirection: "column", height: "100vh", width: "100%" }}>
7143
{/* Controls */}
7244
<div style={{ flex: "0 0 auto", display: "flex", gap: "12px", alignItems: "center", justifyContent: "center", padding: "12px", zIndex: 2 }}>
7345
<IgrButton variant="contained" onClick={this.onDialogShow}>Enter Azure Maps API Key</IgrButton>
7446
<IgrSelect value={this.state.styleName} onChange={this.onStyleChange} style={{ minWidth: "220px" }}>
75-
{Object.keys(mapStyles).map(key => (
47+
{Object.keys(this.mapStyles).map(key => (
7648
<IgrSelectItem key={key} value={key}>{key}</IgrSelectItem>
7749
))}
7850
</IgrSelect>
@@ -111,6 +83,18 @@ export default class MapDisplayImageryAzure extends React.Component<any, any> {
11183
);
11284
}
11385

86+
private geoMap?: IgrGeographicMap;
87+
private dialogRef?: IgrDialog;
88+
89+
private trafficWeatherStyles = [
90+
AzureMapsImageryStyle.TrafficDelayOverlay,
91+
AzureMapsImageryStyle.TrafficAbsoluteOverlay,
92+
AzureMapsImageryStyle.TrafficReducedOverlay,
93+
AzureMapsImageryStyle.TrafficRelativeDarkOverlay,
94+
AzureMapsImageryStyle.WeatherInfraredOverlay,
95+
AzureMapsImageryStyle.WeatherRadarOverlay
96+
];
97+
11498
private onDialogRef(dialog: IgrDialog) { this.dialogRef = dialog; }
11599
private onDialogShow() { this.dialogRef?.show(); }
116100
private onDialogHide() { this.dialogRef?.hide(); }
@@ -119,14 +103,14 @@ export default class MapDisplayImageryAzure extends React.Component<any, any> {
119103

120104
private onApplyKey() {
121105
if (!this.state.apiKey) { this.onDialogHide(); return; }
122-
this.setState({ mapVisible: true }, () => this.updateAzureMap(mapStyles[this.state.styleName].azureStyle));
106+
this.setState({ mapVisible: true }, () => this.updateAzureMap(this.mapStyles[this.state.styleName].azureStyle));
123107
this.onDialogHide();
124108
}
125109

126110
private onStyleChange(e: CustomEvent) {
127111
const selected = e.detail.value as string;
128112
this.setState({ styleName: selected }, () => {
129-
if (this.state.apiKey) this.updateAzureMap(mapStyles[selected].azureStyle);
113+
if (this.state.apiKey) this.updateAzureMap(this.mapStyles[selected].azureStyle);
130114
});
131115
}
132116

@@ -140,7 +124,7 @@ export default class MapDisplayImageryAzure extends React.Component<any, any> {
140124
const series = new IgrGeographicTileSeries({ name: "AzureTileSeries", tileImagery: tileSource });
141125
series.tileImagery = tileSource;
142126

143-
if (trafficWeatherStyles.includes(style)) {
127+
if (this.trafficWeatherStyles.includes(style)) {
144128
const bg = new IgrAzureMapsImagery();
145129
bg.apiKey = this.state.apiKey;
146130
bg.imageryStyle = AzureMapsImageryStyle.DarkGrey;
@@ -173,6 +157,23 @@ export default class MapDisplayImageryAzure extends React.Component<any, any> {
173157
MapUtils.navigateTo(this.geoMap, MapRegion.UnitedStates);
174158
}
175159
}
160+
161+
private mapStyles: Record<string, { placeholder: string; azureStyle: AzureMapsImageryStyle }> = {
162+
Satellite: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_satellite.png", azureStyle: AzureMapsImageryStyle.Satellite },
163+
Road: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_road.png", azureStyle: AzureMapsImageryStyle.Road },
164+
DarkGrey: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_darkgrey.png", azureStyle: AzureMapsImageryStyle.DarkGrey },
165+
TerraOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_terra_overlay.png", azureStyle: AzureMapsImageryStyle.TerraOverlay },
166+
HybridRoadOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/AzureHybridRoad.png", azureStyle: AzureMapsImageryStyle.HybridRoadOverlay },
167+
HybridDarkGreyOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_hybriddarkgrey.png", azureStyle: AzureMapsImageryStyle.HybridDarkGreyOverlay },
168+
LabelsRoadOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_labelsroad.png", azureStyle: AzureMapsImageryStyle.LabelsRoadOverlay },
169+
LabelsDarkGreyOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_labelsdarkgrey.png", azureStyle: AzureMapsImageryStyle.LabelsDarkGreyOverlay },
170+
TrafficDelayOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_trafficdelay.png", azureStyle: AzureMapsImageryStyle.TrafficDelayOverlay },
171+
TrafficAbsoluteOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_absolute.png", azureStyle: AzureMapsImageryStyle.TrafficAbsoluteOverlay },
172+
TrafficReducedOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_light.png", azureStyle: AzureMapsImageryStyle.TrafficReducedOverlay },
173+
TrafficRelativeOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_relative.png", azureStyle: AzureMapsImageryStyle.TrafficRelativeDarkOverlay },
174+
WeatherInfraredOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_weather_Infrared_road.png", azureStyle: AzureMapsImageryStyle.WeatherInfraredOverlay },
175+
WeatherRadarOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_weather_radar.png", azureStyle: AzureMapsImageryStyle.WeatherRadarOverlay }
176+
};
176177
}
177178

178179
// rendering above class to the React DOM

0 commit comments

Comments
 (0)