Use custom icons with canvas rendering leaflet

﹥>﹥吖頭↗ 提交于 2021-02-07 11:49:40

问题


I need to draw thousands of points on a leaflet map with custom icons. The performance using the standard L.marker is too slow to be usable when I get to around 1500 markers. I attempted the solution here using L.circleMarker, and I am able to draw thousands of points with stellar performance. Unforunately, with using L.circleMarker I am only able to make different kinds of circles, which does not satisfy my requirements. I am also not able to leverage clustering, since there isn't a particularly good way to cluster these unrelated markers with different icons.

Is there a way to get the performance benefits of canvas rendering while being able to use custom icons?


回答1:


After spending a few hours looking into this I've come to the conclusion that leaflet doesn't have native support for creating custom icons with canvas.

There is a plugin though called leaflet-canvasicon that adds the functionality though.

I haven't tested it yet but the example looks pretty good.

https://github.com/sashakavun/leaflet-canvasicon




回答2:


I was able to use CircleMarkers and MarkerCluster, but I had to create a custom CircleMarker class like it says here:https://github.com/Leaflet/Leaflet/issues/6257




回答3:


I made a plugin to render markers on a canvas: https://github.com/francoisromain/leaflet-markers-canvas

You can use it with custom markers.




回答4:


You can use https://www.npmjs.com/package/leaflet-canvas-markers Adding all images to just one canvas. And you can create a direction arrow by simply pointing to the previous waypoint!



来源:https://stackoverflow.com/questions/45487771/use-custom-icons-with-canvas-rendering-leaflet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!