rails_admin_baidu_map 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bbd4f96131499548c64a9d018b76b1574ab9889
4
+ data.tar.gz: 55bd98c2120567a07af74d00bf2292b559fe4e2f
5
+ SHA512:
6
+ metadata.gz: cc670e6fad8e04e08bb2504680041dd3a3b8c7c8c4903c7ff68f4fe27e544190b1a7e051341d8c2047a938997bf043d7f9ea831f7cd6a7e435d11ef647c6c3ae
7
+ data.tar.gz: 691372cae26bbcace7e9006718fd698f323ec3c239685ffdbbd2266d2212aa94849accc26e7e9aa2a54f6ed1de275c359600dac1545df9b353f5bd4269dada39
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 tangmonk
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = RailsAdminBaiduMap
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsAdminBaiduMap'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,65 @@
1
+ :coffeescript
2
+ jQuery ->
3
+ map = new BMap.Map("baidumap")
4
+ map.centerAndZoom(new BMap.Point("#{field.default_latitude}", "#{field.default_longitude}"), 14)
5
+ map.enableScrollWheelZoom();
6
+ local = new BMap.LocalSearch(map,renderOptions:{map: map, panel:"baidumap_result"})
7
+
8
+ POINT = null
9
+
10
+ jQuery('#baidumap_comfirm').on 'click', (e)->
11
+ e.preventDefault()
12
+ if POINT
13
+ jQuery("##{field.latitude_dom_name}").val(POINT.lat)
14
+ jQuery("##{field.longitude_dom_name}").val(POINT.lng)
15
+ jQuery('#baidumap_modal').modal('hide')
16
+ else
17
+ alert '请在地图中标注坐标点!'
18
+
19
+ jQuery('#search').on 'click', (e)->
20
+ e.preventDefault()
21
+ local.search $('#search-input').val()
22
+
23
+ map.addEventListener 'click', (e)->
24
+ map.clearOverlays()
25
+ marker = new (BMap.Marker)(e.point)
26
+ map.addOverlay marker
27
+ marker.setAnimation BMAP_ANIMATION_BOUNCE
28
+ POINT = e.point
29
+
30
+ = javascript_include_tag("http://api.map.baidu.com/api?v=2.0&ak=#{field.api_key}")
31
+ :scss
32
+ #baidumap{
33
+ width:100%;height:400px;
34
+ }
35
+
36
+ = form.fields_for field.name do |location_field|
37
+ %div.control-group(class="#{field.latitude_dom_name}")
38
+ = location_field.label :latitude, :class => "control-label"
39
+ %div.controls
40
+ = location_field.send :text_field, nil, field.html_attributes.reverse_merge({ :value => field.value.try(:first) || field.default_latitude, :id => field.latitude_dom_name })
41
+ %div.control-group(class="#{field.longitude_dom_name}")
42
+ = location_field.label :longitude, :class => "control-label"
43
+ %div.controls
44
+ = location_field.send :text_field, nil, field.html_attributes.reverse_merge({ :value => field.value.try(:last) || field.default_longitude, :id => field.longitude_dom_name })
45
+
46
+ %button.btn.btn-success{:type => "button", "data-toggle" => "modal", "data-target" => "#baidumap_modal"} 在地图上标注
47
+
48
+ #baidumap_modal.modal.fade.bs-example-modal-lg{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
49
+ .modal-dialog.modal-lg
50
+ .modal-content
51
+ .modal-header
52
+ %button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
53
+ %span{"aria-hidden" => "true"} &times;
54
+ %h4#myModalLabel.modal-title 地图
55
+ .modal-body.form-inline
56
+ .row
57
+ .col-md-6
58
+ %div#baidumap
59
+ .col-md-6
60
+ %input#search-input.form-control{:placeholder => "请输入详细地址"}
61
+ %button#search.btn.btn-primary 搜索
62
+ %div#baidumap_result
63
+ .modal-footer
64
+ %button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} 关闭
65
+ %button.btn#baidumap_comfirm.btn-primary{:type => "button"} 确定
@@ -0,0 +1,82 @@
1
+ :scss
2
+ #baidumap{
3
+ width:100%;height:400px;
4
+ }
5
+
6
+ = form.hidden_field(:lonlat, value: field.value || field.default_lonlat, id: field.dom_name)
7
+
8
+ %button.btn.btn-success{:type => "button", "data-toggle" => "modal", "data-target" => "#baidumap_modal"} 在地图上标注
9
+
10
+ #baidumap_modal.modal.fade.bs-example-modal-lg{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1"}
11
+ .modal-dialog.modal-lg
12
+ .modal-content
13
+ .modal-header
14
+ %button.close{"aria-label" => "Close", "data-dismiss" => "modal", :type => "button"}
15
+ %span{"aria-hidden" => "true"} &times;
16
+ %h4#myModalLabel.modal-title 地图
17
+ .modal-body.form-inline
18
+ .row
19
+ .col-md-6
20
+ %div#baidumap
21
+ .col-md-6
22
+ %input#search-input.form-control{:placeholder => "请输入详细地址"}
23
+ %button#search.btn.btn-primary 搜索
24
+ %div#baidumap_result
25
+ .modal-footer
26
+ %button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} 关闭
27
+ %button.btn#baidumap_comfirm.btn-primary{:type => "button"} 确定
28
+
29
+ :coffeescript
30
+ window.map =
31
+ show_point: (point) ->
32
+ @map.clearOverlays()
33
+ marker = new (BMap.Marker)(point)
34
+ @map.addOverlay marker
35
+ marker.setAnimation BMAP_ANIMATION_BOUNCE
36
+ @POINT = point
37
+
38
+ load_map: () ->
39
+ jQuery(document).off('rails_admin.dom_ready', @.load_map)
40
+
41
+ script = document.createElement("script")
42
+ script.type = "text/javascript"
43
+ script.src = "http://api.map.baidu.com/api?v=2.0&ak=#{field.api_key}&callback=map.init"
44
+ document.body.appendChild(script)
45
+
46
+ init: () ->
47
+ @map = new BMap.Map("baidumap")
48
+ @POINT = null
49
+
50
+ jQuery('#baidumap_comfirm').on 'click', (e)=>
51
+ e.preventDefault()
52
+ if @POINT
53
+ jQuery("##{field.dom_name}").val("POINT(\#{@POINT.lng} \#{@POINT.lat})")
54
+ jQuery('#baidumap_modal').modal('hide')
55
+ else
56
+ alert '请在地图中标注坐标点!'
57
+
58
+ jQuery('#search').on 'click', (e)->
59
+ e.preventDefault()
60
+ local.search $('#search-input').val()
61
+
62
+ jQuery('#baidumap_modal').on 'shown.bs.modal', =>
63
+ real_point = new BMap.Point("#{field.value.try :x}", "#{field.value.try :y}")
64
+ default_point = new BMap.Point("#{field.default_latitude}", "#{field.default_longitude}")
65
+
66
+ if isNaN(real_point.lat) or isNaN(real_point.lng)
67
+ point = default_point
68
+ else
69
+ point = real_point
70
+ @show_point(point)
71
+
72
+ @map.centerAndZoom(point, 14)
73
+ @map.enableScrollWheelZoom();
74
+ local = new BMap.LocalSearch(@map,renderOptions:{map: @map, panel:"baidumap_result"})
75
+
76
+ @map.addEventListener 'click', (e)=>
77
+ @show_point(e.point)
78
+
79
+ # when the init function fininshed, chrome will throw `Uncaught TypeError: Cannot read property 'rv' of undefined`, hope someone can fix that.
80
+
81
+
82
+ jQuery(document).on 'rails_admin.dom_ready', window.map.load_map
@@ -0,0 +1,160 @@
1
+ require "rails_admin_baidu_map/engine"
2
+
3
+ module RailsAdminBaiduMap
4
+ end
5
+
6
+ require 'rails_admin/config/fields'
7
+ require 'rails_admin/config/fields/base'
8
+
9
+ module RailsAdmin::Config::Fields::Types
10
+ class BaiduMap < RailsAdmin::Config::Fields::Base
11
+ RailsAdmin::Config::Fields::Types::register(:baidu_map, self)
12
+
13
+ register_instance_option(:address_field) do
14
+ "address"
15
+ end
16
+
17
+ register_instance_option(:country_field) do
18
+ "country"
19
+ end
20
+
21
+ register_instance_option(:city_field) do
22
+ "city"
23
+ end
24
+
25
+ register_instance_option(:state_field) do
26
+ "state"
27
+ end
28
+
29
+ register_instance_option(:partial) do
30
+ :form_baidu_map
31
+ end
32
+
33
+ # Google Maps API Key - optional
34
+ register_instance_option(:api_key) do
35
+ nil
36
+ end
37
+
38
+ # Initial latitude value
39
+ register_instance_option(:default_latitude) do
40
+ 116.404
41
+ end
42
+
43
+ # Initial longitude value
44
+ register_instance_option(:default_longitude) do
45
+ 39.915
46
+ end
47
+
48
+ # Default zoom level of the map
49
+ register_instance_option(:default_zoom_level) do
50
+ 8
51
+ end
52
+
53
+ # Map heigth in px
54
+ register_instance_option(:map_width) do
55
+ 300
56
+ end
57
+
58
+ # Map width in px
59
+ register_instance_option(:map_height) do
60
+ 200
61
+ end
62
+
63
+ def sanitized_object_name(object_name)
64
+ object_name.gsub(/]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
65
+ end
66
+
67
+ def form_tag_id(object_name, field)
68
+ "#{sanitized_object_name(object_name.to_s)}_#{field.to_s}"
69
+ end
70
+
71
+ def dom_name
72
+ @dom_name ||= "#{form_tag_id(bindings[:form].object_name, @name)}"
73
+ end
74
+
75
+ def latitude_dom_name
76
+ form_tag_id(bindings[:form].object_name, @name) + '_latitude'
77
+ end
78
+
79
+ def longitude_dom_name
80
+ form_tag_id(bindings[:form].object_name, @name) + '_longitude'
81
+ end
82
+
83
+ def address_dom_name
84
+ form_tag_id(bindings[:form].object_name, address_field)
85
+ end
86
+
87
+ def country_dom_name
88
+ form_tag_id(bindings[:form].object_name, country_field)
89
+ end
90
+
91
+ def city_dom_name
92
+ form_tag_id(bindings[:form].object_name, city_field)
93
+ end
94
+
95
+ def state_dom_name
96
+ form_tag_id(bindings[:form].object_name, state_field)
97
+ end
98
+ end
99
+
100
+ class BaiduMapPostgis < RailsAdmin::Config::Fields::Base
101
+ RailsAdmin::Config::Fields::Types::register(:baidu_map_postgis, self)
102
+
103
+ register_instance_option(:partial) do
104
+ :form_baidu_map_postgis
105
+ end
106
+
107
+ register_instance_option(:api_key) do
108
+ nil
109
+ end
110
+
111
+ # Initial latitude value
112
+ register_instance_option(:default_latitude) do
113
+ 39.915
114
+ end
115
+
116
+ # Initial longitude value
117
+ register_instance_option(:default_longitude) do
118
+ 116.404
119
+ end
120
+
121
+ # Default zoom level of the map
122
+ register_instance_option(:default_zoom_level) do
123
+ 8
124
+ end
125
+
126
+ # Map heigth in px
127
+ register_instance_option(:map_width) do
128
+ 300
129
+ end
130
+
131
+ # Map width in px
132
+ register_instance_option(:map_height) do
133
+ 200
134
+ end
135
+
136
+ def sanitized_object_name(object_name)
137
+ object_name.gsub(/]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
138
+ end
139
+
140
+ def form_tag_id(object_name, field)
141
+ "#{sanitized_object_name(object_name.to_s)}_#{field.to_s}"
142
+ end
143
+
144
+ def dom_name
145
+ @dom_name ||= "#{form_tag_id(bindings[:form].object_name, @name)}"
146
+ end
147
+
148
+ def default_lonlat
149
+ "POINT(#{self.default_longitude} #{self.default_latitude})"
150
+ end
151
+
152
+ def latitude_dom_name
153
+ form_tag_id(bindings[:form].object_name, @name) + '_latitude'
154
+ end
155
+
156
+ def longitude_dom_name
157
+ form_tag_id(bindings[:form].object_name, @name) + '_longitude'
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,4 @@
1
+ module RailsAdminBaiduMap
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminBaiduMap
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_baidu_map
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - TangMonk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Support PostGis And Mongoid
14
+ email:
15
+ - wytwyt02@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - MIT-LICENSE
21
+ - README.rdoc
22
+ - Rakefile
23
+ - app/views/rails_admin/main/_form_baidu_map.html.haml
24
+ - app/views/rails_admin/main/_form_baidu_map_postgis.html.haml
25
+ - lib/rails_admin_baidu_map.rb
26
+ - lib/rails_admin_baidu_map/engine.rb
27
+ - lib/rails_admin_baidu_map/version.rb
28
+ homepage: https://github.com/TangMonk/rails_admin_baidu_map
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.4.5
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Add baidu baidu to rails admin
52
+ test_files: []