2012-05-02 11 views
5

मैं Yii framework और वाईआई egmap extension का उपयोग कर एक इंटरेक्टिव मानचित्र विकसित कर रहा हूं। मैं जब चेक बॉक्स पर उपयोगकर्ता क्लिक चित्र में दिखाए अनुसार मानचित्र (AJAX) ताज़ा करने के लिए करना चाहते हैं: yii-egmap-screenshot मैं केवल यह सर्वर साइड करने के लिए (पूरे पृष्ठ ताज़ा करें) निम्न कोड के साथ कर सकती हूं:वाईआई और ईजीएपी एक्सटेंशन (Google मानचित्र) चेकबॉक्स परिवर्तनों पर मानचित्र रीफ्रेश करें

<?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(strip_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'],0,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(); 

?> 

सभी इन कोड दृश्य फ़ाइल में हैं। नक्शा आईडी EGMapContainer0 के साथ एचटीएमएल तत्व में ईजीएपी एक्सटेंशन द्वारा उत्पन्न होता है। चेकबॉक्स की स्थिति में AJAX के माध्यम से मानचित्र को रीफ्रेश करने का कोई विचार कैसे है?

धन्यवाद।

उत्तर

1

मैं इस मानचित्र के साथ काम कर रहा हूं यह बहुत अच्छा और उपयोग करने में आसान है लेकिन इसके साथ इसके मुद्दे आप इसे renderPartial के साथ उपयोग नहीं कर सकते हैं, यह बस प्रस्तुत नहीं करता है। केवल समाधान Iframe का उपयोग करना है। अजाक्स अद्यतन बस काम नहीं करता है।

+0

आपके उत्तर के लिए धन्यवाद। मैं वास्तव में दृश्य फ़ाइल पर सीधे रेंडरपार्टियल का उपयोग नहीं करता हूं। क्या डीओएम तैयार होने के बाद किसी भी तरह से EGMapContainer0 में हेरफेर करना संभव नहीं होगा? –

+0

मैंने इसका उपयोग नहीं किया है कि आप इसे आजमा सकते हैं और कृपया अपने निष्कर्ष दें। थानल्स –

संबंधित मुद्दे