-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ImageSource.updateImage() #7342
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
17871e0
Adds ImageSource.updateImage.
dcervelli 62eb757
Docs.
dcervelli b76c9ae
Change test data image size.
dcervelli b9ed4e3
Change debug page to use existing radar images.
dcervelli afe1108
Make updateImage() use load().
dcervelli 02cb2e8
Change to debug example for moving coordinates.
dcervelli f7b55dd
Add some tests.
dcervelli 1922e1f
Update animate-images example to use updateImage().
dcervelli 7151d52
Lint fixes.
dcervelli 973985a
Flow fixes.
dcervelli ba4eaa4
Remove coordinate shifting in example.
dcervelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Mapbox GL JS debug page</title> | ||
<meta charset='utf-8'> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> | ||
<link rel='stylesheet' href='/dist/mapbox-gl.css' /> | ||
<style> | ||
body { margin: 0; padding: 0; } | ||
html, body, #map { height: 100%; } | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id='map'></div> | ||
|
||
<script src='/dist/mapbox-gl-dev.js'></script> | ||
<script src='/debug/access_token_generated.js'></script> | ||
<script> | ||
|
||
const map = new mapboxgl.Map({ | ||
container: 'map', | ||
minZoom: 1, | ||
zoom: 6, | ||
center: [-76, 43.5], | ||
style: 'mapbox://styles/mapbox/dark-v9', | ||
hash: false | ||
}); | ||
|
||
const path = "/docs/pages/assets/"; | ||
|
||
const frameCount = 5; | ||
|
||
const coordinates = [ | ||
[-80.425, 46.437], | ||
[-71.516, 46.437], | ||
[-71.516, 37.936], | ||
[-80.425, 37.936] | ||
]; | ||
|
||
map.on("load", () => { | ||
let currentImage = 0; | ||
const getPath = () => `${path}radar${currentImage}.gif`; | ||
|
||
map.addSource("radar", { | ||
type: "image", | ||
url: getPath(), | ||
coordinates | ||
}); | ||
map.addLayer({ | ||
id: "radar-layer", | ||
"type": "raster", | ||
"source": "radar", | ||
"paint": { | ||
"raster-resampling": "nearest", | ||
"raster-fade-duration": 0 | ||
} | ||
}); | ||
|
||
setInterval(() => { | ||
currentImage = (currentImage + 1) % frameCount; | ||
map.getSource("radar").updateImage({ | ||
url: getPath(), | ||
coordinates | ||
}); | ||
|
||
// To illustrate moving coordinates at the same time | ||
coordinates.forEach(c => { | ||
c[0] += 0.025; | ||
c[1] += 0.025; | ||
}); | ||
}, 200); | ||
}); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This moves the image off the screen pretty rapidly and eventually will cause an error when the latitude goes above 90°. I know I suggested this but maybe it would be better to remove it. Sorry about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem.