OpenLayers3 change Layer source URL (or replace features loaded from another URL)

المشرف العام

Administrator
طاقم الإدارة
I have a map with a Vector layer, containing features from a GeoJSON source:

var map = new ol.Map({ layers: [new ol.layer.Tile({ source: new ol.source.OSM() }), new ol.layer.Vector({ source: new ol.source.Vector({ url: 'http://example.com:5000/geo/data/zones/1', format: new ol.format.GeoJSON() }), })], renderer: 'canvas', target: 'map', view: new ol.View({ center: [737514.438475665, 5864533.629390752], zoom: 13 })});I have multiple URLs that returns s GeoJSON string:

I need to be able to switch the URL of my Layer source (or fetch and display features from another URL).

I have tried to find the 'url' property on the ol.Layer.Vector instance:

l=m.getLayers().getArray()[1]l.getProperties()and on the ol.source.Vector instance:

s = l.getSource()s.getProperties()but I haven't found anything about the 'url' property.

Could you provide a way to do that ?

  • is it possible to simply update the source URL (and automagically refresh the layer features) ?
  • shall I remove existing features, load new features using my own logic and add the loaded ones ?
  • shall I remove the whole Layer, re-create it, and re-add it ?

أكثر...
 
أعلى