5

I just make a map using openlayer

I made a map in OpenLayers with our own homemade

But what makes me confused is that I can not integrate jQuery with OpenLayers, where I create a function that is simple jQuery show / hide ()

I tried to click on one of the marker in OpenLayers map which I have made, which has id #OL_Icon_43 inside div#map OpenLayers and I tried to do the function hide() using jquery in the <head> tag that will hide the tag outside tag #map, but that does not work for me

Can you help me please ?

This is the view which I make the jquery code :

$(document).ready(function(){
   $("#OL_Icon_43").click(function() {
     $("footer").hide();
   });
});
Baylor Rae'
  • 3,995
  • 20
  • 39
Jhonny Jr.
  • 363
  • 3
  • 4
  • 15

1 Answers1

6

There's a chance that jQuery cannot find the element #OL_Icon_43 when you are attempting to bind the click event. You will be better off delegating a click event on the #map instead.

$('#map').delegate('#OL_Icon_43', 'click', function() {
  $('#footer').hide();
});

Edit: It looks like OpenLayers allows you to bind events directly to your markers.

var marker = new OpenLayers.Marker(lonlat);
marker.id = "1";
marker.events.register("click", marker, function() {
  $('footer').hide();
});

You just need to make sure jQuery has loaded before OpenLayers so you can hide the footer. I would recommend moving your javascript tags to the bottom of the page before the closing </body> tag.

Baylor Rae'
  • 3,995
  • 20
  • 39
  • Thank you very much about your answer :) But that code is still not working for me :( Can you have any idea ? – Jhonny Jr. Jul 17 '12 at 15:53
  • @user1532193 take a look at my edit. If that doesn't answer your question could you create an isolated example for me to look at? – Baylor Rae' Jul 17 '12 at 16:04
  • Yeah, you are so great, this example code is 100% work for me, now i can use the function show and hide. If i have any question agains about jquery and openlayers, i think i will ask a questions to you again :D Thank you very much :) :) – Jhonny Jr. Jul 17 '12 at 16:17
  • I've been accept your answer, sorry if i'm late because this is my first time i use stackoverflow to publish my question and once again i'm so very grateful about your help :) – Jhonny Jr. Jul 19 '12 at 18:15
  • 3
    You have to make sure, that your marker layer is the top most layer to receive the click event. See http://stackoverflow.com/questions/7927162/openlayers-zindex-for-markers-and-vectors – Stefan Haberl Mar 13 '13 at 16:19