yii2-google-maps-library icon indicating copy to clipboard operation
yii2-google-maps-library copied to clipboard

How to only reload marker without reloading whole map?

Open shivanipatel opened this issue 10 years ago • 0 comments

I Have added more than one marker in my page.. and when I click on particular marker there is one info window in which I have put one button. When I click on that button I update status of marker and marker colour should change. Can anyone tell how to reload only one marker without reloading whole page? http://jsfiddle.net/Vvcbt/1/ Here is code:

View: $latlongcnt = count($latArray); $coordArray = array();

for($i=0; $i< $latlongcnt; $i++)
{
    $coord0 = new LatLng(['lat' => $latArray[0], 'lng' => $longArray[0]]);
    $coord[$i] = new LatLng(['lat' => $latArray[$i], 'lng' => $longArray[$i]]);

    $map = new Map([
        'center' => $coord0,
        'zoom' => 14,
    ]);

    $marker[$i] = new Marker([
        'icon'=> $VisitedArray[$i],
        'position' => $coord[$i],
    ]);

    $btnvisitedValue;
    if ($isVisitedArray[$i] == "visited") {
        $btnvisitedValue = "Mark&nbsp;as&nbsp;not&nbsp;".$isVisitedArray[$i];
    } else {
        $btnvisitedValue = "Mark&nbsp;as&nbsp;visited";
    }

    $btnmustwatchValue;
    $locationid = $locationidArray[$i];

    if ($mustWatchArray[$i] == "Must Watch") {
        $btnmustwatchValue = "Mark&nbsp;as&nbsp;not&nbsp;watch";
    } else {
        $btnmustwatchValue = "Mark&nbsp;as&nbsp;watch";
    }

    $marker[$i]->attachInfoWindow(
        new InfoWindow([
            'content' =>  $add[$i].'<form><br><img src="data:image/png;base64,'. $photoArray[$i] . '"/><br>'.
                            "<br><input style='color:blue' value=".$btnvisitedValue."  type='button' onclick=send('$btnvisitedValue','$locationid')>
                             <br><input style='color:blue' value=".$btnmustwatchValue."  type='button' onclick=send2('$btnmustwatchValue','$locationid')>
                             <br></form>"
        ])
    );

    array_push($coordArray, $marker[$i]);
}

for($i=0; $i< count($coordArray) ; $i++)
{
    $map->addOverlay($coordArray[$i]);
}
echo $map->display();   

?>

Controller: public function actionEditmarker() { $t = array(); $user_id = \Yii::$app->user->identity->id; if(isset($_POST['data'])) { $data = $_POST['data']; $id = $_POST['id']; $data = str_replace("\xc2\xa0", '', $data);

        $newData = "";

        if ($data == 'Markasvisited')
        {
            $sql = "update location set is_visited = 'visited' where location_id = $id and user_id = $user_id";
            \Yii::$app->db->createCommand($sql)->execute();
            $newData = 'visited';
        } else if ($data == "Markasnotvisited") {
            $sql = "update location set is_visited = 'Not Visited' where location_id = $id and user_id = $user_id";
            \Yii::$app->db->createCommand($sql)->execute();
            $newData = 'visited1';
        } else if($data == "Markaswatch"){
            $sql = "update location set must_watch = 'Must Watch' where location_id = $id and user_id = $user_id";
            \Yii::$app->db->createCommand($sql)->execute();
            $newData = 'visited2';
        } else if($data == "Markasnotwatch"){
            $sql = "update location set must_watch = 'No' where location_id = $id and user_id = $user_id";
            \Yii::$app->db->createCommand($sql)->execute();
            $newData = 'visited3';
        } else{
            print_r("--------------------".$data);
        }

        $t['s'] =$newData; 
        return json_encode($t);
    }
    else
    {
        print_r('error');
        exit();
    }
}

shivanipatel avatar Jul 10 '15 12:07 shivanipatel