@@ -221,6 +221,97 @@ describe('ServerGeometry', function () {
221221 serverGeometry . destroy ( ) ;
222222 } ) ;
223223
224+ it ( 'toGeoLineEPS_LinearRing' , function ( ) {
225+ var options = {
226+ id : 1 ,
227+ parts : [ 4 ] ,
228+ points : [ { "y" : - 4377.027184298267 , "x" : 4020.0045221720466 } ,
229+ { "y" : - 4381.569363260499 , "x" : 4057.0600591960642 } ,
230+ { "y" : - 4382.60877717323 , "x" : 4064.595810063362 } ,
231+ { "y" : - 4377.027184298267 , "x" : 4020.0045221720466 } ] ,
232+ type : SuperMap . GeometryType . LINE
233+ } ;
234+ var serverGeometry = new SuperMap . ServerGeometry ( options ) ;
235+ var toGeoLineEPS_LinearRing = serverGeometry . toGeoLineEPS ( ) ;
236+ expect ( toGeoLineEPS_LinearRing ) . not . toBeNull ( ) ;
237+ expect ( toGeoLineEPS_LinearRing . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.LinearRing" ) ;
238+ expect ( toGeoLineEPS_LinearRing . id ) . toContain ( "SuperMap.Geometry_" ) ;
239+ expect ( toGeoLineEPS_LinearRing . componentTypes [ 0 ] ) . toEqual ( "SuperMap.Geometry.Point" ) ;
240+ var components = toGeoLineEPS_LinearRing . components ;
241+ expect ( components . length ) . toEqual ( 4 ) ;
242+ for ( var i = 0 ; i < components . length ; i ++ ) {
243+ expect ( components [ i ] . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.Point" ) ;
244+ expect ( components [ i ] . id ) . toContain ( "SuperMap.Geometry_" ) ;
245+ expect ( components [ i ] . type ) . toEqual ( "Point" ) ;
246+ expect ( components [ i ] . parent . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.LinearRing" ) ;
247+ expect ( components [ i ] . x ) . not . toBeNaN ( ) ;
248+ expect ( components [ i ] . y ) . not . toBeNaN ( ) ;
249+ }
250+ serverGeometry . destroy ( ) ;
251+ } ) ;
252+
253+ it ( 'toGeoLineEPS_LineString' , function ( ) {
254+ var options = {
255+ id : 1 ,
256+ parts : [ 4 ] ,
257+ points : [ { "y" : - 4377.027184298267 , "x" : 4020.0045221720466 } ,
258+ { "y" : - 4381.569363260499 , "x" : 4057.0600591960642 } ,
259+ { "y" : - 4382.60877717323 , "x" : 4064.595810063362 } ,
260+ { "y" : - 4382.939424428795 , "x" : 4076.2655245045335 } ] ,
261+ type : SuperMap . GeometryType . LINE
262+ } ;
263+ var serverGeometry = new SuperMap . ServerGeometry ( options ) ;
264+ var geoLine_LineString = serverGeometry . toGeoLineEPS ( ) ;
265+ expect ( geoLine_LineString ) . not . toBeNull ( ) ;
266+ expect ( geoLine_LineString . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.LineString" ) ;
267+ expect ( geoLine_LineString . id ) . toContain ( "SuperMap.Geometry_" ) ;
268+ expect ( geoLine_LineString . componentTypes [ 0 ] ) . toEqual ( "SuperMap.Geometry.Point" ) ;
269+ expect ( geoLine_LineString . componentTypes [ 1 ] ) . toEqual ( "SuperMap.PointWithMeasure" ) ;
270+ var components = geoLine_LineString . components ;
271+ expect ( components . length ) . toEqual ( 4 ) ;
272+ for ( var i = 0 ; i < components . length ; i ++ ) {
273+ expect ( components [ i ] . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.Point" ) ;
274+ expect ( components [ i ] . id ) . toContain ( "SuperMap.Geometry_" ) ;
275+ expect ( components [ i ] . type ) . toEqual ( "Point" ) ;
276+ expect ( components [ i ] . parent . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.LineString" ) ;
277+ expect ( components [ i ] . x ) . not . toBeNaN ( ) ;
278+ expect ( components [ i ] . y ) . not . toBeNaN ( ) ;
279+ }
280+ serverGeometry . destroy ( ) ;
281+ } ) ;
282+
283+ it ( 'toGeoLineEPS_MultiLineString' , function ( ) {
284+ var options = {
285+ id : 1 ,
286+ parts : [ 4 , 4 ] ,
287+ points : [ { "y" : - 4377.027184298267 , "x" : 4020.0045221720466 } ,
288+ { "y" : - 4381.569363260499 , "x" : 4057.0600591960642 } ,
289+ { "y" : - 4382.60877717323 , "x" : 4064.595810063362 } ,
290+ { "y" : - 4382.939424428795 , "x" : 4076.2655245045335 } ,
291+ { "y" : - 4382.333381109672 , "x" : 4215.049444583775 } ,
292+ { "y" : - 4382.389670274902 , "x" : 4247.756955878764 } ,
293+ { "y" : - 4382.285032149534 , "x" : 4428.153084011883 } ,
294+ { "y" : - 4383.017499027105 , "x" : 4647.579232906979 } ] ,
295+ type : SuperMap . GeometryType . LINE
296+ } ;
297+ var serverGeometry = new SuperMap . ServerGeometry ( options ) ;
298+ var geoLine_MultiLineString = serverGeometry . toGeoLineEPS ( ) ;
299+ expect ( geoLine_MultiLineString ) . not . toBeNull ( ) ;
300+ expect ( geoLine_MultiLineString . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.MultiLineString" ) ;
301+ expect ( geoLine_MultiLineString . id ) . toContain ( "SuperMap.Geometry_" ) ;
302+ expect ( geoLine_MultiLineString . componentTypes [ 0 ] ) . toEqual ( "SuperMap.Geometry.LineString" ) ;
303+ var components = geoLine_MultiLineString . components ;
304+ expect ( components . length ) . toEqual ( 2 ) ;
305+ for ( var i = 0 ; i < components . length ; i ++ ) {
306+ expect ( components [ i ] . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.LineString" ) ;
307+ expect ( components [ i ] . id ) . toContain ( "SuperMap.Geometry_" ) ;
308+ expect ( components [ i ] . componentTypes [ 0 ] ) . toEqual ( "SuperMap.Geometry.Point" ) ;
309+ expect ( components [ i ] . componentTypes [ 1 ] ) . toEqual ( "SuperMap.PointWithMeasure" ) ;
310+ expect ( components [ i ] . components . length ) . toEqual ( 4 ) ;
311+ }
312+ serverGeometry . destroy ( ) ;
313+ } ) ;
314+
224315 it ( 'toGeoLinem' , function ( ) {
225316 var options = {
226317 id : 1 ,
@@ -241,4 +332,123 @@ describe('ServerGeometry', function () {
241332 expect ( geoLinem . components [ 0 ] . components . length ) . toEqual ( 3 ) ;
242333 serverGeometry . destroy ( ) ;
243334 } ) ;
335+
336+ //将服务端的面几何对象转换为客户端几何对象。
337+ it ( 'toGeoRegion' , function ( ) {
338+ var options = {
339+ id : 'test' ,
340+ parts : [ 4 , 4 ] ,
341+ points : [ { "y" : - 4377.027184298267 , "x" : 4020.0045221720466 } ,
342+ { "y" : - 4381.569363260499 , "x" : 4057.0600591960642 } ,
343+ { "y" : - 4382.60877717323 , "x" : 4064.595810063362 } ,
344+ { "y" : - 4382.939424428795 , "x" : 4076.2655245045335 } ,
345+ { "y" : - 4382.333381109672 , "x" : 4215.049444583775 } ,
346+ { "y" : - 4382.389670274902 , "x" : 4247.756955878764 } ,
347+ { "y" : - 4382.285032149534 , "x" : 4428.153084011883 } ,
348+ { "y" : - 4383.017499027105 , "x" : 4647.579232906979 } ] ,
349+ type : SuperMap . GeometryType . LINE
350+ } ;
351+ var serverGeometry = new SuperMap . ServerGeometry ( options ) ;
352+ var geoRegion = serverGeometry . toGeoRegion ( ) ;
353+ expect ( geoRegion ) . not . toBeNull ( ) ;
354+ expect ( geoRegion . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.MultiPolygon" ) ;
355+ expect ( geoRegion . componentTypes [ 0 ] ) . toEqual ( "SuperMap.Geometry.Polygon" ) ;
356+ expect ( geoRegion . components . length ) . toEqual ( 2 ) ;
357+ for ( var i = 0 ; i < geoRegion . components . length ; i ++ ) {
358+ expect ( geoRegion . components [ i ] . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.Polygon" ) ;
359+ var components = geoRegion . components [ i ] . components [ 0 ] . components ;
360+ expect ( components . length ) . toEqual ( 5 ) ;
361+ for ( var j = 0 ; j < components . length ; j ++ ) {
362+ expect ( components [ j ] . type ) . toEqual ( "Point" ) ;
363+ expect ( components [ j ] . x ) . not . toBeNaN ( ) ;
364+ expect ( components [ j ] . y ) . not . toBeNaN ( ) ;
365+ }
366+ }
367+ serverGeometry . destroy ( ) ;
368+ } ) ;
369+
370+ //将服务端的面几何对象转换为客户端几何对象
371+ it ( 'toGeoRegionEPS_Null' , function ( ) {
372+ var serverGeometry = new SuperMap . ServerGeometry ( { parts : [ ] } ) ;
373+ var geoRegionEPS_Null = serverGeometry . toGeoRegionEPS ( ) ;
374+ expect ( geoRegionEPS_Null ) . toBeNull ( ) ;
375+ serverGeometry . destroy ( ) ;
376+ } ) ;
377+
378+ it ( 'toGeoRegionEPS_parts =[1]' , function ( ) {
379+ var options = {
380+ id : 'test' ,
381+ parts : [ 1 ] ,
382+ points : [ { "y" : - 4377.027184298267 , "x" : 4020.0045221720466 } ,
383+ { "y" : - 4381.569363260499 , "x" : 4057.0600591960642 } ,
384+ { "y" : - 4382.60877717323 , "x" : 4064.595810063362 } ] ,
385+ } ;
386+ var serverGeometry = new SuperMap . ServerGeometry ( options ) ;
387+ var geoRegionEPS = serverGeometry . toGeoRegionEPS ( ) ;
388+ expect ( geoRegionEPS ) . not . toBeNull ( ) ;
389+ expect ( geoRegionEPS . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.MultiPolygon" ) ;
390+ expect ( geoRegionEPS . componentTypes [ 0 ] ) . toEqual ( "SuperMap.Geometry.Polygon" ) ;
391+ expect ( geoRegionEPS . components . length ) . toEqual ( 1 ) ;
392+ var component = geoRegionEPS . components [ 0 ] . components [ 0 ] ;
393+ expect ( component . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.LinearRing" ) ;
394+ expect ( component . componentTypes [ 0 ] ) . toEqual ( "SuperMap.Geometry.Point" ) ;
395+ var components = component . components ;
396+ expect ( components . length ) . toEqual ( 4 ) ;
397+ for ( var i = 0 ; i < components . length ; i ++ ) {
398+ expect ( components [ i ] . type ) . toEqual ( "Point" ) ;
399+ expect ( components [ i ] . x ) . not . toBeNaN ( ) ;
400+ expect ( components [ i ] . y ) . not . toBeNaN ( ) ;
401+ expect ( components [ 0 ] ) . toEqual ( components [ 3 ] ) ;
402+ }
403+ serverGeometry . destroy ( ) ;
404+ } ) ;
405+
406+ it ( 'toGeoRegionEPS_parts = [4, 4]' , function ( ) {
407+ var options = {
408+ id : 'test' ,
409+ parts : [ 4 , 4 ] ,
410+ points : [ { "y" : - 4377.027184298267 , "x" : 4020.0045221720466 } ,
411+ { "y" : - 4381.569363260499 , "x" : 4057.0600591960642 } ,
412+ { "y" : - 4382.60877717323 , "x" : 4064.595810063362 } ,
413+ { "y" : - 4382.939424428795 , "x" : 4076.2655245045335 } ,
414+ { "y" : - 4382.333381109672 , "x" : 4215.049444583775 } ,
415+ { "y" : - 4382.389670274902 , "x" : 4247.756955878764 } ,
416+ { "y" : - 4382.285032149534 , "x" : 4428.153084011883 } ,
417+ { "y" : - 4383.017499027105 , "x" : 4647.579232906979 } ] ,
418+ type : SuperMap . GeometryType . LINE
419+ } ;
420+ var serverGeometry = new SuperMap . ServerGeometry ( options ) ;
421+ var geoRegionEPS = serverGeometry . toGeoRegionEPS ( ) ;
422+ expect ( geoRegionEPS ) . not . toBeNull ( ) ;
423+ expect ( geoRegionEPS . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.MultiPolygon" ) ;
424+ expect ( geoRegionEPS . componentTypes [ 0 ] ) . toEqual ( "SuperMap.Geometry.Polygon" ) ;
425+ expect ( geoRegionEPS . components . length ) . toEqual ( 2 ) ;
426+ for ( var i = 0 ; i < geoRegionEPS . components . length ; i ++ ) {
427+ expect ( geoRegionEPS . components [ i ] . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.Polygon" ) ;
428+ expect ( geoRegionEPS . components [ i ] . bounds ) . not . toBeNull ( ) ;
429+ expect ( geoRegionEPS . components [ i ] . components [ 0 ] . CLASS_NAME ) . toEqual ( "SuperMap.Geometry.LinearRing" ) ;
430+ var components = geoRegionEPS . components [ i ] . components [ 0 ] . components ;
431+ expect ( components . length ) . toEqual ( 5 ) ;
432+ for ( var j = 0 ; j < components . length ; j ++ ) {
433+ expect ( components [ j ] . type ) . toEqual ( "Point" ) ;
434+ expect ( components [ j ] . x ) . not . toBeNaN ( ) ;
435+ expect ( components [ j ] . y ) . not . toBeNaN ( ) ;
436+ }
437+ }
438+ serverGeometry . destroy ( ) ;
439+ } ) ;
440+
441+ it ( 'IsClockWise' , function ( ) {
442+ var points1 = [ { "y" : - 4377.027184298267 , "x" : 4020.0045221720466 } ,
443+ { "y" : - 4381.569363260499 , "x" : 4057.0600591960642 } ,
444+ { "y" : - 4382.60877717323 , "x" : 4064.595810063362 } ,
445+ { "y" : - 4382.939424428795 , "x" : 4076.2655245045335 } ,
446+ { "y" : - 4377.027184298267 , "x" : 4020.0045221720466 } ] ;
447+ var result1 = SuperMap . ServerGeometry . IsClockWise ( points1 ) ;
448+ expect ( result1 ) . toEqual ( 23.052148170943838 ) ;
449+ var points2 = [ { "y" : - 4377.027184298267 , "x" : 4020.0045221720466 } ,
450+ { "y" : - 4381.569363260499 , "x" : 4057.0600591960642 } ] ;
451+ var result2 = SuperMap . ServerGeometry . IsClockWise ( points2 ) ;
452+ expect ( result2 ) . toEqual ( 0 ) ;
453+ } ) ;
244454} ) ;
0 commit comments