import { axiosGetWithoutCSRF } from '../helpers/request-helpers'

export default {
  data () {
    return {
      initBounds: null
    }
  },

  methods: {
    initBoundingBoxAndMap () {  
      if (this.mapOptions.boundsUrl) {
        axiosGetWithoutCSRF(
          this.mapOptions.boundsUrl.url, 
          this.getExtentResponseHandler(this.mapOptions.boundsUrl.padding)
        )
      } else {
        this.initMap()
      }
    },

    getExtentResponseHandler (padding) {      
      return res => {
        const extent = res.data.extent
  
        if (extent) {
          this.initBounds = this.getBoundsFromExtent(extent, padding)
        }
  
        this.initMap()
      }
    },

    zoomToExtent (extent, padding) {
      this.map.fitBounds(this.getBoundsFromExtent(extent, padding))
    },

    getBoundsFromExtent (extent, padding=5) {  
      return [
        [
          Math.max(extent.xmin - padding, -180), 
          Math.max(extent.ymin - padding, -90)
        ],
        [
          Math.min(extent.xmax + padding, 180), 
          Math.min(extent.ymax + padding, 90)
        ]
      ]
    }
  }
}
@@ -700,35 +700,290 @@
 omTo
-Extent (extent, padding) %7B%0A
+ (boundsUrl) %7B%0A      axiosGetWithoutCSRF(%0A        boundsUrl.url, %0A        this.getExtentResponseZoomToHandler(boundsUrl.padding)%0A      )%0A    %7D,%0A%0A    getExtentResponseZoomToHandler (padding) %7B%0A      return res =%3E %7B%0A        const extent = res.data.extent%0A  %0A        if (extent) %7B%0A    
     
@@ -1046,16 +1046,34 @@
 dding))%0A
+        %7D%0A      %7D%0A
     %7D,%0A%0A

add mixin to zoom to location based on url object