【问题标题】:Leaflet-canvas-markers cant set strokeLeaflet-canvas-markers 无法设置描边
【发布时间】:2020-11-10 23:52:47
【问题描述】:

Leaflet-canvas-markers 正在扩展 L.circleMarker。

因此应该可以将笔画设置为 L.canvasMarker(?)。

有人知道我做错了什么,或者我需要在传单画布标记包中进行哪些更改才能使其正常工作?

这是一个 jsfiddle;点击circleMarker,它会得到一个更粗的笔划。但如果你点击 canvasMarker 它什么也得不到。

https://jsfiddle.net/tq7nf3j2/

let marker1 = L.canvasMarker([58.970471,5.730373], {
    radius: 15,
    img: {
    url: 'img.png',
    size: [30,30]
    }
    }).addTo(map);


 marker1.on('click', function(e) {
    e.target.setStyle({weight: 10})
    })

【问题讨论】:

    标签: leaflet


    【解决方案1】:

    _updateImg(layer) 函数更改为:

    _updateImg(layer) {
                const { img } = layer.options;
                const p = layer._point.round();
                p.x += img.offset.x; p.y += img.offset.y;
                if (img.rotate) {
                    this._ctx.save();
                    this._ctx.translate(p.x, p.y);
                    this._ctx.rotate(img.rotate * Math.PI / 180);
                    this._ctx.drawImage(img.el, -img.size[0] / 2, -img.size[1] / 2, img.size[0], img.size[1]);
                    this._ctx.restore();
                } else {
                  if(layer.options.stroke && layer.options.weight > 0){
                    this._ctx.strokeStyle = layer.options.color; 
                    this._ctx.lineWidth = layer.options.weight;    
                  }
                  this._ctx.drawImage(img.el, p.x - img.size[0] / 2, p.y - img.size[1] / 2, img.size[0], img.size[1]);
                  if(layer.options.stroke && layer.options.weight > 0){
                    this._ctx.strokeRect(p.x - img.size[0] / 2, p.y - img.size[1] / 2, img.size[0], img.size[1]);
                  }
                }
            }
    

    如果您不希望它与rotate 一起使用,您必须将其复制到上面的块中。 它在图像后面添加了一个带有笔划的矩形。

    另外不要忘记在图片中添加weight: 0,因为circleMarkers 的默认笔划为3。

        let marker1 = L.canvasMarker([58.970471,5.730373], {
          radius: 15,
          img: {
            url: 'https://register.geonorge.no/symbol/files/tilgjengelighet/sittegruppe_positiv_groenn.png',
            size: [30,30]
          },
          weight: 0
        }).addTo(map);
    

    示例:https://jsfiddle.net/falkedesign/bLgd0opq/

    【讨论】:

    • 谢谢!也适用于 geoman :D 唯一的问题是捕捉,这还不错
    猜你喜欢
    • 2023-03-30
    • 2011-12-07
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    • 1970-01-01
    • 1970-01-01
    • 2020-05-24
    相关资源
    最近更新 更多