<commit_before># The main class managing the view of the network on the map.
# A network consists of all the links, nodes, sensors, controllers
# events, and signals along a route. It uses the google api Directions
# Service to determine the route by passing the service
# a set of latitude and longitudes along the route(waypoints). 
#
# The class also creates and then triggers the rendering of the treeView 
# of the scenario elements.
class window.beats.MapNetworkView extends Backbone.View
  $a = window.beats
  WARNING_MSG = 'Directions API Warning(s):'
  ERROR_MSG = 'Directions API Error: Could not render link :'
    
  initialize: (@scenario) ->
    @networks =  @scenario.networks()
    @_initializeCollections()
    _.each(@networks, (network) => @_drawNetwork(network))
    @_centerMap() if @networks[0].position()?
    @_drawScenarioItems()
    @_layersMenu()

    # This class creates the tree view of all the elements of the scenario
    $a.tree = new $a.TreeView({ scenario: @scenario, attach: "#tree_view"})
    @render()
  
  render: ->
    $a.broker.trigger('map:init')
    $a.broker.trigger('app:main_tree')
    # handle network browser event
    @_setUpEvents()
    @
  
  _setUpEvents: ->
    $a.broker.on('map:open_network_editor', @_editor, @)
    $a.broker.on("map:clear_map", @_tearDownEvents, @)

  _tearDownEvents: ->
    $a.broker.off('map:open_network_editor')
  
  _initializeCollections: () ->
    $a.nodeList = new $a.NodeListCollection($a.models.nodes())
    $a.linkList = new $a.LinkListCollection($a.models.links(), @network)
    $a.sensorList = new $a.SensorListCollection($a.models.sensors())
    $a.controllerSet = new $a.ControllerSetCollection($a.models.controllers())
    $a.eventSet = new $a.EventSetCollection($a.models.events())
  
  # This creates the layers menu bar
  _layersMenu: () ->
    attrs = {
      className: 'dropdown-menu bottom-up'
      id: 'l_list'
      parentId: 'lh'
      menuItems: $a.layers_menu
    }
    @lmenu = new $a.LayersMenuView(attrs)
  
  #center the map based on network position
  _centerMap: () ->
    pts = $a.Util.convertPointsToGoogleLatLng(@networks[0].position().points())
    mid = google.maps.geometry.spherical.interpolate(pts[0], pts[1], 0.5)
    $a.map.setCenter(new google.maps.LatLng(mid.lat(), mid.lng()))
  
  _drawScenarioItems: () ->
    @_drawSensors()
    @_drawControllers()
    @_drawEvents()
    #@_drawSignals()
    
  # _drawNetwork is organizing function calling all the methods that
  # instantiate the various elements of the network
  _drawNetwork: (network)->
    $a.map.setCenter($a.Util.getLatLng(network))
    @_drawLinks(network)
    if network.nodes()?
      @_drawNodes network.nodes(), network
  
  # These methods instantiate each elements view instance in the map
  _drawLinks: (network) ->
    $a.linkListView = new $a.LinkListView($a.linkList, network)
    
  _drawNodes: (nodes, network) ->
    $a.nodeListView = new $a.NodeListView($a.nodeList, network)<commit_msg>Fixed: Intermittent node/link display appears related to where you start the zoom level. I backed us out to 16 both at the time the map is created and after we center the map.<commit_after># The main class managing the view of the network on the map.
# A network consists of all the links, nodes, sensors, controllers
# events, and signals along a route. It uses the google api Directions
# Service to determine the route by passing the service
# a set of latitude and longitudes along the route(waypoints). 
#
# The class also creates and then triggers the rendering of the treeView 
# of the scenario elements.
class window.beats.MapNetworkView extends Backbone.View
  $a = window.beats
  WARNING_MSG = 'Directions API Warning(s):'
  ERROR_MSG = 'Directions API Error: Could not render link :'
    
  initialize: (@scenario) ->
    @networks =  @scenario.networks()
    @_initializeCollections()
    _.each(@networks, (network) => @_drawNetwork(network))
    @_centerMap() if @networks[0].position()?
    @_drawScenarioItems()
    @_layersMenu()

    # This class creates the tree view of all the elements of the scenario
    $a.tree = new $a.TreeView({ scenario: @scenario, attach: "#tree_view"})
    @render()
  
  render: ->
    $a.broker.trigger('map:init')
    $a.broker.trigger('app:main_tree')
    # handle network browser event
    @_setUpEvents()
    @
  
  _setUpEvents: ->
    $a.broker.on('map:open_network_editor', @_editor, @)
    $a.broker.on("map:clear_map", @_tearDownEvents, @)

  _tearDownEvents: ->
    $a.broker.off('map:open_network_editor')
  
  _initializeCollections: () ->
    $a.nodeList = new $a.NodeListCollection($a.models.nodes())
    $a.linkList = new $a.LinkListCollection($a.models.links(), @network)
    $a.sensorList = new $a.SensorListCollection($a.models.sensors())
    $a.controllerSet = new $a.ControllerSetCollection($a.models.controllers())
    $a.eventSet = new $a.EventSetCollection($a.models.events())
  
  # This creates the layers menu bar
  _layersMenu: () ->
    attrs = {
      className: 'dropdown-menu bottom-up'
      id: 'l_list'
      parentId: 'lh'
      menuItems: $a.layers_menu
    }
    @lmenu = new $a.LayersMenuView(attrs)
  
  #center the map based on network position
  _centerMap: () ->
    pts = $a.Util.convertPointsToGoogleLatLng(@networks[0].position().points())
    mid = google.maps.geometry.spherical.interpolate(pts[0], pts[1], 0.5)
    $a.map.setCenter(new google.maps.LatLng(mid.lat(), mid.lng()))
  
  _drawScenarioItems: () ->
    @_drawSensors()
    @_drawControllers()
    @_drawEvents()
    #@_drawSignals()
    
  # _drawNetwork is organizing function calling all the methods that
  # instantiate the various elements of the network
  _drawNetwork: (network)->
    $a.map.setCenter($a.Util.getLatLng(network))
    $a.map.setZoom($a.AppView.INITIAL_ZOOM_LEVEL)
    @_drawLinks(network)
    if network.nodes()?
      @_drawNodes network.nodes(), network
  
  # These methods instantiate each elements view instance in the map
  _drawLinks: (network) ->
    $a.linkListView = new $a.LinkListView($a.linkList, network)
    
  _drawNodes: (nodes, network) ->
    $a.nodeListView = new $a.NodeListView($a.nodeList, network)
{'fraction_non_alphanumeric': 0.12766645119586295, 'fraction_numerical': 0.0022624434389140274, 'mean_word_length': 3.713632901751714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '407198', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1991, 'n_words': 518}