Browse Source

User can add marker from outlets map

pull/3/head
Nafies Luthfi 7 years ago
parent
commit
b4434799d4
  1. 6
      resources/views/outlets/create.blade.php
  2. 20
      resources/views/outlets/map.blade.php

6
resources/views/outlets/create.blade.php

@ -24,14 +24,14 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label for="latitude" class="control-label">{{ __('outlet.latitude') }}</label> <label for="latitude" class="control-label">{{ __('outlet.latitude') }}</label>
<input id="latitude" type="text" class="form-control{{ $errors->has('latitude') ? ' is-invalid' : '' }}" name="latitude" value="{{ old('latitude') }}" required>
<input id="latitude" type="text" class="form-control{{ $errors->has('latitude') ? ' is-invalid' : '' }}" name="latitude" value="{{ old('latitude', request('latitude')) }}" required>
{!! $errors->first('latitude', '<span class="invalid-feedback" role="alert">:message</span>') !!} {!! $errors->first('latitude', '<span class="invalid-feedback" role="alert">:message</span>') !!}
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label for="longitude" class="control-label">{{ __('outlet.longitude') }}</label> <label for="longitude" class="control-label">{{ __('outlet.longitude') }}</label>
<input id="longitude" type="text" class="form-control{{ $errors->has('longitude') ? ' is-invalid' : '' }}" name="longitude" value="{{ old('longitude') }}" required>
<input id="longitude" type="text" class="form-control{{ $errors->has('longitude') ? ' is-invalid' : '' }}" name="longitude" value="{{ old('longitude', request('longitude')) }}" required>
{!! $errors->first('longitude', '<span class="invalid-feedback" role="alert">:message</span>') !!} {!! $errors->first('longitude', '<span class="invalid-feedback" role="alert">:message</span>') !!}
</div> </div>
</div> </div>
@ -63,7 +63,7 @@
integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw==" integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw=="
crossorigin=""></script> crossorigin=""></script>
<script> <script>
var mapCenter = [{{ config('leaflet.map_center_latitude') }}, {{ config('leaflet.map_center_longitude') }}];
var mapCenter = [{{ request('latitude', config('leaflet.map_center_latitude')) }}, {{ request('longitude', config('leaflet.map_center_longitude')) }}];
var map = L.map('mapid').setView(mapCenter, {{ config('leaflet.zoom_level') }}); var map = L.map('mapid').setView(mapCenter, {{ config('leaflet.zoom_level') }});
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {

20
resources/views/outlets/map.blade.php

@ -44,5 +44,25 @@
.catch(function (error) { .catch(function (error) {
console.log(error); console.log(error);
}); });
@can('create', new App\Outlet)
var theMarker;
map.on('click', function(e) {
let latitude = e.latlng.lat.toString().substring(0, 15);
let longitude = e.latlng.lng.toString().substring(0, 15);
if (theMarker != undefined) {
map.removeLayer(theMarker);
};
var popupContent = "Your location : " + latitude + ", " + longitude + ".";
popupContent += '<br><a href="{{ route('outlets.create') }}?latitude=' + latitude + '&longitude=' + longitude + '">Add new outlet here</a>';
theMarker = L.marker([latitude, longitude]).addTo(map);
theMarker.bindPopup(popupContent)
.openPopup();
});
@endcan
</script> </script>
@endpush @endpush
Loading…
Cancel
Save