<commit_before># MapMarkerView is base class for scenario elements represented by a
# single latitude and longitude on the Map
class window.beats.MapMarkerView extends Backbone.View
  @IMAGE_PATH: '/scenario-editor-0.4-SNAPSHOT/app/images/'
  $a = window.beats

  broker_events : {
    'map:open_view_mode' : 'viewMode'
    'map:open_network_mode' : 'networkMode'
    'map:open_scenario_mode' : 'scenarioMode'
    'map:init' : 'render'
  }
  
  initialize: (@model) ->
    # get the position, we only draw if the position is defined
    # TODO deal with getting a position if it is not defined
    @latLng = $a.Util.getLatLng(@model)
    @draw()
    @_publishGoogleEvents()
    $a.broker.on("map:select_item:#{@model.cid}", @makeSelected, @)
    $a.broker.on("map:clear_item:#{@model.cid}", @clearSelected, @)
    $a.broker.on("map:open_editor:#{@model.cid}", @_editor, @)
    google.maps.event.addListener($a.map, 'zoom_changed', => @setMarkerSize())
    $a.Util.publishEvents($a.broker, @broker_events, @)

  render: ->
    @marker.setMap($a.map)
    @

  # Draw the marker by determining the type of icon
  # is used for each type of element. The default is the
  # our standard dot.png. Each subclasses overrides get_icon
  # to pass the correct icon
  draw: ->
    @marker = new google.maps.Marker
        position: @latLng
        draggable: true
        icon: @getIcon()
        title: @_getTitle()

  _getTitle: ->
    title = "Name: #{@model.road_names()}\n"
    title += "Id: #{@model.id}\n"
    title += "Latitude: #{@latLng.lat()}\n"
    title += "Longitude: #{@latLng.lng()}"
    title

  getIcon: (img) ->
    img
  
  getMarkerImageIcons: (img) ->
    zoom = @getScaledSizeOnZoomIcons()
    anchorSize = zoom.height / 2
    {
        url: "#{MapMarkerView.IMAGE_PATH}#{img}.svg",
        size: new google.maps.Size(64, 64),
        origin: new google.maps.Point(0, 0),
        anchor: new google.maps.Point(anchorSize, anchorSize),
        scaledSize: zoom
    }
  
  # determine marker size based the zoom level
  getScaledSizeOnZoomIcons: ()->
    zoomLevel = $a.map.getZoom()
    console.log zoomLevel
    if (zoomLevel >= 17)
      return new google.maps.Size(48, 48)
    else if (zoomLevel >= 16)
      return new google.maps.Size(32, 32)
    else if (zoomLevel >= 15)
      return new google.maps.Size(24, 24)
    else if (zoomLevel >= 14)
      return new google.maps.Size(16, 16)
    else
      return new google.maps.Size(12, 12)
  
  # re-render the marker when the zoom changes
  setMarkerSize: ->
    @marker.setIcon(@getIcon())
  
  # in order to remove an element you need to unpublish the events,
  # hide the marker and set it to null
  removeElement: ->
    $a.Util.unpublishEvents($a.broker, @broker_events, @)
    $a.broker.off("map:select_item:#{@model.cid}")
    $a.broker.off("map:clear_item:#{@model.cid}")
    $a.broker.off("map:open_editor:#{@model.cid}")
    @_unpublishGoogleEvents()
    @hideMarker() if @marker?
    @marker = null
    
  # publish/unpublish map google events
  _publishGoogleEvents: ->
    gme = google.maps.event
    @dragEndListener = gme.addListener(@marker, 'dragend', => @dragMarker())
    @clickListener = gme.addListener(@marker, 'click', (event) => @manageMarkerSelect())
    @dblClickListener = gme.addListener(@marker, 'dblclick', (mouseEvent) => @_editor())
    lambda = (event) => @_contextMenu(event)
    @rClickListener = gme.addListener(@marker, 'rightclick', lambda)

  _unpublishGoogleEvents: ->
    gme = google.maps.event
    gme.removeListener(@rClickListener)
    gme.removeListener(@dragEndListener)
    gme.removeListener(@clickListener)
    gme.removeListener(@dblClickListener)
  
  # Context Menu
  #
  # Create the Marker Context Menu.
  #
  # This class is always called by it overridden subclass method. The
  # menu items are stored with their events in an array and can be
  # configired in the menu-data.coffee file. We create a dependency
  # with the ContextMenuView here. There may a better way to do
  # this. I also add the contextMenu itself to the model so the same
  # menu can be added to the tree items for this node
  _contextMenu: (type, menuItems) ->
    @contextMenuOptions =
      class: 'context_menu'
      id: "context-menu-#{type}-#{@model.id}"
    args = <commit_msg>adding removing google zoom listener method to unpublish events.<commit_after># MapMarkerView is base class for scenario elements represented by a
