我有一个 GUI 应用程序,其中我的数据库中的数据显示在表格上,并在传单地图上显示为标记。我已将 Geocode ( L.Control.geocoder() ) 函数添加到我的应用程序中,现在想要显示我的数据库中适合我的 Geocode 位置所在地图边界的标记。
我已经阅读了传单文档中的 map.toBBoxString() 和 map.getBounds() ,这是我认为我需要进行比较并为我的数据库数据编写查询以显示在输入的“地理编码”位置的内容. 我的问题是我不知道如何获取实际值并对我的 Python 查询进行比较。下面是我的代码的搜索按钮部分,它连接到函数以显示用户在 table 和 map 上输入的数据。
def search_all(self):
print ('Searching All...')
looking = str(self.lookall.text())
if looking == "":
QMessageBox.about(self, "No Info ", " Please enter value ")
else :
conn = #connection to DB
cursor = conn.cursor()
query = "SELECT*FROM CT_ALL_F WHERE Lic_no LIKE '%s' OR Licensee LIKE '%s' OR FREQ LIKE '%s' OR Power LIKE '%s' OR Installation_address LIKE '%s' OR Business_address LIKE '%s' OR Tel LIKE '%s' " %('%'+looking+'%','%'+looking+'%','%'+looking+'%','%'+looking+'%','%'+looking+'%','%'+looking+'%','%'+looking+'%')
cursor.execute(query)
results = cursor.fetchall()
self.tableWidget.setRowCount(0)
for row_number, row_data in enumerate(results):
self.tableWidget.insertRow(row_number)
for column_number, data in enumerate (row_data):
self.tableWidget.setItem(row_number,column_number,QtWidgets.QTableWidgetItem(str(data)))
pass
pass
coordinates = []
for result in results:
coordinates.append((result[5], result[6] ,(result[0], result[1],result[2],result[3],result[4])))
lat_center = sum([coordinate[0] for coordinate in coordinates]) / len(coordinates)
lng_center = sum([coordinate[1] for coordinate in coordinates]) / len(coordinates)
html = """
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html { height: 100%; }
body { height: 100%; margin: 0; padding: 0 }
#mapid { height: 100% }
</style>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw==" crossorigin=""></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.css" />
<script src="https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js"></script>
</head>
<body>
<div id="mapDiv" style="width:100%; height:100%"</div>
<script>
"""
html += "var map = L.map('mapDiv').setView([{lat}, {lng}], 10);".format(lat=lat_center, lng=lng_center)
html += """
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.icasa.org.za/">ICASA</a> <br> <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors',
}).addTo(map);
"""
for latitude, longitude , frequency in coordinates:
html += "var marker = L.marker([{lat}, {lng}]);\n ".format(lat=latitude, lng=longitude)
html += "var popupLocation1 = new L.LatLng({lat}, {lng});".format(lat=latitude, lng=longitude )
html += """var popupContent1 = ("License number : {freq}<br>Licensee: {dek}<br>Frequency : {lek}<br>Power : {sek}<br>Location : {mek}<br>"),""".format(freq=frequency[0],dek=frequency[1],lek=frequency[2],sek=frequency[3],mek=frequency[4])
html += "popup1 = new L.Popup();"
html += "popup1.setLatLng(popupLocation1);"
html += "popup1.setContent(popupContent1);"
html+= "marker.bindPopup(popupContent1);"
html += "map.addLayer(popup1).addLayer(marker);"
html += "L.Control.geocoder().addTo(map);</script> </body> </html>"
self.view.setHtml(html)
在输入地理编码位置后,我希望从我的数据库中看到位于地图地图边界内的标记,并显示在我的传单地图上
我将数据类型从我的 Ms Access DB 更改为短文本,这使我能够使用从 geocoder 获得的边界框坐标从我的数据库结果中编写比较查询。这有效
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句