| 123456789101112131415161718192021222324252627282930313233343536373839 |
- import * as maptalks from 'maptalks'
- class DistanceToolEx extends maptalks.DistanceTool {
- constructor(options) {
- super(options)
- this._measureLayers = []
- }
- _measure(toMeasure) {
- const map = this.getMap()
- let length
- if (toMeasure instanceof maptalks.Geometry) {
- length = map.computeGeometryLength(toMeasure)
- } else if (Array.isArray(toMeasure)) {
- length = map.getProjection().measureLength(toMeasure)
- }
- this._lastMeasure = length
- let units
- if (this.options['language'] === 'zh-CN') {
- units = [' 米', ' 公里', ' 英尺', ' 英里']
- } else {
- units = [' m', ' km', ' feet', ' mile']
- }
- let content = ''
- if (this.options['metric']) {
- content += length < 1000 ? length.toFixed(3) + units[0] : (length / 1000).toFixed(2) + units[1]
- }
- if (this.options['imperial']) {
- length *= 3.2808399
- if (content.length > 0) {
- content += '\n'
- }
- content += length < 5280 ? length.toFixed(3) + units[2] : (length / 5280).toFixed(2) + units[3]
- }
- return content
- }
- }
- export default DistanceToolEx
|