laravel-maps
laravel-maps copied to clipboard
laravel implementation
Not an issue really....
Noticed you link to BIOINSTALL site, they just have codeigniter demo, code is close for laravel but not ideal. I have taken some of there demos and reproduced them for Laravel 5.5:
Controller:
namespace App\Http\Controllers\Frontend;
use App\Http\Controllers\Controller;
use GeneaLabs\LaravelMaps\Facades\Map;
/**
* Class HomeController.
*/
class MapsController extends Controller
{
public function index($map)
{
app()
->make('\App\Http\Controllers\Frontend\MapsController')
->callAction($map, $parameters = array());
$map = Map::create_map();
return view('frontend.maps.view')->with('map', $map);
}
public function markers_single()
{
$config = array();
$config['center'] = '37.4419, -122.1419';
$config['draggableCursor'] = 'default';
Map::initialize($config);
$marker = array();
$marker['position'] = '37.4419, -122.1419';
Map::add_marker($marker);
}
public function markers_multiple()
{
$config = array();
$config['center'] = '37.4419, -122.1419';
$config['zoom'] = 'auto';
$config['draggableCursor'] = 'default';
Map::initialize($config);
$marker = array();
$marker['position'] = '37.429, -122.1519';
$marker['infowindow_content'] = '1 - Hello World!';
$marker['icon'] = 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|9999FF|000000';
Map::add_marker($marker);
$marker = array();
$marker['position'] = '37.409, -122.1319';
$marker['draggable'] = TRUE;
$marker['animation'] = 'DROP';
Map::add_marker($marker);
$marker = array();
$marker['position'] = '37.449, -122.1419';
$marker['onclick'] = 'alert("You just clicked me!!")';
Map::add_marker($marker);
}
public function polyline()
{
$config = array();
$config['center'] = '37.4419, -122.1419';
$config['zoom'] = 'auto';
Map::initialize($config);
$polyline = array();
$polyline['points'] = array('37.429, -122.1319',
'37.429, -122.1419',
'37.4419, -122.1219');
Map::add_polyline($polyline);
}
public function polygon()
{
$config = array();
$config['center'] = '37.4419, -122.1419';
$config['zoom'] = 'auto';
Map::initialize($config);
$polygon = array();
$polygon['points'] = array('37.425, -122.1321',
'37.4422, -122.1622',
'37.4412, -122.1322',
'37.425, -122.1021');
$polygon['strokeColor'] = '#000099';
$polygon['fillColor'] = '#000099';
Map::add_polygon($polygon);
}
public function drawing()
{
$config = array();
$config['drawing'] = true;
$config['drawingDefaultMode'] = 'circle';
$config['drawingModes'] = array('circle','rectangle','polygon');
Map::initialize($config);
}
public function directions()
{
$config = array();
$config['center'] = '37.4419, -122.1419';
$config['zoom'] = 'auto';
$config['directions'] = TRUE;
$config['directionsStart'] = 'empire state building';
$config['directionsEnd'] = 'statue of liberty';
$config['directionsDivID'] = 'directionsDiv';
Map::initialize($config);
}
public function streetview()
{
$config = array();
$config['center'] = '37.4419, -122.1419';
$config['map_type'] = 'STREET';
$config['streetViewPovHeading'] = 90;
Map::initialize($config);
}
public function clustering()
{
$config = array();
$config['center'] = '37.409, -122.1319';
$config['zoom'] = '13';
$config['cluster'] = TRUE;
$config['clusterStyles'] = array(
array(
"url"=>"https://raw.githubusercontent.com/googlemaps/js-marker-clusterer/gh-pages/images/m1.png",
"width"=>"53",
"height"=>"53"
));
Map::initialize($config);
$marker = array();
$marker['position'] = '37.409, -122.1319';
Map::add_marker($marker);
$marker = array();
$marker['position'] = '37.409, -122.1419';
Map::add_marker($marker);
$marker = array();
$marker['position'] = '37.409, -122.1219';
Map::add_marker($marker);
$marker = array();
$marker['position'] = '37.409, -122.1519';
Map::add_marker($marker);
}
public function kml_layer()
{
$config = array();
$config['zoom'] = 'auto';
$config['kmlLayerURL'] = 'https://www.google.com/maps/d/kml?mid=zQsfa8t0PJbc.kXZmQVidOFfE';
Map::initialize($config);
}
}
Route:
Route::get('/maps/{map}', 'MapsController@index')->name('maps.index');
View:
@section('scripts')
{!! $map['js'] !!}
@endsection
@section('content')
<div class="row mb-4">
<div class="col">
<div class="card">
<div class="card-header">
<i class="fa fa-map"></i> Maps
<a href="{{ route('frontend.maps.show', ['map' => 'kml_layer']) }}" class="btn btn-sm btn-primary pull-right">KML Layer</a>
<a href="{{ route('frontend.maps.show', ['map' => 'clustering']) }}" class="btn btn-sm btn-primary pull-right">Clustering</a>
<a href="{{ route('frontend.maps.show', ['map' => 'streetview']) }}" class="btn btn-sm btn-primary pull-right">Streetview</a>
<a href="{{ route('frontend.maps.show', ['map' => 'directions']) }}" class="btn btn-sm btn-primary pull-right">Directions</a>
<a href="{{ route('frontend.maps.show', ['map' => 'drawing']) }}" class="btn btn-sm btn-primary pull-right">Drawing</a>
<a href="{{ route('frontend.maps.show', ['map' => 'polygon']) }}" class="btn btn-sm btn-primary pull-right">Polygon</a>
<a href="{{ route('frontend.maps.show', ['map' => 'polyline']) }}" class="btn btn-sm btn-primary pull-right">Polyline</a>
<a href="{{ route('frontend.maps.show', ['map' => 'markers_multiple']) }}" class="btn btn-sm btn-primary pull-right">Multiple Markers</a>
<a href="{{ route('frontend.maps.show', ['map' => 'markers_single']) }}" class="btn btn-sm btn-primary pull-right">Single Markers</a>
</div>
<div class="card-body">
{!! $map['html'] !!}
<div id="directionsDiv"></div>
</div>
</div>
</div>
</div><!--row-->
@endsection
I'm using bootstrap 4 for style and have a layout app blade to yield content in above view
Should be easy to use above rather than the Bioinstall code, but thanks to them for pointing in right direction to use your code.
Next i would like to add a context menu, right click on map to show context menu, have links in menu definable, implementing this code: https://github.com/gizzmo/Gmaps-Context-Menu into your code
Hey @phpgraham thanks for the info! Yea, I took this project on after it was abandoned by its creators a few years ago. I plan to do a complete rewrite. Thanks for the examples, I'll add them to the documentation. :)
Cheers @mikebronner I've now refined the Controller code and created a simple laravel 5.5 package: https://github.com/phpgraham/laravelmaps
@phpgraham Thanks, can you please submit that as a PR to this package?
@mikebronner yes can do, but how do i go about that? i did not fork your project to begin with. I created a clean install of laravel 5.5, then installed your code via composer, then created a simple Controller and View
Ah, I see .... I hadn't actually looked at your project yet, because I'm currently swamped. I will take a closer look soon(ish) when I get more time. Thanks for taking the time to create some good examples. :)
I'm Using Laravel 5.6 infowindow_content does not work for it
@isurutmv thanks for reporting. Please open a separate issue and provide the code you are using to create the info window content.