根据输入的地理编码位置,从数据库中显示落在地图范围内的传单标记
Show leaflet markers that falls inside mapbounds,based on geocode location entered , from database
我有一个 GUI 应用程序,其中来自我的数据库的数据显示在 table 上,并在传单地图上显示为标记。我已将 Geocode (L.Control.geocoder()) 函数添加到我的应用程序中,现在想显示来自我的数据库的标记,这些标记适合我的 Geocode 位置所在的地图边界。
我已经阅读了传单文档中的 map.toBBoxString() 和 map.getBounds(),我认为我需要进行比较并为要显示的数据库数据编写查询在 'Geo-coded' 位置输入。我的问题是我不知道如何获取实际值并对我的 Python 查询进行比较。下面是我的搜索按钮部分代码,它连接到显示用户在 table 和地图上输入的数据的功能。
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/leaflet@1.3.1/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.3.1/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 数据库更改为短文本,这使我能够根据我的数据库结果与我从地理编码器获得的边界框坐标编写比较查询。这有效
我有一个 GUI 应用程序,其中来自我的数据库的数据显示在 table 上,并在传单地图上显示为标记。我已将 Geocode (L.Control.geocoder()) 函数添加到我的应用程序中,现在想显示来自我的数据库的标记,这些标记适合我的 Geocode 位置所在的地图边界。
我已经阅读了传单文档中的 map.toBBoxString() 和 map.getBounds(),我认为我需要进行比较并为要显示的数据库数据编写查询在 'Geo-coded' 位置输入。我的问题是我不知道如何获取实际值并对我的 Python 查询进行比较。下面是我的搜索按钮部分代码,它连接到显示用户在 table 和地图上输入的数据的功能。
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/leaflet@1.3.1/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.3.1/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 数据库更改为短文本,这使我能够根据我的数据库结果与我从地理编码器获得的边界框坐标编写比较查询。这有效