Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 82 additions & 174 deletions samples/maps/geo-map/display-azure-imagery/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,13 @@ import {
import { IgrButton, IgrDialog, IgrInput, IgrSelect, IgrSelectItem } from "igniteui-react";
import { IgrDataChartInteractivityModule } from "igniteui-react-charts";
import "igniteui-webcomponents/themes/light/bootstrap.css";
import { MapUtils, MapRegion } from './MapUtils';

IgrGeographicMapModule.register();
IgrDataChartInteractivityModule.register();

enum MapRegion { UnitedStates }

class MapUtils {
public static navigateTo(geoMap: IgrGeographicMap | undefined, region: MapRegion) {
if (!geoMap) return;
if (region === MapRegion.UnitedStates)
geoMap.zoomToGeographic({ left: -125, top: 50, width: 60, height: 25 });
}

public static zoomToNYC(geoMap: IgrGeographicMap | undefined) {
if (!geoMap) return;
geoMap.zoomToGeographic({ left: -74.2591, top: 40.9176, width: -73.7004 - (-74.2591), height: 40.4774 - 40.9176 });
}
}

const placeholderImages: Record<string, string> = {
Satellite: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_satellite.png",
Road: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_road.png",
DarkGrey: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_darkgrey.png",
TerraOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_terra_overlay.png",
HybridRoadOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/AzureHybridRoad.png",
HybridDarkGreyOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_hybriddarkgrey.png",
LabelsRoadOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_labelsroad.png",
LabelsDarkGreyOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_labelsdarkgrey.png",
TrafficDelayOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_trafficdelay.png",
TrafficAbsoluteOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_absolute.png",
TrafficReducedOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_light.png",
TrafficRelativeOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_relative.png",
WeatherInfraredOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_weather_Infrared_road.png",
WeatherRadarOverlay: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_weather_radar.png"
};

const trafficWeatherStyles = [
AzureMapsImageryStyle.TrafficDelayOverlay,
AzureMapsImageryStyle.TrafficAbsoluteOverlay,
AzureMapsImageryStyle.TrafficReducedOverlay,
AzureMapsImageryStyle.TrafficRelativeDarkOverlay,
AzureMapsImageryStyle.WeatherInfraredOverlay,
AzureMapsImageryStyle.WeatherRadarOverlay
];

export default class MapDisplayImageryAzure extends React.Component<any, any> {
private geoMap?: IgrGeographicMap;
private dialogRef?: IgrDialog;


constructor(props: any) {
super(props);
this.state = { apiKey: "", styleName: "Satellite", mapVisible: false };
Expand All @@ -73,114 +31,69 @@ export default class MapDisplayImageryAzure extends React.Component<any, any> {
this.onStyleChange = this.onStyleChange.bind(this);
}

render(): JSX.Element {
return (
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: "16px",
width: "100%",
padding: "16px",
boxSizing: "border-box"
}}
>
{/* Controls panel */}
<div
style={{
display: "flex",
gap: "12px",
alignItems: "center",
justifyContent: "center",
flexWrap: "wrap"
}}
>
<IgrButton variant="contained" onClick={this.onDialogShow}>
Enter Azure Maps API Key
</IgrButton>

<IgrSelect
value={this.state.styleName}
onChange={this.onStyleChange}
style={{ minWidth: "220px" }}
>
{Object.keys(placeholderImages).map((key) => (
<IgrSelectItem key={key} value={key}>
{key}
</IgrSelectItem>
))}
</IgrSelect>
</div>
componentDidMount() {
this.onDialogShow(); // open dialog on startup
}

{/* Placeholder image */}
{!this.state.mapVisible && (
<div
style={{
width: "640px",
height: "480px",
display: "flex",
justifyContent: "center",
alignItems: "center",
border: "1px solid #ccc",
borderRadius: "6px",
overflow: "hidden",
boxShadow: "0 2px 6px rgba(0,0,0,0.2)"
}}
>
<img
src={placeholderImages[this.state.styleName]}
alt={this.state.styleName}
style={{ width: "100%", height: "100%", objectFit: "cover" }}
/>
render(): JSX.Element {
const currentStyle = this.mapStyles[this.state.styleName];

return (
<div style={{ display: "flex", flexDirection: "column", height: "100vh", width: "100%" }}>
{/* Controls */}
<div style={{ flex: "0 0 auto", display: "flex", gap: "12px", alignItems: "center", justifyContent: "center", padding: "12px", zIndex: 2 }}>
<IgrButton variant="contained" onClick={this.onDialogShow}>Enter Azure Maps API Key</IgrButton>
<IgrSelect value={this.state.styleName} onChange={this.onStyleChange} style={{ minWidth: "220px" }}>
{Object.keys(this.mapStyles).map(key => (
<IgrSelectItem key={key} value={key}>{key}</IgrSelectItem>
))}
</IgrSelect>
</div>
)}

{/* Map container */}
<div
style={{
{/* Image or map */}
<div style={{
width: "100%",
maxWidth: "100%",
height: "1000px",
overflow: "hidden",
display: this.state.mapVisible ? "block" : "none"
}}
>
<IgrGeographicMap
ref={(r) => (this.geoMap = r!)}
width="100%"
height="100%"
zoomable={true}
/>
maxWidth: "960px",
aspectRatio: "4 / 3",
margin: "0 auto",
position: "relative",
overflow: "hidden"
}}>
{!this.state.mapVisible ? (
<img src={currentStyle.placeholder} alt={this.state.styleName} style={{ width: "100%", height: "100%", objectFit: "cover" }} />
) : (
<IgrGeographicMap ref={r => this.geoMap = r!} width="100%" height="100%" zoomable={true} />
)}
</div>

{/* Dialog */}
<IgrDialog title="Azure Key" ref={this.onDialogRef} className="igr-dialog">
<IgrInput
label="An image will remain visible when no key is entered."
value={this.state.apiKey}
inputMode="text"
onInput={this.onApiKeyChange}
/>
<div slot="footer" style={{ display: "flex", justifyContent: "flex-end", gap: "8px" }}>
<IgrButton variant="flat" onClick={this.onResetKey}>Clear</IgrButton>
<IgrButton variant="flat" onClick={this.onApplyKey}>Submit</IgrButton>
</div>
</IgrDialog>
</div>
);
}

{/* Dialog for API key */}
<IgrDialog title="Azure Key" ref={this.onDialogRef}>
<IgrInput
label="Azure Key"
value={this.state.apiKey}
inputMode="text"
onInput={this.onApiKeyChange}
/>
<div
slot="footer"
style={{
display: "flex",
justifyContent: "flex-end",
gap: "8px"
}}
>
<IgrButton variant="flat" onClick={this.onResetKey}>
Reset
</IgrButton>
<IgrButton variant="flat" onClick={this.onApplyKey}>
Submit
</IgrButton>
</div>
</IgrDialog>
</div>
);
}
private geoMap?: IgrGeographicMap;
private dialogRef?: IgrDialog;

private trafficWeatherStyles = [
AzureMapsImageryStyle.TrafficDelayOverlay,
AzureMapsImageryStyle.TrafficAbsoluteOverlay,
AzureMapsImageryStyle.TrafficReducedOverlay,
AzureMapsImageryStyle.TrafficRelativeDarkOverlay,
AzureMapsImageryStyle.WeatherInfraredOverlay,
AzureMapsImageryStyle.WeatherRadarOverlay
];

private onDialogRef(dialog: IgrDialog) { this.dialogRef = dialog; }
private onDialogShow() { this.dialogRef?.show(); }
Expand All @@ -190,37 +103,17 @@ export default class MapDisplayImageryAzure extends React.Component<any, any> {

private onApplyKey() {
if (!this.state.apiKey) { this.onDialogHide(); return; }
this.setState({ mapVisible: true }, () => this.updateAzureMap(this.mapStyleFromName(this.state.styleName)));
this.setState({ mapVisible: true }, () => this.updateAzureMap(this.mapStyles[this.state.styleName].azureStyle));
this.onDialogHide();
}

private onStyleChange(e: CustomEvent) {
const selected = e.detail.value as string;
this.setState({ styleName: selected }, () => {
if (this.state.apiKey) this.updateAzureMap(this.mapStyleFromName(selected));
if (this.state.apiKey) this.updateAzureMap(this.mapStyles[selected].azureStyle);
});
}

private mapStyleFromName(name: string): AzureMapsImageryStyle {
switch (name) {
case "Satellite": return AzureMapsImageryStyle.Satellite;
case "Road": return AzureMapsImageryStyle.Road;
case "DarkGrey": return AzureMapsImageryStyle.DarkGrey;
case "TerraOverlay": return AzureMapsImageryStyle.TerraOverlay;
case "HybridRoadOverlay": return AzureMapsImageryStyle.HybridRoadOverlay;
case "HybridDarkGreyOverlay": return AzureMapsImageryStyle.HybridDarkGreyOverlay;
case "LabelsRoadOverlay": return AzureMapsImageryStyle.LabelsRoadOverlay;
case "LabelsDarkGreyOverlay": return AzureMapsImageryStyle.LabelsDarkGreyOverlay;
case "TrafficDelayOverlay": return AzureMapsImageryStyle.TrafficDelayOverlay;
case "TrafficAbsoluteOverlay": return AzureMapsImageryStyle.TrafficAbsoluteOverlay;
case "TrafficReducedOverlay": return AzureMapsImageryStyle.TrafficReducedOverlay;
case "TrafficRelativeOverlay": return AzureMapsImageryStyle.TrafficRelativeDarkOverlay;
case "WeatherInfraredOverlay": return AzureMapsImageryStyle.WeatherInfraredOverlay;
case "WeatherRadarOverlay": return AzureMapsImageryStyle.WeatherRadarOverlay;
default: return AzureMapsImageryStyle.Satellite;
}
}

private updateAzureMap(style: AzureMapsImageryStyle) {
if (!this.geoMap || !this.state.apiKey) return;

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

if (trafficWeatherStyles.includes(style)) {
if (this.trafficWeatherStyles.includes(style)) {
const bg = new IgrAzureMapsImagery();
bg.apiKey = this.state.apiKey;
bg.imageryStyle = AzureMapsImageryStyle.DarkGrey;
Expand All @@ -243,10 +136,9 @@ export default class MapDisplayImageryAzure extends React.Component<any, any> {
if (style === AzureMapsImageryStyle.WeatherInfraredOverlay || style === AzureMapsImageryStyle.WeatherRadarOverlay) {
MapUtils.navigateTo(this.geoMap, MapRegion.UnitedStates);
} else {
MapUtils.zoomToNYC(this.geoMap);
this.geoMap.zoomToGeographic({ left: -74.2591, top: 40.9176, width: -73.7004 - (-74.2591), height: 40.4774 - 40.9176 });
}
}
else if (style === AzureMapsImageryStyle.TerraOverlay) {
} else if (style === AzureMapsImageryStyle.TerraOverlay) {
const bg = new IgrAzureMapsImagery();
bg.apiKey = this.state.apiKey;
bg.imageryStyle = AzureMapsImageryStyle.Satellite;
Expand All @@ -255,8 +147,7 @@ export default class MapDisplayImageryAzure extends React.Component<any, any> {
tileSource.imageryStyle = style;
this.geoMap.series.add(series);
MapUtils.navigateTo(this.geoMap, MapRegion.UnitedStates);
}
else {
} else {
tileSource.imageryStyle = style;
this.geoMap.series.add(series);
const bg = new IgrAzureMapsImagery();
Expand All @@ -266,6 +157,23 @@ export default class MapDisplayImageryAzure extends React.Component<any, any> {
MapUtils.navigateTo(this.geoMap, MapRegion.UnitedStates);
}
}

private mapStyles: Record<string, { placeholder: string; azureStyle: AzureMapsImageryStyle }> = {
Satellite: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_satellite.png", azureStyle: AzureMapsImageryStyle.Satellite },
Road: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_road.png", azureStyle: AzureMapsImageryStyle.Road },
DarkGrey: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_darkgrey.png", azureStyle: AzureMapsImageryStyle.DarkGrey },
TerraOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_terra_overlay.png", azureStyle: AzureMapsImageryStyle.TerraOverlay },
HybridRoadOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/AzureHybridRoad.png", azureStyle: AzureMapsImageryStyle.HybridRoadOverlay },
HybridDarkGreyOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_hybriddarkgrey.png", azureStyle: AzureMapsImageryStyle.HybridDarkGreyOverlay },
LabelsRoadOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_labelsroad.png", azureStyle: AzureMapsImageryStyle.LabelsRoadOverlay },
LabelsDarkGreyOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_labelsdarkgrey.png", azureStyle: AzureMapsImageryStyle.LabelsDarkGreyOverlay },
TrafficDelayOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_trafficdelay.png", azureStyle: AzureMapsImageryStyle.TrafficDelayOverlay },
TrafficAbsoluteOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_absolute.png", azureStyle: AzureMapsImageryStyle.TrafficAbsoluteOverlay },
TrafficReducedOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_light.png", azureStyle: AzureMapsImageryStyle.TrafficReducedOverlay },
TrafficRelativeOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_traffic_relative.png", azureStyle: AzureMapsImageryStyle.TrafficRelativeDarkOverlay },
WeatherInfraredOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_weather_Infrared_road.png", azureStyle: AzureMapsImageryStyle.WeatherInfraredOverlay },
WeatherRadarOverlay: { placeholder: "https://static.infragistics.com/xplatform/images/browsers/azure-maps/azure_weather_radar.png", azureStyle: AzureMapsImageryStyle.WeatherRadarOverlay }
};
}

// rendering above class to the React DOM
Expand Down
Loading