小编Ale*_*lex的帖子

传单标记弹出文本中的换行符

我有一个表单可以将一些文本与传单地图上的标记相关联:

<form action="map.php" method="POST">
 <section>
  <label>write some text here</label>
   <textarea id="text" rows="3" name="area"></textarea>
 </section>

 <input type="submit" value="show map" />
</form>
Run Code Online (Sandbox Code Playgroud)

正如您在上面看到的,textarea 的内容被传递到页面 map.php,其中显示了一个地图。在地图上,会显示位置标记,并且弹出窗口包含通过 textarea(变量$text)发布的文本:

<?php
$text = htmlspecialchars($_POST["text"]);
?>

<center>
 <div id="map" class="embed-container"></div>
</center>

<script>
  var map = L.map('map').setView([46.13, 11.11], 9);
  L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
    {
      attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
      maxZoom: 17,
      minZoom: 9
    }).addTo(map);
</script>
<script>
  var icon = L.icon({
        iconUrl: 'img/gps.png',
        iconSize: [25, 25],
        });
  var marker = L.marker(['<?=$latitude;?>', '<?=$longitude;?>'], {icon: icon}).addTo(map);
  marker.bindPopup('<?=$text;?>');
</script>
Run Code Online (Sandbox Code Playgroud)

问题是,如果我在 textarea 中写入内容时按ENTER,则没有任何内容传递给弹出标记。我尝试过 …

php newline leaflet

4
推荐指数
1
解决办法
6231
查看次数

标签 统计

leaflet ×1

newline ×1

php ×1