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

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

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

I set the shouldCenter always true when the string in swisssearch is a valid coordinate, so that it will center to the coordinate (instead searching to a location).

Result

Same query with this PR url: https://sys-map.dev.bgdi.ch/preview/bug-pb-1480-swissearch-crosshair/index.html#/map?swisssearch=46.5057,6.6278&zoom=8&crosshair=marker

Test link

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

cypress bot commented Mar 10, 2025

web-mapviewer    Run #4744

Run Properties:  status check passed Passed #4744  •  git commit 86cb8a0ebe: PB-1480: Also handle setSearchQuery on redoSearchWhenNeeded.
Project web-mapviewer
Branch Review bug-pb-1480-swissearch-crosshair
Run status status check passed Passed #4744
Run duration 04m 42s
Commit git commit 86cb8a0ebe: PB-1480: Also handle setSearchQuery on redoSearchWhenNeeded.
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 23
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 239
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
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.

2 participants