# single latitude and longitude on the Map
class window.beats.MapMarkerView extends Backbone.View
  @IMAGE_PATH: '/scenario-editor-0.4-SNAPSHOT/app/images/'
  $a = window.beats

  broker_events : {
    'map:open_view_mode' : 'viewMode'
    'map:open_network_mode' : 'networkMode'
    'map:open_scenario_mode' : 'scenarioMode'
    'map:init' : 'render'
  }
  
  initialize: (@model) ->
    # get the position, we only draw if the position is defined
    # TODO deal with getting a position if it is not defined
    @latLng = $a.Util.getLatLng(@model)
    @draw()
    @_publishGoogleEvents()
    $a.broker.on("map:select_item:#{@model.cid}", @makeSelected, @)
    $a.broker.on("map:clear_item:#{@model.cid}", @clearSelected, @)
    $a.broker.on("map:open_editor:#{@model.cid}", @_editor, @)
    $a.Util.publishEvents($a.broker, @broker_events, @)

  render: ->
    @marker.setMap($a.map)
    @

  # Draw the marker by determining the type of icon
  # is used for each type of element. The default is the
  # our standard dot.png. Each subclasses overrides get_icon
  # to pass the correct icon
  draw: ->
    @marker = new google.maps.Marker
        position: @latLng
        draggable: true
        icon: @getIcon()
        title: @_getTitle()

  _getTitle: ->
    title = "Name: #{@model.road_names()}\n"
    title += "Id: #{@model.id}\n"
    title += "Latitude: #{@latLng.lat()}\n"
    title += "Longitude: #{@latLng.lng()}"
    title

  getIcon: (img) ->
    img
  
  getMarkerImageIcons: (img) ->
    zoom = @getScaledSizeOnZoomIcons()
    anchorSize = zoom.height / 2
    {
        url: "#{MapMarkerView.IMAGE_PATH}#{img}.svg",
        size: new google.maps.Size(64, 64),
        origin: new google.maps.Point(0, 0),
        anchor: new google.maps.Point(anchorSize, anchorSize),
        scaledSize: zoom
    }
  
  # determine marker size based the zoom level
  getScaledSizeOnZoomIcons: ()->
    zoomLevel = $a.map.getZoom()
    console.log zoomLevel
    if (zoomLevel >= 17)
      return new google.maps.Size(48, 48)
    else if (zoomLevel >= 16)
      return new google.maps.Size(32, 32)
    else if (zoomLevel >= 15)
      return new google.maps.Size(24, 24)
    else if (zoomLevel >= 14)
      return new google.maps.Size(16, 16)
    else
      return new google.maps.Size(12, 12)
  
  # re-render the marker when the zoom changes
  setMarkerSize: ->
    @marker.setIcon(@getIcon())
  
  # in order to remove an element you need to unpublish the events,
  # hide the marker and set it to null
  removeElement: ->
    $a.Util.unpublishEvents($a.broker, @broker_events, @)
    $a.broker.off("map:select_item:#{@model.cid}")
    $a.broker.off("map:clear_item:#{@model.cid}")
    $a.broker.off("map:open_editor:#{@model.cid}")
    @_unpublishGoogleEvents()
    @hideMarker() if @marker?
    @marker = null
    
  # publish/unpublish map google events
  _publishGoogleEvents: ->
    gme = google.maps.event
    @dragEndListener = gme.addListener(@marker, 'dragend', => @dragMarker())
    @clickListener = gme.addListener(@marker, 'click', (event) => @manageMarkerSelect())
    @dblClickListener = gme.addListener(@marker, 'dblclick', (mouseEvent) => @_editor())
    lambda = (event) => @_contextMenu(event)
    @rClickListener = gme.addListener(@marker, 'rightclick', lambda)
    @zoomListener = google.maps.event.addListener($a.map, 'zoom_changed', => @setMarkerSize())

  _unpublishGoogleEvents: ->
    gme = google.maps.event
    gme.removeListener(@rClickListener)
    gme.removeListener(@dragEndListener)
    gme.removeListener(@clickListener)
    gme.removeListener(@dblClickListener)
    gme.removeListener(@zoomListener)
  
  # Context Menu
  #
  # Create the Marker Context Menu.
  #
  # This class is always called by it overridden subclass method. The
  # menu items are stored with their events in an array and can be
  # configired in the menu-data.coffee file. We create a dependency
  # with the ContextMenuView here. There may a better way to do
  # this. I also add the contextMenu itself to the model so the same
  # menu can be added to the tree items for this node
  _contextMenu: (type, menuItems) ->
    @contextMenuOptions =
      class: 'context_menu'
      id: "context-menu-#{type}-#{@model.id}"
    args = 
{'fraction_non_alphanumeric': 0.13190998268897866, 'fraction_numerical': 0.008540103866128102, 'mean_word_length': 3.3071570576540754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, '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': '6880318', 'n_tokens_mistral': 2920, 'n_tokens_neox': 2867, 'n_words': 746}