From 6492f6b68cfd4a8fcd758058a558a87e7144b42e Mon Sep 17 00:00:00 2001 From: David Molineus Date: Wed, 2 Jan 2019 13:39:08 +0100 Subject: [PATCH] Fix issue that popup methods are rendered twice (See #4). --- .../LeafletPHP/Encoder/UIEncoder.php | 2 -- tests/Encoder/UIEncoderTest.php | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/Encoder/UIEncoderTest.php diff --git a/src/Netzmacht/LeafletPHP/Encoder/UIEncoder.php b/src/Netzmacht/LeafletPHP/Encoder/UIEncoder.php index f30e268..37a47ac 100644 --- a/src/Netzmacht/LeafletPHP/Encoder/UIEncoder.php +++ b/src/Netzmacht/LeafletPHP/Encoder/UIEncoder.php @@ -77,8 +77,6 @@ public function encodePopup(Popup $popup, Encoder $encoder) $source ? (', ' . $encoder->encodeReference($source)) : '' ); - $buffer .= $this->encodeMethodCalls($popup->getMethodCalls(), $encoder); - return $buffer; } } diff --git a/tests/Encoder/UIEncoderTest.php b/tests/Encoder/UIEncoderTest.php new file mode 100644 index 0000000..c4b8bc6 --- /dev/null +++ b/tests/Encoder/UIEncoderTest.php @@ -0,0 +1,25 @@ +getBuilder(); + + $popup = new Popup('popup'); + $popup->on('add', (new AnonymousFunction())->addLine('console.log("add");')); + + $this->assertSame( + 'layers.popup = L.popup([]);' + . "\n" + . 'layers.popup.on("add", function() { console.log("add"); });', + $leaflet->encode($popup) + ); + } +}