@@ -244,17 +244,20 @@ class DistanceTool extends DrawTool {
244
244
245
245
_msOnDrawStart ( param ) {
246
246
const map = this . getMap ( ) ;
247
- const prjCoord = map . _pointToPrj ( param [ 'point2d' ] ) ;
247
+ // const prjCoord = map._pointToPrj(param['point2d']);
248
248
const uid = UID ( ) ;
249
249
const layerId = 'distancetool_' + uid ;
250
250
const markerLayerId = 'distancetool_markers_' + uid ;
251
251
const zIndex = this . options . zIndex ;
252
+ const enableAltitude = this . options . enableAltitude ;
252
253
if ( ! map . getLayer ( layerId ) ) {
253
254
this . _measureLineLayer = new VectorLayer ( layerId , {
254
- zIndex
255
+ zIndex,
256
+ enableAltitude
255
257
} ) . addTo ( map ) ;
256
258
this . _measureMarkerLayer = new VectorLayer ( markerLayerId , {
257
- zIndex
259
+ zIndex,
260
+ enableAltitude
258
261
} ) . addTo ( map ) ;
259
262
} else {
260
263
this . _measureLineLayer = map . getLayer ( layerId ) ;
@@ -264,14 +267,15 @@ class DistanceTool extends DrawTool {
264
267
this . _measureLayers . push ( this . _measureMarkerLayer ) ;
265
268
this . _pushLayers ( [ this . _measureLineLayer , this . _measureMarkerLayer ] ) ;
266
269
//start marker
267
- const marker = new Marker ( param [ 'coordinate' ] , {
270
+ const firstCoordinate = this . _getFirstCoordinate ( ) || param . coordinate ;
271
+ const marker = new Marker ( firstCoordinate . copy ( ) , {
268
272
'symbol' : this . options [ 'vertexSymbol' ]
269
273
} ) ;
270
274
//调用_setPrjCoordinates主要是为了解决repeatworld下,让它能标注在其他世界的问题
271
- marker . _setPrjCoordinates ( prjCoord ) ;
275
+ // marker._setPrjCoordinates(prjCoord);
272
276
const content = this . translator . translate ( 'distancetool.start' ) ;
273
- const startLabel = new Label ( content , param [ 'coordinate' ] , this . options [ 'labelOptions' ] ) ;
274
- startLabel . _setPrjCoordinates ( prjCoord ) ;
277
+ const startLabel = new Label ( content , firstCoordinate . copy ( ) , this . options [ 'labelOptions' ] ) ;
278
+ // startLabel._setPrjCoordinates(prjCoord);
275
279
this . _lastVertex = startLabel ;
276
280
this . _addVertexMarker ( marker , startLabel ) ;
277
281
}
@@ -288,33 +292,37 @@ class DistanceTool extends DrawTool {
288
292
this . _tailLabel = new Label ( ms , param [ 'coordinate' ] , this . options [ 'labelOptions' ] )
289
293
. addTo ( this . _measureMarkerLayer ) ;
290
294
}
291
- const prjCoords = this . _geometry . _getPrjCoordinates ( ) ;
292
- const lastCoord = prjCoords [ prjCoords . length - 1 ] ;
293
- this . _tailMarker . setCoordinates ( param [ 'coordinate' ] ) ;
294
- this . _tailMarker . _setPrjCoordinates ( lastCoord ) ;
295
+ // const prjCoords = this._geometry._getPrjCoordinates();
296
+ // const lastCoord = prjCoords[prjCoords.length - 1];
297
+ const lastCoordinate = this . _getLasttCoordinate ( ) || param . coordinate ;
298
+ this . _tailMarker . setCoordinates ( lastCoordinate . copy ( ) ) ;
299
+ // this._tailMarker._setPrjCoordinates(lastCoord);
295
300
this . _tailLabel . setContent ( ms ) ;
296
- this . _tailLabel . setCoordinates ( param [ 'coordinate' ] ) ;
297
- this . _tailLabel . _setPrjCoordinates ( lastCoord ) ;
301
+ this . _tailLabel . setCoordinates ( lastCoordinate . copy ( ) ) ;
302
+ // this._tailLabel._setPrjCoordinates(lastCoord);
298
303
}
299
304
300
305
_msGetCoordsToMeasure ( param ) {
301
306
return param [ 'geometry' ] . getCoordinates ( ) . concat ( [ param [ 'coordinate' ] ] ) ;
302
307
}
303
308
304
309
_msOnDrawVertex ( param ) {
305
- const prjCoords = this . _geometry . _getPrjCoordinates ( ) ;
306
- const lastCoord = prjCoords [ prjCoords . length - 1 ] ;
310
+ // const prjCoords = this._geometry._getPrjCoordinates();
311
+ // const lastCoord = prjCoords[prjCoords.length - 1];
312
+
313
+ const lastCoordinate = this . _getLasttCoordinate ( ) || param . coordinate ;
314
+
307
315
const geometry = param [ 'geometry' ] ;
308
316
//vertex marker
309
- const marker = new Marker ( param [ 'coordinate' ] , {
317
+ const marker = new Marker ( lastCoordinate . copy ( ) , {
310
318
'symbol' : this . options [ 'vertexSymbol' ]
311
319
} ) ;
312
320
313
321
const length = this . _measure ( geometry ) ;
314
- const vertexLabel = new Label ( length , param [ 'coordinate' ] , this . options [ 'labelOptions' ] ) ;
322
+ const vertexLabel = new Label ( length , lastCoordinate . copy ( ) , this . options [ 'labelOptions' ] ) ;
315
323
this . _addVertexMarker ( marker , vertexLabel ) ;
316
- vertexLabel . _setPrjCoordinates ( lastCoord ) ;
317
- marker . _setPrjCoordinates ( lastCoord ) ;
324
+ // vertexLabel._setPrjCoordinates(lastCoord);
325
+ // marker._setPrjCoordinates(lastCoord);
318
326
this . _lastVertex = vertexLabel ;
319
327
}
320
328
@@ -334,7 +342,7 @@ class DistanceTool extends DrawTool {
334
342
335
343
_msOnDrawEnd ( param ) {
336
344
this . _clearTailMarker ( ) ;
337
- if ( param [ 'geometry' ] . _getPrjCoordinates ( ) . length < 2 ) {
345
+ if ( param [ 'geometry' ] . getCoordinates ( ) . length < 2 ) {
338
346
this . _lastMeasure = 0 ;
339
347
this . _clearMeasureLayers ( ) ;
340
348
return ;
@@ -345,7 +353,10 @@ class DistanceTool extends DrawTool {
345
353
}
346
354
this . _addClearMarker ( this . _lastVertex . getCoordinates ( ) , this . _lastVertex . _getPrjCoordinates ( ) , size [ 'width' ] ) ;
347
355
const geo = param [ 'geometry' ] . copy ( ) ;
348
- geo . _setPrjCoordinates ( param [ 'geometry' ] . _getPrjCoordinates ( ) ) ;
356
+
357
+ geo . setCoordinates ( param . geometry . getCoordinates ( ) ) ;
358
+
359
+ // geo._setPrjCoordinates(param['geometry']._getPrjCoordinates());
349
360
geo . addTo ( this . _measureLineLayer ) ;
350
361
this . _lastMeasure = geo . getLength ( ) ;
351
362
}
@@ -380,7 +391,7 @@ class DistanceTool extends DrawTool {
380
391
return false ;
381
392
} , this ) ;
382
393
endMarker . addTo ( this . _measureMarkerLayer ) ;
383
- endMarker . _setPrjCoordinates ( prjCoord ) ;
394
+ // endMarker._setPrjCoordinates(prjCoord);
384
395
}
385
396
386
397
_clearTailMarker ( ) {
@@ -399,6 +410,22 @@ class DistanceTool extends DrawTool {
399
410
this . _measureMarkerLayer . remove ( ) ;
400
411
}
401
412
413
+ _getFirstCoordinate ( ) {
414
+ if ( ! this . _geometry ) {
415
+ return null ;
416
+ }
417
+ const coordinates = this . _geometry . getCoordinates ( ) || [ ] ;
418
+ return coordinates [ 0 ] ;
419
+ }
420
+
421
+ _getLasttCoordinate ( ) {
422
+ if ( ! this . _geometry ) {
423
+ return null ;
424
+ }
425
+ const coordinates = this . _geometry . getCoordinates ( ) || [ ] ;
426
+ return coordinates [ coordinates . length - 1 ] ;
427
+ }
428
+
402
429
}
403
430
404
431
DistanceTool . mergeOptions ( options ) ;
0 commit comments