简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM