Skip to content

Commit

Permalink
[worldmap-client] Improvements and fixes on the Gazetteer. Fixes #4072.
Browse files Browse the repository at this point in the history
  • Loading branch information
capooti committed Nov 13, 2018
1 parent 43685d7 commit 7df535c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
6 changes: 4 additions & 2 deletions geonode/client/templates/worldmap/maps/map_worldmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% load static from staticfiles %}

<script type="text/javascript">
OpenLayers.ImgPath = "{% static "worldmap_client/externals/openlayers/theme/default/img" %}";
OpenLayers.ImgPath = "{% static "worldmap_client/externals/openlayers/img/" %}";
OpenLayers.Util.onImageLoadErrorColor = 1;
OpenLayers.Util.onImageLoadErrorColor = 'transparent';
OpenLayers.Util.onImageLoadError = function() {
Expand Down Expand Up @@ -194,7 +194,8 @@
title: '<span class="x-btn-text">{% trans 'Find Place' %}</span>',
iconCls: null,
toggleGroup: 'featureGroup',
pressed: false
pressed: false,
services: '{{ GAZETTEER_SERVICES }}'
}
{% endif %}
{% if user.is_authenticated and DB_DATASTORE %},
Expand Down Expand Up @@ -303,6 +304,7 @@
id: id
})
};

{% endautoescape %}
}
$(document).ready(init);
Expand Down
6 changes: 6 additions & 0 deletions geonode/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ def resource_urls(request):

defaults['USE_GAZETTEER'] = settings.USE_GAZETTEER

defaults['GAZETTEER_SERVICES'] = getattr(
settings,
'GAZETTEER_SERVICES',
'worldmap,geonames,nominatim'
)

defaults['GOOGLE_API_KEY'] = settings.GOOGLE_API_KEY

defaults['GOOGLE_MAPS_API_KEY'] = settings.GOOGLE_MAPS_API_KEY
Expand Down
3 changes: 1 addition & 2 deletions geonode/contrib/worldmap/gazetteer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def getGazetteerResults(place_name, map=None, layer=None, start_date=None, end_d
end_date: return only matches with an end date <= this value
project: only return matches within the specified project
"""

layers = []
if map:
mapObject = get_object_or_404(Map, pk=map)
Expand Down Expand Up @@ -426,7 +425,7 @@ def getConnection(layer_store=None):


def getGeonamesResults(place_name):
g = geocoders.GeoNames(username=settings.GEONAMES_USER)
g = geocoders.GeoNames(username=settings.GAZETTEER_GEONAMES_USER)
try:
results = g.geocode(place_name, False)
formatted_results = []
Expand Down
10 changes: 6 additions & 4 deletions geonode/contrib/worldmap/gazetteer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ def search(request, place_name, map=None, layer=None,
if out_format not in ('xml', 'json'):
out_format = 'json'

if place_name.isdigit():
posts = getGazetteerEntry(place_name)
else:
posts = getGazetteerResults(place_name, map, layer, start_date, end_date, project, user)
posts = []
if 'worldmap' in services:
if place_name.isdigit():
posts = getGazetteerEntry(place_name)
else:
posts = getGazetteerResults(place_name, map, layer, start_date, end_date, project, user)
if services is not None:
posts.extend(getExternalServiceResults(place_name, services))
if out_format == 'json':
Expand Down
9 changes: 7 additions & 2 deletions geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1628,17 +1628,22 @@

if USE_WORLDMAP:
GEONODE_CLIENT_LOCATION = '/static/worldmap_client/'
GAZETTEER_DB_ALIAS = 'default'
INSTALLED_APPS += (
'geoexplorer-worldmap',
'geonode.contrib.worldmap.gazetteer',
'geonode.contrib.worldmap.wm_extra',
'geonode.contrib.createlayer',
)
# WorldMap Gazetter settings
USE_GAZETTEER = True
GAZETTEER_DB_ALIAS = 'default'
GAZETTEER_FULLTEXTSEARCH = False
# external services to be used by the gazetteer
GAZETTEER_SERVICES = 'worldmap,geonames,nominatim'
# this is the GeoNames key which is needed by the WorldMap Gazetteer
GAZETTEER_GEONAMES_USER = os.getenv('GEONAMES_USER', 'your-key-here')
WM_COPYRIGHT_URL = "http://gis.harvard.edu/"
WM_COPYRIGHT_TEXT = "Center for Geographic Analysis"
USE_GAZETTEER = True
DEFAULT_MAP_ABSTRACT = """
<h3>The Harvard WorldMap Project</h3>
<p>WorldMap is an open source web mapping system that is currently
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pycountry
# required by worldmap
datautil==0.4
dicttoxml==1.7.4
django-geoexplorer-worldmap==4.0.51
django-geoexplorer-worldmap==4.0.52
geopy==1.14.0

#production
Expand Down

0 comments on commit 7df535c

Please sign in to comment.