Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank Map loaded with call to API (Part 2 of #1934) #2044

Merged
merged 8 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 2 additions & 11 deletions app/models/concerns/node_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,17 @@ def self.upgrades_grid(body)
end
end

#Blank map loaded only , markers will be loaded using API call .
def self.notes_map(body)
body.gsub(/[^\>`](\<p\>)?\[map\:content\:(\S+)\:(\S+)\]/) do |_tagname|
lat = Regexp.last_match(2)
lon = Regexp.last_match(3)
nids = NodeTag.joins(:tag)
.where('name LIKE ?', 'lat:' + lat[0..lat.length - 2] + '%')
.collect(&:nid)
nids = nids || []
items = Node.includes(:tag)
.references(:node, :term_data)
.where('node.nid IN (?) AND term_data.name LIKE ?', nids, 'lon:' + lon[0..lon.length - 2] + '%')
.limit(200)
.order('node.nid DESC')
a = ActionController::Base.new()
output = a.render_to_string(template: "map/_leaflet",
layout: false,
locals: {
lat: lat,
lon: lon,
items: items
lon: lon
}
)
output
Expand Down
19 changes: 15 additions & 4 deletions app/views/map/_leaflet.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@
<div class="leaflet-map" id="map<%= unique_id %>"></div>
<% if defined? people %><p><i><small>Share your own location on <a href='/profile'>your profile</a>.</small></i></p><% end %>
<script>
var map = L.map('map<%= unique_id %>').setView([<%= lat %>,<%= lon %>], <%= lat.to_s.length.to_i %> + 6);
var map = L.map('map<%= unique_id %>').on('load', onMapLoad).setView([<%= lat %>,<%= lon %>], <%= lat.to_s.length.to_i %> + 6);
L.tileLayer("//a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png").addTo(map);
function onMapLoad(e){
var lat = <%= lat %> ;
var lon = <%= lon %> ;
var s = lat+","+lon ;
$.getJSON("https:"+"//publiclab.org/api/srch/locations?srchString="+s , function(data){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this aim at / rather than //publiclab.org/api/...?

This is looking FANTASTIC

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi , thank you so much ! I think both ways are correct , what do you think ?

screen shot 2018-01-25 at 10 53 55 pm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i mean that if you run this codebase somewhere besides publiclab.org, we'd want to just aim the request at the root. Make sense?

if (!!data.items){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is looking super, but do you think we could do really consistent two-space indentations here so it's cleanly formatted? Sorry to ask, but it does make a big difference over the long run. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @jywarren , i agree and understand the importance of indentation . Doing the changes now , thanks 😄 💯 !

for (i = 0; i < data.items.length ; i++) {
var url = data.items[i].docUrl ;
var title = data.items[i].docTitle ;
L.marker([data.items[i].latitude , data.items[i].longitude]).addTo(map).bindPopup("<a href=" + url + ">" + title + "</a>") ;
}
}
});

<% items.each do |item| %>
L.marker([<%= item.lat %>, <%= item.lon %>]).addTo(map).bindPopup("<a href='<%= item.path %>'><%= item.title %></a>");
<% end %>
}
</script>