@@ -133,7 +133,7 @@ export namespace Measurement {
133133 * 经纬度格式化
134134 * @param position 经纬度 lng=position[0] lat=position[1]
135135 */
136- format ? ( position : GeoJSON . Position ) : string
136+ format ( position : GeoJSON . Position ) : string
137137 }
138138
139139 /**
@@ -147,7 +147,7 @@ export namespace Measurement {
147147 * @param end 是否为最后一个
148148 * @param segment 是否为中间数值
149149 */
150- format ? ( length : number , index : number , end : boolean , segment : boolean ) : string ,
150+ format ( length : number , index : number , end : boolean , segment : boolean ) : string ,
151151
152152 /**
153153 * 是否包含第一个数值
@@ -158,22 +158,22 @@ export namespace Measurement {
158158 }
159159
160160 type TMeasureCalPolygonOptions = {
161- format ? ( area : number ) : string ,
161+ format ( area : number ) : string ,
162162 withLineString ?: boolean ,
163- measureLineStringOptions ? : TMeasureCalLineStringOptions ,
163+ measureLineStringOptions : TMeasureCalLineStringOptions ,
164164 }
165165
166166 /**
167167 * 测量计算参数
168168 */
169- type TMeasureCalOptions = {
170- point ? : TMeasureCalPointOptions ,
171- lineString ? : TMeasureCalLineStringOptions ,
172- polygon ? : TMeasureCalPolygonOptions
169+ export type TMeasureCalOptions = {
170+ point : TMeasureCalPointOptions ,
171+ lineString : TMeasureCalLineStringOptions ,
172+ polygon : TMeasureCalPolygonOptions
173173 }
174174
175- function calPoint ( g : GeoJSON . Position , options ? : TMeasureCalPointOptions ) : TMeasureMarkerFeature [ ] {
176- const value = options ? .format ?. ( g ) || g [ 0 ] . toFixed ( 6 ) + ',' + g [ 1 ] . toFixed ( 6 ) ;
175+ function calPoint ( g : GeoJSON . Position , options : TMeasureCalPointOptions ) : TMeasureMarkerFeature [ ] {
176+ const value = options . format ( g ) ;
177177 return [ {
178178 type : "Feature" ,
179179 geometry : {
@@ -187,7 +187,7 @@ export namespace Measurement {
187187 } ]
188188 }
189189
190- function calLineString ( g : GeoJSON . Position [ ] , options ? : TMeasureCalLineStringOptions , isPolygon : boolean = false ) : TMeasureMarkerFeature [ ] {
190+ function calLineString ( g : GeoJSON . Position [ ] , options : TMeasureCalLineStringOptions , isPolygon : boolean = false ) : TMeasureMarkerFeature [ ] {
191191 const ret = new Array < TMeasureMarkerFeature > ( ) ;
192192 let sumLength = 0 ;
193193
@@ -213,7 +213,7 @@ export namespace Measurement {
213213 coordinates : c . geometry . coordinates
214214 } ,
215215 properties : {
216- value : options ? .format ?. ( l , i , false , true ) || ` ${ l . toFixed ( 2 ) } m` ,
216+ value : options . format ( l , i , false , true ) ,
217217 type : isPolygon ? 'polygon-line-segment' : 'line-segment'
218218 }
219219 } ) ;
@@ -229,7 +229,7 @@ export namespace Measurement {
229229 coordinates : current
230230 } ,
231231 properties : {
232- value : options ? .format ?. ( sumLength , i , i === g . length - 1 , false ) || ` ${ sumLength . toFixed ( 2 ) } m` ,
232+ value : options . format ( sumLength , i , i === g . length - 1 , false ) ,
233233 type : isPolygon ? 'polygon-line' : 'line'
234234 }
235235 } ) ;
@@ -238,12 +238,12 @@ export namespace Measurement {
238238 return ret ;
239239 }
240240
241- function calPolygon ( g : GeoJSON . Position [ ] [ ] , options ? : TMeasureCalPolygonOptions ) : TMeasureMarkerFeature [ ] {
241+ function calPolygon ( g : GeoJSON . Position [ ] [ ] , options : TMeasureCalPolygonOptions ) : TMeasureMarkerFeature [ ] {
242242 const ret = new Array < TMeasureMarkerFeature > ( ) ;
243243
244244 if ( options ?. withLineString !== false ) {
245245 g . forEach ( x => {
246- ret . push ( ...calLineString ( x , options ? .measureLineStringOptions ) ) ;
246+ ret . push ( ...calLineString ( x , options . measureLineStringOptions , true ) ) ;
247247 } ) ;
248248 }
249249
@@ -259,7 +259,7 @@ export namespace Measurement {
259259 coordinates : center . geometry . coordinates
260260 } ,
261261 properties : {
262- value : options ? .format ?. ( a ) || ` ${ a . toFixed ( 2 ) } m²` ,
262+ value : options . format ( a ) ,
263263 type : 'polygon'
264264 }
265265 } )
@@ -268,20 +268,20 @@ export namespace Measurement {
268268 return ret ;
269269 }
270270
271- function calGeometry ( g : GeoJSON . Geometry , options ? : TMeasureCalOptions ) : TMeasureMarkerFeature [ ] {
272- if ( g . type === 'Point' ) return calPoint ( g . coordinates , options ? .point ) ;
273- if ( g . type === 'LineString' ) return calLineString ( g . coordinates , options ? .lineString ) ;
274- if ( g . type === 'Polygon' ) return calPolygon ( g . coordinates , options ? .polygon ) ;
271+ function calGeometry ( g : GeoJSON . Geometry , options : TMeasureCalOptions ) : TMeasureMarkerFeature [ ] {
272+ if ( g . type === 'Point' ) return calPoint ( g . coordinates , options . point ) ;
273+ if ( g . type === 'LineString' ) return calLineString ( g . coordinates , options . lineString ) ;
274+ if ( g . type === 'Polygon' ) return calPolygon ( g . coordinates , options . polygon ) ;
275275
276276 function calMulGeometry < T > ( data : Array < T > , cal : ( d : T , options ?: any ) => TMeasureMarkerFeature [ ] , options : any ) : TMeasureMarkerFeature [ ] {
277277 return data . reduce ( ( p , c ) => {
278278 return p . concat ( cal ( c , options ) ) ;
279279 } , new Array < TMeasureMarkerFeature > ( ) ) ;
280280 }
281281
282- if ( g . type === 'MultiPoint' ) return calMulGeometry ( g . coordinates , calPoint , options ? .point ) ;
283- if ( g . type === 'MultiLineString' ) return calMulGeometry ( g . coordinates , calLineString , options ? .lineString ) ;
284- if ( g . type === 'MultiPolygon' ) return calMulGeometry ( g . coordinates , calPolygon , options ? .polygon ) ;
282+ if ( g . type === 'MultiPoint' ) return calMulGeometry ( g . coordinates , calPoint , options . point ) ;
283+ if ( g . type === 'MultiLineString' ) return calMulGeometry ( g . coordinates , calLineString , options . lineString ) ;
284+ if ( g . type === 'MultiPolygon' ) return calMulGeometry ( g . coordinates , calPolygon , options . polygon ) ;
285285
286286 throw new Error ( `not suppose geometry type: ${ g . type } to measure` ) ;
287287 }
@@ -292,7 +292,7 @@ export namespace Measurement {
292292 * @param options 计算参数
293293 * @returns
294294 */
295- export function cal ( data : GeoJSON . Feature | GeoJSON . Feature [ ] | GeoJSON . Geometry , options ? : TMeasureCalOptions ) {
295+ export function cal ( data : GeoJSON . Feature | GeoJSON . Feature [ ] | GeoJSON . Geometry , options : TMeasureCalOptions ) {
296296 if ( data instanceof Array ) {
297297 return data . reduce ( ( p , c ) => {
298298 const features = calGeometry ( c . geometry , options ) ;
0 commit comments