Skip to content

Commit 3aaac44

Browse files
committed
places
1 parent 76f8856 commit 3aaac44

File tree

10 files changed

+304
-24
lines changed

10 files changed

+304
-24
lines changed

public/js

Whitespace-only changes.
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
// Gmaps
2+
if (jQuery('#map').length) {
3+
var infoWindow = new google.maps.InfoWindow(),
4+
jsonData = [],
5+
markers = [],
6+
markersPoints = [],
7+
markersPos = [],
8+
noms = [],
9+
iterator = 0,
10+
mapOptions = {
11+
mapTypeId: google.maps.MapTypeId.ROADMAP,
12+
center: new google.maps.LatLng(50.85,4.36),
13+
mapTypeControl: false,
14+
streetViewControl: false,
15+
zoom: 12
16+
},
17+
markerShape = {
18+
coord: [0,0, 27,0, 27,37, 0,37],
19+
type: 'poly'
20+
},
21+
map = new google.maps.Map(document.getElementById('map'), mapOptions);
22+
// var markerCluster = new MarkerClusterer(map);
23+
24+
google.maps.event.addListener(map, 'click', function() {
25+
infoWindow.close();
26+
});
27+
28+
function getMarkerIcon(shape) {
29+
if ( ! shape) {
30+
shape = '/images/marker.png';
31+
}
32+
return new google.maps.MarkerImage('/images/'+shape+'.png',
33+
new google.maps.Size(34, 44),
34+
new google.maps.Point(0, 0),
35+
new google.maps.Point(14, 36)
36+
)
37+
}
38+
39+
function drop() {
40+
if (markers.length <= 3) {
41+
for (var i = 0; i < markers.length; i++) {
42+
setTimeout(function() {
43+
addMarker(google.maps.Animation.DROP);
44+
}, i * 200);
45+
}
46+
} else {
47+
for (var i = 0; i < markers.length; i++) {
48+
addMarker(false);
49+
}
50+
}
51+
}
52+
53+
function addMarker(animation) {
54+
55+
// decaler un marker s'il y a déjà un point à la même position
56+
var dedans = 0;
57+
for (var i = markers.length - 1; i >= 0; i--){
58+
// console.log(markers[iterator].lat());
59+
if (markersPos[iterator].lat() == markersPos[i].lat() && markersPos[iterator].lng() == markersPos[i].lng()) {
60+
// markers[i]['html'] += markers[iterator]['html'];
61+
dedans++;
62+
}
63+
};
64+
var latLng;
65+
if (dedans >= 2) {
66+
// console.log(dedans+' '+iterator);
67+
// Il y a au moins deux points ayant la même position, alors on décale un des deux
68+
latLng = new google.maps.LatLng(markersPos[iterator].lat(), markersPos[iterator].lng() + Math.random() / 4000 + 0.00001);
69+
} else {
70+
latLng = markersPos[iterator];
71+
}
72+
73+
markersPoints[iterator] = new google.maps.Marker({
74+
// icon: getMarkerIcon(markers[iterator]['shape']),
75+
icon: getMarkerIcon(),
76+
shape: markerShape,
77+
position: latLng,
78+
map: map,
79+
draggable: false,
80+
animation: animation
81+
});
82+
// console.log(markers[iterator]);
83+
markersPoints[iterator].html = markers[iterator]['html'];
84+
markersPoints[iterator].id = markers[iterator]['id'];
85+
google.maps.event.addListener(markersPoints[iterator], 'click', onMarkerClick);
86+
if (markers.length == 1) {
87+
google.maps.event.trigger(markersPoints[iterator], 'click');
88+
}
89+
iterator++;
90+
}
91+
92+
function highlightAddress(markerId) {
93+
// console.log('marker : '+markerId);
94+
var item = jQuery('#item-' + markerId);
95+
if (item.length && ! item.hasClass('active')) {
96+
jQuery('.list-agencies .active').removeClass('active');
97+
item.addClass('active');
98+
}
99+
}
100+
101+
function AutoCenter() {
102+
var bounds = new google.maps.LatLngBounds();
103+
jQuery.each(markers, function (index, marker) {
104+
bounds.extend(markersPos[index]);
105+
});
106+
map.fitBounds(bounds);
107+
var listener = google.maps.event.addListener(map, 'idle', function() {
108+
if (map.getZoom() > 17) map.setZoom(17);
109+
google.maps.event.removeListener(listener);
110+
});
111+
}
112+
113+
var onMarkerClick = function() {
114+
// console.log(this);
115+
highlightAddress(this.id);
116+
infoWindow.setContent(this.html);
117+
infoWindow.open(map, this);
118+
};
119+
120+
var apiUrl = '/api/places',
121+
placeId = $('#place').data('id');
122+
if (placeId) {
123+
apiUrl = apiUrl + '/' + placeId;
124+
}
125+
jQuery.getJSON(apiUrl + location.search, function(data) {
126+
if ( ! jQuery.isArray(data) ) {
127+
jsonData = [data];
128+
} else {
129+
jsonData = data;
130+
}
131+
for (var i = 0; i < jsonData.length; i++) {
132+
if ( jsonData[i].latitude > 0 && jsonData[i].longitude > 0) {
133+
markersPos[i] = new google.maps.LatLng(jsonData[i].latitude, jsonData[i].longitude);
134+
markers[i] = {};
135+
var coords = [];
136+
markers[i]['id'] = jsonData[i].id;
137+
markers[i]['shape'] = jsonData[i].shape;
138+
markers[i]['html'] = '<h4>' + jsonData[i].title + '</h4>';
139+
markers[i]['html'] += '<p>';
140+
if (jsonData[i].address) coords.push(jsonData[i].address);
141+
if (jsonData[i].phone) coords.push('T ' + jsonData[i].phone);
142+
if (jsonData[i].fax) coords.push('F ' + jsonData[i].fax);
143+
if (jsonData[i].email) coords.push('<a href="mailto:' + jsonData[i].email + '">' + jsonData[i].email + '</a>');
144+
if (jsonData[i].website) coords.push('<a href="' + jsonData[i].website + '" target="_blank">' + data[i].website + '</a>');
145+
markers[i]['html'] += coords.join('<br>');
146+
markers[i]['html'] += '</p>';
147+
}
148+
}
149+
// console.log(markers);
150+
if (markers.length > 0) {
151+
drop();
152+
AutoCenter();
153+
}
154+
});
155+
156+
function getMarkerIcon(shape) {
157+
return new google.maps.MarkerImage('/img/marker-microstart.png',
158+
new google.maps.Size(34, 44),
159+
new google.maps.Point(0, 0),
160+
new google.maps.Point(14, 36)
161+
)
162+
}
163+
164+
// Search Postcode
165+
$('#search-cp button').click(function(){
166+
167+
var cp = $('#search-cp input').val();
168+
169+
if( ! cp.length)
170+
return false;
171+
172+
var geocoder = new google.maps.Geocoder();
173+
geocoder.geocode(
174+
{
175+
address: cp + ' Belgique'
176+
},
177+
function(results_array, status) {
178+
var p = results_array[0].geometry.location;
179+
var lat = p.lat();
180+
var lng = p.lng();
181+
setDistancesForMarkers(lat, lng);
182+
}
183+
);
184+
185+
return false;
186+
});
187+
188+
// Compute distance between two points
189+
var rad = function(x) {
190+
return x * Math.PI / 180;
191+
};
192+
193+
function getDistance(p1_lat, p1_lng, p2_lat, p2_lng) {
194+
var R = 6378137; // Earth’s mean radius in meter
195+
var dLat = rad(p2_lat - p1_lat);
196+
var dLong = rad(p2_lng - p1_lng);
197+
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
198+
Math.cos(rad(p1_lat)) * Math.cos(rad(p2_lat)) *
199+
Math.sin(dLong / 2) * Math.sin(dLong / 2);
200+
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
201+
var d = R * c;
202+
return d; // returns the distance in meter
203+
};
204+
205+
// Get the distance between a given point and the markers
206+
function setDistancesForMarkers(lat, lng){
207+
for (var i = 0; i < jsonData.length; i++) {
208+
if ( jsonData[i].latitude > 0 && jsonData[i].longitude > 0) {
209+
jsonData[i].distance = getDistance(lat, lng, jsonData[i].latitude, jsonData[i].longitude);
210+
// var km = (jsonData[i].distance/1000).toFixed(1);
211+
// var km = (jsonData[i].distance/1000).toFixed(0);
212+
// $('#item-'+jsonData[i].id).data('data-distance', km);
213+
// $('#item-'+jsonData[i].id+' .distance').html('(' + km + ' km)');
214+
jsonData.sort(function(a,b) {
215+
return parseFloat(a.distance) - parseFloat(b.distance);
216+
});
217+
// sortAgenciesList();
218+
}
219+
}
220+
openMarkerId(jsonData[0].id);
221+
};
222+
223+
// function sortAgenciesList() {
224+
// var items = $('#list-agencies li').get();
225+
// items.sort(function(a,b){
226+
// var keyA = parseFloat($(a).data('data-distance'));
227+
// var keyB = parseFloat($(b).data('data-distance'));
228+
// if (keyA < keyB) return -1;
229+
// if (keyA > keyB) return 1;
230+
// return 0;
231+
// });
232+
233+
// var ul = $('#list-agencies');
234+
// $.each(items, function(i, li) {
235+
// ul.append(li);
236+
// });
237+
// }
238+
239+
}
240+
241+
function openMarkerId(id) {
242+
// console.log( 'click : '+id );
243+
for (var i = markers.length - 1; i >= 0; i--){
244+
// console.log( markers[i].id );
245+
if (markers[i].id == id) {
246+
var latLng = new google.maps.LatLng(markersPos[i].lat(),markersPos[i].lng());
247+
map.panTo( latLng );
248+
map.setZoom(13);
249+
google.maps.event.trigger(markersPoints[i], 'click');
250+
}
251+
}
252+
return false;
253+
}

