I've been playing around with Openlayers maps on my website. The map functionality is working perfectly, but I'm having trouble getting the maps to display correctly on my page.
My goal is to show a map in each search result on my screen - one map per result. Everything looks good when I just have a basic bootstrap card for each result (you can see an example of this in the first screenshot below). However, as soon as I add the map code, everything starts overlapping (as shown in the second screenshot).
Any suggestions or ideas on how to solve this issue would be greatly appreciated! Thanks!
Screenshot showing results without the map code
Screenshot showing results with the map code
<% @locations.each do |location| %>
<div class="card" style="width: 18rem;">
<div id="map" class="map">
<script type="text/javascript">
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([-0.479642,52.641882]),
zoom: 10
})
});
</script>
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</br></br>
<% end %>