Skip to content

Commit 4a65595

Browse files
committed
feature #1937 [Map] Create Map component (Kocal)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Map] Create Map component | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Issues | Fix #38 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Hi :) This PR is a proposal for #38 a replacement for #39. Symfony UX Map is a new Symfony UX component that makes it easy to create, customize and use interactive JavaScript maps. The package ships with: - a simple and generic way to create a map, with markers and info-windows - two Bridge, [Leaflet](https://leafletjs.com/index.html) and [Google Maps](https://developers.google.com/maps/documentation/javascript) - a way to define provider-specific options - a nice and fluent API - Flex recipes are also ready: symfony/recipes#1329 # Example ## Bridge configuration ```env # .env UX_MAP_DSN=leaflet://default ``` ```yaml # config/packages/ux_map.yaml ux_map: renderer: '%env(UX_MAP_DSN)%' ``` ## Map creation An example to render a map, custom center and zoom, some markers and info windows: ```php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; use Symfony\UX\Map\InfoWindow; use Symfony\UX\Map\MapFactoryInterface; use Symfony\UX\Map\Marker; use Symfony\UX\Map\Point; final class ContactController extends AbstractController { #[Route('/contact')] public function __invoke(): Response { // 1. Create a new map instance $myMap = (new Map()); ->center(new Point(46.903354, 1.888334)) ->zoom(6) ; // 2. You can add markers, with an optional info window $myMap ->addMarker(new Marker( position: new Point(48.8566, 2.3522), title: 'Paris' )) ->addMarker(new Marker( position: new Point(45.7640, 4.8357), title: 'Lyon', // With an info window infoWindow: new InfoWindow( headerContent: '<b>Lyon</b>', content: 'The French town in the historic Rhône-Alpes region, located at the junction of the Rhône and Saône rivers.' ) )); // 3. And inject the map in your template to render it return $this->render('contact/index.html.twig', [ 'my_map' => $myMap, ]); } } ``` ## Map rendering You must call `render_map(map)` to render the map: ```twig {{ render_map(map, { style: 'height: 700px; width: 1024px; margin: 10px' }) }} ``` It gives you this interactive Leaflet map: <img width="1524" alt="image" src="https://github.com/user-attachments/assets/cd0f64f3-5bf2-45c6-8b8d-8ad23c6ce183"> Commits ------- 212e61d [Map] Create Map component
2 parents 38022b0 + 212e61d commit 4a65595

File tree

115 files changed

+5151
-9
lines changed

Some content is hidden

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

115 files changed

+5151
-9
lines changed

.github/build-packages.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Symfony\Component\Finder\Finder;
1010

1111
$finder = (new Finder())
12-
->in(__DIR__.'/../src/*/')
12+
->in([__DIR__.'/../src/*/', __DIR__.'/../src/*/src/Bridge/*/'])
1313
->depth(0)
1414
->name('composer.json')
1515
;
@@ -44,6 +44,18 @@
4444
$key = isset($packageData['require']['symfony/stimulus-bundle']) ? 'require' : 'require-dev';
4545
$packageData[$key]['symfony/stimulus-bundle'] = '@dev';
4646
}
47+
48+
if (isset($packageData['require']['symfony/ux-map'])
49+
|| isset($packageData['require-dev']['symfony/ux-map'])
50+
) {
51+
$repositories[] = [
52+
'type' => 'path',
53+
'url' => '../../../',
54+
];
55+
$key = isset($packageData['require']['symfony/ux-map']) ? 'require' : 'require-dev';
56+
$packageData[$key]['symfony/ux-map'] = '@dev';
57+
}
58+
4759
if ($repositories) {
4860
$packageData['repositories'] = $repositories;
4961
}

.github/workflows/test.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171

7272
- id: components
7373
run: |
74-
components=$(tree src -J -d -L 1 | jq -c '.[0].contents | map(.name)')
74+
components=$(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*" -printf '%h\n' | jq -R -s -c 'split("\n")[:-1] | map(. | sub("^src/";"")) | sort')
7575
echo "$components"
7676
echo "components=$components" >> $GITHUB_OUTPUT
7777
@@ -89,6 +89,12 @@ jobs:
8989
dependency-version: 'highest'
9090
component: ${{ fromJson(needs.tests-php-components.outputs.components )}}
9191
exclude:
92+
- component: Map # does not support PHP 8.1
93+
php-version: '8.1'
94+
- component: Map/src/Bridge/Google # does not support PHP 8.1
95+
php-version: '8.1'
96+
- component: Map/src/Bridge/Leaflet # does not support PHP 8.1
97+
php-version: '8.1'
9298
- component: Swup # has no tests
9399
- component: Turbo # has its own workflow (test-turbo.yml)
94100
- component: Typed # has no tests

bin/build_javascript.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const files = [
2121
// custom handling for StimulusBundle
2222
'src/StimulusBundle/assets/src/loader.ts',
2323
'src/StimulusBundle/assets/src/controllers.ts',
24+
// custom handling for Bridge
25+
...glob.sync('src/*/src/Bridge/*/assets/src/*controller.ts'),
2426
...glob.sync('src/*/assets/src/*controller.ts'),
2527
];
2628

biome.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
{
22
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
33
"files": {
4-
"include": ["src/*/assets/src/**", "src/*/assets/test/**", "src/*/*.json", "src/*/*/md", "*.json", "*.md"],
4+
"include": [
5+
"*.json",
6+
"*.md",
7+
"src/*/*.json",
8+
"src/*/*/md",
9+
"src/*/assets/src/**",
10+
"src/*/assets/test/**",
11+
"src/*/src/Bridge/*.json",
12+
"src/*/src/Bridge/*.md",
13+
"src/*/src/Bridge/*/assets/src/**",
14+
"src/*/src/Bridge/*/assets/test/**"
15+
],
516
"ignore": ["**/composer.json", "**/vendor", "**/node_modules"]
617
},
718
"linter": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
3-
"workspaces": ["src/*/assets"],
3+
"workspaces": ["src/*/assets", "src/*/src/Bridge/*/assets"],
44
"scripts": {
55
"build": "node bin/build_javascript.js && node bin/build_styles.js",
66
"test": "bin/run-vitest-all.sh",

rollup.config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ const wildcardExternalsPlugin = (peerDependencies) => ({
4646
const moveTypescriptDeclarationsPlugin = (packagePath) => ({
4747
name: 'move-ts-declarations',
4848
writeBundle: async () => {
49-
const files = glob.sync(path.join(packagePath, 'dist', '*', 'assets', 'src', '**/*.d.ts'));
49+
const isBridge = packagePath.includes('src/Bridge');
50+
const globPattern = isBridge
51+
? path.join(packagePath, 'dist', packagePath.replace(/^src\//, ''), '**/*.d.ts')
52+
: path.join(packagePath, 'dist', '*', 'assets', 'src', '**/*.d.ts')
53+
const files = glob.sync(globPattern);
5054
files.forEach((file) => {
51-
// a bit odd, but remove first 7 directories, which will leave
55+
// a bit odd, but remove first 7 or 13 directories, which will leave
5256
// only the relative path to the file
53-
const relativePath = file.split('/').slice(7).join('/');
57+
const relativePath = file.split('/').slice(isBridge ? 13 : 7).join('/');
5458

5559
const targetFile = path.join(packagePath, 'dist', relativePath);
5660
if (!fs.existsSync(path.dirname(targetFile))) {

src/Map/.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/.symfony.bundle.yaml export-ignore
4+
/phpunit.xml.dist export-ignore
5+
/assets/src export-ignore
6+
/assets/test export-ignore
7+
/assets/vitest.config.js export-ignore
8+
/tests export-ignore

src/Map/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor
2+
composer.lock
3+
.phpunit.result.cache

src/Map/.symfony.bundle.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
branches: ["2.x"]
2+
maintained_branches: ["2.x"]
3+
doc_dir: "doc"

src/Map/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CHANGELOG
2+
3+
## Unreleased
4+
5+
- Component added

0 commit comments

Comments
 (0)