@@ -23,31 +23,58 @@ import {Util} from '../Util';
2323export class Point extends Geometry {
2424
2525
26- constructor ( x , y , type , tag ) {
27- super ( x , y , type , tag ) ;
26+ constructor ( xOrCoordinates , yOrType , type , tag ) {
27+ super ( ) ;
2828 /**
2929 * @member {number} GeometryPoint.prototype.x
3030 * @description 横坐标。
3131 */
32- this . x = parseFloat ( x ) ;
32+ this . x ;
3333
3434 /**
3535 * @member {number} GeometryPoint.prototype.y
3636 * @description 纵坐标。
3737 */
38- this . y = parseFloat ( y ) ;
38+ this . y ;
3939
4040 /**
41- * @member {string} GeometryPoint.prototype.tag
42- * @description 用来存储额外的属性,比如插值分析中的 Z 值。
41+ * @member {number} GeometryPoint.prototype.z
42+ * @description Z 值。
43+ */
44+ this . z ;
45+
46+ /**
47+ * @member {number} GeometryPoint.prototype.m
48+ * @description M 值。
4349 */
44- this . tag = ( tag || tag == 0 ) ? parseFloat ( tag ) : null ;
50+ this . m ;
4551
4652 /**
4753 * @member {string} GeometryPoint.prototype.type
4854 * @description 用来存储点的类型。
4955 */
50- this . type = type || "Point" ;
56+ this . type ;
57+ if ( Array . isArray ( xOrCoordinates ) ) {
58+ const [ x , y , z , m ] = xOrCoordinates ;
59+ this . x = parseFloat ( x ) ;
60+ this . y = parseFloat ( y ) ;
61+ this . z = ( z || z == 0 ) ? parseFloat ( z ) : null ;
62+ this . m = ( m || m == 0 ) ? parseFloat ( m ) : null ;
63+ this . type = yOrType || "Point" ;
64+ } else {
65+ this . x = parseFloat ( xOrCoordinates ) ;
66+ this . y = parseFloat ( yOrType ) ;
67+ this . z = ( tag || tag == 0 ) ? parseFloat ( tag ) : null ;
68+ this . m = null ;
69+ this . type = type || "Point" ;
70+ }
71+ /**
72+ * @member {string} GeometryPoint.prototype.tag
73+ * @deprecated
74+ * @description 用来存储额外的属性,比如插值分析中的 Z 值。
75+ */
76+ this . tag = this . z ;
77+
5178 this . CLASS_NAME = "SuperMap.Geometry.Point" ;
5279 this . geometryType = "Point" ;
5380 }
@@ -59,7 +86,7 @@ export class Point extends Geometry {
5986 */
6087 clone ( obj ) {
6188 if ( obj == null ) {
62- obj = new Point ( this . x , this . y ) ;
89+ obj = new Point ( [ this . x , this . y , this . z , this . m ] ) ;
6390 }
6491
6592 // catch any randomly tagged-on properties
@@ -90,7 +117,7 @@ export class Point extends Geometry {
90117 equals ( geom ) {
91118 var equals = false ;
92119 if ( geom != null ) {
93- equals = ( ( this . x === geom . x && this . y === geom . y ) ||
120+ equals = ( ( this . x === geom . x && this . y === geom . y && this . z === geom . z && this . m === geom . m ) ||
94121 ( isNaN ( this . x ) && isNaN ( this . y ) && isNaN ( geom . x ) && isNaN ( geom . y ) ) ) ;
95122 }
96123 return equals ;
@@ -115,7 +142,14 @@ export class Point extends Geometry {
115142 * @returns {string } 字符串代表点对象。(ex. <i>"5, 42"</i>)
116143 */
117144 toShortString ( ) {
118- return ( this . x + ", " + this . y ) ;
145+ const arr = [ this . x , this . y ] ;
146+ if ( this . z || this . z == 0 ) {
147+ arr . push ( this . z ) ;
148+ }
149+ if ( this . m || this . m == 0 ) {
150+ arr . push ( this . m ) ;
151+ }
152+ return arr . join ( ", " ) ;
119153 }
120154
121155 /**
@@ -126,6 +160,8 @@ export class Point extends Geometry {
126160 this . x = null ;
127161 this . y = null ;
128162 this . tag = null ;
163+ this . z = null ;
164+ this . m = null ;
129165 super . destroy ( ) ;
130166 }
131167
@@ -136,7 +172,5 @@ export class Point extends Geometry {
136172 */
137173 getVertices ( ) {
138174 return [ this ] ;
139- }
140-
141-
175+ }
142176}
0 commit comments