Skip to content

Commit

Permalink
map points view & boundry search on points
Browse files Browse the repository at this point in the history
  • Loading branch information
madaeroblade committed Oct 30, 2023
1 parent 6d4d0c2 commit 217f73a
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 56 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/MapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class MapController extends Controller
public function points(Request $request)
{
$filters = $request->get('filters', []);
$bounds = $request->get('bounds', []);
return response()
->json(
[
'points' => MapPoint::getFilteredMapPoints($filters)
'points' => MapPoint::getFilteredMapPoints($filters, $bounds)
]);
}

Expand Down
23 changes: 19 additions & 4 deletions app/Models/MapPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,16 +677,31 @@ public function fieldTypes()
*
* @return Collection
*/
public static function getFilteredMapPoints(array $filters): Collection
{
public static function getFilteredMapPoints(array $filters, array $bounds): Collection
{
if (empty($bounds))
{
return collect([]);
}

$polygon = [
$bounds['northEast']['lat'].' '.$bounds['northEast']['lng'],
$bounds['northWest']['lat'].' '.$bounds['northWest']['lng'],
$bounds['southWest']['lat'].' '.$bounds['southWest']['lng'],
$bounds['southEast']['lat'].' '.$bounds['southEast']['lng'],
$bounds['northEast']['lat'].' '.$bounds['northEast']['lng'],
];
$boundarySearch = "ST_WITHIN(POINT(recycling_points.lat, recycling_points.lon), ST_GEOMETRYFROMTEXT('POLYGON((".implode(", ", $polygon)."))')) AS in_bounds";
$sql = self::
select(
'recycling_points.id',
'recycling_points.lat',
'recycling_points.lon',
'recycling_points.location',
)
->where('status', 1);
\DB::raw($boundarySearch)
)
->having('in_bounds', '=', 1)
->where('status', 1);

if (!empty($filters))
{
Expand Down
Binary file added public/assets/images/pin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resources/assets/images/logo.png
Binary file not shown.
Binary file removed resources/assets/images/notFound.png
Binary file not shown.
37 changes: 0 additions & 37 deletions resources/assets/images/punct_benzinarie.svg

This file was deleted.

106 changes: 93 additions & 13 deletions resources/js/components/IndexPage.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<left-sidebar
:has-results="hasResults"
@filtersChanged="getMapPoints($event)"
@filtersChanged="setFilters($event)"
></left-sidebar>

<div
Expand Down Expand Up @@ -47,7 +47,10 @@
ref="map"
:center="[latitude, longitude]"
:zoom="zoom"
@ready="init"
@ready="initMap"
@update:zoom="zoomEvent($event)"
@update:center="centerEvent($event)"
@update:bounds="boundsEvent($event)"
:use-global-leaflet="false"
>
<l-tile-layer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"></l-tile-layer>
Expand All @@ -58,7 +61,7 @@
>
<l-icon
:icon-size="dynamicSize"
icon-url="/assets/images/logo.png" >
icon-url="/assets/images/pin.png" >
</l-icon>
</l-marker>
</template>
Expand Down Expand Up @@ -118,13 +121,15 @@ export default
longitude: CONSTANTS.DEFAULT_LOCATION.LONGITUDE,
points: {},
icon: L.icon({
iconUrl: '/assets/images/punct_benzinarie.svg',
iconSize: [100, 37],
iconAnchor: [16, 37]
iconUrl: '/assets/images/pin.png',
iconSize: [48, 64],
iconAnchor: [48, 64]
}),
iconSize: 100,
iconSize: 48,
hasApprovedLocation: false,
hasResults: false
hasResults: false,
filters: {},
bounds: {}
};
},
Expand All @@ -150,6 +155,7 @@ export default
const error = (err) =>
{
console.log(error)
this.getMapPoints();
};
navigator.geolocation.getCurrentPosition(success, error);
},
Expand All @@ -174,14 +180,21 @@ export default
this.isAuthenticated = false;
}
},
getMapPoints(filters)
getMapPoints(filters = {})
{
console.log(`filters`, filters);
axios
.get(CONSTANTS.API_DOMAIN + CONSTANTS.ROUTES.MAP.POINTS.INFO)
.get(CONSTANTS.API_DOMAIN + CONSTANTS.ROUTES.MAP.POINTS.INFO, {
params: {
bounds: this.bounds,
filters: this.filters,
lat: this.latitude,
lng: this.longitude
}
})
.then((response) =>
{
this.points = _.get(response, 'data.points', {});
console.log(this.points);
if (Object.keys(this.points).length > 0)
{
this.hasResults = true;
Expand All @@ -190,6 +203,74 @@ export default
{
console.log(err);
});
},
initMap()
{
this.map = this.$refs.map.leafletObject;
this.bounds = {
northEast: {
lat: this.map.getBounds().getNorthEast().lat,
lng: this.map.getBounds().getNorthEast().lng,
},
northWest: {
lat: this.map.getBounds().getNorthWest().lat,
lng: this.map.getBounds().getNorthWest().lng,
},
southWest: {
lat: this.map.getBounds().getSouthWest().lat,
lng: this.map.getBounds().getSouthWest().lng,
},
southEast: {
lat: this.map.getBounds().getSouthEast().lat,
lng: this.map.getBounds().getSouthEast().lng,
},
};
this.getMapPoints();
},
setFilters(event)
{
if (Object.keys(event).length > 0)
{
this.filters = event;
this.getMapPoints();
}
},
zoomEvent(event)
{
if (event != this.zoom)
{
this.getMapPoints();
}
this.zoom = event;
},
centerEvent(event)
{
this.latitude = event.lat;
this.longitude = event.lng;
this.getMapPoints();
},
boundsEvent(event)
{
this.bounds = {
northEast: {
lat: event.getNorthEast().lat,
lng: event.getNorthEast().lng,
},
northWest: {
lat: event.getNorthWest().lat,
lng: event.getNorthWest().lng,
},
southWest: {
lat: event.getSouthWest().lat,
lng: event.getSouthWest().lng,
},
southEast: {
lat: event.getSouthEast().lat,
lng: event.getSouthEast().lng,
}
};
}
},
computed: {
Expand All @@ -199,7 +280,7 @@ export default
},
dynamicSize ()
{
return [this.iconSize, this.iconSize / 2.15];
return [this.iconSize, this.iconSize * 1.25];
}
},
mounted()
Expand All @@ -211,7 +292,6 @@ export default
this.getUserInfo();
});
this.getUserInfo();
this.getMapPoints({});
}
};
</script>
1 change: 0 additions & 1 deletion resources/js/components/leftSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ export default {
this.materialTypesFilters.push(filterToAppend);
}
}
this.collectedFilters.material_type_id = this.materialTypesFilters;
},
serviceFilterChanged(filterId) {
if (filterId === this.searchParamsForFilters.service_id) {
Expand Down

0 comments on commit 217f73a

Please sign in to comment.