search purchase area in search region

parent 1a367e33
...@@ -13,7 +13,7 @@ var polygonList; ...@@ -13,7 +13,7 @@ var polygonList;
var makeRequest = function (value) { var makeRequest = function (value) {
var pol_element = document.getElementById('polygon-list'); var pol_element = document.getElementById('polygon-list');
console.log("hola");
// city request to DB // city request to DB
// variable req_url in map.html // variable req_url in map.html
$.ajax({ $.ajax({
...@@ -46,10 +46,15 @@ var makeRequest = function (value) { ...@@ -46,10 +46,15 @@ var makeRequest = function (value) {
} else { } else {
data.polygonList.forEach(function (polygon) { data.polygonList.forEach(function (polygon) {
var temp = document.querySelector('#city_list_template'); var temp = document.querySelector('#city_list_template');
let search_name = polygon.city + ", " + polygon.state;
if (!polygon.state) {
search_name = polygon.city;
}
// filling template // filling template
temp.content.querySelector('li').id = polygon.id; temp.content.querySelector('li').id = polygon.id;
temp.content.querySelectorAll('span')[0].textContent = polygon.city + ", " + polygon.state; temp.content.querySelectorAll('span')[0].textContent = search_name;
temp.content.querySelectorAll('span')[1].textContent = polygon.description; temp.content.querySelectorAll('span')[1].textContent = polygon.description;
temp.content.querySelectorAll('div')[3].textContent = "Fuente: " + polygon.source; temp.content.querySelectorAll('div')[3].textContent = "Fuente: " + polygon.source;
...@@ -153,26 +158,24 @@ function drawPolygon(element) { ...@@ -153,26 +158,24 @@ function drawPolygon(element) {
// clean product panel // clean product panel
erase_product_list_globe(); erase_product_list_globe();
// set input box with polygon city name
var input_text = polygon.city + ", " + polygon.state;
$("#ajax-input").val(input_text);
$('#search_name').val(input_text);
$("#area_description").val(polygon.description)
// remove prev polygon // remove prev polygon
osmap.removePolygon(); osmap.removePolygon();
// draw wkt polygon var input_text = polygon.city;
// osmap.addWKTPolygon(polygon.wkt_polygon);
// format coords to draw if (polygon.geojson.geometry) {
var coords = osmap.formatCoords(polygon.geojson.geometry.coordinates); var coords = osmap.formatCoords(polygon.geojson.geometry.coordinates);
// get the biggest area
// var biggest = osmap.getBiggestPolygon(coords); // var biggest = osmap.getBiggestPolygon(coords);
// draw coordsR
osmap.addPolygon(coords); osmap.addPolygon(coords);
input_text += ", " + polygon.state
} else {
osmap.addWKTPolygon(polygon.wkt_polygon);
}
// set input box with polygon city name
$("#ajax-input").val(input_text);
$('#search_name').val(input_text);
$("#area_description").val(polygon.description)
} }
}); });
} }
......
...@@ -199,14 +199,17 @@ class SearchSubmitView(View): ...@@ -199,14 +199,17 @@ class SearchSubmitView(View):
def post(self, request): def post(self, request):
template = loader.get_template(self.template) template = loader.get_template(self.template)
searchValue = request.POST.get('value', '') searchValue = request.POST.get('value', '')
searchValue = self.strip_accents(searchValue).lower() searchValue_lower = self.strip_accents(searchValue).lower()
## A simple query for Polygon objects whose name is 'searchValue' ## A simple query for Polygon objects whose name is 'searchValue'
## We exclude those polygons whose E_MUN field are NULL .encode("utf-8")since at this point we're only interested ## We exclude those polygons whose E_MUN field are NULL .encode("utf-8")since at this point we're only interested
## on polygons that represent cities (Municipios). ## on polygons that represent cities (Municipios).
polygonList = Polygon.objects.filter(name__startswith=searchValue).exclude(E_MUN__isnull=True) polygonList = Polygon.objects.filter(name__startswith=searchValue_lower).exclude(E_MUN__isnull=True)
purchased_list = Purchase.objects.values('id', 'name', 'description', 'search__area').filter(user_id=request.user.id, name__startswith=searchValue)
data_list = [] data_list = []
# append searched polygons from Polygon table
if len(polygonList) > 0: if len(polygonList) > 0:
for polygon in polygonList: for polygon in polygonList:
polygonInfo = json.loads(polygon.json_info) polygonInfo = json.loads(polygon.json_info)
...@@ -221,11 +224,22 @@ class SearchSubmitView(View): ...@@ -221,11 +224,22 @@ class SearchSubmitView(View):
'source': polygon.source 'source': polygon.source
}) })
data = { # append searched polygons from Purchase table
'polygonList': data_list if len(purchased_list) > 0:
} for purchase in purchased_list:
data_list.append({
'id': 'p{}'.format(purchase['id']),
'city': purchase['name'],
'state': '',
'geojson': {},
'wkt_polygon': purchase['search__area'],
'description': purchase['description'],
'source': 'Purchase'
})
return JsonResponse(data) return JsonResponse({
'polygonList': data_list
})
# ------------------------------------------------------------------------------- # -------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment