Skip to content

Commit

Permalink
feat(Places): handling of the polygons with less than 4 coordinates
Browse files Browse the repository at this point in the history
issue: #494
  • Loading branch information
rebeccadjim committed Jul 11, 2024
1 parent 413df75 commit 84b9a7d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 0 additions & 3 deletions src/resources/views/livewire/forms/form-area.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class="form-input rounded-md shadow-sm mt-1 block w-full"
@error($form_elem.'.polygons.*.*.long')
<p class="text-sm text-red-600">{{ Str::replace($form_elem.'.polygons.', $this->title.' (longitudes)', $message) }}</p>
@enderror
@error($form_elem.'.polygons.*.*.')
<p class="text-sm text-red-600">{{ Str::replace($form_elem.'.polygons.', $this->title.' (latitudes)', $message) }}</p>
@enderror
</jet-div>
@endfor

Expand Down
15 changes: 9 additions & 6 deletions src/resources/views/map/leaflet.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ function initArea() {
initialArea.forEach(polygonCoords => {
polygonCoords.forEach(coords => {
const sortedCoords = sortClockwise(coords);
const latLngs = sortedCoords.map(coord => [coord.lat, coord.long]);
const polygon = L.polygon(latLngs, { color: 'green' }).addTo(map);
map.fitBounds(polygon.getBounds(), {padding: [50, 50]
});
})
const validCoords = coords.filter(coord => coord.lat !== null && coord.long !== null);
if (validCoords.length > 0) {
const sortedCoords = sortClockwise(validCoords);
const latLngs = sortedCoords.map(coord => [coord.lat, coord.long]);
const polygon = L.polygon(latLngs, { color: 'green' }).addTo(map);
map.fitBounds(polygon.getBounds(), { padding: [50, 50] });
}
});
});
}
/* ------------------------- Handle Map Click Event ------------------------- */
Expand Down

0 comments on commit 84b9a7d

Please sign in to comment.