I want to add a loading symbol to my openlayers map, which is triggered when a layer is set to load and stopped when the layer is loaded. So I used the event listeners loadstart and loaded. Here is my code so far to load the layer:

    uf300 = new OpenLayers.Layer.Vector("UF Notfall", {
            projection: toProjection,
            styleMap: style_uf300,
            strategies: [new OpenLayers.Strategy.Fixed()],
            protocol: new OpenLayers.Protocol.HTTP({
                url: "/GeoJSON/uf_hq300.geojson",
                format: new OpenLayers.Format.GeoJSON()


The event listener is in this function:

function LoadingCircle(layer) {

    layer.events.register("loadstart", layer, function o() {
        var lonlat1 = map.getCenter();
        var circle = new OpenLayers.Marker(lonlat1,icon1);
    layer.events.register("loadend", layer, function p() {

Unfortunately this only works when the layer is selected for the first time. When the user makes the layer invisible and then visible again the symbol won't show.

I tried refreshing and destroying the layer when the user makes it invisible, and also tried 3 different types of calling the event listener. Unfortunately nothing worked...

How can I start running the loading symbol every time the user decides to make the layer visible?

1 Answer 1


Try to add an animation on event:


There is no reason for adding events on create/destroy layer, I think.

  • I thought of that too, but I couldn't think of a way to stop showing the loading symbol without the 'loadend' event. With visibilitychanged I can only start the loading symbol
    – rabear
    Oct 17, 2017 at 11:26
  • 1
    So, you can try this steps: show animation when "featureselected" event of Vector layer throwed, and hide animation on callback of Protocol.Http
    – Veers
    Oct 17, 2017 at 11:39
  • Good idea. I am going to give a try. Might take a while, as I am currently burried in work :)
    – rabear
    Oct 17, 2017 at 12:09
  • Sure, I hope this will be work :)
    – Veers
    Oct 17, 2017 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.