Skip to content
Snippets Groups Projects
LayerBaseVectorEsri.js.map 11.8 KiB
Newer Older
glennvorhes's avatar
glennvorhes committed
{"version":3,"file":"LayerBaseVectorEsri.js","sourceRoot":"","sources":["../../src/layers/LayerBaseVectorEsri.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;AAEH,qDAA0E;AAC1E,qDAAuD;AACvD,2CAAsC;AACtC,0BAA6B;AAC7B,IAAI,EAAE,GAAG,iBAAO,CAAC,QAAQ,CAAC,CAAC;AAC3B,+CAA0C;AAG1C;;;;;;GAMG;AACH,wBAA+B,MAAc,EAAE,OAAe,EAAE,KAAa;IACzE,OAAO,yEAAuE,MAAM,SAAI,OAAO,mBAAc,KAAO,CAAA;AACxH,CAAC;AAFD,wCAEC;AAUD;;;GAGG;AACH;IAAyC,uCAAe;IAMpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,6BAAY,GAAW,EAAE,OAAmC;QAA5D,iBA8BC;QA5BG,IAAI,OAAO,OAAO,CAAC,MAAM,IAAI,QAAQ,EAAE;YACnC,OAAO,CAAC,MAAM,GAAG,EAAE,CAAC;SACvB;QACD,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC;QACjD,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,SAAS,IAAI,GAAG,CAAC;QACvD,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC;QAChD,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC;QAEhD,QAAA,kBAAM,GAAG,EAAE,OAAO,CAAC,SAAC;QACpB,KAAI,CAAC,MAAM,GAAG,KAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACnC,KAAI,CAAC,WAAW,GAAG,IAAI,kBAAQ,EAAE,CAAC;QAElC,IA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CAAC,GAAG,CAAC,CAAC;SAC/C;IACL,CAAC;IAED;;;;;OAKG;IACH,2CAAa,GAAb,UAAc,IAAY,EAAE,OAAe;QACvC,OAAO,iBAAM,aAAa,YAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC1C,0CAA0C;QAC1C,8CAA8C;QAC9C,kBAAkB;QAClB,UAAU;QACV,mBAAmB;QACnB,GAAG;IACP,CAAC;IAED;;;OAGG;IACH,6CAAe,GAAf,UAAgB,CAAS;QACrB,iBAAM,eAAe,YAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC;IACL,0BAAC;AAAD,CAAC,AArKD,CAAyC,iCAAe,GAqKvD;AArKY,kDAAmB;AAuKhC,EAAE,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;AAC7C,kBAAe,mBAAmB,CAAC","sourcesContent":["/**\r\n * Created by gavorhes on 11/2/2015.\r\n */\r\n\r\nimport {LayerBaseVector, LayerBaseVectorOptions} from './LayerBaseVector';\r\nimport * as esriToOl from '../olHelpers/esriToOlStyle';\r\nimport provide from '../util/provide';\r\nimport $ = require('jquery');\r\nlet nm = provide('layers');\r\nimport EsriJSON from 'ol/format/EsriJSON';\r\n\r\n\r\n/**\r\n * Helper to return the url to the service on the production server\r\n * @param {string} folder\r\n * @param {string} service\r\n * @param {number} layer\r\n * @returns {string}\r\n */\r\nexport function makeServiceUrl(folder: string, service: string, layer: number): string{\r\n    return `https://transportal.cee.wisc.edu/applications/arcgis2/rest/services/${folder}/${service}/MapServer/${layer}`\r\n}\r\n\r\nexport interface LayerBaseVectorEsriOptions  extends LayerBaseVectorOptions{\r\n    format?: string;\r\n    outSR?: number;\r\n    where?: string;\r\n    outFields?: string;\r\n    useEsriStyle?: boolean;\r\n}\r\n\r\n/**\r\n * Base layer for esri vector layers\r\n * @augments LayerBaseVector\r\n */\r\nexport class LayerBaseVectorEsri extends LayerBaseVector {\r\n    _outSR: number;\r\n    _esriFormat: ol.format.EsriJSON;\r\n    _urlCopy: string;\r\n    _useEsriStyle: boolean;\r\n\r\n    /**\r\n     * The base vector layer\r\n     * @param {string} url - url for source\r\n     * @param {object} options - config\r\n     * @param {string} [options.id] - layer id\r\n     * @param {string} [options.name=Unnamed Layer] - layer name\r\n     * @param {number} [options.opacity=1] - opacity\r\n     * @param {boolean} [options.visible=true] - default visible\r\n     * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28\r\n     * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28\r\n     * @param {object} [options.params={}] the get parameters to include to retrieve the layer\r\n     * @param {number} [options.zIndex=0] the z index for the layer\r\n     * @param {function} [options.loadCallback] function to call on load, context this is the layer object\r\n     * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed\r\n     * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility\r\n     * @param {boolean} [options.legendContent] additional content to add to the legend\r\n     *\r\n     * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible\r\n     * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined\r\n     * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move\r\n     * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called\r\n     * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages\r\n     *\r\n     * @param {string} [options.where=1=1] the layer filter clause\r\n     * @param {string} [options.outFields=*] comma separated list of output fields, defaults to all\r\n     * @param {string} [options.format=pjson] the format the retrieve the data\r\n     * @param {number} [options.outSR=3857] the output spatial reference, defaults to web mercator\r\n     * @param {boolean} [options.useEsriStyle=false] if the map service style should be used\r\n     * @param {boolean} [options.collapseLegend=false] if the legend should be initially collapsed\r\n     * @param {number} [options.mapMoveMakeGetParams=function(extent, zoomLevel){}] function to create additional map move params\r\n     */\r\n    constructor(url: string, options: LayerBaseVectorEsriOptions) {\r\n\r\n        if (typeof options.params != 'object') {\r\n            options.params = {};\r\n        }\r\n        options.params['where'] = options.where || '1=1';\r\n        options.params['outFields'] = options.outFields || '*';\r\n        options.params['f'] = options.format || 'pjson';\r\n        options.params['outSR'] = options.outSR || 3857;\r\n\r\n        super(url, options);\r\n        this._outSR = this.params['outSR'];\r\n        this._esriFormat = new EsriJSON();\r\n\r\n        if (this._url[this._url.length - 1] !== '/') {\r\n            this._url += '/';\r\n        }\r\n\r\n        this._urlCopy = this.url;\r\n        this._url += 'query?callback=?';\r\n\r\n        if (this.autoLoad || this.visible) {\r\n            this._load();\r\n        }\r\n\r\n        this._useEsriStyle = typeof options.useEsriStyle == 'boolean' ? options.useEsriStyle : false;\r\n\r\n        if (this._useEsriStyle) {\r\n            this.addLegendContent();\r\n        }\r\n    }\r\n\r\n    /**\r\n     * add additional content to the legend\r\n     * @param {string} [additionalContent=''] additional content to add to legend\r\n     */\r\n    addLegendContent(additionalContent?: string) {\r\n        if (!this._useEsriStyle) {\r\n            super.addLegendContent(additionalContent);\r\n        } else {\r\n            $.get(this._urlCopy + '?f=pjson&callback=?', {}, (d) => {\r\n                if (d['subLayers'].length > 0) {\r\n                    alert('should only use single feature layers, not groups');\r\n\r\n                    return;\r\n                }\r\n\r\n                let newStyleAndLegend = esriToOl.makeFeatureServiceLegendAndSymbol(d);\r\n                this.style = newStyleAndLegend.style;\r\n                super.addLegendContent(newStyleAndLegend.legend);\r\n            }, 'json');\r\n        }\r\n    }\r\n\r\n\r\n    /**\r\n     * add feature collection\r\n     * @param {object} featureCollection - features as esrijson\r\n     */\r\n    addFeatures(featureCollection: Object) {\r\n        let feats = this._esriFormat.readFeatures(featureCollection);\r\n        this.source.addFeatures(feats);\r\n    }\r\n\r\n    /**\r\n     * trigger load features\r\n     * @protected\r\n     * @returns {boolean} if already loaded\r\n     */\r\n    _load() {\r\n        if (super._load()) {\r\n            return true;\r\n        }\r\n        $.get(this._url, this.params, (d) => {\r\n            this.addFeatures(d);\r\n            this.loadCallback(this);\r\n        }, 'json').fail(() => {\r\n                this._loaded = false;\r\n            });\r\n\r\n        return false;\r\n    }\r\n\r\n    /**\r\n     * callback to generate the parameters passed in the get request\r\n     * @param {object} extent - extent object\r\n     * @param {number} extent.minX - minX\r\n     * @param {number} extent.minY - minY\r\n     * @param {number} extent.maxX - maxX\r\n     * @param {number} extent.maxY - maxY\r\n     * @param {number} zoomLevel - zoom level\r\n     */\r\n    mapMoveMakeGetParams(extent: {minX: number, minY: number, maxX: number, maxY: number}, zoomLevel: number) {\r\n        super.mapMoveMakeGetParams(extent, zoomLevel);\r\n        this.mapMoveParams['geometry'] = `${extent.minX},${extent.minY},${extent.maxX},${extent.maxY}`;\r\n        this.mapMoveParams['geometryType'] = 'esriGeometryEnvelope';\r\n        this.mapMoveParams['spatialRel'] = 'esriSpatialRelIntersects';\r\n        this.mapMoveParams['spatialRel'] = 'esriSpatialRelIntersects';\r\n        this.mapMoveParams['inSR'] = 3857;\r\n        if (this._outSR == 3857) {\r\n            this.mapMoveParams['geometryPrecision'] = 1;\r\n        }\r\n    }\r\n\r\n    /**\r\n     * Before call to map move callback, can prevent call by returning false\r\n     * @param {number} zoom - zoom level\r\n     * @param {string} [evtType=undefined] undefined for initial load, otherwise one of 'change:center', 'change:resolution'\r\n     * @returns {boolean} if the call should proceed\r\n     */\r\n    mapMoveBefore(zoom: number, evtType: string) {\r\n        return super.mapMoveBefore(zoom, evtType);\r\n        //if (super.mapMoveBefore(zoom, evtType)){\r\n        //    //place holder for additional processing\r\n        //    return true;\r\n        //} else {\r\n        //    return false;\r\n        //}\r\n    }\r\n\r\n    /**\r\n     * callback function on map move\r\n     * @param {object} d - the json response\r\n     */\r\n    mapMoveCallback(d: Object) {\r\n        super.mapMoveCallback(d);\r\n        this.source.addFeatures(this._esriFormat.readFeatures(d));\r\n    }\r\n}\r\n\r\nnm.LayerBaseVectorEsri = LayerBaseVectorEsri;\r\nexport default LayerBaseVectorEsri;\r\n"]}