-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from airbusgeo/feat-multigeometries
feat(geom): Add support for multi-geometries [OL5]
- Loading branch information
Showing
20 changed files
with
482 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
projects/ngx-openlayers/src/lib/collectioncoordinates.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { Component, Input, OnChanges, OnInit, Optional, SimpleChanges } from '@angular/core'; | ||
import { MapComponent } from './map.component'; | ||
import { GeometryLinestringComponent } from './geom/geometrylinestring.component'; | ||
import { GeometryPolygonComponent } from './geom/geometrypolygon.component'; | ||
import { GeometryMultiPointComponent } from './geom/geometrymultipoint.component'; | ||
import { GeometryMultiLinestringComponent } from './geom/geometrymultilinestring.component'; | ||
import { GeometryMultiPolygonComponent } from './geom/geometrymultipolygon.component'; | ||
import { Coordinate } from 'ol/coordinate'; | ||
import { transform } from 'ol/proj'; | ||
|
||
@Component({ | ||
selector: 'aol-collection-coordinates', | ||
template: ` | ||
<div class="aol-collection-coordinates"></div> | ||
`, | ||
}) | ||
export class CollectionCoordinatesComponent implements OnChanges, OnInit { | ||
private host: any; | ||
private mapSrid = 'EPSG:3857'; | ||
|
||
@Input() | ||
coordinates: Coordinate[] | Coordinate[][] | Coordinate[][][]; | ||
@Input() | ||
srid = 'EPSG:3857'; | ||
|
||
constructor( | ||
private map: MapComponent, | ||
@Optional() geometryLinestring: GeometryLinestringComponent, | ||
@Optional() geometryPolygon: GeometryPolygonComponent, | ||
@Optional() geometryMultipoint: GeometryMultiPointComponent, | ||
@Optional() geometryMultilinestring: GeometryMultiLinestringComponent, | ||
@Optional() geometryMultipolygon: GeometryMultiPolygonComponent | ||
) { | ||
if (!!geometryLinestring) { | ||
this.host = geometryLinestring; | ||
} else if (!!geometryPolygon) { | ||
this.host = geometryPolygon; | ||
} else if (!!geometryMultipoint) { | ||
this.host = geometryMultipoint; | ||
} else if (!!geometryMultilinestring) { | ||
this.host = geometryMultilinestring; | ||
} else if (!!geometryMultipolygon) { | ||
this.host = geometryMultipolygon; | ||
} else { | ||
throw new Error('aol-collection-coordinates must be a child of a geometry component'); | ||
} | ||
} | ||
|
||
ngOnInit() { | ||
this.map.instance.on('change:view', e => this.onMapViewChanged(e)); | ||
this.mapSrid = this.map.instance | ||
.getView() | ||
.getProjection() | ||
.getCode(); | ||
this.transformCoordinates(); | ||
} | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
this.transformCoordinates(); | ||
} | ||
|
||
private onMapViewChanged(event) { | ||
this.mapSrid = event.target | ||
.get(event.key) | ||
.getProjection() | ||
.getCode(); | ||
this.transformCoordinates(); | ||
} | ||
|
||
private transformCoordinates() { | ||
let transformedCoordinates: Coordinate[] | Coordinate[][] | Coordinate[][][]; | ||
|
||
if (this.srid === this.mapSrid) { | ||
transformedCoordinates = this.coordinates; | ||
} else { | ||
switch (this.host.componentType) { | ||
case 'geometry-linestring': | ||
case 'geometry-multipoint': | ||
transformedCoordinates = (<Coordinate[]>this.coordinates).map(c => transform(c, this.srid, this.mapSrid)); | ||
break; | ||
case 'geometry-polygon': | ||
case 'geometry-multilinestring': | ||
transformedCoordinates = (<Coordinate[][]>this.coordinates).map(cc => | ||
cc.map(c => transform(c, this.srid, this.mapSrid)) | ||
); | ||
break; | ||
case 'geometry-multipolygon': | ||
transformedCoordinates = (<Coordinate[][][]>this.coordinates).map(ccc => | ||
ccc.map(cc => cc.map(c => transform(c, this.srid, this.mapSrid))) | ||
); | ||
break; | ||
} | ||
} | ||
|
||
this.host.instance.setCoordinates(transformedCoordinates); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
projects/ngx-openlayers/src/lib/geom/geometrycircle.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { FeatureComponent } from '../feature.component'; | ||
import { Circle } from 'ol/geom'; | ||
import { SimpleGeometryComponent } from './simplegeometry.component'; | ||
import { MapComponent } from '../map.component'; | ||
|
||
@Component({ | ||
selector: 'aol-geometry-circle', | ||
template: ` | ||
<ng-content></ng-content> | ||
`, | ||
}) | ||
export class GeometryCircleComponent extends SimpleGeometryComponent implements OnInit { | ||
public componentType = 'geometry-circle'; | ||
public instance: Circle; | ||
|
||
@Input() | ||
get radius(): number { | ||
return this.instance.getRadius(); | ||
} | ||
set radius(radius: number) { | ||
this.instance.setRadius(radius); | ||
} | ||
|
||
constructor(map: MapComponent, host: FeatureComponent) { | ||
super(map, host); | ||
// defaulting coordinates to [0,0]. To be overridden in child component. | ||
this.instance = new Circle([0, 0]); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
projects/ngx-openlayers/src/lib/geom/geometrylinestring.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { FeatureComponent } from '../feature.component'; | ||
import { SimpleGeometryComponent } from './simplegeometry.component'; | ||
import { MapComponent } from '../map.component'; | ||
import { LineString } from 'ol/geom'; | ||
|
||
@Component({ | ||
selector: 'aol-geometry-linestring', | ||
template: ` | ||
<ng-content></ng-content> | ||
`, | ||
}) | ||
export class GeometryLinestringComponent extends SimpleGeometryComponent implements OnInit { | ||
public componentType = 'geometry-linestring'; | ||
public instance: LineString; | ||
|
||
constructor(map: MapComponent, host: FeatureComponent) { | ||
super(map, host); | ||
} | ||
|
||
ngOnInit() { | ||
this.instance = new LineString([[0, 0], [1, 1]]); | ||
super.ngOnInit(); | ||
} | ||
} |
Oops, something went wrong.