rails-marker 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ec6ae65ce3f7aec3a36cc96793768d17dc5e74cb
4
- data.tar.gz: bb269d5807c2caf2c18526a963fdb75c2c804321
2
+ SHA256:
3
+ metadata.gz: da6f80ba26d842eb913f298d647d3ae21588f5fe440c8aa2eda0538a8ae55fd0
4
+ data.tar.gz: 487b0f7160ce7cfd8ff789cfa8c1c77c1a321b79266431378d5526b02f383b8e
5
5
  SHA512:
6
- metadata.gz: c08631be597aa235db3558b0cc401e48a2ca0672296805f74261cc1e5f500ef6be38df2a80be95608a8546994f4d951a4a7fe7024af55e3d115618ca8c990f90
7
- data.tar.gz: fc5e6b1a7ed6888011d10517c5dbe9d6cae80a735e7dd8ba17418bb42eaedfc70204224d13c7cefb76d6a3b36d85dafa8964134ea27a80944e7d417426abe344
6
+ metadata.gz: 5cedf637c1472a4041282c371a5e1f8a57ec9b8fe8dd9ecef3c9c5a6a0daf9f2791b635cb3f5d6151e2d2feab67110f792da0864a3c341a43d9654b2e4bf9a0a
7
+ data.tar.gz: 5fccc7147dd2d35a1a73aea74467538f4413a818340da50ee553d06c171347ca877f1430e5933cb931d14b4ef0238752c7f908298b8de67e01adba96dc4d9291
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2012 Aimbulance http://www.aimbulance.com/
1
+ Copyright 2017 Fodojo LLC
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -58,7 +58,10 @@ And you want edit fields zoom, longitude and latitude:
58
58
  <%= form_for @office do |f| %>
59
59
  <%= f.text_field :longitude, data: { map: 'lng' } %>
60
60
  <%= f.text_field :latitude, data: { map: 'lat' } %>
61
+
62
+ // Optional fields
61
63
  <%= f.text_field :zoom, data: { map: 'zoom' } %>
64
+ <%= f.text_field :radius, data: { map: 'radius' } %>
62
65
 
63
66
  <%= f.marker_field :map %>
64
67
  <% end %>
@@ -68,6 +71,19 @@ It's all you need! Just move the marker, and zoom, latitude and longitude fields
68
71
 
