1
0

leaflet.js 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  7. var _util = require("./util");
  8. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9. var ClusterLayerStore = function () {
  10. function ClusterLayerStore(group) {
  11. _classCallCheck(this, ClusterLayerStore);
  12. this._layers = {};
  13. this._group = group;
  14. }
  15. _createClass(ClusterLayerStore, [{
  16. key: "add",
  17. value: function add(layer, id) {
  18. if (typeof id !== "undefined" && id !== null) {
  19. if (this._layers[id]) {
  20. this._group.removeLayer(this._layers[id]);
  21. }
  22. this._layers[id] = layer;
  23. }
  24. this._group.addLayer(layer);
  25. }
  26. }, {
  27. key: "remove",
  28. value: function remove(id) {
  29. if (typeof id === "undefined" || id === null) {
  30. return;
  31. }
  32. id = (0, _util.asArray)(id);
  33. for (var i = 0; i < id.length; i++) {
  34. if (this._layers[id[i]]) {
  35. this._group.removeLayer(this._layers[id[i]]);
  36. delete this._layers[id[i]];
  37. }
  38. }
  39. }
  40. }, {
  41. key: "clear",
  42. value: function clear() {
  43. this._layers = {};
  44. this._group.clearLayers();
  45. }
  46. }]);
  47. return ClusterLayerStore;
  48. }();
  49. exports.default = ClusterLayerStore;
  50. },{"./util":17}],2:[function(require,module,exports){
  51. "use strict";
  52. Object.defineProperty(exports, "__esModule", {
  53. value: true
  54. });
  55. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  56. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  57. var ControlStore = function () {
  58. function ControlStore(map) {
  59. _classCallCheck(this, ControlStore);
  60. this._controlsNoId = [];
  61. this._controlsById = {};
  62. this._map = map;
  63. }
  64. _createClass(ControlStore, [{
  65. key: "add",
  66. value: function add(control, id, html) {
  67. if (typeof id !== "undefined" && id !== null) {
  68. if (this._controlsById[id]) {
  69. this._map.removeControl(this._controlsById[id]);
  70. }
  71. this._controlsById[id] = control;
  72. } else {
  73. this._controlsNoId.push(control);
  74. }
  75. this._map.addControl(control);
  76. }
  77. }, {
  78. key: "get",
  79. value: function get(id) {
  80. var control = null;
  81. if (this._controlsById[id]) {
  82. control = this._controlsById[id];
  83. }
  84. return control;
  85. }
  86. }, {
  87. key: "remove",
  88. value: function remove(id) {
  89. if (this._controlsById[id]) {
  90. var control = this._controlsById[id];
  91. this._map.removeControl(control);
  92. delete this._controlsById[id];
  93. }
  94. }
  95. }, {
  96. key: "clear",
  97. value: function clear() {
  98. for (var i = 0; i < this._controlsNoId.length; i++) {
  99. var control = this._controlsNoId[i];
  100. this._map.removeControl(control);
  101. }
  102. this._controlsNoId = [];
  103. for (var key in this._controlsById) {
  104. var _control = this._controlsById[key];
  105. this._map.removeControl(_control);
  106. }
  107. this._controlsById = {};
  108. }
  109. }]);
  110. return ControlStore;
  111. }();
  112. exports.default = ControlStore;
  113. },{}],3:[function(require,module,exports){
  114. "use strict";
  115. Object.defineProperty(exports, "__esModule", {
  116. value: true
  117. });
  118. exports.getCRS = getCRS;
  119. var _leaflet = require("./global/leaflet");
  120. var _leaflet2 = _interopRequireDefault(_leaflet);
  121. var _proj4leaflet = require("./global/proj4leaflet");
  122. var _proj4leaflet2 = _interopRequireDefault(_proj4leaflet);
  123. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  124. // Helper function to instanciate a ICRS instance.
  125. function getCRS(crsOptions) {
  126. var crs = _leaflet2.default.CRS.EPSG3857; // Default Spherical Mercator
  127. switch (crsOptions.crsClass) {
  128. case "L.CRS.EPSG3857":
  129. crs = _leaflet2.default.CRS.EPSG3857;
  130. break;
  131. case "L.CRS.EPSG4326":
  132. crs = _leaflet2.default.CRS.EPSG4326;
  133. break;
  134. case "L.CRS.EPSG3395":
  135. crs = _leaflet2.default.CRS.EPSG3395;
  136. break;
  137. case "L.CRS.Simple":
  138. crs = _leaflet2.default.CRS.Simple;
  139. break;
  140. case "L.Proj.CRS":
  141. if (crsOptions.options && crsOptions.options.bounds) {
  142. crsOptions.options.bounds = _leaflet2.default.bounds(crsOptions.options.bounds);
  143. }
  144. if (crsOptions.options && crsOptions.options.transformation) {
  145. crsOptions.options.transformation = new _leaflet2.default.Transformation(crsOptions.options.transformation[0], crsOptions.options.transformation[1], crsOptions.options.transformation[2], crsOptions.options.transformation[3]);
  146. }
  147. crs = new _proj4leaflet2.default.CRS(crsOptions.code, crsOptions.proj4def, crsOptions.options);
  148. break;
  149. case "L.Proj.CRS.TMS":
  150. if (crsOptions.options && crsOptions.options.bounds) {
  151. crsOptions.options.bounds = _leaflet2.default.bounds(crsOptions.options.bounds);
  152. }
  153. if (crsOptions.options && crsOptions.options.transformation) {
  154. crsOptions.options.transformation = _leaflet2.default.Transformation(crsOptions.options.transformation[0], crsOptions.options.transformation[1], crsOptions.options.transformation[2], crsOptions.options.transformation[3]);
  155. }
  156. // L.Proj.CRS.TMS is deprecated as of Leaflet 1.x, fall back to L.Proj.CRS
  157. //crs = new Proj4Leaflet.CRS.TMS(crsOptions.code, crsOptions.proj4def,
  158. //crsOptions.projectedBounds, crsOptions.options);
  159. crs = new _proj4leaflet2.default.CRS(crsOptions.code, crsOptions.proj4def, crsOptions.options);
  160. break;
  161. }
  162. return crs;
  163. }
  164. },{"./global/leaflet":10,"./global/proj4leaflet":11}],4:[function(require,module,exports){
  165. "use strict";
  166. Object.defineProperty(exports, "__esModule", {
  167. value: true
  168. });
  169. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
  170. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  171. var _util = require("./util");
  172. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  173. var DataFrame = function () {
  174. function DataFrame() {
  175. _classCallCheck(this, DataFrame);
  176. this.columns = [];
  177. this.colnames = [];
  178. this.colstrict = [];
  179. this.effectiveLength = 0;
  180. this.colindices = {};
  181. }
  182. _createClass(DataFrame, [{
  183. key: "_updateCachedProperties",
  184. value: function _updateCachedProperties() {
  185. var _this = this;
  186. this.effectiveLength = 0;
  187. this.colindices = {};
  188. this.columns.forEach(function (column, i) {
  189. _this.effectiveLength = Math.max(_this.effectiveLength, column.length);
  190. _this.colindices[_this.colnames[i]] = i;
  191. });
  192. }
  193. }, {
  194. key: "_colIndex",
  195. value: function _colIndex(colname) {
  196. var index = this.colindices[colname];
  197. if (typeof index === "undefined") return -1;
  198. return index;
  199. }
  200. }, {
  201. key: "col",
  202. value: function col(name, values, strict) {
  203. if (typeof name !== "string") throw new Error("Invalid column name \"" + name + "\"");
  204. var index = this._colIndex(name);
  205. if (arguments.length === 1) {
  206. if (index < 0) return null;else return (0, _util.recycle)(this.columns[index], this.effectiveLength);
  207. }
  208. if (index < 0) {
  209. index = this.colnames.length;
  210. this.colnames.push(name);
  211. }
  212. this.columns[index] = (0, _util.asArray)(values);
  213. this.colstrict[index] = !!strict;
  214. // TODO: Validate strictness (ensure lengths match up with other stricts)
  215. this._updateCachedProperties();
  216. return this;
  217. }
  218. }, {
  219. key: "cbind",
  220. value: function cbind(obj, strict) {
  221. var _this2 = this;
  222. Object.keys(obj).forEach(function (name) {
  223. var coldata = obj[name];
  224. _this2.col(name, coldata);
  225. });
  226. return this;
  227. }
  228. }, {
  229. key: "get",
  230. value: function get(row, col, missingOK) {
  231. var _this3 = this;
  232. if (row > this.effectiveLength) throw new Error("Row argument was out of bounds: " + row + " > " + this.effectiveLength);
  233. var colIndex = -1;
  234. if (typeof col === "undefined") {
  235. var _ret = function () {
  236. var rowData = {};
  237. _this3.colnames.forEach(function (name, i) {
  238. rowData[name] = _this3.columns[i][row % _this3.columns[i].length];
  239. });
  240. return {
  241. v: rowData
  242. };
  243. }();
  244. if ((typeof _ret === "undefined" ? "undefined" : _typeof(_ret)) === "object") return _ret.v;
  245. } else if (typeof col === "string") {
  246. colIndex = this._colIndex(col);
  247. } else if (typeof col === "number") {
  248. colIndex = col;
  249. }
  250. if (colIndex < 0 || colIndex > this.columns.length) {
  251. if (missingOK) return void 0;else throw new Error("Unknown column index: " + col);
  252. }
  253. return this.columns[colIndex][row % this.columns[colIndex].length];
  254. }
  255. }, {
  256. key: "nrow",
  257. value: function nrow() {
  258. return this.effectiveLength;
  259. }
  260. }]);
  261. return DataFrame;
  262. }();
  263. exports.default = DataFrame;
  264. },{"./util":17}],5:[function(require,module,exports){
  265. "use strict";
  266. var _leaflet = require("./global/leaflet");
  267. var _leaflet2 = _interopRequireDefault(_leaflet);
  268. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  269. // In RMarkdown's self-contained mode, we don't have a way to carry around the
  270. // images that Leaflet needs but doesn't load into the page. Instead, we'll set
  271. // data URIs for the default marker, and let any others be loaded via CDN.
  272. if (typeof _leaflet2.default.Icon.Default.imagePath === "undefined") {
  273. // if in a local file, support http
  274. switch (window.location.protocol) {
  275. case "http:":
  276. // don't force http site to be done with https
  277. _leaflet2.default.Icon.Default.imagePath = "http://cdn.leafletjs.com/leaflet/v1.3.1/images/";
  278. break;
  279. default:
  280. // file
  281. // https
  282. // otherwise use https as it works on files and https
  283. _leaflet2.default.Icon.Default.imagePath = "https://unpkg.com/leaflet@1.3.1/dist/images/";
  284. break;
  285. }
  286. // don't know how to make this dataURI work since
  287. // will be appended to Defaul.imagePath above
  288. /*
  289. if (L.Browser.retina) {
  290. L.Icon.Default.prototype.options.iconUrl = "data:image/png;base64,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";
  291. } else {
  292. L.Icon.Default.prototype.options.iconUrl = "data:image/png;base64,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";
  293. }
  294. */
  295. }
  296. },{"./global/leaflet":10}],6:[function(require,module,exports){
  297. "use strict";
  298. var _leaflet = require("./global/leaflet");
  299. var _leaflet2 = _interopRequireDefault(_leaflet);
  300. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  301. // add texxtsize, textOnly, and style
  302. _leaflet2.default.Tooltip.prototype.options.textsize = "10px";
  303. _leaflet2.default.Tooltip.prototype.options.textOnly = false;
  304. _leaflet2.default.Tooltip.prototype.options.style = null;
  305. // copy original layout to not completely stomp it.
  306. var initLayoutOriginal = _leaflet2.default.Tooltip.prototype._initLayout;
  307. _leaflet2.default.Tooltip.prototype._initLayout = function () {
  308. initLayoutOriginal.call(this);
  309. this._container.style.fontSize = this.options.textsize;
  310. if (this.options.textOnly) {
  311. _leaflet2.default.DomUtil.addClass(this._container, "leaflet-tooltip-text-only");
  312. }
  313. if (this.options.style) {
  314. for (var property in this.options.style) {
  315. this._container.style[property] = this.options.style[property];
  316. }
  317. }
  318. };
  319. },{"./global/leaflet":10}],7:[function(require,module,exports){
  320. "use strict";
  321. var _leaflet = require("./global/leaflet");
  322. var _leaflet2 = _interopRequireDefault(_leaflet);
  323. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  324. var protocolRegex = /^\/\//;
  325. var upgrade_protocol = function upgrade_protocol(urlTemplate) {
  326. if (protocolRegex.test(urlTemplate)) {
  327. if (window.location.protocol === "file:") {
  328. // if in a local file, support http
  329. // http should auto upgrade if necessary
  330. urlTemplate = "http:" + urlTemplate;
  331. }
  332. }
  333. return urlTemplate;
  334. };
  335. var originalLTileLayerInitialize = _leaflet2.default.TileLayer.prototype.initialize;
  336. _leaflet2.default.TileLayer.prototype.initialize = function (urlTemplate, options) {
  337. urlTemplate = upgrade_protocol(urlTemplate);
  338. originalLTileLayerInitialize.call(this, urlTemplate, options);
  339. };
  340. var originalLTileLayerWMSInitialize = _leaflet2.default.TileLayer.WMS.prototype.initialize;
  341. _leaflet2.default.TileLayer.WMS.prototype.initialize = function (urlTemplate, options) {
  342. urlTemplate = upgrade_protocol(urlTemplate);
  343. originalLTileLayerWMSInitialize.call(this, urlTemplate, options);
  344. };
  345. },{"./global/leaflet":10}],8:[function(require,module,exports){
  346. (function (global){
  347. "use strict";
  348. Object.defineProperty(exports, "__esModule", {
  349. value: true
  350. });
  351. exports.default = global.HTMLWidgets;
  352. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  353. },{}],9:[function(require,module,exports){
  354. (function (global){
  355. "use strict";
  356. Object.defineProperty(exports, "__esModule", {
  357. value: true
  358. });
  359. exports.default = global.jQuery;
  360. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  361. },{}],10:[function(require,module,exports){
  362. (function (global){
  363. "use strict";
  364. Object.defineProperty(exports, "__esModule", {
  365. value: true
  366. });
  367. exports.default = global.L;
  368. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  369. },{}],11:[function(require,module,exports){
  370. (function (global){
  371. "use strict";
  372. Object.defineProperty(exports, "__esModule", {
  373. value: true
  374. });
  375. exports.default = global.L.Proj;
  376. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  377. },{}],12:[function(require,module,exports){
  378. (function (global){
  379. "use strict";
  380. Object.defineProperty(exports, "__esModule", {
  381. value: true
  382. });
  383. exports.default = global.Shiny;
  384. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  385. },{}],13:[function(require,module,exports){
  386. "use strict";
  387. var _jquery = require("./global/jquery");
  388. var _jquery2 = _interopRequireDefault(_jquery);
  389. var _leaflet = require("./global/leaflet");
  390. var _leaflet2 = _interopRequireDefault(_leaflet);
  391. var _shiny = require("./global/shiny");
  392. var _shiny2 = _interopRequireDefault(_shiny);
  393. var _htmlwidgets = require("./global/htmlwidgets");
  394. var _htmlwidgets2 = _interopRequireDefault(_htmlwidgets);
  395. var _util = require("./util");
  396. var _crs_utils = require("./crs_utils");
  397. var _controlStore = require("./control-store");
  398. var _controlStore2 = _interopRequireDefault(_controlStore);
  399. var _layerManager = require("./layer-manager");
  400. var _layerManager2 = _interopRequireDefault(_layerManager);
  401. var _methods = require("./methods");
  402. var _methods2 = _interopRequireDefault(_methods);
  403. require("./fixup-default-icon");
  404. require("./fixup-default-tooltip");
  405. require("./fixup-url-protocol");
  406. var _dataframe = require("./dataframe");
  407. var _dataframe2 = _interopRequireDefault(_dataframe);
  408. var _clusterLayerStore = require("./cluster-layer-store");
  409. var _clusterLayerStore2 = _interopRequireDefault(_clusterLayerStore);
  410. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  411. window.LeafletWidget = {};
  412. window.LeafletWidget.utils = {};
  413. var methods = window.LeafletWidget.methods = _jquery2.default.extend({}, _methods2.default);
  414. window.LeafletWidget.DataFrame = _dataframe2.default;
  415. window.LeafletWidget.ClusterLayerStore = _clusterLayerStore2.default;
  416. window.LeafletWidget.utils.getCRS = _crs_utils.getCRS;
  417. // Send updated bounds back to app. Takes a leaflet event object as input.
  418. function updateBounds(map) {
  419. var id = map.getContainer().id;
  420. var bounds = map.getBounds();
  421. _shiny2.default.onInputChange(id + "_bounds", {
  422. north: bounds.getNorthEast().lat,
  423. east: bounds.getNorthEast().lng,
  424. south: bounds.getSouthWest().lat,
  425. west: bounds.getSouthWest().lng
  426. });
  427. _shiny2.default.onInputChange(id + "_center", {
  428. lng: map.getCenter().lng,
  429. lat: map.getCenter().lat
  430. });
  431. _shiny2.default.onInputChange(id + "_zoom", map.getZoom());
  432. }
  433. function preventUnintendedZoomOnScroll(map) {
  434. // Prevent unwanted scroll capturing. Similar in purpose to
  435. // https://github.com/CliffCloud/Leaflet.Sleep but with a
  436. // different set of heuristics.
  437. // The basic idea is that when a mousewheel/DOMMouseScroll
  438. // event is seen, we disable scroll wheel zooming until the
  439. // user moves their mouse cursor or clicks on the map. This
  440. // is slightly trickier than just listening for mousemove,
  441. // because mousemove is fired when the page is scrolled,
  442. // even if the user did not physically move the mouse. We
  443. // handle this by examining the mousemove event's screenX
  444. // and screenY properties; if they change, we know it's a
  445. // "true" move.
  446. // lastScreen can never be null, but its x and y can.
  447. var lastScreen = { x: null, y: null };
  448. (0, _jquery2.default)(document).on("mousewheel DOMMouseScroll", "*", function (e) {
  449. // Disable zooming (until the mouse moves or click)
  450. map.scrollWheelZoom.disable();
  451. // Any mousemove events at this screen position will be ignored.
  452. lastScreen = { x: e.originalEvent.screenX, y: e.originalEvent.screenY };
  453. });
  454. (0, _jquery2.default)(document).on("mousemove", "*", function (e) {
  455. // Did the mouse really move?
  456. if (lastScreen.x !== null && e.screenX !== lastScreen.x || e.screenY !== lastScreen.y) {
  457. // It really moved. Enable zooming.
  458. map.scrollWheelZoom.enable();
  459. lastScreen = { x: null, y: null };
  460. }
  461. });
  462. (0, _jquery2.default)(document).on("mousedown", ".leaflet", function (e) {
  463. // Clicking always enables zooming.
  464. map.scrollWheelZoom.enable();
  465. lastScreen = { x: null, y: null };
  466. });
  467. }
  468. _htmlwidgets2.default.widget({
  469. name: "leaflet",
  470. type: "output",
  471. factory: function factory(el, width, height) {
  472. var map = null;
  473. return {
  474. // we need to store our map in our returned object.
  475. getMap: function getMap() {
  476. return map;
  477. },
  478. renderValue: function renderValue(data) {
  479. // Create an appropriate CRS Object if specified
  480. if (data && data.options && data.options.crs) {
  481. data.options.crs = (0, _crs_utils.getCRS)(data.options.crs);
  482. }
  483. // As per https://github.com/rstudio/leaflet/pull/294#discussion_r79584810
  484. if (map) {
  485. map.remove();
  486. map = function () {
  487. return;
  488. }(); // undefine map
  489. }
  490. if (data.options.mapFactory && typeof data.options.mapFactory === "function") {
  491. map = data.options.mapFactory(el, data.options);
  492. } else {
  493. map = _leaflet2.default.map(el, data.options);
  494. }
  495. preventUnintendedZoomOnScroll(map);
  496. // Store some state in the map object
  497. map.leafletr = {
  498. // Has the map ever rendered successfully?
  499. hasRendered: false,
  500. // Data to be rendered when resize is called with area != 0
  501. pendingRenderData: null
  502. };
  503. // Check if the map is rendered statically (no output binding)
  504. if (_htmlwidgets2.default.shinyMode && /\bshiny-bound-output\b/.test(el.className)) {
  505. (function () {
  506. map.id = el.id;
  507. // Store the map on the element so we can find it later by ID
  508. (0, _jquery2.default)(el).data("leaflet-map", map);
  509. // When the map is clicked, send the coordinates back to the app
  510. map.on("click", function (e) {
  511. _shiny2.default.onInputChange(map.id + "_click", {
  512. lat: e.latlng.lat,
  513. lng: e.latlng.lng,
  514. ".nonce": Math.random() // Force reactivity if lat/lng hasn't changed
  515. });
  516. });
  517. var groupTimerId = null;
  518. map.on("moveend", function (e) {
  519. updateBounds(e.target);
  520. }).on("layeradd layerremove", function (e) {
  521. // If the layer that's coming or going is a group we created, tell
  522. // the server.
  523. if (map.layerManager.getGroupNameFromLayerGroup(e.layer)) {
  524. // But to avoid chattiness, coalesce events
  525. if (groupTimerId) {
  526. clearTimeout(groupTimerId);
  527. groupTimerId = null;
  528. }
  529. groupTimerId = setTimeout(function () {
  530. groupTimerId = null;
  531. _shiny2.default.onInputChange(map.id + "_groups", map.layerManager.getVisibleGroups());
  532. }, 100);
  533. }
  534. });
  535. })();
  536. }
  537. this.doRenderValue(data, map);
  538. },
  539. doRenderValue: function doRenderValue(data, map) {
  540. // Leaflet does not behave well when you set up a bunch of layers when
  541. // the map is not visible (width/height == 0). Popups get misaligned
  542. // relative to their owning markers, and the fitBounds calculations
  543. // are off. Therefore we wait until the map is actually showing to
  544. // render the value (we rely on the resize() callback being invoked
  545. // at the appropriate time).
  546. //
  547. // There may be an issue with leafletProxy() calls being made while
  548. // the map is not being viewed--not sure what the right solution is
  549. // there.
  550. if (el.offsetWidth === 0 || el.offsetHeight === 0) {
  551. map.leafletr.pendingRenderData = data;
  552. return;
  553. }
  554. map.leafletr.pendingRenderData = null;
  555. // Merge data options into defaults
  556. var options = _jquery2.default.extend({ zoomToLimits: "always" }, data.options);
  557. if (!map.layerManager) {
  558. map.controls = new _controlStore2.default(map);
  559. map.layerManager = new _layerManager2.default(map);
  560. } else {
  561. map.controls.clear();
  562. map.layerManager.clear();
  563. }
  564. var explicitView = false;
  565. if (data.setView) {
  566. explicitView = true;
  567. map.setView.apply(map, data.setView);
  568. }
  569. if (data.fitBounds) {
  570. explicitView = true;
  571. methods.fitBounds.apply(map, data.fitBounds);
  572. }
  573. if (data.flyTo) {
  574. if (!explicitView && !map.leafletr.hasRendered) {
  575. // must be done to give a initial starting point
  576. map.fitWorld();
  577. }
  578. explicitView = true;
  579. map.flyTo.apply(map, data.flyTo);
  580. }
  581. if (data.flyToBounds) {
  582. if (!explicitView && !map.leafletr.hasRendered) {
  583. // must be done to give a initial starting point
  584. map.fitWorld();
  585. }
  586. explicitView = true;
  587. methods.flyToBounds.apply(map, data.flyToBounds);
  588. }
  589. if (data.options.center) {
  590. explicitView = true;
  591. }
  592. // Returns true if the zoomToLimits option says that the map should be
  593. // zoomed to map elements.
  594. function needsZoom() {
  595. return options.zoomToLimits === "always" || options.zoomToLimits === "first" && !map.leafletr.hasRendered;
  596. }
  597. if (!explicitView && needsZoom() && !map.getZoom()) {
  598. if (data.limits && !_jquery2.default.isEmptyObject(data.limits)) {
  599. // Use the natural limits of what's being drawn on the map
  600. // If the size of the bounding box is 0, leaflet gets all weird
  601. var pad = 0.006;
  602. if (data.limits.lat[0] === data.limits.lat[1]) {
  603. data.limits.lat[0] = data.limits.lat[0] - pad;
  604. data.limits.lat[1] = data.limits.lat[1] + pad;
  605. }
  606. if (data.limits.lng[0] === data.limits.lng[1]) {
  607. data.limits.lng[0] = data.limits.lng[0] - pad;
  608. data.limits.lng[1] = data.limits.lng[1] + pad;
  609. }
  610. map.fitBounds([[data.limits.lat[0], data.limits.lng[0]], [data.limits.lat[1], data.limits.lng[1]]]);
  611. } else {
  612. map.fitWorld();
  613. }
  614. }
  615. for (var i = 0; data.calls && i < data.calls.length; i++) {
  616. var call = data.calls[i];
  617. if (methods[call.method]) methods[call.method].apply(map, call.args);else (0, _util.log)("Unknown method " + call.method);
  618. }
  619. map.leafletr.hasRendered = true;
  620. if (_htmlwidgets2.default.shinyMode) {
  621. setTimeout(function () {
  622. updateBounds(map);
  623. }, 1);
  624. }
  625. },
  626. resize: function resize(width, height) {
  627. if (map) {
  628. map.invalidateSize();
  629. if (map.leafletr.pendingRenderData) {
  630. this.doRenderValue(map.leafletr.pendingRenderData, map);
  631. }
  632. }
  633. }
  634. };
  635. }
  636. });
  637. if (_htmlwidgets2.default.shinyMode) {
  638. _shiny2.default.addCustomMessageHandler("leaflet-calls", function (data) {
  639. var id = data.id;
  640. var el = document.getElementById(id);
  641. var map = el ? (0, _jquery2.default)(el).data("leaflet-map") : null;
  642. if (!map) {
  643. (0, _util.log)("Couldn't find map with id " + id);
  644. return;
  645. }
  646. for (var i = 0; i < data.calls.length; i++) {
  647. var call = data.calls[i];
  648. if (call.dependencies) {
  649. _shiny2.default.renderDependencies(call.dependencies);
  650. }
  651. if (methods[call.method]) methods[call.method].apply(map, call.args);else (0, _util.log)("Unknown method " + call.method);
  652. }
  653. });
  654. }
  655. },{"./cluster-layer-store":1,"./control-store":2,"./crs_utils":3,"./dataframe":4,"./fixup-default-icon":5,"./fixup-default-tooltip":6,"./fixup-url-protocol":7,"./global/htmlwidgets":8,"./global/jquery":9,"./global/leaflet":10,"./global/shiny":12,"./layer-manager":14,"./methods":15,"./util":17}],14:[function(require,module,exports){
  656. (function (global){
  657. "use strict";
  658. Object.defineProperty(exports, "__esModule", {
  659. value: true
  660. });
  661. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  662. var _jquery = require("./global/jquery");
  663. var _jquery2 = _interopRequireDefault(_jquery);
  664. var _leaflet = require("./global/leaflet");
  665. var _leaflet2 = _interopRequireDefault(_leaflet);
  666. var _util = require("./util");
  667. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  668. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  669. var LayerManager = function () {
  670. function LayerManager(map) {
  671. _classCallCheck(this, LayerManager);
  672. this._map = map;
  673. // BEGIN layer indices
  674. // {<groupname>: {<stamp>: layer}}
  675. this._byGroup = {};
  676. // {<categoryName>: {<stamp>: layer}}
  677. this._byCategory = {};
  678. // {<categoryName_layerId>: layer}
  679. this._byLayerId = {};
  680. // {<stamp>: {
  681. // "group": <groupname>,
  682. // "layerId": <layerId>,
  683. // "category": <category>,
  684. // "container": <container>
  685. // }
  686. // }
  687. this._byStamp = {};
  688. // {<crosstalkGroupName>: {<key>: [<stamp>, <stamp>, ...], ...}}
  689. this._byCrosstalkGroup = {};
  690. // END layer indices
  691. // {<categoryName>: L.layerGroup}
  692. this._categoryContainers = {};
  693. // {<groupName>: L.layerGroup}
  694. this._groupContainers = {};
  695. }
  696. _createClass(LayerManager, [{
  697. key: "addLayer",
  698. value: function addLayer(layer, category, layerId, group, ctGroup, ctKey) {
  699. var _this = this;
  700. // Was a group provided?
  701. var hasId = typeof layerId === "string";
  702. var grouped = typeof group === "string";
  703. var stamp = _leaflet2.default.Util.stamp(layer) + "";
  704. // This will be the default layer group to add the layer to.
  705. // We may overwrite this let before using it (i.e. if a group is assigned).
  706. // This one liner creates the _categoryContainers[category] entry if it
  707. // doesn't already exist.
  708. var container = this._categoryContainers[category] = this._categoryContainers[category] || _leaflet2.default.layerGroup().addTo(this._map);
  709. var oldLayer = null;
  710. if (hasId) {
  711. // First, remove any layer with the same category and layerId
  712. var prefixedLayerId = this._layerIdKey(category, layerId);
  713. oldLayer = this._byLayerId[prefixedLayerId];
  714. if (oldLayer) {
  715. this._removeLayer(oldLayer);
  716. }
  717. // Update layerId index
  718. this._byLayerId[prefixedLayerId] = layer;
  719. }
  720. // Update group index
  721. if (grouped) {
  722. this._byGroup[group] = this._byGroup[group] || {};
  723. this._byGroup[group][stamp] = layer;
  724. // Since a group is assigned, don't add the layer to the category's layer
  725. // group; instead, use the group's layer group.
  726. // This one liner creates the _groupContainers[group] entry if it doesn't
  727. // already exist.
  728. container = this.getLayerGroup(group, true);
  729. }
  730. // Update category index
  731. this._byCategory[category] = this._byCategory[category] || {};
  732. this._byCategory[category][stamp] = layer;
  733. // Update stamp index
  734. var layerInfo = this._byStamp[stamp] = {
  735. layer: layer,
  736. group: group,
  737. ctGroup: ctGroup,
  738. ctKey: ctKey,
  739. layerId: layerId,
  740. category: category,
  741. container: container,
  742. hidden: false
  743. };
  744. // Update crosstalk group index
  745. if (ctGroup) {
  746. (function () {
  747. if (layer.setStyle) {
  748. // Need to save this info so we know what to set opacity to later
  749. layer.options.origOpacity = typeof layer.options.opacity !== "undefined" ? layer.options.opacity : 0.5;
  750. layer.options.origFillOpacity = typeof layer.options.fillOpacity !== "undefined" ? layer.options.fillOpacity : 0.2;
  751. }
  752. var ctg = _this._byCrosstalkGroup[ctGroup];
  753. if (!ctg) {
  754. (function () {
  755. ctg = _this._byCrosstalkGroup[ctGroup] = {};
  756. var crosstalk = global.crosstalk;
  757. var handleFilter = function handleFilter(e) {
  758. if (!e.value) {
  759. var groupKeys = Object.keys(ctg);
  760. for (var i = 0; i < groupKeys.length; i++) {
  761. var key = groupKeys[i];
  762. var _layerInfo = _this._byStamp[ctg[key]];
  763. _this._setVisibility(_layerInfo, true);
  764. }
  765. } else {
  766. var selectedKeys = {};
  767. for (var _i = 0; _i < e.value.length; _i++) {
  768. selectedKeys[e.value[_i]] = true;
  769. }
  770. var _groupKeys = Object.keys(ctg);
  771. for (var _i2 = 0; _i2 < _groupKeys.length; _i2++) {
  772. var _key = _groupKeys[_i2];
  773. var _layerInfo2 = _this._byStamp[ctg[_key]];
  774. _this._setVisibility(_layerInfo2, selectedKeys[_groupKeys[_i2]]);
  775. }
  776. }
  777. };
  778. var filterHandle = new crosstalk.FilterHandle(ctGroup);
  779. filterHandle.on("change", handleFilter);
  780. var handleSelection = function handleSelection(e) {
  781. if (!e.value || !e.value.length) {
  782. var groupKeys = Object.keys(ctg);
  783. for (var i = 0; i < groupKeys.length; i++) {
  784. var key = groupKeys[i];
  785. var _layerInfo3 = _this._byStamp[ctg[key]];
  786. _this._setOpacity(_layerInfo3, 1.0);
  787. }
  788. } else {
  789. var selectedKeys = {};
  790. for (var _i3 = 0; _i3 < e.value.length; _i3++) {
  791. selectedKeys[e.value[_i3]] = true;
  792. }
  793. var _groupKeys2 = Object.keys(ctg);
  794. for (var _i4 = 0; _i4 < _groupKeys2.length; _i4++) {
  795. var _key2 = _groupKeys2[_i4];
  796. var _layerInfo4 = _this._byStamp[ctg[_key2]];
  797. _this._setOpacity(_layerInfo4, selectedKeys[_groupKeys2[_i4]] ? 1.0 : 0.2);
  798. }
  799. }
  800. };
  801. var selHandle = new crosstalk.SelectionHandle(ctGroup);
  802. selHandle.on("change", handleSelection);
  803. setTimeout(function () {
  804. handleFilter({ value: filterHandle.filteredKeys });
  805. handleSelection({ value: selHandle.value });
  806. }, 100);
  807. })();
  808. }
  809. if (!ctg[ctKey]) ctg[ctKey] = [];
  810. ctg[ctKey].push(stamp);
  811. })();
  812. }
  813. // Add to container
  814. if (!layerInfo.hidden) container.addLayer(layer);
  815. return oldLayer;
  816. }
  817. }, {
  818. key: "brush",
  819. value: function brush(bounds, extraInfo) {
  820. var _this2 = this;
  821. /* eslint-disable no-console */
  822. // For each Crosstalk group...
  823. Object.keys(this._byCrosstalkGroup).forEach(function (ctGroupName) {
  824. var ctg = _this2._byCrosstalkGroup[ctGroupName];
  825. var selection = [];
  826. // ...iterate over each Crosstalk key (each of which may have multiple
  827. // layers)...
  828. Object.keys(ctg).forEach(function (ctKey) {
  829. // ...and for each layer...
  830. ctg[ctKey].forEach(function (stamp) {
  831. var layerInfo = _this2._byStamp[stamp];
  832. // ...if it's something with a point...
  833. if (layerInfo.layer.getLatLng) {
  834. // ... and it's inside the selection bounds...
  835. // TODO: Use pixel containment, not lat/lng containment
  836. if (bounds.contains(layerInfo.layer.getLatLng())) {
  837. // ...add the key to the selection.
  838. selection.push(ctKey);
  839. }
  840. }
  841. });
  842. });
  843. new global.crosstalk.SelectionHandle(ctGroupName).set(selection, extraInfo);
  844. });
  845. }
  846. }, {
  847. key: "unbrush",
  848. value: function unbrush(extraInfo) {
  849. Object.keys(this._byCrosstalkGroup).forEach(function (ctGroupName) {
  850. new global.crosstalk.SelectionHandle(ctGroupName).clear(extraInfo);
  851. });
  852. }
  853. }, {
  854. key: "_setVisibility",
  855. value: function _setVisibility(layerInfo, visible) {
  856. if (layerInfo.hidden ^ visible) {
  857. return;
  858. } else if (visible) {
  859. layerInfo.container.addLayer(layerInfo.layer);
  860. layerInfo.hidden = false;
  861. } else {
  862. layerInfo.container.removeLayer(layerInfo.layer);
  863. layerInfo.hidden = true;
  864. }
  865. }
  866. }, {
  867. key: "_setOpacity",
  868. value: function _setOpacity(layerInfo, opacity) {
  869. if (layerInfo.layer.setOpacity) {
  870. layerInfo.layer.setOpacity(opacity);
  871. } else if (layerInfo.layer.setStyle) {
  872. layerInfo.layer.setStyle({
  873. opacity: opacity * layerInfo.layer.options.origOpacity,
  874. fillOpacity: opacity * layerInfo.layer.options.origFillOpacity
  875. });
  876. }
  877. }
  878. }, {
  879. key: "getLayer",
  880. value: function getLayer(category, layerId) {
  881. return this._byLayerId[this._layerIdKey(category, layerId)];
  882. }
  883. }, {
  884. key: "removeLayer",
  885. value: function removeLayer(category, layerIds) {
  886. var _this3 = this;
  887. // Find layer info
  888. _jquery2.default.each((0, _util.asArray)(layerIds), function (i, layerId) {
  889. var layer = _this3._byLayerId[_this3._layerIdKey(category, layerId)];
  890. if (layer) {
  891. _this3._removeLayer(layer);
  892. }
  893. });
  894. }
  895. }, {
  896. key: "clearLayers",
  897. value: function clearLayers(category) {
  898. var _this4 = this;
  899. // Find all layers in _byCategory[category]
  900. var catTable = this._byCategory[category];
  901. if (!catTable) {
  902. return false;
  903. }
  904. // Remove all layers. Make copy of keys to avoid mutating the collection
  905. // behind the iterator you're accessing.
  906. var stamps = [];
  907. _jquery2.default.each(catTable, function (k, v) {
  908. stamps.push(k);
  909. });
  910. _jquery2.default.each(stamps, function (i, stamp) {
  911. _this4._removeLayer(stamp);
  912. });
  913. }
  914. }, {
  915. key: "getLayerGroup",
  916. value: function getLayerGroup(group, ensureExists) {
  917. var g = this._groupContainers[group];
  918. if (ensureExists && !g) {
  919. this._byGroup[group] = this._byGroup[group] || {};
  920. g = this._groupContainers[group] = _leaflet2.default.featureGroup();
  921. g.groupname = group;
  922. g.addTo(this._map);
  923. }
  924. return g;
  925. }
  926. }, {
  927. key: "getGroupNameFromLayerGroup",
  928. value: function getGroupNameFromLayerGroup(layerGroup) {
  929. return layerGroup.groupname;
  930. }
  931. }, {
  932. key: "getVisibleGroups",
  933. value: function getVisibleGroups() {
  934. var _this5 = this;
  935. var result = [];
  936. _jquery2.default.each(this._groupContainers, function (k, v) {
  937. if (_this5._map.hasLayer(v)) {
  938. result.push(k);
  939. }
  940. });
  941. return result;
  942. }
  943. }, {
  944. key: "getAllGroupNames",
  945. value: function getAllGroupNames() {
  946. var result = [];
  947. _jquery2.default.each(this._groupContainers, function (k, v) {
  948. result.push(k);
  949. });
  950. return result;
  951. }
  952. }, {
  953. key: "clearGroup",
  954. value: function clearGroup(group) {
  955. var _this6 = this;
  956. // Find all layers in _byGroup[group]
  957. var groupTable = this._byGroup[group];
  958. if (!groupTable) {
  959. return false;
  960. }
  961. // Remove all layers. Make copy of keys to avoid mutating the collection
  962. // behind the iterator you're accessing.
  963. var stamps = [];
  964. _jquery2.default.each(groupTable, function (k, v) {
  965. stamps.push(k);
  966. });
  967. _jquery2.default.each(stamps, function (i, stamp) {
  968. _this6._removeLayer(stamp);
  969. });
  970. }
  971. }, {
  972. key: "clear",
  973. value: function clear() {
  974. function clearLayerGroup(key, layerGroup) {
  975. layerGroup.clearLayers();
  976. }
  977. // Clear all indices and layerGroups
  978. this._byGroup = {};
  979. this._byCategory = {};
  980. this._byLayerId = {};
  981. this._byStamp = {};
  982. this._byCrosstalkGroup = {};
  983. _jquery2.default.each(this._categoryContainers, clearLayerGroup);
  984. this._categoryContainers = {};
  985. _jquery2.default.each(this._groupContainers, clearLayerGroup);
  986. this._groupContainers = {};
  987. }
  988. }, {
  989. key: "_removeLayer",
  990. value: function _removeLayer(layer) {
  991. var stamp = void 0;
  992. if (typeof layer === "string") {
  993. stamp = layer;
  994. } else {
  995. stamp = _leaflet2.default.Util.stamp(layer);
  996. }
  997. var layerInfo = this._byStamp[stamp];
  998. if (!layerInfo) {
  999. return false;
  1000. }
  1001. layerInfo.container.removeLayer(stamp);
  1002. if (typeof layerInfo.group === "string") {
  1003. delete this._byGroup[layerInfo.group][stamp];
  1004. }
  1005. if (typeof layerInfo.layerId === "string") {
  1006. delete this._byLayerId[this._layerIdKey(layerInfo.category, layerInfo.layerId)];
  1007. }
  1008. delete this._byCategory[layerInfo.category][stamp];
  1009. delete this._byStamp[stamp];
  1010. if (layerInfo.ctGroup) {
  1011. var ctGroup = this._byCrosstalkGroup[layerInfo.ctGroup];
  1012. var layersForKey = ctGroup[layerInfo.ctKey];
  1013. var idx = layersForKey ? layersForKey.indexOf(stamp) : -1;
  1014. if (idx >= 0) {
  1015. if (layersForKey.length === 1) {
  1016. delete ctGroup[layerInfo.ctKey];
  1017. } else {
  1018. layersForKey.splice(idx, 1);
  1019. }
  1020. }
  1021. }
  1022. }
  1023. }, {
  1024. key: "_layerIdKey",
  1025. value: function _layerIdKey(category, layerId) {
  1026. return category + "\n" + layerId;
  1027. }
  1028. }]);
  1029. return LayerManager;
  1030. }();
  1031. exports.default = LayerManager;
  1032. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1033. },{"./global/jquery":9,"./global/leaflet":10,"./util":17}],15:[function(require,module,exports){
  1034. (function (global){
  1035. "use strict";
  1036. Object.defineProperty(exports, "__esModule", {
  1037. value: true
  1038. });
  1039. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
  1040. var _jquery = require("./global/jquery");
  1041. var _jquery2 = _interopRequireDefault(_jquery);
  1042. var _leaflet = require("./global/leaflet");
  1043. var _leaflet2 = _interopRequireDefault(_leaflet);
  1044. var _shiny = require("./global/shiny");
  1045. var _shiny2 = _interopRequireDefault(_shiny);
  1046. var _htmlwidgets = require("./global/htmlwidgets");
  1047. var _htmlwidgets2 = _interopRequireDefault(_htmlwidgets);
  1048. var _util = require("./util");
  1049. var _crs_utils = require("./crs_utils");
  1050. var _dataframe = require("./dataframe");
  1051. var _dataframe2 = _interopRequireDefault(_dataframe);
  1052. var _clusterLayerStore = require("./cluster-layer-store");
  1053. var _clusterLayerStore2 = _interopRequireDefault(_clusterLayerStore);
  1054. var _mipmapper = require("./mipmapper");
  1055. var _mipmapper2 = _interopRequireDefault(_mipmapper);
  1056. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  1057. var methods = {};
  1058. exports.default = methods;
  1059. function mouseHandler(mapId, layerId, group, eventName, extraInfo) {
  1060. return function (e) {
  1061. if (!_htmlwidgets2.default.shinyMode) return;
  1062. var latLng = e.target.getLatLng ? e.target.getLatLng() : e.latlng;
  1063. if (latLng) {
  1064. // retrieve only lat, lon values to remove prototype
  1065. // and extra parameters added by 3rd party modules
  1066. // these objects are for json serialization, not javascript
  1067. var latLngVal = _leaflet2.default.latLng(latLng); // make sure it has consistent shape
  1068. latLng = { lat: latLngVal.lat, lng: latLngVal.lng };
  1069. }
  1070. var eventInfo = _jquery2.default.extend({
  1071. id: layerId,
  1072. ".nonce": Math.random() // force reactivity
  1073. }, group !== null ? { group: group } : null, latLng, extraInfo);
  1074. _shiny2.default.onInputChange(mapId + "_" + eventName, eventInfo);
  1075. };
  1076. }
  1077. methods.mouseHandler = mouseHandler;
  1078. methods.clearGroup = function (group) {
  1079. var _this = this;
  1080. _jquery2.default.each((0, _util.asArray)(group), function (i, v) {
  1081. _this.layerManager.clearGroup(v);
  1082. });
  1083. };
  1084. methods.setView = function (center, zoom, options) {
  1085. this.setView(center, zoom, options);
  1086. };
  1087. methods.fitBounds = function (lat1, lng1, lat2, lng2, options) {
  1088. this.fitBounds([[lat1, lng1], [lat2, lng2]], options);
  1089. };
  1090. methods.flyTo = function (center, zoom, options) {
  1091. this.flyTo(center, zoom, options);
  1092. };
  1093. methods.flyToBounds = function (lat1, lng1, lat2, lng2, options) {
  1094. this.flyToBounds([[lat1, lng1], [lat2, lng2]], options);
  1095. };
  1096. methods.setMaxBounds = function (lat1, lng1, lat2, lng2) {
  1097. this.setMaxBounds([[lat1, lng1], [lat2, lng2]]);
  1098. };
  1099. methods.addPopups = function (lat, lng, popup, layerId, group, options) {
  1100. var _this2 = this;
  1101. var df = new _dataframe2.default().col("lat", lat).col("lng", lng).col("popup", popup).col("layerId", layerId).col("group", group).cbind(options);
  1102. var _loop = function _loop(i) {
  1103. if (_jquery2.default.isNumeric(df.get(i, "lat")) && _jquery2.default.isNumeric(df.get(i, "lng"))) {
  1104. (function () {
  1105. var popup = _leaflet2.default.popup(df.get(i)).setLatLng([df.get(i, "lat"), df.get(i, "lng")]).setContent(df.get(i, "popup"));
  1106. var thisId = df.get(i, "layerId");
  1107. var thisGroup = df.get(i, "group");
  1108. this.layerManager.addLayer(popup, "popup", thisId, thisGroup);
  1109. }).call(_this2);
  1110. }
  1111. };
  1112. for (var i = 0; i < df.nrow(); i++) {
  1113. _loop(i);
  1114. }
  1115. };
  1116. methods.removePopup = function (layerId) {
  1117. this.layerManager.removeLayer("popup", layerId);
  1118. };
  1119. methods.clearPopups = function () {
  1120. this.layerManager.clearLayers("popup");
  1121. };
  1122. methods.addTiles = function (urlTemplate, layerId, group, options) {
  1123. this.layerManager.addLayer(_leaflet2.default.tileLayer(urlTemplate, options), "tile", layerId, group);
  1124. };
  1125. methods.removeTiles = function (layerId) {
  1126. this.layerManager.removeLayer("tile", layerId);
  1127. };
  1128. methods.clearTiles = function () {
  1129. this.layerManager.clearLayers("tile");
  1130. };
  1131. methods.addWMSTiles = function (baseUrl, layerId, group, options) {
  1132. if (options && options.crs) {
  1133. options.crs = (0, _crs_utils.getCRS)(options.crs);
  1134. }
  1135. this.layerManager.addLayer(_leaflet2.default.tileLayer.wms(baseUrl, options), "tile", layerId, group);
  1136. };
  1137. // Given:
  1138. // {data: ["a", "b", "c"], index: [0, 1, 0, 2]}
  1139. // returns:
  1140. // ["a", "b", "a", "c"]
  1141. function unpackStrings(iconset) {
  1142. if (!iconset) {
  1143. return iconset;
  1144. }
  1145. if (typeof iconset.index === "undefined") {
  1146. return iconset;
  1147. }
  1148. iconset.data = (0, _util.asArray)(iconset.data);
  1149. iconset.index = (0, _util.asArray)(iconset.index);
  1150. return _jquery2.default.map(iconset.index, function (e, i) {
  1151. return iconset.data[e];
  1152. });
  1153. }
  1154. function addMarkers(map, df, group, clusterOptions, clusterId, markerFunc) {
  1155. (function () {
  1156. var _this3 = this;
  1157. var clusterGroup = this.layerManager.getLayer("cluster", clusterId),
  1158. cluster = clusterOptions !== null;
  1159. if (cluster && !clusterGroup) {
  1160. clusterGroup = _leaflet2.default.markerClusterGroup.layerSupport(clusterOptions);
  1161. if (clusterOptions.freezeAtZoom) {
  1162. var freezeAtZoom = clusterOptions.freezeAtZoom;
  1163. delete clusterOptions.freezeAtZoom;
  1164. clusterGroup.freezeAtZoom(freezeAtZoom);
  1165. }
  1166. clusterGroup.clusterLayerStore = new _clusterLayerStore2.default(clusterGroup);
  1167. }
  1168. var extraInfo = cluster ? { clusterId: clusterId } : {};
  1169. var _loop2 = function _loop2(i) {
  1170. if (_jquery2.default.isNumeric(df.get(i, "lat")) && _jquery2.default.isNumeric(df.get(i, "lng"))) {
  1171. (function () {
  1172. var marker = markerFunc(df, i);
  1173. var thisId = df.get(i, "layerId");
  1174. var thisGroup = cluster ? null : df.get(i, "group");
  1175. if (cluster) {
  1176. clusterGroup.clusterLayerStore.add(marker, thisId);
  1177. } else {
  1178. this.layerManager.addLayer(marker, "marker", thisId, thisGroup, df.get(i, "ctGroup", true), df.get(i, "ctKey", true));
  1179. }
  1180. var popup = df.get(i, "popup");
  1181. var popupOptions = df.get(i, "popupOptions");
  1182. if (popup !== null) {
  1183. if (popupOptions !== null) {
  1184. marker.bindPopup(popup, popupOptions);
  1185. } else {
  1186. marker.bindPopup(popup);
  1187. }
  1188. }
  1189. var label = df.get(i, "label");
  1190. var labelOptions = df.get(i, "labelOptions");
  1191. if (label !== null) {
  1192. if (labelOptions !== null) {
  1193. if (labelOptions.permanent) {
  1194. marker.bindTooltip(label, labelOptions).openTooltip();
  1195. } else {
  1196. marker.bindTooltip(label, labelOptions);
  1197. }
  1198. } else {
  1199. marker.bindTooltip(label);
  1200. }
  1201. }
  1202. marker.on("click", mouseHandler(this.id, thisId, thisGroup, "marker_click", extraInfo), this);
  1203. marker.on("mouseover", mouseHandler(this.id, thisId, thisGroup, "marker_mouseover", extraInfo), this);
  1204. marker.on("mouseout", mouseHandler(this.id, thisId, thisGroup, "marker_mouseout", extraInfo), this);
  1205. marker.on("dragend", mouseHandler(this.id, thisId, thisGroup, "marker_dragend", extraInfo), this);
  1206. }).call(_this3);
  1207. }
  1208. };
  1209. for (var i = 0; i < df.nrow(); i++) {
  1210. _loop2(i);
  1211. }
  1212. if (cluster) {
  1213. this.layerManager.addLayer(clusterGroup, "cluster", clusterId, group);
  1214. }
  1215. }).call(map);
  1216. }
  1217. methods.addGenericMarkers = addMarkers;
  1218. methods.addMarkers = function (lat, lng, icon, layerId, group, options, popup, popupOptions, clusterOptions, clusterId, label, labelOptions, crosstalkOptions) {
  1219. var icondf = void 0;
  1220. var getIcon = void 0;
  1221. if (icon) {
  1222. // Unpack icons
  1223. icon.iconUrl = unpackStrings(icon.iconUrl);
  1224. icon.iconRetinaUrl = unpackStrings(icon.iconRetinaUrl);
  1225. icon.shadowUrl = unpackStrings(icon.shadowUrl);
  1226. icon.shadowRetinaUrl = unpackStrings(icon.shadowRetinaUrl);
  1227. // This cbinds the icon URLs and any other icon options; they're all
  1228. // present on the icon object.
  1229. icondf = new _dataframe2.default().cbind(icon);
  1230. // Constructs an icon from a specified row of the icon dataframe.
  1231. getIcon = function getIcon(i) {
  1232. var opts = icondf.get(i);
  1233. if (!opts.iconUrl) {
  1234. return new _leaflet2.default.Icon.Default();
  1235. }
  1236. // Composite options (like points or sizes) are passed from R with each
  1237. // individual component as its own option. We need to combine them now
  1238. // into their composite form.
  1239. if (opts.iconWidth) {
  1240. opts.iconSize = [opts.iconWidth, opts.iconHeight];
  1241. }
  1242. if (opts.shadowWidth) {
  1243. opts.shadowSize = [opts.shadowWidth, opts.shadowHeight];
  1244. }
  1245. if (opts.iconAnchorX) {
  1246. opts.iconAnchor = [opts.iconAnchorX, opts.iconAnchorY];
  1247. }
  1248. if (opts.shadowAnchorX) {
  1249. opts.shadowAnchor = [opts.shadowAnchorX, opts.shadowAnchorY];
  1250. }
  1251. if (opts.popupAnchorX) {
  1252. opts.popupAnchor = [opts.popupAnchorX, opts.popupAnchorY];
  1253. }
  1254. return new _leaflet2.default.Icon(opts);
  1255. };
  1256. }
  1257. if (!(_jquery2.default.isEmptyObject(lat) || _jquery2.default.isEmptyObject(lng)) || _jquery2.default.isNumeric(lat) && _jquery2.default.isNumeric(lng)) {
  1258. var df = new _dataframe2.default().col("lat", lat).col("lng", lng).col("layerId", layerId).col("group", group).col("popup", popup).col("popupOptions", popupOptions).col("label", label).col("labelOptions", labelOptions).cbind(options).cbind(crosstalkOptions || {});
  1259. if (icon) icondf.effectiveLength = df.nrow();
  1260. addMarkers(this, df, group, clusterOptions, clusterId, function (df, i) {
  1261. var options = df.get(i);
  1262. if (icon) options.icon = getIcon(i);
  1263. return _leaflet2.default.marker([df.get(i, "lat"), df.get(i, "lng")], options);
  1264. });
  1265. }
  1266. };
  1267. methods.addAwesomeMarkers = function (lat, lng, icon, layerId, group, options, popup, popupOptions, clusterOptions, clusterId, label, labelOptions, crosstalkOptions) {
  1268. var icondf = void 0;
  1269. var getIcon = void 0;
  1270. if (icon) {
  1271. // This cbinds the icon URLs and any other icon options; they're all
  1272. // present on the icon object.
  1273. icondf = new _dataframe2.default().cbind(icon);
  1274. // Constructs an icon from a specified row of the icon dataframe.
  1275. getIcon = function getIcon(i) {
  1276. var opts = icondf.get(i);
  1277. if (!opts) {
  1278. return new _leaflet2.default.AwesomeMarkers.icon();
  1279. }
  1280. if (opts.squareMarker) {
  1281. opts.className = "awesome-marker awesome-marker-square";
  1282. }
  1283. return new _leaflet2.default.AwesomeMarkers.icon(opts);
  1284. };
  1285. }
  1286. if (!(_jquery2.default.isEmptyObject(lat) || _jquery2.default.isEmptyObject(lng)) || _jquery2.default.isNumeric(lat) && _jquery2.default.isNumeric(lng)) {
  1287. var df = new _dataframe2.default().col("lat", lat).col("lng", lng).col("layerId", layerId).col("group", group).col("popup", popup).col("popupOptions", popupOptions).col("label", label).col("labelOptions", labelOptions).cbind(options).cbind(crosstalkOptions || {});
  1288. if (icon) icondf.effectiveLength = df.nrow();
  1289. addMarkers(this, df, group, clusterOptions, clusterId, function (df, i) {
  1290. var options = df.get(i);
  1291. if (icon) options.icon = getIcon(i);
  1292. return _leaflet2.default.marker([df.get(i, "lat"), df.get(i, "lng")], options);
  1293. });
  1294. }
  1295. };
  1296. function addLayers(map, category, df, layerFunc) {
  1297. var _loop3 = function _loop3(i) {
  1298. (function () {
  1299. var _this4 = this;
  1300. var layer = layerFunc(df, i);
  1301. if (!_jquery2.default.isEmptyObject(layer)) {
  1302. (function () {
  1303. var thisId = df.get(i, "layerId");
  1304. var thisGroup = df.get(i, "group");
  1305. _this4.layerManager.addLayer(layer, category, thisId, thisGroup, df.get(i, "ctGroup", true), df.get(i, "ctKey", true));
  1306. if (layer.bindPopup) {
  1307. var popup = df.get(i, "popup");
  1308. var popupOptions = df.get(i, "popupOptions");
  1309. if (popup !== null) {
  1310. if (popupOptions !== null) {
  1311. layer.bindPopup(popup, popupOptions);
  1312. } else {
  1313. layer.bindPopup(popup);
  1314. }
  1315. }
  1316. }
  1317. if (layer.bindTooltip) {
  1318. var label = df.get(i, "label");
  1319. var labelOptions = df.get(i, "labelOptions");
  1320. if (label !== null) {
  1321. if (labelOptions !== null) {
  1322. layer.bindTooltip(label, labelOptions);
  1323. } else {
  1324. layer.bindTooltip(label);
  1325. }
  1326. }
  1327. }
  1328. layer.on("click", mouseHandler(_this4.id, thisId, thisGroup, category + "_click"), _this4);
  1329. layer.on("mouseover", mouseHandler(_this4.id, thisId, thisGroup, category + "_mouseover"), _this4);
  1330. layer.on("mouseout", mouseHandler(_this4.id, thisId, thisGroup, category + "_mouseout"), _this4);
  1331. var highlightStyle = df.get(i, "highlightOptions");
  1332. if (!_jquery2.default.isEmptyObject(highlightStyle)) {
  1333. (function () {
  1334. var defaultStyle = {};
  1335. _jquery2.default.each(highlightStyle, function (k, v) {
  1336. if (k != "bringToFront" && k != "sendToBack") {
  1337. if (df.get(i, k)) {
  1338. defaultStyle[k] = df.get(i, k);
  1339. }
  1340. }
  1341. });
  1342. layer.on("mouseover", function (e) {
  1343. this.setStyle(highlightStyle);
  1344. if (highlightStyle.bringToFront) {
  1345. this.bringToFront();
  1346. }
  1347. });
  1348. layer.on("mouseout", function (e) {
  1349. this.setStyle(defaultStyle);
  1350. if (highlightStyle.sendToBack) {
  1351. this.bringToBack();
  1352. }
  1353. });
  1354. })();
  1355. }
  1356. })();
  1357. }
  1358. }).call(map);
  1359. };
  1360. for (var i = 0; i < df.nrow(); i++) {
  1361. _loop3(i);
  1362. }
  1363. }
  1364. methods.addGenericLayers = addLayers;
  1365. methods.addCircles = function (lat, lng, radius, layerId, group, options, popup, popupOptions, label, labelOptions, highlightOptions, crosstalkOptions) {
  1366. if (!(_jquery2.default.isEmptyObject(lat) || _jquery2.default.isEmptyObject(lng)) || _jquery2.default.isNumeric(lat) && _jquery2.default.isNumeric(lng)) {
  1367. var df = new _dataframe2.default().col("lat", lat).col("lng", lng).col("radius", radius).col("layerId", layerId).col("group", group).col("popup", popup).col("popupOptions", popupOptions).col("label", label).col("labelOptions", labelOptions).col("highlightOptions", highlightOptions).cbind(options).cbind(crosstalkOptions || {});
  1368. addLayers(this, "shape", df, function (df, i) {
  1369. if (_jquery2.default.isNumeric(df.get(i, "lat")) && _jquery2.default.isNumeric(df.get(i, "lng")) && _jquery2.default.isNumeric(df.get(i, "radius"))) {
  1370. return _leaflet2.default.circle([df.get(i, "lat"), df.get(i, "lng")], df.get(i, "radius"), df.get(i));
  1371. } else {
  1372. return null;
  1373. }
  1374. });
  1375. }
  1376. };
  1377. methods.addCircleMarkers = function (lat, lng, radius, layerId, group, options, clusterOptions, clusterId, popup, popupOptions, label, labelOptions, crosstalkOptions) {
  1378. if (!(_jquery2.default.isEmptyObject(lat) || _jquery2.default.isEmptyObject(lng)) || _jquery2.default.isNumeric(lat) && _jquery2.default.isNumeric(lng)) {
  1379. var df = new _dataframe2.default().col("lat", lat).col("lng", lng).col("radius", radius).col("layerId", layerId).col("group", group).col("popup", popup).col("popupOptions", popupOptions).col("label", label).col("labelOptions", labelOptions).cbind(crosstalkOptions || {}).cbind(options);
  1380. addMarkers(this, df, group, clusterOptions, clusterId, function (df, i) {
  1381. return _leaflet2.default.circleMarker([df.get(i, "lat"), df.get(i, "lng")], df.get(i));
  1382. });
  1383. }
  1384. };
  1385. /*
  1386. * @param lat Array of arrays of latitude coordinates for polylines
  1387. * @param lng Array of arrays of longitude coordinates for polylines
  1388. */
  1389. methods.addPolylines = function (polygons, layerId, group, options, popup, popupOptions, label, labelOptions, highlightOptions) {
  1390. if (polygons.length > 0) {
  1391. var df = new _dataframe2.default().col("shapes", polygons).col("layerId", layerId).col("group", group).col("popup", popup).col("popupOptions", popupOptions).col("label", label).col("labelOptions", labelOptions).col("highlightOptions", highlightOptions).cbind(options);
  1392. addLayers(this, "shape", df, function (df, i) {
  1393. var shapes = df.get(i, "shapes");
  1394. shapes = shapes.map(function (shape) {
  1395. return _htmlwidgets2.default.dataframeToD3(shape[0]);
  1396. });
  1397. if (shapes.length > 1) {
  1398. return _leaflet2.default.polyline(shapes, df.get(i));
  1399. } else {
  1400. return _leaflet2.default.polyline(shapes[0], df.get(i));
  1401. }
  1402. });
  1403. }
  1404. };
  1405. methods.removeMarker = function (layerId) {
  1406. this.layerManager.removeLayer("marker", layerId);
  1407. };
  1408. methods.clearMarkers = function () {
  1409. this.layerManager.clearLayers("marker");
  1410. };
  1411. methods.removeMarkerCluster = function (layerId) {
  1412. this.layerManager.removeLayer("cluster", layerId);
  1413. };
  1414. methods.removeMarkerFromCluster = function (layerId, clusterId) {
  1415. var cluster = this.layerManager.getLayer("cluster", clusterId);
  1416. if (!cluster) return;
  1417. cluster.clusterLayerStore.remove(layerId);
  1418. };
  1419. methods.clearMarkerClusters = function () {
  1420. this.layerManager.clearLayers("cluster");
  1421. };
  1422. methods.removeShape = function (layerId) {
  1423. this.layerManager.removeLayer("shape", layerId);
  1424. };
  1425. methods.clearShapes = function () {
  1426. this.layerManager.clearLayers("shape");
  1427. };
  1428. methods.addRectangles = function (lat1, lng1, lat2, lng2, layerId, group, options, popup, popupOptions, label, labelOptions, highlightOptions) {
  1429. var df = new _dataframe2.default().col("lat1", lat1).col("lng1", lng1).col("lat2", lat2).col("lng2", lng2).col("layerId", layerId).col("group", group).col("popup", popup).col("popupOptions", popupOptions).col("label", label).col("labelOptions", labelOptions).col("highlightOptions", highlightOptions).cbind(options);
  1430. addLayers(this, "shape", df, function (df, i) {
  1431. if (_jquery2.default.isNumeric(df.get(i, "lat1")) && _jquery2.default.isNumeric(df.get(i, "lng1")) && _jquery2.default.isNumeric(df.get(i, "lat2")) && _jquery2.default.isNumeric(df.get(i, "lng2"))) {
  1432. return _leaflet2.default.rectangle([[df.get(i, "lat1"), df.get(i, "lng1")], [df.get(i, "lat2"), df.get(i, "lng2")]], df.get(i));
  1433. } else {
  1434. return null;
  1435. }
  1436. });
  1437. };
  1438. /*
  1439. * @param lat Array of arrays of latitude coordinates for polygons
  1440. * @param lng Array of arrays of longitude coordinates for polygons
  1441. */
  1442. methods.addPolygons = function (polygons, layerId, group, options, popup, popupOptions, label, labelOptions, highlightOptions) {
  1443. if (polygons.length > 0) {
  1444. var df = new _dataframe2.default().col("shapes", polygons).col("layerId", layerId).col("group", group).col("popup", popup).col("popupOptions", popupOptions).col("label", label).col("labelOptions", labelOptions).col("highlightOptions", highlightOptions).cbind(options);
  1445. addLayers(this, "shape", df, function (df, i) {
  1446. // This code used to use L.multiPolygon, but that caused
  1447. // double-click on a multipolygon to fail to zoom in on the
  1448. // map. Surprisingly, putting all the rings in a single
  1449. // polygon seems to still work; complicated multipolygons
  1450. // are still rendered correctly.
  1451. var shapes = df.get(i, "shapes").map(function (polygon) {
  1452. return polygon.map(_htmlwidgets2.default.dataframeToD3);
  1453. }).reduce(function (acc, val) {
  1454. return acc.concat(val);
  1455. }, []);
  1456. return _leaflet2.default.polygon(shapes, df.get(i));
  1457. });
  1458. }
  1459. };
  1460. methods.addGeoJSON = function (data, layerId, group, style) {
  1461. // This time, self is actually needed because the callbacks below need
  1462. // to access both the inner and outer senses of "this"
  1463. var self = this;
  1464. if (typeof data === "string") {
  1465. data = JSON.parse(data);
  1466. }
  1467. var globalStyle = _jquery2.default.extend({}, style, data.style || {});
  1468. var gjlayer = _leaflet2.default.geoJson(data, {
  1469. style: function style(feature) {
  1470. if (feature.style || feature.properties.style) {
  1471. return _jquery2.default.extend({}, globalStyle, feature.style, feature.properties.style);
  1472. } else {
  1473. return globalStyle;
  1474. }
  1475. },
  1476. onEachFeature: function onEachFeature(feature, layer) {
  1477. var extraInfo = {
  1478. featureId: feature.id,
  1479. properties: feature.properties
  1480. };
  1481. var popup = feature.properties.popup;
  1482. if (typeof popup !== "undefined" && popup !== null) layer.bindPopup(popup);
  1483. layer.on("click", mouseHandler(self.id, layerId, group, "geojson_click", extraInfo), this);
  1484. layer.on("mouseover", mouseHandler(self.id, layerId, group, "geojson_mouseover", extraInfo), this);
  1485. layer.on("mouseout", mouseHandler(self.id, layerId, group, "geojson_mouseout", extraInfo), this);
  1486. }
  1487. });
  1488. this.layerManager.addLayer(gjlayer, "geojson", layerId, group);
  1489. };
  1490. methods.removeGeoJSON = function (layerId) {
  1491. this.layerManager.removeLayer("geojson", layerId);
  1492. };
  1493. methods.clearGeoJSON = function () {
  1494. this.layerManager.clearLayers("geojson");
  1495. };
  1496. methods.addTopoJSON = function (data, layerId, group, style) {
  1497. // This time, self is actually needed because the callbacks below need
  1498. // to access both the inner and outer senses of "this"
  1499. var self = this;
  1500. if (typeof data === "string") {
  1501. data = JSON.parse(data);
  1502. }
  1503. var globalStyle = _jquery2.default.extend({}, style, data.style || {});
  1504. var gjlayer = _leaflet2.default.geoJson(null, {
  1505. style: function style(feature) {
  1506. if (feature.style || feature.properties.style) {
  1507. return _jquery2.default.extend({}, globalStyle, feature.style, feature.properties.style);
  1508. } else {
  1509. return globalStyle;
  1510. }
  1511. },
  1512. onEachFeature: function onEachFeature(feature, layer) {
  1513. var extraInfo = {
  1514. featureId: feature.id,
  1515. properties: feature.properties
  1516. };
  1517. var popup = feature.properties.popup;
  1518. if (typeof popup !== "undefined" && popup !== null) layer.bindPopup(popup);
  1519. layer.on("click", mouseHandler(self.id, layerId, group, "topojson_click", extraInfo), this);
  1520. layer.on("mouseover", mouseHandler(self.id, layerId, group, "topojson_mouseover", extraInfo), this);
  1521. layer.on("mouseout", mouseHandler(self.id, layerId, group, "topojson_mouseout", extraInfo), this);
  1522. }
  1523. });
  1524. global.omnivore.topojson.parse(data, null, gjlayer);
  1525. this.layerManager.addLayer(gjlayer, "topojson", layerId, group);
  1526. };
  1527. methods.removeTopoJSON = function (layerId) {
  1528. this.layerManager.removeLayer("topojson", layerId);
  1529. };
  1530. methods.clearTopoJSON = function () {
  1531. this.layerManager.clearLayers("topojson");
  1532. };
  1533. methods.addControl = function (html, position, layerId, classes) {
  1534. function onAdd(map) {
  1535. var div = _leaflet2.default.DomUtil.create("div", classes);
  1536. if (typeof layerId !== "undefined" && layerId !== null) {
  1537. div.setAttribute("id", layerId);
  1538. }
  1539. this._div = div;
  1540. // It's possible for window.Shiny to be true but Shiny.initializeInputs to
  1541. // not be, when a static leaflet widget is included as part of the shiny
  1542. // UI directly (not through leafletOutput or uiOutput). In this case we
  1543. // don't do the normal Shiny stuff as that will all happen when Shiny
  1544. // itself loads and binds the entire doc.
  1545. if (window.Shiny && _shiny2.default.initializeInputs) {
  1546. _shiny2.default.renderHtml(html, this._div);
  1547. _shiny2.default.initializeInputs(this._div);
  1548. _shiny2.default.bindAll(this._div);
  1549. } else {
  1550. this._div.innerHTML = html;
  1551. }
  1552. return this._div;
  1553. }
  1554. function onRemove(map) {
  1555. if (window.Shiny && _shiny2.default.unbindAll) {
  1556. _shiny2.default.unbindAll(this._div);
  1557. }
  1558. }
  1559. var Control = _leaflet2.default.Control.extend({
  1560. options: { position: position },
  1561. onAdd: onAdd,
  1562. onRemove: onRemove
  1563. });
  1564. this.controls.add(new Control(), layerId, html);
  1565. };
  1566. methods.addCustomControl = function (control, layerId) {
  1567. this.controls.add(control, layerId);
  1568. };
  1569. methods.removeControl = function (layerId) {
  1570. this.controls.remove(layerId);
  1571. };
  1572. methods.getControl = function (layerId) {
  1573. this.controls.get(layerId);
  1574. };
  1575. methods.clearControls = function () {
  1576. this.controls.clear();
  1577. };
  1578. methods.addLegend = function (options) {
  1579. var _this5 = this;
  1580. var legend = _leaflet2.default.control({ position: options.position });
  1581. var gradSpan = void 0;
  1582. legend.onAdd = function (map) {
  1583. var div = _leaflet2.default.DomUtil.create("div", options.className),
  1584. colors = options.colors,
  1585. labels = options.labels,
  1586. legendHTML = "";
  1587. if (options.type === "numeric") {
  1588. (function () {
  1589. // # Formatting constants.
  1590. var singleBinHeight = 20; // The distance between tick marks, in px
  1591. var vMargin = 8; // If 1st tick mark starts at top of gradient, how
  1592. // many extra px are needed for the top half of the
  1593. // 1st label? (ditto for last tick mark/label)
  1594. var tickWidth = 4; // How wide should tick marks be, in px?
  1595. var labelPadding = 6; // How much distance to reserve for tick mark?
  1596. // (Must be >= tickWidth)
  1597. // # Derived formatting parameters.
  1598. // What's the height of a single bin, in percentage (of gradient height)?
  1599. // It might not just be 1/(n-1), if the gradient extends past the tick
  1600. // marks (which can be the case for pretty cut points).
  1601. var singleBinPct = (options.extra.p_n - options.extra.p_1) / (labels.length - 1);
  1602. // Each bin is `singleBinHeight` high. How tall is the gradient?
  1603. var totalHeight = 1 / singleBinPct * singleBinHeight + 1;
  1604. // How far should the first tick be shifted down, relative to the top
  1605. // of the gradient?
  1606. var tickOffset = singleBinHeight / singleBinPct * options.extra.p_1;
  1607. gradSpan = (0, _jquery2.default)("<span/>").css({
  1608. "background": "linear-gradient(" + colors + ")",
  1609. "opacity": options.opacity,
  1610. "height": totalHeight + "px",
  1611. "width": "18px",
  1612. "display": "block",
  1613. "margin-top": vMargin + "px"
  1614. });
  1615. var leftDiv = (0, _jquery2.default)("<div/>").css("float", "left"),
  1616. rightDiv = (0, _jquery2.default)("<div/>").css("float", "left");
  1617. leftDiv.append(gradSpan);
  1618. (0, _jquery2.default)(div).append(leftDiv).append(rightDiv).append((0, _jquery2.default)("<br>"));
  1619. // Have to attach the div to the body at this early point, so that the
  1620. // svg text getComputedTextLength() actually works, below.
  1621. document.body.appendChild(div);
  1622. var ns = "http://www.w3.org/2000/svg";
  1623. var svg = document.createElementNS(ns, "svg");
  1624. rightDiv.append(svg);
  1625. var g = document.createElementNS(ns, "g");
  1626. (0, _jquery2.default)(g).attr("transform", "translate(0, " + vMargin + ")");
  1627. svg.appendChild(g);
  1628. // max label width needed to set width of svg, and right-justify text
  1629. var maxLblWidth = 0;
  1630. // Create tick marks and labels
  1631. _jquery2.default.each(labels, function (i, label) {
  1632. var y = tickOffset + i * singleBinHeight + 0.5;
  1633. var thisLabel = document.createElementNS(ns, "text");
  1634. (0, _jquery2.default)(thisLabel).text(labels[i]).attr("y", y).attr("dx", labelPadding).attr("dy", "0.5ex");
  1635. g.appendChild(thisLabel);
  1636. maxLblWidth = Math.max(maxLblWidth, thisLabel.getComputedTextLength());
  1637. var thisTick = document.createElementNS(ns, "line");
  1638. (0, _jquery2.default)(thisTick).attr("x1", 0).attr("x2", tickWidth).attr("y1", y).attr("y2", y).attr("stroke-width", 1);
  1639. g.appendChild(thisTick);
  1640. });
  1641. // Now that we know the max label width, we can right-justify
  1642. (0, _jquery2.default)(svg).find("text").attr("dx", labelPadding + maxLblWidth).attr("text-anchor", "end");
  1643. // Final size for <svg>
  1644. (0, _jquery2.default)(svg).css({
  1645. width: maxLblWidth + labelPadding + "px",
  1646. height: totalHeight + vMargin * 2 + "px"
  1647. });
  1648. if (options.na_color && _jquery2.default.inArray(options.na_label, labels) < 0) {
  1649. (0, _jquery2.default)(div).append("<div><i style=\"" + "background:" + options.na_color + ";opacity:" + options.opacity + ";margin-right:" + labelPadding + "px" + ";\"></i>" + options.na_label + "</div>");
  1650. }
  1651. })();
  1652. } else {
  1653. if (options.na_color && _jquery2.default.inArray(options.na_label, labels) < 0) {
  1654. colors.push(options.na_color);
  1655. labels.push(options.na_label);
  1656. }
  1657. for (var i = 0; i < colors.length; i++) {
  1658. legendHTML += "<i style=\"background:" + colors[i] + ";opacity:" + options.opacity + "\"></i> " + labels[i] + "<br>";
  1659. }
  1660. div.innerHTML = legendHTML;
  1661. }
  1662. if (options.title) (0, _jquery2.default)(div).prepend("<div style=\"margin-bottom:3px\"><strong>" + options.title + "</strong></div>");
  1663. return div;
  1664. };
  1665. if (options.group) {
  1666. (function () {
  1667. // Auto generate a layerID if not provided
  1668. if (!options.layerId) {
  1669. options.layerId = _leaflet2.default.Util.stamp(legend);
  1670. }
  1671. var map = _this5;
  1672. map.on("overlayadd", function (e) {
  1673. if (e.name === options.group) {
  1674. map.controls.add(legend, options.layerId);
  1675. }
  1676. });
  1677. map.on("overlayremove", function (e) {
  1678. if (e.name === options.group) {
  1679. map.controls.remove(options.layerId);
  1680. }
  1681. });
  1682. map.on("groupadd", function (e) {
  1683. if (e.name === options.group) {
  1684. map.controls.add(legend, options.layerId);
  1685. }
  1686. });
  1687. map.on("groupremove", function (e) {
  1688. if (e.name === options.group) {
  1689. map.controls.remove(options.layerId);
  1690. }
  1691. });
  1692. })();
  1693. }
  1694. this.controls.add(legend, options.layerId);
  1695. };
  1696. methods.addLayersControl = function (baseGroups, overlayGroups, options) {
  1697. var _this6 = this;
  1698. // Only allow one layers control at a time
  1699. methods.removeLayersControl.call(this);
  1700. var firstLayer = true;
  1701. var base = {};
  1702. _jquery2.default.each((0, _util.asArray)(baseGroups), function (i, g) {
  1703. var layer = _this6.layerManager.getLayerGroup(g, true);
  1704. if (layer) {
  1705. base[g] = layer;
  1706. // Check if >1 base layers are visible; if so, hide all but the first one
  1707. if (_this6.hasLayer(layer)) {
  1708. if (firstLayer) {
  1709. firstLayer = false;
  1710. } else {
  1711. _this6.removeLayer(layer);
  1712. }
  1713. }
  1714. }
  1715. });
  1716. var overlay = {};
  1717. _jquery2.default.each((0, _util.asArray)(overlayGroups), function (i, g) {
  1718. var layer = _this6.layerManager.getLayerGroup(g, true);
  1719. if (layer) {
  1720. overlay[g] = layer;
  1721. }
  1722. });
  1723. this.currentLayersControl = _leaflet2.default.control.layers(base, overlay, options);
  1724. this.addControl(this.currentLayersControl);
  1725. };
  1726. methods.removeLayersControl = function () {
  1727. if (this.currentLayersControl) {
  1728. this.removeControl(this.currentLayersControl);
  1729. this.currentLayersControl = null;
  1730. }
  1731. };
  1732. methods.addScaleBar = function (options) {
  1733. // Only allow one scale bar at a time
  1734. methods.removeScaleBar.call(this);
  1735. var scaleBar = _leaflet2.default.control.scale(options).addTo(this);
  1736. this.currentScaleBar = scaleBar;
  1737. };
  1738. methods.removeScaleBar = function () {
  1739. if (this.currentScaleBar) {
  1740. this.currentScaleBar.remove();
  1741. this.currentScaleBar = null;
  1742. }
  1743. };
  1744. methods.hideGroup = function (group) {
  1745. var _this7 = this;
  1746. _jquery2.default.each((0, _util.asArray)(group), function (i, g) {
  1747. var layer = _this7.layerManager.getLayerGroup(g, true);
  1748. if (layer) {
  1749. _this7.removeLayer(layer);
  1750. }
  1751. });
  1752. };
  1753. methods.showGroup = function (group) {
  1754. var _this8 = this;
  1755. _jquery2.default.each((0, _util.asArray)(group), function (i, g) {
  1756. var layer = _this8.layerManager.getLayerGroup(g, true);
  1757. if (layer) {
  1758. _this8.addLayer(layer);
  1759. }
  1760. });
  1761. };
  1762. function setupShowHideGroupsOnZoom(map) {
  1763. if (map.leafletr._hasInitializedShowHideGroups) {
  1764. return;
  1765. }
  1766. map.leafletr._hasInitializedShowHideGroups = true;
  1767. function setVisibility(layer, visible, group) {
  1768. if (visible !== map.hasLayer(layer)) {
  1769. if (visible) {
  1770. map.addLayer(layer);
  1771. map.fire("groupadd", { "name": group, "layer": layer });
  1772. } else {
  1773. map.removeLayer(layer);
  1774. map.fire("groupremove", { "name": group, "layer": layer });
  1775. }
  1776. }
  1777. }
  1778. function showHideGroupsOnZoom() {
  1779. if (!map.layerManager) return;
  1780. var zoom = map.getZoom();
  1781. map.layerManager.getAllGroupNames().forEach(function (group) {
  1782. var layer = map.layerManager.getLayerGroup(group, false);
  1783. if (layer && typeof layer.zoomLevels !== "undefined") {
  1784. setVisibility(layer, layer.zoomLevels === true || layer.zoomLevels.indexOf(zoom) >= 0, group);
  1785. }
  1786. });
  1787. }
  1788. map.showHideGroupsOnZoom = showHideGroupsOnZoom;
  1789. map.on("zoomend", showHideGroupsOnZoom);
  1790. }
  1791. methods.setGroupOptions = function (group, options) {
  1792. var _this9 = this;
  1793. _jquery2.default.each((0, _util.asArray)(group), function (i, g) {
  1794. var layer = _this9.layerManager.getLayerGroup(g, true);
  1795. // This slightly tortured check is because 0 is a valid value for zoomLevels
  1796. if (typeof options.zoomLevels !== "undefined" && options.zoomLevels !== null) {
  1797. layer.zoomLevels = (0, _util.asArray)(options.zoomLevels);
  1798. }
  1799. });
  1800. setupShowHideGroupsOnZoom(this);
  1801. this.showHideGroupsOnZoom();
  1802. };
  1803. methods.addRasterImage = function (uri, bounds, opacity, attribution, layerId, group) {
  1804. // uri is a data URI containing an image. We want to paint this image as a
  1805. // layer at (top-left) bounds[0] to (bottom-right) bounds[1].
  1806. // We can't simply use ImageOverlay, as it uses bilinear scaling which looks
  1807. // awful as you zoom in (and sometimes shifts positions or disappears).
  1808. // Instead, we'll use a TileLayer.Canvas to draw pieces of the image.
  1809. // First, some helper functions.
  1810. // degree2tile converts latitude, longitude, and zoom to x and y tile
  1811. // numbers. The tile numbers returned can be non-integral, as there's no
  1812. // reason to expect that the lat/lng inputs are exactly on the border of two
  1813. // tiles.
  1814. //
  1815. // We'll use this to convert the bounds we got from the server, into coords
  1816. // in tile-space at a given zoom level. Note that once we do the conversion,
  1817. // we don't to do any more trigonometry to convert between pixel coordinates
  1818. // and tile coordinates; the source image pixel coords, destination canvas
  1819. // pixel coords, and tile coords all can be scaled linearly.
  1820. function degree2tile(lat, lng, zoom) {
  1821. // See http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
  1822. var latRad = lat * Math.PI / 180;
  1823. var n = Math.pow(2, zoom);
  1824. var x = (lng + 180) / 360 * n;
  1825. var y = (1 - Math.log(Math.tan(latRad) + 1 / Math.cos(latRad)) / Math.PI) / 2 * n;
  1826. return { x: x, y: y };
  1827. }
  1828. // Given a range [from,to) and either one or two numbers, returns true if
  1829. // there is any overlap between [x,x1) and the range--or if x1 is omitted,
  1830. // then returns true if x is within [from,to).
  1831. function overlap(from, to, x, /* optional */x1) {
  1832. if (arguments.length == 3) x1 = x;
  1833. return x < to && x1 >= from;
  1834. }
  1835. function getCanvasSmoothingProperty(ctx) {
  1836. var candidates = ["imageSmoothingEnabled", "mozImageSmoothingEnabled", "webkitImageSmoothingEnabled", "msImageSmoothingEnabled"];
  1837. for (var i = 0; i < candidates.length; i++) {
  1838. if (typeof ctx[candidates[i]] !== "undefined") {
  1839. return candidates[i];
  1840. }
  1841. }
  1842. return null;
  1843. }
  1844. // Our general strategy is to:
  1845. // 1. Load the data URI in an Image() object, so we can get its pixel
  1846. // dimensions and the underlying image data. (We could have done this
  1847. // by not encoding as PNG at all but just send an array of RGBA values
  1848. // from the server, but that would inflate the JSON too much.)
  1849. // 2. Create a hidden canvas that we use just to extract the image data
  1850. // from the Image (using Context2D.getImageData()).
  1851. // 3. Create a TileLayer.Canvas and add it to the map.
  1852. // We want to synchronously create and attach the TileLayer.Canvas (so an
  1853. // immediate call to clearRasters() will be respected, for example), but
  1854. // Image loads its data asynchronously. Fortunately we can resolve this
  1855. // by putting TileLayer.Canvas into async mode, which will let us create
  1856. // and attach the layer but have it wait until the image is loaded before
  1857. // it actually draws anything.
  1858. // These are the variables that we will populate once the image is loaded.
  1859. var imgData = null; // 1d row-major array, four [0-255] integers per pixel
  1860. var imgDataMipMapper = null;
  1861. var w = null; // image width in pixels
  1862. var h = null; // image height in pixels
  1863. // We'll use this array to store callbacks that need to be invoked once
  1864. // imgData, w, and h have been resolved.
  1865. var imgDataCallbacks = [];
  1866. // Consumers of imgData, w, and h can call this to be notified when data
  1867. // is available.
  1868. function getImageData(callback) {
  1869. if (imgData != null) {
  1870. // Must not invoke the callback immediately; it's too confusing and
  1871. // fragile to have a function invoke the callback *either* immediately
  1872. // or in the future. Better to be consistent here.
  1873. setTimeout(function () {
  1874. callback(imgData, w, h, imgDataMipMapper);
  1875. }, 0);
  1876. } else {
  1877. imgDataCallbacks.push(callback);
  1878. }
  1879. }
  1880. var img = new Image();
  1881. img.onload = function () {
  1882. // Save size
  1883. w = img.width;
  1884. h = img.height;
  1885. // Create a dummy canvas to extract the image data
  1886. var imgDataCanvas = document.createElement("canvas");
  1887. imgDataCanvas.width = w;
  1888. imgDataCanvas.height = h;
  1889. imgDataCanvas.style.display = "none";
  1890. document.body.appendChild(imgDataCanvas);
  1891. var imgDataCtx = imgDataCanvas.getContext("2d");
  1892. imgDataCtx.drawImage(img, 0, 0);
  1893. // Save the image data.
  1894. imgData = imgDataCtx.getImageData(0, 0, w, h).data;
  1895. imgDataMipMapper = new _mipmapper2.default(img);
  1896. // Done with the canvas, remove it from the page so it can be gc'd.
  1897. document.body.removeChild(imgDataCanvas);
  1898. // Alert any getImageData callers who are waiting.
  1899. for (var i = 0; i < imgDataCallbacks.length; i++) {
  1900. imgDataCallbacks[i](imgData, w, h, imgDataMipMapper);
  1901. }
  1902. imgDataCallbacks = [];
  1903. };
  1904. img.src = uri;
  1905. var canvasTiles = _leaflet2.default.gridLayer({
  1906. opacity: opacity,
  1907. attribution: attribution,
  1908. detectRetina: true,
  1909. async: true
  1910. });
  1911. // NOTE: The done() function MUST NOT be invoked until after the current
  1912. // tick; done() looks in Leaflet's tile cache for the current tile, and
  1913. // since it's still being constructed, it won't be found.
  1914. canvasTiles.createTile = function (tilePoint, done) {
  1915. var zoom = tilePoint.z;
  1916. var canvas = _leaflet2.default.DomUtil.create("canvas");
  1917. var error = void 0;
  1918. // setup tile width and height according to the options
  1919. var size = this.getTileSize();
  1920. canvas.width = size.x;
  1921. canvas.height = size.y;
  1922. getImageData(function (imgData, w, h, mipmapper) {
  1923. try {
  1924. var _ret8 = function () {
  1925. // The Context2D we'll being drawing onto. It's always 256x256.
  1926. var ctx = canvas.getContext("2d");
  1927. // Convert our image data's top-left and bottom-right locations into
  1928. // x/y tile coordinates. This is essentially doing a spherical mercator
  1929. // projection, then multiplying by 2^zoom.
  1930. var topLeft = degree2tile(bounds[0][0], bounds[0][1], zoom);
  1931. var bottomRight = degree2tile(bounds[1][0], bounds[1][1], zoom);
  1932. // The size of the image in x/y tile coordinates.
  1933. var extent = { x: bottomRight.x - topLeft.x, y: bottomRight.y - topLeft.y };
  1934. // Short circuit if tile is totally disjoint from image.
  1935. if (!overlap(tilePoint.x, tilePoint.x + 1, topLeft.x, bottomRight.x)) return {
  1936. v: void 0
  1937. };
  1938. if (!overlap(tilePoint.y, tilePoint.y + 1, topLeft.y, bottomRight.y)) return {
  1939. v: void 0
  1940. };
  1941. // The linear resolution of the tile we're drawing is always 256px per tile unit.
  1942. // If the linear resolution (in either direction) of the image is less than 256px
  1943. // per tile unit, then use nearest neighbor; otherwise, use the canvas's built-in
  1944. // scaling.
  1945. var imgRes = {
  1946. x: w / extent.x,
  1947. y: h / extent.y
  1948. };
  1949. // We can do the actual drawing in one of three ways:
  1950. // - Call drawImage(). This is easy and fast, and results in smooth
  1951. // interpolation (bilinear?). This is what we want when we are
  1952. // reducing the image from its native size.
  1953. // - Call drawImage() with imageSmoothingEnabled=false. This is easy
  1954. // and fast and gives us nearest-neighbor interpolation, which is what
  1955. // we want when enlarging the image. However, it's unsupported on many
  1956. // browsers (including QtWebkit).
  1957. // - Do a manual nearest-neighbor interpolation. This is what we'll fall
  1958. // back to when enlarging, and imageSmoothingEnabled isn't supported.
  1959. // In theory it's slower, but still pretty fast on my machine, and the
  1960. // results look the same AFAICT.
  1961. // Is imageSmoothingEnabled supported? If so, we can let canvas do
  1962. // nearest-neighbor interpolation for us.
  1963. var smoothingProperty = getCanvasSmoothingProperty(ctx);
  1964. if (smoothingProperty || imgRes.x >= 256 && imgRes.y >= 256) {
  1965. // Use built-in scaling
  1966. // Turn off anti-aliasing if necessary
  1967. if (smoothingProperty) {
  1968. ctx[smoothingProperty] = imgRes.x >= 256 && imgRes.y >= 256;
  1969. }
  1970. // Don't necessarily draw with the full-size image; if we're
  1971. // downscaling, use the mipmapper to get a pre-downscaled image
  1972. // (see comments on Mipmapper class for why this matters).
  1973. mipmapper.getBySize(extent.x * 256, extent.y * 256, function (mip) {
  1974. // It's possible that the image will go off the edge of the canvas--
  1975. // that's OK, the canvas should clip appropriately.
  1976. ctx.drawImage(mip,
  1977. // Convert abs tile coords to rel tile coords, then *256 to convert
  1978. // to rel pixel coords
  1979. (topLeft.x - tilePoint.x) * 256, (topLeft.y - tilePoint.y) * 256,
  1980. // Always draw the whole thing and let canvas clip; so we can just
  1981. // convert from size in tile coords straight to pixels
  1982. extent.x * 256, extent.y * 256);
  1983. });
  1984. } else {
  1985. // Use manual nearest-neighbor interpolation
  1986. // Calculate the source image pixel coordinates that correspond with
  1987. // the top-left and bottom-right of this tile. (If the source image
  1988. // only partially overlaps the tile, we use max/min to limit the
  1989. // sourceStart/End to only reflect the overlapping portion.)
  1990. var sourceStart = {
  1991. x: Math.max(0, Math.floor((tilePoint.x - topLeft.x) * imgRes.x)),
  1992. y: Math.max(0, Math.floor((tilePoint.y - topLeft.y) * imgRes.y))
  1993. };
  1994. var sourceEnd = {
  1995. x: Math.min(w, Math.ceil((tilePoint.x + 1 - topLeft.x) * imgRes.x)),
  1996. y: Math.min(h, Math.ceil((tilePoint.y + 1 - topLeft.y) * imgRes.y))
  1997. };
  1998. // The size, in dest pixels, that each source pixel should occupy.
  1999. // This might be greater or less than 1 (e.g. if x and y resolution
  2000. // are very different).
  2001. var pixelSize = {
  2002. x: 256 / imgRes.x,
  2003. y: 256 / imgRes.y
  2004. };
  2005. // For each pixel in the source image that overlaps the tile...
  2006. for (var row = sourceStart.y; row < sourceEnd.y; row++) {
  2007. for (var col = sourceStart.x; col < sourceEnd.x; col++) {
  2008. // ...extract the pixel data...
  2009. var i = (row * w + col) * 4;
  2010. var r = imgData[i];
  2011. var g = imgData[i + 1];
  2012. var b = imgData[i + 2];
  2013. var a = imgData[i + 3];
  2014. ctx.fillStyle = "rgba(" + [r, g, b, a / 255].join(",") + ")";
  2015. // ...calculate the corresponding pixel coord in the dest image
  2016. // where it should be drawn...
  2017. var pixelPos = {
  2018. x: (col / imgRes.x + topLeft.x - tilePoint.x) * 256,
  2019. y: (row / imgRes.y + topLeft.y - tilePoint.y) * 256
  2020. };
  2021. // ...and draw a rectangle there.
  2022. ctx.fillRect(Math.round(pixelPos.x), Math.round(pixelPos.y),
  2023. // Looks crazy, but this is necessary to prevent rounding from
  2024. // causing overlap between this rect and its neighbors. The
  2025. // minuend is the location of the next pixel, while the
  2026. // subtrahend is the position of the current pixel (to turn an
  2027. // absolute coordinate to a width/height). Yes, I had to look
  2028. // up minuend and subtrahend.
  2029. Math.round(pixelPos.x + pixelSize.x) - Math.round(pixelPos.x), Math.round(pixelPos.y + pixelSize.y) - Math.round(pixelPos.y));
  2030. }
  2031. }
  2032. }
  2033. }();
  2034. if ((typeof _ret8 === "undefined" ? "undefined" : _typeof(_ret8)) === "object") return _ret8.v;
  2035. } catch (e) {
  2036. error = e;
  2037. } finally {
  2038. done(error, canvas);
  2039. }
  2040. });
  2041. return canvas;
  2042. };
  2043. this.layerManager.addLayer(canvasTiles, "image", layerId, group);
  2044. };
  2045. methods.removeImage = function (layerId) {
  2046. this.layerManager.removeLayer("image", layerId);
  2047. };
  2048. methods.clearImages = function () {
  2049. this.layerManager.clearLayers("image");
  2050. };
  2051. methods.addMeasure = function (options) {
  2052. // if a measureControl already exists, then remove it and
  2053. // replace with a new one
  2054. methods.removeMeasure.call(this);
  2055. this.measureControl = _leaflet2.default.control.measure(options);
  2056. this.addControl(this.measureControl);
  2057. };
  2058. methods.removeMeasure = function () {
  2059. if (this.measureControl) {
  2060. this.removeControl(this.measureControl);
  2061. this.measureControl = null;
  2062. }
  2063. };
  2064. methods.addSelect = function (ctGroup) {
  2065. var _this10 = this;
  2066. methods.removeSelect.call(this);
  2067. this._selectButton = _leaflet2.default.easyButton({
  2068. states: [{
  2069. stateName: "select-inactive",
  2070. icon: "ion-qr-scanner",
  2071. title: "Make a selection",
  2072. onClick: function onClick(btn, map) {
  2073. btn.state("select-active");
  2074. _this10._locationFilter = new _leaflet2.default.LocationFilter2();
  2075. if (ctGroup) {
  2076. (function () {
  2077. var selectionHandle = new global.crosstalk.SelectionHandle(ctGroup);
  2078. selectionHandle.on("change", function (e) {
  2079. if (e.sender !== selectionHandle) {
  2080. if (_this10._locationFilter) {
  2081. _this10._locationFilter.disable();
  2082. btn.state("select-inactive");
  2083. }
  2084. }
  2085. });
  2086. var handler = function handler(e) {
  2087. _this10.layerManager.brush(_this10._locationFilter.getBounds(), { sender: selectionHandle });
  2088. };
  2089. _this10._locationFilter.on("enabled", handler);
  2090. _this10._locationFilter.on("change", handler);
  2091. _this10._locationFilter.on("disabled", function () {
  2092. selectionHandle.close();
  2093. _this10._locationFilter = null;
  2094. });
  2095. })();
  2096. }
  2097. _this10._locationFilter.addTo(map);
  2098. }
  2099. }, {
  2100. stateName: "select-active",
  2101. icon: "ion-close-round",
  2102. title: "Dismiss selection",
  2103. onClick: function onClick(btn, map) {
  2104. btn.state("select-inactive");
  2105. _this10._locationFilter.disable();
  2106. // If explicitly dismissed, clear the crosstalk selections
  2107. _this10.layerManager.unbrush();
  2108. }
  2109. }]
  2110. });
  2111. this._selectButton.addTo(this);
  2112. };
  2113. methods.removeSelect = function () {
  2114. if (this._locationFilter) {
  2115. this._locationFilter.disable();
  2116. }
  2117. if (this._selectButton) {
  2118. this.removeControl(this._selectButton);
  2119. this._selectButton = null;
  2120. }
  2121. };
  2122. methods.createMapPane = function (name, zIndex) {
  2123. this.createPane(name);
  2124. this.getPane(name).style.zIndex = zIndex;
  2125. };
  2126. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2127. },{"./cluster-layer-store":1,"./crs_utils":3,"./dataframe":4,"./global/htmlwidgets":8,"./global/jquery":9,"./global/leaflet":10,"./global/shiny":12,"./mipmapper":16,"./util":17}],16:[function(require,module,exports){
  2128. "use strict";
  2129. Object.defineProperty(exports, "__esModule", {
  2130. value: true
  2131. });
  2132. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  2133. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2134. // This class simulates a mipmap, which shrinks images by powers of two. This
  2135. // stepwise reduction results in "pixel-perfect downscaling" (where every
  2136. // pixel of the original image has some contribution to the downscaled image)
  2137. // as opposed to a single-step downscaling which will discard a lot of data
  2138. // (and with sparse images at small scales can give very surprising results).
  2139. var Mipmapper = function () {
  2140. function Mipmapper(img) {
  2141. _classCallCheck(this, Mipmapper);
  2142. this._layers = [img];
  2143. }
  2144. // The various functions on this class take a callback function BUT MAY OR MAY
  2145. // NOT actually behave asynchronously.
  2146. _createClass(Mipmapper, [{
  2147. key: "getBySize",
  2148. value: function getBySize(desiredWidth, desiredHeight, callback) {
  2149. var _this = this;
  2150. var i = 0;
  2151. var lastImg = this._layers[0];
  2152. var testNext = function testNext() {
  2153. _this.getByIndex(i, function (img) {
  2154. // If current image is invalid (i.e. too small to be rendered) or
  2155. // it's smaller than what we wanted, return the last known good image.
  2156. if (!img || img.width < desiredWidth || img.height < desiredHeight) {
  2157. callback(lastImg);
  2158. return;
  2159. } else {
  2160. lastImg = img;
  2161. i++;
  2162. testNext();
  2163. return;
  2164. }
  2165. });
  2166. };
  2167. testNext();
  2168. }
  2169. }, {
  2170. key: "getByIndex",
  2171. value: function getByIndex(i, callback) {
  2172. var _this2 = this;
  2173. if (this._layers[i]) {
  2174. callback(this._layers[i]);
  2175. return;
  2176. }
  2177. this.getByIndex(i - 1, function (prevImg) {
  2178. if (!prevImg) {
  2179. // prevImg could not be calculated (too small, possibly)
  2180. callback(null);
  2181. return;
  2182. }
  2183. if (prevImg.width < 2 || prevImg.height < 2) {
  2184. // Can't reduce this image any further
  2185. callback(null);
  2186. return;
  2187. }
  2188. // If reduce ever becomes truly asynchronous, we should stuff a promise or
  2189. // something into this._layers[i] before calling this.reduce(), to prevent
  2190. // redundant reduce operations from happening.
  2191. _this2.reduce(prevImg, function (reducedImg) {
  2192. _this2._layers[i] = reducedImg;
  2193. callback(reducedImg);
  2194. return;
  2195. });
  2196. });
  2197. }
  2198. }, {
  2199. key: "reduce",
  2200. value: function reduce(img, callback) {
  2201. var imgDataCanvas = document.createElement("canvas");
  2202. imgDataCanvas.width = Math.ceil(img.width / 2);
  2203. imgDataCanvas.height = Math.ceil(img.height / 2);
  2204. imgDataCanvas.style.display = "none";
  2205. document.body.appendChild(imgDataCanvas);
  2206. try {
  2207. var imgDataCtx = imgDataCanvas.getContext("2d");
  2208. imgDataCtx.drawImage(img, 0, 0, img.width / 2, img.height / 2);
  2209. callback(imgDataCanvas);
  2210. } finally {
  2211. document.body.removeChild(imgDataCanvas);
  2212. }
  2213. }
  2214. }]);
  2215. return Mipmapper;
  2216. }();
  2217. exports.default = Mipmapper;
  2218. },{}],17:[function(require,module,exports){
  2219. "use strict";
  2220. Object.defineProperty(exports, "__esModule", {
  2221. value: true
  2222. });
  2223. exports.log = log;
  2224. exports.recycle = recycle;
  2225. exports.asArray = asArray;
  2226. function log(message) {
  2227. /* eslint-disable no-console */
  2228. if (console && console.log) console.log(message);
  2229. /* eslint-enable no-console */
  2230. }
  2231. function recycle(values, length, inPlace) {
  2232. if (length === 0 && !inPlace) return [];
  2233. if (!(values instanceof Array)) {
  2234. if (inPlace) {
  2235. throw new Error("Can't do in-place recycling of a non-Array value");
  2236. }
  2237. values = [values];
  2238. }
  2239. if (typeof length === "undefined") length = values.length;
  2240. var dest = inPlace ? values : [];
  2241. var origLength = values.length;
  2242. while (dest.length < length) {
  2243. dest.push(values[dest.length % origLength]);
  2244. }
  2245. if (dest.length > length) {
  2246. dest.splice(length, dest.length - length);
  2247. }
  2248. return dest;
  2249. }
  2250. function asArray(value) {
  2251. if (value instanceof Array) return value;else return [value];
  2252. }
  2253. },{}]},{},[13]);