Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Map] add polyline support #2340

Open
wants to merge 14 commits into
base: 2.x
Choose a base branch
from

Conversation

sblondeau
Copy link

@sblondeau sblondeau commented Nov 4, 2024

Q A
Bug fix? no
New feature? yes
Issues Fix #...
License MIT

Add polyline support to Map for Leaflet and GoogleMap (useful e.g. for itinerary drawing)

public function index(): Response
    {
        $map = (new Map('default'))
            ->center(new Point(45.7534031, 4.8295061))
            ->zoom(6)

            ->addPolyline(
                new Polyline(
                    title: 'my title',
                    points: [
                        new Point(48.8566, 2.3522),
                        new Point(45.7640, 4.8357),
                        new Point(43.2965, 5.3698),

                    ]
                )
            )
      ;          
        return $this->render('hom/index.html.twig', [
            'map' => $map,
        ]);;
    }

image

@sblondeau sblondeau requested a review from Kocal as a code owner November 4, 2024 21:19
@carsonbot carsonbot added Feature New Feature Status: Needs Review Needs to be reviewed labels Nov 4, 2024
Copy link

github-actions bot commented Nov 4, 2024

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
Autocomplete
controller.js 15.04 kB / 3.62 kB 15.02 kB0% / 3.6 kB0%
Map
abstract_map_controller.d.ts 3 kB / 741 B 3.86 kB+29% 📈 / 815 B+10% 📈
abstract_map_controller.js 1.88 kB / 610 B 2.32 kB+23% 📈 / 682 B+12% 📈
Map (Bridge Google)
map_controller.d.ts 2.07 kB / 729 B 2.38 kB+15% 📈 / 769 B+5% 📈
map_controller.js 7.07 kB / 1.67 kB 5.77 kB-18% 📉 / 1.4 kB-16% 📉
Map (Bridge Leaflet)
map_controller.d.ts 1.31 kB / 544 B Removed
map_controller.js 5.52 kB / 1.77 kB Removed

@WebMamba
Copy link
Collaborator

WebMamba commented Nov 4, 2024

Hey, thanks a lot for this PR @sblondeau! Could you please add more info about this new feature to your PR description? Some screenshots, details and what you trying to achieve! Thannnnnks 😁

@sblondeau sblondeau changed the title add polyline support [Map] add polyline support Nov 5, 2024
Copy link
Member

@Kocal Kocal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feature, I didn't even know that "polyline" existed :)

I've added some comments that must be resolved if we want to merge your work.

Also, a lot of CI checks are failing, can you take a look please? Thanks!

Comment on lines 136 to 147
You can add Polylines, which represents a path made by a series of `Point` instances
$myMap->addPolyline(new Polyline(
points: [
new Point(48.8566, 2.3522),
new Point(45.7640, 4.8357),
new Point(43.2965, 5.3698),
new Point(44.8378, -0.5792),
],
infoWindow: new InfoWindow(
content: 'A line passing through Paris, Lyon, Marseille, Bordeaux',
),
));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also move this section under Add Polygons please? Thanks :)

Suggested change
You can add Polylines, which represents a path made by a series of `Point` instances
$myMap->addPolyline(new Polyline(
points: [
new Point(48.8566, 2.3522),
new Point(45.7640, 4.8357),
new Point(43.2965, 5.3698),
new Point(44.8378, -0.5792),
],
infoWindow: new InfoWindow(
content: 'A line passing through Paris, Lyon, Marseille, Bordeaux',
),
));
You can add Polylines, which represents a path made by a series of ``Point`` instances::
$myMap->addPolyline(new Polyline(
points: [
new Point(48.8566, 2.3522),
new Point(45.7640, 4.8357),
new Point(43.2965, 5.3698),
new Point(44.8378, -0.5792),
],
infoWindow: new InfoWindow(
content: 'A line passing through Paris, Lyon, Marseille, Bordeaux',
),
));

Comment on lines 231 to 237
element.addListener('click', (event: any) => {
if (definition.autoClose) {
this.closeInfoWindowsExcept(infoWindow);
}
infoWindow.setPosition(event.latLng);
infoWindow.open(this.map);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this logic is the same for Polygon, maybe we can merge the two blocks together?

@@ -70,7 +76,7 @@ public function renderMap(

public function render(array $args = []): string
{
$map = array_intersect_key($args, ['map' => 0, 'markers' => 0, 'polygons' => 0, 'center' => 1, 'zoom' => 2]);
$map = array_intersect_key($args, ['map' => 0, 'markers' => 0, 'polygons' => 0, 'polylines' => 0, 'center' => 1, 'zoom' => 2]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is an issue here, I don't fully remember why it has been done like this, but values should be sequential 0, 1, 2, 3, 4, ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need here, as it's then using named arguments with the spread.

But it's a good idea at least to prevent future errors if we change to some array_reverse :)

@carsonbot carsonbot added Status: Needs Work Additional work is needed and removed Status: Needs Review Needs to be reviewed labels Nov 5, 2024
@Kocal Kocal added the Map label Nov 5, 2024
src/Map/CHANGELOG.md Outdated Show resolved Hide resolved
src/Map/src/Polyline.php Outdated Show resolved Hide resolved
src/Map/src/Polyline.php Outdated Show resolved Hide resolved
@carsonbot carsonbot added Status: Needs Review Needs to be reviewed and removed Status: Needs Work Additional work is needed labels Nov 9, 2024
@@ -15,7 +15,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this change (or see in another PR) to focus on one package :)

@sblondeau
Copy link
Author

Hello, I tried a lot of things but some tests (js ans php) failed and I do not understand why :(
If someone has some time to investigate...
Thanks :-)

@Kocal
Copy link
Member

Kocal commented Nov 11, 2024

Hi @sblondeau, where are stuck?

Please ensure to rebase your branch from the latest 2.x quite often, but also try to run some yarn scripts to easy your development:

yarn lint
yarn format
yarn workspaces foreach -Rp --from '{src/Map/assets,src/Map/src/Bridge/Google/assets,src/Map/src/Bridge/Leaflet/assets}' run build
yarn workspaces foreach -Rp --from '{src/Map/assets,src/Map/src/Bridge/Google/assets,src/Map/src/Bridge/Leaflet/assets}' run test

Also, please start to squash your commits, we don't want to see commits 1517fe1 (#2340) like this because it will spam the history for nothing (meaning, harder to blame if necessary).

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature Map Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants