<commit_before>BaseController = require('./BaseController')
_ = require('underscore/underscore')

class Map extends BaseController
  @mapOptions =
    attributionControl: false
    
  # Set the default image path
  L.Icon.Default.imagePath = 'css/images'

  name: "Map"
  
  constructor: ->
    super
    @subscribe @subChannel, @process
    @html require('views/map')()
    @createSky()
    @plotObjects()
    
  createSky: =>
    @map = L.map("sky", Map.mapOptions).setView([0, 180], 6)
    @layer = L.tileLayer('/tiles/#{zoom}/#{tilename}.jpg',
      maxZoom: 7
    )
    @layer.getTileUrl = (tilePoint) ->
      zoom = @_getZoomForUrl()
      convertTileUrl = (x, y, s, zoom) ->
        pixels = Math.pow(2, zoom)
        d = (x + pixels) % (pixels)
        e = (y + pixels) % (pixels)
        f = "t"
        g = 0
        while g < zoom
          pixels = pixels / 2
          if e < pixels
            if d < pixels
              f += "q"
            else
              f += "r"
              d -= pixels
          else
            if d < pixels
              f += "t"
              e -= pixels
            else
              f += "s"
              d -= pixels
              e -= pixels
          g++
        x: x
        y: y
        src: f
        s: s

      url = convertTileUrl(tilePoint.x, tilePoint.y, 1, zoom)
      return "/tiles/#{zoom}/#{url.src}.jpg"

    @layer.addTo @map
  
  plotObject: (coords, options) =>
    L.circle(coords, 500, options).addTo(@map)
    
  plotObjects: =>
    options =
      color: '#0172E6'
    
    for subject in @subjects
      coords = subject.coords
      circle = @plotObject coords, options
      circle.zooniverse_id = subject.zooniverse_id
      circle.bindPopup require('views/map_popup')({subject})
      circle.on 'click', =>
        circle.openPopup()
        @publish circle.zooinverse_id
        

  process: (message) =>
    console.log message
    @selected message.item_id if message.message == "selected"
 
  selected: (itemId) ->
    item = _.find @subjects, (subject) ->
      subject.zooniverse_id = itemId

    latlng = new L.LatLng(item.coords[0], item.coords[1])
    @map.panTo latlng
  
module.exports = Map<commit_msg>Add popup when item is selected in the table<commit_after>BaseController = require('./BaseController')
_ = require('underscore/underscore')

class Map extends BaseController
  @mapOptions =
    attributionControl: false
    
  # Set the default image path
  L.Icon.Default.imagePath = 'css/images'

  name: "Map"
  circles: []
  
  constructor: ->
    super
    @subscribe @subChannel, @process
    @html require('views/map')()
    @createSky()
    @plotObjects()
    
  createSky: =>
    @map = L.map("sky", Map.mapOptions).setView([0, 180], 6)
    @layer = L.tileLayer('/tiles/#{zoom}/#{tilename}.jpg',
      maxZoom: 7
    )
    @layer.getTileUrl = (tilePoint) ->
      zoom = @_getZoomForUrl()
      convertTileUrl = (x, y, s, zoom) ->
        pixels = Math.pow(2, zoom)
        d = (x + pixels) % (pixels)
        e = (y + pixels) % (pixels)
        f = "t"
        g = 0
        while g < zoom
          pixels = pixels / 2
          if e < pixels
            if d < pixels
              f += "q"
            else
              f += "r"
              d -= pixels
          else
            if d < pixels
              f += "t"
              e -= pixels
            else
              f += "s"
              d -= pixels
              e -= pixels
          g++
        x: x
        y: y
        src: f
        s: s

      url = convertTileUrl(tilePoint.x, tilePoint.y, 1, zoom)
      return "/tiles/#{zoom}/#{url.src}.jpg"

    @layer.addTo @map
  
  plotObject: (coords, options) =>
    circle = L.circle(coords, 500, options).addTo(@map)
    @circles.push circle
    circle
    
  plotObjects: =>
    options =
      color: '#0172E6'
    
    for subject in @subjects
      coords = subject.coords
      circle = @plotObject coords, options
      circle.zooniverse_id = subject.zooniverse_id
      circle.bindPopup require('views/map_popup')({subject})
      circle.on 'click', =>
        circle.openPopup()
        @publish circle.zooinverse_id
        

  process: (message) =>
    console.log message
    @selected message.item_id if message.message == "selected"
 
  selected: (itemId) ->
    item = _.find @subjects, (subject) ->
      subject.zooniverse_id = itemId

    latlng = new L.LatLng(item.coords[0], item.coords[1])
    @map.panTo latlng
    circle = _.find @circles, (circle) ->
      circle.zooniverse_id = itemId
    circle.openPopup()
    
  
module.exports = Map
{'fraction_non_alphanumeric': 0.12947598253275108, 'fraction_numerical': 0.008733624454148471, 'mean_word_length': 1.800122249388753, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 24, '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': '4594635', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1473, 'n_words': 355}