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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
35 changes: 23 additions & 12 deletions app/views/map/_leaflet.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<% unique_id = rand(100) %>
<style>
<% unique_id = rand(100) %>
<style>
#map<%= unique_id %> { width:100%; height:300px; margin: 0; position: relative;}
</style>
<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);
L.tileLayer("//a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png").addTo(map);
</style>
<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<%= unique_id %> = 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<%= unique_id %>);
function onMapLoad(e){
var lat = <%= lat %> ;
var lon = <%= lon %> ;
var s = lat+","+lon ;
$.getJSON("/api/srch/locations?srchString="+s , function(data){
if (!!data.items){
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<%= unique_id %>).bindPopup("<a href=" + url + ">" + title + "</a>") ;
}
}
});
}
</script>

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