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
Reloading a vector source when URL changes #2683
Comments
Hi there, Where can I make a +1? ;-) Best regards, |
This can easily be done at the application level: function reload() {
$.ajax(url_to_ws, function(response) {
var geojsonFormat = new ol.format.GeoJSON();
vectorSource.clear();
vectorSource.addFeatures(geojsonFormat.readFeatures(response));
});
} No? |
I ran into this issue and it appears that all is now necessary is:
I found that calling |
@akrherz note that setting a url and format on the vector source is not mandatory, you can do things manually if you want to fully control the behavior of your vector source. This is what I would use: function loadSource(source, url) {
$.ajax(url, function(response) {
var geojsonFormat = new ol.format.GeoJSON();
source.clear(true);
source.addFeatures(geojsonFormat.readFeatures(response));
});
}
var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector()
});
// initial loading of the vector source
loadSource(vectorLayer.getSource(), initialUrl); |
@elemoine when I call |
@akrherz in my example the source does not have a |
@elemoine I am unsure what to say, when I try your code example in my app (no public access) and simply call |
I'd need to see your code. |
@elemoine if it does not do this when you try it, it likely means I am doing something wrong. It isn't worth your bother. Thanks for the responses and work on openlayers. |
Hello. I faced with the same problem. When i call clear() it consumed a lot of resources.
|
What ol3 version do you use? Note that ServerVector was removed in 3.5. |
Oh, I used the last version (v3.2.1). As I understand the new version does not have this problem? Thank you. |
Hi,
following Bart's recommendation I open this ticket so the issue can be commented.
It starts with https://groups.google.com/forum/#!topic/ol3-dev/PjFBy5mxwgo and https://groups.google.com/forum/#!topic/ol3-dev/H6tZaFUUO4E topics on the forum.
Once a vector layer with its source pointing to some URL is created, there is no way to update the layer (really the source) content other than loading, cleaning and adding new features by hand.
Although manually loading is the most flexible option, I think it is a bit confusing. I a user loads data initially setting an
url
property, why we need to load content manually if we want update the source?It could be easy to have a
setUrl()
that updates theurl
property and invokes theloadFeaturesFromURL()
method.Any opinions?
PS: I offer as voluntary to make the code changes. But I don't know when I have enough free time :)
Want to back this issue? Place a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: