Google maps store locator changes hard initialization to dynamic

I am trying to modify this example http://storelocator.googlecode.com/git/examples/panel.html

javascript code is here: https://gist.github.com/2725336

The aspect I come across changes this:

MedicareDataSource.prototype.FEATURES_ = new storeLocator.FeatureSet(
  new storeLocator.Feature('Wheelchair-YES', 'Wheelchair access'),
  new storeLocator.Feature('Audio-YES', 'Audio')
);

to create a FeatureSet from a function, so for example, I have this function that parses a JSON object

WPmmDataSource.prototype.setFeatures_ = function(json) {
    var features = [];

    // convert features JSON to js object
    var rows = jQuery.parseJSON(json);

    // iterate through features collection
    jQuery.each(rows, function(i, row){

    var feature = new storeLocator.Feature(row.slug + '-YES', row.name)

    features.push(feature);
    });

    return  new storeLocator.FeatureSet(features);
    };

then change the first code snippet to something like

WPmmDataSource.prototype.FEATURES_ = this.setFeatures_(wpmm_features);

which returns an error:

Uncaught TypeError: Object [object Window] has no method 'setFeatures_'
+5
source share
1 answer

I think you just need to make some changes to the method WPmmDataSource.prototypeand yours setFeatures_:

WPmmDataSource.prototype = {
    FEATURES_ : null,        
    setFeatures_ : function( json ) {
        //Set up an empty FEATURES_ FeatureSet
        this.FEATURES_ = new storeLocator.FeatureSet();
        //avoid the use of "this" within the jQuery loop by creating a local var
        var featureSet = this.FEATURES_;
        // convert features JSON to js object
        var rows = jQuery.parseJSON( json );
        // iterate through features collection
        jQuery.each( rows, function( i, row ) {
            featureSet.add(
                new storeLocator.Feature( row.slug + '-YES', row.name ) );
        });
    }
}

, setFeatures_; FEATURES_. , :

WPmmDataSource.prototype.FEATURES_ = this.setFeatures_(wpmm_features);

. , , WPmmDataSource, :

var wpmd = new WPmmDataSource( /* whatever options, etc. you want */ );
wpmd.setFeatures_( json );
// Thereafter, wpmd will have its FEATURES_ set

, , , . , -

+1

All Articles