<script>
import commonMixin from '@/base/mixins/common.js'
import { TileSuperMapRest } from '@/supermap/openlayers'
import OverviewMap from '@/controls/OverviewMap.js'
export default {
  name: 'bs-supermaplayer',
  render () { },
  mixins: [commonMixin('layer')],
  props: {
    url: {
      type: String
    },
    showOverView: {
      type: Boolean,
      default: false
    }
  },
  watch: {
  },
  methods: {
    load () {
      const { ol, $rootComponent, map, url, showOverView } = this
      const layer = new ol.layer.Tile({
        source: new TileSuperMapRest({
          url: url,
          wrapX: true
        }),
        projection: $rootComponent.projection
      })
      this.originInstance = layer
      map.addLayer(layer)
      if (showOverView) {
        const overview = new OverviewMap({
          collapsible: true,
          collapsed: false,
          view: new ol.View({
            projection: $rootComponent.projection,
            center: $rootComponent.center,
            zoom: 2
          })
        })
        $rootComponent.addControl(overview)
      }
    }
  }
}
</script>
