jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – Yii和EGMap扩展(Google Map)刷新复选框更改的地图大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 Yii framework和Yii egmap extension开发交互式地图.
用户点击复选框时,我想刷新地图(ajaX),如图所示:

我只能使用以下代码在服务器端(刷新整个页面)执行此操作:

<?PHP
    Yii::app()->clientScript->registerScript('filterscript',"
        $('#filter_all').click(function() {
            $(\"input[name='filter\[\]']\").prop('checked',this.checked);
            window.LOCATIOn.href = 'http://' + window.LOCATIOn.host + window.LOCATIOn.pathname + '?tags=SALE,rent,residential,commercial,agricultural';
        });
        $(\"input[name='filter\[\]']\").click(function() {
            var tags = '?tags=';
            var tmp=new Array();
            $('#filter_all').prop('checked',!$(\"input[name='filter\[\]']:not(:checked)\").length);
            $('input[type=checkBox]').each(function () {
                if (this.checked) 
                    tmp.push($(this).val());

            });
            tags += tmp.join(',');
            window.LOCATIOn.href = 'http://' + window.LOCATIOn.host + window.LOCATIOn.pathname + tags;
        });
        $('#filter_all').prop('checked',!$(\"input[name='filter\[\]']:not(:checked)\").length);
    ",CClientScript::POS_READY);
?>

并使用此代码使用EGMap扩展生成地图:

<?PHP

// Get latlong from LOCATIOn-aware web browser saved in cookie
if (isset($_COOKIE['latlng'])){
    list($lat,$long) = explode(',',htmlentities(htmlspecialchars(@R_616_10495@p_tags($_COOKIE['latlng']))));
}else{
    $lat = 3.159553312559541;
    $long = 101.71481802016604;
}
Yii::import('ext.gmap.*');

$gMap = new EGMap();
$gMap->setJsName('map');
$gMap->zoom = 10;
$mapTypeControlOptions = array(
    'sensor'=>true,'position'=> EGMapControlPosition::LEFT_BOTTOM,'style'=>EGMap::MAPTYPECONTROL_STYLE_DROPDOWN_MENU
);

$gMap->mapTypeControlOptions= $mapTypeControlOptions;
$gMap->setWidth('100%');
$gMap->setHeight(500);
$gMap->setCenter($lat,$long);

$icon = new EGMapMarkerImage("http://".$_SERVER['http_HOST'].Yii::app()->baseUrl."/images/bighouse.png");

$icon->setSize(32,37);
$icon->setAnchor(16,16.5);
$icon->setOrigin(0,0);

// Status label
$status_type = array(
    0=>'success',1=>'warning',2=>'important',3=>'important',);

$condition = '';
$SALE_cond = '';
$rent_cond = '';

if ($match['SALE']==='' && $match['rent']==='' && $match['residential']==='' && $match['commercial']==='' && $match['agricultural']===''){
    $condition = "AND (
        (MATCH (tags) AGAINST ('SALE') 
        AND MATCH (tags) AGAINST ('residential'))
        OR
        (MATCH (tags) AGAINST ('rent') 
        AND MATCH (tags) AGAINST ('residential') )
        OR
        (MATCH (tags) AGAINST ('SALE') 
        AND MATCH (tags) AGAINST ('commercial'))
        OR
        (MATCH (tags) AGAINST ('rent') 
        AND MATCH (tags) AGAINST ('commercial') )
        OR
        (MATCH (tags) AGAINST ('SALE') 
        AND MATCH (tags) AGAINST ('agricultural'))
        OR
        (MATCH (tags) AGAINST ('rent') 
        AND MATCH (tags) AGAINST ('agricultural') )
    )";
}else{
    if ($match['SALE']!=''){
        $SALE_cond = "MATCH (tags) AGAINST ('SALE')";
        if ($match['residential']!=''){
            $cond[1] = "(".$SALE_cond." AND MATCH (tags) AGAINST ('residential'))";
        }
        if ($match['commercial']!=''){
            $cond[2] = "(".$SALE_cond." AND MATCH (tags) AGAINST ('commercial'))";
        }
        if ($match['agricultural']!=''){
            $cond[3] = "(".$SALE_cond." AND MATCH (tags) AGAINST ('agricultural'))";
        }
        if ($match['residential']!='' || $match['commercial']!='' || $match['agricultural']!=''){
            $SALE_cond = implode(' OR ',$cond);
        }
    }
    if ($match['rent']!=''){
        $rent_cond = "MATCH (tags) AGAINST ('rent')";
        if ($match['residential']!=''){
            $cond[1] = "(".$rent_cond." AND MATCH (tags) AGAINST ('residential'))";
        }
        if ($match['commercial']!=''){
            $cond[2] = "(".$rent_cond." AND MATCH (tags) AGAINST ('commercial'))";
        }
        if ($match['agricultural']!=''){
            $cond[3] = "(".$rent_cond." AND MATCH (tags) AGAINST ('agricultural'))";
        }
        if ($match['residential']!='' || $match['commercial']!='' || $match['agricultural']!=''){
            $rent_cond = implode(' OR ',$cond);
        }

    }
    if ($SALE_cond!=''){
        $condition = 'AND '.$SALE_cond;
        if ($rent_cond!=''){
            $condition .= ' OR '.$rent_cond;
        }
    }elseif ($rent_cond!=''){
        $condition = 'AND '.$rent_cond;
    }
}

$props = Property::model()->findAll('active=1 '.$condition);
if ($props!==null){
    foreach ($props as $prop){
        // Prepare status label for info Box
        $status_label='<span class="label label-'.$status_type[(int)$prop['status']].'">'.$list_status[(int)$prop['status']].'</span>';
        $prop_photo = '';
        $win_height = '110px';
        // check if photo exist
        if (is_file('images/property/'.$prop['photo'])){
            $prop_photo = '<img src="http://'.$_SERVER['http_HOST'].Yii::app()->baseUrl.'/images/property/'.$prop['photo'].'" /><br />'; 
            $win_height = '310px';
        }

        $email_img = '<img src="http://'.$_SERVER['http_HOST'].Yii::app()->baseUrl.'/site/strtoimg?pid='.$prop['id'].'" />';

        $view_link = '<div style="float:left"><a href="'.Yii::app()->baseUrl.'/public/view/'.$prop['id'].'">View this property</a></div>';
        $edit_link = '';
        if (!Yii::app()->user->isGuest && (int)$prop['user_id']===(int)Yii::app()->user->id){
            $edit_link = '<div style="float:right"><a href="'.Yii::app()->baseUrl.'/prop/update/'.$prop['id'].'">Edit this property</a></div>';
        }
        $links = '<div>'.$view_link.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$edit_link.'</div>';

        $info_window = new EGMapInfoWindow('<div style="height:'.$win_height.'">'.
                $prop_photo.
                substr($prop['description'],40).'...'.'<br />'.
                'Price: '.$prop['price'].'<br />'.
                'Email: '.$email_img.'<br />'.
                'Tel: '.$prop['contact_phone'].'<br />'.
                $status_label.' Added: '.$prop['date_upload'].'<br />'.
                $links.
                '</div>');
        $marker = new EGMapMarker($prop['latitude'],$prop['longitude'],array('title' => $prop['title'],'icon'=>$icon));
        $marker->addHtmlInfoWindow($info_window);
        $gMap->addMarker($marker);
    }
}
$gMap->renderMap();

?>

所有这代码都在视图文件中.地图由带有id EGMapContainer0的html元素中的EGMap扩展生成.知道如何在复选框点击的情况下通过ajax刷新地图吗?

谢谢.

解决方法

我一直在使用这个地图它很棒且易于使用,但它的问题是你不能使用它与renderPartial它只是不渲染.只有解决方案是使用iframe. Ajax更新根本不起作用.

大佬总结

以上是大佬教程为你收集整理的jquery – Yii和EGMap扩展(Google Map)刷新复选框更改的地图全部内容,希望文章能够帮你解决jquery – Yii和EGMap扩展(Google Map)刷新复选框更改的地图所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。