<commit_before>_ = require "underscore"
$ = require "jquery"
HasParent = require "../../common/has_parent"
PlotWidget = require "../../common/plot_widget"
properties = require "../../common/properties"
wmts = require "./wmts_tile_source"
ImagePool = require "./image_pool"
{logger} = require "../../common/logging"

class TileRendererView extends PlotWidget

  initialize: () ->
    @attributionEl = null
    super

  get_extent: () ->
    return [@x_range.get('start'), @y_range.get('start'), @x_range.get('end'), @y_range.get('end')]

  _set_data: () ->
    @pool = new ImagePool()
    @map_plot = @plot_view.model
    @map_canvas = @plot_view.canvas_view.ctx
    @map_frame = @plot_view.frame
    @x_range = @map_plot.get('x_range')
    @x_mapper = this.map_frame.get('x_mappers')['default']
    @y_range = @map_plot.get('y_range')
    @y_mapper = this.map_frame.get('y_mappers')['default']
    @extent = @get_extent()
    @_last_height = undefined
    @_last_width = undefined

  _add_attribution: () =>
    attribution = @mget('tile_source').get('attribution')

    if _.isString(attribution) and attribution.length > 0
      if @attributionEl?
        @attributionEl.html(attribution)
      else
        border_width = @map_plot.get('outline_line_width').value
        bottom_offset = @map_plot.get('min_border_bottom') + border_width
        right_offset = @map_plot.get('min_border_right') + border_width
        right_offset = @map_plot.get('min_border_right') + border_width
        max_width = @map_frame.get('width') - border_width
        @attributionEl = $('<div>')
          .html(attribution)
          .addClass('bk-tile-attribution')
          .css({
            'position': 'absolute'
            'bottom': "#{bottom_offset}px"
            'right': "#{right_offset}px"
            'max-width': "#{max_width}px"
            'background-color': 'rgba(255,255,255,0.8)'
            'font-size': '9pt'
            'font-family': 'sans-serif'
          })

        overlays = @plot_view.$el.find('div.bk-canvas-overlays')
        @attributionEl.appendTo(overlays)

  _map_data: () ->
    @initial_extent = @get_extent()
    zoom_level = @mget('tile_source').get_level_by_extent(@initial_extent, @map_frame.get('height'), @map_frame.get('width'))
    new_extent = @mget('tile_source').snap_to_zoom(@initial_extent, @map_frame.get('height'), @map_frame.get('width'), zoom_level)
    @x_range.set('start', new_extent[0])
    @y_range.set('start', new_extent[1])
    @x_range.set('end', new_extent[2])
    @y_range.set('end', new_extent[3])

  _on_tile_load: (e) =>
    tile_data = e.target.tile_data
    tile_data.img = e.target
    tile_data.current = true
    tile_data.loaded = true
    @request_render()<commit_msg>set right property and add attribution div to .bk-canvas-events instead of .bk-canvas-overlays for z-index issues<commit_after>_ = require "underscore"
$ = require "jquery"
HasParent = require "../../common/has_parent"
PlotWidget = require "../../common/plot_widget"
properties = require "../../common/properties"
wmts = require "./wmts_tile_source"
ImagePool = require "./image_pool"
{logger} = require "../../common/logging"

class TileRendererView extends PlotWidget

  initialize: () ->
    @attributionEl = null
    super

  get_extent: () ->
    return [@x_range.get('start'), @y_range.get('start'), @x_range.get('end'), @y_range.get('end')]

  _set_data: () ->
    @pool = new ImagePool()
    @map_plot = @plot_view.model
    @map_canvas = @plot_view.canvas_view.ctx
    @map_frame = @plot_view.frame
    @x_range = @map_plot.get('x_range')
    @x_mapper = this.map_frame.get('x_mappers')['default']
    @y_range = @map_plot.get('y_range')
    @y_mapper = this.map_frame.get('y_mappers')['default']
    @extent = @get_extent()
    @_last_height = undefined
    @_last_width = undefined

  _add_attribution: () =>
    attribution = @mget('tile_source').get('attribution')

    if _.isString(attribution) and attribution.length > 0
      if @attributionEl?
        @attributionEl.html(attribution)
      else
        border_width = @map_plot.get('outline_line_width').value
        bottom_offset = @map_plot.get('min_border_bottom') + border_width
        right_offset = @map_frame.get('right') - @map_frame.get('width')
        max_width = @map_frame.get('width') - border_width
        @attributionEl = $('<div>')
          .html(attribution)
          .addClass('bk-tile-attribution')
          .css({
            'position': 'absolute'
            'bottom': "#{bottom_offset}px"
            'right': "#{right_offset}px"
            'max-width': "#{max_width}px"
            'background-color': 'rgba(255,255,255,0.8)'
            'font-size': '9pt'
            'font-family': 'sans-serif'
          })

        overlays = @plot_view.$el.find('div.bk-canvas-events')
        @attributionEl.appendTo(overlays)

  _map_data: () ->
    @initial_extent = @get_extent()
    zoom_level = @mget('tile_source').get_level_by_extent(@initial_extent, @map_frame.get('height'), @map_frame.get('width'))
    new_extent = @mget('tile_source').snap_to_zoom(@initial_extent, @map_frame.get('height'), @map_frame.get('width'), zoom_level)
    @x_range.set('start', new_extent[0])
    @y_range.set('start', new_extent[1])
    @x_range.set('end', new_extent[2])
    @y_range.set('end', new_extent[3])

  _on_tile_load: (e) =>
    tile_data = e.target.tile_data
    tile_data.img = e.target
    tile_data.current = true
    tile_data.loaded = true
    @request_render()
{'fraction_non_alphanumeric': 0.16457080371787863, 'fraction_numerical': 0.0061964643703298706, 'mean_word_length': 3.3417721518987342, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4148808', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1896, 'n_words': 290}