0

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()
            })
        }); 

LoadingCircle(uf300);

The event listener is in this function:

function LoadingCircle(layer) {

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

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

Try to add an animation on event:

visibilitychanged

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 '17 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 '17 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 '17 at 12:09
  • Sure, I hope this will be work :) – Veers Oct 17 '17 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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