【发布时间】:2019-11-13 02:39:05
【问题描述】:
我有这个鼠标移动功能:
$("#mapContainer").on("mousemove", "#colorpicker"+mapNo, function(event){
//do something here
//layer.setStyle({color: color, fillColor: color});
});
每当我在 mousemove 函数中删除 layer.setStyle 的注释时,我都会收到错误 "layer is not defined" 所以我希望调用 mousemove 函数当地图中已经存在图层时。我在定义层的地方有这个功能:
function drawCreated(e) {
type = e.layerType,
layer = e.layer;
layer.addTo(drawnItems);
console.log(type, ' drawn', layer);
//for drawing
if (type === 'circle') {
var theCenterPt = layer.getLatLng();
var theRadius = layer.getRadius();
var center = [theCenterPt.lng,theCenterPt.lat];
console.log(center);
points['lng'] = theCenterPt.lng;
points['lat'] = theCenterPt.lat;
points['radius'] = theRadius;
console.log(points);
drawnItems.addLayer(layer);
//drawnItems.setStyle({color: color, fillColor: color});
}
if(map.hasLayer(layer)){
console.log("true");
//must call the mousemove function here or mousemove will work when there is a layer
}else{
console.log("false");
}
}
【问题讨论】:
-
我不确定这不是 XY 问题 - 你能描述一下你想要实现的行为吗?
-
我想用 mousemove 函数改变图层的颜色。但是我总是收到一个错误,说没有定义图层,因为地图中没有图层,这就是为什么我要检查,如果有图层,mousemove 将起作用,但如果没有,它将不起作用。跨度>
-
我不明白你的目标是什么。您希望图层移动时或鼠标移动时更改图层颜色吗?应该所有图层都更改颜色还是只更改某些图层?
-
@FalkeDesign 我想在颜色选择器中移动光标时更改图层的颜色。它应该改变某个图层,这是我绘制的图层。
标签: javascript php codeigniter leaflet leaflet.draw