patch.js 965 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // leaflet 补丁
  2. // author: wzx
  3. // version: 1.0
  4. import iconRetinaUrl from "leaflet/dist/images/marker-icon-2x.png"
  5. import iconUrl from "leaflet/dist/images/marker-icon.png"
  6. import shadowUrl from "leaflet/dist/images/marker-shadow.png"
  7. export default {
  8. run() {
  9. this.patchIconPath()
  10. this.patchTileWhiteLine()
  11. },
  12. // 解决leaflet默认图标的路径错误问题
  13. patchIconPath() {
  14. delete L.Icon.Default.prototype._getIconUrl
  15. L.Icon.Default.mergeOptions({
  16. iconRetinaUrl: iconRetinaUrl,
  17. iconUrl: iconUrl,
  18. shadowUrl: shadowUrl
  19. })
  20. },
  21. // 解决leaflet瓦片显示有白线问题
  22. patchTileWhiteLine() {
  23. (function() {
  24. var originalInitTile = L.GridLayer.prototype._initTile
  25. L.GridLayer.include({
  26. _initTile: function(tile) {
  27. originalInitTile.call(this, tile);
  28. var tileSize = this.getTileSize();
  29. tile.style.width = tileSize.x + 1 + 'px';
  30. tile.style.height = tileSize.y + 1 + 'px';
  31. }
  32. });
  33. })()
  34. }
  35. }