I'm trying to modify this example http://storelocator.googlecode.com/git/examples/panel.html
the javascript code is here: https://gist.github.com/2725336
the aspect I'm having difficulties with is changing this:
MedicareDataSource.prototype.FEATURES_ = new storeLocator.FeatureSet(
new storeLocator.Feature('Wheelchair-YES', 'Wheelchair access'),
new storeLocator.Feature('Audio-YES', 'Audio')
);
to create the FeatureSet from a function, so for example I have this function which 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);
};
so 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_'
I think you just have to make some changes to the WPmmDataSource.prototype
and your setFeatures_
method:
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 ) );
});
}
}
And with this, you don't have to do the assignment by returning a value from setFeatures_
; it has direct access to the FEATURES_
member. So the line:
WPmmDataSource.prototype.FEATURES_ = this.setFeatures_(wpmm_features);
is no longer necessary. This also means that later, when you have created an instance of WPmmDataSource
, your code can work like this:
var wpmd = new WPmmDataSource( /* whatever options, etc. you want */ );
wpmd.setFeatures_( json );
// Thereafter, wpmd will have its FEATURES_ set
I'm not exactly sure what you are trying to achieve, but I believe this will get you over the hurdle of your current stall. I hope this gets you moving forward -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With