Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 3d buildings #71

Open
bradcornford opened this issue Aug 18, 2016 · 0 comments
Open

Create 3d buildings #71

bradcornford opened this issue Aug 18, 2016 · 0 comments

Comments

@bradcornford
Copy link
Owner

I think I have manage to create something usefull :

Mapper.php:

/**
     * Add a new map 3d building.
     *
     * @param array $coordinates
     * @param array $bottomOptions
     * @param array $topOptions
     * @param array $wallsOptions
     * @param array $height
     *
     * @return self
     */
    public function building(array $coordinates = [], array $bottomOptions = [], array $topOptions = [], array $wallsOptions = [], $height = 0.1) {

        $i = 0;
        foreach($coordinates as $coord){
            $bottom[$i]['latitude'] = $coord['latitude'];
            $bottom[$i]['longitude'] = $coord['longitude'];

            $top[$i]['latitude'] = $coord['latitude'] + $height;
            $top[$i]['longitude'] = $coord['longitude'] + $height;

            $i++;
        }
        $i--;

        //bottom
        $this->polygon($bottom, $bottomOptions);

        //roof
        $this->polygon($top, $topOptions);

        //walls
        for($w = $i; $w >= 0; $w--){
            $z= $w - 1;
            if($w === 0) $z = $i;
            $this->polygon([$bottom[$w], $bottom[$z], $top[$z], $top[$w]], $wallsOptions);
        }

        return $this;
    }

Example:

Mapper::map(1, 1, ['zoom' => 8, 'center' => true]);

        $coordinates = [['latitude' => 1, 'longitude' => 1], ['latitude' => 3, 'longitude' => 1], ['latitude' => 3, 'longitude' => 3], ['latitude' => 1, 'longitude' => 3], ['latitude' => 0, 'longitude' => 1.2], ['latitude' => 0.5, 'longitude' => 1.5]];
        $bottomOptions = ['fillColor' => 'red', 'strokeColor' => 'red', 'strokeOpacity' => 0.5];
        $topOptions = ['fillColor' => 'blue', 'strokeColor' => 'blue', 'strokeWeight' => 5, 'strokeOpacity' => 1, 'fillOpacity' => 1];
        $wallsOptions = ['fillColor' => 'yellow', 'strokeColor' => 'yellow', 'strokeOpacity' => 0.1];
        $height = 0.5;

        Mapper::building($coordinates, $bottomOptions, $topOptions, $wallsOptions, $height);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant