app/Http/Controllers/MapController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index($tahun = null)
    {
        $geofile = [];
        $color = [];
        $coor = [];
        $index = 0;
        $index2 = 0;
        $tematik = Tematik::all();
        if ($tahun) {
            $data = HalamanData::where('tanggal', $tahun)->get();
        } else {
            $data = HalamanData::all();
        }
        foreach ($tematik as $item) {
            $geofile[$index] = '/storage/' . $item->geojson;
            $index++;
        }
        foreach ($tematik as $item) {
            $color[$item->kecamatan] = $item->warna;
        }
        foreach ($data as $item) {
            $coor[$index2] = [$item->alamat, $item->lat, $item->long, $item->tematik->kecamatan, $item->jumlah_kecelakaan];
            $index2++;
        }
        $tahunList = HalamanData::groupby('tanggal')->get();
        return view('maps', [
            'geofile' => $geofile,
            'tahunList' => $tahunList,
            'tahun' => $tahun,
            'color' => $color,
            'data' => $coor
        ]);
    }
public function index ( $ tahun = null ) { $ geofile = [ ] ; $ color = [ ] ; $ coor = [ ] ; $ index = 0 ; $ index2 = 0 ; $ tematik = Tematik :: all ( ) ; if ( $ tahun ) { $ data = HalamanData :: where ( 'tanggal' , $ tahun ) -> get ( ) ; } else { $ data = HalamanData :: all ( ) ; } foreach ( $ tematik as $ item ) { $ geofile [ $ index ] = '/storage/' . $ item -> geojson ; $ index ++ ; } foreach ( $ tematik as $ item ) { $ color [ $ item -> kecamatan ] = $ item -> warna ; } foreach ( $ data as $ item ) { $ coor [ $ index2 ] = [ $ item -> alamat , $ item -> lat , $ item -> long , $ item -> tematik -> kecamatan , $ item -> jumlah_kecelakaan ] ; $ index2 ++ ; } $ tahunList = HalamanData :: groupby ( 'tanggal' ) -> get ( ) ; return view ( 'maps' , [ 'geofile' => $ geofile , 'tahunList' => $ tahunList , 'tahun' => $ tahun , 'color' => $ color , 'data' => $ coor ] ) ; }
Display a listing of the resource.
Display a listing of the resource .