Skip to content
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
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ Other:
- Fix search which include the terms "and", "or" and "not"
[jeffersonbledsoe]

- implement AJAX geoJSON feature (needs ``plone.patternslib>=1.2.2``)
[petschki]


3.4.2 (2021-02-25)
------------------
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def read(*rnames):
# support for latitude/longitude catalog index
"collective.geolocationbehavior >= 1.6.0",
# refactored map configuration
"plone.formwidget.geolocation >= 2.2.0",
# leaflet JS events for map filter
"plone.patternslib >= 1.1.0",
'plone.formwidget.geolocation >= 2.2.0',
# AJAX geoJSON feature
'plone.patternslib >= 1.2.2.dev0',
],
"test": [
"plone.app.mosaic",
Expand Down
106 changes: 66 additions & 40 deletions src/collective/collectionfilter/baseviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
from plone import api
from plone.api.portal import get_registry_record as getrec
from plone.app.uuid.utils import uuidToCatalogBrain
from plone.app.uuid.utils import uuidToObject
from plone.i18n.normalizer.interfaces import IIDNormalizer
from plone.memoize import instance
from plone.uuid.interfaces import IUUID
from Products.CMFPlone.utils import get_top_request
from Products.CMFPlone.utils import safe_unicode
from Products.Five import BrowserView
from six.moves.urllib.parse import urlencode
from zope.component import getUtility
from zope.component import queryUtility
Expand Down Expand Up @@ -303,32 +303,50 @@ def ajax_url(self):
return ajax_url

@property
def locations(self):
custom_query = {} # Additional query to filter the collection

collection = uuidToObject(self.collection_uuid)
if not collection:
return None

def geojson_ajax_url(self):
# Recursively transform all to unicode
request_params = safe_decode(self.top_request.form or {})

# Get all collection results with additional filter
# defined by urlquery
custom_query = base_query(request_params)
custom_query = make_query(custom_query)
return (
ICollectionish(collection)
.selectContent(self.settings.content_selector)
.results(custom_query, request_params)
request_params = safe_decode(self.top_request.form)
urlquery = base_query(
request_params, extra_ignores=['latitude', 'longitude'])
query_param = urlencode(safe_encode(urlquery), doseq=True)
geojson_ajax_url = u'{}/@@geodata.json?geojson-limit={}{}'.format(
self.collection.getURL(),
self.settings.geojson_properties_limit,
'&' + query_param if query_param else '',
)
return geojson_ajax_url

@property
def data_geojson(self):
def map_configuration(self):
config = {
"fullscreencontrol": getrec("geolocation.fullscreen_control"),
"locatecontrol": getrec("geolocation.locate_control"),
"zoomcontrol": getrec("geolocation.zoom_control"),
"minimap": getrec("geolocation.show_minimap"),
"default_map_layer": self.settings.default_map_layer,
"map_layers": [
{"title": translate(_(it), context=self.request), "id": it}
for it in self.settings.map_layers
],
}
return json.dumps(config)


class GeoJSON(BaseView, BrowserView):

def __call__(self):
"""Return the geo location as GeoJSON string."""
self.request.response.setHeader("Content-type", "application/json")
features = []
locations = self.locations
count = len(locations)

try:
limit = int(self.request.get("geojson-limit"))
except Exception:
limit = 500

for it in self.locations:
for it in locations:
if not it.longitude or not it.latitude:
# these ``it`` are brains, so anything which got lat/lng
# indexed can be used.
Expand All @@ -347,13 +365,14 @@ def data_geojson(self):
},
}

props = IGeoJSONProperties(it.getObject(), None)
if getattr(props, "popup", None):
feature["properties"]["popup"] = props.popup
if getattr(props, "color", None):
feature["properties"]["color"] = props.color
if getattr(props, "extraClasses", None):
feature["properties"]["extraClasses"] = props.extraClasses
if count < limit:
props = IGeoJSONProperties(it.getObject(), None)
if getattr(props, 'popup', None):
feature['properties']['popup'] = props.popup
if getattr(props, 'color', None):
feature['properties']['color'] = props.color
if getattr(props, 'extraClasses', None):
feature['properties']['extraClasses'] = props.extraClasses

