Issue with layer bounds

2 posts / 0 new
Last post
gwestern
Issue with layer bounds

Hello, I have been trying to access the bounds of a RouteLayer without success. I am able to call the getBounds() function on a RouteLayer, but the value returned is NULL rather than a latLngBounds object. I have included a JSFiddle-compatible example below. It generates two popups-- one with the result of calling getBounds() on the map itself, and the other calling it on the layer. The application I'm working on requires getting an individual layer's bounds.

 

       var map = L.map('map', {
            layers: MQ.mapLayer(),
            center: [38.575210, -121.483426],
            zoom: 12
        });

       var dir2 = MQ.routing.directions();

        dir2.route({
            locations: [
              "woodland, ca",
              "dixon, ca"
            ]
        });

     var layer1 = MQ.routing.routeLayer({
            directions: dir2,
            fitBounds: true
        });
        
       map.addLayer(layer1);
       

       window.alert(map.getBounds());
       window.alert(layer1.getBounds());


MQBrianCoakley
Make sure the bounds are
Make sure the bounds are requested after the layer has bounds - in the success event of the directions request. Here is how I did it.          var dir2 = MQ.routing.directions()        .on('success', function(data){        try{            console.log(layer1.routeData.boundingBox);        }catch(e){}        });