Michael Geary wrote:
> I don't think this approach will work quite the way you'd like. In your
> example:
>
>> // I access my plugin via:
>> $("#myMap").Map({ <options hash> });
>>
>> // later I can access a public function on this object like:
>> $("#myMap").Map.recenter(x, y, dxy);
>
> Those two $("#myMap") calls are going to result in different jQuery objects.
> How does the recenter() method know it applies to the Map object you created
> earlier?
This is what I'm having trouble understanding.
So it sounds like Map object is not getting attached to the DOM object
be to the jQuery object that the DOM object is wrapped in. So if you
later search for the same DOM object, the jQuery result does not contain
the Map.
> OTOH, you could easily get this to work:
>
> // Create a map object for an element
> var map = $("#myMap").Map({ <options hash> });
> // later I can access a public function on this object like:
> map.recenter(x, y, dxy);
So I need to save the instance I create an then work on that.
> But before I make any more specific suggestions, does your Map object always
> relate to a single map as in your example, or could one Map object relate to
> multiple maps, e.g.
>
> // Get a Map object that controls every map with class anyMap
> var maps = $('.anyMap').Map();
> // Recenter all the maps
> maps.recenter( x, y, dxy );
It is conceivable that there will be multiple maps on a page and you
might want to recenter them all or not. I will also want to be about to
create a map and pass it to another map as a dependent map where it will
get control by its owner. For example create a small overview map the
shows the world and as the large map is zoom, it will tell the small map
to display a rectangle showing its current extents.
So ideally, I want a map object that I can attach to a DOM or jQuery
object, that will expose some public methods. I then will have other
controls on the page, that will manipulate the map object via these
public methods. The map will be interactive based on events, like
dragging the map, or selecting navigation tools on the map, or clicking
or double clicking on the map, etc.
I'm hoping to use other jQuery plugins for building this, like interface
Resizable and Dragable, etc.
I have a beasic shell I have started coding, but it has my head spinning.
http://imaptools.com:8081/jmap/test.html
I want to refactor/rewrite from scratch the mapping used in this:
http://imaptools.com:8081/map/demo.html
-Steve
> -Mike
>
>> From: Stephen Woodbridge
>>
>> OK, How much of this is right?
>>
>> jQuery.Map = {
>> // this is a public global attribute?
>> // ie: global across all instances of jQuery.Map
>> whatever : null,
>>
>> // a public function
>> init : function(options)
>> {
>> // this is the jQuery search collection
>> // self is a private pointer to the collection
>> var self = this;
>>
>> // another private variable scoped to the function
>> var _maph = 0;
>>
>> // an public attribute, accessed via $("#map").Map._maph
>> this._maph = 0;
>>
>> // a method, accessed via $("#map").Map.recenter(x,y,dxy)
>> this.recenter = function(x, y, dxy)
>> {
>> console.log("calling recenter()");
>>
>> };
>>
>> return this.each(
>> function(options) {
>>
>> // this is each respective object in the collection
>> // this is a DOM object not a jQuery object
>>
>> // here I can modify the DOM, bind events, etc
>>
>> };
>> };
>>
>> // This extends jQuery with my plugin
>> jQuery.fn.extend(
>> {
>> Map : jQuery.Map.init
>> }
>> );
>>
>> // I access my plugin via:
>> $("#myMap").Map({ <options hash> });
>>
>> // later I can access a public function on this object like:
>> $("#myMap").Map.recenter(x, y, dxy);
>>
>> Is this right? I probably have some terminology mixed up.
>>
>> -Steve
>>
>> _______________________________________________
>> jQuery mailing list
>> [email protected]
>> http://jquery.com/discuss/
>>
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/