首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将leaflet插件添加到脚本之外的表单中

如何将leaflet插件添加到脚本之外的表单中
EN

Stack Overflow用户
提问于 2015-12-22 00:31:48
回答 1查看 296关注 0票数 1

我正在使用地理编码控件插件L.GeoSearch (https://github.com/smeijer/L.GeoSearch),并且在我的单张地图的左侧边栏上有一个表单。表单应该将输入提交到一个php文件,然后由该文件通过XMLHttpRequest进行处理。

坐标也必须转移,我有点卡住了如何将地理搜索比特集成到表单中。有没有人能帮帮我或者给点提示?

页面:http://app.seedbomb.city/cartodb.html

这是我的地图代码:https://jsfiddle.net/Gopher69/oza08ja4/embedded/result/

代码语言:javascript
复制
<!-- 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!-->

php处理文件:

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

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

发布于 2015-12-22 22:09:08

您可以利用Leaflet的map events,如clickmoveend,让用户选择位置。

使用这些坐标,您可以在表单中的输入字段中填充坐标。在地图上单击时,此代码将使用坐标更新输入字段:

代码语言:javascript
复制
map.on('click', function(e){
  document.getElementById('userlocation').value = e.latlng.lat+','+e.latlng.lng;
});

演示代码如下:https://jsfiddle.net/chk1/dh58ury9/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34400291

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档