Question

J'essaie de convertir mon fichier erb en haml.Je pensais que je pourrais interpoler la plupart de mon code par chaîne, mais je rencontre des problèmes lorsque j'essaie d'utiliser une fonction JavaScript Leaflet, L.polygon() (http://leafletjs.com/reference.html#polygon), qui n'accepte que les chiffres.Voici mon code erb :

<h1>MAP!</h1>
<ul>
<li>Start: <%= @start %></li>
<li>End: <%= @end %></li>
</ul>
<div id="map"></div>
<script type="text/javascript" charset="utf-8">
  var map = L.map('map').setView([40.7142, -74.0064], 13);
  L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', {attribution: 'Stamen Toner'}, {
    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
    maxZoom: 18
  }).addTo(map);
  L.marker(<%= @start %>).addTo(map);
  L.marker(<%= @end %>).addTo(map);
  L.polygon([
    <%= @start %>,
    <%= @end %>
]).addTo(map);
</script>

Et voici mon code HAML qui ne fonctionne pas vraiment :

%h1 MAP!
%ul
  %li
    Start: #{@start}
  %li
    End: #{@end}
#map
%script{charset: "utf-8", type: "text/javascript"}
  var map = L.map('map').setView([40.7142, -74.0064], 13);
  L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', {attribution: 'Stamen Toner'}, {
  attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',maxZoom: 18}).addTo(map);
  L.marker(#{@start}).addTo(map);
  L.marker(#{@end}).addTo(map);
  L.polygon([#{@start},#{@end}]).addTo(map);
Était-ce utile?

La solution

Essayez d'utiliser parseInt:

L.polygon([parseInt(#{@start}),parseInt(#{@end})]).addTo(map);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top