src/Http/Controllers/PublicController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public function index()
2626
{
2727
TypiCMS::setModel($this->repository->getModel());
2828

29-
$places = $this->repository->all();
29+
$models = $this->repository->all();
3030

3131
return view('places::public.index')
32-
->withPlaces($places);
32+
->with(compact('models'));
3333
}
3434

3535
/**

src/Providers/ModuleProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public function boot()
3737
$this->publishes([
3838
__DIR__ . '/../../tests' => base_path('tests'),
3939
], 'tests');
40+
$this->publishes([
41+
__DIR__ . '/../../resources/assets' => public_path(),
42+
], 'scripts');
4043

4144
AliasLoader::getInstance()->alias(
4245
'Places',

src/resources/lang/en/global.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@
55
'New' => 'New place',
66
'Edit' => 'Edit place',
77
'Back' => 'Back to places',
8+
'Find nearest' => 'Find nearest address',
9+
'address' => 'address',
10+
'Address' => 'Address',
11+
'Search' => 'Search',
12+
'Filter' => 'Filter',
813
);

src/resources/lang/fr/global.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@
55
'New' => 'Nouvelle adresse',
66
'Edit' => 'Modifier l’adresse',
77
'Back' => 'Retour à la liste des adresses',
8+
'Find nearest' => 'Trouver l’adresse la plus proche',
9+
'address' => 'adresse',
10+
'Address' => 'Adresse',
11+
'Search' => 'Chercher',
12+
'Filter' => 'Filtrer',
813
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<li id="item-{{ $place->id }}">
2+
@if ($place->latitude && $place->longitude)
3+
<a class="btn-map" href="" title="{{ trans('db.Show on map') }}"><i class="fa fa-map-marker"></i><span class="sr-only">{{ trans('db.Show on map') }}</span></a>
4+
@endif
5+
<a href="{{ route($lang.'.places.slug', array($place->slug)) }}" title="{{ trans('db.More') }}">
6+
{{ $place->title }}
7+
</a>
8+
</li>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ul class="list-places">
2+
@foreach ($items as $place)
3+
@include('places::public._list-item')
4+
@endforeach
5+
</ul>

src/resources/views/public/index.blade.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,43 @@
1717

1818
<div class="col-sm-4">
1919

20+
<h2>@lang('places::global.Filter')</h2>
2021
<form method="get" role="form">
21-
<label for="string" class="sr-only">@lang('db.Search')</label>
22-
<div class="input-group">
23-
<input id="string" type="text" placeholder="{{ trans('db.Search') }}" name="string" value="{{ Input::get('string') }}" class="form-control input-sm">
22+
<label for="string" class="sr-only">@lang('places::global.Search')</label>
23+
<div class="input-group input-group-lg">
24+
<input id="string" type="text" name="string" value="{{ Input::get('string') }}" class="form-control input-sm">
2425
<span class="input-group-btn">
25-
<button type="submit" class="btn btn-sm btn-primary">@lang('db.Search')</button>
26+
<button type="submit" class="btn btn-sm btn-primary">@lang('places::global.Search')</button>
2627
</span>
2728
</div>
2829
</form>
2930

3031
<h3>
31-
{{ $places->count() }} @choice('places::global.places', $places->count())
32+
{{ $models->count() }} @choice('places::global.places', $models->count())
3233
@if(Input::get('string')) @lang('for')
3334
{{ Input::get('string') }}
3435
@endif
3536
</h3>
3637

37-
<ul class="list-unstyled addresses">
38-
@foreach ($places as $place)
39-
<li id="item-{{ $place->id }}">
40-
<div class="btns">
41-
@if ($place->latitude && $place->longitude)
42-
<a class="btn-map" href="" title="{{ trans('db.Show on map') }}"><i class="fa fa-map-marker"></i><span class="sr-only">{{ trans('db.Show on map') }}</span></a>
43-
@endif
44-
<a href="{{ route($lang.'.places.slug', array($place->slug)) }}" title="{{ trans('db.More') }}"><span class="fa fa-plus"></span><span class="sr-only">{{ trans('db.More') }}</span></a>
45-
</div>
46-
{{ $place->title }}
47-
</li>
48-
@endforeach
49-
</ul>
38+
@if ($models->count())
39+
@include('places::public._list', ['items' => $models])
40+
@endif
5041

5142
</div>
5243

5344
<div class="col-sm-8">
45+
46+
<h2>@lang('places::global.Find nearest')</h2>
47+
<form id="search-nearest" class="hides" method="get" role="form">
48+
<label for="address" class="sr-only">@lang('places::global.address')</label>
49+
<div class="input-group input-group-lg">
50+
<input class="form-control" id="address" type="text" placeholder="{{ trans('places::global.Address') }}" name="address" value="">
51+
<span class="input-group-btn">
52+
<button type="submit" class="btn btn-sm btn-primary">@lang('places::global.Search')</button>
53+
</span>
54+
</div>
55+
</form>
56+
5457
<div id="map" class="map"></div>
5558
</div>
5659

src/resources/views/public/show.blade.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
<div class="col-sm-4">
1818
<h3>{{ $model->title }}</h3>
1919

20-
@if($model->logo)
21-
<p><img src="{{ Croppa::url('/uploads/places/'.$model->logo, 0, 200) }}" alt=""></p>
22-
@endif
20+
{!! $model->present()->thumb(540, 400) !!}
2321

24-
<p>
22+
<p id="place" data-id="{{ $model->id }}">
2523
@if ($model->address)
2624
{{ $model->address }}<br>
2725
@endif

0 commit comments

Comments
 (0)