Filtered Map Search Events

Login or register to post comments
6 replies [Last post]
scottux's picture
Offline
Joined: 11/07/2008

Okay, here is my scenario.

I have a qcontrol basically the QGoogleMap plugin with a bunch of QListControls. I have attached events to each qlistcontrol that should change a query string that is used to create an xml file full of markers that is used in the map.

My issue is one of event order. I need for the following to happen on the list change event:
1.) clear the previous query 2.) the query string gets changed to reflect the new list options 3.) the map gets reloaded with the new query string and loads the markers

I am using a combination of PHP and Javascript and one is writing the other and then firing events at different times and I need someone to clue me in on a better method for this. I am leaning towards more Javascript and less PHP, and I just need to know where the query string needs to be changed in order to get the events to work in the proper order so that when I change a variable, it affects the map directly. At the moment, the change event fires the previous query and then sets up the next query.

scottux's picture
Offline
Joined: 11/07/2008

Here is the code in it's current wacky state.

<?php
class QFilteredMapSearch extends QPanel {
    protected
$blnUseAjax = true;
    protected
$strSearchQuery;
    protected
$lblTestString;

    protected
$lstMinBaths;
    protected
$lstMaxBaths;
   
    protected
$lstMinBeds;
    protected
$lstMaxBeds;
   
    protected
$lstPropertyTypes;
   
// Local Areas, should be a user and search friendly list, not a raw list from the MLS
   
protected $lstLocalAreas;
   
// Minimum price range
   
protected $lstMinPrice;
   
// maximum price range
   
protected $lstMaxPrice;
   
// Set up a Spinner animation for impatient ADD sufferers
   
protected $objDefaultWaitIcon;

   
/**
     *    Google Map API Key
     *    @var    string
     **/
   
protected $_MapKey = '';

   
/**
     *    Is data provided by a GPS Sensor?
     *    @var    boolean
     **/
   
protected $_MapSensor = "false";
   
   
   
/**
     *    Default Map Sizes
     *    @var    int
     **/
   
protected $_MapWidth = '470';
    protected
$_MapHeight = '300';
   
   
/**
     *    Default Map Zoom Level
     *    @var    int
     **/
   
protected $_MapZoom ='9';

