Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoInt_SIDT
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoInt_SIDT
Commits
db4f1e27
Commit
db4f1e27
authored
May 10, 2019
by
Emmanuel René Huchim Puc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
search purchase area in search region
parent
1a367e33
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
27 deletions
+44
-27
dataRetrieval.js
catalog/static/catalog/js/dataRetrieval.js
+20
-17
views.py
catalog/views.py
+24
-10
No files found.
catalog/static/catalog/js/dataRetrieval.js
View file @
db4f1e27
...
@@ -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
.
stat
e
;
temp
.
content
.
querySelectorAll
(
'span'
)[
0
].
textContent
=
search_nam
e
;
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
)
}
}
});
});
}
}
...
...
catalog/views.py
View file @
db4f1e27
...
@@ -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
})
# -------------------------------------------------------------------------------
# -------------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment