Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions demo/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ interactiveMap.on('map:ready', function (e) {
// framePlugin.addFrame('test', {
// aspectRatio: 1
// })
interactPlugin.enable()
// interactPlugin.enable()
})

interactiveMap.on('datasets:ready', () => {
Expand All @@ -150,19 +150,19 @@ interactiveMap.on('datasets:ready', () => {
})

interactiveMap.on('draw:ready', function () {
// drawPlugin.addFeature({
// id: 'test1234',
// type: 'Feature',
// geometry: { type: 'Polygon', coordinates: [[[-2.9406643378873127,54.918060570259456],[-2.9092219779267054,54.91564249172612],[-2.904350626383433,54.90329530000005],[-2.909664828067463,54.89540129642464],[-2.9225074821353587,54.88979816151294],[-2.937121536764323,54.88826989853317],[-2.95682836800691,54.88916139231736],[-2.965463945742613,54.898966521920045],[-2.966349646023133,54.910805898763385],[-2.9406643378873127,54.918060570259456]]] },
// properties: {
// stroke: 'rgba(0,112,60,1)',
// fill: 'rgba(0,112,60,0.2)',
// strokeWidth: 2,
// }
// })
// drawPlugin.newPolygon('test', {
// snapLayers: ['OS/TopographicArea_1/Agricultural Land']
// })
drawPlugin.addFeature({
id: 'test1234',
type: 'Feature',
geometry: { type: 'Polygon', coordinates: [[[-2.9406643378873127,54.918060570259456],[-2.9092219779267054,54.91564249172612],[-2.904350626383433,54.90329530000005],[-2.909664828067463,54.89540129642464],[-2.9225074821353587,54.88979816151294],[-2.937121536764323,54.88826989853317],[-2.95682836800691,54.88916139231736],[-2.965463945742613,54.898966521920045],[-2.966349646023133,54.910805898763385],[-2.9406643378873127,54.918060570259456]]] },
properties: {
stroke: 'rgba(0,112,60,1)',
fill: 'rgba(0,112,60,0.2)',
strokeWidth: 2,
}
})
drawPlugin.newPolygon('test', {
snapLayers: ['OS/TopographicArea_1/Agricultural Land']
})
// drawPlugin.editFeature('test1234')
})

Expand Down
7 changes: 4 additions & 3 deletions plugins/datasets/src/mapLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { getValueForStyle } from '../../../src/utils/getValueForStyle.js'

// Generate a hash for consistent source ID generation
const hashString = (str) => {
const HASH_BASE = 36
let hash = 0
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) - hash) + str.charCodeAt(i)
for (const ch of str) {
hash = ((hash << 5) - hash) + ch.codePointAt(0)
hash = hash & hash
}
return Math.abs(hash).toString(36)
return Math.abs(hash).toString(HASH_BASE)
}

// Generate a consistent source ID for source sharing
Expand Down
2 changes: 1 addition & 1 deletion plugins/draw-ml/src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function attachEvents ({ appState, appConfig, mapState, pluginState, mapP
}
layers.filter(l => l.source?.startsWith('mapbox-gl-draw')).forEach(l => map.moveLayer(l.id))
}
map.on('styledata', () => handleStyleData(map))
map.on('styledata', () => handleStyleData())

// --- A new shape is created
const onCreate = (e) => {
Expand Down
18 changes: 11 additions & 7 deletions plugins/draw-ml/src/mapboxSnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export function initMapLibreSnap(map, draw, snapOptions = {}) {

patchSourceData(source)

/** @type {any} */
const snap = new MapboxSnap({
map,
drawing: draw,
Expand All @@ -218,20 +219,23 @@ export function initMapLibreSnap(map, draw, snapOptions = {}) {
// Override the status property to prevent library from auto-setting it
// The library sets status=true on draw.modechange and draw.selectionchange
// We want external control only via setSnapStatus()
let _status = status
let controlledStatus = status

/* sonar-disable sonarjs:S4275 */
Object.defineProperty(snap, 'status', {
get() {
return _status
get () {
return controlledStatus
},
set() {
// Ignore the library's auto-set attempts - only allow via setSnapStatus()
set () {
// intentionally empty: library writes are ignored
},
configurable: true
})
/* sonar-enable sonarjs:S4275 */

// Provide a method for external control of status
// Provide a controlled method for updating status
snap.setSnapStatus = (value) => {
_status = value
controlledStatus = value
}

// Store default layers and provide method to override per-call
Expand Down
4 changes: 2 additions & 2 deletions plugins/draw-ml/src/modes/drawVertexMode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DrawPolygon from '/node_modules/@mapbox/mapbox-gl-draw/src/modes/draw_polygon.js'
import createVertex from '/node_modules/@mapbox/mapbox-gl-draw/src/lib/create_vertex.js'
import DrawPolygon from '../../../../node_modules/@mapbox/mapbox-gl-draw/src/modes/draw_polygon.js'
import createVertex from '../../../../node_modules/@mapbox/mapbox-gl-draw/src/lib/create_vertex.js'
import { isValidClick } from '../utils.js'
import {
getSnapInstance,
Expand Down
8 changes: 4 additions & 4 deletions plugins/draw-ml/src/modes/editVertexMode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import DirectSelect from '/node_modules/@mapbox/mapbox-gl-draw/src/modes/direct_select.js'
import DirectSelect from '../../../../node_modules/@mapbox/mapbox-gl-draw/src/modes/direct_select.js'
import { spatialNavigate } from '../utils.js'
import {
getSnapInstance, isSnapActive, isSnapEnabled, getSnapLngLat,
Expand Down Expand Up @@ -203,7 +203,7 @@ export const EditVertexMode = {

if (meta === 'vertex') {
this.changeMode(state, {
selectedVertexIndex: parseInt(coordPath.split('.')[1], 10),
selectedVertexIndex: Number.parseInt(coordPath.split('.')[1], 10),
selectedVertexType: 'vertex', coordPath
})
} else if (meta === 'midpoint') {
Expand All @@ -221,7 +221,7 @@ export const EditVertexMode = {

const touch = { x: e.touches[0].clientX, y: e.touches[0].clientY }
const style = window.getComputedStyle(state.touchVertexTarget)
state.deltaTarget = { x: touch.x - parseFloat(style.left), y: touch.y - parseFloat(style.top) }
state.deltaTarget = { x: touch.x - Number.parseFloat(style.left), y: touch.y - Number.parseFloat(style.top) }
const vertexPt = this.map.project(state.vertecies[state.selectedVertexIndex])
state.deltaVertex = { x: (touch.x / state.scale) - vertexPt.x, y: (touch.y / state.scale) - vertexPt.y }
},
Expand Down Expand Up @@ -311,7 +311,7 @@ export const EditVertexMode = {
},

getVertexIndexFromMidpoint(vertecies, coordPath) {
const afterIdx = parseInt(coordPath.split('.')[1], 10)
const afterIdx = Number.parseInt(coordPath.split('.')[1], 10)
return vertecies.length + ((afterIdx - 1 + vertecies.length) % vertecies.length)
},

Expand Down
36 changes: 18 additions & 18 deletions plugins/map-styles/src/MapStyles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export const MapStyles = ({ mapState, pluginConfig, services, mapProvider }) =>
}

return (
<div className='im-c-map-styles'>
<div className='im-c-map-styles__group'>
<div className='im-c-map-styles__inner'>
<div className="im-c-map-styles">
<div className="im-c-map-styles__group">
<div className="im-c-map-styles__inner">
{mapStyles.filter(mapStyle => mapStyle.url).map(mapStyle => (
<div className='im-c-map-styles__item' key={mapStyle.id}>
<button className='im-c-map-styles__button' aria-pressed={mapStyle.id === currentMapStyle.id} onClick={() => handleMapStyleClick(mapStyle)}>
<div className='im-c-map-styles__image'>
<img src={mapStyle.thumbnail || undefined} height='60' width='60' />
<div className="im-c-map-styles__item" key={mapStyle.id}>
<button className="im-c-map-styles__button" aria-pressed={mapStyle.id === currentMapStyle.id} onClick={() => handleMapStyleClick(mapStyle)}>
<div className="im-c-map-styles__image">
<img src={mapStyle.thumbnail || undefined} alt="" height="60" width="60" />
</div>
{mapStyle.label}
</button>
Expand All @@ -34,16 +34,16 @@ export const MapStyles = ({ mapState, pluginConfig, services, mapProvider }) =>
</div>
</div>
{supportsMapSizes && (
<div className='im-c-map-styles__group'>
<h3 className='im-c-map-styles__heading' id='map-text-sizes'>Map size</h3>
<div className='im-c-map-styles__inner'>
{['small', 'medium', 'large'].map(size => (
<div className='im-c-map-styles__item' key={size}>
<button className='im-c-map-styles__button' onClick={() => handleMapSizeClick(size)} aria-pressed={size === currentMapSize}>
<div className='im-c-map-styles__image'>
<svg width='60' height='60' viewBox='0 0 60 60' fillRule='evenodd'>
<rect className='im-c-map-styles__image-bg' width='100%' height='100%' />
<g style={{ transform: `scale(${scaleFactor[size]})`, transformOrigin: '8px 52px' }}>
<div className="im-c-map-styles__group">
<h3 className="im-c-map-styles__heading" id="map-text-sizes">Map size</h3>
<div className="im-c-map-styles__inner">
{["small", "medium", "large"].map(size => (
<div className="im-c-map-styles__item" key={size}>
<button className="im-c-map-styles__button" onClick={() => handleMapSizeClick(size)} aria-pressed={size === currentMapSize}>
<div className="im-c-map-styles__image">
<svg width="60" height="60" viewBox="0 0 60 60" fillRule="evenodd">
<rect className="im-c-map-styles__image-bg" width="100%" height="100%" />
<g style={{ transform: `scale(${scaleFactor[size]})`, transformOrigin: "8px 52px" }}>
<path d={textSizeSvgPath} />
</g>
</svg>
Expand All @@ -57,4 +57,4 @@ export const MapStyles = ({ mapState, pluginConfig, services, mapProvider }) =>
)}
</div>
)
}
}
6 changes: 3 additions & 3 deletions plugins/search/src/components/Suggestions/Suggestions.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// src/plugins/search/Suggestions.jsx
export const Suggestions = ({ id, pluginState, handleSuggestionClick }) => {
return (
<ul
<ul // nosonar
id={`${id}-search-suggestions`}
role="listbox"
aria-labelledby={`${id}-search`} // Option A: label from input
Expand All @@ -13,11 +13,11 @@ export const Suggestions = ({ id, pluginState, handleSuggestionClick }) => {
key={suggestion.id}
id={`${id}-search-suggestion-${i}`}
className="im-c-search-suggestions__item"
role="option"
role="option" // nosonar
aria-selected={pluginState.selectedIndex === i}
aria-setsize={pluginState.suggestions.length}
aria-posinset={i + 1}
onClick={() => handleSuggestionClick(suggestion)}
onClick={() => handleSuggestionClick(suggestion)} // nosonar
>
<span className="im-c-search-suggestions__label" dangerouslySetInnerHTML={{ __html: suggestion.marked }} />
</li>
Expand Down
2 changes: 1 addition & 1 deletion plugins/search/src/events/fetchSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fetchDataset } from '../utils/fetchDataset.js'
* Sanitise input query
* Allows letters, numbers, spaces, dashes, commas, full stops
*/
const sanitiseQuery = (value) => value.replace(/[^a-zA-Z0-9\s\-.,]/g, '').trim()
const sanitiseQuery = (value) => value.replaceAll(/[^a-zA-Z0-9\s\-.,]/g, '').trim()

/**
* Fetch suggestions from multiple datasets
Expand Down
6 changes: 3 additions & 3 deletions plugins/search/src/utils/parseOsNamesResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const POINT_BUFFER = 500
const MAX_RESULTS = 8

const isPostcode = (value) => {
value = value.replace(/\s/g, '')
value = value.replaceAll(/\s/g, '')
const regex = /^(([A-Z]{1,2}\d[A-Z\d]?|ASCN|STHL|TDCU|BBND|[BFS]IQQ|PCRN|TKCA) ?\d[A-Z]{2}|BFPO ?\d{1,4}|(KY\d|MSR|VG|AI)[ -]?\d{4}|[A-Z]{2} ?\d{2}|GE ?CX|GIR ?0A{2}|SAN ?TA1)$/i
return regex.test(value)
}
Expand All @@ -17,12 +17,12 @@ const removeDuplicates = (results) =>
Array.from(new Map(results.map(r => [r.GAZETTEER_ENTRY.ID, r])).values())

const removeTenuousResults = (results, query) => {
const words = query.toLowerCase().replace(/,/g, '').split(' ')
const words = query.toLowerCase().replaceAll(',', '').split(' ')
return results.filter(l => words.some(w => l.GAZETTEER_ENTRY.NAME1.toLowerCase().includes(w) || isPostcode(query)))
}

const markString = (string, find) => {
const clean = find.replace(/\s+/g, '')
const clean = find.replaceAll(/\s+/g, '')
// Create a pattern where whitespace is optional between every character
// e.g. "ab12cd" -> "a\s* b\s* 1\s* 2\s* c\s* d"
const spacedPattern = clean.split('').join('\\s*')
Expand Down
4 changes: 2 additions & 2 deletions providers/esri/src/esriProvider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// src/plugins/mapStyles/EsriProvider.jsx
import './esriProvider.scss'
import esriConfig from '@arcgis/core/config.js'
import Map from '@arcgis/core/Map.js'
import EsriMap from '@arcgis/core/Map.js'
import MapView from '@arcgis/core/views/MapView.js'
import VectorTileLayer from '@arcgis/core/layers/VectorTileLayer.js'
import { defaults, supportedShortcuts } from './defaults.js'
Expand Down Expand Up @@ -36,7 +36,7 @@ export default class EsriProvider {
}

const baseTileLayer = new VectorTileLayer({ id: 'baselayer', url: mapStyle.url, visible: true })
const map = new Map({ layers: [baseTileLayer] })
const map = new EsriMap({ layers: [baseTileLayer] })
const geometry = maxExtent ? getExtentFromFlatCoords(maxExtent) : null

const view = new MapView({
Expand Down
10 changes: 6 additions & 4 deletions providers/esri/src/utils/spatial.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const formatDimension = (meters) => {
}

if (miles < WHOLE_MILE_THRESHOLD) {
const value = parseFloat(miles.toFixed(1))
const unit = value === 1 ? 'mile' : 'miles'
return `${value} ${unit}`
const value = Number.parseFloat(miles.toFixed(1))
const units = value === 1 ? 'mile' : 'miles'
return `${value} ${units}`
}

const rounded = Math.round(miles)
Expand Down Expand Up @@ -96,7 +96,9 @@ function getCardinalMove(from, to) {
* @param {Object} padding - Optional: { top, right, bottom, left } in pixels
* @returns {Extent} - Padded extent
*/
const getPaddedExtent = (view, padding = { top: 0, right: 0, bottom: 0, left: 0 }) => {
const DEFAULT_PADDING = { top: 0, right: 0, bottom: 0, left: 0 }

const getPaddedExtent = (view, padding = DEFAULT_PADDING) => {
if (!view.container) {
return null
}
Expand Down
6 changes: 3 additions & 3 deletions providers/maplibre/src/utils/spatial.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const formatDimension = (meters) => {
}

if (miles < WHOLE_MILE_THRESHOLD) {
const value = parseFloat(miles.toFixed(1))
const unit = value === 1 ? 'mile' : 'miles'
return `${value} ${unit}`
const value = Number.parseFloat(miles.toFixed(1))
const units = value === 1 ? 'mile' : 'miles'
return `${value} ${units}`
}

const rounded = Math.round(miles)
Expand Down
14 changes: 7 additions & 7 deletions src/App/components/Panel/Panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ export const Panel = ({ panelId, panelConfig, props, WrappedChild, label, html,
const innerHtmlProp = useMemo(() => html ? { __html: html } : null, [html])

return (
<div
<div // nosonar
ref={panelRef}
id={elementId}
aria-labelledby={`${elementId}-label`}
tabIndex={shouldFocus ? -1 : undefined}
role={isDialog ? 'dialog' : isDismissable ? 'complementary' : 'region'}
tabIndex={shouldFocus ? -1 : undefined} // nosonar
role={isDialog ? 'dialog' : (isDismissable && 'complementary') || 'region'}
aria-modal={isDialog && isModal ? 'true' : undefined}
style={bpConfig.width ? { width: bpConfig.width } : undefined}
className={panelClass}
Expand All @@ -84,18 +84,18 @@ export const Panel = ({ panelId, panelConfig, props, WrappedChild, label, html,

{innerHtmlProp
? (
<div
<div // nosonar
ref={bodyRef}
className={panelBodyClass}
tabIndex={isBodyScrollable ? 0 : undefined}
tabIndex={isBodyScrollable ? 0 : undefined} // nosonar
dangerouslySetInnerHTML={innerHtmlProp}
/>
)
: (
<div
<div // nosonar
ref={bodyRef}
className={panelBodyClass}
tabIndex={isBodyScrollable ? 0 : undefined}
tabIndex={isBodyScrollable ? 0 : undefined} // nosonar
role={isBodyScrollable ? 'region' : undefined}
aria-labelledby={isBodyScrollable ? `${elementId}-label` : undefined}
>
Expand Down
2 changes: 1 addition & 1 deletion src/App/components/Viewport/Viewport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const Viewport = ({ keyboardHintPortalRef }) => {
className={`im-c-viewport im-c-viewport--${mapSize}`}
aria-label={mapLabel}
role='application'
tabIndex='0'
tabIndex='0' // nosonar
onFocus={handleFocus}
onBlur={handleBlur}
ref={layoutRefs.viewportRef}
Expand Down
4 changes: 2 additions & 2 deletions src/App/hooks/useCrossHairAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useCrossHair = () => {
const { x, y } = mapProvider.mapToScreen(coords)
crossHair.coords = coords
dispatch({ type: 'UPDATE_CROSS_HAIR', payload: { isPinnedToMap: true, isVisible: true, coords, state } })
updatePosition(el, x, y, state)
updatePosition(el, x, y)
}

crossHair.fixAtCenter = () => {
Expand Down Expand Up @@ -78,7 +78,7 @@ export const useCrossHair = () => {
const handleRender = () => {
if (crossHair.coords && crossHair.isPinnedToMap) {
const { x, y } = mapProvider.mapToScreen(crossHair.coords)
updatePosition(el, x, y, crossHair.state)
updatePosition(el, x, y)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/App/hooks/useLayoutMeasurements.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function useLayoutMeasurements () {
}

const root = document.documentElement
const dividerGap = parseInt(getComputedStyle(root).getPropertyValue('--divider-gap'), 10)
const dividerGap = Number.parseInt(getComputedStyle(root).getPropertyValue('--divider-gap'), 10)

// === Inset offsets ===
const insetOffsetTop = topLeftCol.offsetHeight + top.offsetTop
Expand Down
2 changes: 1 addition & 1 deletion src/App/hooks/useModalPanelBehaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function useModalPanelBehaviour ({

// === Set absolute offset positions and recalculate on mainRef resize === //
const root = document.documentElement
const dividerGap = parseInt(getComputedStyle(root).getPropertyValue('--divider-gap'), 10)
const dividerGap = Number.parseInt(getComputedStyle(root).getPropertyValue('--divider-gap'), 10)

useResizeObserver([mainRef], () => {
if (!isModal || !buttonContainerEl || !mainRef.current) {
Expand Down
Loading