diff --git a/demo/js/index.js b/demo/js/index.js index 75e03cee..c5710de6 100755 --- a/demo/js/index.js +++ b/demo/js/index.js @@ -138,7 +138,7 @@ interactiveMap.on('map:ready', function (e) { // framePlugin.addFrame('test', { // aspectRatio: 1 // }) - interactPlugin.enable() + // interactPlugin.enable() }) interactiveMap.on('datasets:ready', () => { @@ -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') }) diff --git a/plugins/datasets/src/mapLayers.js b/plugins/datasets/src/mapLayers.js index 1764068e..8a1a1c7f 100644 --- a/plugins/datasets/src/mapLayers.js +++ b/plugins/datasets/src/mapLayers.js @@ -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 diff --git a/plugins/draw-ml/src/events.js b/plugins/draw-ml/src/events.js index c4594181..0d72d2cb 100755 --- a/plugins/draw-ml/src/events.js +++ b/plugins/draw-ml/src/events.js @@ -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) => { diff --git a/plugins/draw-ml/src/mapboxSnap.js b/plugins/draw-ml/src/mapboxSnap.js index 8347e37e..758913f1 100644 --- a/plugins/draw-ml/src/mapboxSnap.js +++ b/plugins/draw-ml/src/mapboxSnap.js @@ -207,6 +207,7 @@ export function initMapLibreSnap(map, draw, snapOptions = {}) { patchSourceData(source) + /** @type {any} */ const snap = new MapboxSnap({ map, drawing: draw, @@ -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 diff --git a/plugins/draw-ml/src/modes/drawVertexMode.js b/plugins/draw-ml/src/modes/drawVertexMode.js index 3159ae1f..201de33f 100755 --- a/plugins/draw-ml/src/modes/drawVertexMode.js +++ b/plugins/draw-ml/src/modes/drawVertexMode.js @@ -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, diff --git a/plugins/draw-ml/src/modes/editVertexMode.js b/plugins/draw-ml/src/modes/editVertexMode.js index 13fb5c39..370a5bad 100755 --- a/plugins/draw-ml/src/modes/editVertexMode.js +++ b/plugins/draw-ml/src/modes/editVertexMode.js @@ -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, @@ -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') { @@ -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 } }, @@ -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) }, diff --git a/plugins/map-styles/src/MapStyles.jsx b/plugins/map-styles/src/MapStyles.jsx index 13a056ac..cb870341 100755 --- a/plugins/map-styles/src/MapStyles.jsx +++ b/plugins/map-styles/src/MapStyles.jsx @@ -18,14 +18,14 @@ export const MapStyles = ({ mapState, pluginConfig, services, mapProvider }) => } return ( -
-
-
+
+
+
{mapStyles.filter(mapStyle => mapStyle.url).map(mapStyle => ( -
- @@ -34,16 +34,16 @@ export const MapStyles = ({ mapState, pluginConfig, services, mapProvider }) =>
{supportsMapSizes && ( -
-

Map size

-
- {['small', 'medium', 'large'].map(size => ( -
-