Skip to content

Commit d5d4a0f

Browse files
authored
Merge pull request #1457 from geoman-io/develop
release v2.16.0
2 parents 9d76409 + 038c7d2 commit d5d4a0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3901
-15802
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
"L": true,
2020
"window": true,
2121
"document": true
22-
}
22+
},
23+
"ignorePatterns": [
24+
"cypress/libs"
25+
]
2326
}

.github/workflows/nodejs.yml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,44 @@ on: [push, pull_request]
44

55
jobs:
66
build:
7+
name: Test
78
runs-on: ubuntu-latest
89

910
strategy:
1011
matrix:
11-
node-version: [16.x, 20.x]
12+
node-version: [20.x]
1213

1314
steps:
14-
- uses: actions/checkout@v2
15-
- name: Use Node.js ${{ matrix.node-version }}
16-
uses: actions/setup-node@v1
15+
- uses: actions/checkout@v4
16+
17+
- uses: pnpm/action-setup@v3
18+
with:
19+
version: 8
20+
21+
- name: Use Node.js 20.x
22+
uses: actions/setup-node@v4
1723
with:
1824
node-version: ${{ matrix.node-version }}
19-
- run: npm install
20-
- run: npm run build --if-present
21-
- run: npm test
25+
cache: pnpm
26+
27+
- name: Get pnpm store directory
28+
shell: bash
29+
run: |
30+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
31+
32+
- uses: actions/cache@v4
33+
name: Setup pnpm cache
34+
with:
35+
path: |
36+
${{ env.STORE_PATH }}
37+
/home/runner/.cache/Cypress
38+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
39+
restore-keys: |
40+
${{ runner.os }}-pnpm-store-
41+
42+
- name: Install dependencies
43+
run: pnpm install --frozen-lockfile --store-dir ${{ env.STORE_PATH }}
44+
- run: pnpm run build
45+
- run: pnpm test
2246
env:
2347
CI: true

.github/workflows/release.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'v*.*.*'
8+
9+
env:
10+
FILE_NAME_PREFIX: geoman-io-leaflet-geoman-pro
11+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
12+
13+
jobs:
14+
build:
15+
name: release job
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set version
22+
id: version
23+
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
24+
25+
- name: Check version
26+
run: |
27+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
28+
if [ "${{ steps.version.outputs.version }}" != "$PACKAGE_VERSION" ]; then
29+
echo "Tag version ($TAG_VERSION) does not match package.json version ($PACKAGE_VERSION)"
30+
exit 1
31+
fi
32+
33+
- uses: pnpm/action-setup@v3
34+
with:
35+
version: 8
36+
37+
- name: Use Node.js 20.x
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: 20.x
41+
cache: pnpm
42+
43+
- name: Get pnpm store directory
44+
shell: bash
45+
run: |
46+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
47+
48+
- uses: actions/cache@v4
49+
name: Setup pnpm cache
50+
with:
51+
path: ${{ env.STORE_PATH }}
52+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
53+
restore-keys: |
54+
${{ runner.os }}-pnpm-store-
55+
56+
- name: Install dependencies
57+
run: pnpm install --frozen-lockfile --store-dir ${{ env.STORE_PATH }}
58+
59+
- name: Prepare package
60+
run: pnpm pack
61+
62+
- name: Release
63+
uses: softprops/action-gh-release@v1
64+
with:
65+
name: ${{ steps.version.outputs.version }}
66+
tag_name: v${{ steps.version.outputs.version }}
67+
token: ${{ secrets.GEOMAN_RELEASE_TOKEN }}
68+
files: |
69+
${{env.FILE_NAME_PREFIX}}-${{ steps.version.outputs.version }}.tgz
70+
LICENSE
71+
72+
- name: Publish to NPM
73+
shell: bash
74+
run: |
75+
#!/bin/bash
76+
77+
# Set npm configurations
78+
pnpm config set shamefully-hoist true
79+
pnpm config set strict-peer-dependencies false
80+
81+
# Set auth token
82+
pnpm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
83+
pnpm publish --no-git-checks

bundle.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as esbuild from 'esbuild';
2+
import fs from 'fs';
3+
4+
const plugins = [{
5+
name: 'my-plugin',
6+
setup(build) {
7+
let count = 0;
8+
build.onEnd(({ errors, warnings }) => {
9+
count++;
10+
const message = errors.length === 0 && warnings.length === 0
11+
? 'Build completed.'
12+
: `Build completed with ${errors.length} error(s) and ${warnings.length} warning(s).`;
13+
console.log(`[BUILD #${count.toString().padStart(3, '0')}]:`, message); });
14+
},
15+
}];
16+
17+
const buildOptions = {
18+
bundle: true,
19+
entryPoints: ['./src/js/L.PM.js'],
20+
loader: {
21+
'.js': 'jsx',
22+
'.css': 'css',
23+
'.svg': 'dataurl' },
24+
minify: true,
25+
outfile: './dist/leaflet-geoman.js',
26+
sourcemap: process.env.DEV ? true : false,
27+
}
28+
29+
const ctx = await esbuild.context({ ...buildOptions, plugins });
30+
31+
if (process.env.DEV) {
32+
// Watch in dev mode
33+
await ctx.watch();
34+
console.log('watching...');
35+
const { host, port } = await ctx.serve({
36+
port: 5500,
37+
servedir: '.',
38+
fallback: "./index.html"
39+
});
40+
console.log(`Serving app at ${host}:${port}.`);
41+
} else {
42+
// Clean /dist folder
43+
fs.rmSync("./dist", { recursive: true, force: true });
44+
45+
// Build
46+
await ctx.rebuild();
47+
48+
// Dispose context
49+
ctx.dispose();
50+
51+
// Copy types
52+
fs.copyFileSync('leaflet-geoman.d.ts', './dist/leaflet-geoman.d.ts');
53+
fs.copyFileSync('./dist/leaflet-geoman.js', './dist/leaflet-geoman.min.js');
54+
}

cypress/integration/mixins.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
describe('KeyboardMixin', () => {
2+
it('Should unbind event listeners that bound by the KeyboardMixin after the map is destroyed', () => {
3+
cy.window().then((window) => {
4+
const { map, document } = window;
5+
6+
map.remove();
7+
8+
const isWindowBlurEventUnbound = !Object.entries(
9+
window._leaflet_events
10+
).some(([name, handler]) => name.startsWith('blur') && handler);
11+
expect(
12+
isWindowBlurEventUnbound,
13+
'window blur event listener is not unbound'
14+
).to.eq(true);
15+
16+
const isKeyUpDownEventUnbound = !Object.entries(
17+
document._leaflet_events
18+
).some(([name, handler]) => name.startsWith('key') && handler);
19+
expect(
20+
isKeyUpDownEventUnbound,
21+
'document keyboard event listener is not unbound'
22+
).to.eq(true);
23+
});
24+
});
25+
});

cypress/integration/polygon.spec.js

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,8 @@ describe('Draw & Edit Poly', () => {
716716
onStop() {
717717
expect(poly.pm.hasSelfIntersection()).to.equal(true);
718718

719-
const toucherSelfIntersectionFalse = handSelfIntersectionFalse.growFinger(
720-
'mouse'
721-
);
719+
const toucherSelfIntersectionFalse =
720+
handSelfIntersectionFalse.growFinger('mouse');
722721
toucherSelfIntersectionFalse
723722
.wait(100)
724723
.moveTo(504, 337, 100)
@@ -744,9 +743,8 @@ describe('Draw & Edit Poly', () => {
744743
allowSelfIntersectionEdit: true,
745744
});
746745

747-
const toucherSelfIntersectionTrue = handSelfIntersectionTrue.growFinger(
748-
'mouse'
749-
);
746+
const toucherSelfIntersectionTrue =
747+
handSelfIntersectionTrue.growFinger('mouse');
750748
toucherSelfIntersectionTrue
751749
.wait(100)
752750
.moveTo(294, 114, 100)
@@ -1280,4 +1278,53 @@ describe('Draw & Edit Poly', () => {
12801278
expect(hintLine.options.color).to.eql('red');
12811279
});
12821280
});
1281+
1282+
it('snap to start marker instead of to the layer below', () => {
1283+
cy.window().then(({ map, L }) => {
1284+
// it was not possible to create this test with creating the polygon by clicking
1285+
const polygon = L.polygon([
1286+
[
1287+
[20.53507732696281, 71.98242187500001],
1288+
[19.87005983797396, 71.97143554687501],
1289+
[19.782211275967995, 73.35021972656251],
1290+
[20.55565240377338, 73.48754882812501],
1291+
[20.53507732696281, 71.98242187500001],
1292+
],
1293+
]);
1294+
polygon.addTo(map);
1295+
map.fitBounds(polygon.getBounds(), { animate: false });
1296+
map.setZoom(8, { animate: false });
1297+
1298+
map.pm.enableDraw('Polygon');
1299+
1300+
map.pm.Draw.Polygon._hintMarker.setLatLng([
1301+
20.53837097209846, 72.22334801861803,
1302+
]);
1303+
map.pm.Draw.Polygon._createVertex({
1304+
latlng: [20.53837097209846, 72.22334801861803],
1305+
});
1306+
1307+
map.pm.Draw.Polygon._hintMarker.setLatLng([
1308+
20.21581109239457, 72.13073730468751,
1309+
]);
1310+
map.pm.Draw.Polygon._createVertex({
1311+
latlng: [20.21581109239457, 72.13073730468751],
1312+
});
1313+
1314+
map.pm.Draw.Polygon._hintMarker.setLatLng([
1315+
20.205501205844214, 72.77893066406251,
1316+
]);
1317+
map.pm.Draw.Polygon._createVertex({
1318+
latlng: [20.205501205844214, 72.77893066406251],
1319+
});
1320+
});
1321+
1322+
cy.get(mapSelector).trigger('mousemove', 413, 180);
1323+
1324+
cy.window().then(({ map }) => {
1325+
const hintMarker = map.pm.Draw.Polygon._hintMarker;
1326+
expect(hintMarker.getLatLng().lat).to.eq(20.53837097209846);
1327+
expect(hintMarker.getLatLng().lng).to.eq(72.22334801861803);
1328+
});
1329+
});
12831330
});

cypress/integration/rotation.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('Rotation', () => {
3737

3838
cy.window().then(({ map }) => {
3939
const layer = map.pm.getGeomanDrawLayers()[0];
40+
expect(layer.pm.rotateEnabled()).to.equal(false);
4041

4142
layer.pm.enableRotate();
4243
expect(layer.pm.rotateEnabled()).to.equal(true);

cypress/integration/toolbar.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,4 +500,24 @@ describe('Testing the Toolbar', () => {
500500
expect(eventFired).to.equal('drawPolygon');
501501
});
502502
});
503+
504+
it("After disabling & enabling of a button, while a mode is active, don't call disable on the draw layer", (done) => {
505+
let eventFired = '';
506+
507+
cy.toolbarButton('edit').click();
508+
509+
cy.window().then(({ map }) => {
510+
map.on('pm:drawend', ({ shape }) => {
511+
eventFired = shape;
512+
});
513+
map.pm.Toolbar.setButtonDisabled('drawText', true);
514+
map.pm.Toolbar.setButtonDisabled('drawText', false);
515+
});
516+
cy.toolbarButton('text').click();
517+
518+
cy.window().then(() => {
519+
expect(eventFired).to.equal('');
520+
done();
521+
});
522+
});
503523
});

demo/customcontrols.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ <h2>Custom Controls in the Toolbar</h2>
2828
</article>
2929
</div>
3030
<script src="https://unpkg.com/leaflet@latest/dist/leaflet.js"></script>
31-
<script src="../dist/leaflet-geoman.min.js"></script>
31+
<script src="../dist/leaflet-geoman.js"></script>
3232
<!-- You can change from the local source to the cdn: -->
33-
<!-- <script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.min.js"></script> -->
33+
<!-- <script src="https://unpkg.com/@geoman-io/leaflet-geoman-free@latest/dist/leaflet-geoman.js"></script> -->
3434
<script src="customcontrols.js"></script>
3535
</body>
3636
</html>

demo/demo-canvas.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const geoJsonData = {
114114
coordinates: [
115115
[
116116
[-0.15483856201171872, 51.527329038465936],
117-
[-0.16977310180664062, 51.51643437722083],
117+
[-0.1697731018066406, 51.51643437722083],
118118
[-0.15964508056640625, 51.50094238217541],
119119
[-0.13149261474609375, 51.5042549065934],
120120
[-0.11758804321289061, 51.518463972439385],

0 commit comments

Comments
 (0)