gmaps4rails 1.5.8 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.travis.yml +9 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +149 -0
- data/Guardfile.old +24 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +129 -0
- data/Rakefile +4 -0
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +20 -0
- data/gmaps4rails.gemspec +38 -0
- data/lib/generators/gmaps4rails/install_generator.rb +43 -0
- data/lib/generators/templates/README +2 -0
- data/lib/gmaps4rails.rb +26 -0
- data/lib/gmaps4rails/acts_as_gmappable.rb +54 -0
- data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +40 -0
- data/lib/gmaps4rails/api_wrappers/direction.rb +87 -0
- data/lib/gmaps4rails/api_wrappers/geocoder.rb +54 -0
- data/lib/gmaps4rails/api_wrappers/places.rb +74 -0
- data/lib/gmaps4rails/base.rb +126 -0
- data/lib/gmaps4rails/extensions/enumerable.rb +14 -0
- data/lib/gmaps4rails/extensions/hash.rb +9 -0
- data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +33 -0
- data/lib/gmaps4rails/js_builder.rb +154 -0
- data/lib/gmaps4rails/json_builder.rb +140 -0
- data/lib/gmaps4rails/model_handler.rb +101 -0
- data/lib/gmaps4rails/version.rb +3 -0
- data/lib/gmaps4rails/view_helper.rb +172 -0
- data/lib/tasks/jasmine.rake +8 -0
- data/public/javascripts/gmaps4rails/all.js +2144 -0
- data/public/javascripts/gmaps4rails/base.js +792 -0
- data/public/javascripts/gmaps4rails/google.js +556 -0
- data/public/javascripts/gmaps4rails/openlayers.js +377 -0
- data/public/stylesheets/gmaps4rails.css +24 -0
- data/spec/dummy/.gitignore +3 -0
- data/spec/dummy/.rspec +1 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +18 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +24 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/users_controller.rb +105 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/place.rb +16 -0
- data/spec/dummy/app/models/user.rb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +17 -0
- data/spec/dummy/app/views/users/_form.html.erb +37 -0
- data/spec/dummy/app/views/users/edit.html.erb +6 -0
- data/spec/dummy/app/views/users/index.html.erb +268 -0
- data/spec/dummy/app/views/users/new.html.erb +5 -0
- data/spec/dummy/app/views/users/show.html.erb +30 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +62 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/gmaps4rails.rb +1 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +60 -0
- data/spec/dummy/db/migrate/20120408170155_create_users.rb +16 -0
- data/spec/dummy/db/schema.rb +29 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/Player.js +22 -0
- data/spec/dummy/public/javascripts/Song.js +7 -0
- data/spec/dummy/public/logo.png +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/place_factory.rb +16 -0
- data/spec/factories/user_factory.rb +23 -0
- data/spec/fixtures/google_direction_valid.json +65 -0
- data/spec/fixtures/google_geocoding_toulon_france.json +58 -0
- data/spec/fixtures/google_places_valid.json +45 -0
- data/spec/fixtures/google_wrong_geocoding.json +4 -0
- data/spec/launchers/all_but_requests.rb +0 -0
- data/spec/launchers/all_specs.rb +0 -0
- data/spec/launchers/requests.rb +0 -0
- data/spec/lib/base_spec.rb +59 -0
- data/spec/lib/direction_spec.rb +53 -0
- data/spec/lib/geocoder_spec.rb +46 -0
- data/spec/lib/js_builder_spec.rb +134 -0
- data/spec/lib/json_builder_spec.rb +232 -0
- data/spec/lib/places_spec.rb +25 -0
- data/spec/models/place_spec.rb +39 -0
- data/spec/models/user_spec.rb +187 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/geocoding.rb +40 -0
- data/spec/support/matchers.rb +73 -0
- data/todo +0 -0
- data/vendor/assets/javascripts/gmaps4rails/all.js +1 -0
- data/vendor/assets/javascripts/gmaps4rails/base.coffee +1 -0
- data/vendor/assets/javascripts/gmaps4rails/base/common.coffee +43 -0
- data/vendor/assets/javascripts/gmaps4rails/base/configuration.coffee +7 -0
- data/vendor/assets/javascripts/gmaps4rails/base/gmaps.coffee +13 -0
- data/vendor/assets/javascripts/gmaps4rails/base/interfaces/basic_interface.coffee +15 -0
- data/vendor/assets/javascripts/gmaps4rails/base/interfaces/controller_interface.coffee +15 -0
- data/vendor/assets/javascripts/gmaps4rails/base/interfaces/map_interface.coffee +27 -0
- data/vendor/assets/javascripts/gmaps4rails/base/interfaces/marker_interface.coffee +15 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main.coffee +124 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/circle_controller.coffee +29 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/kml_controller.coffee +5 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/marker_controller.coffee +76 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polygon_controller.coffee +29 -0
- data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polyline_controller.coffee +29 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/circle.coffee +12 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/kml.coffee +8 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/map.coffee +62 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/marker.coffee +24 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/polygon.coffee +11 -0
- data/vendor/assets/javascripts/gmaps4rails/base/objects/polyline.coffee +11 -0
- data/vendor/assets/javascripts/gmaps4rails/bing.coffee +1 -0
- data/vendor/assets/javascripts/gmaps4rails/bing/main.coffee +29 -0
- data/vendor/assets/javascripts/gmaps4rails/bing/objects/map.coffee +63 -0
- data/vendor/assets/javascripts/gmaps4rails/bing/objects/marker.coffee +78 -0
- data/vendor/assets/javascripts/gmaps4rails/bing/shared.coffee +20 -0
- data/vendor/assets/javascripts/gmaps4rails/google.coffee +1 -0
- data/vendor/assets/javascripts/gmaps4rails/google/main.coffee +47 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/circle.coffee +38 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/kml.coffee +16 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/map.coffee +71 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/marker.coffee +114 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/polygon.coffee +38 -0
- data/vendor/assets/javascripts/gmaps4rails/google/objects/polyline.coffee +49 -0
- data/vendor/assets/javascripts/gmaps4rails/google/shared.coffee +27 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers.coffee +1 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers/main.coffee +138 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/map.coffee +49 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/marker.coffee +68 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/polyline.coffee +39 -0
- data/vendor/assets/javascripts/gmaps4rails/openlayers/shared.coffee +19 -0
- metadata +378 -14
- checksums.yaml +0 -7
@@ -0,0 +1,13 @@
|
|
1
|
+
@Gmaps =
|
2
|
+
triggerOldOnload: ->
|
3
|
+
window.Gmaps.oldOnload() if typeof(window.Gmaps.oldOnload) == 'function'
|
4
|
+
|
5
|
+
loadMaps: ->
|
6
|
+
#loop through all variable names.
|
7
|
+
#there should only be maps inside so it trigger their load function
|
8
|
+
for key, value of window.Gmaps
|
9
|
+
#console.log key, searchLoadIncluded
|
10
|
+
if /^load_/.test(key)
|
11
|
+
#load_function_name = "load_" + key
|
12
|
+
window.Gmaps[key]()
|
13
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gmaps4Rails.Interfaces ||= {}
|
2
|
+
|
3
|
+
Gmaps4Rails.Interfaces.Basic =
|
4
|
+
|
5
|
+
clear: ()->
|
6
|
+
throw "clear should be implemented"
|
7
|
+
|
8
|
+
show: () ->
|
9
|
+
throw "show should be implemented"
|
10
|
+
|
11
|
+
hide: () ->
|
12
|
+
throw "hide should be implemented"
|
13
|
+
|
14
|
+
isVisible: ->
|
15
|
+
throw "hide should be implemented"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gmaps4Rails.Interfaces ||= {}
|
2
|
+
|
3
|
+
Gmaps4Rails.Interfaces.Controller =
|
4
|
+
|
5
|
+
# module is the namespace of the map provider you implement, ie: Gmaps4Rails.Google
|
6
|
+
getModule: ->
|
7
|
+
throw "getModule should be implemented in controller"
|
8
|
+
|
9
|
+
# This method should create and return a clusterer object
|
10
|
+
createClusterer : (markers_array) ->
|
11
|
+
throw "createClusterer should be implemented in controller"
|
12
|
+
|
13
|
+
# this method should reset the clusterer
|
14
|
+
clearClusterer : ->
|
15
|
+
throw "clearClusterer should be implemented in controller"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Gmaps4Rails.Interfaces ||= {}
|
2
|
+
|
3
|
+
Gmaps4Rails.Interfaces.Map =
|
4
|
+
|
5
|
+
extendBoundsWithMarker : (marker) ->
|
6
|
+
throw "extendBoundsWithMarker should be implemented in controller"
|
7
|
+
|
8
|
+
extendBoundsWithPolyline: (polyline)->
|
9
|
+
throw "extendBoundsWithPolyline should be implemented in controller"
|
10
|
+
|
11
|
+
extendBoundsWithPolygon: (polygon)->
|
12
|
+
throw "extendBoundsWithPolygon should be implemented in controller"
|
13
|
+
|
14
|
+
extendBoundsWithCircle: (circle)->
|
15
|
+
throw "extendBoundsWithCircle should be implemented in controller"
|
16
|
+
|
17
|
+
extendBound: (bound)->
|
18
|
+
throw "extendBound should be implemented in controller"
|
19
|
+
|
20
|
+
adaptToBounds:()->
|
21
|
+
throw "adaptToBounds should be implemented in controller"
|
22
|
+
|
23
|
+
fitBounds : ->
|
24
|
+
throw "fitBounds should be implemented in controller"
|
25
|
+
|
26
|
+
centerMapOnUser : (position)->
|
27
|
+
throw "centerMapOnUser should be implemented in controller"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Gmaps4Rails.Interfaces ||= {}
|
2
|
+
|
3
|
+
Gmaps4Rails.Interfaces.Marker =
|
4
|
+
|
5
|
+
createInfoWindow : () ->
|
6
|
+
throw "createInfoWindow should be implemented in marker"
|
7
|
+
|
8
|
+
clear: ()->
|
9
|
+
throw "clear should be implemented in marker"
|
10
|
+
|
11
|
+
show: () ->
|
12
|
+
throw "show should be implemented in marker"
|
13
|
+
|
14
|
+
hide: () ->
|
15
|
+
throw "hide should be implemented in marker"
|
@@ -0,0 +1,124 @@
|
|
1
|
+
#= require './common'
|
2
|
+
#= require './configuration'
|
3
|
+
#= require './gmaps'
|
4
|
+
|
5
|
+
#= require_tree './objects'
|
6
|
+
#= require_tree './main_controller_extensions'
|
7
|
+
#= require_tree './interfaces'
|
8
|
+
|
9
|
+
class @Gmaps4Rails.BaseController extends Gmaps4Rails.Common
|
10
|
+
|
11
|
+
@include Gmaps4Rails.MarkerController
|
12
|
+
@include Gmaps4Rails.PolylineController
|
13
|
+
@include Gmaps4Rails.PolygonController
|
14
|
+
@include Gmaps4Rails.CircleController
|
15
|
+
@include Gmaps4Rails.KmlController
|
16
|
+
|
17
|
+
@include Gmaps4Rails.Interfaces.Controller
|
18
|
+
|
19
|
+
visibleInfoWindow: null #contains the current opened infowindow
|
20
|
+
userLocation: null #contains user's location if geolocalization was performed and successful
|
21
|
+
|
22
|
+
#empty slots
|
23
|
+
afterMapInitialization: -> false
|
24
|
+
geolocationSuccess: -> false
|
25
|
+
geolocationFailure: -> false #triggered when geolocation fails. If customized, must be like= function(navigator_handles_geolocation){} where 'navigator_handles_geolocation' is a boolean
|
26
|
+
callback: -> false #to let user set a custom callback function
|
27
|
+
customClusterer: -> false #to let user set custom clusterer pictures
|
28
|
+
infobox: -> false #to let user use custom infoboxes
|
29
|
+
jsTemplate: false #to let user create infowindows client side
|
30
|
+
|
31
|
+
|
32
|
+
#Stored variables
|
33
|
+
map_options: {} # deleted once map is created
|
34
|
+
markers: [] # contains all markers. A marker contains the following: {"description": , "longitude": , "title":, "latitude":, "picture": "", "width": "", "length": "", "sidebar": "", "serviceObject": google_marker}
|
35
|
+
boundsObject: null # contains current bounds from markers, polylines etc...
|
36
|
+
polygons: [] # contains raw data, array of arrays (first element could be a hash containing options)
|
37
|
+
polylines: [] # contains raw data, array of arrays (first element could be a hash containing options)
|
38
|
+
circles: [] # contains raw data, array of hash
|
39
|
+
markerClusterer: null # contains all marker clusterers
|
40
|
+
markerImages: []
|
41
|
+
kmls: []
|
42
|
+
rootModule: null
|
43
|
+
|
44
|
+
constructor: ->
|
45
|
+
@rootModule = @getModule()
|
46
|
+
@markers_conf = @rootModule.Marker.setConf() if @rootModule.Marker?
|
47
|
+
@polylines_conf = @rootModule.Polyline.setConf() if @rootModule.Polyline?
|
48
|
+
@polygons_conf = @rootModule.Polygon.setConf() if @rootModule.Polygon?
|
49
|
+
@circles_conf = @rootModule.Circle.setConf() if @rootModule.Circle?
|
50
|
+
|
51
|
+
#////////////////////////////////////////////////////
|
52
|
+
#/////////////// Basic Objects //////////////
|
53
|
+
#////////////////////////////////////////////////////
|
54
|
+
|
55
|
+
createMap : ->
|
56
|
+
new @rootModule.Map(@map_options, @)
|
57
|
+
|
58
|
+
createMarker: (args)->
|
59
|
+
new @rootModule.Marker(args, @)
|
60
|
+
|
61
|
+
createPolyline: (args)->
|
62
|
+
new @rootModule.Polyline(args, @)
|
63
|
+
|
64
|
+
createPolygon: (args)->
|
65
|
+
new @rootModule.Polygon(args, @)
|
66
|
+
|
67
|
+
createCircle: (args)->
|
68
|
+
new @rootModule.Circle(args, @)
|
69
|
+
|
70
|
+
createKml: (args)->
|
71
|
+
new @rootModule.Kml(args, @)
|
72
|
+
|
73
|
+
#///////////////////////////////////
|
74
|
+
#/////////////// Map //////////////
|
75
|
+
#///////////////////////////////////
|
76
|
+
|
77
|
+
initialize : ->
|
78
|
+
detectUserLocation = @map_options.detect_location or @map_options.center_on_user
|
79
|
+
center_on_user = @map_options.center_on_user
|
80
|
+
@map = @createMap()
|
81
|
+
@afterMapInitialization()
|
82
|
+
|
83
|
+
delete @map_options
|
84
|
+
|
85
|
+
if detectUserLocation
|
86
|
+
@findUserLocation(this, center_on_user)
|
87
|
+
|
88
|
+
getMapObject: ->
|
89
|
+
@map.serviceObject
|
90
|
+
|
91
|
+
adjustMapToBounds: ->
|
92
|
+
@map.adjustToBounds() if @map.autoAdjustRequested()
|
93
|
+
|
94
|
+
#////////////////////////////////////////////////////
|
95
|
+
#/////////////// Miscellaneous //////////////
|
96
|
+
#////////////////////////////////////////////////////
|
97
|
+
|
98
|
+
clusterize : ->
|
99
|
+
if @markers_conf.do_clustering
|
100
|
+
#first clear the existing clusterer if any
|
101
|
+
@clearClusterer() if @markerClusterer?
|
102
|
+
|
103
|
+
markers_array = []
|
104
|
+
for marker in @markers
|
105
|
+
markers_array.push(marker.serviceObject)
|
106
|
+
|
107
|
+
@markerClusterer = @createClusterer(markers_array)
|
108
|
+
|
109
|
+
findUserLocation : (controller, center_on_user) ->
|
110
|
+
if navigator.geolocation
|
111
|
+
#try to retrieve user's position
|
112
|
+
positionSuccessful = (position) ->
|
113
|
+
controller.userLocation = controller.createLatLng(position.coords.latitude, position.coords.longitude)
|
114
|
+
#change map's center to focus on user's geoloc if asked
|
115
|
+
controller.geolocationSuccess()
|
116
|
+
if center_on_user
|
117
|
+
controller.map.centerMapOnUser(controller.userLocation)
|
118
|
+
positionFailure = (error)->
|
119
|
+
controller.geolocationFailure(true)
|
120
|
+
|
121
|
+
navigator.geolocation.getCurrentPosition( positionSuccessful, positionFailure)
|
122
|
+
else
|
123
|
+
#failure but the navigator doesn't handle geolocation
|
124
|
+
controller.geolocationFailure(false)
|
data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/circle_controller.coffee
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
@Gmaps4Rails.CircleController =
|
2
|
+
|
3
|
+
#polygons is an array of arrays. It loops.
|
4
|
+
addCircles: (circleData)->
|
5
|
+
for circleArgs in circleData
|
6
|
+
@circles.push @createCircle(circleArgs)
|
7
|
+
|
8
|
+
replaceCircles : (circleData) ->
|
9
|
+
#reset previous polylines and kill them from map
|
10
|
+
@clearCircles()
|
11
|
+
#set new polylines
|
12
|
+
@addCircles(circleData)
|
13
|
+
#.... and adjust map boundaries
|
14
|
+
@adjustMapToBounds()
|
15
|
+
|
16
|
+
clearCircles : ->
|
17
|
+
for circle in @circles
|
18
|
+
#delete polylines from map
|
19
|
+
circle.clear()
|
20
|
+
#empty array
|
21
|
+
@circles = []
|
22
|
+
|
23
|
+
showCircles : ->
|
24
|
+
for circle in @circles
|
25
|
+
circle.show()
|
26
|
+
|
27
|
+
hideCircles : ->
|
28
|
+
for circle in @circles
|
29
|
+
circle.hide()
|
data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/marker_controller.coffee
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
@Gmaps4Rails.MarkerController =
|
2
|
+
|
3
|
+
addMarkers: (markersData)->
|
4
|
+
@clearClusterer() if @markerClusterer?
|
5
|
+
|
6
|
+
for markerData, index in markersData
|
7
|
+
#unless markerData.serviceObject?
|
8
|
+
|
9
|
+
lat = markerData.lat
|
10
|
+
lng = markerData.lng
|
11
|
+
|
12
|
+
if @markers_conf.randomize
|
13
|
+
latLng = @randomize(lat, lng)
|
14
|
+
#retrieve coordinates from the array
|
15
|
+
lat = latLng[0]
|
16
|
+
lng = latLng[1]
|
17
|
+
|
18
|
+
newMarker = @createMarker
|
19
|
+
"marker_picture": if markerData.picture then markerData.picture else @markers_conf.picture
|
20
|
+
"marker_width": if markerData.width then markerData.width else @markers_conf.width
|
21
|
+
"marker_height": if markerData.height then markerData.height else @markers_conf.length
|
22
|
+
"marker_title": if markerData.title then markerData.title else null
|
23
|
+
"marker_anchor": if markerData.marker_anchor then markerData.marker_anchor else null
|
24
|
+
"shadow_anchor": if markerData.shadow_anchor then markerData.shadow_anchor else null
|
25
|
+
"shadow_picture": if markerData.shadow_picture then markerData.shadow_picture else null
|
26
|
+
"shadow_width": if markerData.shadow_width then markerData.shadow_width else null
|
27
|
+
"shadow_height": if markerData.shadow_height then markerData.shadow_height else null
|
28
|
+
"marker_draggable": if markerData.draggable then markerData.draggable else @markers_conf.draggable
|
29
|
+
"rich_marker": if markerData.rich_marker then markerData.rich_marker else null
|
30
|
+
"zindex": if markerData.zindex then markerData.zindex else null
|
31
|
+
"lat": lat
|
32
|
+
"lng": lng
|
33
|
+
"index": index
|
34
|
+
|
35
|
+
|
36
|
+
Gmaps4Rails.Common.mergeWith.call(newMarker, markerData)
|
37
|
+
#add infowindowstuff if enabled
|
38
|
+
newMarker.createInfoWindow()
|
39
|
+
|
40
|
+
@markers.push newMarker
|
41
|
+
|
42
|
+
@clusterize()
|
43
|
+
|
44
|
+
#replace old markers with new markers on an existing map
|
45
|
+
replaceMarkers : (new_markers) ->
|
46
|
+
@clearMarkers()
|
47
|
+
#reset previous markers
|
48
|
+
@markers = []
|
49
|
+
#reset current bounds
|
50
|
+
@boundsObject = @createLatLngBounds()
|
51
|
+
#add new markers
|
52
|
+
@addMarkers(new_markers)
|
53
|
+
|
54
|
+
#clear markers
|
55
|
+
clearMarkers : ->
|
56
|
+
@clearClusterer() if @markerClusterer?
|
57
|
+
for marker in @markers
|
58
|
+
marker.clear()
|
59
|
+
@markers = []
|
60
|
+
|
61
|
+
#show and hide markers
|
62
|
+
showMarkers : ->
|
63
|
+
for marker in @markers
|
64
|
+
marker.show()
|
65
|
+
|
66
|
+
hideMarkers : ->
|
67
|
+
for marker in @markers
|
68
|
+
marker.hide()
|
69
|
+
|
70
|
+
randomize : (Lat0, Lng0) ->
|
71
|
+
#distance in meters between 0 and max_random_distance (positive or negative)
|
72
|
+
dx = @markers_conf.max_random_distance * @random()
|
73
|
+
dy = @markers_conf.max_random_distance * @random()
|
74
|
+
Lat = parseFloat(Lat0) + (180/Math.PI)*(dy/6378137)
|
75
|
+
Lng = parseFloat(Lng0) + ( 90/Math.PI)*(dx/6378137)/Math.cos(Lat0)
|
76
|
+
return [Lat, Lng]
|
data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polygon_controller.coffee
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
@Gmaps4Rails.PolygonController =
|
2
|
+
|
3
|
+
#polygons is an array of arrays. It loops.
|
4
|
+
addPolygons: (polygonData)->
|
5
|
+
for polygonArgs in polygonData
|
6
|
+
@polygons.push @createPolygon(polygonArgs)
|
7
|
+
|
8
|
+
replacePolygons : (polylineData) ->
|
9
|
+
#reset previous polylines and kill them from map
|
10
|
+
@clearPolygons()
|
11
|
+
#set new polylines
|
12
|
+
@addPolygons(polylineData)
|
13
|
+
#.... and adjust map boundaries
|
14
|
+
@adjustMapToBounds()
|
15
|
+
|
16
|
+
clearPolygons : ->
|
17
|
+
for polygon in @polygons
|
18
|
+
#delete polylines from map
|
19
|
+
polygon.clear()
|
20
|
+
#empty array
|
21
|
+
@polygons = []
|
22
|
+
|
23
|
+
showPolygons : ->
|
24
|
+
for polygon in @polygons
|
25
|
+
polygon.show()
|
26
|
+
|
27
|
+
hidePolygons : ->
|
28
|
+
for polygon in @polygons
|
29
|
+
polygon.hide()
|
@@ -0,0 +1,29 @@
|
|
1
|
+
@Gmaps4Rails.PolylineController =
|
2
|
+
|
3
|
+
replacePolylines : (polylineData) ->
|
4
|
+
#reset previous polylines and kill them from map
|
5
|
+
@clearPolylines()
|
6
|
+
#set new polylines
|
7
|
+
@addPolylines(polylineData)
|
8
|
+
#.... and adjust map boundaries
|
9
|
+
@adjustMapToBounds()
|
10
|
+
|
11
|
+
clearPolylines : ->
|
12
|
+
for polyline in @polylines
|
13
|
+
#delete polylines from map
|
14
|
+
polyline.clear()
|
15
|
+
#empty array
|
16
|
+
@polylines = []
|
17
|
+
|
18
|
+
#polylines is an array of arrays. It loops.
|
19
|
+
addPolylines: (polylineData)->
|
20
|
+
for polylineArgs in polylineData
|
21
|
+
@polylines.push @createPolyline(polylineArgs)
|
22
|
+
|
23
|
+
showPolylines : ->
|
24
|
+
for polyline in @polylines
|
25
|
+
polyline.show()
|
26
|
+
|
27
|
+
hidePolylines : ->
|
28
|
+
for polyline in @polylines
|
29
|
+
polyline.hide()
|
@@ -0,0 +1,62 @@
|
|
1
|
+
@Gmaps4Rails.Map =
|
2
|
+
|
3
|
+
DEFAULT_CONF:
|
4
|
+
id: 'map'
|
5
|
+
draggable: true
|
6
|
+
detect_location: false # should the browser attempt to use geolocation detection features of HTML5?
|
7
|
+
center_on_user: false # centers map on the location detected through the browser
|
8
|
+
center_latitude: 0
|
9
|
+
center_longitude: 0
|
10
|
+
zoom: 7
|
11
|
+
maxZoom: null
|
12
|
+
minZoom: null
|
13
|
+
auto_adjust : true # adjust the map to the markers if set to true
|
14
|
+
auto_zoom: true # zoom given by auto-adjust
|
15
|
+
bounds: [] # adjust map to these limits. Should be [{"lat": , "lng": }]
|
16
|
+
raw: {} # raw json to pass additional options
|
17
|
+
|
18
|
+
#to make the map fit the different LatLng points
|
19
|
+
adjustToBounds : ->
|
20
|
+
#reset previous bounds
|
21
|
+
@boundsObject = @createLatLngBounds()
|
22
|
+
|
23
|
+
#from markers
|
24
|
+
@extendBoundsWithMarkers()
|
25
|
+
|
26
|
+
#from polylines:
|
27
|
+
@extendBoundsWithPolylines()
|
28
|
+
|
29
|
+
#from polygons:
|
30
|
+
@extendBoundsWithPolygons()
|
31
|
+
|
32
|
+
#from circles
|
33
|
+
@extendBoundsWithCircles()
|
34
|
+
|
35
|
+
#in every case, I've to take into account the bounds set up by the user
|
36
|
+
@extendBoundsWithLatLng()
|
37
|
+
|
38
|
+
#SECOND_STEP: ajust the map to the bounds
|
39
|
+
@adaptToBounds()
|
40
|
+
|
41
|
+
extendBoundsWithMarkers : ->
|
42
|
+
for marker in @controller.markers
|
43
|
+
@extendBoundsWithMarker(marker) if marker.isVisible()
|
44
|
+
|
45
|
+
extendBoundsWithPolylines: ()->
|
46
|
+
for polyline in @controller.polylines
|
47
|
+
@extendBoundsWithPolyline(polyline) #if polyline.isVisible()
|
48
|
+
|
49
|
+
extendBoundsWithPolygons: ()->
|
50
|
+
for polygon in @controller.polygons
|
51
|
+
@extendBoundsWithPolygon(polygon) #if polygon.isVisible()
|
52
|
+
|
53
|
+
extendBoundsWithCircles: ()->
|
54
|
+
for circle in @controller.circles
|
55
|
+
@extendBoundsWithCircle(circle) #if circle.isVisible()
|
56
|
+
|
57
|
+
extendBoundsWithLatLng: ()->
|
58
|
+
for bound in @options.bounds
|
59
|
+
@extendBound bound
|
60
|
+
|
61
|
+
autoAdjustRequested: ->
|
62
|
+
@options.auto_adjust or @options.bounds.length > 0
|