dongque1462 2015-12-21 16:31
浏览 59

如何将小册子插件添加到脚本外部的表单中

I am using the geocoding control plugin L.GeoSearch (https://github.com/smeijer/L.GeoSearch) and I have a form on the left sidebar of my leaflet map. The form should submit the inputs to a php file that then does the processing via XMLHttpRequest.

The coordinates have to be transferred as well and I am a little bit stuck on how to integrate the geosearch bit into the form. Can somebody help me out or give some hints?

The page: http://app.seedbomb.city/cartodb.html

This is my map code: https://jsfiddle.net/Gopher69/oza08ja4/embedded/result/

<!-- Begin Sidebar!-->
<div id="sidebar">
    <h2>Markiere deinen Standort</h2>
    <div class="ss-form-container">
        <div class="ss-header-image-container">
            <div class="ss-header-image-image">
                <div class="ss-header-image-sizer"></div>
            </div>
        </div>
        <div class="ss-top-of-page"></div>
        <div class="ss-form">
            <form onsubmit="" target="_self" id="ss-form" method="POST" action="write_cartodb.php">
                <ol style="padding-left: 0" class="ss-question-list" role="list">
                    <div role="listitem" class="ss-form-question errorbox-good">
                        <div class="ss-item  ss-text" dir="auto">
                            <div class="ss-form-entry">
                                <label for="entry_2039516724" class="ss-q-item-label">
                                    <div class="ss-q-title">Bildbeschreibung
                                    </div>
                                    <div dir="auto" class="ss-q-help ss-secondary-text"></div>
                                </label>
                                <input type="text" title="" aria-label="caption  " dir="auto" id="entry_2039516724" class="ss-q-short" value="" name="beschreibung">
                            </div>
                        </div>
                    </div>
                    <div role="listitem" class="ss-form-question errorbox-good">
                        </br>
                        <input type="file" name="bild" id="uploadfiles" accept="image/*" />
                    </div>
        </div>
    </div>
    </br>

    </br>
    <div class="ss-item ss-navigate">
        <table id="navigation-table">
            <tbody>
                <tr>
                    <td dir="ltr" id="navigation-buttons" class="ss-form-entry goog-inline-block">
                        <input type="submit" class="jfk-button jfk-button-action " id="ss-submit" value="Senden" name="submit">
                </tr>
            </tbody>
        </table>
    </div>
</div>
<!-- End Sidebar!-->

The php processing file:

https://jsfiddle.net/Gopher69/c692kqov/embedded/result/

<?php

echo "<h1>" . $_POST["beschreibung"] . "</h1>";
echo "<h1>" . $_POST["bild"] . "</h1>";

?>

<script>
    function dialResponse() {
        console.log(this.responseText); //should be return value of 1
    }

    var oReq = new XMLHttpRequest();
    oReq.onload = dialResponse;
    oReq.open("get", "https://{account}.cartodb.com/api/v2/sql?q=INSERT INTO cartodb_test (caption, image_low, image_standard, image_thumb, latitude, longitude) VALUES (<?php echo $beschreibung;?>, http://app.seedbomb.city/images/<?php echo $bild;?>, http://app.seedbomb.city/images/<?php echo $bild;?>, http://app.seedbomb.city/images/<?php echo $bild;?>, 12.532534, 12.643245)&api_key=http://app.seedbomb.city/images/<?php echo $bild;?>"
            ", true);
            oReq.send();
</script>
  • 写回答

1条回答 默认 最新

  • doucan4873 2015-12-22 14:09
    关注

    You can utilize Leaflet's map events, such as click or moveend, to let a user chose the position.

    With those you can fill an input field in your form with the coordinates. This code will update an input field with a coordinate when clicking on the map:

    map.on('click', function(e){
      document.getElementById('userlocation').value = e.latlng.lat+','+e.latlng.lng;
    });
    

    Demo code here: https://jsfiddle.net/chk1/dh58ury9/

    评论

报告相同问题?

悬赏问题

  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里