最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to Click the Marker on OpenLayers - Stack Overflow

programmeradmin1浏览0评论

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

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();
   });
});
Share Improve this question edited Jul 17, 2012 at 15:49 Baylor Rae' 4,01022 silver badges40 bronze badges asked Jul 17, 2012 at 15:21 Jhonny Jr.Jhonny Jr. 3063 gold badges4 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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 remend moving your javascript tags to the bottom of the page before the closing </body> tag.

发布评论

评论列表(0)

  1. 暂无评论