Issue
I am using Laravel to get all the data from a table and show the list of coordinates for Leaflet. Currently I am working on how to use $gis
in the GisController to the index's JavaScript.
So here's the GisController.php
public function index()
{
$gis = Gis::all();
return view('gis/map', compact('gis'));
}
and this is from the index.blade.php
foreach ($gis as $gisData) {
//------- data from controller
var gisType = $gisData->type;
if (gisType == 1) {
//------- data from controller
var polylinePoints = $gisData->coordinates;
var polyline = L.polyline(polylinePoints).addTo(map);
} else if (gisType == 2) {
//------- data from controller
var markerPoint= $gisData->coordinates;
var marker = L.marker(markerPoint).addTo(map);
}
}
Solution
have 2 ways :
- using ajax return object
- set variable into javascript
<script>
const gisData = <?php echo json_encode($gis); ?>;
</script>
note : can convert $gis to array
Answered By - Xupitan Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.