@@ -101,11 +101,11 @@ const hasOutputFormat = (data) => {
101101 return toPairs ( pickedObj ) . map ( ( [ prop , value ] ) => ( { name : prop , label : value } ) ) ;
102102} ;
103103
104- const getWFSFeature = ( { url, filterObj = { } , layerFilter, layer, downloadOptions = { } , options } = { } ) => {
104+ const getWFSFeature = ( { url, filterObj = { } , layerFilter, layer, viewportFilter , downloadOptions = { } , options } = { } ) => {
105105 const { sortOptions, propertyNames } = options ;
106106
107107 const cqlFilter = getCQLFilterFromLayer ( layer ) ;
108- const data = mergeFiltersToOGC ( { ogcVersion : '1.1.0' , addXmlnsToRoot : true , xmlnsToAdd : [ 'xmlns:ogc="http://www.opengis.net/ogc"' , 'xmlns:gml="http://www.opengis.net/gml"' ] } , downloadOptions . downloadFilteredDataSet ? layerFilter : { } , downloadOptions . downloadFilteredDataSet ? filterObj : { } , cqlFilter ) ;
108+ const data = mergeFiltersToOGC ( { ogcVersion : '1.1.0' , addXmlnsToRoot : true , xmlnsToAdd : [ 'xmlns:ogc="http://www.opengis.net/ogc"' , 'xmlns:gml="http://www.opengis.net/gml"' ] } , downloadOptions . downloadFilteredDataSet ? layerFilter : { } , downloadOptions . downloadFilteredDataSet ? filterObj : { } , viewportFilter , cqlFilter ) ;
109109
110110 return getXMLFeature ( url , getFilterFeature ( query (
111111 filterObj . featureTypeName , [ ...( sortOptions ? [ sortBy ( sortOptions . sortBy , sortOptions . sortOrder ) ] : [ ] ) , ...( propertyNames ? [ propertyName ( propertyNames ) ] : [ ] ) , ...( data ? castArray ( data ) : [ ] ) ] ,
@@ -123,11 +123,45 @@ const getFileName = action => {
123123 return name ;
124124} ;
125125const getDefaultSortOptions = ( attribute ) => {
126- return attribute ? { sortBy : attribute , sortOrder : 'A' } : { } ;
126+ return attribute ? { sortBy : attribute , sortOrder : 'A' } : null ;
127127} ;
128128const getFirstAttribute = ( state ) => {
129129 return state . query && state . query . featureTypes && state . query . featureTypes [ state . query . typeName ] && state . query . featureTypes [ state . query . typeName ] . attributes && state . query . featureTypes [ state . query . typeName ] . attributes [ 0 ] && state . query . featureTypes [ state . query . typeName ] . attributes [ 0 ] . attribute || null ;
130130} ;
131+ const getBboxExtent = ( bounds = { } ) => {
132+ return Array . isArray ( bounds )
133+ ? bounds
134+ : [ bounds . minx , bounds . miny , bounds . maxx , bounds . maxy ] ;
135+ } ;
136+ const getViewportFilter = ( cropDataSet , mapBbox , geometryAttribute ) => {
137+ if ( ! cropDataSet || ! mapBbox ?. bounds ) {
138+ return null ;
139+ }
140+ const projection = mapBbox . crs || 'EPSG:4326' ;
141+ if ( geometryAttribute ) {
142+ return {
143+ spatialField : {
144+ geometry : {
145+ ...bboxToFeatureGeometry ( mapBbox . bounds ) ,
146+ projection
147+ } ,
148+ attribute : geometryAttribute ,
149+ method : 'Rectangle' ,
150+ operation : 'INTERSECTS'
151+ }
152+ } ;
153+ }
154+ return {
155+ spatialField : {
156+ geometry : {
157+ extent : [ getBboxExtent ( mapBbox . bounds ) ] ,
158+ projection
159+ } ,
160+ method : 'BBOX' ,
161+ operation : 'BBOX'
162+ }
163+ } ;
164+ } ;
131165
132166const wpsExecuteErrorToMessage = e => {
133167 switch ( e . code ) {
@@ -255,11 +289,11 @@ export const startFeatureExportDownload = (action$, store) =>
255289
256290 const mapBbox = mapBboxSelector ( state ) ;
257291 const currentLocale = currentLocaleSelector ( state ) ;
292+ const geometryAttribute = extractGeometryAttributeName ( layerDescribeSelector ( state , layer . name ) ) ;
258293 const propertyNames = action . downloadOptions . propertyName ? [
259- extractGeometryAttributeName ( layerDescribeSelector ( state , layer . name ) ) ,
294+ ... ( geometryAttribute ? [ geometryAttribute ] : [ ] ) ,
260295 ...action . downloadOptions . propertyName
261296 ] : null ;
262-
263297 const { layerFilter } = layer ;
264298
265299 const wfsFlow = ( ) => getWFSFeature ( {
@@ -268,6 +302,7 @@ export const startFeatureExportDownload = (action$, store) =>
268302 filterObj : isNil ( action . filterObj ) ? { } : action . filterObj ,
269303 layer,
270304 layerFilter,
305+ viewportFilter : getViewportFilter ( action . downloadOptions . cropDataSet , mapBbox , geometryAttribute ) ,
271306 options : {
272307 pagination : ! virtualScroll && get ( action , "downloadOptions.singlePage" ) ? action . filterObj && action . filterObj . pagination : null ,
273308 propertyNames
@@ -289,11 +324,12 @@ export const startFeatureExportDownload = (action$, store) =>
289324 filterObj : action . filterObj ,
290325 layer,
291326 layerFilter,
327+ viewportFilter : getViewportFilter ( action . downloadOptions . cropDataSet , mapBbox , geometryAttribute ) ,
292328 options : {
293329 pagination : ! virtualScroll && get ( action , "downloadOptions.singlePage" ) ? action . filterObj && action . filterObj . pagination : null ,
294330 sortOptions : getDefaultSortOptions ( getFirstAttribute ( store . getState ( ) ) ) ,
295331 propertyNames : action . downloadOptions . propertyName ? [ ...action . downloadOptions . propertyName ,
296- extractGeometryAttributeName ( layerDescribeSelector ( state , layer . name ) ) ] : null
332+ ... ( geometryAttribute ? [ geometryAttribute ] : [ ] ) ] : null
297333 }
298334 } ) . do ( ( { data, headers } ) => {
299335 if ( headers [ "content-type" ] === "application/xml" ) { // TODO add expected mimetypes in the case you want application/dxf
0 commit comments