2014-10-31 2 views
0

내 데이터베이스에 파이프 모델이 있는데 형상 속성 (LineString)이 있습니다.전단지를 사용하여 보여주는 LineString을 얻으려면 어떻게해야합니까?

def index 
    @pipes = Pipe.all 
    @geojson = Array.new 

    @pipes.each do |pipe| 

    @geojson<< { 
     type: "FeatureCollection", 
     crs: { type: "name", properties: { name: "urn:ogc:def:crs:OGC:1.3:CRS84" } }, 
     features: [ 
     type: 'Feature', 
     properties: { 
      geometry: { 
      type: 'LineString', 
      coordinates: pipe.get_coordinates 
      }, 
      stroke: "#1087bf" 
     } 
    ]} 
    end 
    respond_to do |format| 
     format.html 
     format.json { render json: @geojson } # respond with the created JSON object 
    end 
end 

이것은 pipes.js 파일 :

$(document).ready(function() { 
    if ($("#pipes_map").length>0) { 
    var geojson; 
    var map = L.map('pipes_map', { 
     center: [42.44, 19.26], 
     zoom: 16 
    }); 
    L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { 
     max_zoom: 22 
    }).addTo(map); 

    L.geoJson(geojson).addTo(map); 
    $.ajax({ 
     dataType: 'text', 
     url: 'http://localhost:3000/pipes.json', 
     success: function(data) { 
     var myStyle = { 
      "color": "#ff7800", 
      "weight": 5, 
      "opacity": 0.65 
     }; 
     geojson = $.parseJSON(data); 
     L.geoJson(geojson).addTo(map);     
     }, 
     error : function() { 
     alert('Error!'); 
     } 
    }) 
    } 
}) 

을하지만 내 파이프가지도에 표시되지 않습니다 나는이 pipes_controller.rb에 추가. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 어쩌면 내 파이프 .json이 제대로 형성되지 않았을 까? 아니면 스타일이 안 좋아?

def index 
@pipes = Pipe.all 
@geojson = Array.new 

@pipes.each do |pipe| 

    @geojson<< { 
    type: 'Feature', 
    properties: { 
     :category=> pipe.category.name 
    }, 
    geometry: { 
     type: 'LineString', 
     coordinates: pipe.get_coordinates 
    } 
    } 
end 
respond_to do |format| 
    format.html 
    format.json { render json: @geojson } # respond with the created JSON object 
end 

나머지는 괜찮 :

+0

브라우저의 콘솔에 오류가 있습니까? 디버깅을 시도 했습니까? –

+0

네, 컨트롤러에서 뭔가 엉망이되었습니다 ... – ivanacorovic

답변

0

이 컨트롤러가 어떻게 보일지입니다.

관련 문제