    protected
$_MapObjectArray = array();
   
/**
     *    Default Marker Icon Color Scheme
     *    @var    string
     **/
   
protected $_IconColor = 'YOSEMITE';
   
   
   
   
/**
     *    Array of Marker Icon Color Schemes
     *    @var    array
     **/
   
protected $_IconColorArr = array(
                           
'PACIFICA'        =>    'pacifica',
                           
'YOSEMITE'        =>    'yosemite',
                           
'MOAB'            =>    'moab',
                           
'GRANITE_PINE'    =>    'granitepine',
                           
'DESERT_SPICE'    =>    'desertspice',
                           
'CABO_SUNSET'    =>    'cabosunset',
                           
'TAHITI_SEA'    =>    'tahitisea',
                           
'POPPY'            =>    'poppy',
                           
'NAUTICA'        =>    'nautica',
                           
'DEEP_JUNGLE'    =>    'deepjungle',
                           
'SLATE'            =>    'slate'
                           
);

   
/**
     *    Default Marker Icon Style
     *    @var    string
     **/
   
protected $_IconStyle = 'HOUSE';

   
/**
     *    Array of Marker Icon Styles
     *    @var    array
     **/
   
protected $_IconStyleArr = array(
       
'FLAG'        =>array(
                       
'DIR'                =>    'flag',
                       
'ICON_W'            =>    31,
                       
'ICON_H'            =>    35,
                       
'ICON_ANCHR_W'        =>    4,
                       
'ICON_ANCHR_H'        =>    27,
                       
'INFO_WIN_ANCHR_W'    =>    8,
                       
'INFO_WIN_ANCHR_H'    =>    3
       
),
   
       
'GT_FLAT'    =>array(
                       
'DIR'                =>    'traditionalflat',
                       
'ICON_W'            =>    34,
                       
'ICON_H'            =>    35,
                       
'ICON_ANCHR_W'        =>    9,
                       
'ICON_ANCHR_H'        =>    23,
                       
'INFO_WIN_ANCHR_W'    =>    19,
                       
'INFO_WIN_ANCHR_H'    =>    0
       
),
   
       
'GT_PILLOW'    =>array(
                       
'DIR'                =>'traditionalpillow',
                       
'ICON_W'            =>34,
                       
'ICON_H'            =>35,
                       
'ICON_ANCHR_W'        =>9,
                       
'ICON_ANCHR_H'        =>23,
                       
'INFO_WIN_ANCHR_W'    =>19,
                       
'INFO_WIN_ANCHR_H'    =>0
       
),
   
       
'HOUSE'        =>array(
                       
'DIR'                =>'house',
                       
'ICON_W'            =>24,
                       
'ICON_H'            =>14,
                       
'ICON_ANCHR_W'        =>9,
                       
'ICON_ANCHR_H'        =>13,
                       
'INFO_WIN_ANCHR_W'    =>9,
                       
'INFO_WIN_ANCHR_H'    =>0
       
),
   
       
'PIN'        =>array(
                       
'DIR'                =>'pin',
                       
'ICON_W'            =>31,
                       
'ICON_H'            =>24,
                       
'ICON_ANCHR_W'        =>17,
                       
'ICON_ANCHR_H'        =>22,
                       
'INFO_WIN_ANCHR_W'    =>17,
                       
'INFO_WIN_ANCHR_H'    =>0
       
),
   
       
'PUSH_PIN'    =>array(
                       
'DIR'                =>'pushpin',
                       
'ICON_W'            =>40,
                       
'ICON_H'            =>41,
                       
'ICON_ANCHR_W'        =>7,
                       
'ICON_ANCHR_H'        =>38,
                       
'INFO_WIN_ANCHR_W'    =>26,
                       
'INFO_WIN_ANCHR_H'    =>1
       
),
   
       
'STAR'        =>array(
                       
'DIR'                =>'star',
                       
'ICON_W'            =>29,
                       
'ICON_H'            =>39,
                       
'ICON_ANCHR_W'        =>15,
                       
'ICON_ANCHR_H'        =>15,
                       
'INFO_WIN_ANCHR_W'    =>19,
                       
'INFO_WIN_ANCHR_H'    =>7
   
));

   
/**
     *    Default Map Control Style
     *    @var    string
     **/
   
protected $_MapControl = 'SMALL_PAN_ZOOM';

   
/**
     *    Arrays of Map Control Styles
     *    @var    array
     **/
   
protected $_MapControlArr = array(
       
'NONE',
       
'SMALL_PAN_ZOOM',
       
'LARGE_PAN_ZOOM',
       
'LARGE_PAN_ZOOM_3D',
       
'SMALL_ZOOM',
       
'SMALL_ZOOM_3D'
   
);

   
/**
     *    Enable/Disable Map Continuous Zooming
     *    @var    boolean
     **/
   
public $_ContinuousZoom = FALSE;

   
/**
     *
     *    @var    booleanEnable/Disable Map Double Click Zooming
     **/
   
public $_DoubleClickZoom = TRUE;

   
/**
     *
     *    @var    booleanEnable/Disable Map Scroll Wheel Zooming
     **/
   
public $_ScrollWheelZoom = TRUE;

   
/**
     *    Enable/Disable Map Scale (Mi/Km)
     *    @var    boolean
     **/
   
public $_MapScale = FALSE;

   
/**
     *    Enable/Disable Map Inset
     *    @var    boolean
     **/
   
public $_MapInset = FALSE;

   
/**
     *    Enable/Disable Map Type (Map/Satellite/Hybrid)
     *    @var    boolean
     **/
   
public $_MapType = FALSE;

   
/**
     * If this control needs to update itself from the $_POST data, the logic to do so
     * will be performed in this method.
     */
   
public function ParsePostData() {}

   
/**
     *    If this control has validation rules, the logic to do so
     * will be performed in this method.
     * @return boolean
     */
   
public function Validate() {return true;}


   
/**
     *    QFilteredMapSearch Constructor
     *    @return    void
     **/
   
public function __construct($objParentObject, $strControlId = null) {
        try {
           
parent::__construct($objParentObject, $strControlId);
        } catch (
QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
       
$objParentObject->AddJavascriptFile('http://maps.google.com/maps?file=api&amp;v=2&amp;sensor='.$this->_MapSensor.'&amp;key='.$this->_MapKey);
       
QApplication::ExecuteJavascript($this->BuildJS());
       
QApplication::ExecuteJavascript("window.onunload = function() { GUnload(); }");
       
$this->CreateMapFilters();
       
$this->SetupFilterActions();
       
$this->lblTestString = new QLabel($this);
       
$this->lblTestString->Text="Test";
    }

   
/////////////////////////
    // Public Properties: SET
    /////////////////////////
   
public function __set($strName, $mixValue) {
       
$this->blnModified = true;

        switch (
$strName) {
           
/**
             *    Set Map Width
             */
           
case 'MapWidth':
                try {
                   
$this->_MapWidth = QType::Cast($mixValue, QType::Integer);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Set Map Zoom Level
                 */
           
case 'MapZoom' :
                try {
                   
$this->_MapZoom = QType::Cast($mixValue, QType::Integer);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Set Map hHeight
                 */
           
case 'MapHeight' :
                try {
                   
$this->_MapHeight = QType::Cast($mixValue, QType::Integer);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Set Marker Icon Color Scheme
                 *     options{'PACIFICA','YOSEMITE','MOAB','GRANITE_PINE','DESERT_SPICE',
                 *        'CABO_SUNSET','TAHITI_SEA','POPPY','NAUTICA','SLATE'}
                 *     default = 'PACIFICA'
                 */
           
case 'IconColor' :
                try {
                   
$this->_IconColor = QType::Cast($mixValue, QType::String);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Set Marker Icon Style Scheme
                 *     options{'FLAG','GT_FLAT','GT_PILLOW','HOUSE','PIN','PUSH_PIN','STAR'}
                 *     default = 'GT_FLAT'
                 */
           
case 'IconStyle' :
                try {
                   
$this->_IconStyle = QType::Cast($mixValue, QType::String);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Set Map Control Type
                 *     options{'NONE','SMALL_PAN_ZOOM','LARGE_PAN_ZOOM','SMALL_ZOOM'}
                 *     default = 'SMALL_PAN_ZOOM'
                 */
           
case 'MapControl' :
                try {
                   
$this->_MapControl = QType::Cast($mixValue, QType::String);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Enable/Disable Continuous Zoom Default=FALSE
                 */
           
case 'ContinuousZoom' :
                try {
                   
$this->_ContinuousZoom = QType::Cast($mixValue, QType::Boolean);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Enable/Disable Double-Click Zoom Default=FALSE
                 */
           
case 'DoubleClickZoom' :
                try {
                   
$this->_DoubleClickZoom = QType::Cast($mixValue, QType::Boolean);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Enable/Disable Map Scale Default=FALSE
                 */
           
case 'MapScale' :
                try {
                   
$this->_MapScale = QType::Cast($mixValue, QType::Boolean);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Enable/Disable Map Inset Default=FALSE
                 */
           
case 'MapInset' :
                try {
                   
$this->_MapInset = QType::Cast($mixValue, QType::Boolean);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Enable/Disable Map Type Default=FALSE
                 */
           
case 'MapType' :
                try {
                   
$this->_MapType = QType::Cast($mixValue, QType::Boolean);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Set Google Maps API KEY
                 */
           
case 'MapKey' :
                try {
                   
$this->_MapKey = QType::Cast($mixValue, QType::String);
                   
$this->strJavaScripts = 'http://maps.google.com/maps?file=api&amp;v=2&amp;sensor='.$this->_MapSensor.'&amp;key='.$this->_MapKey;
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }

               
/**
                 *    Set Whether a GPS Sensor is used or not.
                 */
           
case 'MapSensor' :
                try {
                   
$this->_MapSensor = QType::Cast($mixValue, QType::Boolean);
                    break;
                } catch (
QInvalidCastException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }
                if(
$this->_MapSensor == TRUE) {
                   
$this->_MapSensor = "true";
                }else{
                   
$this->_MapSensor = "false";
                }

            default:
                try {
                   
parent::__set($strName, $mixValue);
                } catch (
QCallerException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }
                break;
        }
    }

   
/////////////////////////
    // Public Properties: GET
    /////////////////////////
   
public function __get($strName)    {
        switch (
$strName) {
            case
'MapKey': return $this->_MapKey;
            default:
                try {
                    return
parent::__get($strName);
                }
                catch (
QCallerException $objExc) {
                   
$objExc->IncrementOffset();
                    throw
$objExc;
                }
        }
    }

   
/**
     *    Add Address to the list
     **/
   
public function AddAddress($address, $info = null) {
       
$this->_Index++;
       
$this->_MapObjectArray[$this->_Index]['address'] = $address;
       
$this->_MapObjectArray[$this->_Index]['popup'] = $info;
    }

   
/**
     *  Add Coords
     *
     *  This function is more accurate than AddAddress
     *  (AddAddress when fails will not mark a point on the map to match the listed item).
     **/
   
public function AddCoords($lat,$lon, $info = null) {
       
$this->_Index++;
       
$coords = $lat.','.$lon;
       
$this->_MapObjectArray[$this->_Index]['coords'] = $coords;
       
$this->_MapObjectArray[$this->_Index]['popup'] = $info;
    }

   
/**
     *    Generate JS Code
     **/
   
public function BuildJS() {
       
       
$cnt_add = count($this->_MapObjectArray);

       
$color = $this->_IconColorArr[$this->_IconColor];
       
$dir = $this->_IconStyleArr[$this->_IconStyle]['DIR'];

       
$icon_w  = $this->_IconStyleArr[$this->_IconStyle]['ICON_W'];
       
$icon_h  = $this->_IconStyleArr[$this->_IconStyle]['ICON_H'];

       
$icon_anchr_w  = $this->_IconStyleArr[$this->_IconStyle]['ICON_ANCHR_W'];
       
$icon_anchr_h  = $this->_IconStyleArr[$this->_IconStyle]['ICON_ANCHR_H'];

       
$info_win_anchr_w  = $this->_IconStyleArr[$this->_IconStyle]['INFO_WIN_ANCHR_W'];
       
$info_win_anchr_h  = $this->_IconStyleArr[$this->_IconStyle]['INFO_WIN_ANCHR_H'];
       
       
// start of JS
        // Write Begin CDATA
       
$ret = "/* <![CDATA[ */\n";
       
// Declare map and marker icons
       
$ret .= "var map; \n";
       
$ret .= "var icon = new GIcon();\n";
       
$ret .= "icon.image = 'http://google.webassist.com/google/markers/$dir/$color.png';\n";
       
$ret .= "icon.shadow = 'http://google.webassist.com/google/markers/$dir/shadow.png';\n";
       
$ret .= "icon.iconSize = new GSize($icon_w,$icon_h);\n";
       
$ret .= "icon.shadowSize = new GSize($icon_w,$icon_h);\n";
       
$ret .= "icon.iconAnchor = new GPoint($icon_anchr_w,$icon_anchr_h);\n";
       
$ret .= "icon.infoWindowAnchor = new GPoint($info_win_anchr_w,$info_win_anchr_h);\n";
       
$ret .= "icon.printImage = 'http://google.webassist.com/google/markers/$dir/$color.gif';\n";
       
$ret .= "icon.mozPrintImage = 'http://google.webassist.com/google/markers/$dir/{$color}_mozprint.png';\n";
       
$ret .= "icon.printShadow = 'http://google.webassist.com/google/markers/$dir/shadow.gif'; \n";
       
$ret .= "icon.transparent = 'http://google.webassist.com/google/markers/$dir/{$color}_transparent.png';\n\n";
       
       
$ret .= "if(GBrowserIsCompatible()) {\n";
       
$ret .= "    window.onload = function() { \n";
       
       
$ret .= "        map = new GMap2(document.getElementById('map_canvas'));\n";
       
       
// handle map continuous zooming
       
$ret .= ($this->_ContinuousZoom==TRUE)?"            map.enableContinuousZoom();\n":"";

       
// handle map mouse scroll wheel zooming
       
$ret .= ($this->_ScrollWheelZoom==TRUE)?"        map.enableScrollWheelZoom();\n":"";

       
// handle map double click zooming
       
$ret .= ($this->_DoubleClickZoom==TRUE)?"        map.enableDoubleClickZoom();\n":"";

       
// handle map controls
       
$mapCtrl = "";
        switch (
$this->_MapControl) {
            case
'NONE':
               
$mapCtrl = "";
                break;

            case
'SMALL_PAN_ZOOM':
               
$mapCtrl = "map.addControl(new GSmallMapControl());\n";
                break;

            case
'LARGE_PAN_ZOOM':
               
$mapCtrl = "map.addControl(new GLargeMapControl());\n";
                break;

            case
'LARGE_PAN_ZOOM_3D':
               
$mapCtrl = "map.addControl(new GLargeMapControl3D());\n";
                break;

            case
'SMALL_ZOOM':
               
$mapCtrl = "map.addControl(new GSmallZoomControl());\n";
                break;

            case
'SMALL_ZOOM_3D':
               
$mapCtrl = "map.addControl(new GSmallZoomControl3D());\n";
                break;

            default;
            break;

        }
// end switch
       
$ret .= "        $mapCtrl";

       
// handle map scale (mi/km)
       
$ret .= ($this->_MapScale==TRUE)?"        map.addControl(new GScaleControl());\n":"";

       
// handle map type (map/satellite/hybrid)
       
$ret .= ($this->_MapType==TRUE)?"        map.addControl(new GMapTypeControl());\n":"";

       
// handle map inset
       
$ret .= ($this->_MapInset==TRUE)?"        map.addControl(new GOverviewMapControl());\n":"";
       
       
// Center Map
       
$ret .= "        map.setCenter( new GLatLng (32.783333, -79.933333), $this->_MapZoom );\n";
       
       
// A function to read the data
       
$ret .= 'function readMap(query) {
           
            map.clearOverlays();
            // hide the info window, otherwise it still stays open where the removed marker used to be
            map.getInfoWindow().hide();
            var url="/property/search?"+query;
            GDownloadUrl(url, function(data, responseCode) {
                var xmlDoc = GXml.parse(data);
                // obtain the array of markers and loop through it
                var markers = xmlDoc.documentElement.getElementsByTagName("marker");
   
                for (var i = 0; i < markers.length; i++) {
                    // obtain the attribues of each marker
                    var lat = parseFloat(markers[i].getAttribute("lat"));
                    var lng = parseFloat(markers[i].getAttribute("lng"));
                    var point = new GLatLng(lat,lng);
                    var htmlstring = "<strong>" + markers[i].getAttribute("address") + "</strong><br />" + markers[i].getAttribute("city") + ", " + markers[i].getAttribute("state") + " " + markers[i].getAttribute("zip") + "<br />" + markers[i].getAttribute("price");
                    // create the marker
                    var marker = createMarker(point, htmlstring);
                    map.addOverlay(marker);
                }
            });
        }'
;
       
$ret .=    "function createMarker(point, html) {
            var marker = new GMarker(point, icon);
           
            GEvent.addListener(marker, 'click', function() {
                marker.openInfoWindowHtml(html);
            });
              return marker;
        }"
;
       
// Call readMap() on page load with a default query.
       
$ret .=    'readMap("minPrice=75000&maxPrice=1000000&minBeds=2&minBaths=1&maxBaths=3&maxBeds=6");';
       
       
$ret .= "    } // end load function \n\n";
       
       
// Write End if compatible
       
$ret .= "} // end if compatible \n\n";
       
// Write End CDATA
       
$ret .= "/* ]]> */\n";
        return
$ret;
    }

   
/**
     *    Create the Filter Options for the Map (static)
     * @return: string
     **/
   
public function CreateMapFilters() {
       
$this->lstMinBeds = new QListBox($this, 'minBedsSelect');
       
$this->lstMinBeds->Name = QApplication::Translate('Min. Beds');
       
$this->lstMinBeds->AddItem('Min # of Beds', null);
        for (
$i=1;$i<=6;$i++) {
           
$this->lstMinBeds->AddItem( $i.' or more', $i );
        }

       
$this->lstMinBaths = new QListBox($this, 'minBathsSelect');
       
$this->lstMinBaths->Name = QApplication::Translate('Min. Baths');
       
$this->lstMinBaths->AddItem('Min # of Baths', null);
        for (
$i=1;$i<=4;$i++) {
           
$this->lstMinBaths->AddItem($i.' or more', $i);
        }
           
       
$this->lstMaxBeds = new QListBox($this, 'maxBedsSelect');
       
$this->lstMaxBeds->Name = QApplication::Translate('Max. Beds');
       
$this->lstMaxBeds->AddItem('Max # of Beds', null);
        for (
$i=1;$i<=6;$i++) {
           
$this->lstMaxBeds->AddItem( $i.' or more', $i );
        }

       
$this->lstMaxBaths = new QListBox($this, 'maxBathsSelect');
       
$this->lstMaxBaths->Name = QApplication::Translate('Max. Baths');
       
$this->lstMaxBaths->AddItem('Max # of Baths', null);
        for (
$i=1;$i<=4;$i++) {
           
$this->lstMaxBaths->AddItem($i.' or more', $i);
        }

       
// Property Type Select
       
$this->lstPropertyTypes = new QListBox($this, 'propertyTypeSelect');
       
$this->lstPropertyTypes->Name = QApplication::Translate('Property Types');
       
$this->lstPropertyTypes->AddItem('Select a Property Type', null);
       
$this->lstPropertyTypes->AddItem('Single Family Attached', 'SFA');
       
$this->lstPropertyTypes->AddItem('Single Family Detached', 'SFD');
       
$this->lstPropertyTypes->AddItem('Vacant Land', 'VAC');
       
       
// Local Areas Select
       
$this->lstLocalAreas = new QListBox($this, 'localAreaSelect');
       
$this->lstLocalAreas->Name = QApplication::Translate('Local Area');
       
$this->lstLocalAreas->AddItem('All Local Areas', null);
       
$this->lstLocalAreas->AddItem('Charleston','Charleston');
       
$this->lstLocalAreas->AddItem('James Island','JamesIsland');

       
$this->lstMinPrice = new QListBox($this, 'minPriceSelect');
       
$this->lstMinPrice->Name = QApplication::Translate('Min. Price');
       
$this->lstMinPrice->AddItem('Min. Price', null);
        for (
$i=50000;$i<=1000000;$i=$i+50000) {
           
$this->lstMinPrice->AddItem("$".number_format($i), $i);
        }

       
$this->lstMaxPrice = new QListBox($this, 'maxPriceSelect');
       
$this->lstMaxPrice->Name = QApplication::Translate('Max. Price');
       
$this->lstMaxPrice->AddItem('Max. Price', null);
        for (
$i=100000;$i<=2000000;$i=$i+50000) {
           
$this->lstMaxPrice->AddItem("$".number_format($i), $i);
        }
       
$this->objDefaultWaitIcon = new QWaitIcon($this);
    }

    protected function
SetupFilterActions() {
       
// In case any actions are setup already, let's remove them
       
$this->lstMinBaths->RemoveAllActions('onchange');
       
$this->lstMaxBaths->RemoveAllActions('onchange');
       
$this->lstMinBeds->RemoveAllActions('onchange');
       
$this->lstMaxBeds->RemoveAllActions('onchange');
       
$this->lstMinPrice->RemoveAllActions('onchange');
       
$this->lstMaxPrice->RemoveAllActions('onchange');
       
$this->lstPropertyTypes->RemoveAllActions('onchange');
       
$this->lstLocalAreas->RemoveAllActions('onchange');
           
       
// Notice how, instead of Server or Ajax actions, we use Server-
        // or Ajax- CONTROL actions.  This is because the actual PHP method
        // we want to run is in this CONTROL, instead of on the form.  We must specify
        // which control has the method we want to run, or in this case, $this.
           
$this->lstMinBaths->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstMinBaths_Change'));
           
$this->lstMaxBaths->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstMaxBaths_Change'));
           
$this->lstMinBeds->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstMinBeds_Change'));
           
$this->lstMaxBeds->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstMaxBeds_Change'));
           
$this->lstMinPrice->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstMinPrice_Change'));
           
$this->lstMaxPrice->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstMaxPrice_Change'));
           
$this->lstPropertyTypes->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstPropertyTypes_Change'));
           
$this->lstLocalAreas->AddAction(new QChangeEvent(), new QAjaxControlAction($this, 'lstLocalAreas_Change'));
           
           
$this->lstMinBaths->AddAction(new QChangeEvent(), new QJavaScriptAction("readMap('".htmlentities($this->strSearchQuery)."')"));
           
$this->lstMaxBaths->AddAction(new QChangeEvent(), new QJavaScriptAction("readMap('".htmlentities($this->strSearchQuery)."')"));
           
$this->lstMinBeds->AddAction(new QChangeEvent(), new QJavaScriptAction("readMap('".htmlentities($this->strSearchQuery)."')"));
           
$this->lstMaxBeds->AddAction(new QChangeEvent(), new QJavaScriptAction("readMap('".htmlentities($this->strSearchQuery)."')"));
           
$this->lstMinPrice->AddAction(new QChangeEvent(), new QJavaScriptAction("readMap('".htmlentities($this->strSearchQuery)."')"));
           
$this->lstMaxPrice->AddAction(new QChangeEvent(), new QJavaScriptAction("readMap('".htmlentities($this->strSearchQuery)."')"));
    }

   
// Event Handlers -- Because these will be called by the Form (which triggers ALL events), these
    // MUST be declared as PUBLIC.
   
public function lstMinBaths_Change($strFormId, $strControlId, $strParameter) {
       
$this->UpdateQueryString();
       
$this->SetupFilterActions();
       
$this->lblTestString->Text="Changed Min Baths";
    }

    public function
lstMaxBaths_Change($strFormId, $strControlId, $strParameter) {
       
$this->UpdateQueryString();
       
$this->SetupFilterActions();
       
$this->lblTestString->Text="Changed Max Baths";
    }

    public function
lstMinBeds_Change($strFormId, $strControlId, $strParameter) {
       
$this->UpdateQueryString();
       
$this->SetupFilterActions();
       
$this->lblTestString->Text="Changed Min Beds";
    }

    public function
lstMaxBeds_Change($strFormId, $strControlId, $strParameter) {
       
$this->UpdateQueryString();
       
$this->SetupFilterActions();
       
$this->lblTestString->Text="Changed Max Beds";       
    }

    public function
lstMinPrice_Change($strFormId, $strControlId, $strParameter) {
       
$this->UpdateQueryString();
       
$this->SetupFilterActions();
       
$this->lblTestString->Text="Changed Min Price. New Query: ".$this->strSearchQuery;
    }

    public function
lstMaxPrice_Change($strFormId, $strControlId, $strParameter) {
       
$this->UpdateQueryString();
       
$this->SetupFilterActions();
       
$this->lblTestString->Text="Changed Max Price. New Query: ".$this->strSearchQuery;
       
    }

    public function
lstPropertyTypes_Change($strFormId, $strControlId, $strParameter) {
       
$this->UpdateQueryString();
       
$this->SetupFilterActions();
       
$this->lblTestString->Text="Changed Property Type";
    }

    public function
lstLocalAreas_Change($strFormId, $strControlId, $strParameter) {
       
$this->UpdateQueryString();
       
$this->SetupFilterActions();
       
$this->lblTestString->Text="Changed Local Area";
    }

    public function
UpdateQueryString() {
       
$this->strSearchQuery = "minPrice=".$this->lstMinPrice->SelectedValue."&maxPrice=".$this->lstMaxPrice->SelectedValue."&minBeds=".$this->lstMinBeds->SelectedValue."&minBaths=".$this->lstMinBaths->SelectedValue."&maxBaths=".$this->lstMaxBaths->SelectedValue."&maxBeds=".$this->lstMaxBeds->SelectedValue;
    }
   
   
/**
     *    Generate Map HTML (static)
     * @return: string (The Google Map)
     **/
   
public function GetControlHtml() {
       
       
// Lets get Style attributes
       
$strStyle = $this->GetStyleAttributes();

       
// Lets get all the other attributes -- because we have actions defined internally,
        // we specifically do not want to include externally defined actions.  Therefore,
        // we pass in "false" for the optional blnIncludeAction parameter
       
$strAttributes = $this->GetAttributes(true, false);
       
$strPropertyTypes = $this->lstPropertyTypes->Render(false);
       
$strMinBeds $this->lstMinBeds->Render(false);
       
$strMinBaths = $this->lstMinBaths->Render(false);
       
$strMaxBeds $this->lstMaxBeds->Render(false);
       
$strMaxBaths = $this->lstMaxBaths->Render(false);
       
$strLocalAreas = $this->lstLocalAreas->Render(false);
       
$strMinPrice = $this->lstMinPrice->Render(false);
       
$strMaxPrice = $this->lstMaxPrice->Render(false);
       
$objWaitIcon = $this->objDefaultWaitIcon->Render(false);
       
$strTestString = $this->lblTestString->Render(false);

        return
sprintf('<div id="%s" %s%s><div id="map_canvas" style="width: %spx; height: %spx;"></div>%s%s%s%s%s%s%s%s%s%s</div>',
           
$this->strControlId,
           
$strStyle,
           
$strAttributes,
           
$this->_MapWidth,
           
$this->_MapHeight,
           
$strPropertyTypes,
           
$strMinBeds,
           
$strMaxBeds,
           
$strMinBaths,
           
$strMaxBaths,
           
$strLocalAreas,
           
$strMinPrice,
           
$strMaxPrice,
           
$objWaitIcon,
           
$strTestString
       
);
    }
}
?>

alex94040's picture
Online
Joined: 11/06/2008

Scott - I've done a project before where I would have controls next to a Google Map, and clicking on those controls would have an effect on the map. I'll send you some stuff via email.

Offline
Joined: 06/04/2010

hello Alex94040,
Can you send me project with google maps please?
Thanks.

alex94040's picture
Online
Joined: 11/06/2008

The google maps code was wrapped up nicely by scott into a plugin: see it in action here - http://examples.qcu.be/assets/plugins/QGoogleMap/example/QGoogleMapExamp...

Download it here: http://trac.qcu.be/projects/qcubed/wiki/plugins

Offline
Joined: 06/04/2010

I know, but this plugin is not suited to version 3 of google maps.

scottux's picture
Offline
Joined: 11/07/2008

I have redone a lot of the map code to extend it for eracharlestonrealty.com - if you would like to send me a PM with your email, I can send you some code snippets that may help.

On my todo list is updating the google maps plugin hosted here. I just have a very long todo list.