Skip to content

Commit

Permalink
Merge pull request #419 from sronveaux/infoclick-mapclick-bug
Browse files Browse the repository at this point in the history
Corrected InfoClick bug when using MeasureTool afterwards
  • Loading branch information
sronveaux authored Oct 2, 2024
2 parents 70949db + a84a4e8 commit 0f3b4eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
29 changes: 16 additions & 13 deletions src/components/infoclick/InfoClickWin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
</template>

<script>
import ModuleCard from './../modulecore/ModuleCard';
import ModuleCard from '../modulecore/ModuleCard';
import { WguEventBus } from '../../WguEventBus.js';
import PropertyTable from './PropertyTable';
import CoordsTable from './CoordsTable';
Expand Down Expand Up @@ -125,16 +125,18 @@ export default {
*/
onMapClick (evt) {
const me = this;
me.features = []
me.features = [];
me.map.forEachFeatureAtPixel(evt.pixel,
(feature, layer) => {
me.features.push([feature, layer])
if (layer) {
me.features.push([feature, layer]);
}
});
// collect feature attributes --> PropertyTable
if (this.features.length !== 0) {
this.featureIdx = 0
this.numfeats = me.features.length
this.featureIdx = 0;
this.numfeats = me.features.length;
this.viewProps(this.featureIdx)
} else {
this.attributeData = null;
Expand All @@ -148,19 +150,19 @@ export default {
},
prevFeat () {
this.featureIdx -= 1
this.featureIdx -= 1;
if (this.featureIdx < 0) {
this.featureIdx = this.features.length - 1
this.featureIdx = this.features.length - 1;
}
this.viewProps(this.featureIdx)
this.viewProps(this.featureIdx);
},
nextFeat () {
this.featureIdx += 1
this.featureIdx += 1;
if (this.featureIdx > this.features.length - 1) {
this.featureIdx = 0
this.featureIdx = 0;
}
this.viewProps(this.featureIdx)
this.viewProps(this.featureIdx);
},
viewProps (idx) {
Expand All @@ -169,8 +171,8 @@ export default {
// do not show geometry property
delete props.geometry;
this.attributeData = props;
this.layerName = this.features[idx][1].get('name')
const lid = this.features[idx][1].get('lid')
this.layerName = this.features[idx][1].get('name');
const lid = this.features[idx][1].get('lid');
const correspondingInteraction = MapInteractionUtil.getSelectInteraction(this.map, lid);
Expand All @@ -195,6 +197,7 @@ export default {
me.registerMapClick();
} else {
// cleanup old data
me.registerMapClick(true);
me.attributeData = null;
me.coordsData = null;
}
Expand Down
22 changes: 16 additions & 6 deletions tests/unit/specs/components/infoclick/InfoClickWin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,25 @@ describe('infoclick/InfoClickWin.vue', () => {
});

it('show registers map click when module is opened', () => {
let cnt = 0;
const mockFn = () => {
cnt++;
};
vm.registerMapClick = mockFn;
const map = new OlMap();
vm.map = map;
const onSPy = sinon.replace(map, 'on', sinon.fake(map.on));

vm.show(false);
vm.show(true);
expect(cnt).to.equal(1);

expect(onSPy).to.have.been.calledOnceWithExactly('singleclick', vm.onMapClick);
});

it('show unregisters map click when module is closed', () => {
const map = new OlMap();
vm.map = map;
const unSPy = sinon.replace(map, 'un', sinon.fake(map.un));

vm.show(true);
vm.show(false);

expect(unSPy).to.have.been.calledOnceWithExactly('singleclick', vm.onMapClick);
});
});
});

0 comments on commit 0f3b4eb

Please sign in to comment.