Skip to content

Commit 8fcbaee

Browse files
committed
added support for cartodb.com
1 parent 199f811 commit 8fcbaee

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/Adapters/Cartodb.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Embed\Adapters;
4+
5+
use Embed\Request;
6+
use Embed\Utils;
7+
8+
/**
9+
* Adapter to get the embed code from cartodb.
10+
*/
11+
class Cartodb extends Webpage implements AdapterInterface
12+
{
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
public static function check(Request $request)
17+
{
18+
return $request->isValid() && $request->match([
19+
'https://*.cartodb.com/viz/*/public_map',
20+
]);
21+
}
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function getCode()
27+
{
28+
$this->width = null;
29+
$this->height = 520;
30+
31+
$url = $this->request->createUrl()->withDirectoryPosition(2, 'embed_map')->getUrl();
32+
33+
return Utils::iframe($url, '100%', $this->height);
34+
}
35+
}

tests/CartodbTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
class CartodbTest extends TestCaseBase
4+
{
5+
public function testOne()
6+
{
7+
$this->assertEmbed(
8+
'https://porcentua26j.cartodb.com/viz/ab0f51e6-3c16-11e6-b12e-0e5db1731f59',
9+
[
10+
'title' => 'Resultados 26J / 20Dj',
11+
'height' => 520,
12+
'type' => 'rich',
13+
'code' => '<iframe src="https://porcentua26j.cartodb.com/viz/ab0f51e6-3c16-11e6-b12e-0e5db1731f59/embed_map" frameborder="0" allowTransparency="true" style="border:none;overflow:hidden;width:100%;height:520px;"></iframe>',
14+
'providerName' => 'CartoDB',
15+
]
16+
);
17+
}
18+
}

0 commit comments

Comments
 (0)