def _build_payload(self, params, layer, feature_count, version, bbox, width, height, x, y, cql_filters, cql_filter_string, _buffer): """Build the request payload for GetFeatureInfo.""" DATUM_key = 'SRS' X_key = 'X' Y_key = 'Y' if version == '1.3.0': DATUM_key = 'CRS' X_key = 'I' Y_key = 'J' payload = { 'REQUEST': 'GetFeatureInfo', 'EXCEPTIONS': 'application/vnd.ogc.se_xml', 'INFO_FORMAT': self._get_feature_mimetype(), 'SERVICE': 'WMS', DATUM_key: 'EPSG:3857', # Always Google (web mercator) 'FEATURE_COUNT': feature_count, # Set the layer we want 'LAYERS': layer, 'QUERY_LAYERS': layer, 'BBOX': bbox, # Height and width in pixels 'HEIGHT': height, 'WIDTH': width, # The clicked on pixel X_key: x, Y_key: y, # Version from parameter 'VERSION': version, # Non-standard WMS parameter to slightly increase search # radius. Shouldn't hurt as most WMS server software ignore # unknown parameters. see # http://docs.geoserver.org/latest/en/user/services/wms/vendor.html 'BUFFER': _buffer, } # Add styles to request when defined if 'styles' in params and params['styles']: payload['STYLES'] = params['styles'] total_cql_filter = [] # cql filter string comes from Filter Page if cql_filter_string: total_cql_filter.append(cql_filter_string) # cql filter defined in the wms source parameters if 'cql_filter' in params and params['cql_filter']: total_cql_filter.append(params['cql_filter']) # CQL filters passed through from the frontend if cql_filters is not None: allowed_filters = self.featureline_set.filter( visible=True, name__in=cql_filters.keys() ).values_list('name', flat=True) for key in allowed_filters: total_cql_filter.append('='.join([key, str(cql_filters[key])])) if total_cql_filter: payload['CQL_FILTER'] = ' AND '.join(total_cql_filter) if self.timepositions: # Get the user selected date/time selection. date = get_view_state(tls.request) formatting = '%Y-%m-%dT%H:%M:%SZ' payload['TIME'] = '/'.join( d.strftime(formatting) for d in [date['dt_start'], date['dt_end']]) return payload