PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/files/leaflet.esri/1.0.3/builds/basemaps/esri-leaflet-basemaps-src.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 586 lines | 476 code | 74 blank | 36 comment | 63 complexity | e121eeae5f29c5e8b3bf0453326c299a MD5 | raw file
  1. /*! esri-leaflet - v1.0.3 - 2016-02-22
  2. * Copyright (c) 2016 Environmental Systems Research Institute, Inc.
  3. * Apache License*/
  4. (function (factory) {
  5. //define an AMD module that relies on 'leaflet'
  6. if (typeof define === 'function' && define.amd) {
  7. define(['leaflet'], function (L) {
  8. return factory(L);
  9. });
  10. //define a common js module that relies on 'leaflet'
  11. } else if (typeof module === 'object' && typeof module.exports === 'object') {
  12. module.exports = factory(require('leaflet'));
  13. }
  14. if(typeof window !== 'undefined' && window.L){
  15. factory(window.L);
  16. }
  17. }(function (L) {
  18. var EsriLeaflet = { //jshint ignore:line
  19. VERSION: '1.0.3',
  20. Layers: {},
  21. Services: {},
  22. Controls: {},
  23. Tasks: {},
  24. Util: {},
  25. Support: {
  26. CORS: !!(window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()),
  27. pointerEvents: document.documentElement.style.pointerEvents === ''
  28. }
  29. };
  30. if(typeof window !== 'undefined' && window.L){
  31. window.L.esri = EsriLeaflet;
  32. }
  33. (function(EsriLeaflet){
  34. var callbacks = 0;
  35. window._EsriLeafletCallbacks = {};
  36. function serialize(params){
  37. var data = '';
  38. params.f = params.f || 'json';
  39. for (var key in params){
  40. if(params.hasOwnProperty(key)){
  41. var param = params[key];
  42. var type = Object.prototype.toString.call(param);
  43. var value;
  44. if(data.length){
  45. data += '&';
  46. }
  47. if (type === '[object Array]'){
  48. value = (Object.prototype.toString.call(param[0]) === '[object Object]') ? JSON.stringify(param) : param.join(',');
  49. } else if (type === '[object Object]') {
  50. value = JSON.stringify(param);
  51. } else if (type === '[object Date]'){
  52. value = param.valueOf();
  53. } else {
  54. value = param;
  55. }
  56. data += encodeURIComponent(key) + '=' + encodeURIComponent(value);
  57. }
  58. }
  59. return data;
  60. }
  61. function createRequest(callback, context){
  62. var httpRequest = new XMLHttpRequest();
  63. httpRequest.onerror = function(e) {
  64. httpRequest.onreadystatechange = L.Util.falseFn;
  65. callback.call(context, {
  66. error: {
  67. code: 500,
  68. message: 'XMLHttpRequest error'
  69. }
  70. }, null);
  71. };
  72. httpRequest.onreadystatechange = function(){
  73. var response;
  74. var error;
  75. if (httpRequest.readyState === 4) {
  76. try {
  77. response = JSON.parse(httpRequest.responseText);
  78. } catch(e) {
  79. response = null;
  80. error = {
  81. code: 500,
  82. message: 'Could not parse response as JSON. This could also be caused by a CORS or XMLHttpRequest error.'
  83. };
  84. }
  85. if (!error && response.error) {
  86. error = response.error;
  87. response = null;
  88. }
  89. httpRequest.onerror = L.Util.falseFn;
  90. callback.call(context, error, response);
  91. }
  92. };
  93. return httpRequest;
  94. }
  95. // AJAX handlers for CORS (modern browsers) or JSONP (older browsers)
  96. EsriLeaflet.Request = {
  97. request: function(url, params, callback, context){
  98. var paramString = serialize(params);
  99. var httpRequest = createRequest(callback, context);
  100. var requestLength = (url + '?' + paramString).length;
  101. // request is less then 2000 characters and the browser supports CORS, make GET request with XMLHttpRequest
  102. if(requestLength <= 2000 && L.esri.Support.CORS){
  103. httpRequest.open('GET', url + '?' + paramString);
  104. httpRequest.send(null);
  105. // request is less more then 2000 characters and the browser supports CORS, make POST request with XMLHttpRequest
  106. } else if (requestLength > 2000 && L.esri.Support.CORS){
  107. httpRequest.open('POST', url);
  108. httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  109. httpRequest.send(paramString);
  110. // request is less more then 2000 characters and the browser does not support CORS, make a JSONP request
  111. } else if(requestLength <= 2000 && !L.esri.Support.CORS){
  112. return L.esri.Request.get.JSONP(url, params, callback, context);
  113. // request is longer then 2000 characters and the browser does not support CORS, log a warning
  114. } else {
  115. EsriLeaflet.Util.warn('a request to ' + url + ' was longer then 2000 characters and this browser cannot make a cross-domain post request. Please use a proxy http://esri.github.io/esri-leaflet/api-reference/request.html');
  116. return;
  117. }
  118. return httpRequest;
  119. },
  120. post: {
  121. XMLHTTP: function (url, params, callback, context) {
  122. var httpRequest = createRequest(callback, context);
  123. httpRequest.open('POST', url);
  124. httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  125. httpRequest.send(serialize(params));
  126. return httpRequest;
  127. }
  128. },
  129. get: {
  130. CORS: function (url, params, callback, context) {
  131. var httpRequest = createRequest(callback, context);
  132. httpRequest.open('GET', url + '?' + serialize(params), true);
  133. httpRequest.send(null);
  134. return httpRequest;
  135. },
  136. JSONP: function(url, params, callback, context){
  137. var callbackId = 'c' + callbacks;
  138. params.callback = 'window._EsriLeafletCallbacks.' + callbackId;
  139. var script = L.DomUtil.create('script', null, document.body);
  140. script.type = 'text/javascript';
  141. script.src = url + '?' + serialize(params);
  142. script.id = callbackId;
  143. window._EsriLeafletCallbacks[callbackId] = function(response){
  144. if(window._EsriLeafletCallbacks[callbackId] !== true){
  145. var error;
  146. var responseType = Object.prototype.toString.call(response);
  147. if(!(responseType === '[object Object]' || responseType === '[object Array]')){
  148. error = {
  149. error: {
  150. code: 500,
  151. message: 'Expected array or object as JSONP response'
  152. }
  153. };
  154. response = null;
  155. }
  156. if (!error && response.error) {
  157. error = response;
  158. response = null;
  159. }
  160. callback.call(context, error, response);
  161. window._EsriLeafletCallbacks[callbackId] = true;
  162. }
  163. };
  164. callbacks++;
  165. return {
  166. id: callbackId,
  167. url: script.src,
  168. abort: function(){
  169. window._EsriLeafletCallbacks._callback[callbackId]({
  170. code: 0,
  171. message: 'Request aborted.'
  172. });
  173. }
  174. };
  175. }
  176. }
  177. };
  178. // choose the correct AJAX handler depending on CORS support
  179. EsriLeaflet.get = (EsriLeaflet.Support.CORS) ? EsriLeaflet.Request.get.CORS : EsriLeaflet.Request.get.JSONP;
  180. // always use XMLHttpRequest for posts
  181. EsriLeaflet.post = EsriLeaflet.Request.post.XMLHTTP;
  182. // expose a common request method the uses GET\POST based on request length
  183. EsriLeaflet.request = EsriLeaflet.Request.request;
  184. })(EsriLeaflet);
  185. (function(EsriLeaflet){
  186. var tileProtocol = (window.location.protocol !== 'https:') ? 'http:' : 'https:';
  187. EsriLeaflet.Layers.BasemapLayer = L.TileLayer.extend({
  188. statics: {
  189. TILES: {
  190. Streets: {
  191. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
  192. attributionUrl: 'https://static.arcgis.com/attribution/World_Street_Map',
  193. options: {
  194. hideLogo: false,
  195. logoPosition: 'bottomright',
  196. minZoom: 1,
  197. maxZoom: 19,
  198. subdomains: ['server', 'services'],
  199. attribution: 'Esri'
  200. }
  201. },
  202. Topographic: {
  203. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}',
  204. attributionUrl: 'https://static.arcgis.com/attribution/World_Topo_Map',
  205. options: {
  206. hideLogo: false,
  207. logoPosition: 'bottomright',
  208. minZoom: 1,
  209. maxZoom: 19,
  210. subdomains: ['server', 'services'],
  211. attribution: 'Esri'
  212. }
  213. },
  214. Oceans: {
  215. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Base/MapServer/tile/{z}/{y}/{x}',
  216. attributionUrl: 'https://static.arcgis.com/attribution/Ocean_Basemap',
  217. options: {
  218. hideLogo: false,
  219. logoPosition: 'bottomright',
  220. minZoom: 1,
  221. maxZoom: 16,
  222. subdomains: ['server', 'services'],
  223. attribution: 'Esri'
  224. }
  225. },
  226. OceansLabels: {
  227. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/arcgis/rest/services/Ocean/World_Ocean_Reference/MapServer/tile/{z}/{y}/{x}',
  228. options: {
  229. hideLogo: true,
  230. logoPosition: 'bottomright',
  231. //pane: 'esri-label',
  232. minZoom: 1,
  233. maxZoom: 16,
  234. subdomains: ['server', 'services']
  235. }
  236. },
  237. NationalGeographic: {
  238. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer/tile/{z}/{y}/{x}',
  239. options: {
  240. hideLogo: false,
  241. logoPosition: 'bottomright',
  242. minZoom: 1,
  243. maxZoom: 16,
  244. subdomains: ['server', 'services'],
  245. attribution: 'Esri'
  246. }
  247. },
  248. DarkGray: {
  249. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Base/MapServer/tile/{z}/{y}/{x}',
  250. options: {
  251. hideLogo: false,
  252. logoPosition: 'bottomright',
  253. minZoom: 1,
  254. maxZoom: 16,
  255. subdomains: ['server', 'services'],
  256. attribution: 'Esri, DeLorme, HERE'
  257. }
  258. },
  259. DarkGrayLabels: {
  260. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Dark_Gray_Reference/MapServer/tile/{z}/{y}/{x}',
  261. options: {
  262. hideLogo: true,
  263. logoPosition: 'bottomright',
  264. //pane: 'esri-label',
  265. minZoom: 1,
  266. maxZoom: 16,
  267. subdomains: ['server', 'services']
  268. }
  269. },
  270. Gray: {
  271. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}',
  272. options: {
  273. hideLogo: false,
  274. logoPosition: 'bottomright',
  275. minZoom: 1,
  276. maxZoom: 16,
  277. subdomains: ['server', 'services'],
  278. attribution: 'Esri, NAVTEQ, DeLorme'
  279. }
  280. },
  281. GrayLabels: {
  282. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Reference/MapServer/tile/{z}/{y}/{x}',
  283. options: {
  284. hideLogo: true,
  285. logoPosition: 'bottomright',
  286. //pane: 'esri-label',
  287. minZoom: 1,
  288. maxZoom: 16,
  289. subdomains: ['server', 'services']
  290. }
  291. },
  292. Imagery: {
  293. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
  294. options: {
  295. hideLogo: false,
  296. logoPosition: 'bottomright',
  297. minZoom: 1,
  298. maxZoom: 19,
  299. subdomains: ['server', 'services'],
  300. attribution: 'Esri, DigitalGlobe, GeoEye, i-cubed, USDA, USGS, AEX, Getmapping, Aerogrid, IGN, IGP, swisstopo, and the GIS User Community'
  301. }
  302. },
  303. ImageryLabels: {
  304. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{z}/{y}/{x}',
  305. options: {
  306. hideLogo: true,
  307. logoPosition: 'bottomright',
  308. //pane: 'esri-label',
  309. minZoom: 1,
  310. maxZoom: 19,
  311. subdomains: ['server', 'services']
  312. }
  313. },
  314. ImageryTransportation: {
  315. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer/tile/{z}/{y}/{x}',
  316. //pane: 'esri-label',
  317. options: {
  318. hideLogo: true,
  319. logoPosition: 'bottomright',
  320. minZoom: 1,
  321. maxZoom: 19,
  322. subdomains: ['server', 'services']
  323. }
  324. },
  325. ShadedRelief: {
  326. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/{z}/{y}/{x}',
  327. options: {
  328. hideLogo: false,
  329. logoPosition: 'bottomright',
  330. minZoom: 1,
  331. maxZoom: 13,
  332. subdomains: ['server', 'services'],
  333. attribution: 'Esri, NAVTEQ, DeLorme'
  334. }
  335. },
  336. ShadedReliefLabels: {
  337. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places_Alternate/MapServer/tile/{z}/{y}/{x}',
  338. options: {
  339. hideLogo: true,
  340. logoPosition: 'bottomright',
  341. //pane: 'esri-label',
  342. minZoom: 1,
  343. maxZoom: 12,
  344. subdomains: ['server', 'services']
  345. }
  346. },
  347. Terrain: {
  348. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer/tile/{z}/{y}/{x}',
  349. options: {
  350. hideLogo: false,
  351. logoPosition: 'bottomright',
  352. minZoom: 1,
  353. maxZoom: 13,
  354. subdomains: ['server', 'services'],
  355. attribution: 'Esri, USGS, NOAA'
  356. }
  357. },
  358. TerrainLabels: {
  359. urlTemplate: tileProtocol + '//{s}.arcgisonline.com/ArcGIS/rest/services/Reference/World_Reference_Overlay/MapServer/tile/{z}/{y}/{x}',
  360. options: {
  361. hideLogo: true,
  362. logoPosition: 'bottomright',
  363. //pane: 'esri-label',
  364. minZoom: 1,
  365. maxZoom: 13,
  366. subdomains: ['server', 'services']
  367. }
  368. }
  369. }
  370. },
  371. initialize: function(key, options){
  372. var config;
  373. // set the config variable with the appropriate config object
  374. if (typeof key === 'object' && key.urlTemplate && key.options){
  375. config = key;
  376. } else if(typeof key === 'string' && EsriLeaflet.BasemapLayer.TILES[key]){
  377. config = EsriLeaflet.BasemapLayer.TILES[key];
  378. } else {
  379. throw new Error('L.esri.BasemapLayer: Invalid parameter. Use one of "Streets", "Topographic", "Oceans", "OceansLabels", "NationalGeographic", "Gray", "GrayLabels", "DarkGray", "DarkGrayLabels", "Imagery", "ImageryLabels", "ImageryTransportation", "ShadedRelief", "ShadedReliefLabels", "Terrain" or "TerrainLabels"');
  380. }
  381. // merge passed options into the config options
  382. var tileOptions = L.Util.extend(config.options, options);
  383. // call the initialize method on L.TileLayer to set everything up
  384. L.TileLayer.prototype.initialize.call(this, config.urlTemplate, L.Util.setOptions(this, tileOptions));
  385. // if this basemap requires dynamic attribution set it up
  386. if(config.attributionUrl){
  387. this._getAttributionData(config.attributionUrl);
  388. }
  389. this._logo = new EsriLeaflet.Controls.Logo({
  390. position: this.options.logoPosition
  391. });
  392. },
  393. onAdd: function(map){
  394. if(!this.options.hideLogo && !map._hasEsriLogo){
  395. this._logo.addTo(map);
  396. map._hasEsriLogo = true;
  397. }
  398. // if(this.options.pane && EsriLeaflet.Support.pointerEvents){
  399. // this._initPane();
  400. // }
  401. L.TileLayer.prototype.onAdd.call(this, map);
  402. map.on('moveend', this._updateMapAttribution, this);
  403. },
  404. onRemove: function(map){
  405. // check to make sure the logo hasn't already been removed
  406. if(!map._hasEsriLogo && this._logo && this._logo._container){
  407. map.removeControl(this._logo);
  408. map._hasEsriLogo = false;
  409. }
  410. L.TileLayer.prototype.onRemove.call(this, map);
  411. map.off('moveend', this._updateMapAttribution, this);
  412. },
  413. getAttribution:function(){
  414. var attribution = '<span class="esri-attributions" style="line-height:14px; vertical-align: -3px; text-overflow:ellipsis; white-space:nowrap; overflow:hidden; display:inline-block;">' + this.options.attribution + '</span>'/* + logo*/;
  415. return attribution;
  416. },
  417. // _initPane: function(){
  418. // if(!this._map.getPane(this.options.pane)){
  419. // var pane = this._map.createPane(this.options.pane);
  420. // pane.style.pointerEvents = 'none';
  421. // pane.style.zIndex = 5;
  422. // }
  423. // },
  424. _getAttributionData: function(url){
  425. L.esri.Request.get.JSONP(url, {}, L.Util.bind(function(error, attributions){
  426. this._attributions = [];
  427. for (var c = 0; c < attributions.contributors.length; c++) {
  428. var contributor = attributions.contributors[c];
  429. for (var i = 0; i < contributor.coverageAreas.length; i++) {
  430. var coverageArea = contributor.coverageAreas[i];
  431. var southWest = new L.LatLng(coverageArea.bbox[0], coverageArea.bbox[1]);
  432. var northEast = new L.LatLng(coverageArea.bbox[2], coverageArea.bbox[3]);
  433. this._attributions.push({
  434. attribution: contributor.attribution,
  435. score: coverageArea.score,
  436. bounds: new L.LatLngBounds(southWest, northEast),
  437. minZoom: coverageArea.zoomMin,
  438. maxZoom: coverageArea.zoomMax
  439. });
  440. }
  441. }
  442. this._attributions.sort(function(a, b){
  443. return b.score - a.score;
  444. });
  445. this._updateMapAttribution();
  446. }, this));
  447. },
  448. _updateMapAttribution: function(){
  449. if(this._map && this._map.attributionControl && this._attributions){
  450. var newAttributions = '';
  451. var bounds = this._map.getBounds();
  452. var zoom = this._map.getZoom();
  453. for (var i = 0; i < this._attributions.length; i++) {
  454. var attribution = this._attributions[i];
  455. var text = attribution.attribution;
  456. if(!newAttributions.match(text) && bounds.intersects(attribution.bounds) && zoom >= attribution.minZoom && zoom <= attribution.maxZoom) {
  457. newAttributions += (', ' + text);
  458. }
  459. }
  460. newAttributions = newAttributions.substr(2);
  461. var attributionElement = this._map.attributionControl._container.querySelector('.esri-attributions');
  462. attributionElement.innerHTML = newAttributions;
  463. attributionElement.style.maxWidth = (this._map.getSize().x * 0.65) + 'px';
  464. this.fire('attributionupdated', {
  465. attribution: newAttributions
  466. });
  467. }
  468. }
  469. });
  470. EsriLeaflet.BasemapLayer = EsriLeaflet.Layers.BasemapLayer;
  471. EsriLeaflet.Layers.basemapLayer = function(key, options){
  472. return new EsriLeaflet.Layers.BasemapLayer(key, options);
  473. };
  474. EsriLeaflet.basemapLayer = function(key, options){
  475. return new EsriLeaflet.Layers.BasemapLayer(key, options);
  476. };
  477. })(EsriLeaflet);
  478. EsriLeaflet.Controls.Logo = L.Control.extend({
  479. options: {
  480. position: 'bottomright',
  481. marginTop: 0,
  482. marginLeft: 0,
  483. marginBottom: 0,
  484. marginRight: 0
  485. },
  486. onAdd: function () {
  487. var div = L.DomUtil.create('div', 'esri-leaflet-logo');
  488. div.style.marginTop = this.options.marginTop;
  489. div.style.marginLeft = this.options.marginLeft;
  490. div.style.marginBottom = this.options.marginBottom;
  491. div.style.marginRight = this.options.marginRight;
  492. div.innerHTML = this._adjustLogo(this._map._size);
  493. this._map.on('resize', function(e){
  494. div.innerHTML = this._adjustLogo(e.newSize);
  495. }, this);
  496. return div;
  497. },
  498. _adjustLogo: function (mapSize) {
  499. if (mapSize.x <= 600 || mapSize.y <= 600){
  500. return '<a href="https://developers.arcgis.com" style="border: none;"><img src="https://js.arcgis.com/3.13/esri/images/map/logo-sm.png" alt="Powered by Esri" style="border: none;"></a>';
  501. }
  502. else {
  503. return '<a href="https://developers.arcgis.com" style="border: none;"><img src="https://js.arcgis.com/3.13/esri/images/map/logo-med.png" alt="Powered by Esri" style="border: none;"></a>';
  504. }
  505. }
  506. });
  507. EsriLeaflet.Controls.logo = function(options){
  508. return new L.esri.Controls.Logo(options);
  509. };
  510. return EsriLeaflet;
  511. }));
  512. //# sourceMappingURL=esri-leaflet-basemaps-src.js.map