主要是用来优化if的
if (this.mapHighlightInfo.highlightType == "instant-river") {
let highInfo: InstantRiverHighlightInfo = <InstantRiverHighlightInfo>this.mapHighlightInfo;
if (highInfo.subHighlightInfo.subType == "instant-river-sensor-station") {
this.labelPoints = highInfo.subHighlightInfo.relatedSensorReports.map(report => {
return {
lat: report.lat,
lng: report.lng,
properties: <InstantWaterReport>report
}
});
}else if (highInfo.subHighlightInfo.subType == "instant-river-primary-sensor-stations" || highInfo.subHighlightInfo.subType == "instant-river-grade") {
this.labelPoints = highInfo.subHighlightInfo.sensorReports.map(report => {
return {
lat: report.lat,
lng: report.lng,
properties: <InstantWaterReport>report
}
});
}
} else if (this.mapHighlightInfo.highlightType == "weekly-river") {
let highInfo: WeeklyRiverHighlightInfo = <WeeklyRiverHighlightInfo>this.mapHighlightInfo;
if (highInfo.subHighlightInfo.subType == "weekly-river-sensor-station") {
this.labelPoints = highInfo.subHighlightInfo.relatedSensorReports.map(report => {
return {
lat: report.lat,
lng: report.lng,
properties: <InstantWaterReport>report
}
});
}else if (highInfo.subHighlightInfo.subType == "weekly-river-primary-sensor-stations" || highInfo.subHighlightInfo.subType == "weekly-river-grade") {
this.labelPoints = highInfo.subHighlightInfo.sensorReports.map(report => {
return {
lat: report.lat,
lng: report.lng,
properties: <InstantWaterReport>report
}
});
}
} else if (this.mapHighlightInfo.highlightType == "lake-river") {
let highInfo: LakeRiverHighlightInfo = <LakeRiverHighlightInfo>this.mapHighlightInfo;
if (highInfo.subHighlightInfo.subType == "lake-river-sensor-station") {
this.labelPoints = highInfo.subHighlightInfo.relatedSensorReports.map(report => {
return {
lat: report.lat,
lng: report.lng,
properties: <InstantWaterReport>report
}
});
}else if (highInfo.subHighlightInfo.subType == "lake-river-primary-sensor-stations" || highInfo.subHighlightInfo.subType == "lake-river-grade") {
this.labelPoints = highInfo.subHighlightInfo.sensorReports.map(report => {
return {
lat: report.lat,
lng: report.lng,
properties: <InstantWaterReport>report
}
});
}
} else if (this.mapHighlightInfo.highlightType == "drinking-river") {
let highInfo: DrinkingRiverHighlightInfo = <DrinkingRiverHighlightInfo>this.mapHighlightInfo;
if (highInfo.subHighlightInfo.subType == "drinking-river-sensor-station") {
this.labelPoints = highInfo.subHighlightInfo.relatedSensorReports.map(report => {
return {
lat: report.lat,
lng: report.lng,
properties: <InstantWaterReport>report
}
});
}else if (highInfo.subHighlightInfo.subType == "drinking-river-primary-sensor-stations" || highInfo.subHighlightInfo.subType == "drinking-river-grade") {
this.labelPoints = highInfo.subHighlightInfo.sensorReports.map(report => {
return {
lat: report.lat,
lng: report.lng,
properties: <InstantWaterReport>report
}
});
}
}
handles = [
{
type: "instant-river",
subType: "instant-river-sensor-station",
action: () => this.relatedSensorReportFuns()
},
{
type: "instant-river",
subType: "instant-river-primary-sensor-stations",
action: () => this.sensorReportFuns()
},
{
type: "instant-river",
subType: "instant-river-grade",
action: () => this.sensorReportFuns()
},
{
type: "weekly-river",
subType: "weekly-river-sensor-station",
action: () => this.relatedSensorReportFuns()
},
{
type: "weekly-river",
subType: "weekly-river-primary-sensor-stations",
action: () => this.sensorReportFuns()
},
{
type: "weekly-river",
subType: "weekly-river-grade",
action: () => this.sensorReportFuns()
},
{
type: "lake-river",
subType: "lake-river-sensor-station",
action: () => this.relatedSensorReportFuns()
},
{
type: "lake-river",
subType: "lake-river-primary-sensor-stations",
action: () => this.sensorReportFuns()
},
{
type: "lake-river",
subType: "lake-river-grade",
action: () => this.sensorReportFuns()
},
{
type: "drinking-river",
subType: "drinking-river-sensor-station",
action: () => this.relatedSensorReportFuns()
},
{
type: "drinking-river",
subType: "drinking-river-primary-sensor-stations",
action: () => this.sensorReportFuns()
},
{
type: "drinking-river",
subType: "drinking-river-grade",
action: () => this.sensorReportFuns()
}
];
匹配的代码
let type: string = this.mapHighlightInfo.highlightType;
let subType: string = this.mapHighlightInfo.subHighlightInfo.subType;
this.handles.forEach(h => {
if (h.type == type && h.subType == subType) {
h.action();
}
});