javascript - ESRI 传单地图,重置样式不起作用
问题描述
我正在制作我的第一张传单地图,但在尝试重置 onMouseOut 样式时遇到了问题。它在鼠标悬停时正确更改样式,但在鼠标移出时,我不断收到:对象不支持属性或方法“resetStyle”
这就是我所拥有和尝试过的:
var MAP_ID = 'DISTRICT_MAP';
var map = L.map(MAP_ID).setView([37.71, -99.88], 4);
function showMap() {
var layerConfig = {
....
onEachFeature: onEachFeature,
style: style
};
var districtLayer;
//Add base map layer
L.esri.basemapLayer('Gray').addTo(map);
//Add the District layer
districtLayer = L.esri.featureLayer(layerConfig);
map.addLayer(districtLayer);
}
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7,
});
if (!L.Browser.ie && !L.Browser.opera12 && L.Browser.edge) {
layer.bringToFront();
}
}
// Can't get this to work!
function resetHighlight(e) {
//L.esri.featureLayer.resetStyle(e.target);
//e.target.resetStyle(e.target);
//e.layer.resetStyle();
}
function onEachFeature(feature, layer) {
layer.on("mouseover", function (e) {
highlightFeature(e);
});
layer.on("mouseout", function (e) {
if (e.target && e.target.feature && e.target.feature.properties) {
resetHighlight(e);
}
});
layer.on("click", function (e) {
....
}
});
}
function style(feature, layer) {
...
}
解决方案
根据API 参考,这FeatureLayer
本身就是一种方法,并希望您传递id
特定功能的 。
// because the individual feature is GeoJSON, it has an id, along with properties and geometry
districtLayer.resetStyle(e.layer.feature.id);
推荐阅读
- node.js - PayPal /v1/invoicing/invoices/ REST API 不可用
- algorithm - 在图中,O(n*m) 复杂度被认为是多项式还是什么?
- visual-studio-code - 如何在 Visual Studio Code 中禁用新的“灰色错误”?
- c++ - string.find() 无法正常工作
- sql - SQLite 中是否有一些相当于 [ WHERE col IN (%) ] 的内容?
- javascript - 监听外部 js 文件中的内容是否加载到 DOM 中供 javascript 使用
- c# - 如果我输入搜索参数,如何让机器人框架机器人发回数据库的单元格?
- windows - GCP SDK gsutil rsynch不返回进度
- javascript - npm 脚本抛出错误,但没有提供任何有用的信息
- scala - 具有路径相关类型和协变参数的 Scala 复制类