【问题标题】:How to load my postgis points into leaflet如何将我的 postgis 点加载到传单中
【发布时间】:2019-02-05 02:09:09
【问题描述】:

我参加了一个 udemy 课程以获取传单。加载课程数据效果很好,但现在尝试使用我的 PostGIS 数据复制代码,但它不起作用。

我参加了关于 Udemy for Leaflet 的课程。我能够使用他提供的数据重现讲师所做的事情。我能够使用我的 PostGIS 数据库中的数据来重现一个表格,类似于讲师在另一个视频中教授的内容。现在,我无法用我的数据重新创建类似的地图。我已在 Udemy 课程网站上发布了此内容,但没有任何人回复。尽管在他的一个视频中指示建议使用 stackoverflow 寻求帮助,但我在这里。

From HTML Page
23 <script>
24 var queryLayer;
25 var mymap = L.map('mapdiv')
26 mymap.setView([33.86585, -118.08240], 15);
27        
28 var backgroundLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png');
29 mymap.addLayer(backgroundLayer);
30
31 $("#filterSubmit").click(function(){
32     $.ajax({
33         url:'query_permit_ajax.php',
34         type:'POST',
35         data:{
36             date_recd: $("#date_recd").val(),
37             act_stat: $("#act_stat").val()
38            },
39         success: function(response){
40             if (queryLayer) {
41                 mymap.removeLayer(queryLayer);
42            }
43              queryLayer=L.geoJSON(JSON.parse(response)).addTo(mymap);
44              mymap.fitBounds(queryLayer.getBounds());
45             }
46         });
47     });
48 </script>

From PHP Page
1 <?php
2     $dr=$_POST['date_recd'];
3     $as=$_POST['act_stat'];
4     $db = new PDO('pgsql:host=localhost;port=5433;dbname=webmap101;','postgres','123456');
5     $sql = $db->prepare("SELECT id, item_no, permit_no, scope_work, proj_site, st_from, st_to, date_recd, rev_stat, act_stat, ret_date, draft_inv, pay_recd, ST_AsGeoJSON(geom, 5) FROM permit_loc WHERE act_stat> :as");
6 $params = ["as"=>$as];
7 $sql->execute($params);
8    
9 $features=[];
10 while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
11     $feature=['type'=>"Feature"];
12     $feature['geometry']=json_decode($row['geom']);
13     unset($row['geom']);
14     $feature['properties']=$row;
15     array_push($features,$feature);
16 }
17     $featureCollection=['type'=>'FeatureCollection','features'=>$features];
18    echo json_encode($featureCollection);
19 ?>

这些点应该会在我的传单地图上弹出。

【问题讨论】:

    标签: javascript php html leaflet postgis


    【解决方案1】:

    你必须知道的第一件事:你的问题是在服务器端(php)还是浏览器端(javascript)?

    检查你的php错误日志和你的浏览器开发者控制台(你也可以在浏览器上检查网络)

    您还可以生成一些调试信息来了解数据的样子。

    console.log(JSON.parse(response)) 查看您的 ajax 响应数据

    error_log(json_encode($featureCollection) 看看你的 php 发送了什么

    根据结果,您会知道问题出在服务器端还是浏览器端。

    【讨论】:

    • 所以,事实证明我的数据不在正确的投影中,而是在其他地方绘制。很抱歉长时间延迟回复。我这样做是为了了解更多信息。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 2012-03-26
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多