gmaps4rails 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  module Gmaps4rails
2
2
  class GmapsController < ApplicationController
3
- #unloadable
3
+ unloadable
4
+
4
5
  def index
5
6
  @model = params["model"]
6
7
  if @model.constantize.is_gmappable? == true
@@ -2,6 +2,57 @@
2
2
  <meta name="viewport" content="initial-scale=1.0, user-scalable=yes" />
3
3
  <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
4
4
  <script type="text/javascript" src="/javascripts/gmaps4rails.js"> </script>
5
+ <script type="text/javascript" src="/javascripts/gmaps4rails.js">
6
+ var gmaps4rails_map;
7
+ var gmaps4rails_Options;
8
+ var gmaps4rails_ctaLayer;
9
+ var gmaps4rails_model;
10
+
11
+ function gmaps4rails_init(model) {
12
+ gmaps4rails_model = model;
13
+ var myLatLng = new google.maps.LatLng(0,0);
14
+ gmaps4rails_Options = {
15
+ zoom: 2,
16
+ center: myLatLng,
17
+ mapTypeId: google.maps.MapTypeId.ROADMAP
18
+ }
19
+ gmaps4rails_map = new google.maps.Map(document.getElementById("gmaps4rails_canvas"), gmaps4rails_Options);
20
+ create_map();
21
+ }
22
+
23
+ function create_map(filter_value) {
24
+ var date = new Date();
25
+ //adding the date (which is a unique parameter, enables to bypass google map's cache on google server)
26
+ var request = 'http://furious-robot-66.heroku.com/gmaps.xml?model=' + gmaps4rails_model + '&time=' + date.getTime();
27
+ if (!(filter_value == null))
28
+ {
29
+ split_filter_value = filter_value.split('+');
30
+ if (!(split_filter_value[0] == null))
31
+ {
32
+ request += '&filter=' + split_filter_value[0];
33
+ }
34
+ if (!(split_filter_value[1] == null))
35
+ {
36
+ request += '&options=' + split_filter_value[1];
37
+ }
38
+ }
39
+ alert(request); //TODO remove for real production
40
+ gmaps4rails_ctaLayer = new google.maps.KmlLayer(request);
41
+ gmaps4rails_ctaLayer.setMap(gmaps4rails_map);
42
+ }
43
+
44
+ function gmaps4rails_raz(){
45
+ gmaps4rails_map = new google.maps.Map(document.getElementById("gmaps4rails_canvas"), gmaps4rails_myOptions);
46
+ }
47
+
48
+ function gmaps4rails_resfreshmap()
49
+ {
50
+ gmaps4rails_raz();
51
+ var index = document.gmaps4rails_form.gmaps4rails_list.selectedIndex;
52
+ var filter_value = document.gmaps4rails_form.gmaps4rails_list.options[index].value;
53
+ create_map(filter_value);
54
+ }
55
+ </script>
5
56
  <% end %>
6
57
 
7
58
  <div id="gmaps4rails_canvas" style="width:100%; height:100%"></div>
@@ -26,28 +26,28 @@ module Gmaps4rails
26
26
  module InstanceMethods
27
27
 
28
28
  def get_coordinates
29
- if self.adress.nil? || self.adress == ""
30
- self.gmaps = false
31
- else
32
- geocoder = "http://maps.google.com/maps/geo?q="
33
- output = "&output=csv"
34
- #send request to the google api to get the lat/lng
35
- request = geocoder + self.adress + output
36
- url = URI.escape(request)
37
- resp = Net::HTTP.get_response(URI.parse(url))
38
- #parse result if result received properly
39
- if resp.inspect.include?('HTTPOK 200 OK')
40
- fields = resp.body.split(',')
41
- self.gmaps4rails_latitude = fields[2]
42
- self.gmaps4rails_longitude = fields[3]
43
- #saves a boolean to remind the status
44
- self.gmaps = true
45
- else
46
- self.gmaps = false
47
- end
48
- end
49
- return true
29
+ if self.adress.nil? || self.adress == ""
30
+ self.gmaps = false
31
+ else
32
+ geocoder = "http://maps.google.com/maps/geo?q="
33
+ output = "&output=csv"
34
+ #send request to the google api to get the lat/lng
35
+ request = geocoder + self.adress + output
36
+ url = URI.escape(request)
37
+ resp = Net::HTTP.get_response(URI.parse(url))
38
+ #parse result if result received properly
39
+ if resp.inspect.include?('HTTPOK 200 OK')
40
+ fields = resp.body.split(',')
41
+ self.gmaps4rails_latitude = fields[2]
42
+ self.gmaps4rails_longitude = fields[3]
43
+ #saves a boolean to remind the status
44
+ self.gmaps = true
45
+ else
46
+ self.gmaps = false
50
47
  end
48
+ end
49
+ return true
50
+ end
51
51
  end # InstanceMethods
52
52
  end
53
53
  end
data/lib/engine.rb CHANGED
@@ -1,18 +1,17 @@
1
- require 'gmaps4rails'
2
1
  require 'rails'
3
2
  require 'action_controller'
4
3
  require 'application_helper'
4
+ require 'acts_as_gmappable/base'
5
+ require 'gmaps4rails'
5
6
 
6
7
  module Gmaps4rails
7
8
  class Engine < Rails::Engine
8
-
9
9
  # Config defaults
10
10
  config.widget_factory_name = "gmaps4rails"
11
11
  config.mount_at = '/'
12
12
 
13
13
  # Check the gem config
14
14
  initializer "check config" do |app|
15
-
16
15
  # make sure mount_at ends with trailing slash
17
16
  config.mount_at += '/' unless config.mount_at.last == '/'
18
17
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmaps4rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Benjamin Roth