diff --git a/README.md b/README.md index 9096cc8..258f0a6 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,12 @@ [![Build Status](https://travis-ci.org/bradcornford/Googlmapper.svg?branch=master)](https://travis-ci.org/bradcornford/Googlmapper) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/bradcornford/Googlmapper/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/bradcornford/Googlmapper/?branch=master) -Think of Googlmapper as an easy way to integrate Google Maps with Laravel 4, providing a variety of helpers to speed up the utilisation of mapping. These include: +### For Laravel 4.x, check [version 1.0.1](https://github.com/bradcornford/Googlmapper/tree/v1.0.1) + +Think of Googlmapper as an easy way to integrate Google Maps with Laravel, providing a variety of helpers to speed up the utilisation of mapping. These include: - `Mapper::map` +- `Mapper::location` - `Mapper::stretview` - `Mapper::marker` - `Mapper::informationWindow` @@ -22,7 +25,7 @@ Think of Googlmapper as an easy way to integrate Google Maps with Laravel 4, pro Begin by installing this package through Composer. Edit your project's `composer.json` file to require `cornford/googlmapper`. "require": { - "cornford/googlmapper": "1.*" + "cornford/googlmapper": "2.*" } Next, update Composer from the Terminal: @@ -35,11 +38,13 @@ Once this operation completes, the next step is to add the service provider. Ope The next step is to introduce the facade. Open `app/config/app.php`, and add a new item to the aliases array. - 'Mapper' => 'Cornford\Googlmapper\Facades\Mapper', + 'Mapper' => 'Cornford\Googlmapper\Facades\MapperFacade', + +Finally we need to introduce the configuration files into your application. -Finally we need to introduce the configuration files into your application/ + php artisan vendor:publish --provider="Cornford\\Googlmapper\\MapperServiceProvider" - php artisan config:publish cornford/googlmapper +You also need to set your Google API Key into the `GOOGLE_API_KEY` environment variable. To obtain an API key for your project, visit the [Google developers console](https://console.developers.google.com/). That's it! You're all set to go. @@ -54,11 +59,20 @@ You can now configure Googlmapper in a few simple steps. Open `app/config/packag - `user` - Use custom Google Maps for users logged into the Google service, e.g. false. - `marker` - Automatically add Google Maps marker for your maps initial location, e.g. true. - `center` - Automatically center Google Maps around the initial location, when false, Google Maps will automatically center the map, e.g. true. +- `locate` - Automatically center Google Maps around the users current location, when false, Google Maps will automatically center the map, e.g. true. - `zoom` - Set the default zoom level for Google Maps, e.g. 8. +- `scrollWheelZoom` - Set the default scroll wheel zoom Google Maps, e.g. true. +- `fullscreenControl` - Set the default fullscreen control for Google Maps, e.g. true. - `type` - Set the default map type for Google Maps, e.g. ROADMAP, SATELLITE, HYBRID, TERRAIN. - `ui` - Show the Google Maps default UI options, e.g. true. - `markers.icon` - Set the default marker icon, e.g. img/icon.png. - `markers.animation` - Set the default marker animation, e.g. NONE, DROP, BOUNCE. +- `cluster` - Set if map marker clusters should be used. +- `clusters.icon` - Display custom images for clusters using icon path. +- `clusters.grid` - The grid size of a cluster in pixels. +- `clusters.zoom` - The maximum zoom level that a marker can be part of a cluster. +- `clusters.center` - Whether the center of each cluster should be the average of all markers in the cluster. +- `clusters.size` - The minimum number of markers to be in a cluster before the markers are hidden and a count is shown. ## Usage @@ -69,6 +83,7 @@ It's really as simple as using the Mapper class in any Controller / Model / File This will give you access to - [Map](#map) +- [Location](#location) - [Streetview](#streetview) - [Marker](#marker) - [Information Window](#information-window) @@ -84,14 +99,38 @@ The `map` method allows a map to be created, with latitude, longitude and option Mapper::map(53.381128999999990000, -1.470085000000040000); Mapper::map(53.381128999999990000, -1.470085000000040000, ['zoom' => 15, 'center' => false, 'marker' => false, 'type' => 'HYBRID', 'overlay' => 'TRAFFIC']); - Mapper::map(53.381128999999990000, -1.470085000000040000, ['zoom' => 10, 'markers' => ['title' => 'My Location', 'Animation' => 'DROP']]); + Mapper::map(53.381128999999990000, -1.470085000000040000, ['zoom' => 10, 'markers' => ['title' => 'My Location', 'animation' => 'DROP']]); + Mapper::map(53.381128999999990000, -1.470085000000040000, ['zoom' => 10, 'markers' => ['title' => 'My Location', 'animation' => 'DROP'], 'cluster' => false]); + Mapper::map(53.381128999999990000, -1.470085000000040000, ['zoom' => 10, 'markers' => ['title' => 'My Location', 'animation' => 'DROP'], 'clusters' => ['size' => 10, 'center' => true, 'zoom' => 20]]); + +##### Map Events + +**Before Load** + +This event is fired before the map is loaded. + + Mapper::map(53.381128999999990000, -1.470085000000040000, ['eventBeforeLoad' => 'console.log("before load");']); + +**After Load** + +This event is fired after the map is loaded. + + Mapper::map(53.381128999999990000, -1.470085000000040000, ['eventAfterLoad' => 'console.log("after load");']); + +### Location + +The `location` method allows a location to be searched for with a string, returning a Location object with its latitude and longitude. + + Mapper::location('Sheffield'); + Mapper::location('Sheffield')->map(['zoom' => 15, 'center' => false, 'marker' => false, 'type' => 'HYBRID', 'overlay' => 'TRAFFIC']); + Mapper::location('Sheffield')->streetview(1, 1, ['ui' => false]); ### Streetview The `streetview` method allows a streetview map to be created, with latitude, longitude, heading, pitch and optional parameters for options. - Mapper::streetview(53.381128999999990000, -1.470085000000040000); - Mapper::streetview(53.381128999999990000, -1.470085000000040000, ['ui' => false]); + Mapper::streetview(53.381128999999990000, -1.470085000000040000, 1, 1); + Mapper::streetview(53.381128999999990000, -1.470085000000040000, 1, 1, ['ui' => false]); ### Marker @@ -101,6 +140,68 @@ The `marker` method allows a marker to be added to a map, with latitude, longitu Mapper::marker(53.381128999999990000, -1.470085000000040000, ['symbol' => 'circle', 'scale' => 1000]); Mapper::map(52.381128999999990000, 0.470085000000040000)->marker(53.381128999999990000, -1.470085000000040000, ['markers' => ['symbol' => 'circle', 'scale' => 1000, 'animation' => 'DROP']]); +#### Draggable Markers + +If you need draggable marker, you can add option draggable. + + Mapper::marker(53.381128999999990000, -1.470085000000040000, ['draggable' => true]); + +##### Draggable Events + +**Click** + +This event is fired when the marker icon was clicked. + + Mapper::marker(53.381128999999990000, -1.470085000000040000, ['draggable' => true, 'eventClick' => 'console.log("left click");']); + +**Right Click** + +This event is fired for a right click on the marker. + + Mapper::marker(53.381128999999990000, -1.470085000000040000, ['draggable' => true, 'eventRightClick' => 'console.log("right click");']); + +**Mouse Over** + +This event is fired when the mouse enters the area of the marker icon. + + Mapper::marker(53.381128999999990000, -1.470085000000040000, ['draggable' => true, 'eventMouseOver' => 'console.log("mouse over");']); + +**Mouse Down** + +This event is fired for a mouse down on the marker. + + Mapper::marker(53.381128999999990000, -1.470085000000040000, ['draggable' => true, 'eventMouseDown' => 'console.log("mouse down");']); + +**Mouse Up** + +This event is fired for a mouse up on the marker. + + Mapper::marker(53.381128999999990000, -1.470085000000040000, ['draggable' => true, 'eventMouseUp' => 'console.log("mouse up");']); + +**Mouse Out** + +This event is fired when the mouse leaves the area of the marker icon. + + Mapper::marker(53.381128999999990000, -1.470085000000040000, ['draggable' => true, 'eventMouseOut' => 'console.log("mouse out");']); + +**Drag** + +This event is repeatedly fired while the user drags the marker. + + Mapper::marker(53.381128999999990000, -1.470085000000040000, ['draggable' => true, 'eventDrag' => 'console.log("dragging");']); + +**Drag Start** + +This event is fired when the user starts dragging the marker. + + Mapper::marker(53.381128999999990000, -1.470085000000040000, ['draggable' => true, 'eventDragStart' => 'console.log("drag start");']); + +**Drag End** + +This event is fired when the user stops dragging the marker. + + Mapper::marker(53.381128999999990000, -1.470085000000040000, ['draggable' => true, 'eventDragEnd' => 'console.log("drag end");']); + ### Information Window The `informationWindow` method allows an information window to be added to to a map, with latitude, longitude, content, and optional parameters for options. @@ -150,4 +251,4 @@ The `render` method allows all maps to be rendered to the page, this method can ### License -Googlmapper is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) \ No newline at end of file +Googlmapper is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) diff --git a/composer.json b/composer.json index 07684b2..96a28f1 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ ], "require": { "php": ">=5.4.0", - "illuminate/support": "4.2.*" + "illuminate/view": "5.*", + "illuminate/support": "5.*" }, "require-dev": { "phpspec/phpspec": "2.0.*@dev", diff --git a/example.php b/example.php new file mode 100644 index 0000000..3afc3da --- /dev/null +++ b/example.php @@ -0,0 +1,57 @@ +addNamespace('googlmapper', [__DIR__ . '/src/views']); + +$engineResolver = new EngineResolver(); +$engineResolver->register( + 'blade', + function () { + return new CompilerEngine(new BladeCompiler(new Filesystem(), sys_get_temp_dir())); + } +); + +$viewFactory = new Factory($engineResolver, $fileViewFinder, new Dispatcher(new Container)); + +$config = include_once __DIR__ . '/src/config/config.php'; + +$mapper = new Mapper($viewFactory, $config); + +// Location +$mapper->location('Sheffield')->streetview(1, 1, ['ui' => false]); + +// Map +$mapper->map(53.3, -1.4, ['zoom' => 10, 'center' => false, 'markers' => ['title' => 'My Location', 'animation' => 'DROP']]); + +// Information window +$mapper->informationWindow(53.4, -1.5, 'Content'); +$mapper->informationWindow(52.4, -1.0, 'Content'); +$mapper->informationWindow(51.4, -0.5, 'Content'); + +// Render +print $mapper->render(); \ No newline at end of file diff --git a/spec/Cornford/Googlmapper/MapperSpec.php b/spec/Cornford/Googlmapper/MapperSpec.php index 17907ff..9ff101a 100644 --- a/spec/Cornford/Googlmapper/MapperSpec.php +++ b/spec/Cornford/Googlmapper/MapperSpec.php @@ -8,20 +8,28 @@ class MapperSpec extends ObjectBehavior { const STRING = 'test'; + const LOCATION = 'Sheffield, United Kingdom'; const INTEGER = 10; + const BOOLEAN = false; const REGION = 'GB'; const LANGUAGE = 'en-gb'; const TYPE = 'ROADMAP'; + const ANIMATION = 'NONE'; + public function let() { + $location = Mockery::mock('Cornford\Googlmapper\Models\Location'); + $view = Mockery::mock('Illuminate\View\Factory'); $view->shouldReceive('make')->andReturn($view); $view->shouldReceive('withView')->andReturn($view); $view->shouldReceive('withOptions')->andReturn($view); $view->shouldReceive('withItems')->andReturn($view); $view->shouldReceive('render')->andReturn(self::STRING); + $view->shouldReceive('location')->andReturn($location); + $this->beConstructedWith($view, ['enabled' => true, 'key' => self::STRING, 'region' => self::REGION, 'language' => self::LANGUAGE]); } @@ -37,9 +45,14 @@ public function it_throws_an_exception_with_incorrect_options() ->during('__construct', [$view]); } - public function it_can_render_map_code() + public function it_can_return_a_location_when_a_location_is_searched() { - $this->render()->shouldReturn(self::STRING); + $this->location(self::LOCATION)->shouldReturnAnInstanceOf('Cornford\Googlmapper\Models\Location'); + } + + public function it_can_throws_an_exception_when_a_blank_location_is_searched() + { + $this->shouldThrow('Cornford\Googlmapper\Exceptions\MapperArgumentException')->during('location', ['']); } public function it_can_be_enabled() @@ -77,7 +90,7 @@ public function it_can_set_and_get_language_option() $this->getLanguage()->shouldReturn(self::LANGUAGE); } - public function it_can_be_set_and_get_user_option() + public function it_can_set_and_get_user_option() { $this->enableUsers(); $this->getUser()->shouldReturn(true); @@ -85,7 +98,7 @@ public function it_can_be_set_and_get_user_option() $this->getUser()->shouldReturn(false); } - public function it_can_be_set_and_get_marker_option() + public function it_can_set_and_get_marker_option() { $this->enableMarkers(); $this->getMarker()->shouldReturn(true); @@ -93,7 +106,7 @@ public function it_can_be_set_and_get_marker_option() $this->getMarker()->shouldReturn(false); } - public function it_can_be_set_and_get_center_option() + public function it_can_set_and_get_center_option() { $this->enableCenter(); $this->getCenter()->shouldReturn(true); @@ -101,7 +114,15 @@ public function it_can_be_set_and_get_center_option() $this->getCenter()->shouldReturn(false); } - public function it_can_be_set_and_get_ui_option() + public function it_can_set_and_get_locate_option() + { + $this->enableLocate(); + $this->getLocate()->shouldReturn(true); + $this->disableLocate(); + $this->getLocate()->shouldReturn(false); + } + + public function it_can_set_and_get_ui_option() { $this->enableUi(); $this->getUi()->shouldReturn(false); @@ -127,6 +148,56 @@ public function it_can_set_and_get_tilt_option() $this->getTilt()->shouldReturn(self::INTEGER); } + public function it_can_set_and_get_icon_option() + { + $this->setIcon(self::STRING); + $this->getIcon()->shouldReturn(self::STRING); + } + + public function it_can_set_and_get_animation_option() + { + $this->setAnimation(self::ANIMATION); + $this->getAnimation()->shouldReturn(self::ANIMATION); + } + + public function it_can_set_and_get_cluster_option() + { + $this->enableCluster(); + $this->getCluster()->shouldReturn(true); + $this->disableCluster(); + $this->getCluster()->shouldReturn(false); + } + + public function it_can_set_and_get_clusters_icon_option() + { + $this->setClustersIcon(self::STRING); + $this->getClustersIcon()->shouldReturn(self::STRING); + } + + public function it_can_set_and_get_clusters_grid_option() + { + $this->setClustersGrid(self::INTEGER); + $this->getClustersGrid()->shouldReturn(self::INTEGER); + } + + public function it_can_set_and_get_clusters_zoom_option() + { + $this->setClustersZoom(self::INTEGER); + $this->getClustersZoom()->shouldReturn(self::INTEGER); + } + + public function it_can_set_and_get_clusters_center_option() + { + $this->setClustersCenter(self::BOOLEAN); + $this->getClustersCenter()->shouldReturn(self::BOOLEAN); + } + + public function it_can_set_and_get_clusters_size_option() + { + $this->setClustersSize(self::INTEGER); + $this->getClustersSize()->shouldReturn(self::INTEGER); + } + public function it_can_create_a_map() { $this->map(self::INTEGER, self::INTEGER)->shouldReturn($this); diff --git a/spec/Cornford/Googlmapper/Models/LocationSpec.php b/spec/Cornford/Googlmapper/Models/LocationSpec.php new file mode 100644 index 0000000..104dd61 --- /dev/null +++ b/spec/Cornford/Googlmapper/Models/LocationSpec.php @@ -0,0 +1,46 @@ +shouldReceive('map')->andReturn($mapper); + $mapper->shouldReceive('streetview')->andReturn($mapper); + + $this->beConstructedWith([ + 'mapper' => $mapper, + 'search' => self::STRING, + 'address' => self::STRING, + 'type' => self::STRING, + 'latitude' => self::INTEGER, + 'longitude' => self::INTEGER, + 'placeId' => self::STRING + ]); + } + + public function it_is_initializable() + { + $this->shouldHaveType('Cornford\Googlmapper\Models\Location'); + } + + public function it_can_create_a_map() + { + $this->map()->shouldReturnAnInstanceOf('Cornford\Googlmapper\Mapper'); + } + + public function it_can_create_a_streetview() + { + $this->streetview(self::INTEGER, self::INTEGER)->shouldReturnAnInstanceOf('Cornford\Googlmapper\Mapper'); + } + +} diff --git a/src/Cornford/Googlmapper/Contracts/MappingBaseInterface.php b/src/Cornford/Googlmapper/Contracts/MappingBaseInterface.php index c973630..cbb7016 100644 --- a/src/Cornford/Googlmapper/Contracts/MappingBaseInterface.php +++ b/src/Cornford/Googlmapper/Contracts/MappingBaseInterface.php @@ -1,5 +1,7 @@ view->make('googlmapper::mapper') ->withView($this->view) ->withOptions($this->getOptions()) - ->withItems(array_reverse($item > -1 ? $this->getItem($item) : $this->getItems()))->render(); + ->withItems($item > -1 ? [$item => $this->getItem($item)] : $this->getItems())->render(); + } + + /** + * Search for a location against Google Maps Api. + * + * @param string $location + * + * @return mixed + */ + protected function searchLocation($location) + { + $location = urlencode($location); + $request = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address={$location}&sensor=false"); + + return json_decode($request); + } + + /** + * Locate a location and return a Location instance. + * + * @param string $location + * + * @throws MapperArgumentException + * @throws MapperSearchException + * @throws MapperSearchResultException + * @throws MapperException + * + * @return Location + */ + public function location($location) + { + if (empty($location)) { + throw new MapperArgumentException('Invalid location search term provided.'); + } + + try { + $resultObject = $this->searchLocation($location); + } catch (Exception $exception) { + throw new MapperSearchException('Unable to perform location search, the error was: "' . $exception->getMessage() . '".'); + } + + if (!isset($resultObject->results) || count($resultObject->results) == 0) { + throw new MapperSearchResultException('No results found for the location search.'); + } + + if (!isset($resultObject->results[0]->formatted_address) || + !isset($resultObject->results[0]->address_components[0]->types[0]) || + !isset($resultObject->results[0]->geometry->location->lat) || + !isset($resultObject->results[0]->geometry->location->lng) || + !isset($resultObject->results[0]->place_id) + ) { + throw new MapperException('The location search return invalid result data.'); + } + + return new Location([ + 'mapper' => $this, + 'search' => $location, + 'address' => $resultObject->results[0]->formatted_address, + 'type' => $resultObject->results[0]->address_components[0]->types[0], + 'latitude' => $resultObject->results[0]->geometry->location->lat, + 'longitude' => $resultObject->results[0]->geometry->location->lng, + 'placeId' => $resultObject->results[0]->place_id, + ]); } /** @@ -126,13 +194,13 @@ public function marker($latitude, $longitude, array $options = []) public function informationWindow($latitude, $longitude, $content, array $options = []) { $items = $this->getItems(); - $parameters = $this->getOptions(); - $options = array_replace_recursive(['user' => $parameters['user']], $parameters['markers'], $options); - + if (empty($items)) { throw new MapperException('No map found to add a information window to.'); } + $parameters = $this->getOptions(); + $options = array_replace_recursive(['user' => $parameters['user']], ['markers' => $parameters['markers']], $options); $item = end($items); $item->marker($latitude, $longitude, array_replace_recursive($options, ['markers' => ['content' => $content]])); @@ -165,7 +233,7 @@ public function polyline(array $coordinates = [], array $options = []) $options = array_replace_recursive(['user' => $parameters['user']], $defaults, $options); if (empty($items)) { - throw new MapperException('No map found to add a marker to.'); + throw new MapperException('No map found to add a polyline to.'); } $item = end($items); @@ -201,7 +269,7 @@ public function polygon(array $coordinates = [], array $options = []) $options = array_replace_recursive(['user' => $parameters['user']], $defaults, $options); if (empty($items)) { - throw new MapperException('No map found to add a marker to.'); + throw new MapperException('No map found to add a polygon to.'); } $item = end($items); @@ -237,7 +305,7 @@ public function rectangle(array $coordinates = [], array $options = []) $options = array_replace_recursive(['user' => $parameters['user']], $defaults, $options); if (empty($items)) { - throw new MapperException('No map found to add a marker to.'); + throw new MapperException('No map found to add a rectangle to.'); } $item = end($items); @@ -274,7 +342,7 @@ public function circle(array $coordinates = [], array $options = []) $options = array_replace_recursive(['user' => $parameters['user']], $defaults, $options); if (empty($items)) { - throw new MapperException('No map found to add a marker to.'); + throw new MapperException('No map found to add a circle to.'); } $item = end($items); diff --git a/src/Cornford/Googlmapper/MapperBase.php b/src/Cornford/Googlmapper/MapperBase.php index e0b112f..a48da40 100644 --- a/src/Cornford/Googlmapper/MapperBase.php +++ b/src/Cornford/Googlmapper/MapperBase.php @@ -7,6 +7,8 @@ abstract class MapperBase implements MappingBaseInterface { + const ENABLED = true; + const REGION = 'GB'; const LANGUAGE = 'en-gb'; @@ -16,10 +18,23 @@ abstract class MapperBase implements MappingBaseInterface const TYPE_HYBRID = 'HYBRID'; const TYPE_TERRAIN = 'TERRAIN'; + const USER = false; + + const MARKER = true; + + const CENTER = true; + + const LOCATE = false; + const ZOOM = 8; + const SCROLL_WHEEL_ZOOM = true; + + const FULLSCREEN_CONTROL = true; const TILT = 90; + const UI = true; + const ANIMATION_NONE = 'NONE'; const ANIMATION_DROP = 'DROP'; const ANIMATION_BOUNCE = 'BOUNCE'; @@ -35,6 +50,16 @@ abstract class MapperBase implements MappingBaseInterface const SYMBOL_BACKWARD_OPEN_ARROW = 'BACKWARD_OPEN_ARROW'; const SYMBOL_FORWARD_OPEN_ARROW = 'FORWARD_OPEN_ARROW'; + const ICON = ''; + + const CLUSTER = true; + + const CLUSTERS_ICON = '//googlemaps.github.io/js-marker-clusterer/images/m'; + const CLUSTERS_GRID = 60; + const CLUSTERS_ZOOM = null; + const CLUSTERS_CENTER = false; + const CLUSTERS_SIZE = 2; + /** * View. * @@ -487,6 +512,13 @@ abstract class MapperBase implements MappingBaseInterface */ protected $center; + /** + * Locate users location. + * + * @var boolean + */ + protected $locate; + /** * Show map UI. * @@ -501,6 +533,20 @@ abstract class MapperBase implements MappingBaseInterface */ protected $zoom; + /** + * Map scroll wheel zoom. + * + * @var boolean + */ + protected $scrollWheelZoom; + + /** + * Map fullscreen zoom. + * + * @var boolean + */ + protected $fullscreenControl; + /** * Map type. * @@ -552,6 +598,48 @@ abstract class MapperBase implements MappingBaseInterface 'BOUNCE', ]; + /** + * Map marker cluster. + * + * @var boolean + */ + protected $cluster; + + /** + * Map marker clusters icon. + * + * @var array + */ + protected $clustersIcon; + + /** + * Map marker clusters grid. + * + * @var integer + */ + protected $clustersGrid; + + /** + * Map marker clusters zoom. + * + * @var integer|null + */ + protected $clustersZoom; + + /** + * Map marker clusters center. + * + * @var boolean + */ + protected $clustersCenter; + + /** + * Map marker clusters size. + * + * @var integer + */ + protected $clustersSize; + /** * Mapping items. * @@ -591,19 +679,28 @@ public function __construct(View $view, array $options = []) throw new MapperArgumentException('Language is required in ISO 639-1 code format.'); } - $this->setEnabled(isset($options['enabled']) ? $options['enabled'] : true); + $this->setEnabled(isset($options['enabled']) ? $options['enabled'] : self::ENABLED); $this->setKey($options['key']); $this->setRegion(isset($options['region']) ? $options['region'] : self::REGION); $this->setLanguage(isset($options['language']) ? $options['language'] : self::LANGUAGE); - $this->setUser(isset($options['user']) ? $options['user'] : false); - $this->setMarker(isset($options['marker']) ? $options['marker'] : true); - $this->setCenter(isset($options['centre']) ? $options['centre'] : true); + $this->setUser(isset($options['user']) ? $options['user'] : self::USER); + $this->setMarker(isset($options['marker']) ? $options['marker'] : self::MARKER); + $this->setCenter(isset($options['center']) ? $options['center'] : self::CENTER); + $this->setLocate(isset($options['locate']) ? $options['locate'] : self::LOCATE); $this->setZoom(isset($options['zoom']) ? $options['zoom'] : self::ZOOM); + $this->setScrollWheelZoom(isset($options['scrollWheelZoom']) ? $options['scrollWheelZoom'] : self::SCROLL_WHEEL_ZOOM); + $this->setFullscreenControl(isset($options['fullscreenControl']) ? $options['fullscreenControl'] : self::FULLSCREEN_CONTROL); $this->setType(isset($options['type']) ? $options['type'] : self::TYPE_ROADMAP); $this->setTilt(isset($options['tilt']) ? $options['tilt'] : self::TILT); - $this->setUi(isset($options['ui']) ? $options['ui'] : true); - $this->setIcon(isset($options['markers']['icon']) ? $options['markers']['icon'] : ''); + $this->setUi(isset($options['ui']) ? $options['ui'] : self::UI); + $this->setIcon(isset($options['markers']['icon']) ? $options['markers']['icon'] : self::ICON); $this->setAnimation(isset($options['markers']['animation']) ? $options['markers']['animation'] : self::ANIMATION_NONE); + $this->setCluster(isset($options['cluster']) ? $options['cluster'] : self::CLUSTER); + $this->setClustersIcon(isset($options['clusters']['icon']) ? $options['clusters']['icon'] : self::CLUSTERS_ICON); + $this->setClustersGrid(isset($options['clusters']['grid']) ? $options['clusters']['grid'] : self::CLUSTERS_GRID); + $this->setClustersZoom(isset($options['clusters']['zoom']) ? $options['clusters']['zoom'] : self::CLUSTERS_ZOOM); + $this->setClustersCenter(isset($options['clusters']['center']) ? $options['clusters']['center'] : self::CLUSTERS_CENTER); + $this->setClustersSize(isset($options['clusters']['size']) ? $options['clusters']['size'] : self::CLUSTERS_SIZE); } /** @@ -900,6 +997,54 @@ public function disableCenter() $this->setCenter(false); } + /** + * Set the map locate user status. + * + * @param boolean $value + * + * @throws MapperArgumentException + * + * @return void + */ + protected function setLocate($value) + { + if (!is_bool($value)) { + throw new MapperArgumentException('Invalid map locate setting.'); + } + + $this->locate = $value; + } + + /** + * Get the map locate user status. + * + * @return boolean + */ + public function getLocate() + { + return $this->locate; + } + + /** + * Enable locate user position on maps. + * + * @return void + */ + public function enableLocate() + { + $this->setLocate(true); + } + + /** + * Disable locate user position on maps. + * + * @return void + */ + public function disableLocate() + { + $this->setLocate(false); + } + /** * Set the map UI status. * @@ -980,6 +1125,62 @@ public function getZoom() return $this->zoom; } + /** + * Set map scroll wheel zoom. + * + * @param boolean $value + * + * @throws MapperArgumentException + * + * @return void + */ + public function setScrollWheelZoom($value) + { + if (!is_bool($value)) { + throw new MapperArgumentException('Mouse Wheel Zoom must be a boolean.'); + } + + $this->scrollWheelZoom = $value; + } + + /** + * Get map scroll wheel zoom. + * + * @return boolean + */ + public function getScrollWheelZoom() + { + return $this->scrollWheelZoom; + } + + /** + * Set map fullscreen control. + * + * @param boolean $value + * + * @throws MapperArgumentException + * + * @return void + */ + public function setFullscreenControl($value) + { + if (!is_bool($value)) { + throw new MapperArgumentException('Fullscreen control must be a boolean.'); + } + + $this->fullscreenControl = $value; + } + + /** + * Get map fullscreen control. + * + * @return boolean + */ + public function getFullscreenControl() + { + return $this->fullscreenControl; + } + /** * Set map type. * @@ -1092,6 +1293,194 @@ public function getAnimation() return $this->animation; } + /** + * Set cluster status. + * + * @param boolean $value + * + * @throws MapperArgumentException + * + * @return void + */ + protected function setCluster($value) + { + if (!is_bool($value)) { + throw new MapperArgumentException('Invalid map cluster setting.'); + } + + $this->cluster = $value; + } + + /** + * Get the cluster status. + * + * @return boolean + */ + public function getCluster() + { + return $this->cluster; + } + + /** + * Enable cluster. + * + * @return void + */ + public function enableCluster() + { + $this->setCluster(true); + } + + /** + * Disable cluster. + * + * @return void + */ + public function disableCluster() + { + $this->setCluster(false); + } + + /** + * Set map cluster icon. + * + * @param string $value + * + * @throws MapperArgumentException + * + * @return void + */ + public function setClustersIcon($value) + { + if (!is_string($value)) { + throw new MapperArgumentException('Invalid map clusters icon setting.'); + } + + $this->clustersIcon = $value; + } + + /** + * Get map clusters icon. + * + * @return string + */ + public function getClustersIcon() + { + return $this->clustersIcon; + } + + /** + * Set map cluster grid. + * + * @param integer $value + * + * @throws MapperArgumentException + * + * @return void + */ + public function setClustersGrid($value) + { + if (!is_integer($value)) { + throw new MapperArgumentException('Invalid map clusters grid setting.'); + } + + $this->clustersGrid = $value; + } + + /** + * Get map cluster grid. + * + * @return integer + */ + public function getClustersGrid() + { + return $this->clustersGrid; + } + + /** + * Set map cluster zoom. + * + * @param integer|null $value + * + * @throws MapperArgumentException + * + * @return void + */ + public function setClustersZoom($value) + { + if (!is_integer($value) && !is_null($value)) { + throw new MapperArgumentException('Invalid map clusters zoom setting.'); + } + + $this->clustersZoom = $value; + } + + /** + * Get map cluster grid. + * + * @return integer|null + */ + public function getClustersZoom() + { + return $this->clustersZoom; + } + + /** + * Set map cluster center. + * + * @param boolean $value + * + * @throws MapperArgumentException + * + * @return void + */ + public function setClustersCenter($value) + { + if (!is_bool($value)) { + throw new MapperArgumentException('Invalid map clusters center setting.'); + } + + $this->clustersCenter = $value; + } + + /** + * Get map cluster center. + * + * @return boolean + */ + public function getClustersCenter() + { + return $this->clustersCenter; + } + + /** + * Set map cluster size. + * + * @param integer $value + * + * @throws MapperArgumentException + * + * @return void + */ + public function setClustersSize($value) + { + if (!is_integer($value)) { + throw new MapperArgumentException('Invalid map clusters size setting.'); + } + + $this->clustersSize = $value; + } + + /** + * Get map cluster size. + * + * @return integer + */ + public function getClustersSize() + { + return $this->clustersSize; + } + /** * Get mapper options. * @@ -1107,7 +1496,10 @@ protected function getOptions() 'user' => $this->getUser(), 'marker' => $this->getMarker(), 'center' => $this->getCenter(), + 'locate' => $this->getLocate(), 'zoom' => $this->getZoom(), + 'scrollWheelZoom' => $this->getScrollWheelZoom(), + 'fullscreenControl' => $this->getFullscreenControl(), 'type' => $this->getType(), 'tilt' => $this->getTilt(), 'ui' => $this->getUi(), @@ -1119,7 +1511,15 @@ protected function getOptions() 'place' => '', 'animation' => $this->getAnimation(), 'symbol' => '', - ] + ], + 'cluster' => $this->getCluster(), + 'clusters' => [ + 'icon' => $this->getClustersIcon(), + 'grid' => $this->getClustersGrid(), + 'zoom' => $this->getClustersZoom(), + 'center' => $this->getClustersCenter(), + 'size' => $this->getClustersSize() + ], ]; } diff --git a/src/Cornford/Googlmapper/MapperServiceProvider.php b/src/Cornford/Googlmapper/MapperServiceProvider.php index 479a4e7..0320206 100644 --- a/src/Cornford/Googlmapper/MapperServiceProvider.php +++ b/src/Cornford/Googlmapper/MapperServiceProvider.php @@ -19,7 +19,15 @@ class MapperServiceProvider extends ServiceProvider { */ public function boot() { - $this->package('cornford/googlmapper'); + $this->loadViewsFrom(base_path('resources/views/cornford/googlmapper'), 'googlmapper'); + + $this->publishes( + [ + __DIR__ . '/../../config/config.php' => config_path('googlmapper.php'), + __DIR__ . '/../../views' => base_path('resources/views/cornford/googlmapper') + ], + 'googlmapper' + ); } /** @@ -29,13 +37,14 @@ public function boot() */ public function register() { + $configPath = __DIR__ . '/../../config/config.php'; + $this->mergeConfigFrom($configPath, 'googlmapper'); + $this->app['mapper'] = $this->app->share(function($app) { - $config = $app['config']->get('googlmapper::config'); - return new Mapper( $this->app->view, - $config + $app['config']->get('googlmapper') ); }); } diff --git a/src/Cornford/Googlmapper/Models/Location.php b/src/Cornford/Googlmapper/Models/Location.php new file mode 100644 index 0000000..e65a045 --- /dev/null +++ b/src/Cornford/Googlmapper/Models/Location.php @@ -0,0 +1,257 @@ +setMapper($parameters['mapper']); + $this->setSearch($parameters['search']); + $this->setAddress($parameters['address']); + $this->setType($parameters['type']); + $this->setLatitude($parameters['latitude']); + $this->setLongitude($parameters['longitude']); + $this->setPlaceId($parameters['placeId']); + } + + /** + * Get the mapper instance. + * + * @return Mapper + */ + protected function getMapper() + { + return self::$mapper; + } + + /** + * Set the mapper instance. + * + * @param Mapper $mapper + * + * @return void + */ + protected function setMapper(Mapper $mapper) + { + self::$mapper = $mapper; + } + + /** + * Get the locations search. + * + * @return string + */ + public function getSearch() + { + return $this->search; + } + + /** + * Set the locations search. + * + * @param string $search + * + * @return void + */ + protected function setSearch($search) + { + $this->search = $search; + } + + /** + * Get the locations address. + * + * @return string + */ + public function getAddress() + { + return $this->address; + } + + /** + * Set the locations address. + * + * @param string $address + * + * @return void + */ + protected function setAddress($address) + { + $this->address = $address; + } + + /** + * Get the locations type. + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Set the locations type. + * + * @param string $type + * + * @return void + */ + protected function setType($type) + { + $this->type = $type; + } + + /** + * Get the locations latitude. + * + * @return float + */ + public function getLatitude() + { + return $this->latitude; + } + + /** + * Set the locations latitude. + * + * @param float $latitude + * + * @return void + */ + protected function setLatitude($latitude) + { + $this->latitude = $latitude; + } + + /** + * Get the locations longitude. + * + * @return float + */ + public function getLongitude() + { + return $this->longitude; + } + + /** + * Set the locations longitude. + * + * @param float $longitude + * + * @return void + */ + protected function setLongitude($longitude) + { + $this->longitude = $longitude; + } + + /** + * Get the place id. + * + * @return string + * + * @return string + */ + public function getPlaceId() + { + return $this->placeId; + } + + /** + * Set the place id. + * + * @param string $placeId + * + * @return void + */ + protected function setPlaceId($placeId) + { + $this->placeId = $placeId; + } + + /** + * Create a new map from location. + * + * @param array $options + * + * @return Mapper + */ + public function map(array $options = []) + { + return self::$mapper->map($this->getLatitude(), $this->getLongitude(), $options); + } + + /** + * Create a new street view map from location. + * + * @param integer $heading + * @param integer $pitch + * @param array $options + * + * @return Mapper + */ + public function streetview($heading, $pitch, array $options = []) + { + return self::$mapper->streetview($this->getLatitude(), $this->getLongitude(), $heading, $pitch, $options); + } + +} diff --git a/src/Cornford/Googlmapper/Models/Marker.php b/src/Cornford/Googlmapper/Models/Marker.php index 8767978..70064f1 100644 --- a/src/Cornford/Googlmapper/Models/Marker.php +++ b/src/Cornford/Googlmapper/Models/Marker.php @@ -22,7 +22,7 @@ public function __construct(array $parameters = []) $this->options = $parameters; if (isset($parameters['markers'])) { - $this->options = array_replace_recursive($this->options, $parameters['markers']); + $this->options = array_replace_recursive($parameters['markers'], $this->options); } } diff --git a/src/config/config.php b/src/config/config.php index 01009ea..49721dc 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -20,7 +20,7 @@ | A Google API key to link Googlmapper to Google's API. | */ - 'key' => 'AIzaSyAtqWsq5Ai3GYv6dSa6311tZiYKlbYT4mw', + 'key' => env('GOOGLE_API_KEY', 'AIzaSyAtqWsq5Ai3GYv6dSa6311tZiYKlbYT4mw'), /* |-------------------------------------------------------------------------- @@ -74,6 +74,17 @@ */ 'center' => true, + /* + |-------------------------------------------------------------------------- + | Locate Users Location + |-------------------------------------------------------------------------- + | + | Automatically center the Googlmapper displayed map on the users current + | location. + | + */ + 'locate' => false, + /* |-------------------------------------------------------------------------- | Default Zoom @@ -84,6 +95,26 @@ */ 'zoom' => 8, + /* + |-------------------------------------------------------------------------- + | Scroll wheel Zoom + |-------------------------------------------------------------------------- + | + | Set if scroll wheel zoom should be used by Googlmapper. + | + */ + 'scrollWheelZoom' => true, + + /* + |-------------------------------------------------------------------------- + | Fullscreen Control + |-------------------------------------------------------------------------- + | + | Set if fullscreen control should be displayed by Googlmapper. + | + */ + 'fullscreenControl' => true, + /* |-------------------------------------------------------------------------- | Map Type @@ -136,4 +167,78 @@ ), + /* + |-------------------------------------------------------------------------- + | Map Marker Cluster + |-------------------------------------------------------------------------- + | + | Enable default Googlmapper map marker cluster. + | + */ + 'cluster' => true, + + /* + |-------------------------------------------------------------------------- + | Map Marker Cluster + |-------------------------------------------------------------------------- + | + | Set the default Googlmapper map marker cluster behaviour. + | + */ + 'clusters' => array ( + + /* + |-------------------------------------------------------------------------- + | Cluster Icon + |-------------------------------------------------------------------------- + | + | Display custom images for clusters using icon path. (Link to an image path) + | + */ + 'icon' => '//googlemaps.github.io/js-marker-clusterer/images/m', + + /* + |-------------------------------------------------------------------------- + | Cluster Size + |-------------------------------------------------------------------------- + | + | The grid size of a cluster in pixels. + | + */ + 'grid' => 60, + + /* + |-------------------------------------------------------------------------- + | Cluster Zoom + |-------------------------------------------------------------------------- + | + | The maximum zoom level that a marker can be part of a cluster. + | + */ + 'zoom' => null, + + /* + |-------------------------------------------------------------------------- + | Cluster Center + |-------------------------------------------------------------------------- + | + | Whether the center of each cluster should be the average of all markers + | in the cluster. + | + */ + 'center' => false, + + /* + |-------------------------------------------------------------------------- + | Cluster Size + |-------------------------------------------------------------------------- + | + | The minimum number of markers to be in a cluster before the markers are + | hidden and a count is shown. + | + */ + 'size' => 2 + + ), + ); diff --git a/src/views/circle.blade.php b/src/views/circle.blade.php index ce263b6..3ebd7f8 100644 --- a/src/views/circle.blade.php +++ b/src/views/circle.blade.php @@ -1,18 +1,22 @@ -var circleCoordinates_{{ $id }} = ( +var circleCoordinates_{!! $id !!} = ( @foreach ($options['coordinates'] as $key => $coordinate) - new google.maps.LatLng({{ $coordinate['latitude'] }}, {{ $coordinate['longitude'] }}) + new google.maps.LatLng({!! $coordinate['latitude'] !!}, {!! $coordinate['longitude'] !!}) @endforeach ); -var circle_{{ $id }} = new google.maps.Circle({ - strokeColor: '{{ $options['strokeColor'] }}', - strokeOpacity: {{ $options['strokeOpacity'] }}, - strokeWeight: {{ $options['strokeWeight'] }}, - fillColor: '{{ $options['fillColor'] }}', - fillOpacity: {{ $options['fillOpacity'] }}, - center: circleCoordinates_{{ $id }}, - radius: {{ $options['radius'] }}, - editable: {{ $options['editable'] ? 'true' : 'false' }} +var circle_{!! $id !!} = new google.maps.Circle({ + strokeColor: '{!! $options['strokeColor'] !!}', + strokeOpacity: {!! $options['strokeOpacity'] !!}, + strokeWeight: {!! $options['strokeWeight'] !!}, + fillColor: '{!! $options['fillColor'] !!}', + fillOpacity: {!! $options['fillOpacity'] !!}, + center: circleCoordinates_{!! $id !!}, + radius: {!! $options['radius'] !!}, + editable: {!! $options['editable'] ? 'true' : 'false' !!} }); -circle_{{ $id }}.setMap({{ $options['map'] }}); \ No newline at end of file +circle_{!! $id !!}.setMap({!! $options['map'] !!}); + +shapes.push({ + 'circle_{!! $id !!}': circle_{!! $id !!} +}); \ No newline at end of file diff --git a/src/views/map.blade.php b/src/views/map.blade.php index 2bc0d0c..bacd9d2 100644 --- a/src/views/map.blade.php +++ b/src/views/map.blade.php @@ -1,56 +1,98 @@ -
+ \ No newline at end of file diff --git a/src/views/mapper.blade.php b/src/views/mapper.blade.php index d3c4c60..c1a1040 100644 --- a/src/views/mapper.blade.php +++ b/src/views/mapper.blade.php @@ -1,8 +1,14 @@ - + + +@if ($options['cluster']) + + + +@endif @foreach ($items as $id => $item) - {{ $item->render($id, $view) }} + {!! $item->render($id, $view) !!} @endforeach diff --git a/src/views/marker.blade.php b/src/views/marker.blade.php index 47ebf5a..55c1441 100644 --- a/src/views/marker.blade.php +++ b/src/views/marker.blade.php @@ -1,8 +1,8 @@ @if ($options['user'] && $options['place']) - var service = new google.maps.places.PlacesService({{ $options['map'] }}); + var service = new google.maps.places.PlacesService({!! $options['map'] !!}); var request = { - placeId: '{{ $options['place'] }}' + placeId: '{!! $options['place'] !!}' }; service.getDetails(request, function(placeResult, status) { @@ -13,41 +13,47 @@ @endif -var markerPosition_{{ $id }} = new google.maps.LatLng({{ $options['latitude'] }}, {{ $options['longitude'] }}); +var markerPosition_{!! $id !!} = new google.maps.LatLng({!! $options['latitude'] !!}, {!! $options['longitude'] !!}); -var marker_{{ $id }} = new google.maps.Marker({ - position: markerPosition_{{ $id }}, +var marker_{!! $id !!} = new google.maps.Marker({ + position: markerPosition_{!! $id !!}, @if ($options['user'] && $options['place']) place: { - placeId: '{{ $options['place'] }}', - location: { lat: {{ $options['latitude'] }}, lng: {{ $options['longitude'] }} } + placeId: '{!! $options['place'] !!}', + location: { lat: {!! $options['latitude'] !!}, lng: {!! $options['longitude'] !!} } }, attribution: { source: document.title, webUrl: document.URL }, @endif - title: '{{ $options['title'] }}', - animation: @if (empty($options['animation']) || $options['animation'] == 'NONE') '' @else google.maps.Animation.{{ $options['animation'] }} @endif, + + @if (isset($options['draggable']) && $options['draggable'] == true) + draggable:true, + @endif + + title: {!! json_encode($options['title']) !!}, + animation: @if (empty($options['animation']) || $options['animation'] == 'NONE') '' @else google.maps.Animation.{!! $options['animation'] !!} @endif, @if ($options['symbol']) icon: { - path: google.maps.SymbolPath.{{ $options['symbol'] }}, - scale: {{ $options['scale'] }} + path: google.maps.SymbolPath.{!! $options['symbol'] !!}, + scale: {!! $options['scale'] !!} } @else - icon: '{{ $options['icon'] }}' + icon: '{!! $options['icon'] !!}' @endif }); -bounds.extend(marker_{{ $id }}.position); +bounds.extend(marker_{!! $id !!}.position); -marker_{{ $id }}.setMap({{ $options['map'] }}); +marker_{!! $id !!}.setMap({!! $options['map'] !!}); +markers.push(marker_{!! $id !!}); @if ($options['user'] && $options['place']) - marker_{{ $id }}.addListener('click', function() { + marker_{!! $id !!}.addListener('click', function() { infowindow.setContent('' + placeResult.name + ''); - infowindow.open({{ $options['map'] }}, this); + infowindow.open({!! $options['map'] !!}, this); }); }); @@ -55,14 +61,26 @@ @if (!empty($options['content'])) - var infowindow_{{ $id }} = new google.maps.InfoWindow({ - content: '{{ $options['content'] }}' + var infowindow_{!! $id !!} = new google.maps.InfoWindow({ + content: {!! json_encode($options['content']) !!} + }); + + google.maps.event.addListener(marker_{!! $id !!}, 'click', function() { + infowindow_{!! $id !!}.open({!! $options['map'] !!}, marker_{!! $id !!}); }); - google.maps.event.addListener(marker_{{ $id }}, 'click', function() { - infowindow_{{ $id }}.open({{ $options['map'] }}, marker_{{ $id }}); + @endif + +@endif + +@foreach (['eventClick', 'eventRightClick', 'eventMouseOver', 'eventMouseDown', 'eventMouseUp', 'eventMouseOut', 'eventDrag', 'eventDragStart', 'eventDragEnd'] as $event) + + @if (isset($options[$event])) + + google.maps.event.addListener(marker_{!! $id !!}, '{!! str_replace('event', '', strtolower($event)) !!}', function (event) { + {!! $options[$event] !!} }); @endif -@endif \ No newline at end of file +@endforeach diff --git a/src/views/overlay.blade.php b/src/views/overlay.blade.php index d53bb66..da22bbc 100644 --- a/src/views/overlay.blade.php +++ b/src/views/overlay.blade.php @@ -1,12 +1,12 @@ -var overlayCoordinates_{{ $id }} = new google.maps.LatLngBounds( +var overlayCoordinates_{!! $id !!} = new google.maps.LatLngBounds( @foreach ($options['coordinates'] as $coordinate) - new google.maps.LatLng({{ $coordinate['latitude'] }}, {{ $coordinate['longitude'] }}), + new google.maps.LatLng({!! $coordinate['latitude'] !!}, {!! $coordinate['longitude'] !!}), @endforeach ); -overlay_{{ $id }} = new google.maps.GroundOverlay( - '{{ $options['image'] }}', - overlayCoordinates_{{ $id }} +overlay_{!! $id !!} = new google.maps.GroundOverlay( + '{!! $options['image'] !!}', + overlayCoordinates_{!! $id !!} ); -overlay_{{ $id }}.setMap({{ $options['map'] }}); +overlay_{!! $id !!}.setMap({!! $options['map'] !!}); diff --git a/src/views/polygon.blade.php b/src/views/polygon.blade.php index fa77fc3..3c7030c 100644 --- a/src/views/polygon.blade.php +++ b/src/views/polygon.blade.php @@ -1,17 +1,21 @@ -var polygonCoordinates_{{ $id }} = [ +var polygonCoordinates_{!! $id !!} = [ @foreach ($options['coordinates'] as $coordinate) - new google.maps.LatLng({{ $coordinate['latitude'] }}, {{ $coordinate['longitude'] }}), + new google.maps.LatLng({!! $coordinate['latitude'] !!}, {!! $coordinate['longitude'] !!}), @endforeach ]; -var polygon_{{ $id }} = new google.maps.Polygon({ - paths: polygonCoordinates_{{ $id }}, - strokeColor: '{{ $options['strokeColor'] }}', - strokeOpacity: {{ $options['strokeOpacity'] }}, - strokeWeight: {{ $options['strokeWeight'] }}, - fillColor: '{{ $options['fillColor'] }}', - fillOpacity: {{ $options['fillOpacity'] }}, - editable: {{ $options['editable'] ? 'true' : 'false' }} +var polygon_{!! $id !!} = new google.maps.Polygon({ + paths: polygonCoordinates_{!! $id !!}, + strokeColor: '{!! $options['strokeColor'] !!}', + strokeOpacity: {!! $options['strokeOpacity'] !!}, + strokeWeight: {!! $options['strokeWeight'] !!}, + fillColor: '{!! $options['fillColor'] !!}', + fillOpacity: {!! $options['fillOpacity'] !!}, + editable: {!! $options['editable'] ? 'true' : 'false' !!} }); -polygon_{{ $id }}.setMap({{ $options['map'] }}); +polygon_{!! $id !!}.setMap({!! $options['map'] !!}); + +shapes.push({ + 'polygon_{!! $id !!}': polygon_{!! $id !!} +}); \ No newline at end of file diff --git a/src/views/polyline.blade.php b/src/views/polyline.blade.php index 4203904..1b4b5e9 100644 --- a/src/views/polyline.blade.php +++ b/src/views/polyline.blade.php @@ -1,16 +1,20 @@ -var polylineCoordinates_{{ $id }} = [ +var polylineCoordinates_{!! $id !!} = [ @foreach ($options['coordinates'] as $coordinate) - new google.maps.LatLng({{ $coordinate['latitude'] }}, {{ $coordinate['longitude'] }}), + new google.maps.LatLng({!! $coordinate['latitude'] !!}, {!! $coordinate['longitude'] !!}), @endforeach ]; -var polyline_{{ $id }} = new google.maps.Polyline({ - path: polylineCoordinates_{{ $id }}, - geodesic: {{ $options['strokeColor'] ? 'true' : 'false' }}, - strokeColor: '{{ $options['strokeColor'] }}', - strokeOpacity: {{ $options['strokeOpacity'] }}, - strokeWeight: {{ $options['strokeWeight'] }}, - editable: {{ $options['editable'] ? 'true' : 'false' }} +var polyline_{!! $id !!} = new google.maps.Polyline({ + path: polylineCoordinates_{!! $id !!}, + geodesic: {!! $options['strokeColor'] ? 'true' : 'false' !!}, + strokeColor: '{!! $options['strokeColor'] !!}', + strokeOpacity: {!! $options['strokeOpacity'] !!}, + strokeWeight: {!! $options['strokeWeight'] !!}, + editable: {!! $options['editable'] ? 'true' : 'false' !!} }); -polyline_{{ $id }}.setMap({{ $options['map'] }}); \ No newline at end of file +polyline_{!! $id !!}.setMap({!! $options['map'] !!}); + +shapes.push({ + 'polyline_{!! $id !!}': polyline_{!! $id !!} +}); \ No newline at end of file diff --git a/src/views/rectangle.blade.php b/src/views/rectangle.blade.php index c8c2119..1f354e3 100644 --- a/src/views/rectangle.blade.php +++ b/src/views/rectangle.blade.php @@ -1,17 +1,21 @@ -var rectangleCoordinates_{{ $id }} = new google.maps.LatLngBounds( +var rectangleCoordinates_{!! $id !!} = new google.maps.LatLngBounds( @foreach ($options['coordinates'] as $key => $coordinate) - new google.maps.LatLng({{ $coordinate['latitude'] }}, {{ $coordinate['longitude'] }})@if (count($options['coordinates']) - 1 > $key), @endif + new google.maps.LatLng({!! $coordinate['latitude'] !!}, {!! $coordinate['longitude'] !!})@if (count($options['coordinates']) - 1 > $key), @endif @endforeach ); -var rectangle_{{ $id }} = new google.maps.Rectangle({ - strokeColor: '{{ $options['strokeColor'] }}', - strokeOpacity: {{ $options['strokeOpacity'] }}, - strokeWeight: {{ $options['strokeWeight'] }}, - fillColor: '{{ $options['fillColor'] }}', - fillOpacity: {{ $options['fillOpacity'] }}, - bounds: rectangleCoordinates_{{ $id }}, - editable: {{ $options['editable'] ? 'true' : 'false' }} +var rectangle_{!! $id !!} = new google.maps.Rectangle({ + strokeColor: '{!! $options['strokeColor'] !!}', + strokeOpacity: {!! $options['strokeOpacity'] !!}, + strokeWeight: {!! $options['strokeWeight'] !!}, + fillColor: '{!! $options['fillColor'] !!}', + fillOpacity: {!! $options['fillOpacity'] !!}, + bounds: rectangleCoordinates_{!! $id !!}, + editable: {!! $options['editable'] ? 'true' : 'false' !!} }); -rectangle_{{ $id }}.setMap({{ $options['map'] }}); +rectangle_{!! $id !!}.setMap({!! $options['map'] !!}); + +shapes.push({ + 'rectangle_{!! $id !!}': rectangle_{!! $id !!} +}); \ No newline at end of file diff --git a/src/views/streetview.blade.php b/src/views/streetview.blade.php index 55a4c62..94d3170 100644 --- a/src/views/streetview.blade.php +++ b/src/views/streetview.blade.php @@ -1,35 +1,35 @@ - + \ No newline at end of file