Javascript 如何使mouseover事件在我的传单.js地图中工作?
我一直在努力关注传单网站,但我无法正常工作。mouseover一次只能在某些形状中工作,但mouseout实际上从来不会清除更改-现在永久高亮显示的多边形成为mouseover事件每次工作的少数多边形之一 这是我正在使用的代码:Javascript 如何使mouseover事件在我的传单.js地图中工作?,javascript,jquery,leaflet,Javascript,Jquery,Leaflet,我一直在努力关注传单网站,但我无法正常工作。mouseover一次只能在某些形状中工作,但mouseout实际上从来不会清除更改-现在永久高亮显示的多边形成为mouseover事件每次工作的少数多边形之一 这是我正在使用的代码: window.map = L.map('map').setView([-14, -50], 5); L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { id: 'teste',
window.map = L.map('map').setView([-14, -50], 5);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
id: 'teste',
attribution: '© <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
}).addTo(map);
geojson = L.geoJson(dados,{ onEachFeature: onEachFeature }
).addTo(map);
function style(feature) {
return {
fillColor: '#800026',
weight: 0.2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
L.geoJson(dados, {style: style}).addTo(map)
info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
info.update = function (props) {
if (props) this._div.innerHTML = '<h2>'+props.nome_ibge_ + ' - '+props.estado+'</h2><br/>' + '<h3>'+ props.populacao_ +'</h3>';
else this._div.innerHTML = '<h2>Passe o mouse sobre uma área</h2>'
};
info.addTo(map);
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
function resetHighlight(e) {
console.log("RESETANDO")
geojson.resetStyle(e.target);
info.update()
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
}
window.map=L.map('map').setView([-14,-50],5);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'{
id:'teste',
属性:“©;贡献者,”
}).addTo(地图);
geojson=L.geojson(数据集,{onEachFeature:onEachFeature}
).addTo(地图);
功能样式(特征){
返回{
填充颜色:'#800026',
重量:0.2,
不透明度:1,
颜色:'白色',
dashArray:'3',
填充不透明度:0.7
};
}
L.geoJson(dados,{style:style}).addTo(map)
info=L.control();
info.onAdd=函数(映射){
this._div=L.DomUtil.create('div','info');//使用类“info”创建一个div
这个.update();
把这个还给我;
};
info.update=功能(道具){
如果(props)这个;
除此之外。_div.innerHTML='Passe o mouse sobre umaárea'
};
信息地址(地图);
功能高亮功能(e){
var层=e.目标;
layer.setStyle({
体重:5,
颜色:'#666',
dashArray:“”,
填充不透明度:0.7
});
如果(!L.Browser.ie&&!L.Browser.opera){
层。布氏体();
}
信息更新(图层、特征、属性);
}
功能重置突出显示(e){
console.log(“RESETANDO”)
geojson.resetStyle(e.target);
info.update()
}
函数ZoomTof性质(e){
fitBounds(e.target.getBounds());
}
功能onEachFeature(功能,图层){
分层({
鼠标悬停:Highlight功能,
mouseout:resetHighlight,
单击:缩放自然
});
}
您的示例似乎在Chrome中运行。