Skip to content

PB-1480: Fix bug with swissearch and crosshair together#1257

Merged
ismailsunni merged 11 commits intodevelopfrom
bug-pb-1480-swissearch-crosshair
Mar 24, 2025
Merged

PB-1480: Fix bug with swissearch and crosshair together#1257
ismailsunni merged 11 commits intodevelopfrom
bug-pb-1480-swissearch-crosshair

Conversation

@ismailsunni
Copy link
Contributor

@ismailsunni ismailsunni commented Mar 10, 2025

Test link

Bug description

The issue occurs when the swisssearch value is a valid location and also a valid coordinate. An example from the JIRA issue: http://map.geo.admin.ch/?swisssearch=46.5057,6.6278&zoom=8&crosshair=marker. The query is swisssearch=46.5057,6.6278. It is a valid coordinate, and when we search the location, it returns a valid object:

{
    "fuzzy": "true",
    "results": [
        {
            "attrs": {
                "detail": "dorfstrasse 46 5057 reitnau 4281 reitnau ch ag",
                "featureId": "3098536_0",
                "geom_quadindex": "021131022303023202112",
                "geom_st_box2d": "BOX(2646205.076 1233096.405,2646205.076 1233096.405)",
                "label": "Dorfstrasse 46 <b>5057 Reitnau</b>",
                "lat": 47.247169494628906,
                "lon": 8.048954963684082,
                "num": 46,
                "objectclass": "",
                "origin": "address",
                "rank": 7,
                "x": 1233096.375,
                "y": 2646205.0,
                "zoomlevel": 10
            },
            "id": 974163,
            "weight": 1546
        }
    ]
}

Fix

It seems we don't keep the swisssearch in the URL anymore when sharing location, so the center should be set to the swisssearch location.

Result

Legacy URL Parser

With the buggy coordinate

New URL Parser

With the buggy coordinate

Full list of URL variations

I write all possible combinations of the URL here

Test link

@github-actions github-actions bot added the bug label Mar 10, 2025
@cypress
Copy link

cypress bot commented Mar 10, 2025

web-mapviewer    Run #4860

Run Properties:  status check passed Passed #4860  •  git commit d5a62bfcf1: Merge pull request #1257 from geoadmin/bug-pb-1480-swissearch-crosshair
Project web-mapviewer
Branch Review develop
Run status status check passed Passed #4860
Run duration 01m 38s
Commit git commit d5a62bfcf1: Merge pull request #1257 from geoadmin/bug-pb-1480-swissearch-crosshair
Committer Ismail Sunni
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 1
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 48
View all changes introduced in this branch ↗︎

@ismailsunni ismailsunni force-pushed the bug-pb-1480-swissearch-crosshair branch from 3fe2e1e to 1cedf02 Compare March 10, 2025 08:41
@ismailsunni ismailsunni changed the title PB-1480: remove should center when the center is valid location. PB-1480: Fix bug with swissearch and crosshair together Mar 10, 2025
@ismailsunni ismailsunni force-pushed the bug-pb-1480-swissearch-crosshair branch 2 times, most recently from 3bf0de9 to 915ea3c Compare March 10, 2025 09:12
@ismailsunni ismailsunni marked this pull request as ready for review March 10, 2025 09:34
@ismailsunni ismailsunni requested a review from ltkum March 10, 2025 09:34
Copy link
Contributor

@ltkum ltkum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is something strange going on here :

With your solution, if I go through the legacy parser --> https://sys-map.dev.bgdi.ch/preview/bug-pb-1480-swissearch-crosshair/index.html?swisssearch=46.5057,6.6278&zoom=8&crosshair=marker it works fine, but if I go through the current parser, it goes to the address. I don't think the issue is with the shouldCenter boolean. This boolean had been introduced so that sharing locations would not be overriden by a swisssearch being present. Since then, the swisssearch parameter is no longer kept in the URL, but people can still play around with it.

Also, this only happens when the application is loaded for the first time.

From what I could see, upon starting in map mode, the application will go through setSearchQuery twice. The first time because of the parameter, and it will have its setCenter set to true. The second time, it goes through the else

try {
results = await search({
outputProjection: currentProjection,
queryString: query,
lang: rootState.i18n.lang,
layersToSearch: getters.visibleLayers,
limit: state.autoSelect ? 1 : null,
})
if (
(originUrlParam && results.length === 1) ||
(originUrlParam && state.autoSelect && results.length >= 1)
) {
dispatch('selectResultEntry', {
dispatcher: `${dispatcher}/setSearchQuery`,
entry: getResultForAutoselect(results),
})
}
} catch (error) {
log.error(`Search failed`, error)
}

it can still see the coordinates, but the shouldCenter parameter is false.

It's not called by the searchParam itself. Perhaps it's the onMounted function of the searchBar which creates a small conflict.

@ismailsunni ismailsunni force-pushed the bug-pb-1480-swissearch-crosshair branch from 915ea3c to 86cb8a0 Compare March 12, 2025 08:26
@ismailsunni ismailsunni force-pushed the bug-pb-1480-swissearch-crosshair branch 2 times, most recently from fc6ff9b to c50f8f5 Compare March 19, 2025 08:40
@ismailsunni ismailsunni requested a review from pakb March 20, 2025 09:16
@ismailsunni ismailsunni force-pushed the bug-pb-1480-swissearch-crosshair branch from 851a6a4 to 3e8cb0a Compare March 20, 2025 09:20
@ismailsunni ismailsunni requested a review from ltkum March 20, 2025 09:20
Copy link
Contributor

@ltkum ltkum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to work, and it's a simplification of the code. Good job. One or two minor modifications could be good, but those are really minor.

@ismailsunni ismailsunni force-pushed the bug-pb-1480-swissearch-crosshair branch from 3e8cb0a to e8ed889 Compare March 23, 2025 22:51
@ismailsunni ismailsunni requested review from ltkum and pakb March 23, 2025 22:51
Copy link
Contributor

@ltkum ltkum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me, thanks for your work :)

@ismailsunni ismailsunni force-pushed the bug-pb-1480-swissearch-crosshair branch from e8ed889 to e574d67 Compare March 24, 2025 22:33
@ismailsunni ismailsunni merged commit d5a62bf into develop Mar 24, 2025
6 checks passed
@ismailsunni ismailsunni deleted the bug-pb-1480-swissearch-crosshair branch March 24, 2025 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants