imaffett / jqMobi-Plugins

Plugins for jqMobi
http://www.jqmobi.com
MIT License
24 stars 9 forks source link

Passing coords thru data-load create map function #2

Closed surfjedi closed 12 years ago

surfjedi commented 12 years ago

Im trying to create several panels. Rather than make a different function for each I'm trying to create one function to be called on data-load and pass in variables like map div ID, lat and long. But cant figure out how to pass in variable from data-load function

I am only displaying one map at a time. But would rather not make all the maps and add to the app loading time, and write a lot of functions all the same except for Coords.

my function snippet : function createMap(mapId, Lat, lng){ $(mapId).gmaps({zoom: 10,center: new google.maps.LatLng(lat, lng),mapTypeId: google.maps.MapTypeId.ROADMAP}); console.log(mapId, Lat, lng);

};

Is it possible to apss in variables in data-load? or is there an alternate method?

imaffett commented 12 years ago

This isn't the place for questions about jqMobi/jqUi - this should just be for the plugins. You can get support at http://jqmobi.com/ and click "bugs".

BUT, I will answer your question. You can not pass variables in directly, but data-onload and data-unload call the function and pass in the current div as a parameter, so you can do this.

<div id='whatever' class='panel' data-load='createMap' data-map-id='map4' data-map-lat='40.1' data-map-lng='40.1' data-load='createMap'>
</div>

Then in your function

function createMap(obj){
$obj=$(obj);
var mapId=$obj.data('map-id');
var lat=$obj.data("map-lat");
var lng=$obj.data("map-lng");
//the rest of your code
}
surfjedi commented 12 years ago

Thanks!