私は点のレイヤーと線のレイヤーを持っています。レイヤーは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
に利用可能にされます。しかし、私はRailsの魔法を理解することはできません。
ポイントを持つ2番目のレイヤーが必要です。私は最初にコントローラにを追加するだけで、@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/ 私はサイトをアップロードして、(in)アクションで見ることができます。 Herokuで正しく読み込まれません。
これは難しいことではありません。ありがとうございました。