<commit_before>module Cloudkicker
  class Map
    include Cloudkicker::ControlElements
    include Cloudkicker::MapLocation
    include Cloudkicker::MapBookmarking
    include Cloudkicker::MapEvents
    
    def initialize(options={})
      configure
      map:
        lat:                      
        long:                     
        map_control:              
        map_control_type:         
        zoom:                     
        style_id:                 
        bounds:                   
        bound_zoom:               
        enable_bookmarking:       
        ajax_markers:             
        ajax_url:                 
        markers:                  
        scroll_wheel_zoom_enabled:
      
      
      
      @lat                       = options.delete(:lat)                || @ck_config['map']['lat']
      @long                      = options.delete(:long)               || @ck_config['map']['long']
      @map_control               = options.delete(:map_control)        || @ck_config['map']['map_control']['visible']
      @map_control_type          = options.delete(:map_control_type)   || @ck_config['map']['map_control']['type'].to_sym
      @zoom                      = options.delete(:zoom)               || @ck_config['map']['zoom']
      @style_id                  = options.delete(:style_id)           || @ck_config['map']['style']['id']
      @bounds                    = options.delete(:bounds)             || @ck_config['map']['bounds']['enabled']
      @bound_points              = options.delete(:points)             || 0
      if @bounds && @bound_points == 0
        raise "You must provide at least one point (via :bound_points) if you are using bounds set to true"
      end
      @bound_zoom                = options.delete(:bound_zoom)         || @ck_config['map']['bounds']['zoom'] #used when only a single point is passed to bound_points
      @enable_bookmarking        = options.delete(:enable_bookmarking) || @ck_config['map']['bookmarking']['enabled']
      @ajax_markers              = options.delete(:ajax_markers)       || @ck_config['map']['markers']['ajax']['enabled']
      @ajax_url                  = options.delete(:ajax_url)           || @ck_config['map']['markers']['ajax']['url']
      @markers                   = []
      @disable_scroll_wheel_zoom = options.delete(:disable_scroll_wheel_zoom) || @ck_config['map']['scroll_wheel_zoom']['enabled']
    end
    
    def configure
      app_root = RAILS_ROOT if defined?(RAILS_ROOT)
      @ck_config   = YAML.load( File.open("#{app_root}/config/cloud_kicker.yml", 'r') )
    end
    
    def to_js(map_id='map')
      js = []
      js << <<-JS
        <script type=\"text/javascript\" src=\"#{CLOUDMADE_SRC}\"></script>
        <script type="text/javascript">
          $(document).ready(function() {
            
            // create a new cloudmade tile object with our api key and the map style we want
            var cloudmade = new CM.Tiles.CloudMade.Web({key: '#{CLOUDMADE_API_KEY}', styleId: #{@style_id}});
            
            // create a new map object on the DOM element reference by map_id and the tile object above
            var map = new CM.Map('#{map_id}', cloudmade);
    
            // set up options here like turning on or off certain map features or setting the map center
      JS
      
      if @disableScrollWheelZoom
        js << <<-JS   
            map.disableScrollWheelZoom();
        JS
      end
      
      if @map_control
        js << add_map_control(@map_control_type)
      end
      
      js << set_map_center(@lat, @long, @zoom, @bounds, @bound_points, @bound_zoom)
      
      js << add_map_events(:ajax_markers => @ajax_markers, 
                           :enable_bookmarking => @enable_bookmarking)
      
      unless @ajax_markers
        @markers.each do |marker|
          js << marker
        end
      end
      
      js << '}); //end $(document).ready'
      
      
      if @ajax_markers
        js << add_ajax_marker_functions(@ajax_url)
      end
      
      if @enable_bookmarking
        js << add_bookmarking_functions
      end
      
      js << '</script>'
      js.join("\n")
    end
    
    def markers
      @markers
    end
    
    def bounding_box(points)
      # lats  = []
      # longs = []
      # points.each do |point|
      #   lats  << point.latitude
      #   longs << point.longitude
      # end
      # 
      # max_lat = lats.max
      # min_lat = lats.min
      # max_long = longs.max
      # min_long = longs.min
      # 
      # north_east_lat  = max_lat  + (max_lat  - min_lat)
      # north_east_long = max_long + (max_long - min_long)
      # 
      # south_west_lat  = min_lat  - (max_lat  - min_lat)
      # south_west_long = min_long - (max_long - min_long)
      
      cloud_map_points = []
    
      points.each do |point|
        cloud_map_points << "new CM.LatLng(#{point.latitude}, #{point.longitude})"
      end
      
      "new CM.LatLngBounds(#{cloud_map_points.join(',')})"
    end
  end
  
end<commit_msg>Organize the location of functions and calls properly so that everything works properly. The javacript here is dependent on particular ordering for events to properly be caught and acted on.<commit_after>module Cloudkicker
  class Map
    include Cloudkicker::ControlElements
    include Cloudkicker::MapLocation
    include Cloudkicker::MapBookmarking
    include Cloudkicker::MapEvents
    include Cloudkicker::AjaxMarkers
    
    def initialize(options={})
      configure
      
      @lat                       = options.delete(:lat)                || @ck_config['map']['lat']
      @long                      = options.delete(:long)               || @ck_config['map']['long']
      @map_control               = options.delete(:map_control)        || @ck_config['map']['map_control']['visible']
      @map_control_type          = options.delete(:map_control_type)   || @ck_config['map']['map_control']['type'].to_sym
      @zoom                      = options.delete(:zoom)               || @ck_config['map']['zoom']
      @style_id                  = options.delete(:style_id)           || @ck_config['map']['style']['id']
      @bounds                    = options.delete(:bounds)             || @ck_config['map']['bounds']['enabled']
      @bound_points              = options.delete(:points)             || 0
      if @bounds && @bound_points == 0
        raise "You must provide at least one point (via :bound_points) if you are using bounds set to true"
      end
      @bound_zoom                = options.delete(:bound_zoom)         || @ck_config['map']['bounds']['zoom'] #used when only a single point is passed to bound_points
      @enable_bookmarking        = options.delete(:enable_bookmarking) || @ck_config['map']['bookmarking']['enabled']
      @ajax_markers              = options.delete(:ajax_markers)       || @ck_config['map']['markers']['ajax']['enabled']
      @ajax_url                  = options.delete(:ajax_url)           || @ck_config['map']['markers']['ajax']['url']
      @markers                   = []
      @disable_scroll_wheel_zoom = options.delete(:disable_scroll_wheel_zoom) || @ck_config['map']['scroll_wheel_zoom']['enabled']
    end
    
    def configure
      app_root = RAILS_ROOT if defined?(RAILS_ROOT)
      @ck_config   = YAML.load( File.open("#{app_root}/config/cloud_kicker.yml", 'r') )
    end
    
    def to_js(map_id='map')
      js = []
      # get the cloudmade map js
      js << <<-JS
        <script type=\"text/javascript\" src=\"#{CLOUDMADE_SRC}\"></script>
      JS

      # create the script that will create and manage the map
      js << <<-JS
        <script type="text/javascript">
          $(document).ready(function() {
            
            // create a new cloudmade tile object with our api key and the map style we want
            var cloudmade = new CM.Tiles.CloudMade.Web({key: '#{CLOUDMADE_API_KEY}', styleId: #{@style_id}});
            
            // create a new map object on the DOM element reference by map_id and the tile object above
            var map = new CM.Map('#{map_id}', cloudmade);
    
            // set up the array of added markers for use later
            var addedMarkers = [];
    
            // set up options here like turning on or off certain map features or setting the map center
      JS
      
      if @disableScrollWheelZoom
        js << <<-JS   
            map.disableScrollWheelZoom();
        JS
      end
      
      if @map_control
        js << add_map_control(@map_control_type)
      end
      
      # add listenters for events
      js << add_events(:ajax_markers => @ajax_markers, 
                       :enable_bookmarking => @enable_bookmarking)
      
      # set center of map properly 
      # (must come after any listeners for map load - setting the center is what triggers the event it)
      js << set_map_center(@lat, @long, @zoom, @bounds, @bound_points, @bound_zoom)
      
      
      unless @ajax_markers
        @markers.each do |marker|
          js << marker
        end
      end
      
      # add the functions we'll need (for events, etc)
      if @ajax_markers
        js << add_ajax_marker_functions(@ajax_url)
      end
      
      if @enable_bookmarking
        js << add_bookmarking_functions
      end
      
      js << '}); //end $(document).ready'
      
      js << '</script>'
      js.join("\n")
    end
    
    def markers
      @markers
    end
    
    def bounding_box(points)
      # lats  = []
      # longs = []
      # points.each do |point|
      #   lats  << point.latitude
      #   longs << point.longitude
      # end
      # 
      # max_lat = lats.max
      # min_lat = lats.min
      # max_long = longs.max
      # min_long = longs.min
      # 
      # north_east_lat  = max_lat  + (max_lat  - min_lat)
      # north_east_long = max_long + (max_long - min_long)
      # 
      # south_west_lat  = min_lat  - (max_lat  - min_lat)
      # south_west_long = min_long - (max_long - min_long)
      
      cloud_map_points = []
    
      points.each do |point|
        cloud_map_points << "new CM.LatLng(#{point.latitude}, #{point.longitude})"
      end
      
      "new CM.LatLngBounds(#{cloud_map_points.join(',')})"
    end
  end
  
end
{'fraction_non_alphanumeric': 0.11724608043626449, 'fraction_numerical': 0.00038952186191449994, 'mean_word_length': 1.831541218637993, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 15, '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': '3489001', 'n_tokens_mistral': 3003, 'n_tokens_neox': 2953, 'n_words': 664}