Mapa de polígono geográfico Angular
En el componente de mapa Angular, puede usar IgxGeographicShapeSeriesComponent
para mostrar datos geoespaciales usando polígonos de formas en un contexto geográfico. Este tipo de serie geográfica se utiliza a menudo para representar formas de países o regiones definidas por ubicaciones geográficas.
Angular Geographic Polygon Map Example
IgxGeographicShapeSeriesComponent
funciona de manera muy similar a IgxGeographicPolylineSeriesComponent
, excepto que los datos geoespaciales se representan con polígonos en lugar de polilíneas.
Data Requirements
Al igual que otros tipos de series geográficas en el control de mapa, el IgxGeographicShapeSeriesComponent
tiene la ItemsSource
propiedad que se puede enlazar a una matriz de objetos. Además, cada elemento de datos de este objeto debe tener una columna de datos que almacene una o varias formas mediante una matriz de matrices de objetos con valores x e y que representen ubicaciones geográficas. A continuación, esta columna de datos se asigna a la shapeMemberPath
propiedad. Utiliza IgxGeographicShapeSeriesComponent
puntos de esta columna de datos asignados para trazar polígonos en el control de mapa.
Code Snippet
El siguiente código demuestra cómo vincular IgxGeographicShapeSeriesComponent
a formas de países del mundo cargados desde un archivo de formas utilizando IgxShapeDataSource
.
<div className="sampleRoot" >
<igx-geographic-map #map
width="700px"
height="500px"
zoomable="true" >
</igx-geographic-map>
</div>
<ng-template let-series="series" let-item="item" #template>
<div>
<div *ngIf="item.org;then hasOrg; else notOrg" ></div>
<span [style.color]="series.brush">
{{item.name}}
</span>
<br/>
<span>
Population {{item.pop}} M
</span>
</div>
<ng-template #hasOrg>
<span>
Population {{item.pop}} M
</span>
<br />
</ng-template>
<ng-template #notOrg>
<span>
</span>
</ng-template>
</ng-template>
import { AfterViewInit, Component, TemplateRef, ViewChild } from "@angular/core";
import { IgxShapeDataSource } from 'igniteui-angular-core';
import { IgxGeographicMapComponent } from 'igniteui-angular-maps';
import { IgxGeographicShapeSeriesComponent } from 'igniteui-angular-maps';
@Component({
selector: "app-map-geographic-shape-polygon-series",
styleUrls: ["./map-geographic-shape-polygon-series.component.scss"],
templateUrl: "./map-geographic-shape-polygon-series.component.html"
})
export class MapTypeShapePolygonSeriesComponent implements AfterViewInit {
@ViewChild ("map")
public map: IgxGeographicMapComponent;
@ViewChild("template")
public tooltip: TemplateRef<object>;
public data: any;
constructor() {
}
public ngAfterViewInit(): void {
const sds = new IgxShapeDataSource();
sds.shapefileSource = "assets/Shapes/WorldCountries.shp";
sds.databaseSource = "assets/Shapes/WorldCountries.dbf";
sds.dataBind();
sds.importCompleted.subscribe(() => this.onDataLoaded(sds, ""));
}
public onDataLoaded(sds: IgxShapeDataSource, e: any) {
const shapeRecords = sds.getPointData();
console.log("loaded /Shapes/WorldCountries.shp " + shapeRecords.length);
const countriesNATO: any[] = [];
const countriesSCO: any[] = [];
const countriesARAB: any[] = [];
const countriesOther: any[] = [];
for (const record of shapeRecords) {
// using field/column names from .DBF file
const country = {
name: record.fieldValues.NAME,
org: record.fieldValues.ALLIANCE,
points: record.points,
pop: record.fieldValues.POPULATION
};
const group = record.fieldValues.ALLIANCE;
if (group === "NATO") {
countriesNATO.push(country);
} else if (group === "SCO") {
countriesSCO.push(country);
} else if (group === "ARAB LEAGUE") {
countriesARAB.push(country);
} else {
countriesOther.push(country);
}
}
this.addSeriesWith(countriesNATO, "rgb(32, 146, 252)", "NATO");
this.addSeriesWith(countriesSCO, "rgb(252, 32, 32)", "SCO");
this.addSeriesWith(countriesARAB, "rgb(14, 194, 14)", "AL");
this.addSeriesWith(countriesOther, "rgb(146, 146, 146)", "Other");
}
public addSeriesWith(shapeData: any[], shapeBrush: string, shapeTitle: string) {
const seriesName = shapeTitle + "series";
const geoSeries = new IgxGeographicShapeSeriesComponent();
geoSeries.dataSource = shapeData;
geoSeries.shapeMemberPath = "points";
geoSeries.brush = shapeBrush;
geoSeries.outline = "Black";
geoSeries.tooltipTemplate = this.tooltip;
geoSeries.thickness = 1;
geoSeries.title = shapeTitle;
this.map.series.add(geoSeries);
}
}
API References
IgxGeographicPolylineSeriesComponent
IgxGeographicShapeSeriesComponent
ItemsSource
shapeMemberPath
IgxShapeDataSource