Draw cross in map center

1,154 views
Skip to first unread message

Jurgis Stepanovs

unread,
Oct 18, 2010, 8:21:05 AM10/18/10
to Google Maps JavaScript API v3

I need solution how to draw a cross in Javascript API at map center,
and update it
when ever map bounds, and zoom changes?

I need to hold cross at map center on refresh and all other map
events.

Jurgis

Chris Broadfoot

unread,
Oct 18, 2010, 10:59:53 AM10/18/10
to google-map...@googlegroups.com
Lots of ways to do this. Here's one way:

    var marker = new google.maps.Marker({
        map: map,
        icon: 'cross.png'
    });
    marker.bindTo('position', map, 'center');

You could also probably do this with a KML screen overlay (though I am not 100% familiar with KML).

Chris


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Nathan Raley

unread,
Oct 18, 2010, 12:43:36 PM10/18/10
to google-map...@googlegroups.com
And if you don't have an image you can draw two polylines.

Jurgis Stepanovs

unread,
Oct 18, 2010, 2:02:43 PM10/18/10
to Google Maps JavaScript API v3
Thanks very much! :) I will prefere with png file :) Jurgis

On 18 okt., 17:59, Chris Broadfoot <c...@google.com> wrote:
> Lots of ways to do this. Here's one way:
>
>     var marker = new google.maps.Marker({
>         map: map,
>         icon: 'cross.png'
>     });
>     marker.bindTo('position', map, 'center');
>
> You could also probably do this with a KML screen overlay (though I am not
> 100% familiar with KML).
>
> Chris
>
> On Mon, Oct 18, 2010 at 11:21 PM, Jurgis Stepanovs <
>
>
>
> jurgis.stepan...@gmail.com> wrote:
>
> >  I need solution how to draw a cross in Javascript API  at map center,
> > and update it
> > when ever map bounds, and zoom changes?
>
> >  I need to hold cross at map center on refresh and all other map
> > events.
>
> > Jurgis
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Maps JavaScript API v3" group.
> > To post to this group, send email to
> > google-map...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B unsub...@googlegroups.com>
> > .

Esa

unread,
Oct 18, 2010, 8:11:44 PM10/18/10
to Google Maps JavaScript API v3
If you want to have solution with no cursor change nor other weird
feedback, you will come back.

Jacko'92

unread,
Oct 25, 2010, 1:35:48 PM10/25/10
to Google Maps JavaScript API v3
i tried the code suggested by Chris above, and i noticed that you cant
drag the map under where the image is (by clicking and dragging ontop
of the image), im going to be using a large image on my map (of a
circular crosshair), so its important that i can still interact with
the map under the image, does anyone have a solution for this?

Nathan Raley

unread,
Oct 25, 2010, 1:54:27 PM10/25/10
to google-map...@googlegroups.com
If you loaded the image as a marker set its clickable property to false.

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.

Jacko'92

unread,
Oct 25, 2010, 1:58:48 PM10/25/10
to google-map...@googlegroups.com
ahhh, thanks a lot, that seems to have done the trick (:

Jacko'92

unread,
Oct 25, 2010, 2:46:51 PM10/25/10
to google-map...@googlegroups.com
found another problem with centering an image with the above suggested way, the image stutters quite a lot while dragging around the map (tested with Chrome and FF)  ...does anyone else have this problem?  and is there any way of fixing this?

Nathan Raley

unread,
Oct 25, 2010, 3:08:05 PM10/25/10
to google-map...@googlegroups.com
You have a link to the map so we can see if we can reproduce the "stutter"?

On Mon, Oct 25, 2010 at 1:46 PM, Jacko'92 <jacko...@googlemail.com> wrote:
found another problem with centering an image with the above suggested way, the image stutters quite a lot while dragging around the map (tested with Chrome and FF)  ...does anyone else have this problem?  and is there any way of fixing this?

--

Rossko

unread,
Oct 25, 2010, 3:34:54 PM10/25/10
to Google Maps JavaScript API v3
I would have thought a simple div floated over the map div would be
useful here,as it's nailed to the screen, not the slippy map. But I
do not know how you can make it "transparent" to mouse events.

Jacko'92

unread,
Oct 25, 2010, 3:39:38 PM10/25/10
to google-map...@googlegroups.com
sorry i dont have a link (currently working locally).. but all my source consisted of was the basic gmap initialize codes, and the above marker code, using a large (large in dimensions) image as the marker

but using a blog post i just found, i implemented a centered image by slightly altering the code featured on the blog (as the code on the blog is for centering div's, and arraigning them to look like a crosshair)


Nathan Raley

unread,
Oct 25, 2010, 4:02:42 PM10/25/10
to google-map...@googlegroups.com
perhaps it has to do with the dimensions of the cross being so large?

Jacko'92

unread,
Oct 25, 2010, 4:10:27 PM10/25/10
to google-map...@googlegroups.com
yeahh, i think thats probably it... but after using the solution found on that blog, the same image no longer stutters at all,  so i think thats probably the best way to go when it comes to large images
Reply all
Reply to author
Forward
0 new messages