2amigos / yii2-leaflet-extension

Yii 2 Extension library to display interactive maps with Leaflet .
http://yiiwheels.com
Other
30 stars 26 forks source link

Add getCenter() method to LatLngBounds Class #18

Closed gfargo closed 8 years ago

gfargo commented 8 years ago

Wrote a simple $bounds->getCenter() method for finding the center point within the LatLngBounds.php class :tada: Very useful when trying to find the center of a dynamic collection of LatLngs.

Note: The function itself is a basic port from the existing functionality in LatLngBounds.js - github.

PHPUnit Test

I attempted to write a PHPUnit test for the new function, placing it alongside the others used in troubleshooting LatLngBounds.php but I am still very much a beginner when it comes to writing unit tests.

Also fixes a few random PHP CodeSniffer errors in src/types/LatLngBounds.php. Not sure if I am applying the appropriate sniffer config.

gfargo commented 8 years ago

Realized the real potential behind $clientEvents and $clientOptions :sweat_smile: please forgive my ignorance

For anyone running into this in the future.. centering the map would be easily accomplished by adding a clientEvent. I found this page in the wiki to be very illuminating.

$leaflet = new LeafLet([
            'name'      => 'leafletMap',
            'center'    => $center, // set the $center latlng object
            'zoom'      => 13, // set zoom
            'clientEvents'  => [
                'load'        => new JsExpression(" leafletMap.DoSomething( with $whatever ) "),
                'otherEvent'  => new JsExpression(" more js stuff! ")
            ],
]);

Because of these methods there is no need to further extend the php side of things, just pipe all your stuff through $clientEvents[] and $clientOptions[].

Cheers & thanks for a stellar library :beers: