-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for dynamically changing image source properties (#139)
- Loading branch information
1 parent
f47d0b1
commit 0a60463
Showing
8 changed files
with
101 additions
and
32 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
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
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
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
71 changes: 71 additions & 0 deletions
71
projects/showcase/src/app/demo/examples/live-update-image-srource.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,71 @@ | ||
import { Component, OnDestroy, OnInit } from '@angular/core'; | ||
import { interval, Subscription } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'showcase-demo', | ||
template: ` | ||
<mgl-map | ||
[style]="'mapbox://styles/mapbox/satellite-v9'" | ||
[center]="center" | ||
[zoom]="[14]" | ||
movingMethod="jumpTo" | ||
> | ||
<mgl-image-source | ||
id="test_source" | ||
[url]="url" | ||
[coordinates]="coordinates" | ||
> | ||
</mgl-image-source> | ||
<mgl-layer | ||
id="test_layer" | ||
source="test_source" | ||
type="raster" | ||
[paint]="{ 'raster-fade-duration': 0}" | ||
> | ||
</mgl-layer> | ||
</mgl-map> | ||
`, | ||
styleUrls: ['./examples.css'] | ||
}) | ||
export class LiveUpdateImageSourceComponent implements OnInit, OnDestroy { | ||
private sub: Subscription; | ||
private readonly size = 0.001; | ||
center: number[]; | ||
|
||
url = 'assets/red.png'; | ||
coordinates: number[][]; | ||
|
||
async ngOnInit() { | ||
const data: GeoJSON.FeatureCollection<GeoJSON.LineString> = <any>await import('./hike.geo.json'); | ||
const points = data.features[0].geometry!.coordinates; | ||
const coordinates = points.map(c => this.makeRectangle(c)); | ||
|
||
this.center = points[0]; | ||
this.coordinates = coordinates[0]; | ||
|
||
let i = 0; | ||
|
||
this.sub = interval(250) | ||
.subscribe(() => { | ||
this.url = Math.random() < 0.5 ? 'assets/red.png' : 'assets/blue.png'; | ||
this.coordinates = coordinates[i]; | ||
i = (i + 1) % coordinates.length; | ||
}); | ||
} | ||
|
||
ngOnDestroy() { | ||
if (this.sub !== undefined) { | ||
this.sub.unsubscribe(); | ||
} | ||
} | ||
|
||
private makeRectangle([long, lat]: number[]): number[][] { | ||
return [ | ||
[long, lat], | ||
[long + this.size, lat], | ||
[long + this.size, lat - this.size], | ||
[long, lat - this.size] | ||
]; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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