首页 > 解决方案 > 如何从 html 文件输入中加载 geojson 数据?

问题描述

我想构建允许客户端从 html 表单上传 geojson 文件的系统,这些数据将显示在传单地图上。当我尝试这样做时,它显示错误代码 405。我想提交包含geojson 文件的表单并使用leaflet-omnivore 插件加载此文件。

我的 html 文件为,

    <section class="addVectorLayer">
        <form action="" method="POST" class="vector">
            Click to add your vector layer. It support Json, Geojson, csv, gpx and kml formats.
            <input type="file" name="files" id="input_files">
        </form>
    </section> 

我的js文件在这里,

    geojson.onlode = function() {
    geojson.readAsDataURL(document.getElementById('input_files').files[0]);
    };
    omnivore.geojson(geojson.result).addTo(map);

编辑

抱歉,这不是重复的。在这个问题中,我想使用omnivore Leaflet-plugin 读取geojson 文件。

标签: javascriptfileleafletgeojson

解决方案


推荐阅读