features.append(feature)

Expand All @@ -364,16 +383,23 @@ def data_geojson(self):
return geo_json

@property
def map_configuration(self):
config = {
"fullscreencontrol": getrec("geolocation.fullscreen_control"),
"locatecontrol": getrec("geolocation.locate_control"),
"zoomcontrol": getrec("geolocation.zoom_control"),
"minimap": getrec("geolocation.show_minimap"),
"default_map_layer": self.settings.default_map_layer,
"map_layers": [
{"title": translate(_(it), context=self.request), "id": it}
for it in self.settings.map_layers
],
}
return json.dumps(config)
def locations(self):

custom_query = {} # Additional query to filter the collection

collection = api.content.get(UID=self.collection_uuid)
if not collection:
return None

# Recursively transform all to unicode
request_params = safe_decode(self.top_request.form or {})

# Get all collection results with additional filter
# defined by urlquery
custom_query = base_query(request_params)
custom_query = make_query(custom_query)
return (
ICollectionish(collection)
.selectContent(self.settings.content_selector)
.results(custom_query, request_params)
)
8 changes: 8 additions & 0 deletions src/collective/collectionfilter/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
handler=".contentfilter.set_content_filter"
/>

<browser:page
zcml:condition="installed collective.geolocationbehavior"
name="geodata.json"
class=".baseviews.GeoJSON"
for="*"
permission="zope2.View"
/>

<genericsetup:registerProfile
name="default"
title="collective.collectionfilter base"
Expand Down
14 changes: 13 additions & 1 deletion src/collective/collectionfilter/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,16 @@ class ICollectionMapsSchema(ICollectionFilterBaseSchema):
value_type=schema.Choice(
vocabulary="plone.formwidget.geolocation.vocabularies.map_layers"
),
) # noqa: E501
)

geojson_properties_limit = schema.Int(
title=_(
u'geojson_properties_limit',
default=u"Limit for GeoJSON properties"),
description=_(
u'help_geojson_properties_limit',
default=u"If the search result is larger than this limit, no additional "
"GeoJSON properties (like popup information) are shown."),
required=False,
default=500,
)
5 changes: 2 additions & 3 deletions src/collective/collectionfilter/portlets/maps.pt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

<header class="portletHeader" tal:condition="view/title" tal:content="view/title">Title</header>
<tal:if condition="view/collection|nothing">
<tal:def define="geojson view/data_geojson">
<header tal:condition="view/title" tal:content="view/title">Title</header>
<div class="pat-leaflet" data-pat-leaflet='${view/map_configuration}' data-url="${view/ajax_url}" data-narrow-down-result="${view/settings/narrow_down}"
tal:attributes="data-geojson python:geojson or None"></div>
</tal:def>
data-geojson="${view/geojson_ajax_url}"></div>
<div class="plone-loader"><div class="loader" /></div>
</tal:if>
</aside>
3 changes: 3 additions & 0 deletions src/collective/collectionfilter/portlets/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Assignment(base.Assignment):
narrow_down = False
default_map_layer = default_map_layer
map_layers = default_map_layers
geojson_properties_limit = 500

def __init__(
self,
Expand All @@ -35,6 +36,7 @@ def __init__(
narrow_down=False,
default_map_layer=default_map_layer,
map_layers=default_map_layers,
geojson_properties_limit=500,
):
self.header = header
self.target_collection = target_collection
Expand All @@ -43,6 +45,7 @@ def __init__(
self.narrow_down = narrow_down
self.default_map_layers = default_map_layers
self.map_layers = map_layers
self.geojson_properties_limit = geojson_properties_limit

@property
def title(self):
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading