diff --git a/README.md b/README.md index a6c43d6..ff63f6b 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,14 @@ For different configurations, rails_admin_map_field can be configured with the f - `google_api_key` - if you use a Google Maps API Key, it can be specified here. - `default_latitude` - the latitude to center the map shown on if the latitude field is blank. Defaults to 51.5, the latitude of London, UK. - `default_longitude` - the longitude used if the longitude field is blank. Defaults to -0.126, the longitude of London, UK. +- `draggable` - when to enable draggable map. Default true. +- `scrollwheel` - when to enable scrolling map with mouse wheel. Default true. +- `zoom_control` - when to enable zoom control on top of map. Default true. +- `street_view_control` - when to enable street_view option. Default true. +- `fixed_marker` - when to disable relocating the marker (like read_only true). Default false. +- `disable_double_click_zoom` - when to disable zoom with mouse double click. Default false. +- `width` - map width in px. Default 300. +- `height` - map height in px. Default 200. A more complicated configuration example: @@ -49,6 +57,7 @@ RailsAdmin.config do |config| google_api_key "a1b2c3d4e5f6deadbeef" default_latitude -34.0 # Sydney, Australia default_longitude 151.0 + zoom_control false end end end diff --git a/app/views/rails_admin/main/_form_map.html.haml b/app/views/rails_admin/main/_form_map.html.haml index 3cda5b3..bbd7c6e 100644 --- a/app/views/rails_admin/main/_form_map.html.haml +++ b/app/views/rails_admin/main/_form_map.html.haml @@ -10,6 +10,12 @@ var myOptions = { zoom: #{field.default_zoom_level}, center: latlng, + draggable: #{field.draggable}, + scrollwheel: #{field.scrollwheel}, + zoomControl: #{field.zoom_control}, + disableDoubleClickZoom: #{field.disable_double_click_zoom}, + streetViewControl: #{field.street_view_control}, + center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; @@ -22,27 +28,28 @@ map: map }); - :plain + - unless field.fixed_marker + :plain google.maps.event.addListener(map, 'click', function(e) { - updateLocation(e.latLng); - }); - - function updateLocation(location) { - if(marker) { - marker.setPosition(location); - } else { - marker = new google.maps.Marker({ - position: location, - map: map - }); + updateLocation(e.latLng); + }); + + function updateLocation(location) { + if(marker) { + marker.setPosition(location); + } else { + marker = new google.maps.Marker({ + position: location, + map: map + }); + } + + map.setCenter(location); + jQuery("##{field.latitude_dom_name}").val(location.lat()); + jQuery("##{field.longitude_dom_name}").val(location.lng()); } - - map.setCenter(location); - jQuery("##{field.latitude_dom_name}").val(location.lat()); - jQuery("##{field.longitude_dom_name}").val(location.lng()); - } - - })}; -%div.ramf-map-container{:id => field.dom_name, :style => "width:300px;height:200px"} + :plain + })}; +%div.ramf-map-container{:id => field.dom_name, :style => "width:#{field.width}px;height:#{field.height}px"} = form.send :hidden_field, field.name, :id => field.latitude_dom_name -= form.send :hidden_field, field.longitude_field, :id => field.longitude_dom_name \ No newline at end of file += form.send :hidden_field, field.longitude_field, :id => field.longitude_dom_name diff --git a/lib/rails_admin_map_field/rails_admin/config/fields/types/map.rb b/lib/rails_admin_map_field/rails_admin/config/fields/types/map.rb index 7b48232..84732d9 100644 --- a/lib/rails_admin_map_field/rails_admin/config/fields/types/map.rb +++ b/lib/rails_admin_map_field/rails_admin/config/fields/types/map.rb @@ -16,6 +16,38 @@ def allowed_methods :form_map end + register_instance_option(:draggable) do + true + end + + register_instance_option(:scrollwheel) do + true + end + + register_instance_option(:zoom_control) do + true + end + + register_instance_option(:street_view_control) do + true + end + + register_instance_option(:fixed_marker) do + false + end + + register_instance_option(:disable_double_click_zoom) do + false + end + + register_instance_option(:width) do + 300 + end + + register_instance_option(:height) do + 200 + end + # Google Maps API Key - optional register_instance_option(:google_api_key) do nil