javascript
ArcGIS API for JavaScript压缩版(compact)与标准版的区别
文章目錄
- 前言
- 區別一
- 區別二
- 參考鏈接
前言
在我們下載下來的API文件中可以看到里面包含了兩個版本,一個是常用的標準版,另一個是壓縮版。
如果到各自文件夾里面對比看的話,除了兩個版本的init.js文件大小不一樣外(壓縮版小點,900多kb),其他文件大小一致。除了init.js文件大小不同的區別外,還有以下兩個區別。
區別一
The compact build removes the dependency on the dijit namespace upon initial download, meaning that if you don’t need the dojo dijits they won’t be loaded. A side-effect of this is that a new info window and slider are provided.
壓縮版把最開始dijit下面的一些依賴給移除掉了,這里的dijit指的是dojo框架自身的一些微件(控件),ArcGIS在dijit之上封裝了一些常用微件如信息窗(infowindow)、縮放條(slider)等。下面通過最簡單的例子看一看。
標準版
<!DOCTYPE html> <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/><title>Simple Map</title><link rel="stylesheet" href="https://js.arcgis.com/3.28/esri/css/esri.css"><style>html, body, #map {height: 100%;margin: 0;padding: 0;}</style><script src="https://js.arcgis.com/3.28/"></script><script>var map;require(["esri/map", "dojo/domReady!"], function(Map) {map = new Map("map", {basemap: "topo", //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wdcenter: [-122.45, 37.75], // longitude, latitudezoom: 13});new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle");console.log("標準版,esri.tasks.QueryTask直接就可以用,因為在init.js里面提前就有了");});</script></head><body><div id="map"></div></body> </html>壓縮版
<!DOCTYPE html> <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/><title>Simple Map</title><link rel="stylesheet" href="https://js.arcgis.com/3.28compact/esri/css/esri.css"><style>html, body, #map {height: 100%;margin: 0;padding: 0;}</style><script src="https://js.arcgis.com/3.28compact/"></script><script>var map;require(["esri/map", "dojo/domReady!"], function(Map) {map = new Map("map", {basemap: "topo", //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wdcenter: [-122.45, 37.75], // longitude, latitudezoom: 13});new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_Currents_World/GPServer/MessageInABottle");console.log("壓縮版,esri.tasks.QueryTask也可以用,不過是init.js里面某行代碼require觸發的,而不是直接把QueryTask類的代碼拷貝了一份放到了init.js");});</script></head><body><div id="map"></div></body> </html>可以很明顯的看出來,init.js文件大小不一樣,而且同一個加載地圖的功能,壓縮版明顯加載的js文件數更多。就是因為壓縮版為了減小init.js的體積,把里面的一些依賴給移除掉了。
區別二
The compact build includes less modules than the standard build. If your application requires objects from modules not included in the compact build you will need to load them using require(). For example, if you want to perform geoprocessing with the compact build you will need to add the following require() statement to your application.
require([“esri/tasks/Geoprocessor”, … ], function(Geoprocessor, … ){ … });
These two features reduce the size of the build significantly. Less JavaScript code to execute means less work the browser has to do.
這個說的是比起標準版,壓縮版里面包含了更少的模塊。比如說esri/tasks/Geoprocessor,這個在壓縮版中是沒有事先引入的,你必須通過require手動引入。其實這條跟沒說差不多,因為我并不知道哪些是事先已經引入的,用的時候為了保險我只能先手動require進來。
參考鏈接
https://developers.arcgis.com/javascript/3/jshelp/intro_accessapi.html#compact-build
總結
以上是生活随笔為你收集整理的ArcGIS API for JavaScript压缩版(compact)与标准版的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ArcMap导出属性表为Excel文件
- 下一篇: margin-top的百分比是相对父元素