Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 点击地图框标记_Javascript_Html_Onclick_Mapbox_Markers - Fatal编程技术网

Javascript 点击地图框标记

Javascript 点击地图框标记,javascript,html,onclick,mapbox,markers,Javascript,Html,Onclick,Mapbox,Markers,我已经能够将标记集成到我们正在使用的地图框中,但仍然想知道我们是否可以点击它们。如果是,怎么做 以下是我的代码: <style> /* * Unlike other icons, you can style `L.divIcon` with CSS. * These styles make each marker a circle with a border and centered text. */ .count-icon1 { background:url(images

我已经能够将标记集成到我们正在使用的地图框中,但仍然想知道我们是否可以点击它们。如果是,怎么做

以下是我的代码:

<style>
/*
 * Unlike other icons, you can style `L.divIcon` with CSS.
 * These styles make each marker a circle with a border and centered text.
 */
.count-icon1 {
  background:url(images/redpin.png);  
  color:#000;
  font-weight:600;
  text-align:center; 
  padding:19px 0 0 0px; font-size:180%;
 }
.count-icon2 {
  background:url(images/greenpin.png);  
  color:#000;
  font-weight:600;
  text-align:center; 
  padding:19px 0 0 0px; font-size:180%;
 }
</style>
js代码:

我试着做了一点研发,但没有成功: 我们需要使用,但不知道如何使用

对于单击功能,我们需要遵循此代码,但是如何操作

// Listen for individual marker clicks.
myLayer.on('click',function(e) {
    // Force the popup closed.
    e.layer.closePopup();

    var feature = e.layer.feature;
    var content = '<div><strong>' + feature.properties.title + '</strong>' +
                  '<p>' + feature.properties.description + '</p></div>';

    info.innerHTML = content;
});
非常感谢您的帮助


谢谢

我相信使用Mapbox有多种方法可以做到这一点,不幸的是,我现在无法访问我的项目,所以我只是不使用Mapbox文档

按照您的示例,这看起来最简单-如果您添加了标记,例如:

var marker = L.marker([43.6475, -79.3838], {
  icon: L.mapbox.marker.icon({
    'marker-color': '#9c89cc'
  })
})
.bindPopup('<p>Your html code here</p>')
.addTo(map);
有效地在map变量上添加一个事件侦听器,然后通过传递给事件侦听器的事件参数来侦听您单击的内容

这可能有用:

祝你好运

var marker = L.marker([43.6475, -79.3838], {
  icon: L.mapbox.marker.icon({
    'marker-color': '#9c89cc'
  })
})
.bindPopup('<p>Your html code here</p>')
.addTo(map);
myLayer.on('click', function(e) {
    resetColors();
    e.layer.feature.properties['old-color'] = e.layer.feature.properties['marker-color'];
    e.layer.feature.properties['marker-color'] = '#ff8888';
    myLayer.setGeoJSON(geoJson);
});

map.on('click', resetColors);