leaflet.mouseBlur.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. L.Control.MouseBlur = L.Control.extend({
  2. //是否初始化
  3. _initialized: false,
  4. options: {
  5. weight: 1,
  6. color: '#000000',
  7. opacity: 0.8
  8. },
  9. linesData: {
  10. lineX: null,
  11. lineY: null
  12. },
  13. initialize: function(options) {
  14. L.setOptions(this, options);
  15. return this;
  16. },
  17. onAdd: function(map) {
  18. this._map = map;
  19. this.craetMouse();
  20. this._map.on('mousemove', this.mouseMove, this);
  21. this._container = L.DomUtil.create('div', 'leaflet-bar leaflet-cross');
  22. return this._container;
  23. },
  24. craetMouse: function() {
  25. var _this = this;
  26. _this.printBounds = _this._map.getBounds();
  27. _this.center = _this._map.getCenter();
  28. _this.linesData.lineX = [
  29. [_this.center.lat, _this.printBounds._northEast.lng],
  30. [_this.center.lat, _this.printBounds._southWest.lng]
  31. ];
  32. _this.linesData.lineY = [
  33. [_this.printBounds._northEast.lat, _this.center.lng],
  34. [_this.printBounds._southWest.lat, _this.center.lng]
  35. ];
  36. _this.crosslineX = L.polyline(
  37. _this.linesData.lineX,
  38. _this.options
  39. ).addTo(_this._map);
  40. _this.crosslineY = L.polyline(
  41. _this.linesData.lineY,
  42. _this.options
  43. ).addTo(_this._map);
  44. if (L.Browser.ie || L.Browser.firefox) {
  45. _this._map.getContainer().style.cursor = 'url(../scripts/vendor/map23dlib/images/cur-none.cur),auto';
  46. } else {
  47. _this._map.getContainer().style.cursor = 'url(../scripts/vendor/map23dlib/images/cur-none.cur) 5 5,auto';
  48. }
  49. },
  50. mouseMove: function(e) {
  51. var _this = this;
  52. _this.center = e.latlng;
  53. _this.linesData.lineX = [
  54. [_this.center.lat, 180],
  55. [_this.center.lat, -180]
  56. ];
  57. _this.linesData.lineY = [
  58. [90, _this.center.lng],
  59. [-90, _this.center.lng]
  60. ];
  61. _this.crosslineX.setLatLngs(_this.linesData.lineX);
  62. _this.crosslineY.setLatLngs(_this.linesData.lineY);
  63. },
  64. remove: function() {
  65. var _this = this;
  66. /*_this._map.removeLayer(_this.crosslineY);
  67. _this._map.removeLayer(_this.crosslineX);
  68. _this._map.getContainer().style.cursor = "auto";*/
  69. }
  70. });
  71. L.control.mouseblur = function(options) {
  72. return new L.Control.MouseBlur(options);
  73. }