Skip to content

Conversation

@geographika
Copy link
Contributor

@geographika geographika commented Jan 17, 2025

The comment states // Loose equality check since code could be a string or an int however an exact check is used.
This then causes filtered to be an empty array when checking 3857 ==== "3857" between a projection code in the store and the projection code from the map.

Results in the JS error:

CoordinateMousePositionPanel.js?_dc=1737122544728:347 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'name')
    at constructor.generateCrsChangeButtonGroup (CoordinateMousePositionPanel.js?_dc=1737122544728:347:53)
    at CoordinateMousePositionPanel.js?_dc=1737122544728:273:20

In addition the filtered ? filtered[0].name : '' will return true for an empty array (which is always created using Ext.Array.filter) - updated to account for this.

@geographika
Copy link
Contributor Author

@KaiVolland - looking at the history this may be intentional? 5116f3c
However even adding a code as a string, this gets converted to a number as the model BasiGX.model.Projection has code set to int.

        projectionsStore.loadData([{
            code: 4326,
            name: 'WGS 84',
            proj4: '+proj=longlat +datum=WGS84 +no_defs +type=crs',
            unit: 'degree (supplier to define representation)',
        }, {
            code: '3857',
            name: 'WGS 84 / Pseudo-Mercator',
            proj4: '+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs',
            unit: 'metre'
        },

@geographika
Copy link
Contributor Author

Alternately, the mapCode could be converted to an int:

                // update view model to set correct CRS name of map
                var mapCode = parseInt(me.olMap.getView().getProjection().getCode()
                    .split(':')[1], 10);

@KaiVolland KaiVolland requested a review from dnlkoch January 21, 2025 08:06
@KaiVolland
Copy link
Member

KaiVolland commented Jan 21, 2025

@dnlkoch can you please have an additional look and then merge it if it is fine for you.

@geographika geographika changed the title Use loose equality check in CoordinateMousePositionPanel Check for proj codes as str or int in CoordinateMousePositionPanel Jan 22, 2025
@dnlkoch
Copy link
Member

dnlkoch commented Jan 22, 2025

Thanks @geographika!

@dnlkoch dnlkoch merged commit 1b74560 into terrestris:master Jan 22, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants