示例#1
0
 public function growAroundTile($index)
 {
     $this->freeIndexSearchIsRandom = true;
     $roundToBuild = 2;
     $map = $this->getMap();
     $position = new Tile($map->getAllTiles()[$index][self::COORDINATES][self::X], $map->getAllTiles()[$index][self::COORDINATES][self::Y]);
     $map->setTileDistance($index, self::COORDINATES);
     for ($round = self::DISTANCE; $round <= $roundToBuild; $round++) {
         $position->move(Directions::RIGHT_UP);
         foreach (Directions::getDirections() as $direction) {
             for ($step = 0; $step < $round; $step++) {
                 $tile = $position->move($direction);
                 if ($map->hasTile($tile)) {
                     if ($round == self::FIRST_ROUND) {
                         if ($map->isTileOnTheEdge($tile)) {
                             $newTileIndex = $map->getTileIndex($tile);
                             $map->setTileDistance($newTileIndex, self::DISTANCE);
                         }
                     }
                 } else {
                     $map->addTile($tile, $round);
                 }
             }
         }
     }
 }
示例#2
0
 public function __construct(Tile $position, $rounds)
 {
     $this->addTile($position);
     for ($round = 1; $round < $rounds; $round++) {
         $position->move(Directions::RIGHT_UP);
         foreach (Directions::getDirections() as $direction) {
             for ($step = 0; $step < $round; $step++) {
                 $this->addTile($position->move($direction), $round);
             }
         }
     }
 }
 $marker3->setPosition($org[0]['latitude'], $org[0]['longitude'], true);
 $marker3->setAnimation(Animation::DROP);
 $marker3->setOption('clickable', true);
 $marker3->setOption('flat', true);
 $marker3->setOptions(array('clickable' => true, 'flat' => true));
 $map->addMarker($marker);
 $marker4 = new Marker();
 $marker4->setPrefixJavascriptVariable('marker_two');
 $marker4->setPosition($des[0]['latitude'], $des[0]['longitude'], true);
 $marker4->setAnimation(Animation::DROP);
 $marker4->setOption('clickable', true);
 $marker4->setOption('flat', true);
 $marker4->setOptions(array('clickable' => true, 'flat' => true));
 $map->addMarker($marker4);
 // trying directions
 $directions = new Directions(new CurlHttpAdapter());
 $request = new DirectionsRequest();
 // Set your origin
 $request->setOrigin($marker3->getPosition(), true);
 // Set your destination
 $request->setDestination($marker4->getPosition(), true);
 $response = $directions->route($request);
 // Get the routes
 $routes = $response->getRoutes();
 // Iterate each routes
 foreach ($routes as $route) {
     // Get the bound
     $bound = $route->getBound();
     // Get the copyrights
     $copyrights = $route->getCopyrights();
     // Get the legs
function getMarker2($orglat, $orglong, $deslat, $deslong)
{
    //creating map
    $map = new Map();
    $map->setPrefixJavascriptVariable('map_');
    $map->setHtmlContainerId('map_canvas');
    $map->setAsync(false);
    $map->setAutoZoom(false);
    $map->setCenter(37.806381, -122.415468, true);
    $map->setMapOption('zoom', 16);
    $map->setBound(-2.1, -3.9, 2.6, 1.4, true, true);
    $map->setMapOption('mapTypeId', MapTypeId::ROADMAP);
    $map->setMapOption('mapTypeId', 'roadmap');
    $map->setMapOption('disableDefaultUI', true);
    $map->setMapOption('disableDoubleClickZoom', true);
    $map->setMapOptions(array('disableDefaultUI' => true, 'disableDoubleClickZoom' => true));
    $map->setStylesheetOption('width', '600px');
    $map->setStylesheetOption('height', '600px');
    $map->setStylesheetOptions(array('width' => '1000px', 'height' => '800px'));
    $map->setLanguage('en');
    //creating marker
    $marker3 = new Marker();
    $marker3->setPrefixJavascriptVariable('marker_');
    $marker3->setPosition($orglat, $orglong, true);
    $marker3->setAnimation(Animation::DROP);
    $marker3->setOption('clickable', true);
    $marker3->setOption('flat', true);
    $marker3->setOptions(array('clickable' => true, 'flat' => true));
    $map->addMarker($marker);
    $marker4 = new Marker();
    $marker4->setPrefixJavascriptVariable('marker_two');
    $marker4->setPosition($deslat, $deslong, true);
    $marker4->setAnimation(Animation::DROP);
    $marker4->setOption('clickable', true);
    $marker4->setOption('flat', true);
    $marker4->setOptions(array('clickable' => true, 'flat' => true));
    $map->addMarker($marker4);
    // trying directions
    $directions = new Directions(new CurlHttpAdapter());
    $request = new DirectionsRequest();
    // Set your origin
    $request->setOrigin($marker3->getPosition(), true);
    // Set your destination
    $request->setDestination($marker4->getPosition(), true);
    $response = $directions->route($request);
    // Get the routes
    $routes = $response->getRoutes();
    // Iterate each routes
    foreach ($routes as $route) {
        // Get the bound
        $bound = $route->getBound();
        // Get the copyrights
        $copyrights = $route->getCopyrights();
        // Get the legs
        $legs = $route->getLegs();
        // Get the summary
        //$summary = $route->getSummary();
        //print_r ($summary);
        foreach ($legs as $leg) {
            // Gets the distance
            $distance = $leg->getDistance();
            //$dist = (String)$distance;
            print_r($distance);
            // Gets the duration
            $duration = $leg->getDuration();
            print_r($duration);
            //summary
            //$summary = $leg->getSummary();
            //print_r ($summary);
            // Gets the directions steps.
            $steps = $leg->getSteps();
            // Iterate each step
            foreach ($steps as $step) {
                // Gets the encoded polyline.
                $encodedPolyline = $step->getEncodedPolyline();
                $map->addEncodedPolyline($encodedPolyline);
            }
        }
    }
    // end of 1st iteration. found time and distance
    //printing the map
    $mapHelper = new MapHelper();
    echo $mapHelper->renderHtmlContainer($map);
    echo $mapHelper->renderJavascripts($map);
}
示例#5
0
        echo json_encode($results);
    }
});
// PUT route
$app->put('/directions/:id', function ($id) use($app) {
    $request = (array) json_decode($app->request()->getBody());
    $name = $request['name'];
    $db = new Directions();
    $items = $db->update_direction($id, $name);
    if ($items) {
        // if successful, return the new object with the values
        $results = array('id' => $id, 'name' => $name);
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($results);
    } else {
        $app->response()->status(500);
    }
});
// DELETE route
$app->delete('/directions/:id', function ($id) use($app) {
    $request = (array) json_decode($app->request()->getBody());
    $db = new Directions();
    $items = $db->delete_direction($id);
    if ($items) {
        // if successful, just return the deleted item if it's needed on the client side
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($request);
    } else {
        $app->response()->status(500);
    }
});
示例#6
0
$app->put('/recipes/:id', function ($id) use($app) {
    $request = (array) json_decode($app->request()->getBody());
    $name = $request['name'];
    $db = new Recipes();
    $items = $db->update_recipe($id, $name);
    if ($items) {
        // if successful, return the new object with the values
        $results = array('id' => $id, 'name' => $name);
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($results);
    } else {
        $app->response()->status(500);
    }
});
// DELETE route
$app->delete('/recipes/:id', function ($id) use($app) {
    $request = (array) json_decode($app->request()->getBody());
    $db = new Recipes();
    $items = $db->delete_recipe($id);
    if ($items) {
        $db = new Ingredients();
        $items = $db->delete_ingredient_by_value($id);
        $db = new Directions();
        $items = $db->delete_direction_by_value($id);
        // if successful, just return the deleted item if it's needed on the client side
        $app->response()->header('Content-Type', 'application/json');
        echo json_encode($request);
    } else {
        $app->response()->status(500);
    }
});