Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom to location completed. #1077

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion controllers/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3780,4 +3780,77 @@ def screenshot():
else:
raise HTTP(500, "Screenshot not taken")

# END =========================================================================
# =============================================================================
def search_gis_locations():
import urllib2

#Get vars from url
user_str = get_vars["name_startsWith"]
callback_func = request.vars["callback"]
atable = db.gis_location
query = atable.name.lower().like(user_str + '%')
rows = db(query).select(atable.id,
atable.level,
atable.name,
atable.lat,
atable.lon
)
results = []
count = 0
for row in rows:
count += 1
result = {}

#Convert the level colum into the ADM codes geonames returns
#fcode = row["gis_location.level"]
level = row["gis_location.level"]
if level=="L0": #Country
fcode = "PCL" #Zoom 5
elif level=="L1": #State/Province
fcode = "ADM1"
elif level=="L2": #County/District
fcode = "ADM2"
elif level=="L3": #Village/Suburb
fcode = "ADM3"
else: #City/Town/Village
fcode = "ADM4"

result = {"id" : row["gis_location.id"],
"fcode" : fcode,
"name" : row["gis_location.name"],
"lat" : row["gis_location.lat"],
"lng" : row["gis_location.lon"]}
results.append(result)

#if count = 0, then search on geonames
if count == 0:
username = settings.get_gis_geonames_username()
maxrows = "20"
lang = "en"
charset = "UTF8"
nameStartsWith = user_str
geonames_base_url = "http://ws.geonames.org/searchJSON?"
url = "%susername=%s&maxRows=%s&lang=%s&charset=%s&name_startsWith=%s" % (geonames_base_url,username,maxrows,lang,charset,nameStartsWith)
response = urllib2.urlopen(url)
dictResponse = json.loads(response.read().decode(response.info().getparam('charset') or 'utf-8'))
response.close()

results = []
if dictResponse["totalResultsCount"] != 0:
geonamesResults = dictResponse["geonames"]
for geonamesResult in geonamesResults:
result = {}

result = {"id" : int(geonamesResult["geonameId"]), "fcode" : str(geonamesResult["fcode"]),
"name" : str(geonamesResult["name"]),"lat" : float(geonamesResult["lat"]),
"lng" : float(geonamesResult["lng"])}
results.append(result)

returnVal = {}
returnVal["gislocations"] = results
returnVal["totalResultsCount"] = count

#Autocomplete caller expects JSONP response. Callback wrapper.
return callback_func+'('+json.dumps(returnVal)+')'

# END =========================================================================
47 changes: 40 additions & 7 deletions static/scripts/gis/GeoExt/ux/GeoNamesSearchCombo.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ GeoExt.ux.GeoNamesSearchCombo = Ext.extend(Ext.form.ComboBox, {
* See http://www.dev.sencha.com/deploy/dev/docs/source/Combo.html#cfg-Ext.form.ComboBox-loadingText,
* default value is "Search in Geonames...".
*/
loadingText: 'Search in Geonames...',
loadingText: 'Searching locations...',

/** api: config[emptyText]
* See http://www.dev.sencha.com/deploy/dev/docs/source/TextField.html#cfg-Ext.form.TextField-emptyText,
* default value is "Search location in Geonames".
* default value is "Search locations".
*/
emptyText: 'Search location in Geonames',
emptyText: 'Search locations',

/** api: config[username]
* ``String`` Username to send with API requests. Mandatory.
Expand Down Expand Up @@ -217,7 +217,8 @@ GeoExt.ux.GeoNamesSearchCombo = Ext.extend(Ext.form.ComboBox, {
/** private: property[url]
* Url of the GeoNames service: http://www.GeoNames.org/export/GeoNames-search.html
*/
url: 'http://ws.geonames.org/searchJSON?',
/*url: 'http://ws.geonames.org/searchJSON?',*/
url: 'http://'+window.location.hostname+':8000/eden/gis/search_gis_locations.html/',

/** private: constructor
*/
Expand All @@ -238,9 +239,40 @@ GeoExt.ux.GeoNamesSearchCombo = Ext.extend(Ext.form.ComboBox, {
urlAppendString = urlAppendString + this.featureCodeString;
}

//Query internal locations first
this.store = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: this.url,
method: 'GET'
}),
reader: new Ext.data.JsonReader({
idProperty: 'id',
root: "gislocations",
totalProperty: "totalResultsCount",
fields: [
{
name:'id'
},
{
name:'fcode'
},
{
name: 'name'
},
{
name: 'lng'
},
{
name: 'lat'
}
]
}) //End reader
}); //End store

/*if(this.store.reader.totalProperty==0){ //No internal matches
this.store = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: this.url + urlAppendString,
url: 'http://ws.geonames.org/searchJSON?' + urlAppendString,
method: 'GET'
}),
baseParams: {
Expand Down Expand Up @@ -298,8 +330,9 @@ GeoExt.ux.GeoNamesSearchCombo = Ext.extend(Ext.form.ComboBox, {
name: 'adminName1'
}
]
})
});
}) //End reader
});//end store
}//end if*/

if (this.zoom > 0) {
this.on("select", function(combo, record, index) {
Expand Down
Empty file.