diff --git a/resources/views/polyline.blade.php b/resources/views/polyline.blade.php index 0726191..09a4472 100644 --- a/resources/views/polyline.blade.php +++ b/resources/views/polyline.blade.php @@ -19,6 +19,21 @@ 'polyline_{!! $id !!}': polyline_{!! $id !!} }); +google.maps.event.addListener(polyline_{!! $id !!}, 'click', function(event) { + + @if (isset($options['autoClose']) && $options['autoClose']) + + for (var i = 0; i < infowindows.length; i++) { + infowindows[i].close(); + } + + @endif + + infowindow_{!! $id+3 !!}.open({!! $options['map'] !!}, marker_{!! $id+3 !!}); + infowindow_{!! $id+3 !!}.setPosition(event.latLng); + +}); + @foreach (['eventClick', 'eventDblClick', 'eventRightClick', 'eventMouseOver', 'eventMouseDown', 'eventMouseUp', 'eventMouseOut', 'eventDrag', 'eventDragStart', 'eventDragEnd', 'eventDomReady'] as $event) @if (isset($options[$event])) diff --git a/src/Facades/MapperFacade.php b/src/Facades/MapperFacade.php index 5265885..b03279f 100644 --- a/src/Facades/MapperFacade.php +++ b/src/Facades/MapperFacade.php @@ -13,7 +13,7 @@ * @method static Mapper streetview($latitude, $longitude, $heading, $pitch, array $options = []) * @method static Mapper marker($latitude, $longitude, array $options = []) * @method static Mapper informationWindow($latitude, $longitude, $content = '', array $options = []) - * @method static Mapper polyline(array $coordinates = [], array $options = []) + * @method static Mapper polyline(array $coordinates = [], $content = '', array $options = []) * @method static Mapper polygon(array $coordinates = [], array $options = []) * @method static Mapper rectangle(array $coordinates = [], array $options = []) * @method static Mapper circle(array $coordinates = [], array $options = []) diff --git a/src/Mapper.php b/src/Mapper.php index 46a61c3..952a977 100644 --- a/src/Mapper.php +++ b/src/Mapper.php @@ -335,7 +335,7 @@ public function informationWindow($latitude, $longitude, $content = '', array $o * * @return self */ - public function polyline(array $coordinates = [], array $options = []) + public function polyline(array $coordinates = [], $content = '', array $options = []) { $items = $this->getItems(); @@ -360,9 +360,44 @@ public function polyline(array $coordinates = [], array $options = []) $item->shape('polyline', $coordinates, $options); + // Info window for a polyline if contentis not empty + if(!empty($content)) { + $parameters = $this->getOptions(); + $options = array_replace_recursive( + ['markers' => $parameters['markers']], + $item->getOptions()['markers'], + $options, + ($content !== '' ? ['markers' => ['content' => $content]] : []) + ); + $options['markers']['visible'] = false; + $coordinates = $this->midpoint($coordinates[0]['latitude'], $coordinates[0]['longitude'], $coordinates[1]['latitude'], $coordinates[1]['longitude']); + $latitude = $coordinates[0]; + $longitude = $coordinates[1]; + $item->marker($latitude, $longitude, $options); + } + return $this; } + public function midpoint ($lat1, $lng1, $lat2, $lng2) { + + $lat1= deg2rad($lat1); + $lng1= deg2rad($lng1); + $lat2= deg2rad($lat2); + $lng2= deg2rad($lng2); + + $dlng = $lng2 - $lng1; + $Bx = cos($lat2) * cos($dlng); + $By = cos($lat2) * sin($dlng); + $lat3 = atan2( sin($lat1)+sin($lat2), + sqrt((cos($lat1)+$Bx)*(cos($lat1)+$Bx) + $By*$By )); + $lng3 = $lng1 + atan2($By, (cos($lat1) + $Bx)); + $pi = pi(); + $coords[] = ($lat3*180)/$pi; + $coords[] = ($lng3*180)/$pi; + return $coords; + } + /** * Add a new map polygon. *