leaflet-d3Layer.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*!
  2. *
  3. * Copyright (c) 2014 Teralytics AG
  4. * Copyright© 2000-2017 SuperMap Software Co. Ltd
  5. * Leaflet.D3SvgOverlay.(https://github.com/SuperMap/Leaflet.D3SvgOverlay)
  6. * license: MIT
  7. * version: v2.2.0
  8. *
  9. */
  10. /******/ (function(modules) { // webpackBootstrap
  11. /******/ // The module cache
  12. /******/ var installedModules = {};
  13. /******/
  14. /******/ // The require function
  15. /******/ function __webpack_require__(moduleId) {
  16. /******/
  17. /******/ // Check if module is in cache
  18. /******/ if(installedModules[moduleId]) {
  19. /******/ return installedModules[moduleId].exports;
  20. /******/ }
  21. /******/ // Create a new module (and put it into the cache)
  22. /******/ var module = installedModules[moduleId] = {
  23. /******/ i: moduleId,
  24. /******/ l: false,
  25. /******/ exports: {}
  26. /******/ };
  27. /******/
  28. /******/ // Execute the module function
  29. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  30. /******/
  31. /******/ // Flag the module as loaded
  32. /******/ module.l = true;
  33. /******/
  34. /******/ // Return the exports of the module
  35. /******/ return module.exports;
  36. /******/ }
  37. /******/
  38. /******/
  39. /******/ // expose the modules object (__webpack_modules__)
  40. /******/ __webpack_require__.m = modules;
  41. /******/
  42. /******/ // expose the module cache
  43. /******/ __webpack_require__.c = installedModules;
  44. /******/
  45. /******/ // identity function for calling harmony imports with the correct context
  46. /******/ __webpack_require__.i = function(value) { return value; };
  47. /******/
  48. /******/ // define getter function for harmony exports
  49. /******/ __webpack_require__.d = function(exports, name, getter) {
  50. /******/ if(!__webpack_require__.o(exports, name)) {
  51. /******/ Object.defineProperty(exports, name, {
  52. /******/ configurable: false,
  53. /******/ enumerable: true,
  54. /******/ get: getter
  55. /******/ });
  56. /******/ }
  57. /******/ };
  58. /******/
  59. /******/ // getDefaultExport function for compatibility with non-harmony modules
  60. /******/ __webpack_require__.n = function(module) {
  61. /******/ var getter = module && module.__esModule ?
  62. /******/ function getDefault() { return module['default']; } :
  63. /******/ function getModuleExports() { return module; };
  64. /******/ __webpack_require__.d(getter, 'a', getter);
  65. /******/ return getter;
  66. /******/ };
  67. /******/
  68. /******/ // Object.prototype.hasOwnProperty.call
  69. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  70. /******/
  71. /******/ // __webpack_public_path__
  72. /******/ __webpack_require__.p = "";
  73. /******/
  74. /******/ // Load entry module and return exports
  75. /******/ return __webpack_require__(__webpack_require__.s = 4);
  76. /******/ })
  77. /************************************************************************/
  78. /******/ ([
  79. /* 0 */
  80. /***/ (function(module, exports, __webpack_require__) {
  81. "use strict";
  82. Object.defineProperty(exports, "__esModule", {
  83. value: true
  84. });
  85. exports.d3SvgOverlay = exports.D3SvgOverlay = undefined;
  86. var _leaflet = __webpack_require__(2);
  87. var _leaflet2 = _interopRequireDefault(_leaflet);
  88. var _d = __webpack_require__(3);
  89. var d3 = _interopRequireWildcard(_d);
  90. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  91. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  92. // Tiny stylesheet bundled here instead of a separate file
  93. /**
  94. * Copyright 2015 Teralytics AG
  95. *
  96. * @author Kirill Zhuravlev <kirill.zhuravlev@teralytics.ch>
  97. *
  98. * Adapted to d3 v4 by SuperMap.
  99. */
  100. if (_leaflet2.default.version >= "1.0") {
  101. d3.select("head").append("style").attr("type", "text/css").text("g.d3-overlay *{pointer-events:visiblePainted;}");
  102. }
  103. // Class definition
  104. var D3SvgOverlay = exports.D3SvgOverlay = (_leaflet2.default.version < "1.0" ? _leaflet2.default.Class : _leaflet2.default.Layer).extend({
  105. includes: _leaflet2.default.version < "1.0" ? _leaflet2.default.Mixin.Events : [],
  106. version: "2.2",
  107. _undef: function _undef(a) {
  108. return typeof a == "undefined";
  109. },
  110. _options: function _options(options) {
  111. if (this._undef(options)) {
  112. return this.options;
  113. }
  114. options.zoomHide = this._undef(options.zoomHide) ? false : options.zoomHide;
  115. options.zoomDraw = this._undef(options.zoomDraw) ? true : options.zoomDraw;
  116. return this.options = options;
  117. },
  118. _disableLeafletRounding: function _disableLeafletRounding() {
  119. this._leaflet_round = _leaflet2.default.Point.prototype._round;
  120. _leaflet2.default.Point.prototype._round = function () {
  121. return this;
  122. };
  123. },
  124. _enableLeafletRounding: function _enableLeafletRounding() {
  125. _leaflet2.default.Point.prototype._round = this._leaflet_round;
  126. },
  127. draw: function draw() {
  128. this._disableLeafletRounding();
  129. this._drawCallback(this.selection, this.projection, this.map.getZoom());
  130. this._enableLeafletRounding();
  131. },
  132. initialize: function initialize(drawCallback, options) {
  133. // (Function(selection, projection)), (Object)options
  134. this._options(options || {});
  135. this._drawCallback = drawCallback;
  136. },
  137. // Handler for "viewreset"-like events, updates scale and shift after the animation
  138. _zoomChange: function _zoomChange(evt) {
  139. this._disableLeafletRounding();
  140. var newZoom = this._undef(evt.zoom) ? this.map._zoom : evt.zoom; // "viewreset" event in Leaflet has not zoom/center parameters like zoomanim
  141. this._zoomDiff = newZoom - this._zoom;
  142. this._scale = Math.pow(2, this._zoomDiff);
  143. this.projection.scale = this._scale;
  144. this._shift = this.map.latLngToLayerPoint(this._wgsOrigin)._subtract(this._wgsInitialShift.multiplyBy(this._scale));
  145. var shift = ["translate(", this._shift.x, ",", this._shift.y, ") "];
  146. var scale = ["scale(", this._scale, ",", this._scale, ") "];
  147. this._rootGroup.attr("transform", shift.concat(scale).join(""));
  148. if (this.options.zoomDraw) {
  149. this.draw();
  150. }
  151. this._enableLeafletRounding();
  152. },
  153. onAdd: function onAdd(map) {
  154. this.map = map;
  155. var _layer = this;
  156. // SVG element
  157. if (_leaflet2.default.version < "1.0") {
  158. map._initPathRoot();
  159. this._svg = d3.select(map._panes.overlayPane).select("svg");
  160. this._rootGroup = this._svg.append("g");
  161. } else {
  162. this._svg = _leaflet2.default.svg();
  163. map.addLayer(this._svg);
  164. this._rootGroup = d3.select(this._svg._rootGroup).classed("d3-overlay", true);
  165. }
  166. this._rootGroup.classed("leaflet-zoom-hide", this.options.zoomHide);
  167. this.selection = this._rootGroup;
  168. var me = this;
  169. var oldOn = d3.selection.prototype.on;
  170. d3.selection.prototype.on = function (t, n, e) {
  171. oldOn.apply(me.selection, [t, n, e]);
  172. me.map.on(t, function () {
  173. me.selection.dispatch(t);
  174. });
  175. };
  176. // Init shift/scale invariance helper values
  177. this._pixelOrigin = map.getPixelOrigin();
  178. this._wgsOrigin = _leaflet2.default.latLng([0, 0]);
  179. this._wgsInitialShift = this.map.latLngToLayerPoint(this._wgsOrigin);
  180. this._zoom = this.map.getZoom();
  181. this._shift = _leaflet2.default.point(0, 0);
  182. this._scale = 1;
  183. // Create projection object
  184. this.projection = {
  185. latLngToLayerPoint: function latLngToLayerPoint(latLng, zoom) {
  186. zoom = _layer._undef(zoom) ? _layer._zoom : zoom;
  187. var projectedPoint = _layer.map.project(_leaflet2.default.latLng(latLng), zoom)._round();
  188. return projectedPoint._subtract(_layer._pixelOrigin);
  189. },
  190. layerPointToLatLng: function layerPointToLatLng(point, zoom) {
  191. zoom = _layer._undef(zoom) ? _layer._zoom : zoom;
  192. var projectedPoint = _leaflet2.default.point(point).add(_layer._pixelOrigin);
  193. return _layer.map.unproject(projectedPoint, zoom);
  194. },
  195. unitsPerMeter: 256 * Math.pow(2, _layer._zoom) / 40075017,
  196. map: _layer.map,
  197. layer: _layer,
  198. scale: 1
  199. };
  200. this.projection._projectPoint = function (x, y) {
  201. var point = _layer.projection.latLngToLayerPoint(new _leaflet2.default.LatLng(y, x));
  202. this.stream.point(point.x, point.y);
  203. };
  204. this.projection.pathFromGeojson = d3.geoPath().projection(d3.geoTransform({ point: this.projection._projectPoint }));
  205. // Compatibility with v.1
  206. this.projection.latLngToLayerFloatPoint = this.projection.latLngToLayerPoint;
  207. this.projection.getZoom = this.map.getZoom.bind(this.map);
  208. this.projection.getBounds = this.map.getBounds.bind(this.map);
  209. this.selection = this._rootGroup;
  210. if (_leaflet2.default.version < "1.0") map.on("viewreset", this._zoomChange, this);
  211. // Initial draw
  212. this.draw();
  213. },
  214. // Leaflet 1.0
  215. getEvents: function getEvents() {
  216. return { zoomend: this._zoomChange };
  217. },
  218. onRemove: function onRemove(map) {
  219. if (_leaflet2.default.version < "1.0") {
  220. map.off("viewreset", this._zoomChange, this);
  221. this._rootGroup.remove();
  222. } else {
  223. this._svg.remove();
  224. }
  225. },
  226. addTo: function addTo(map) {
  227. map.addLayer(this);
  228. return this;
  229. }
  230. });
  231. // Factory method
  232. var d3SvgOverlay = exports.d3SvgOverlay = function d3SvgOverlay(drawCallback, options) {
  233. return new D3SvgOverlay(drawCallback, options);
  234. };
  235. _leaflet2.default.supermap = _leaflet2.default.supermap || {};
  236. _leaflet2.default.supermap.d3Layer = d3SvgOverlay;
  237. /***/ }),
  238. /* 1 */
  239. /***/ (function(module, exports, __webpack_require__) {
  240. "use strict";
  241. __webpack_require__(0);
  242. /***/ }),
  243. /* 2 */
  244. /***/ (function(module, exports) {
  245. module.exports = L;
  246. /***/ }),
  247. /* 3 */
  248. /***/ (function(module, exports) {
  249. module.exports = d3;
  250. /***/ }),
  251. /* 4 */
  252. /***/ (function(module, exports, __webpack_require__) {
  253. __webpack_require__(1);
  254. module.exports = __webpack_require__(0);
  255. /***/ })
  256. /******/ ]);