Jump to content

combining functions.


knowram

Recommended Posts

I am new to javascript and don't use it much at all but i am trying to combine these 2 functions. Can someone please take pity on me and tell me what I am doing wrong. Thank you in advance.

 

I am working with google's API the first function looks like this

function importanceOrder (marker,b) {
        return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance*1000000;
    }

 

and is used in this code

var marker = new GMarker(new GLatLng(43.90,-78.5),{zIndexProcess:importanceOrder});
      marker.importance = 2;
      map.addOverlay(marker);

 

 

the second function looks like this

function createMarker(point,html,ba,ov) {

        var mylabel = {"url":overlay[ov], "anchor":new GLatLng(4,4), "size":new GSize(12,12)};
        var Icon = new GIcon(G_DEFAULT_ICON, background[ba], mylabel)

        var marker = new GMarker(point,Icon);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }

 

and is used in this code

var point = new GLatLng(43.90,-78.0);
        var marker = createMarker(point,\''.$Cap.'\',\'Up\',\'A\');
        map.addOverlay(marker);

 

And this is my attempt to put the 2 of them together.

function createMarker(point,html,ba,ov,b) {

        var mylabel = {"url":overlay[ov], "anchor":new GLatLng(4,4), "size":new GSize(12,12)};
        var Icon = new GIcon(G_DEFAULT_ICON, background[ba], mylabel)

        var marker = new GMarker(point,Icon,{zIndexProcess:importanceOrder});
         marker.importance = b;
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html)
        });
       return marker;
      }

 

and the code trying to use it

var point = new GLatLng(43.90,-78.0);
        var marker = createMarker(point,\''.$Cap.'\',\'Up\',\'A\',\'2\');
        map.addOverlay(marker);

 

 

Thank you again for any help

 

 

 


 

 

 

 

Link to comment
Share on other sites

Based on the GMarkerOptions API, I believe what you want to do is pass the Icon and zIndexProcess to the GMarker constructor as an object. Try something like this and see if it works (notice especially lines 6-9 where the new GMarker is created):

function createMarker(point, html, ba, ov, b)
{
var mylabel = {"url": overlay[ov], "anchor":new GLatLng(4, 4), "size": new GSize(12, 12));
var Icon = new GIcon(G_DEFAULT_ICON, background[ba], mylabel);

var marker = new GMarker(point, {
	icon: Icon,
	zIndexProcess: importanceOrder
});
marker.importance = b;

GEvent.addListener(marker, "click", function()
{
	marker.openInfoWindowHtml(html);
});
return marker;
}

var point = new GLatLng(43.90, -78.0);
var marker = createMarker(point, 'asdf', 'Up', 'A', 2);
map.addOverlay(marker);

 

Hope this helps!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.