How to update an XYZ layer in Open Layers 5
up vote
1
down vote
favorite
Is removing and re-adding an XYZ layer the only way to update it in ol5?
I know TileWMS has an updateParams() method, which is nice, but some of the layers I'm working with are XYZ with a time query parameter.
Here is the pseudo code for how I've worked around it, but it doesn't seem like the right way to go about it.
function createLayer()
return new TileLayer(
source: new XYZ(
url: 'https://url?x=x&y=y&z=z&time=' + dateTimeString,
)
);
map.addLayer(createLayer());
// user interaction to change the time
map.removeLayer(createLayer());
map.addLayer(createLayer());
Thanks!
openlayers openlayers-5
add a comment |
up vote
1
down vote
favorite
Is removing and re-adding an XYZ layer the only way to update it in ol5?
I know TileWMS has an updateParams() method, which is nice, but some of the layers I'm working with are XYZ with a time query parameter.
Here is the pseudo code for how I've worked around it, but it doesn't seem like the right way to go about it.
function createLayer()
return new TileLayer(
source: new XYZ(
url: 'https://url?x=x&y=y&z=z&time=' + dateTimeString,
)
);
map.addLayer(createLayer());
// user interaction to change the time
map.removeLayer(createLayer());
map.addLayer(createLayer());
Thanks!
openlayers openlayers-5
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Is removing and re-adding an XYZ layer the only way to update it in ol5?
I know TileWMS has an updateParams() method, which is nice, but some of the layers I'm working with are XYZ with a time query parameter.
Here is the pseudo code for how I've worked around it, but it doesn't seem like the right way to go about it.
function createLayer()
return new TileLayer(
source: new XYZ(
url: 'https://url?x=x&y=y&z=z&time=' + dateTimeString,
)
);
map.addLayer(createLayer());
// user interaction to change the time
map.removeLayer(createLayer());
map.addLayer(createLayer());
Thanks!
openlayers openlayers-5
Is removing and re-adding an XYZ layer the only way to update it in ol5?
I know TileWMS has an updateParams() method, which is nice, but some of the layers I'm working with are XYZ with a time query parameter.
Here is the pseudo code for how I've worked around it, but it doesn't seem like the right way to go about it.
function createLayer()
return new TileLayer(
source: new XYZ(
url: 'https://url?x=x&y=y&z=z&time=' + dateTimeString,
)
);
map.addLayer(createLayer());
// user interaction to change the time
map.removeLayer(createLayer());
map.addLayer(createLayer());
Thanks!
openlayers openlayers-5
openlayers openlayers-5
asked Nov 10 at 15:42
Michael
614513
614513
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
This method can be used either as a dummy parameter to override caching or to set a configurable time parameter on sources such as weather maps:
var layer = new TileLayer(
source: new XYZ()
);
function setTileUrl(dateTime)
layer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTime);
setTileUrl(initialDateTime);
map.addLayer(layer);
// user interaction to change the time
setTileUrl(newDateTime);
add a comment |
up vote
2
down vote
Another way would be to refresh the source in connection with using a tileUrlFunction:
TileLayer.getSource().refresh();
See also here.
2
That would only clear the Openlayers cache, it won't re-evaluate the url.TileLayer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTimeString);will do both (the time parameter will still be needed to override the browser cache).
– Mike
Nov 10 at 18:33
You are right. In connection with a tileUrlFunction it works for me.
– RalphL
Nov 11 at 16:50
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
This method can be used either as a dummy parameter to override caching or to set a configurable time parameter on sources such as weather maps:
var layer = new TileLayer(
source: new XYZ()
);
function setTileUrl(dateTime)
layer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTime);
setTileUrl(initialDateTime);
map.addLayer(layer);
// user interaction to change the time
setTileUrl(newDateTime);
add a comment |
up vote
3
down vote
accepted
This method can be used either as a dummy parameter to override caching or to set a configurable time parameter on sources such as weather maps:
var layer = new TileLayer(
source: new XYZ()
);
function setTileUrl(dateTime)
layer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTime);
setTileUrl(initialDateTime);
map.addLayer(layer);
// user interaction to change the time
setTileUrl(newDateTime);
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
This method can be used either as a dummy parameter to override caching or to set a configurable time parameter on sources such as weather maps:
var layer = new TileLayer(
source: new XYZ()
);
function setTileUrl(dateTime)
layer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTime);
setTileUrl(initialDateTime);
map.addLayer(layer);
// user interaction to change the time
setTileUrl(newDateTime);
This method can be used either as a dummy parameter to override caching or to set a configurable time parameter on sources such as weather maps:
var layer = new TileLayer(
source: new XYZ()
);
function setTileUrl(dateTime)
layer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTime);
setTileUrl(initialDateTime);
map.addLayer(layer);
// user interaction to change the time
setTileUrl(newDateTime);
answered Nov 10 at 20:52
Mike
51916
51916
add a comment |
add a comment |
up vote
2
down vote
Another way would be to refresh the source in connection with using a tileUrlFunction:
TileLayer.getSource().refresh();
See also here.
2
That would only clear the Openlayers cache, it won't re-evaluate the url.TileLayer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTimeString);will do both (the time parameter will still be needed to override the browser cache).
– Mike
Nov 10 at 18:33
You are right. In connection with a tileUrlFunction it works for me.
– RalphL
Nov 11 at 16:50
add a comment |
up vote
2
down vote
Another way would be to refresh the source in connection with using a tileUrlFunction:
TileLayer.getSource().refresh();
See also here.
2
That would only clear the Openlayers cache, it won't re-evaluate the url.TileLayer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTimeString);will do both (the time parameter will still be needed to override the browser cache).
– Mike
Nov 10 at 18:33
You are right. In connection with a tileUrlFunction it works for me.
– RalphL
Nov 11 at 16:50
add a comment |
up vote
2
down vote
up vote
2
down vote
Another way would be to refresh the source in connection with using a tileUrlFunction:
TileLayer.getSource().refresh();
See also here.
Another way would be to refresh the source in connection with using a tileUrlFunction:
TileLayer.getSource().refresh();
See also here.
edited Nov 11 at 16:52
answered Nov 10 at 16:06
RalphL
213
213
2
That would only clear the Openlayers cache, it won't re-evaluate the url.TileLayer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTimeString);will do both (the time parameter will still be needed to override the browser cache).
– Mike
Nov 10 at 18:33
You are right. In connection with a tileUrlFunction it works for me.
– RalphL
Nov 11 at 16:50
add a comment |
2
That would only clear the Openlayers cache, it won't re-evaluate the url.TileLayer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTimeString);will do both (the time parameter will still be needed to override the browser cache).
– Mike
Nov 10 at 18:33
You are right. In connection with a tileUrlFunction it works for me.
– RalphL
Nov 11 at 16:50
2
2
That would only clear the Openlayers cache, it won't re-evaluate the url.
TileLayer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTimeString); will do both (the time parameter will still be needed to override the browser cache).– Mike
Nov 10 at 18:33
That would only clear the Openlayers cache, it won't re-evaluate the url.
TileLayer.getSource().setUrl('https://url?x=x&y=y&z=z&time=' + dateTimeString); will do both (the time parameter will still be needed to override the browser cache).– Mike
Nov 10 at 18:33
You are right. In connection with a tileUrlFunction it works for me.
– RalphL
Nov 11 at 16:50
You are right. In connection with a tileUrlFunction it works for me.
– RalphL
Nov 11 at 16:50
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240548%2fhow-to-update-an-xyz-layer-in-open-layers-5%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown