Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 55098dbb

Přidáno uživatelem Tomáš Ballák před více než 4 roky(ů)

  • ID 55098dbb88feff1302dfdabf4c1c162a2f8444f2
  • Rodič fa91b0c1

Re #7857

Zobrazit rozdíly:

.gitignore
7 7
database/
8 8
dev-dump/
9 9
*.lock
10
.env
website/.env
1
# In all environments, the following files are loaded if they exist,
2
# the latter taking precedence over the former:
3
#
4
#  * .env                contains default values for the environment variables needed by the app
5
#  * .env.local          uncommitted file with local overrides
6
#  * .env.$APP_ENV       committed environment-specific defaults
7
#  * .env.$APP_ENV.local uncommitted environment-specific overrides
8
#
9
# Real environment variables win over .env files.
10
#
11
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
12
#
13
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
14
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
15

  
16
###> symfony/framework-bundle ###
17
APP_ENV=dev
18
APP_SECRET=ca5751564bbb9a0d75d412e020790283
19
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
20
#TRUSTED_HOSTS='^(localhost|example\.com)$'
21
###< symfony/framework-bundle ###
website/config/services.yaml
4 4
# Put parameters here that don't need to change on each machine where the app is deployed
5 5
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
6 6
parameters:
7
    databaseConnectionString: 'mongodb://root:root@database'
7 8

  
8 9
services:
9 10
    # default configuration for services in *this* file
10 11
    _defaults:
11 12
        autowire: true      # Automatically injects dependencies in your services.
12 13
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
14
        bind:
15
            $connectionString: '%databaseConnectionString%'
13 16

  
14 17
    # makes classes in src/ available to be used as services
15 18
    # this creates a service per class whose id is the fully-qualified class name
......
25 28

  
26 29
    # add more service definitions when explicit configuration is needed
27 30
    # please note that last definitions always *replace* previous ones
31

  
32
    App\OpenData\OpenDataManager: ~      
33
    App\OpenData\IOpenDataManager: '@App\OpenData\OpenDataManager'
website/public/js/zcu-heatmap.js
1
var mymap;
2

  
3

  
4
function initMap(x = 49.724, y = 13.352, zoom = 17) {
5

  
6
    mymap = L.map('heatmap').setView([x, y], zoom);
7

  
8
    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
9
        attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
10
        maxZoom: 19
11
    }).addTo(mymap);
12
    
13
    
14

  
15
}
16

  
17
function showHeatmap(route) {
18

  
19
    $.ajax({
20
        type: "POST",
21
        url: route, 
22
        success: function(result) {
23
            drawHeatmap(result);
24
        }
25
    });
26

  
27
}
28

  
29
function drawHeatmap(points) {
30
        
31
    // Flipped x and y
32
    points = points.map(function (p) { return [p['y'], p['x'], p['number']]; });
33

  
34
    L.heatLayer(points).addTo(mymap), draw = true;
35

  
36
}
37
            
38
            
39

  
40

  
website/src/Controller/HeatmapController.php
2 2

  
3 3
namespace App\Controller;
4 4

  
5
use App\Entity\OpenData;
6
use MongoDB\Driver\Query;
7
use MongoDB\Driver\Manager;
5
use App\OpenData\IOpenDataManager;
8 6
use Symfony\Component\Routing\Annotation\Route;
9 7
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10 8

  
......
13 11
     * @Route("/heatmap")
14 12
     */
15 13
    public function index() {
16
        $manager = new Manager(
17
            'mongodb://root:root@database'
18
        );
19

  
20
        $openData = $manager->executeQuery('open-data-db.KOLOBEZKY31102018', new Query([], []));
21
        $openData->setTypeMap([
22
            'array' => 'array',
23
            'document' => 'array',
24
            'root' => 'array',
25
        ]);
26

  
27
        return $this->render('heatmap.html.twig', [
28
            'open_data' => $openData->toArray(),
29
        ]);
14
        return $this->render('heatmap.html.twig');
30 15
    }
31 16

  
32 17
    /**
33
     * @Route("heatmap/opendata", name="opendata")
18
     * @Route("heatmap/opendata/{collectionName}", name="opendata")
34 19
     */
35
    public function opendata() {
36
        $manager = new Manager(
37
            'mongodb://root:root@database'
38
        );
39

  
40
        $openData = $manager->executeQuery('open-data-db.KOLOBEZKY31102018', new Query([], []));
41
        $openData->setTypeMap([
42
            'array' => 'array',
43
            'document' => 'array',
44
            'root' => 'array',
45
        ]);
46

  
47
        return $this->json($openData->toArray());
20
    public function opendata(IOpenDataManager $manager, $collectionName) {
21
        return $this->json($manager->getCollectionDataByName($collectionName));
48 22
    }
49 23
}
website/src/IOpenDataManager.php
1
<?php
2

  
3
namespace App\OpenData;
4

  
5
interface IOpenDataManager {
6
    public function getCollectionDataByName($name);
7
}
website/src/OpenDataManager.php
1
<?php
2

  
3
namespace App\OpenData;
4

  
5
use MongoDB\Driver\Query;
6
use MongoDB\Driver\Manager;
7

  
8
class OpenDataManager implements IOpenDataManager {
9
    private $manager;
10

  
11
    public function __construct() {
12
        $this->manager = new Manager(
13
            $_ENV['DATABASE_CONNECTION_STRING']
14
        );
15
    }
16

  
17
    public function getCollectionDataByName($name) {
18
        $openData = $this->manager->executeQuery($name, new Query([], []));
19

  
20
        $openData->setTypeMap([
21
            'array' => 'array',
22
            'document' => 'array',
23
            'root' => 'array',
24
        ]);
25

  
26
        return $openData->toArray();
27
    }
28
}
website/templates/heatmap.html.twig
24 24
    <script src="https://code.jquery.com/jquery-3.5.0.min.js" integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
25 25
    <script src="{{ asset('js/leaflet.js') }}"></script>
26 26
    <script src="{{ asset('js/leaflet-heat.js') }}"></script>
27

  
27
    <script src="{{ asset('js/zcu-heatmap.js') }}"></script>
28 28
    <script>
29 29

  
30
        $(document).ready(function() {
31
            
32
            var mymap = L.map('heatmap').setView([49.724, 13.352], 17);
33

  
34
            L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
35
                attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
36
                maxZoom: 19
37
            }).addTo(mymap);
38
            
39
            $.ajax({
40
                type: "POST",
41
                url: "{{ path('opendata') }}",
42
                success: function(result) {
43
                    heatmap(result);
44
                }
45
            });
46
        
47
            function heatmap(points) {
48
                
49
                points = points.map(function (p) { return [p['y'], p['x'], p['number']]; });
50

  
51
                var heat = L.heatLayer(points).addTo(mymap),
52
                    draw = true;
53

  
54
            }
55

  
56
        });
57

  
30
       initMap();
31
       showHeatmap("{{ path('opendata', {'collectionName':'open-data-db.KOLOBEZKY31102018'}) }}");
58 32

  
59 33
    </script>
60 34

  

Také k dispozici: Unified diff