@@ -367,4 +367,106 @@ describe('leaflet_FeatureService_getFeaturesByBounds', () => {
367367 done ( ) ;
368368 } ) ;
369369 } ) ;
370+
371+ it ( 'getFeaturesCount' , done => {
372+ var polygon = L . polygon ( [
373+ [ - 20 , 20 ] ,
374+ [ 0 , 20 ] ,
375+ [ 0 , 40 ] ,
376+ [ - 20 , 40 ] ,
377+ [ - 20 , 20 ]
378+ ] ) ;
379+ var getFeaturesByBoundsParams = new GetFeaturesByBoundsParameters ( {
380+ datasetNames : [ 'World:Capitals' ] ,
381+ bounds : polygon . getBounds ( ) ,
382+ returnContent : true
383+ } ) ;
384+ var getFeaturesByBoundsService = featureService ( dataServiceURL , options ) ;
385+ spyOn ( FetchRequest , 'commit' ) . and . callFake ( ( method , testUrl , params , options ) => {
386+ expect ( method ) . toBe ( 'POST' ) ;
387+ expect ( testUrl ) . toBe ( dataServiceURL + '/featureResults?fromIndex=0&toIndex=19&returnCountOnly=true&returnContent=true' ) ;
388+ var paramsObj = JSON . parse ( params . replace ( / ' / g, '"' ) ) ;
389+ expect ( paramsObj . datasetNames [ 0 ] ) . toBe ( 'World:Capitals' ) ;
390+ expect ( paramsObj . getFeatureMode ) . toBe ( 'BOUNDS' ) ;
391+ expect ( paramsObj . spatialQueryMode ) . toBe ( 'CONTAIN' ) ;
392+ expect ( options ) . not . toBeNull ( ) ;
393+ return Promise . resolve ( new Response ( JSON . stringify ( {
394+ "features" : null ,
395+ "featureUriList" : null ,
396+ "datasetInfos" : null ,
397+ "totalCount" : 1889 ,
398+ "featureCount" : 20
399+ } ) ) ) ;
400+ } ) ;
401+ getFeaturesByBoundsService . getFeaturesCount ( getFeaturesByBoundsParams , result => {
402+ serviceResult = result ;
403+ try {
404+ expect ( getFeaturesByBoundsService ) . not . toBeNull ( ) ;
405+ expect ( serviceResult . result ) . not . toBeNull ( ) ;
406+ expect ( serviceResult . result . succeed ) . toBeTruthy ( ) ;
407+ expect ( serviceResult . result . totalCount ) . toEqual ( 1889 ) ;
408+ expect ( serviceResult . result . features ) . toBe ( null ) ;
409+ done ( ) ;
410+ } catch ( exception ) {
411+ console . log (
412+ "leafletGetFeaturesByBoundsService_'getFeaturesCount'案例失败:" +
413+ exception . name +
414+ ':' +
415+ exception . message
416+ ) ;
417+ getFeaturesByBoundsService . destroy ( ) ;
418+ expect ( false ) . toBeTruthy ( ) ;
419+ done ( ) ;
420+ }
421+ } ) ;
422+ } ) ;
423+
424+ it ( 'getFeaturesDatasetInfo' , done => {
425+ var polygon = L . polygon ( [
426+ [ - 20 , 20 ] ,
427+ [ 0 , 20 ] ,
428+ [ 0 , 40 ] ,
429+ [ - 20 , 40 ] ,
430+ [ - 20 , 20 ]
431+ ] ) ;
432+ var getFeaturesByBoundsParams = new GetFeaturesByBoundsParameters ( {
433+ datasetNames : [ 'World:Capitals' ] ,
434+ bounds : polygon . getBounds ( ) ,
435+ returnContent : true
436+ } ) ;
437+ var getFeaturesByBoundsService = featureService ( dataServiceURL , options ) ;
438+ spyOn ( FetchRequest , 'commit' ) . and . callFake ( ( method , testUrl , params , options ) => {
439+ expect ( method ) . toBe ( 'POST' ) ;
440+ expect ( testUrl ) . toBe ( dataServiceURL + '/featureResults?fromIndex=0&toIndex=19&returnDatasetInfoOnly=true&returnContent=true' ) ;
441+ var paramsObj = JSON . parse ( params . replace ( / ' / g, '"' ) ) ;
442+ expect ( paramsObj . datasetNames [ 0 ] ) . toBe ( 'World:Capitals' ) ;
443+ expect ( paramsObj . getFeatureMode ) . toBe ( 'BOUNDS' ) ;
444+ expect ( paramsObj . spatialQueryMode ) . toBe ( 'CONTAIN' ) ;
445+ expect ( options ) . not . toBeNull ( ) ;
446+ return Promise . resolve ( new Response ( JSON . stringify ( getReturnDatasetInfoOnlyResult ) ) ) ;
447+ } ) ;
448+ getFeaturesByBoundsService . getFeaturesDatasetInfo ( getFeaturesByBoundsParams , result => {
449+ serviceResult = result ;
450+ try {
451+ expect ( getFeaturesByBoundsService ) . not . toBeNull ( ) ;
452+ expect ( serviceResult . type ) . toBe ( 'processCompleted' ) ;
453+ expect ( serviceResult . result ) . not . toBeNull ( ) ;
454+ expect ( serviceResult . result . succeed ) . toBeTruthy ( ) ;
455+ expect ( serviceResult . result [ 0 ] . datasetName ) . toBe ( "World:Countries" ) ;
456+ expect ( serviceResult . result [ 0 ] . fieldInfos . length ) . toEqual ( 13 ) ;
457+ getFeaturesByBoundsService . destroy ( ) ;
458+ done ( ) ;
459+ } catch ( exception ) {
460+ console . log (
461+ "leafletGetFeaturesByBoundsService_'getFeaturesDatasetInfo'案例失败:" +
462+ exception . name +
463+ ':' +
464+ exception . message
465+ ) ;
466+ getFeaturesByBoundsService . destroy ( ) ;
467+ expect ( false ) . toBeTruthy ( ) ;
468+ done ( ) ;
469+ }
470+ } ) ;
471+ } ) ;
370472} ) ;
0 commit comments