Simple implementation of Yandex maps in rails admin.
Inspired by these projects:
Add this line to your application's Gemfile:
gem 'rails_admin_yamap_field'
And then execute:
$ bundle
Add attr_accessor ya_map
to you model for which you need to show the map or define
ya_map
and ya_map=
methods as you wish, for example:
class Address < ApplicationRecord
# others methods
def ya_map=(lat_lon)
self[:lat], self[:lon] = lat_lon.split(",")
end
def ya_map
[lat, lon].join(",")
end
# others methods
end
- center_lat - map center latitude
- center_long - map center longitude
- zoom_level - map zoom level
- map_html_width - width div map container: default '100%'
- map_html_height - height div map container: default '500px'
- map_lang - language map: default 'ru_RU', for other values see this ref
- api_key - api key for enterprise version: default 'nil'
- latitude_field - latitude attribute name in you model: default 'latitude'
- longitude_field - longitude attribute name in you model: default 'longitude'
class Address < ApplicationRecord
attr_accessor :ya_map
rails_admin do
field :lat, :hidden
field :lon, :hidden
field :ya_map, :yamap_field do
map_html_width "600px"
latitude_field :lat
longitude_field :lon
end
end
end
Feel free to send pull requests or write issue.
The gem is available as open source under the terms of the MIT License.