OpenLayers重新加载图层数据

var now = Date.now();
var format = selectedLayerSource.getFormat();
var url = selectedLayerSource.getUrl();
url = url + '?t=' + now;

//make AJAX request to source url
$.ajax({
    url: url,
    success: function (result) {

        //manually remove features from the source
        selectedLayerSource.forEachFeature(function (feature) {
            selectedLayerSource.removeFeature(feature);
        });

        //create features from AJAX results
        var features = format.readFeatures(result, {
            featureProjection: 'EPSG:3857'
        });

        //add features to the source
        selectedLayerSource.addFeatures(features);

    },
    error: function (err) {
        alert("Could not load features from " + selectedLayerName + " at " + url + " error code: " + err.status);
    }
});

你可能感兴趣的:(OpenLayers)