Skip to content

Commit

Permalink
PB-875: select geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
sommerfe committed Oct 15, 2024
1 parent fc8745a commit 920e0e4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ export function useDragBoxSelect() {
}
}

/**
* Converts an OpenLayers geometry object to a Turf.js geometry object.
*
* @param {ol.geom.Geometry} olGeometry - The OpenLayers geometry object to convert.
* @returns {Object | null} The corresponding Turf.js geometry object, or null if the geometry type
* is not supported.
*/
function fromOlGeometryToTurfGeometry(olGeometry) {
if (olGeometry instanceof Point) {
return point(olGeometry.getCoordinates())
Expand Down
8 changes: 8 additions & 0 deletions src/utils/layerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ export function indexOfMaxResolution(projection, layerMaxResolution) {
return indexOfResolution
}

/**
* Creates a LayerFeature object from an OpenLayers feature and a layer.
*
* @param {ol.Feature} olFeature - The OpenLayers feature to convert.
* @param {AbstractLayer} layer - The layer associated with the feature.
* @returns {LayerFeature | null} The created LayerFeature object or null if the feature has no
* geometry.
*/
export function createLayerFeature(olFeature, layer) {
if (!olFeature?.getGeometry()) return null
return new LayerFeature({
Expand Down
41 changes: 34 additions & 7 deletions tests/cypress/tests-e2e/featureSelection.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ describe('Testing the feature selection', () => {
})
})
context('Feature identification on the map', () => {
function drawRectangleOnMap(pixelsFromCenter) {
function drawRectangleOnMap(pixelsFromCenter, position = 'center') {
cy.get('@olMap').realMouseDown({ ctrlKey: true, position: 'center' })
cy.get('@olMap').realMouseMove(pixelsFromCenter.x, pixelsFromCenter.y, {
ctrlKey: true,
position: 'center',
position,
})
cy.get('@olMap').then((olMapElement) => {
cy.get('@olMap').realMouseUp({
Expand All @@ -267,9 +267,28 @@ describe('Testing the feature selection', () => {
}

it('can select an area to identify features inside it', () => {
cy.goToMapView({
layers: 'test.wms.layer',
// Import KML file
const localKmlFile = 'import-tool/external-kml-file.kml'
cy.goToMapView(
{
layers: 'test.wms.layer',
},
true
)
const featureCountWithKml = DEFAULT_FEATURE_COUNT_RECTANGLE_SELECTION + 1
cy.openMenuIfMobile()
cy.get('[data-cy="menu-tray-tool-section"]:visible').click()
cy.get('[data-cy="menu-advanced-tools-import-file"]:visible').click()
cy.get('[data-cy="import-file-local-btn"]:visible').click()
cy.fixture(localKmlFile, null).as('kmlFixture')
cy.get('[data-cy="file-input"]').selectFile('@kmlFixture', {
force: true,
})
cy.get('[data-cy="import-file-load-button"]:visible').click()
cy.get('[data-cy="modal-close-button"]:visible').click()

cy.closeMenuIfMobile()

cy.get('[data-cy="ol-map"]').as('olMap').should('be.visible')
cy.log(
'Selecting a rectangle (by click&drag) while pressing SHIFT, should start a rectangle identification of features'
Expand All @@ -278,7 +297,8 @@ describe('Testing the feature selection', () => {
x: 100,
y: -100,
})
cy.log('making sure 50 items are requested when selecting a dragbox on the map')

cy.log('making sure 51 items are requested when selecting a dragbox on the map') // including the one from the kml file
cy.wait('@identify')
.its('request.query.limit')
.should('eq', `${DEFAULT_FEATURE_COUNT_RECTANGLE_SELECTION}`)
Expand All @@ -299,7 +319,7 @@ describe('Testing the feature selection', () => {
cy.log('checking that each feature has been rendered in the list')
cy.get('@highlightedFeatures')
.find('[data-cy="feature-item"]')
.should('have.length', DEFAULT_FEATURE_COUNT_RECTANGLE_SELECTION)
.should('have.length', featureCountWithKml)
cy.get('@highlightedFeatures').scrollTo('bottom')

cy.get('[data-cy="feature-list-load-more"]').as('loadMore').should('be.visible')
Expand All @@ -321,7 +341,7 @@ describe('Testing the feature selection', () => {
}
cy.get('@highlightedFeatures')
.find('[data-cy="feature-item"]')
.should('have.length', 2 * DEFAULT_FEATURE_COUNT_RECTANGLE_SELECTION)
.should('have.length', 2 * DEFAULT_FEATURE_COUNT_RECTANGLE_SELECTION + 1)

cy.log('Sending an empty response for further identify')
cy.intercept('**identify**', {
Expand All @@ -337,6 +357,13 @@ describe('Testing the feature selection', () => {
cy.log(
'sending a single feature as response, checking that the "Load more" button is not added'
)
cy.goToMapView(
{
layers: 'test.wms.layer',
},
true
)

cy.intercept('**identify**', {
fixture: 'features/features.fixture',
}).as('identifySingleFeature')
Expand Down

0 comments on commit 920e0e4

Please sign in to comment.