69
72
  ![Marker field in use](https://raw.githubusercontent.com/galetahub/rails-marker/master/screenshots/rails-marker-in-use.png)
70
73
 
74
+ ### ActiveAdmin
75
+
76
+ Formtastic integration
77
+
78
+ ``` ruby
79
+ f.inputs name: 'Location', for: [:location, f.object.location || f.object.build_location] do |loc|
80
+ loc.input :latitude, input_html: { data: { map: 'lat' } }
81
+ loc.input :longitude, input_html: { data: { map: 'lng' } }
82
+ loc.input :content, input_html: { rows: 2 }
83
+ loc.input :map, as: :marker, google_api_key: 'your_google_api_key'
84
+ end
85
+ ```
86
+
71
87
  ## Contributing
72
88
 
73
89
  1. Fork it
@@ -76,4 +92,4 @@ It's all you need! Just move the marker, and zoom, latitude and longitude fields
76
92
  4. Push to the branch (`git push origin my-new-feature`)
77
93
  5. Create new Pull Request
78
94
 
79
- Copyright (c) 2017 Fodojo, released under the MIT license
95
+ Copyright (c) 2017 Fodojo LLC, released under the MIT license
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
@@ -0,0 +1,15 @@
1
+ (function() {
2
+ var initMarkerMap;
3
+
4
+ initMarkerMap = function() {
5
+ var elements;
6
+ elements = document.querySelectorAll('[data-marker]');
7
+ return elements.forEach(function(el, index, array) {
8
+ var map;
9
+ map = new MapGoogle(el);
10
+ return $(el).data('map', map);
11
+ });
12
+ };
13
+
14
+ window['initMarkerMap'] = initMarkerMap;
15
+ }).call(this);
@@ -0,0 +1,146 @@
1
+ (function() {
2
+ var $, MapGoogle;
3
+
4
+ $ = jQuery;
5
+
6
+ MapGoogle = (function() {
7
+ function MapGoogle(dom, options) {
8
+ var defaults;
9
+ this.dom = dom;
10
+ if (options == null) {
11
+ options = {};
12
+ }
13
+ defaults = {
14
+ lat: 50.44067063154785,
15
+ lng: 30.52654266357422,
16
+ zoom: 6,
17
+ radius: 1000
18
+ };
19
+ this.element = $(this.dom);
20
+ this.options = $.extend(defaults, this.element.data(), options);
21
+ this.name = this.element.data('marker');
22
+ this.options.field_lat = "[data-" + this.name + "='lat']";
23
+ this.options.field_lng = "[data-" + this.name + "='lng']";
24
+ this.options.field_zoom = "[data-" + this.name + "='zoom']";
25
+ this.options.field_radius = "[data-" + this.name + "='radius']";
26
+
27
+ this._setup();
28
+ }
29
+
30
+ MapGoogle.prototype._setup = function() {
31
+ var number;
32
+
33
+ this.location = this._build_location();
34
+ this.map = this._build_map(this.element.get(0));
35
+ this.marker = this._build_marker();
36
+ this.field_lat = $(this.options.field_lat + ':eq(0)');
37
+ this.field_lng = $(this.options.field_lng + ':eq(0)');
38
+ this.field_zoom = $(this.options.field_zoom + ':eq(0)');
39
+ this.field_radius = $(this.options.field_radius + ':eq(0)');
40
+
41
+ google.maps.event.addListener(this.marker, 'dragend', (function(_this) {
42
+ return function(event) {
43
+ return _this._update_location(event)
44
+ };
45
+ })(this));
46
+ google.maps.event.addListener(this.map, 'zoom_changed', (function(_this) {
47
+ return function() {
48
+ return _this.field_zoom.val(_this.map.getZoom());
49
+ };
50
+ })(this));
51
+ if (this.field_radius.length > 0) {
52
+ number = this._parse_value(this.field_radius, this.options.radius);
53
+ this.circle = this._build_circle({
54
+ radius: number
55
+ });
56
+ return this.circle.bindTo('center', this.marker, 'position');
57
+ }
58
+ };
59
+
60
+ MapGoogle.prototype.placeMarker = function(location) {
61
+ var marker;
62
+ marker = this._build_marker({
63
+ position: location
64
+ });
65
+ this.map.setCenter(location);
66
+ return marker;
67
+ };
68
+
69
+ MapGoogle.prototype._build_location = function() {
70
+ var lat, lng;
71
+ lat = this._parse_value(this.options.field_lat, this.options.lat);
72
+ lng = this._parse_value(this.options.field_lng, this.options.lng);
73
+ return new google.maps.LatLng(lat, lng);
74
+ };
75
+
76
+ MapGoogle.prototype._build_map = function(element, options) {
77
+ var defaults, settings, zoom;
78
+ if (options == null) {
79
+ options = {};
80
+ }
81
+ zoom = this._parse_value(this.options.field_zoom, this.options.zoom);
82
+ defaults = {
83
+ zoom: zoom,
84
+ center: this.location,
85
+ mapTypeId: google.maps.MapTypeId.ROADMAP
86
+ };
87
+ settings = $.extend(defaults, options);
88
+ return new google.maps.Map(element, settings);
89
+ };
90
+
91
+ MapGoogle.prototype._build_marker = function(options) {
92
+ var defaults, settings;
93
+ if (options == null) {
94
+ options = {};
95
+ }
96
+ defaults = {
97
+ position: this.location,
98
+ map: this.map,
99
+ draggable: true
100
+ };
101
+ settings = $.extend(defaults, options);
102
+ return new google.maps.Marker(settings);
103
+ };
104
+
105
+ MapGoogle.prototype._build_circle = function(options) {
106
+ var defaults, settings;
107
+ if (options == null) {
108
+ options = {};
109
+ }
110
+ defaults = {
111
+ map: this.map,
112
+ strokeColor: '#FF0000',
113
+ strokeOpacity: 0.8,
114
+ strokeWeight: 2,
115
+ fillColor: '#FF0000',
116
+ fillOpacity: 0.35,
117
+ radius: 1000
118
+ };
119
+ settings = $.extend(defaults, options);
120
+ return new google.maps.Circle(settings);
121
+ };
122
+
123
+ MapGoogle.prototype._update_location = function(event) {
124
+ var pos = this.marker.getPosition();
125
+
126
+ this.field_lat.val(pos.lat());
127
+ this.field_lng.val(pos.lng());
128
+
129
+ return this.map.setCenter(event.latLng);
130
+ };
131
+
132
+ MapGoogle.prototype._parse_value = function(field, default_value) {
133
+ var value;
134
+ value = parseFloat($(field).val());
135
+ if (value) {
136
+ return value;
137
+ } else {
138
+ return parseFloat(default_value);
139
+ }
140
+ };
141
+
142
+ return MapGoogle;
143
+ })();
144
+
145
+ window.MapGoogle = MapGoogle;
146
+ }).call(this);
@@ -1,4 +1,4 @@
1
1
  <%= javascript_include_tag 'marker/application' %>
2
- <%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=#{Marker.google_api_key}&callback=initMarkerMap", async: true, defer: true %>
2
+ <%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=#{field.google_api_key}&callback=initMarkerMap", async: true, defer: true %>
3
3
 
4
4
  <%= content_tag :div, nil, field.input_options %>
@@ -49,6 +49,10 @@ module Marker
49
49
  def object_name
50
50
  @options[:object_name]
51
51
  end
52
+
53
+ def google_api_key
54
+ @options[:google_api_key] || Marker.google_api_key
55
+ end
52
56
  end
53
57
  end
54
58
  end
@@ -1,3 +1,3 @@
1
1
  module Marker
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,16 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-marker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Galeta
8
8
  - Pavlo Galeta
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-13 00:00:00.000000000 Z
12
+ date: 2022-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: sqlite3
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -36,8 +50,8 @@ files:
36
50
  - README.md
37
51
  - Rakefile
38
52
  - app/assets/javascripts/marker/application.js
39
- - app/assets/javascripts/marker/init.js.coffee
40
- - app/assets/javascripts/marker/map_google.js.coffee
53
+ - app/assets/javascripts/marker/init.js
54
+ - app/assets/javascripts/marker/map_google.js
41
55
  - app/views/marker/_google.html.erb
42
56
  - lib/marker.rb
43
57
  - lib/marker/engine.rb
@@ -49,9 +63,10 @@ files:
49
63
  - lib/marker/version.rb
50
64
  - lib/rails_marker.rb
51
65
  homepage: https://github.com/galetahub/rails-marker
52
- licenses: []
66
+ licenses:
67
+ - MIT
53
68
  metadata: {}
54
- post_install_message:
69
+ post_install_message:
55
70
  rdoc_options: []
56
71
  require_paths:
57
72
  - lib
@@ -66,9 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
81
  - !ruby/object:Gem::Version
67
82
  version: '0'
68
83
  requirements: []
69
- rubyforge_project:
70
- rubygems_version: 2.6.12
71
- signing_key:
84
+ rubygems_version: 3.3.7
85
+ signing_key:
72
86
  specification_version: 4
73
87
  summary: Easy way to edit zoom, longitude and latitude
74
88
  test_files: []
@@ -1,7 +0,0 @@
1
- initMarkerMap = () ->
2
- elements = document.querySelectorAll('[data-marker]')
3
-
4
- elements.forEach (el, index, array) ->
5
- map = new MapGoogle(el)
6
-
7
- window['initMarkerMap'] = initMarkerMap
@@ -1,86 +0,0 @@
1
- $ = jQuery
2
-
3
- class MapGoogle
4
- constructor: (@dom, options = {}) ->
5
- defaults =
6
- lat: 50.44067063154785
7
- lng: 30.52654266357422
8
- zoom: 6
9
-
10
- @element = $(@dom)
11
- @options = $.extend defaults, @element.data(), options
12
-
13
- @name = @element.data('marker')
14
-
15
- @options.field_lat = "[data-#{@name}='lat']"
16
- @options.field_lng = "[data-#{@name}='lng']"
17
- @options.field_zoom = "[data-#{@name}='zoom']"
18
-
19
- this._setup()
20
-
21
- _setup: ->
22
- @location = this._build_location()
23
- @map = this._build_map(@element.get(0))
24
- @marker = this._build_marker()
25
-
26
- @field_lat = $(@options.field_lat + ':eq(0)')
27
- @field_lng = $(@options.field_lng + ':eq(0)')
28
- @field_zoom = $(@options.field_zoom + ':eq(0)')
29
-
30
- google.maps.event.addListener(@marker, 'dragend', (event) =>
31
- pos = @marker.getPosition()
32
-
33
- @field_lat.val pos.lat()
34
- @field_lng.val pos.lng()
35
-
36
- @map.setCenter(event.latLng)
37
- )
38
-
39
- google.maps.event.addListener(@map, 'zoom_changed', () =>
40
- @field_zoom.val @map.getZoom()
41
- )
42
-
43
- placeMarker: (location) ->
44
- marker = this._build_marker {position: location}
45
-
46
- @map.setCenter(location);
47
-
48
- return marker
49
-
50
- _build_location: ->
51
- lat = this._parse_value @options.field_lat, @options.lat
52
- lng = this._parse_value @options.field_lng, @options.lng
53
-
54
- new google.maps.LatLng(lat, lng)
55
-
56
- _build_map: (element, options = {}) ->
57
- zoom = this._parse_value @options.field_zoom, @options.zoom
58
-
59
- defaults =
60
- zoom: zoom
61
- center: @location
62
- mapTypeId: google.maps.MapTypeId.ROADMAP
63
-
64
- settings = $.extend defaults, options
65
-
66
- new google.maps.Map(element, settings)
67
-
68
- _build_marker: (options = {}) ->
69
- defaults =
70
- position: @location
71
- map: @map
72
- draggable: true
73
-
74
- settings = $.extend defaults, options
75
-
76
- new google.maps.Marker(settings)
77
-
78
- _parse_value: (field, default_value) ->
79
- value = parseFloat $(field).val()
80
-
81
- if value
82
- return value
83
- else
84
- return parseFloat(default_value)
85
-
86
- window.MapGoogle = MapGoogle