나는 포인트 레이어와 라인 레이어를 가지고 있습니다. 레이어는 jbuilder에 의해 생성되고 전단지가 표시됩니다. 레이어를 개별적으로 만들고 표시 할 수 있지만 함께 표시 할 수는 없습니다. 한 층 , map.js
는 jbuilder로 다중 레이어 만들기
var featureLayer = L.mapbox.featureLayer()
.loadURL('map/map_data.geojson')
.addTo(map);
featureLayer.on('ready', function(e) {
map.fitBounds(featureLayer.getBounds());
});
map_controller.rb
def map_data
start = '1895-01-01'
start = start.to_date
finish = (start + 3.year)
@lines = RestoResidLine.where(resto_date: start..finish).select("id, person_id, resto_loc_id, resid_loc_id, resto_name, resto_date, title_resto, resid_date, title_resid, long_resto, lat_resto, long_resid, lat_resid")
end
map_data.json.jbuilder
:
json.type "FeatureCollection"
json.features @lines do |line|
if (line.long_resto && line.long_resid)
json.type "Feature"
json.geometry do
json.type "LineString"
json.coordinates [[line.long_resto, line.lat_resto], [line.long_resid, line.lat_resid]]
end
end
end
map_data.json map.js
는 사용할 수있게된다. 그러나 레일즈의 모든 것들이 어떻게 함께하는지에 대한 마법은 이해하지 못합니다.
포인트가있는 두 번째 레이어가 필요합니다. 먼저 콘트롤러에 번을 추가하려고 시도했다. @lines
. 그러나 마지막 것만 나타납니다. 나는 그들이 연결될 것 같다고 생각했다. 아마도 @의 정의를 바꿀 수 있습니다. 필요한 정보를 모두 가져와 하나의 해결책이 될 수 있습니다. 그러나 논리는 추악 할 것이다.
point_data.json.jbuilder
을 만들고 구축됩니다
map.js
var featureLayer = L.mapbox.featureLayer()
.loadURL('map/point_data.geojson')
.addTo(map);
과연 point_data.json에 추가했는데, 그것은 2400 선 HTML <title>Action Controller: Exception caught</title>
입니다. map_data.json
이 빌드되어 올바르게 표시됩니다.
이름 지정 문제입니까? 또는? 나는 Rails, ActiveRecord 및 JavaScript Leaflet에 대한 새로운 개념입니다.
코드 : https://bitbucket.org/MtnBiker/crores5/ 조치를 취할 때 볼 수 있도록 사이트를 업로드하려고합니다. Heroku에서 제대로로드되지 않습니다.
어렵지 않을 수 있습니다. 고맙습니다.