Jhonny Jr.
Jhonny Jr.

Reputation: 306

How to Click the Marker on OpenLayers

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();
   });
});

Upvotes: 5

Views: 12613

Answers (1)

Baylor Rae&#39;
Baylor Rae&#39;

Reputation: 4010

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.

Upvotes: 6

Related Questions