Skip to content
Snippets Groups Projects
Select Git revision
  • 86c399db70f87abf5a05de863e8323b51eb0179c
  • 3.9 default
  • develop
  • 6.0
  • 5.0
  • 4.0
  • scrutinizer-patch-4
  • scrutinizer-patch-3
  • scrutinizer-patch-2
  • scrutinizer-patch-1
  • 3.7
  • 3.8
  • 3.6
  • 3.9_backported
  • 3.8_backported
  • 3.7_backported
  • 3.5
  • 3.6_backported
  • 3.5_backported
  • 3.4
  • 3.3_backported
  • 6.0.4
  • 6.0.3
  • 5.0.7
  • 6.0.2
  • 6.0.1
  • 5.0.6
  • 6.0.0
  • 5.0.5
  • 6.0.0-rc
  • 5.0.4
  • 6.0.0-beta
  • 5.0.3
  • 4.0.6
  • 5.0.2
  • 5.0.1
  • 4.0.5
  • 5.0.0
  • 4.0.4
  • 5.0.0-rc2
  • 5.0.0-rc1
41 results

about.php

Blame
  • loading.js 1.46 KiB
    /* exported loadGraphs */
    /* globals PositionedVertex PositionedEdge UndirectedGraph */
    
    const WALK_SPEED = 5;
    const DRIVE_SPEED = 15;
    
    function dataToGraphs(data) {
      const verticesByName = new Map();
      const walkGraph = new UndirectedGraph();
      const driveGraph = new UndirectedGraph();
      for (const description of data.vertices) {
        const vertex = new PositionedVertex(description.name, description.position);
        verticesByName.set(description.name, vertex);
        walkGraph.addVertex(vertex);
        driveGraph.addVertex(vertex);
      }
      for (const description of data.edges) {
        const source = verticesByName.get(description.source);
        const destination = verticesByName.get(description.destination);
        if (walkGraph.getEdge(source, destination) === undefined) {
          const edge = new PositionedEdge(source, description.path, description.length / WALK_SPEED, destination);
          walkGraph.addEdge(source, edge, destination);
        }
        if (driveGraph.getEdge(source, destination) === undefined) {
          const edge = new PositionedEdge(source, description.path, description.length / DRIVE_SPEED, destination);
          driveGraph.addEdge(source, edge, destination);
        }
      }
      return {
        walkGraph,
        driveGraph,
      };
    }
    
    function loadGraphs(address, radius, success, error) {
      $.ajax({
        async: false,
        url: 'server/city.cgi',
        data: {
          address,
          radius,
        },
        dataType: 'json',
        success: (data) => {
          success(dataToGraphs(data));
        },
        error,
      });
    }