gmaps4rails - many markers, one location - how to view? - ruby-on-rails-3

I am wondering how to deal with the situation where one location may have many markers.
I am using gmaps4rails and rails 3
does this have something to do with the "do_clustering" property of the gmaps?
Thanks!
Adam

excellent, just found "randomize" in the documentation! perfect:
{:data => #json, :options => { :do_clustering => true, randomize: true} }) %>

Related

Google-Maps-for-Rails Direction Wiki Explaination Needed

Hi I am currently working on a trash bin/recycling bin location application using google maps for rails.
I have a recyclingbin.rb model with the address as its attributes, that itself is enough to put markers on a map that can get displayed using the gem. I believe the gem converts the model and its attributes into json data.
I am trying to implement a feature where I can input my location and get direction to the nearest marker.
I have looked at the wiki , https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Direction
Am I suppose to put this in the view ?
{ "data" => { "from" => "Paris, france", "to" => "Toulon, france" } }
})
%>
with the from to be embedded with my location for now? I understand I can pass options to this reference from google.
The wiki is quite short, can someone give me a quick explanation ?
The wiki does need some more work. I have a simple app working that shows the directions on the map from a location to another (pre-defined) location
<%= gmaps("map_options" => {"zoom" => 14}, "markers" => { "data" => #json },
"direction" => { "data" => {"from" => #location.address, "to" => "New York City"},"travelMode" => "DRIVING"}) %>
I just put this in my view. It shouldn't matter where, just as long as its there. Hope this helps

Setting header size in PDFKit with Ruby on Rails?

I need a repeating image to be shown on every page of the pdf. The only solution to this I've found so far is putting it into the header using
%meta{:name => 'pdfkit-header_html', :content => pdf_header_url}
Works fine but the image is bigger than the header size. Is there any way I can increase the height of the header or put a repeating image somehow outside the header?
Thanks!
You'll need to tweak the margin-top and header-spacing values. For example:
%meta{:name => 'pdfkit-header_html', :content => pdf_header_url}
%meta{:name => 'pdfkit-margin_top', :content => '3cm' }
%meta{:name => 'pdfkit-header_spacing', :content => '10' }
From the wkhtmltopdf docs:
--header-spacing * <real> Spacing between header and content in mm
(default 0)
-T, --margin-top <unitreal> Set the page top margin (default 10mm)
You can put any of the wkpdftohtml options in the meta tags and PDFKit will pass them through.
I ended up adding this code
PDFKit.configure do |config|
config.default_options = {
:page_size => 'Letter',
:margin_top => '3.6in',
:margin_right => '0.3in',
:margin_bottom => '1.3in',
:margin_left => '0.3in'
}
end
to /config/initializers/pdfkit.rb. Worked like charm after I restarted the server.

Geodesic routes in gmaps4rails

I can currently draw polylines using gmaps4rails in Rails but I'd like to draw them as geodesic paths. According to the Google Map documentation this should be as simple as adding "geodesic: true" to the options (link). Below is my current implementation that doesn't work but simply draws a straight line on the map. Is there a correct way of setting this option in gmaps4rails or is this not currently supported?
In my controller:
#json_route =
[
[
{'lng' => 80.190262, 'lat' => 55.774252 },
{'lng' => -66.118292, 'lat' => 38.466465 }
]
]
#gmaps_options =
{
:polylines => { "data" => #json_route.to_json, "options" => { "geodesic" => true }}
}
In my html page:
<%= gmaps(#gmaps_options) %>
Thank you!

Rails 3, how to prevent ajax remote calls (jquery) with a link_to and :remote => true with JS

So I have a simple ajax call to a page:
= link_to 'click me', my_path, :onclick => "if ($('#go').val() == "ok") { alert('going'); } else { return false; }", :remote => true do
This works just fine, I see the alert only when my field with id "go" has ok in there... but the issue is that the remote action triggers every time no matter what.
If this was not a remote link it would work just fine, not going through with the link, but it does not seem to behave the same way with a :remote => true ?
How can I achieve the expected result ?
Thanks,
ALex
The issue here is that the Rails UJS driver will see the data-remote and then perform the action because of a function like this in rails.js so perhaps try setting the property om your link inside the JS and remove the :remote => true. That might work however I dont know if rails.js would bind to that correctly or not.
Also, consider placing this JS in the application.js once you're done debugging just so you dont have inline JS all over your controllers.

Rails 3 Flowplayer Gem Usage

I'm attempting to use the flowplayer gem in my Rails 3 app. I've followed the installation instructions
Flowplayer Helper for Rails 3
applications
gem 'flowplayer' in your gem file
rails g flowplayer or rails g flowplayer commercial
add javascript_include_tag 'flowplayer.min.js' to your
application layout
read below
Usage
For JQuery
= flowplayer_for :video, '/flowplayer.swf', 'jquery' do
|player|
- player.playlist [{:url => "video_still.jpg" }, {:url =>
"video_512x288.flv", :autoPlay =>
false, :autoBuffering => true }]
- player.onLoad do
- 'this.unmute();'
For Prototype
= flowplayer_for :video, '/flowplayer.swf', 'prototype' do
|player|
- player.playlist [{:url => "video_still.jpg" }, {:url =>
"video_512x288.flv", :autoPlay =>
false, :autoBuffering => true }]
- player.onLoad do
- 'this.unmute();'
Configs are the same ones here
http://flowplayer.org/documentation/api/index.html
TODO
More documentation
After Step 1 I executed
bundle install
Which was successful.
For Step 2, I executed the first option
rails g flowplayer
Which was successful.
For Step 3, I added
= javascript_include_tag 'flowplayer.min.js'
to the head of my application.html.haml file; which was successful.
For Step 4, I added
%a#video{:style => "display:block;width:512px;height312px;"}
to my home.html.haml file; which was successful and the equivalent of
<a id='video' style='display:block;width:512px;height312px;'>
as per this HTML2HAML converter.
Now I've come to the last portion. I am using jQuery, but I have no idea where to put this last snippet of code.
Any help would be great thanks!
I know this is old but for anyone else - you can put the last bit of code right after the rest of your code. Caveat: There is a bug in the latest flowplayer gem. flowplayer_for only takes two parameters (causing it to always use jQuery) while the example shows three parameters. I've sent the author a pull request to change it.
So (in haml):
- content_for :head do
= javascript_include_tag "flowplayer.min.js"
%a#video{:style => "display:block;width:512px;height312px;"}
= flowplayer_for :video, '/flowplayer.swf'do |player|
- player.playlist [{:url => "video_still.jpg" }, {:url => "video_512x288.flv", :autoPlay => false, :autoBuffering => true }]
- player.onLoad do
- 'this.unmute();'