patch.js 887 B

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