Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix measurement results for projected maps #385

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/components/measuretool/MeasureResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</template>

<script>
import { Mapable } from '../../mixins/Mapable';
import AngleUtil from '../../../src/util/Angle';
import LineStringGeom from 'ol/geom/LineString';
import { getArea, getLength } from 'ol/sphere.js';
Expand All @@ -23,12 +24,14 @@ const EMPTY_RESULT_TEXT = ' -- ';

export default {
name: 'wgu-measure-result',
mixins: [Mapable],
props: {
measureGeom: { type: Object },
measureType: { type: String }
},
data () {
return {
map: null,
chrismayer marked this conversation as resolved.
Show resolved Hide resolved
area: EMPTY_RESULT_TEXT,
distance: EMPTY_RESULT_TEXT,
angle: EMPTY_RESULT_TEXT
Expand Down Expand Up @@ -61,12 +64,13 @@ export default {
},
methods: {
/**
* Calculates and formats the length of the given line.
*
* @param {ol.geom.LineString} line The LineString object to calculate length for
*/
* Calculates and formats the length of the given line.
*
* @param {ol.geom.LineString} line The LineString object to calculate length for
*/
formatLength (line) {
const length = getLength(line);
const mapSrs = this.map.getView().getProjection().getCode();
const length = getLength(line, { projection: mapSrs });
let output;
if (length > 100) {
output = this.$t('wgu-measuretool.lengthKm',
Expand All @@ -83,7 +87,8 @@ export default {
* @param {ol.geom.Polygon} polygon The Polygon object to calculate area for
*/
formatArea (polygon) {
const area = getArea(polygon);
const mapSrs = this.map.getView().getProjection().getCode();
const area = getArea(polygon, { projection: mapSrs });
let output;
if (area > 10000) {
output = this.$t('wgu-measuretool.areaSquareKm',
Expand Down
24 changes: 22 additions & 2 deletions tests/unit/specs/components/measuretool/MeasureResult.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { shallowMount } from '@vue/test-utils';
import MeasureResult from '@/components/measuretool/MeasureResult';
import PolygonGeom from 'ol/geom/Polygon'
import LineStringGeom from 'ol/geom/LineString';
import Map from 'ol/Map';
import View from 'ol/View';

describe('measuretool/MeasureResult.vue', () => {
// Inspect the raw component options
Expand Down Expand Up @@ -39,7 +41,16 @@ describe('measuretool/MeasureResult.vue', () => {
let comp;
let vm;
beforeEach(() => {
comp = shallowMount(MeasureResult);
const olMap = new Map({
view: new View({ center: [0, 0], zoom: 2 })
});
comp = shallowMount(MeasureResult, {
data () {
return {
map: olMap
}
}
});
vm = comp.vm;
});

Expand Down Expand Up @@ -71,7 +82,16 @@ describe('measuretool/MeasureResult.vue', () => {
describe('watchers', () => {
let comp;
beforeEach(() => {
comp = shallowMount(MeasureResult);
const olMap = new Map({
view: new View({ center: [0, 0], zoom: 2 })
});
comp = shallowMount(MeasureResult, {
data () {
return {
map: olMap
}
}
});
});

it('watches measureGeom Area', done => {
Expand Down
Loading