Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion resources/views/polyline.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,31 @@

shapes.push({
'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]))

google.maps.event.addListener(polyline_{!! $id !!}, '{!! str_replace('event', '', strtolower($event)) !!}', function (event) {
{!! $options[$event] !!}
});

@endif

@endforeach
2 changes: 1 addition & 1 deletion src/Facades/MapperFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
Expand Down
37 changes: 36 additions & 1 deletion src/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -360,9 +360,44 @@ public function polyline(array $coordinates = [], array $options = [])

$item->shape('polyline', $coordinates, $options);

// Info window for a polyline if content is 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.
*
Expand Down