diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000000000000000000000000000000000000..8e22463d5dd3389e33980446c4b570fe89dd1d4b --- /dev/null +++ b/.babelrc @@ -0,0 +1,7 @@ +{ + "presets": ["es2015"], + "plugins": [ + "add-module-exports", + "transform-es2015-modules-umd" + ] +} \ No newline at end of file diff --git a/lib/collections/ItsLayerCollection.js b/lib/collections/ItsLayerCollection.js index 981d58fff5706742ff62f5552661a19b43a27665..b58ae06d7c1494b0993b09f6dac2eae44c93994f 100644 --- a/lib/collections/ItsLayerCollection.js +++ b/lib/collections/ItsLayerCollection.js @@ -1,143 +1,193 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); /** - * Created by gavorhes on 12/14/2015. - */ +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../layers/LayerItsInventory', '../util/colors', '../util/provide'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../layers/LayerItsInventory'), require('../util/colors'), require('../util/provide')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.LayerItsInventory, global.colors, global.provide); + global.ItsLayerCollection = mod.exports; + } +})(this, function (module, exports, _LayerItsInventory, _colors, _provide) { + 'use strict'; -var _LayerItsInventory = require('../layers/LayerItsInventory'); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _LayerItsInventory2 = _interopRequireDefault(_LayerItsInventory); + var _LayerItsInventory2 = _interopRequireDefault(_LayerItsInventory); -var _colors = require('../util/colors'); + var colors = _interopRequireWildcard(_colors); -var colors = _interopRequireWildcard(_colors); + var _provide2 = _interopRequireDefault(_provide); -var _provide = require('../util/provide'); + function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = {}; -var _provide2 = _interopRequireDefault(_provide); + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; + } + } -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + newObj.default = obj; + return newObj; + } + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } + 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; + }; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -var nm = (0, _provide2.default)('collections'); + 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); + } + } -var itsConfig = [{ name: 'Camera', itsType: 'cctv', minZoom: 11, itsIcon: 'cctv.png' }, { - name: 'Message Signs', - itsType: 'DMS', - minZoom: 11, - itsIconConfig: { - prop: 'dmsType', - defaultName: 'DMS', - defaultIcon: 'dms.png', - iconArray: [['pcms', 'PCMS', 'pcms.png']] - } -}, { name: 'Lighting', itsType: 'light', minZoom: 16, itsIcon: 'streetlight.png', visible: false, onDemand: true }, { name: 'Bluetooth', itsType: 'blue', minZoom: 10, itsIcon: 'bluetooth.png', visible: false }, { name: 'Cabinets', itsType: 'cabinet', minZoom: 10, itsIcon: 'cabinet.png', visible: false }, { name: 'Hut', itsType: 'hut', minZoom: 10, itsIcon: 'hut.png', visible: false }, { name: 'Vault', itsType: 'vault', minZoom: 13, itsIcon: 'vault.png', visible: false }, { name: 'Advisory Radio', itsType: 'har', minZoom: 10, itsIcon: 'har.png', visible: false }, { - name: 'Loop Detectors', - itsType: 'loop', - legendCollapse: true, - minZoom: 14, - visible: false, - itsIconConfig: { - prop: 'dtctrType', - defaultName: 'Other', - defaultIcon: 'loopdetectorother.png', - iconArray: [['detector', 'Detector', 'loopdetector.png'], ['long', 'Long', 'loopdetectorlong.png'], ['zone', 'Zone', 'loopdetectorzone.png']] - }, - onDemand: true -}, { name: 'Microwave', itsType: 'microwave', minZoom: 14, itsIcon: 'microwave.png', visible: false }, { name: 'Pull Box', itsType: 'pull', minZoom: 14, itsIcon: 'pullbox.png', visible: false, onDemand: true }, { name: 'RWIS', itsType: 'rwis', minZoom: 7, itsIcon: 'rwis.png', visible: false }, { name: 'Ramp Gates', itsType: 'gate', minZoom: 10, itsIcon: 'rampgate.png', visible: false }, { name: 'Ramp Meter', itsType: 'meter', minZoom: 10, itsIcon: 'rampmeter.png', visible: false }, { name: 'Signal', itsType: 'signal', minZoom: 13, itsIcon: 'signal.png', visible: false, onDemand: true }, { name: 'Tower', itsType: 'tower', minZoom: 10, itsIcon: 'tower.png', visible: false }, { - name: 'Trench', - itsType: 'trench', - onDemand: true, - visible: false, - onDemandDelay: 500, - minZoom: 15, - legendCollapse: true, - itsLineConfig: { - prop: 'owner', - //defaultName: 'Other', - //defaultWidth: 7, - defaultColor: colors.hexAlphaToRgbOrRgba('#747474', 0.8), - lineArray: [['WisDOT', 'WisDOT', colors.hexAlphaToRgbOrRgba('#FF032F', 0.7)], ['WIN', 'WIN', colors.hexAlphaToRgbOrRgba('#FFC632', 0.7)], ['USXchange', 'USXchange', colors.hexAlphaToRgbOrRgba('#2DFF46', 0.7)], ['AT&T', 'AT&T', colors.hexAlphaToRgbOrRgba('#ff2be5', 0.7)], ['Touch America', 'Touch America', colors.hexAlphaToRgbOrRgba('#52f3ff', 0.7)], ['Qwest', 'Qwest', colors.hexAlphaToRgbOrRgba('#9278ff', 0.7)], ['McLeodUSA', 'McLeodUSA', colors.hexAlphaToRgbOrRgba('#2926FF', 0.7)], ['CINC', 'CINC', colors.hexAlphaToRgbOrRgba('#CB00FF', 0.7)], ['City of Madison', 'Madison', colors.hexAlphaToRgbOrRgba('#000380', 0.7)]] - } -}]; - -var ItsLayerCollection = (function () { - - /** - * Create a collection of all ITS layers - * @param {ol.Map} theMap the openlayers map - * @param {Array} [exclude=[]] array of Its layer identifiers to exclude - * - * BLUE Bluetooth Detector - Bluetooth Detector - * CABINET Cabinets - The cabinets - * CCTV Camera - Traffic Cameras - * HUT Communication Hut - Communication Hut - * VAULT Communication Vault - The communication vaults - * HAR Highway Advisory Radio - Advisory Radios - * LIGHT Lighting - Lighting - * LOOP Loop Detectors - Loop Detectors - * DMS Message Board - Message Boards and Signs - * MICROWAVE Microwave Detector - Microwave Detectors - * PULL Pull Box - A pull box - * RWIS RWIS - Road weather information system - * GATE Ramp Gate - The ramp Gates - * METER Ramp Meter - The ramp meters - * SIGNAL Signal - Traffic Signal - * TOWER Tower - The towers - * TRENCH - */ - - function ItsLayerCollection(theMap, exclude) { - _classCallCheck(this, ItsLayerCollection); - - this.map = theMap; - this._layers = []; - - exclude = (typeof exclude === 'undefined' ? 'undefined' : _typeof(exclude)) == 'object' ? exclude : []; - - for (var i = 0; i < itsConfig.length; i++) { - var lyrConfig = itsConfig[i]; - var addLayer = true; - - for (var j = 0; j < exclude.length; j++) { - if (exclude[j] == lyrConfig.itsType) { - addLayer = false; - break; + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + var nm = (0, _provide2.default)('collections'); + + var itsConfig = [{ name: 'Camera', itsType: 'cctv', minZoom: 11, itsIcon: 'cctv.png' }, { + name: 'Message Signs', + itsType: 'DMS', + minZoom: 11, + itsIconConfig: { + prop: 'dmsType', + defaultName: 'DMS', + defaultIcon: 'dms.png', + iconArray: [['pcms', 'PCMS', 'pcms.png']] + } + }, { name: 'Lighting', itsType: 'light', minZoom: 16, itsIcon: 'streetlight.png', visible: false, onDemand: true }, { name: 'Bluetooth', itsType: 'blue', minZoom: 10, itsIcon: 'bluetooth.png', visible: false }, { name: 'Cabinets', itsType: 'cabinet', minZoom: 10, itsIcon: 'cabinet.png', visible: false }, { name: 'Hut', itsType: 'hut', minZoom: 10, itsIcon: 'hut.png', visible: false }, { name: 'Vault', itsType: 'vault', minZoom: 13, itsIcon: 'vault.png', visible: false }, { name: 'Advisory Radio', itsType: 'har', minZoom: 10, itsIcon: 'har.png', visible: false }, { + name: 'Loop Detectors', + itsType: 'loop', + legendCollapse: true, + minZoom: 14, + visible: false, + itsIconConfig: { + prop: 'dtctrType', + defaultName: 'Other', + defaultIcon: 'loopdetectorother.png', + iconArray: [['detector', 'Detector', 'loopdetector.png'], ['long', 'Long', 'loopdetectorlong.png'], ['zone', 'Zone', 'loopdetectorzone.png']] + }, + onDemand: true + }, { name: 'Microwave', itsType: 'microwave', minZoom: 14, itsIcon: 'microwave.png', visible: false }, { name: 'Pull Box', itsType: 'pull', minZoom: 14, itsIcon: 'pullbox.png', visible: false, onDemand: true }, { name: 'RWIS', itsType: 'rwis', minZoom: 7, itsIcon: 'rwis.png', visible: false }, { name: 'Ramp Gates', itsType: 'gate', minZoom: 10, itsIcon: 'rampgate.png', visible: false }, { name: 'Ramp Meter', itsType: 'meter', minZoom: 10, itsIcon: 'rampmeter.png', visible: false }, { name: 'Signal', itsType: 'signal', minZoom: 13, itsIcon: 'signal.png', visible: false, onDemand: true }, { name: 'Tower', itsType: 'tower', minZoom: 10, itsIcon: 'tower.png', visible: false }, { + name: 'Trench', + itsType: 'trench', + onDemand: true, + visible: false, + onDemandDelay: 500, + minZoom: 15, + legendCollapse: true, + itsLineConfig: { + prop: 'owner', + //defaultName: 'Other', + //defaultWidth: 7, + defaultColor: colors.hexAlphaToRgbOrRgba('#747474', 0.8), + lineArray: [['WisDOT', 'WisDOT', colors.hexAlphaToRgbOrRgba('#FF032F', 0.7)], ['WIN', 'WIN', colors.hexAlphaToRgbOrRgba('#FFC632', 0.7)], ['USXchange', 'USXchange', colors.hexAlphaToRgbOrRgba('#2DFF46', 0.7)], ['AT&T', 'AT&T', colors.hexAlphaToRgbOrRgba('#ff2be5', 0.7)], ['Touch America', 'Touch America', colors.hexAlphaToRgbOrRgba('#52f3ff', 0.7)], ['Qwest', 'Qwest', colors.hexAlphaToRgbOrRgba('#9278ff', 0.7)], ['McLeodUSA', 'McLeodUSA', colors.hexAlphaToRgbOrRgba('#2926FF', 0.7)], ['CINC', 'CINC', colors.hexAlphaToRgbOrRgba('#CB00FF', 0.7)], ['City of Madison', 'Madison', colors.hexAlphaToRgbOrRgba('#000380', 0.7)]] + } + }]; + + var ItsLayerCollection = function () { + + /** + * Create a collection of all ITS layers + * @param {ol.Map} theMap the openlayers map + * @param {Array} [exclude=[]] array of Its layer identifiers to exclude + * + * BLUE Bluetooth Detector - Bluetooth Detector + * CABINET Cabinets - The cabinets + * CCTV Camera - Traffic Cameras + * HUT Communication Hut - Communication Hut + * VAULT Communication Vault - The communication vaults + * HAR Highway Advisory Radio - Advisory Radios + * LIGHT Lighting - Lighting + * LOOP Loop Detectors - Loop Detectors + * DMS Message Board - Message Boards and Signs + * MICROWAVE Microwave Detector - Microwave Detectors + * PULL Pull Box - A pull box + * RWIS RWIS - Road weather information system + * GATE Ramp Gate - The ramp Gates + * METER Ramp Meter - The ramp meters + * SIGNAL Signal - Traffic Signal + * TOWER Tower - The towers + * TRENCH + */ + + function ItsLayerCollection(theMap, exclude) { + _classCallCheck(this, ItsLayerCollection); + + this.map = theMap; + this._layers = []; + + exclude = (typeof exclude === 'undefined' ? 'undefined' : _typeof(exclude)) == 'object' ? exclude : []; + + for (var i = 0; i < itsConfig.length; i++) { + var lyrConfig = itsConfig[i]; + var addLayer = true; + + for (var j = 0; j < exclude.length; j++) { + if (exclude[j] == lyrConfig.itsType) { + addLayer = false; + break; + } } - } - if (addLayer) { - var inventLyr = new _LayerItsInventory2.default(lyrConfig); - this['map'].addLayer(inventLyr.olLayer); - this._layers.push(inventLyr); + if (addLayer) { + var inventLyr = new _LayerItsInventory2.default(lyrConfig); + this['map'].addLayer(inventLyr.olLayer); + this._layers.push(inventLyr); + } } } - } - /** - * Return the array of layers in this collection - * @returns {Array<LayerItsInventory>} an array of layers - */ + /** + * Return the array of layers in this collection + * @returns {Array<LayerItsInventory>} an array of layers + */ - _createClass(ItsLayerCollection, [{ - key: 'layers', - get: function get() { - return this._layers; - } - }]); - return ItsLayerCollection; -})(); + _createClass(ItsLayerCollection, [{ + key: 'layers', + get: function get() { + return this._layers; + } + }]); + + return ItsLayerCollection; + }(); -nm.ItsLayerCollection = ItsLayerCollection; -exports.default = ItsLayerCollection; -module.exports = exports['default']; \ No newline at end of file + nm.ItsLayerCollection = ItsLayerCollection; + exports.default = ItsLayerCollection; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/collections/LayerLegend.js b/lib/collections/LayerLegend.js index 44b3602ff30b91cbac9e7b6d7b5d9b3d2c3eb615..e941d7710f7d9eee3250cfdfc7fb1f53b41cd860 100644 --- a/lib/collections/LayerLegend.js +++ b/lib/collections/LayerLegend.js @@ -1,441 +1,451 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); /** - * Created by gavorhes on 12/16/2015. - */ - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); - -var _provide = require('../util/provide'); - -var _provide2 = _interopRequireDefault(_provide); - -var _makeGuid = require('../util/makeGuid'); - -var _makeGuid2 = _interopRequireDefault(_makeGuid); - -var _mapMove = require('../olHelpers/mapMove'); - -var _mapMove2 = _interopRequireDefault(_mapMove); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', '../util/provide', '../util/makeGuid', '../olHelpers/mapMove'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('../util/provide'), require('../util/makeGuid'), require('../olHelpers/mapMove')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.provide, global.makeGuid, global.mapMove); + global.LayerLegend = mod.exports; + } +})(this, function (module, exports, _jquery, _provide, _makeGuid, _mapMove) { + 'use strict'; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + Object.defineProperty(exports, "__esModule", { + value: true + }); -var nm = (0, _provide2.default)('collections'); + var _jquery2 = _interopRequireDefault(_jquery); -var LayerGroup = (function () { + var _provide2 = _interopRequireDefault(_provide); - /** - * - * @param {object} [groupConfig={}] - group configuration object - * @param {string} groupConfig.groupName - the group name - * @param {boolean} [groupConfig.collapse=false] - if the group should be collapsed initially - * @param {boolean} [groupConfig.addCheck=true] - if the group should have a checkbox controlling visibility of all layers - * @param {LayerGroup} [parent=undefined] - the parent group - */ + var _makeGuid2 = _interopRequireDefault(_makeGuid); - function LayerGroup(groupConfig, parent) { - _classCallCheck(this, LayerGroup); + var _mapMove2 = _interopRequireDefault(_mapMove); - this.groupLayers = []; - this.groupLayersLookup = {}; - this.groupGroups = []; - this.groupGroupsLookup = {}; - this.itemIdArray = []; + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } - if (typeof groupConfig == 'undefined') { - this.parent = null; - this.groupId = 'root'; - this.groupName = 'root'; - this.allGroupLookup = { root: this }; - this.allGroupArray = [this]; - this.allLayerArray = []; - this.allLayerLookup = {}; - this.layerParentLookup = {}; - this.collapse = false; - this.addCheck = false; - } else { - this.groupId = (0, _makeGuid2.default)(); - this.parent = parent; - this.groupName = groupConfig.groupName; - this.collapse = typeof groupConfig.collapse == 'boolean' ? groupConfig.collapse : false; - this.addCheck = typeof groupConfig.addCheck == 'boolean' ? groupConfig.addCheck : true; + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); } } - /** - * - * @param {object} groupConfig - configuration object - * @param {string} groupConfig.groupName - the group name - * @param {boolean} groupConfig.collapse if the group should be collapsed initially - * @param {boolean} groupConfig.addCheck if the group should have a checkbox controlling visibility of all layers - * @param {Array<LayerGroup>} parents parent groups - * @returns {LayerGroup} the layer group just added - */ - - _createClass(LayerGroup, [{ - key: 'addGroup', - value: function addGroup(groupConfig, parents) { - var parent = undefined; - if (parents.length > 0) { - parent = parents[parents.length - 1]; - } else { - parent = 'root'; + 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); } + } - /** - * @type {LayerGroup} - */ - var parentGroup = this.allGroupLookup[parent]; - var newGroup = new LayerGroup(groupConfig, parentGroup); - this.allGroupLookup[newGroup.groupId] = newGroup; - this.allGroupArray.push(newGroup); + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); - parentGroup.groupGroups.push(newGroup); - parentGroup.groupGroupsLookup[newGroup.groupId] = newGroup; + var nm = (0, _provide2.default)('collections'); - if (parentGroup.itemIdArray.indexOf(newGroup.groupId) > 0) { - console.log(newGroup.groupId); - throw 'layer and group ids must be unique'; - } - parentGroup.itemIdArray.push(newGroup.groupId); - - return newGroup; - } + var LayerGroup = function () { /** * - * @param {LayerBase} newLayer the layer to be added - * @param {Array} parents array + * @param {object} [groupConfig={}] - group configuration object + * @param {string} groupConfig.groupName - the group name + * @param {boolean} [groupConfig.collapse=false] - if the group should be collapsed initially + * @param {boolean} [groupConfig.addCheck=true] - if the group should have a checkbox controlling visibility of all layers + * @param {LayerGroup} [parent=undefined] - the parent group */ - }, { - key: 'addLegendLayer', - value: function addLegendLayer(newLayer, parents) { - var parent = undefined; - if (parents.length > 0) { - parent = parents[parents.length - 1]; + function LayerGroup(groupConfig, parent) { + _classCallCheck(this, LayerGroup); + + this.groupLayers = []; + this.groupLayersLookup = {}; + this.groupGroups = []; + this.groupGroupsLookup = {}; + this.itemIdArray = []; + + if (typeof groupConfig == 'undefined') { + this.parent = null; + this.groupId = 'root'; + this.groupName = 'root'; + this.allGroupLookup = { root: this }; + this.allGroupArray = [this]; + this.allLayerArray = []; + this.allLayerLookup = {}; + this.layerParentLookup = {}; + this.collapse = false; + this.addCheck = false; } else { - parent = 'root'; + this.groupId = (0, _makeGuid2.default)(); + this.parent = parent; + this.groupName = groupConfig.groupName; + this.collapse = typeof groupConfig.collapse == 'boolean' ? groupConfig.collapse : false; + this.addCheck = typeof groupConfig.addCheck == 'boolean' ? groupConfig.addCheck : true; } - - this.allLayerLookup[newLayer.id] = newLayer; - this.allLayerArray.push(newLayer); - - /** - * @type {LayerGroup} - */ - var parentGroup = this.allGroupLookup[parent]; - - parentGroup.groupLayers.push(newLayer); - parentGroup.groupLayersLookup[newLayer.id] = newLayer; - if (parentGroup.itemIdArray.indexOf(newLayer.id) > 0) { - console.log(newLayer.id); - throw 'layer and group ids must be unique'; - } - parentGroup.itemIdArray.push(newLayer.id); - - this.layerParentLookup[newLayer.id] = parentGroup; } - }, { - key: 'getLegendHtml', - value: function getLegendHtml(legendId, options) { - var legendHtml = '<ul id="' + legendId + '" class="legend-container">'; + /** + * + * @param {object} groupConfig - configuration object + * @param {string} groupConfig.groupName - the group name + * @param {boolean} groupConfig.collapse if the group should be collapsed initially + * @param {boolean} groupConfig.addCheck if the group should have a checkbox controlling visibility of all layers + * @param {Array<LayerGroup>} parents parent groups + * @returns {LayerGroup} the layer group just added + */ - legendHtml += '<li>' + options.legendTitle + '<input type="checkbox" checked id="suppress-by-extent-' + legendId + '" class="suppress-by-extent">' + ('<label title="Suppress layers not visible at this zoom level" for="suppress-by-extent-' + legendId + '">') + '<span></span>' + '</label></li>'; - legendHtml += this._buildLegend(this.itemIdArray, this, options.layerDivClasses) + '</ul>'; + _createClass(LayerGroup, [{ + key: 'addGroup', + value: function addGroup(groupConfig, parents) { + var parent = void 0; + if (parents.length > 0) { + parent = parents[parents.length - 1]; + } else { + parent = 'root'; + } - return legendHtml; - } + /** + * @type {LayerGroup} + */ + var parentGroup = this.allGroupLookup[parent]; + var newGroup = new LayerGroup(groupConfig, parentGroup); + this.allGroupLookup[newGroup.groupId] = newGroup; + this.allGroupArray.push(newGroup); - /** - * @param {Array} itemIds the items to process - * @param {LayerGroup} theGroup new group - * @param {Array} [layerDivClasses=[]] optional classes to apply to the layer divs - * @static - * @returns {string} html string - */ + parentGroup.groupGroups.push(newGroup); + parentGroup.groupGroupsLookup[newGroup.groupId] = newGroup; - }, { - key: '_buildLegend', - value: function _buildLegend(itemIds, theGroup, layerDivClasses) { + if (parentGroup.itemIdArray.indexOf(newGroup.groupId) > 0) { + console.log(newGroup.groupId); + throw 'layer and group ids must be unique'; + } + parentGroup.itemIdArray.push(newGroup.groupId); - if (itemIds.length == 0) { - return ''; + return newGroup; } + }, { + key: 'addLegendLayer', + value: function addLegendLayer(newLayer, parents) { + var parent = void 0; + if (parents.length > 0) { + parent = parents[parents.length - 1]; + } else { + parent = 'root'; + } - var theHml = ''; - - var itemId = itemIds[0]; - - if (theGroup.groupLayersLookup[itemId]) { + this.allLayerLookup[newLayer.id] = newLayer; + this.allLayerArray.push(newLayer); /** - * @type {LayerBase} - */ - var lyr = theGroup.groupLayersLookup[itemId]; - theHml += '<li id="' + lyr.id + '-layer-li" class="legend-layer-li ' + layerDivClasses.join(' ') + '">' + lyr.getLegendDiv() + '</li>'; - } else if (theGroup.groupGroupsLookup[itemId]) { - /** - * type {LayerGroup} + * @type {LayerGroup} */ - var otherGroup = theGroup.groupGroupsLookup[itemId]; - - theHml += '<li>'; - theHml += '<div id="' + otherGroup.groupId + '-legend-layer-div" ' + ('class="legend-layer-group ' + layerDivClasses.join(' ') + '">'); + var parentGroup = this.allGroupLookup[parent]; - if (otherGroup.addCheck) { - theHml += '<input type="checkbox" checked id="' + otherGroup.groupId + '-group-chck">' + ('<label for="' + otherGroup.groupId + '-group-chck" title="Click arrow to expand or collapse">' + otherGroup.groupName + '</label>'); - } else { - theHml += '<label title="Click arrow to expand or collapse">' + otherGroup.groupName + '</label>'; + parentGroup.groupLayers.push(newLayer); + parentGroup.groupLayersLookup[newLayer.id] = newLayer; + if (parentGroup.itemIdArray.indexOf(newLayer.id) > 0) { + console.log(newLayer.id); + throw 'layer and group ids must be unique'; } + parentGroup.itemIdArray.push(newLayer.id); + + this.layerParentLookup[newLayer.id] = parentGroup; + } + }, { + key: 'getLegendHtml', + value: function getLegendHtml(legendId, options) { + + var legendHtml = '<ul id="' + legendId + '" class="legend-container">'; + + legendHtml += '<li>' + options.legendTitle + '<input type="checkbox" checked id="suppress-by-extent-' + legendId + '" class="suppress-by-extent">' + ('<label title="Suppress layers not visible at this zoom level" for="suppress-by-extent-' + legendId + '">') + '<span></span>' + '</label></li>'; - theHml += '<span title="Expand/Collapse" class="layer-group-expander'; - theHml += (otherGroup.collapse ? ' legend-layer-group-initial-collapse' : '') + '">'; - theHml += otherGroup.collapse ? '▶' : '▼'; - theHml += '</span>'; + legendHtml += this._buildLegend(this.itemIdArray, this, options.layerDivClasses) + '</ul>'; - //parents.push(groupId); - theHml += '<ul>' + this._buildLegend(otherGroup.itemIdArray, otherGroup, layerDivClasses) + '</ul>'; - theHml += '</div>'; - theHml += '</li>'; + return legendHtml; } + }, { + key: '_buildLegend', + value: function _buildLegend(itemIds, theGroup, layerDivClasses) { - return theHml + this._buildLegend(itemIds.slice(1), theGroup, layerDivClasses); - } - }]); + if (itemIds.length == 0) { + return ''; + } - return LayerGroup; -})(); + var theHml = ''; -/** - * a wrapper to make a legend - */ + var itemId = itemIds[0]; -var LayerLegend = (function () { + if (theGroup.groupLayersLookup[itemId]) { - /** - * - * @param {Array} legendItems array of layers or objects with {groupName: {string}, collapse: {boolean}, addCheck: {boolean}, items: {Array}} - * @param {string} divId the div where the legend should be added - * @param {object} options for legend - * @param {Array} [options.layerDivClasses=[]] optional array of classes to be applied to the layer legend divs for custom styling - * @param {string} [options.legendTitle=Legend] the legend title - * @param {bool} [options.scaleDependent=true] if legend display is scale dependent - */ + /** + * @type {LayerBase} + */ + var lyr = theGroup.groupLayersLookup[itemId]; + theHml += '<li id="' + lyr.id + '-layer-li" class="legend-layer-li ' + layerDivClasses.join(' ') + '">' + lyr.getLegendDiv() + '</li>'; + } else if (theGroup.groupGroupsLookup[itemId]) { + /** + * type {LayerGroup} + */ + var otherGroup = theGroup.groupGroupsLookup[itemId]; - function LayerLegend(legendItems, divId, options) { - _classCallCheck(this, LayerLegend); + theHml += '<li>'; + theHml += '<div id="' + otherGroup.groupId + '-legend-layer-div" ' + ('class="legend-layer-group ' + layerDivClasses.join(' ') + '">'); - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + if (otherGroup.addCheck) { + theHml += '<input type="checkbox" checked id="' + otherGroup.groupId + '-group-chck">' + ('<label for="' + otherGroup.groupId + '-group-chck" title="Click arrow to expand or collapse">' + otherGroup.groupName + '</label>'); + } else { + theHml += '<label title="Click arrow to expand or collapse">' + otherGroup.groupName + '</label>'; + } - try { - for (var _iterator = legendItems[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var i = _step.value; + theHml += '<span title="Expand/Collapse" class="layer-group-expander'; + theHml += (otherGroup.collapse ? ' legend-layer-group-initial-collapse' : '') + '">'; + theHml += otherGroup.collapse ? '▶' : '▼'; + theHml += '</span>'; - if (typeof i == 'undefined') { - throw 'undefined item passed in array to legend constructor'; + //parents.push(groupId); + theHml += '<ul>' + this._buildLegend(otherGroup.itemIdArray, otherGroup, layerDivClasses) + '</ul>'; + theHml += '</div>'; + theHml += '</li>'; } + + return theHml + this._buildLegend(itemIds.slice(1), theGroup, layerDivClasses); } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { + }]); + + return LayerGroup; + }(); + + var LayerLegend = function () { + + /** + * + * @param {Array} legendItems array of layers or objects with {groupName: {string}, collapse: {boolean}, addCheck: {boolean}, items: {Array}} + * @param {string} divId the div where the legend should be added + * @param {object} options for legend + * @param {Array} [options.layerDivClasses=[]] optional array of classes to be applied to the layer legend divs for custom styling + * @param {string} [options.legendTitle=Legend] the legend title + * @param {bool} [options.scaleDependent=true] if legend display is scale dependent + */ + + function LayerLegend(legendItems, divId, options) { + _classCallCheck(this, LayerLegend); + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); + for (var _iterator = legendItems[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var i = _step.value; + + if (typeof i == 'undefined') { + throw 'undefined item passed in array to legend constructor'; + } } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; } finally { - if (_didIteratorError) { - throw _iteratorError; + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } } } - } - - options = options || {}; - options.legendTitle = typeof options.legendTitle == 'string' ? options.legendTitle : 'Legend'; - options.scaleDependent = typeof options.scaleDependent == 'boolean' ? options.scaleDependent : true; - options.layerDivClasses = options.layerDivClasses || []; + options = options || {}; - // if legend display is scale dependent, make sure the mapMove object is initialized first - if (options.scaleDependent) { - _mapMove2.default.checkInit(); - } + options.legendTitle = typeof options.legendTitle == 'string' ? options.legendTitle : 'Legend'; + options.scaleDependent = typeof options.scaleDependent == 'boolean' ? options.scaleDependent : true; + options.layerDivClasses = options.layerDivClasses || []; - this.$divElement = (0, _jquery2.default)('#' + divId); + // if legend display is scale dependent, make sure the mapMove object is initialized first + if (options.scaleDependent) { + _mapMove2.default.checkInit(); + } - this._legendItems = legendItems; + this.$divElement = (0, _jquery2.default)('#' + divId); - this.layerGroup = new LayerGroup(); + this._legendItems = legendItems; - this._buildTree(legendItems); + this.layerGroup = new LayerGroup(); - this.legendId = (0, _makeGuid2.default)(); + this._buildTree(legendItems); - this.$divElement.append(this.layerGroup.getLegendHtml(this.legendId, options)); + this.legendId = (0, _makeGuid2.default)(); - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; + this.$divElement.append(this.layerGroup.getLegendHtml(this.legendId, options)); - try { - for (var _iterator2 = this.layerGroup.allLayerArray[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var l = _step2.value; + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; - l.applyCollapse(); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { try { - if (!_iteratorNormalCompletion2 && _iterator2.return) { - _iterator2.return(); + for (var _iterator2 = this.layerGroup.allLayerArray[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var l = _step2.value; + + l.applyCollapse(); } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; } finally { - if (_didIteratorError2) { - throw _iteratorError2; + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } } } - } - var _this = this; + var _this = this; - //// if legend display is scale dependent, make sure the mapMove object is initialized first - if (options.scaleDependent) { - _mapMove2.default.checkInit(); + //// if legend display is scale dependent, make sure the mapMove object is initialized first + if (options.scaleDependent) { + _mapMove2.default.checkInit(); - _mapMove2.default.addCallback(function (ext, zoom, evt) { - if (typeof evt == 'undefined' || evt == 'change:resolution') { - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; + _mapMove2.default.addCallback(function (ext, zoom, evt) { + if (typeof evt == 'undefined' || evt == 'change:resolution') { + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; - try { - for (var _iterator3 = this.layerGroup.allLayerArray[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var lyr = _step3.value; - - var $lyrLi = (0, _jquery2.default)('#' + lyr.id + '-layer-li'); - if (zoom > lyr.maxZoom || zoom < lyr.minZoom) { - $lyrLi.addClass('layer-not-visible'); - } else { - $lyrLi.removeClass('layer-not-visible'); - } - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { try { - if (!_iteratorNormalCompletion3 && _iterator3.return) { - _iterator3.return(); + for (var _iterator3 = this.layerGroup.allLayerArray[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var lyr = _step3.value; + + var $lyrLi = (0, _jquery2.default)('#' + lyr.id + '-layer-li'); + if (zoom > lyr.maxZoom || zoom < lyr.minZoom) { + $lyrLi.addClass('layer-not-visible'); + } else { + $lyrLi.removeClass('layer-not-visible'); + } } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; } finally { - if (_didIteratorError3) { - throw _iteratorError3; + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } } } } - } - }, this, 100, true, 'legend1'); - } - - // <editor-fold desc="add event listeners"> - - this.$divElement.find(".suppress-by-extent").change(function () { - var legendLayerLis = (0, _jquery2.default)('.legend-layer-li'); - if (this.checked) { - legendLayerLis.removeClass('layer-force-show'); - } else { - legendLayerLis.addClass('layer-force-show'); + }, this, 100, true, 'legend1'); } - }); - this.$divElement.find('.legend-check').change(function () { - var lyrId = this.id.replace('-legend-layer-check', ''); - _this.layerGroup.allLayerLookup[lyrId].visible = this.checked; - }); + // <editor-fold desc="add event listeners"> - this.$divElement.find('.legend-layer-group > input[type=checkbox]').change(function () { - (0, _jquery2.default)(this).siblings('ul').find('input[type=checkbox]').prop('checked', this.checked).trigger('change'); - }); + this.$divElement.find(".suppress-by-extent").change(function () { + var legendLayerLis = (0, _jquery2.default)('.legend-layer-li'); + if (this.checked) { + legendLayerLis.removeClass('layer-force-show'); + } else { + legendLayerLis.addClass('layer-force-show'); + } + }); - this.$divElement.find('.layer-group-expander').click(function () { - var $this = (0, _jquery2.default)(this); - $this.removeClass('legend-layer-group-initial-collapse'); + this.$divElement.find('.legend-check').change(function () { + var lyrId = this.id.replace('-legend-layer-check', ''); + _this.layerGroup.allLayerLookup[lyrId].visible = this.checked; + }); - $this.siblings('ul').slideToggle(); + this.$divElement.find('.legend-layer-group > input[type=checkbox]').change(function () { + (0, _jquery2.default)(this).siblings('ul').find('input[type=checkbox]').prop('checked', this.checked).trigger('change'); + }); - if ($this.hasClass('legend-layer-group-collapsed')) { - $this.removeClass('legend-layer-group-collapsed'); - $this.html('▼'); - } else { - $this.addClass('legend-layer-group-collapsed'); - $this.html('▶'); - } - }); + this.$divElement.find('.layer-group-expander').click(function () { + var $this = (0, _jquery2.default)(this); + $this.removeClass('legend-layer-group-initial-collapse'); - this.$divElement.find('.legend-layer-group-initial-collapse').trigger('click'); - // </editor-fold> - } + $this.siblings('ul').slideToggle(); - /** - * @param {Array} [legendItems=this._layerConfig] the legend items - * @param {Array} [parents=[]] the ordered list of groups in which this item is a member - * @private - */ + if ($this.hasClass('legend-layer-group-collapsed')) { + $this.removeClass('legend-layer-group-collapsed'); + $this.html('▼'); + } else { + $this.addClass('legend-layer-group-collapsed'); + $this.html('▶'); + } + }); - _createClass(LayerLegend, [{ - key: '_buildTree', - value: function _buildTree(legendItems, parents) { + this.$divElement.find('.legend-layer-group-initial-collapse').trigger('click'); + // </editor-fold> + } - if (legendItems.length == 0) { - return; - } + /** + * @param {Array} [legendItems=this._layerConfig] the legend items + * @param {Array} [parents=[]] the ordered list of groups in which this item is a member + * @private + */ - var oneItem = legendItems[0]; - //reset the parent if the item is in the base array - if (this._legendItems.indexOf(oneItem) > -1 || typeof parents == 'undefined') { - parents = []; - } + _createClass(LayerLegend, [{ + key: '_buildTree', + value: function _buildTree(legendItems, parents) { - if (typeof oneItem['groupName'] !== 'undefined') { - var groupItem = legendItems[0]; - var newGroup = this.layerGroup.addGroup(groupItem, parents); - parents.push(newGroup.groupId); - this._buildTree(groupItem.items, parents); - } else { - /** - * @type {LayerBase} - */ - var layerItem = legendItems[0]; + if (legendItems.length == 0) { + return; + } - this.layerGroup.addLegendLayer(layerItem, parents); - } + var oneItem = legendItems[0]; - this._buildTree(legendItems.slice(1), parents); - } - }, { - key: 'showAll', - set: function set(val) {} - }]); + //reset the parent if the item is in the base array + if (this._legendItems.indexOf(oneItem) > -1 || typeof parents == 'undefined') { + parents = []; + } + + if (typeof oneItem['groupName'] !== 'undefined') { + var groupItem = legendItems[0]; + var newGroup = this.layerGroup.addGroup(groupItem, parents); + parents.push(newGroup.groupId); + this._buildTree(groupItem.items, parents); + } else { + /** + * @type {LayerBase} + */ + var layerItem = legendItems[0]; - return LayerLegend; -})(); + this.layerGroup.addLegendLayer(layerItem, parents); + } -nm.LayerLegend = LayerLegend; -exports.default = LayerLegend; -module.exports = exports['default']; \ No newline at end of file + this._buildTree(legendItems.slice(1), parents); + } + }, { + key: 'showAll', + set: function set(val) {} + }]); + + return LayerLegend; + }(); + + nm.LayerLegend = LayerLegend; + exports.default = LayerLegend; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/collections/Sliders.js b/lib/collections/Sliders.js index 6824424a058e4189aadb8a777fc265f2628a249f..a9f1f0de63bc10df0c31a5feb68590c7c10d22bf 100644 --- a/lib/collections/Sliders.js +++ b/lib/collections/Sliders.js @@ -1,603 +1,532 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); /** - * Created by gavorhes on 12/10/2015. - */ - -var _provide = require('../util/provide'); - -var _provide2 = _interopRequireDefault(_provide); - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var nm = (0, _provide2.default)('collections'); - -var _Slider = (function () { - - /** - * Slider constructor - * @param {string} name - the slider name - * @param {Array} selections - the selection - * @param {number} wgt - weight - * @param {boolean} selected - if selected - */ - - function _Slider(name, selections, wgt, selected) { - _classCallCheck(this, _Slider); - - //let _this = this; - this.name = name; - this.domId = name.toLowerCase().replace(/ /g, '-'); - this._weight = wgt; - this._weightDefault = this._weight; - - this.selectedParam = null; - this.selectedParamDefault = null; - - this._locked = false; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../util/provide', '../jquery'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../util/provide'), require('../jquery')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.provide, global.jquery); + global.Sliders = mod.exports; + } +})(this, function (module, exports, _provide, _jquery) { + 'use strict'; - this._min = 0.0; - this._max = 100; + Object.defineProperty(exports, "__esModule", { + value: true + }); - this.labelLow = null; - this.labelHigh = null; - this.labelVal = null; - this.slider = null; - this.chk = null; + var _provide2 = _interopRequireDefault(_provide); - this.atMin = this._weight == this._min; - this.atMax = this._weight == this._max; + var _jquery2 = _interopRequireDefault(_jquery); - var sel = '<select class="' + (selections.length == 1 ? 'hidden-select' : 'show-select') + '" id="' + this.domId + '_chg">'; - for (var _i = 0; _i < selections.length; _i++) { - var itm = selections[_i][0]; - var itmSelected = itm === selected; + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } - sel += '<option value="' + itm + '" ' + (itmSelected ? ' selected="selected"' : '') + '>' + selections[_i][1] + '</option>'; - if (itmSelected) { - this.selectedParam = itm; - } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); } - sel += '</select>'; - - this.selectedParamDefault = this.selectedParam; - - this.html = '<div class="slider-div">' + ('<label for="' + this.domId + '_chk" class="slider-label">' + this.name + '</label>') + sel + '<br>' + ('<input id="' + this.domId + '_chk" type="checkbox" title="Lock/Unlock Slider">') + ('<label id="' + this.domId + '_low" class="low-high">' + this._min.toFixed(1) + '</label>') + ('<input id="' + this.domId + '" type="range" value="' + this._weight.toFixed(1) + '" min="0" max="100" step="0.1">') + ('<label id="' + this.domId + '_high" class="low-high">' + this._max.toFixed(1) + '</label>') + ('<label id="' + this.domId + '_lbl" for="' + this.domId + '" class="percent-label">' + this._weight.toFixed(1) + '%</label></div>'); } - /** - * add html to dom - * @param {jQuery} $container - container element - */ - - _createClass(_Slider, [{ - key: 'addToDom', - value: function addToDom($container) { - $container.append(this.html); - this.labelLow = (0, _jquery2.default)('#' + this.domId + '_low'); - this.labelHigh = (0, _jquery2.default)('#' + this.domId + '_high'); - this.labelVal = (0, _jquery2.default)('#' + this.domId + '_lbl'); - this.slider = (0, _jquery2.default)('#' + this.domId); - this.selectionBox = (0, _jquery2.default)('#' + this.domId + '_chg'); - this.chk = (0, _jquery2.default)('#' + this.domId + '_chk'); + 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); + } } - /** - * increment the slider - * @param {number} delta change delta - * @returns {number} the remainder not able to be allocated to this slider - */ - - }, { - key: 'increment', - value: function increment(delta) { - var remainder = 0; - delta = Number(delta.toFixed(1)); - - this._weight += delta; - if (this._weight < this._min) { - remainder = this._min - this._weight; - this._weight = this._min; - this.atMin = true; - } else if (this._weight > this._max) { - remainder = this._max - this._weight; - this._weight = this._max; - this.atMax = true; - } else { - this.atMin = false; - this.atMax = false; - } + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); - this.slider.val(this._weight.toFixed(1)); - this.labelVal.html(this._weight.toFixed(1) + '%'); + var nm = (0, _provide2.default)('collections'); - return remainder; - } + var _Slider = function () { /** - * reset to the original values + * Slider constructor + * @param {string} name - the slider name + * @param {Array} selections - the selection + * @param {number} wgt - weight + * @param {boolean} selected - if selected */ - }, { - key: 'reset', - value: function reset() { - this.weight = this._weightDefault; - this.slider.val(this._weightDefault.toFixed(1)); - this.selectionBox.val(this.selectedParamDefault); - this.chk.attr('checked', false); - //let event = new CustomEvent('change'); - //this.chk[0].dispatchEvent(event); - } + function _Slider(name, selections, wgt, selected) { + _classCallCheck(this, _Slider); - /** - * set the value and drop down - * @param {number} newVal the new value - * @param {string} selectedParam the selected parameter - */ + //let _this = this; + this.name = name; + this.domId = name.toLowerCase().replace(/ /g, '-'); + this._weight = wgt; + this._weightDefault = this._weight; - }, { - key: 'setValAndDropDown', - value: function setValAndDropDown(newVal, selectedParam) { - this.weight = newVal; - this.min = 0; - this.max = 100; - this.slider.val(newVal.toFixed(1)); - this.selectionBox.val(selectedParam); - this.selectedParam = selectedParam; - this.locked = true; - } + this.selectedParam = null; + this.selectedParamDefault = null; - /** - * - * @returns {boolean} if locked - */ + this._locked = false; - }, { - key: 'locked', - get: function get() { - return this._locked; - } + this._min = 0.0; + this._max = 100; - /** - * - * @param {boolean} val if locked - */ - , - set: function set(val) { - this._locked = val; - this.slider.prop('disabled', this._locked); - this.selectionBox.prop('disabled', this._locked); - this.chk.prop('checked', !this._locked); - } + this.labelLow = null; + this.labelHigh = null; + this.labelVal = null; + this.slider = null; + this.chk = null; - /** - * - * @returns {number} the minimum - */ + this.atMin = this._weight == this._min; + this.atMax = this._weight == this._max; - }, { - key: 'min', - get: function get() { - return this._min; - } + var sel = '<select class="' + (selections.length == 1 ? 'hidden-select' : 'show-select') + '" id="' + this.domId + '_chg">'; + for (var _i = 0; _i < selections.length; _i++) { + var itm = selections[_i][0]; + var itmSelected = itm === selected; - /** - * - * @param {number} newVal new minimum - */ - , - set: function set(newVal) { - this._min = Number(newVal.toFixed(1)); - if (this._min < 0) { - this._min = 0; + sel += '<option value="' + itm + '" ' + (itmSelected ? ' selected="selected"' : '') + '>' + selections[_i][1] + '</option>'; + if (itmSelected) { + this.selectedParam = itm; + } } - this.labelLow.html(this._min.toFixed(1)); - this.slider.attr('min', this._min.toFixed(1)); - this.atMin = this._weight == this._min; - } + sel += '</select>'; - /** - * - * @returns {number} the maximum - */ + this.selectedParamDefault = this.selectedParam; - }, { - key: 'max', - get: function get() { - return this._max; + this.html = '<div class="slider-div">' + ('<label for="' + this.domId + '_chk" class="slider-label">' + this.name + '</label>') + sel + '<br>' + ('<input id="' + this.domId + '_chk" type="checkbox" title="Lock/Unlock Slider">') + ('<label id="' + this.domId + '_low" class="low-high">' + this._min.toFixed(1) + '</label>') + ('<input id="' + this.domId + '" type="range" value="' + this._weight.toFixed(1) + '" min="0" max="100" step="0.1">') + ('<label id="' + this.domId + '_high" class="low-high">' + this._max.toFixed(1) + '</label>') + ('<label id="' + this.domId + '_lbl" for="' + this.domId + '" class="percent-label">' + this._weight.toFixed(1) + '%</label></div>'); } /** - * - * @param {number} newVal the maximum + * add html to dom + * @param {jQuery} $container - container element */ - , - set: function set(newVal) { - this._max = Number(newVal.toFixed(1)); - if (this._max > 100) { - this._max = 100.0; - } - this.labelHigh.html(this._max.toFixed(1)); - this.slider.attr('max', this._max.toFixed(1)); - this.atMax = this._weight == this._max; - } - /** - * - * @returns {number} the weight - */ - - }, { - key: 'weight', - get: function get() { - return this._weight; - } - /** - * - * @param {number} newVal the weight - */ - , - set: function set(newVal) { - this._weight = Number(newVal.toFixed(1)); - this.labelVal.html(this._weight.toFixed(1) + '%'); - if (this._weight <= this._min) { - this.atMin = true; - this.atMax = false; - } else if (this._weight >= this._max) { - this.atMin = false; - this.atMax = true; - } else { - this.atMin = false; - this.atMax = false; + _createClass(_Slider, [{ + key: 'addToDom', + value: function addToDom($container) { + $container.append(this.html); + this.labelLow = (0, _jquery2.default)('#' + this.domId + '_low'); + this.labelHigh = (0, _jquery2.default)('#' + this.domId + '_high'); + this.labelVal = (0, _jquery2.default)('#' + this.domId + '_lbl'); + this.slider = (0, _jquery2.default)('#' + this.domId); + this.selectionBox = (0, _jquery2.default)('#' + this.domId + '_chg'); + this.chk = (0, _jquery2.default)('#' + this.domId + '_chk'); } - } - }]); + }, { + key: 'increment', + value: function increment(delta) { + var remainder = 0; + delta = Number(delta.toFixed(1)); + + this._weight += delta; + if (this._weight < this._min) { + remainder = this._min - this._weight; + this._weight = this._min; + this.atMin = true; + } else if (this._weight > this._max) { + remainder = this._max - this._weight; + this._weight = this._max; + this.atMax = true; + } else { + this.atMin = false; + this.atMax = false; + } + + this.slider.val(this._weight.toFixed(1)); + this.labelVal.html(this._weight.toFixed(1) + '%'); - return _Slider; -})(); + return remainder; + } + }, { + key: 'reset', + value: function reset() { + this.weight = this._weightDefault; + this.slider.val(this._weightDefault.toFixed(1)); + this.selectionBox.val(this.selectedParamDefault); + this.chk.attr('checked', false); + //let event = new CustomEvent('change'); + //this.chk[0].dispatchEvent(event); + } + }, { + key: 'setValAndDropDown', + value: function setValAndDropDown(newVal, selectedParam) { + this.weight = newVal; + this.min = 0; + this.max = 100; + this.slider.val(newVal.toFixed(1)); + this.selectionBox.val(selectedParam); + this.selectedParam = selectedParam; + this.locked = true; + } + }, { + key: 'locked', + get: function get() { + return this._locked; + }, + set: function set(val) { + this._locked = val; + this.slider.prop('disabled', this._locked); + this.selectionBox.prop('disabled', this._locked); + this.chk.prop('checked', !this._locked); + } + }, { + key: 'min', + get: function get() { + return this._min; + }, + set: function set(newVal) { + this._min = Number(newVal.toFixed(1)); + if (this._min < 0) { + this._min = 0; + } + this.labelLow.html(this._min.toFixed(1)); + this.slider.attr('min', this._min.toFixed(1)); + this.atMin = this._weight == this._min; + } + }, { + key: 'max', + get: function get() { + return this._max; + }, + set: function set(newVal) { + this._max = Number(newVal.toFixed(1)); + if (this._max > 100) { + this._max = 100.0; + } + this.labelHigh.html(this._max.toFixed(1)); + this.slider.attr('max', this._max.toFixed(1)); + this.atMax = this._weight == this._max; + } + }, { + key: 'weight', + get: function get() { + return this._weight; + }, + set: function set(newVal) { + this._weight = Number(newVal.toFixed(1)); + this.labelVal.html(this._weight.toFixed(1) + '%'); + if (this._weight <= this._min) { + this.atMin = true; + this.atMax = false; + } else if (this._weight >= this._max) { + this.atMin = false; + this.atMax = true; + } else { + this.atMin = false; + this.atMax = false; + } + } + }]); -nm._Slider = _Slider; + return _Slider; + }(); -/** - * class to make a slider group - */ + nm._Slider = _Slider; -var Sliders = (function () { /** - * - * @param {Array} paramList list of parameters - * @param {string} divId the div id + * class to make a slider group */ - function Sliders(paramList, divId) { - _classCallCheck(this, Sliders); - - this.resetting = false; - this._slideFinishedFunctions = []; - this.reservedPercent = 0.0; - this.$container = (0, _jquery2.default)('#' + divId); - this.$container.addClass('slider-container'); - - this.sliderList = []; - this.sliderLookup = {}; - - this.total = 0; - - for (var _i2 = 0; _i2 < paramList.length; _i2++) { - var p = paramList[_i2]; + var Sliders = function () { + /** + * + * @param {Array} paramList list of parameters + * @param {string} divId the div id + */ - var _sld = new _Slider(p[0], p[1], p[2], p[3]); - this.sliderList.push(_sld); - this.sliderLookup[_sld.domId] = _sld; - _sld.addToDom(this.$container); - this.total += _sld._weight; - } + function Sliders(paramList, divId) { + _classCallCheck(this, Sliders); - if (this.total != 100) { - alert('total not equal to 100'); - } + this.resetting = false; + this._slideFinishedFunctions = []; + this.reservedPercent = 0.0; + this.$container = (0, _jquery2.default)('#' + divId); + this.$container.addClass('slider-container'); - this.lockedList = []; - this.inRangeList = []; - this.atMinList = []; - this.atMaxList = []; + this.sliderList = []; + this.sliderLookup = {}; - this.lockedCount = 0; - this.notLockedCount = 0; + this.total = 0; - this._splitSliderArray(); - this._addEventListeners(); - } + for (var _i2 = 0; _i2 < paramList.length; _i2++) { + var p = paramList[_i2]; - _createClass(Sliders, [{ - key: 'addSlideFinishedFunction', - value: function addSlideFinishedFunction(finishedFunction) { - this._slideFinishedFunctions.push(finishedFunction); - } + var _sld = new _Slider(p[0], p[1], p[2], p[3]); + this.sliderList.push(_sld); + this.sliderLookup[_sld.domId] = _sld; + _sld.addToDom(this.$container); + this.total += _sld._weight; + } - /** - * split array into subarrays holding the sliders - * @private - */ + if (this.total != 100) { + alert('total not equal to 100'); + } - }, { - key: '_splitSliderArray', - value: function _splitSliderArray() { this.lockedList = []; this.inRangeList = []; this.atMinList = []; this.atMaxList = []; - for (var _i3 = 0; _i3 < this.sliderList.length; _i3++) { - var _sld2 = this.sliderList[_i3]; + this.lockedCount = 0; + this.notLockedCount = 0; - if (_sld2.locked) { - this.lockedList.push(_sld2); - } else if (_sld2.atMin) { - this.atMinList.push(_sld2); - } else if (_sld2.atMax) { - this.atMaxList.push(_sld2); - } else { - this.inRangeList.push(_sld2); - } - } - this.lockedCount = this.lockedList.length; - this.notLockedCount = this.sliderList.length - this.lockedCount; + this._splitSliderArray(); + this._addEventListeners(); } - /** - * handle remainder, recursive to take care of min max overshoots - * @param {number} remain the remainder - * @param {string} skipDomId - this dom id - * @private - */ - - }, { - key: '_handleRemainder', - value: function _handleRemainder(remain, skipDomId) { - - remain = Number(remain.toFixed(1)); - if (remain == 0) { - return; + _createClass(Sliders, [{ + key: 'addSlideFinishedFunction', + value: function addSlideFinishedFunction(finishedFunction) { + this._slideFinishedFunctions.push(finishedFunction); } - - this._splitSliderArray(); - - var canChangeArray = []; - for (var _i4 = 0; _i4 < this.inRangeList.length; _i4++) { - var _sld3 = this.inRangeList[_i4]; - if (_sld3.domId == skipDomId) { - continue; + }, { + key: '_splitSliderArray', + value: function _splitSliderArray() { + this.lockedList = []; + this.inRangeList = []; + this.atMinList = []; + this.atMaxList = []; + + for (var _i3 = 0; _i3 < this.sliderList.length; _i3++) { + var _sld2 = this.sliderList[_i3]; + + if (_sld2.locked) { + this.lockedList.push(_sld2); + } else if (_sld2.atMin) { + this.atMinList.push(_sld2); + } else if (_sld2.atMax) { + this.atMaxList.push(_sld2); + } else { + this.inRangeList.push(_sld2); + } } - canChangeArray.push(_sld3); + this.lockedCount = this.lockedList.length; + this.notLockedCount = this.sliderList.length - this.lockedCount; } + }, { + key: '_handleRemainder', + value: function _handleRemainder(remain, skipDomId) { - if (remain > 0) { - for (var _i5 = 0; _i5 < this.atMaxList.length; _i5++) { - var _sld4 = this.atMaxList[_i5]; - if (_sld4.domId == skipDomId) { - continue; - } - canChangeArray.push(_sld4); + remain = Number(remain.toFixed(1)); + if (remain == 0) { + return; } - } else { - for (var _i6 = 0; _i6 < this.atMinList.length; _i6++) { - var _sld5 = this.atMinList[_i6]; - if (_sld5.domId == skipDomId) { + + this._splitSliderArray(); + + var canChangeArray = []; + for (var _i4 = 0; _i4 < this.inRangeList.length; _i4++) { + var _sld3 = this.inRangeList[_i4]; + if (_sld3.domId == skipDomId) { continue; } - canChangeArray.push(_sld5); + canChangeArray.push(_sld3); } - } - if (canChangeArray.length == 0) { - return; - } - - var inc = -1 * Number((remain / canChangeArray.length).toFixed(1)); + if (remain > 0) { + for (var _i5 = 0; _i5 < this.atMaxList.length; _i5++) { + var _sld4 = this.atMaxList[_i5]; + if (_sld4.domId == skipDomId) { + continue; + } + canChangeArray.push(_sld4); + } + } else { + for (var _i6 = 0; _i6 < this.atMinList.length; _i6++) { + var _sld5 = this.atMinList[_i6]; + if (_sld5.domId == skipDomId) { + continue; + } + canChangeArray.push(_sld5); + } + } - var newRemainder = 0; - for (var _i7 = 0; _i7 < canChangeArray.length; _i7++) { - newRemainder += canChangeArray[_i7].increment(inc); - } + if (canChangeArray.length == 0) { + return; + } - this._handleRemainder(newRemainder, skipDomId); - } + var inc = -1 * Number((remain / canChangeArray.length).toFixed(1)); - /** - * reset all - */ + var newRemainder = 0; + for (var _i7 = 0; _i7 < canChangeArray.length; _i7++) { + newRemainder += canChangeArray[_i7].increment(inc); + } - }, { - key: 'reset', - value: function reset() { - this.resetting = true; - for (var _i8 = 0; _i8 < this.sliderList.length; _i8++) { - var _sld6 = this.sliderList[_i8]; - _sld6.reset(); + this._handleRemainder(newRemainder, skipDomId); } - this.resetting = false; + }, { + key: 'reset', + value: function reset() { + this.resetting = true; + for (var _i8 = 0; _i8 < this.sliderList.length; _i8++) { + var _sld6 = this.sliderList[_i8]; + _sld6.reset(); + } + this.resetting = false; - if (this._slideFinishedFunctions != null) { - this._slideFinishedFunctions(); + if (this._slideFinishedFunctions != null) { + this._slideFinishedFunctions(); + } } - } - - /** - * - * @param {object} keyValList key and value list - */ - - }, { - key: 'setValues', - value: function setValues(keyValList) { - this.resetting = true; - for (var k in keyValList) { - if (keyValList.hasOwnProperty(k)) { - this.sliderLookup[k].setValAndDropDown(keyValList[k][0], keyValList[k][1]); + }, { + key: 'setValues', + value: function setValues(keyValList) { + this.resetting = true; + for (var k in keyValList) { + if (keyValList.hasOwnProperty(k)) { + this.sliderLookup[k].setValAndDropDown(keyValList[k][0], keyValList[k][1]); + } } + this.resetting = false; } - this.resetting = false; - } - - /** - * get the weight sum - * @returns {number} the weight sum - */ + }, { + key: 'getSum', + value: function getSum() { + var total = 0; + for (var _i9 = 0; _i9 < this.sliderList.length; _i9++) { + var _sld7 = this.sliderList[_i9]; + total += Number(_sld7.weight.toFixed(1)); + } - }, { - key: 'getSum', - value: function getSum() { - var total = 0; - for (var _i9 = 0; _i9 < this.sliderList.length; _i9++) { - var _sld7 = this.sliderList[_i9]; - total += Number(_sld7.weight.toFixed(1)); + return total; } + }, { + key: 'getParams', + value: function getParams() { + var paramWeights = {}; + for (var _i10 = 0; _i10 < this.sliderList.length; _i10++) { + var _sld8 = this.sliderList[_i10]; + paramWeights[_sld8.selectedParam] = Number(_sld8.weight.toFixed(1)); + } - return total; - } - - /** - * get the parameter weights - * @returns {object} lookup with parameter weights - */ - - }, { - key: 'getParams', - value: function getParams() { - var paramWeights = {}; - for (var _i10 = 0; _i10 < this.sliderList.length; _i10++) { - var _sld8 = this.sliderList[_i10]; - paramWeights[_sld8.selectedParam] = Number(_sld8.weight.toFixed(1)); + return paramWeights; } + }, { + key: '_addEventListeners', + value: function _addEventListeners() { + var _this = this; + + //change function + this.$container.find('input[type="range"]').change(function () { + if (_this.resetting) { + return; + } - return paramWeights; - } - }, { - key: '_addEventListeners', - value: function _addEventListeners() { - var _this = this; - - //change function - this.$container.find('input[type="range"]').change(function () { - if (_this.resetting) { - return; - } - - var $this = (0, _jquery2.default)(this); - var domId = this.id; - var sldr = _this.sliderLookup[domId]; + var $this = (0, _jquery2.default)(this); + var domId = this.id; + var sldr = _this.sliderLookup[domId]; - var newValue = parseFloat($this.val()); + var newValue = parseFloat($this.val()); - var oldValue = sldr.weight; - var diff = newValue - oldValue; - diff = Number(diff.toFixed(1)); + var oldValue = sldr.weight; + var diff = newValue - oldValue; + diff = Number(diff.toFixed(1)); - sldr.weight = Number(newValue.toFixed(1)); + sldr.weight = Number(newValue.toFixed(1)); - _this._handleRemainder(diff, domId); + _this._handleRemainder(diff, domId); - //cleanup, make sure the sum is still 100 - var sum = Number(_this.getSum().toFixed(1)); + //cleanup, make sure the sum is still 100 + var sum = Number(_this.getSum().toFixed(1)); - if (sum > 100) { - loop1: while (true) { - for (i = 0; i < _this.sliderList.length; i++) { - var _sld9 = _this.sliderList[i]; - if (_sld9.domId == domId || _sld9.locked || _sld9.atMin) { - continue; - } - _sld9.increment(-0.1); - sum -= 0.1; - if (sum.toFixed(1) == '100.0') { - break loop1; + if (sum > 100) { + loop1: while (true) { + for (i = 0; i < _this.sliderList.length; i++) { + var _sld9 = _this.sliderList[i]; + if (_sld9.domId == domId || _sld9.locked || _sld9.atMin) { + continue; + } + _sld9.increment(-0.1); + sum -= 0.1; + if (sum.toFixed(1) == '100.0') { + break loop1; + } } } - } - } else if (sum < 100) { - loop1: while (true) { - for (i = 0; i < _this.sliderList.length; i++) { - sld = _this.sliderList[i]; - if (sld.domId == domId || sld.locked || sld.atMax) { - continue; - } - sld.increment(0.1); - sum += 0.1; - if (sum.toFixed(1) == '100.0') { - break loop1; + } else if (sum < 100) { + loop1: while (true) { + for (i = 0; i < _this.sliderList.length; i++) { + sld = _this.sliderList[i]; + if (sld.domId == domId || sld.locked || sld.atMax) { + continue; + } + sld.increment(0.1); + sum += 0.1; + if (sum.toFixed(1) == '100.0') { + break loop1; + } } } } - } - for (var _i11 = 0; _i11 < _this._slideFinishedFunctions.length; _i11++) { - _this._slideFinishedFunctions[_i11](); - } - }); + for (var _i11 = 0; _i11 < _this._slideFinishedFunctions.length; _i11++) { + _this._slideFinishedFunctions[_i11](); + } + }); - //update the selected parameter when the selection is changed - (0, _jquery2.default)('.show-select').change(function () { - if (_this.resetting) { - return; - } - _this.sliderLookup[this.id.replace('_chg', '')].selectedParam = (0, _jquery2.default)(this).val(); - }); + //update the selected parameter when the selection is changed + (0, _jquery2.default)('.show-select').change(function () { + if (_this.resetting) { + return; + } + _this.sliderLookup[this.id.replace('_chg', '')].selectedParam = (0, _jquery2.default)(this).val(); + }); - //lock the slider and update the reserved percent - this.$container.find('input[type="checkbox"]').change(function () { - var domEl = this; + //lock the slider and update the reserved percent + this.$container.find('input[type="checkbox"]').change(function () { + var domEl = this; - _this.sliderLookup[domEl.id.replace('_chk', '')].locked = !domEl.checked; - _this.reservedPercent = 0.0; - _this.notLockedCount = 0; + _this.sliderLookup[domEl.id.replace('_chk', '')].locked = !domEl.checked; + _this.reservedPercent = 0.0; + _this.notLockedCount = 0; - var notLockedSliders = []; + var notLockedSliders = []; - for (var _i12 = 0; _i12 < _this.sliderList.length; _i12++) { - var _sld10 = _this.sliderList[_i12]; - if (_sld10.locked) { - _this.reservedPercent += _sld10.weight; - continue; + for (var _i12 = 0; _i12 < _this.sliderList.length; _i12++) { + var _sld10 = _this.sliderList[_i12]; + if (_sld10.locked) { + _this.reservedPercent += _sld10.weight; + continue; + } + notLockedSliders.push(_sld10); + _this.notLockedCount++; } - notLockedSliders.push(_sld10); - _this.notLockedCount++; - } - for (i = 0; i < _this.sliderList.length; i++) { - sld = _this.sliderList[i]; - if (sld.locked) { - continue; + for (i = 0; i < _this.sliderList.length; i++) { + sld = _this.sliderList[i]; + if (sld.locked) { + continue; + } + sld.max = 100 - _this.reservedPercent; } - sld.max = 100 - _this.reservedPercent; - } - if (notLockedSliders.length == 1) { - notLockedSliders[0].min = notLockedSliders[0].weight; - } else { - for (i = 0; i < notLockedSliders.length; i++) { - notLockedSliders[i].min = 0; + if (notLockedSliders.length == 1) { + notLockedSliders[0].min = notLockedSliders[0].weight; + } else { + for (i = 0; i < notLockedSliders.length; i++) { + notLockedSliders[i].min = 0; + } } - } - }); - } - }]); + }); + } + }]); - return Sliders; -})(); + return Sliders; + }(); -nm.Sliders = Sliders; -window.gv['collections'].Sliders = Sliders; -exports.default = Sliders; -module.exports = exports['default']; \ No newline at end of file + nm.Sliders = Sliders; + window.gv['collections'].Sliders = Sliders; + exports.default = Sliders; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/gulp-helpers.js b/lib/gulp-helpers.js index 425b8e6a55625309249cec697ce1a58a675b7ebc..cfaa02de2a9538cf8a55d1ef71a50655a1d7412b 100644 --- a/lib/gulp-helpers.js +++ b/lib/gulp-helpers.js @@ -1,180 +1,177 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.bundleEs2015 = bundleEs2015; -exports.processLessFile = processLessFile; -exports.bundleEs2015Multiple = bundleEs2015Multiple; -/** - * Created by gavorhes on 5/10/2016. - * Helpers functions for gulp tasks - */ - -var gulp = require('gulp'); -var babel = require('gulp-babel'); -var babelify = require('babelify'); -var browserify = require('browserify'); -var buffer = require('vinyl-buffer'); -var source = require('vinyl-source-stream'); -var sourcemaps = require('gulp-sourcemaps'); -var minify = require('gulp-minify'); -var less = require('gulp-less'); -var cssmin = require('gulp-cssmin'); -var rename = require('gulp-rename'); -var glob = require('glob'); -var watchify = require('watchify'); -var gulpUtil = require('gulp-util'); - -/** - * @typedef {object} dirNameFilePath - * @property {string} dirName - directory name - * @property {string} fileName - file name - */ - -/** - * get directory and file name from output path - * @param {string} outputFile - output file path - * @returns {dirNameFilePath} file directory and path - * @private - */ -function _processOutDir(outputFile) { - "use strict"; - - var pathParts = outputFile.split('/'); - var outFileName = pathParts[pathParts.length - 1]; - pathParts.splice(pathParts.length - 1, 1); - var outDir = pathParts.length === 0 ? '.' : pathParts.join('/'); - - return { dirName: outDir, fileName: outFileName }; -} - -/** - * - * @param {string} inputFile - input file set to null to bundle everything in 'test' directory - * @param {dirNameFilePath|string} outFile - output file as string or path object - * @param {boolean} [production=false] if production, minify and don't watch - * @returns {*} the stream - * @private - */ -function bundleEs2015(inputFile, outFile, production) { - "use strict"; - - if (typeof outFile == 'string') { - outFile = _processOutDir(outFile); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['exports', 'gulp', 'gulp-babel', 'babelify', 'browserify', 'vinyl-buffer', 'vinyl-source-stream', 'gulp-sourcemaps', 'gulp-minify', 'gulp-less', 'gulp-cssmin', 'gulp-rename', 'glob', 'watchify', 'gulp-util'], factory); + } else if (typeof exports !== "undefined") { + factory(exports, require('gulp'), require('gulp-babel'), require('babelify'), require('browserify'), require('vinyl-buffer'), require('vinyl-source-stream'), require('gulp-sourcemaps'), require('gulp-minify'), require('gulp-less'), require('gulp-cssmin'), require('gulp-rename'), require('glob'), require('watchify'), require('gulp-util')); + } else { + var mod = { + exports: {} + }; + factory(mod.exports, global.gulp, global.gulpBabel, global.babelify, global.browserify, global.vinylBuffer, global.vinylSourceStream, global.gulpSourcemaps, global.gulpMinify, global.gulpLess, global.gulpCssmin, global.gulpRename, global.glob, global.watchify, global.gulpUtil); + global.gulpHelpers = mod.exports; } +})(this, function (exports, gulp, babel, babelify, browserify, buffer, source, sourcemaps, minify, less, cssmin, rename, glob, watchify, gulpUtil) { + 'use strict'; - production = typeof production == 'boolean' ? production : false; - - if (inputFile.indexOf('*') > -1) { - inputFile = glob.sync(inputFile); + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.bundleEs2015 = bundleEs2015; + exports.processLessFile = processLessFile; + exports.bundleEs2015Multiple = bundleEs2015Multiple; + + + /** + * @typedef {object} dirNameFilePath + * @property {string} dirName - directory name + * @property {string} fileName - file name + */ + + /** + * get directory and file name from output path + * @param {string} outputFile - output file path + * @returns {dirNameFilePath} file directory and path + * @private + */ + function _processOutDir(outputFile) { + "use strict"; + + var pathParts = outputFile.split('/'); + var outFileName = pathParts[pathParts.length - 1]; + pathParts.splice(pathParts.length - 1, 1); + var outDir = pathParts.length === 0 ? '.' : pathParts.join('/'); + + return { dirName: outDir, fileName: outFileName }; } - var bundler = browserify({ - entries: inputFile, - cache: {}, - packageCache: {}, - debug: true - }); + /** + * + * @param {string} inputFile - input file set to null to bundle everything in 'test' directory + * @param {dirNameFilePath|string} outFile - output file as string or path object + * @param {boolean} [production=false] if production, minify and don't watch + * @returns {*} the stream + * @private + */ + function bundleEs2015(inputFile, outFile, production) { + "use strict"; + + if (typeof outFile == 'string') { + outFile = _processOutDir(outFile); + } - bundler.transform(babelify.configure({ - presets: ["es2015"], - ignore: /ol\-build\.js|jquery\.min|\/node_modules\/(?!webmapsjs\/)|\/node_modules\/webmapsjs\/(?!lib\/)/ - })); + production = typeof production == 'boolean' ? production : false; - if (!production) { - bundler = watchify(bundler); - } + if (inputFile.indexOf('*') > -1) { + inputFile = glob.sync(inputFile); + } + + var bundler = browserify({ + entries: inputFile, + cache: {}, + packageCache: {}, + debug: true + }); + + bundler.transform(babelify.configure({ + global: true, + presets: ["es2015"], + ignore: /ol\-build\.js|jquery\.min|\/node_modules\/(?!webmapsjs\/)/ + })); + + if (!production) { + bundler = watchify(bundler); + } + + function runBundle() { + var stream = bundler.bundle().on('error', function (err) { + console.error(err); + }).pipe(source(outFile.fileName)).pipe(buffer()).pipe(sourcemaps.init({ loadMaps: true })); + + if (production) { + stream = stream.pipe(minify({ + ext: { + src: '-debug.js', + min: '.js' + }, + exclude: ['tasks'], + ignoreFiles: ['.combo.js', '-min.js'] + })); + } - function runBundle() { - var stream = bundler.bundle().on('error', function (err) { - console.error(err); - }).pipe(source(outFile.fileName)).pipe(buffer()).pipe(sourcemaps.init({ loadMaps: true })); - - if (production) { - stream = stream.pipe(minify({ - ext: { - src: '-debug.js', - min: '.js' - }, - exclude: ['tasks'], - ignoreFiles: ['.combo.js', '-min.js'] - })); + return stream.pipe(sourcemaps.write('./')).pipe(gulp.dest(outFile.dirName)); } - return stream.pipe(sourcemaps.write('./')).pipe(gulp.dest(outFile.dirName)); + if (!production) { + bundler.on('update', runBundle); + bundler.on('log', gulpUtil.log); + } + + return runBundle(); } - if (!production) { - bundler.on('update', runBundle); - bundler.on('log', gulpUtil.log); + /** + * convert less file + * @param {string} inputFile - input less file + * @param {string} outputFile - output css file + * @returns {*} stream + */ + function processLessFile(inputFile, outputFile) { + "use strict"; + + var pathParts = outputFile.split('/'); + var outFileName = pathParts[pathParts.length - 1]; + pathParts.splice(pathParts.length - 1, 1); + var outDir = pathParts.length === 0 ? '.' : pathParts.join('/'); + + var fileNameParts = outFileName.split('.'); + + return gulp.src(inputFile).pipe(less().on('error', function (err) { + console.log(err); + })).pipe(cssmin().on('error', function (err) { + console.log(err); + })).pipe(rename({ + basename: fileNameParts[0], + extname: '.' + fileNameParts[1], + suffix: '.min' + })).pipe(gulp.dest(outDir)); } - return runBundle(); -} - -/** - * convert less file - * @param {string} inputFile - input less file - * @param {string} outputFile - output css file - * @returns {*} stream - */ -function processLessFile(inputFile, outputFile) { - "use strict"; - - var pathParts = outputFile.split('/'); - var outFileName = pathParts[pathParts.length - 1]; - pathParts.splice(pathParts.length - 1, 1); - var outDir = pathParts.length === 0 ? '.' : pathParts.join('/'); - - var fileNameParts = outFileName.split('.'); - - return gulp.src(inputFile).pipe(less().on('error', function (err) { - console.log(err); - })).pipe(cssmin().on('error', function (err) { - console.log(err); - })).pipe(rename({ - basename: fileNameParts[0], - extname: '.' + fileNameParts[1], - suffix: '.min' - })).pipe(gulp.dest(outDir)); -} - -/** - * make multiple bundles - * @param {Array<Array<string>>} fileArray - array with elements [input file, output file] - * @param {boolean} production - if is production - * @returns {*} output stream - */ -function bundleEs2015Multiple(fileArray, production) { - "use strict"; - - var outStream = undefined; - - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = fileArray[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var f = _step.value; - - outStream = bundleEs2015(f[0], f[1], production); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { + /** + * make multiple bundles + * @param {Array<Array<string>>} fileArray - array with elements [input file, output file] + * @param {boolean} production - if is production + * @returns {*} output stream + */ + function bundleEs2015Multiple(fileArray, production) { + "use strict"; + + var outStream = undefined; + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); + for (var _iterator = fileArray[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var f = _step.value; + + outStream = bundleEs2015(f[0], f[1], production); } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; } finally { - if (_didIteratorError) { - throw _iteratorError; + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } } } - } - return outStream; -} \ No newline at end of file + return outStream; + } +}); \ No newline at end of file diff --git a/lib/jquery-plugin/animate-buttons.js b/lib/jquery-plugin/animate-buttons.js index b92056197c680e170cdcf3a2e4e9eccb5085888f..4824f64652f0c0fc3d988e060ae7a45cd3ebb37e 100644 --- a/lib/jquery-plugin/animate-buttons.js +++ b/lib/jquery-plugin/animate-buttons.js @@ -1,252 +1,266 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); - -/** - * Created by gavorhes on 11/2/2015. - */ - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); - -var _provide = require('../util/provide'); - -var _provide2 = _interopRequireDefault(_provide); - -require('./range-change'); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var nm = (0, _provide2.default)('jQueryPlugin'); - -/** - * @callback mediaCallback - * @param {number} newValue - */ - -function timeToLocalDateString(tm) { - "use strict"; - - var d = new Date(tm); - var p1 = d.toLocaleTimeString().split(' '); - var p2 = p1[0].split(':'); - p2 = p2.slice(0, 2); - - return d.toLocaleDateString() + '<br>' + p2.join(':') + ' ' + p1[1]; -} - -var MediaControl = (function () { - function MediaControl(jQueryElement, min, max, val, step, func, playInterval, dateFormat) { - _classCallCheck(this, MediaControl); - - this._container = jQueryElement; - this._playInterval = playInterval; - this._interval = undefined; - this._func = func; - - this._dateFormat = dateFormat; - - this._currentValue = undefined; - this._min = undefined; - this._max = undefined; - this._step = undefined; - this._playing = false; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', '../util/provide', './range-change'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('../util/provide'), require('./range-change')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.provide, global.rangeChange); + global.animateButtons = mod.exports; + } +})(this, function (module, exports, _jquery, _provide) { + 'use strict'; - var htmlStr = '<span class="media-player-button media-back"></span>' + '<span class="media-player-button media-play"></span>' + '<span class="media-player-button media-pause media-disabled"></span>' + '<span class="media-player-button media-stop media-disabled" ></span>' + '<span class="media-player-button media-ahead"></span>' + '<input type="range">' + '<div class="media-control-value-label-container">' + '<span class="media-control-value-label-min"></span>' + '<span class="media-control-value-label-val"></span>' + '<span class="media-control-value-label-max"></span>' + '</div>'; + Object.defineProperty(exports, "__esModule", { + value: true + }); - this._container.append(htmlStr); + var _jquery2 = _interopRequireDefault(_jquery); - var btnPause = this._container.find('.media-pause'); - var btnPlay = this._container.find('.media-play'); - this._$btnStop = this._container.find('.media-stop'); - var btnAhead = this._container.find('.media-ahead'); - var btnBack = this._container.find('.media-back'); - this._$slider = this._container.find('input[type=range]'); + var _provide2 = _interopRequireDefault(_provide); - this._$valLabelMin = this._container.find('.media-control-value-label-min'); - this._$valLabelVal = this._container.find('.media-control-value-label-val'); - this._$valLabelMax = this._container.find('.media-control-value-label-max'); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } - this.setMinMaxValueStep(min, max, val, step); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } - var _this = this; + 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); + } + } - this._$slider.rangeChange(function (newVal, ratio, evt) { - _this.currentValue = newVal; - }, 100); + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); - btnPlay.click(function () { - var $this = (0, _jquery2.default)(this); - $this.addClass('media-disabled'); - _this._$btnStop.removeClass('media-disabled'); - btnAhead.addClass('media-locked'); - btnBack.addClass('media-locked'); - _this._$slider.prop('disabled', true); - _this._playing = true; + var nm = (0, _provide2.default)('jQueryPlugin'); - _this._interval = setInterval(function () { - _this.currentValue += _this._step; - }, _this._playInterval); - }); + /** + * @callback mediaCallback + * @param {number} newValue + */ - this._$btnStop.click(function () { - clearInterval(_this._interval); - var $this = (0, _jquery2.default)(this); - $this.addClass('media-disabled'); - btnPlay.removeClass('media-disabled'); - btnAhead.removeClass('media-locked'); - btnBack.removeClass('media-locked'); - _this._$slider.prop('disabled', false); - _this._playing = false; - }); + function timeToLocalDateString(tm) { + "use strict"; - btnAhead.click(function () { - _this.currentValue = _this.currentValue + _this._step; - }); + var d = new Date(tm); + var p1 = d.toLocaleTimeString().split(' '); + var p2 = p1[0].split(':'); + p2 = p2.slice(0, 2); - btnBack.click(function () { - _this.currentValue = _this.currentValue - _this._step; - }); + return d.toLocaleDateString() + '<br>' + p2.join(':') + ' ' + p1[1]; } - _createClass(MediaControl, [{ - key: 'stopPlaying', - value: function stopPlaying() { - if (this._playing) { - this._$btnStop.trigger('click'); - } + var MediaControl = function () { + function MediaControl(jQueryElement, min, max, val, step, func, playInterval, dateFormat) { + _classCallCheck(this, MediaControl); + + this._container = jQueryElement; + this._playInterval = playInterval; + this._interval = undefined; + this._func = func; + + this._dateFormat = dateFormat; + + this._currentValue = undefined; + this._min = undefined; + this._max = undefined; + this._step = undefined; + this._playing = false; + + var htmlStr = '<span class="media-player-button media-back"></span>' + '<span class="media-player-button media-play"></span>' + '<span class="media-player-button media-pause media-disabled"></span>' + '<span class="media-player-button media-stop media-disabled" ></span>' + '<span class="media-player-button media-ahead"></span>' + '<input type="range">' + '<div class="media-control-value-label-container">' + '<span class="media-control-value-label-min"></span>' + '<span class="media-control-value-label-val"></span>' + '<span class="media-control-value-label-max"></span>' + '</div>'; + + this._container.append(htmlStr); + + var btnPause = this._container.find('.media-pause'); + var btnPlay = this._container.find('.media-play'); + this._$btnStop = this._container.find('.media-stop'); + var btnAhead = this._container.find('.media-ahead'); + var btnBack = this._container.find('.media-back'); + this._$slider = this._container.find('input[type=range]'); + + this._$valLabelMin = this._container.find('.media-control-value-label-min'); + this._$valLabelVal = this._container.find('.media-control-value-label-val'); + this._$valLabelMax = this._container.find('.media-control-value-label-max'); + + this.setMinMaxValueStep(min, max, val, step); + + var _this = this; + + this._$slider.rangeChange(function (newVal, ratio, evt) { + _this.currentValue = newVal; + }, 100); + + btnPlay.click(function () { + var $this = (0, _jquery2.default)(this); + $this.addClass('media-disabled'); + _this._$btnStop.removeClass('media-disabled'); + btnAhead.addClass('media-locked'); + btnBack.addClass('media-locked'); + _this._$slider.prop('disabled', true); + _this._playing = true; + + _this._interval = setInterval(function () { + _this.currentValue += _this._step; + }, _this._playInterval); + }); + + this._$btnStop.click(function () { + clearInterval(_this._interval); + var $this = (0, _jquery2.default)(this); + $this.addClass('media-disabled'); + btnPlay.removeClass('media-disabled'); + btnAhead.removeClass('media-locked'); + btnBack.removeClass('media-locked'); + _this._$slider.prop('disabled', false); + _this._playing = false; + }); + + btnAhead.click(function () { + _this.currentValue = _this.currentValue + _this._step; + }); + + btnBack.click(function () { + _this.currentValue = _this.currentValue - _this._step; + }); } - }, { - key: 'setMinMaxValueStep', - - /** - * set min and max value with step - * @param {number} newMin the new min - * @param {number} newMax the new mas - * @param {number} [newValue=newMin] the value to set - * @param {number} [newStep=(newMax-newMin)/20] step value - */ - value: function setMinMaxValueStep(newMin, newMax, newValue, newStep) { - this._min = newMin; - this._max = newMax; - - newValue = typeof newValue == 'number' ? newValue : newMin; - newStep = typeof newStep == 'number' ? newStep : (newMax - newMin) / 20; - - this._currentValue = newValue; - this._step = newStep; - - this._$slider.prop('min', this.min.toString()); - this._$slider.prop('max', this.max.toString()); - this._$slider.prop('step', this.step.toString()); - this._$slider.val(this.currentValue.toString()); - - if (this._dateFormat) { - this._$valLabelMin.html(timeToLocalDateString(this._min)); - this._$valLabelVal.html(timeToLocalDateString(this.currentValue)); - this._$valLabelMax.html(timeToLocalDateString(this._max)); - } else { - this._$valLabelMin.html(this._min.toString()); - this._$valLabelVal.html(this.currentValue.toString()); - this._$valLabelMax.html(this._max.toString()); - } - } - - /** - * - * @param {mediaCallback} newFunc the callback on change - */ - }, { - key: 'playing', - get: function get() { - return this._playing; - } - }, { - key: 'min', - get: function get() { - return this._min; - } - }, { - key: 'max', - get: function get() { - return this._max; - } - }, { - key: 'step', - get: function get() { - return this._step; - } - }, { - key: 'currentValue', - get: function get() { - return this._currentValue; - }, - set: function set(newValue) { - if (newValue > this._max) { - newValue = this._min; - } else if (newValue < this._min) { - newValue = this._max; + _createClass(MediaControl, [{ + key: 'stopPlaying', + value: function stopPlaying() { + if (this._playing) { + this._$btnStop.trigger('click'); + } } - this._currentValue = newValue; - this._$slider.val(this._currentValue.toFixed(2)); - - if (this._dateFormat) { - this._$valLabelVal.html(timeToLocalDateString(this.currentValue)); - } else { - this._$valLabelVal.html(this.currentValue.toString()); + }, { + key: 'setMinMaxValueStep', + value: function setMinMaxValueStep(newMin, newMax, newValue, newStep) { + this._min = newMin; + this._max = newMax; + + newValue = typeof newValue == 'number' ? newValue : newMin; + newStep = typeof newStep == 'number' ? newStep : (newMax - newMin) / 20; + + this._currentValue = newValue; + this._step = newStep; + + this._$slider.prop('min', this.min.toString()); + this._$slider.prop('max', this.max.toString()); + this._$slider.prop('step', this.step.toString()); + this._$slider.val(this.currentValue.toString()); + + if (this._dateFormat) { + this._$valLabelMin.html(timeToLocalDateString(this._min)); + this._$valLabelVal.html(timeToLocalDateString(this.currentValue)); + this._$valLabelMax.html(timeToLocalDateString(this._max)); + } else { + this._$valLabelMin.html(this._min.toString()); + this._$valLabelVal.html(this.currentValue.toString()); + this._$valLabelMax.html(this._max.toString()); + } } - - this._func(newValue); - } - }, { - key: 'changeFunction', - set: function set(newFunc) { - this._func = newFunc; - } - }]); - - return MediaControl; -})(); - -nm.MediaControl = MediaControl; - -/** - * Adds a media control to a container - * @param {number} [min=0] the min - * @param {number} [max=100] the max - * @param {number} [val=0] the val - * @param {number} [step=1] the step - * @param {mediaCallback} [func=function (n) {console.log('default function', n);}] media change callback function - * @param {number} [playInterval=500] play interval - * @param {boolean} [dateFormat=false] date format - * @this {jQuery} - * @returns {MediaControl} the Media control object - */ -_jquery2.default.fn.mediaControl = function (min, max, val, step, func, playInterval, dateFormat) { - - min = typeof min == 'number' ? min : 0; - max = typeof max == 'number' ? max : 100; - val = typeof val == 'number' ? val : 0; - step = typeof step == 'number' ? step : 1; - func = typeof func == 'function' ? func : function (n) { - console.log('default function', n); + }, { + key: 'playing', + get: function get() { + return this._playing; + } + }, { + key: 'min', + get: function get() { + return this._min; + } + }, { + key: 'max', + get: function get() { + return this._max; + } + }, { + key: 'step', + get: function get() { + return this._step; + } + }, { + key: 'currentValue', + get: function get() { + return this._currentValue; + }, + set: function set(newValue) { + if (newValue > this._max) { + newValue = this._min; + } else if (newValue < this._min) { + newValue = this._max; + } + this._currentValue = newValue; + this._$slider.val(this._currentValue.toFixed(2)); + + if (this._dateFormat) { + this._$valLabelVal.html(timeToLocalDateString(this.currentValue)); + } else { + this._$valLabelVal.html(this.currentValue.toString()); + } + + this._func(newValue); + } + }, { + key: 'changeFunction', + set: function set(newFunc) { + this._func = newFunc; + } + }]); + + return MediaControl; + }(); + + nm.MediaControl = MediaControl; + + /** + * Adds a media control to a container + * @param {number} [min=0] the min + * @param {number} [max=100] the max + * @param {number} [val=0] the val + * @param {number} [step=1] the step + * @param {mediaCallback} [func=function (n) {console.log('default function', n);}] media change callback function + * @param {number} [playInterval=500] play interval + * @param {boolean} [dateFormat=false] date format + * @this {jQuery} + * @returns {MediaControl} the Media control object + */ + _jquery2.default.fn.mediaControl = function (min, max, val, step, func, playInterval, dateFormat) { + + min = typeof min == 'number' ? min : 0; + max = typeof max == 'number' ? max : 100; + val = typeof val == 'number' ? val : 0; + step = typeof step == 'number' ? step : 1; + func = typeof func == 'function' ? func : function (n) { + console.log('default function', n); + }; + + playInterval = typeof playInterval == 'number' ? playInterval : 500; + dateFormat = typeof dateFormat == 'boolean' ? dateFormat : false; + + this.addClass('media-control-container'); + + return new MediaControl(this, min, max, val, step, func, playInterval, dateFormat); }; - playInterval = typeof playInterval == 'number' ? playInterval : 500; - dateFormat = typeof dateFormat == 'boolean' ? dateFormat : false; - - this.addClass('media-control-container'); - - return new MediaControl(this, min, max, val, step, func, playInterval, dateFormat); -}; - -exports.default = undefined; -module.exports = exports['default']; \ No newline at end of file + exports.default = undefined; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/jquery-plugin/day-range.js b/lib/jquery-plugin/day-range.js index 1cd062750e5c14c875bd23472f0fce3f8dc41c4c..6ce95dd9b6069060fdd3ee94fdb4a513d7dcee5d 100644 --- a/lib/jquery-plugin/day-range.js +++ b/lib/jquery-plugin/day-range.js @@ -1,121 +1,153 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', '../util/provide', 'jquery-ui/datepicker'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('../util/provide'), require('jquery-ui/datepicker')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.provide, global.datepicker); + global.dayRange = mod.exports; + } +})(this, function (module, exports, _jquery, _provide) { + 'use strict'; -var _jquery = require('../jquery'); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _jquery2 = _interopRequireDefault(_jquery); + var _jquery2 = _interopRequireDefault(_jquery); -var _provide = require('../util/provide'); + var _provide2 = _interopRequireDefault(_provide); -var _provide2 = _interopRequireDefault(_provide); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + 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); + } + } -require('jquery-ui/datepicker'); + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); -var nm = (0, _provide2.default)('jQueryPlugin'); + var nm = (0, _provide2.default)('jQueryPlugin'); -var DayRange = (function () { + var DayRange = function () { - /** - * constructor for the date range - * @param {number} dayRange number of days - * @param {jQuery} jQueryRef reference to the jquery element - */ + /** + * constructor for the date range + * @param {number} dayRange number of days + * @param {jQuery} jQueryRef reference to the jquery element + */ - function DayRange(dayRange, jQueryRef) { - _classCallCheck(this, DayRange); + function DayRange(dayRange, jQueryRef) { + _classCallCheck(this, DayRange); - this._workingDayRange = dayRange - 1; + this._workingDayRange = dayRange - 1; - var pickerHtml = '<label for="start-date" style="width: 78px; display: inline-block; margin:5px;">Start Date</label>' + '<input type="text" readonly id="start-date" class="date-pick" style="width: 90px;">' + '<br><label for="end-date" style="width: 78px; display: inline-block; margin:5px;">End Date</label>' + '<input type="text" readonly id="end-date" class="date-pick" style="width: 90px;">'; + var pickerHtml = '<label for="start-date" style="width: 78px; display: inline-block; margin:5px;">Start Date</label>' + '<input type="text" readonly id="start-date" class="date-pick" style="width: 90px;">' + '<br><label for="end-date" style="width: 78px; display: inline-block; margin:5px;">End Date</label>' + '<input type="text" readonly id="end-date" class="date-pick" style="width: 90px;">'; - jQueryRef.append(pickerHtml); + jQueryRef.append(pickerHtml); - this._$startDate = (0, _jquery2.default)('#start-date'); - this._$endDate = (0, _jquery2.default)('#end-date'); + this._$startDate = (0, _jquery2.default)('#start-date'); + this._$endDate = (0, _jquery2.default)('#end-date'); - this._$startDate.datepicker(); - this._$endDate.datepicker(); + this._$startDate.datepicker(); + this._$endDate.datepicker(); - this._startDate = null; - this._endDate = null; + this._startDate = null; + this._endDate = null; - var dte1 = new Date(); - dte1.setHours(0, 0, 0, 0); - var dte2 = new Date(dte1.getTime()); - dte2.setDate(dte2.getDate() + dayRange); - dte2.setHours(23, 59, 59, 0); - this._maxDateRange = dte2 - dte1; + var dte1 = new Date(); + dte1.setHours(0, 0, 0, 0); + var dte2 = new Date(dte1.getTime()); + dte2.setDate(dte2.getDate() + dayRange); + dte2.setHours(23, 59, 59, 0); + this._maxDateRange = dte2 - dte1; - var _this = this; + var _this = this; - //add event listeners - this._$startDate.change(function () { - _this.startDate = this.value; - }); + //add event listeners + this._$startDate.change(function () { + _this.startDate = this.value; + }); - this._$endDate.change(function () { - _this.endDate = this.value; - }); + this._$endDate.change(function () { + _this.endDate = this.value; + }); - // initialize - this.endDate = new Date().getTime(); - } + // initialize + this.endDate = new Date().getTime(); + } - _createClass(DayRange, [{ - key: 'startDate', - get: function get() { - return this._startDate; - }, - set: function set(val) { - this._startDate = new Date(val); - this._startDate.setHours(0, 0, 0, 0); - this._$startDate.val(this._startDate.toLocaleDateString()); - - if (this.endDate == null || this._endDate - this._startDate > this._maxDateRange || this._endDate.getTime() - this._startDate.getTime() < 24 * 60 * 60 * 1000) { - var tmpDate = new Date(this._startDate.getTime()); - tmpDate.setDate(tmpDate.getDate() + this._workingDayRange); - this.endDate = tmpDate.getTime(); + _createClass(DayRange, [{ + key: 'startDate', + get: function get() { + return this._startDate; + }, + set: function set(val) { + this._startDate = new Date(val); + this._startDate.setHours(0, 0, 0, 0); + this._$startDate.val(this._startDate.toLocaleDateString()); + + if (this.endDate == null || this._endDate - this._startDate > this._maxDateRange || this._endDate.getTime() - this._startDate.getTime() < 24 * 60 * 60 * 1000) { + var tmpDate = new Date(this._startDate.getTime()); + tmpDate.setDate(tmpDate.getDate() + this._workingDayRange); + this.endDate = tmpDate.getTime(); + } } - } - }, { - key: 'endDate', - get: function get() { - return this._endDate; - }, - set: function set(val) { - this._endDate = new Date(val); - this._endDate.setHours(23, 59, 59, 0); - this._$endDate.val(this._endDate.toLocaleDateString()); - if (this._startDate == null || this._endDate - this.startDate > this._maxDateRange || this._endDate.getTime() - this._startDate.getTime() < 24 * 60 * 60 * 1000) { - var tmpDate = new Date(this._endDate.getTime()); - tmpDate.setDate(tmpDate.getDate() - this._workingDayRange); - this.startDate = tmpDate.getTime(); + }, { + key: 'endDate', + get: function get() { + return this._endDate; + }, + set: function set(val) { + this._endDate = new Date(val); + this._endDate.setHours(23, 59, 59, 0); + this._$endDate.val(this._endDate.toLocaleDateString()); + if (this._startDate == null || this._endDate - this.startDate > this._maxDateRange || this._endDate.getTime() - this._startDate.getTime() < 24 * 60 * 60 * 1000) { + var tmpDate = new Date(this._endDate.getTime()); + tmpDate.setDate(tmpDate.getDate() - this._workingDayRange); + this.startDate = tmpDate.getTime(); + } } - } - }]); + }]); - return DayRange; -})(); + return DayRange; + }(); -nm.DayRange = DayRange; + nm.DayRange = DayRange; -/** - * Adds day range control - * @param {number} dayRange the number of days - * @returns {DayRange} the day range object - */ -_jquery2.default.fn.dayRange = function (dayRange) { - return new DayRange(dayRange, this); -}; + /** + * Adds day range control + * @param {number} dayRange the number of days + * @returns {DayRange} the day range object + */ + _jquery2.default.fn.dayRange = function (dayRange) { + return new DayRange(dayRange, this); + }; -exports.default = undefined; -module.exports = exports['default']; \ No newline at end of file + exports.default = undefined; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/jquery-plugin/range-change.js b/lib/jquery-plugin/range-change.js index 648a43946683a82e5a6d75a65b0778925182d926..93ab14e014d1454669dc70727a420bbeb7c029d5 100644 --- a/lib/jquery-plugin/range-change.js +++ b/lib/jquery-plugin/range-change.js @@ -1,135 +1,151 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var mouseIn = false; - -/** - * Created by gavorhes on 11/2/2015. - */ - -var mouseDown = false; -var timeout = null; -var dragged = false; -var lastVal = undefined; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery); + global.rangeChange = mod.exports; + } +})(this, function (module, exports, _jquery) { + 'use strict'; -function triggerCallback(callback, evt) { - "use strict"; + Object.defineProperty(exports, "__esModule", { + value: true + }); - var val = parseFloat(this.value); - var min = parseFloat(this.min); - var max = parseFloat(this.max); - var step = parseFloat(this.step); + var _jquery2 = _interopRequireDefault(_jquery); - if (max - val < step) { - val = max; + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; } - var percent = (val - min) / (max - min); + var mouseIn = false; - if (typeof lastVal == 'number' && val == lastVal) { - return; - } - lastVal = val; - callback(val, percent, evt); -} - -/** - * callback on range change interaction, context of this is the firing dom element - * @callback rangeChangeCallback - * @param {number} newValue - * @param {number} ratio value from 0 to 1 relative of the value to the min and max - * @param {object} evt - */ - -/** - * Add a variety of listeners for range inputs applied to a common callback - * @param {rangeChangeCallback} callback - the callback - * @param {number} [changeTimeout=75] before the callback is called - * @this {jQuery} - * @returns {jQuery} the jQuery object - */ -_jquery2.default.fn.rangeChange = function (callback, changeTimeout) { - - changeTimeout = typeof changeTimeout == 'number' ? changeTimeout : 75; - - this.mouseenter(function () { - mouseIn = true; - }); + /** + * Created by gavorhes on 11/2/2015. + */ - this.mouseleave(function () { - mouseIn = false; - mouseDown = false; - }); + var mouseDown = false; + var timeout = null; + var dragged = false; + var lastVal = void 0; - this.mousedown(function () { - mouseDown = true; - }); + function triggerCallback(callback, evt) { + "use strict"; - this.mouseup(function () { - mouseDown = false; - }); + var val = parseFloat(this.value); + var min = parseFloat(this.min); + var max = parseFloat(this.max); + var step = parseFloat(this.step); - this.mousemove( - /** - * - * @param {object} evt - event properties - * @this {HTMLElement} - */ - function (evt) { - if (!(mouseIn && mouseDown)) { - return; + if (max - val < step) { + val = max; } - dragged = true; + var percent = (val - min) / (max - min); - if (lastVal == this['value']) { + if (typeof lastVal == 'number' && val == lastVal) { return; } - lastVal = this['value']; - - if (timeout != null) { - clearTimeout(timeout); - } - - var _this = this; + lastVal = val; + callback(val, percent, evt); + } - timeout = setTimeout(function () { - triggerCallback.call(_this, callback, evt); - timeout = null; - }, changeTimeout); - }); + /** + * callback on range change interaction, context of this is the firing dom element + * @callback rangeChangeCallback + * @param {number} newValue + * @param {number} ratio value from 0 to 1 relative of the value to the min and max + * @param {object} evt + */ - this.keyup( /** - * - * @param {object} evt - event properties + * Add a variety of listeners for range inputs applied to a common callback + * @param {rangeChangeCallback} callback - the callback + * @param {number} [changeTimeout=75] before the callback is called + * @this {jQuery} + * @returns {jQuery} the jQuery object */ - function (evt) { - if (evt.keyCode == 37 || evt.keyCode == 39) { + _jquery2.default.fn.rangeChange = function (callback, changeTimeout) { + + changeTimeout = typeof changeTimeout == 'number' ? changeTimeout : 75; + + this.mouseenter(function () { + mouseIn = true; + }); + + this.mouseleave(function () { + mouseIn = false; + mouseDown = false; + }); + + this.mousedown(function () { + mouseDown = true; + }); + + this.mouseup(function () { + mouseDown = false; + }); + + this.mousemove( + /** + * + * @param {object} evt - event properties + * @this {HTMLElement} + */ + function (evt) { + if (!(mouseIn && mouseDown)) { + return; + } + + dragged = true; + + if (lastVal == this['value']) { + return; + } + lastVal = this['value']; + + if (timeout != null) { + clearTimeout(timeout); + } + + var _this = this; + + timeout = setTimeout(function () { + triggerCallback.call(_this, callback, evt); + timeout = null; + }, changeTimeout); + }); + + this.keyup( + /** + * + * @param {object} evt - event properties + */ + function (evt) { + if (evt.keyCode == 37 || evt.keyCode == 39) { + triggerCallback.call(this, callback, evt); + } + }); + + this.change(function (evt) { + if (dragged) { + dragged = false; + + return; + } triggerCallback.call(this, callback, evt); - } - }); - - this.change(function (evt) { - if (dragged) { - dragged = false; - - return; - } - triggerCallback.call(this, callback, evt); - }); + }); - return this; -}; + return this; + }; -exports.default = undefined; -module.exports = exports['default']; \ No newline at end of file + exports.default = undefined; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/jquery.js b/lib/jquery.js index 5ee1bac0819834de38de57c1da223fee25cdbc43..0d072422fac1b63ee8d920ab3239f3c344aa1794 100644 --- a/lib/jquery.js +++ b/lib/jquery.js @@ -1,12 +1,26 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -/** - * Created by gavorhes on 5/3/2016. - */ -global.jQuery = require('jquery'); - -exports.default = global.jQuery; -module.exports = exports['default']; \ No newline at end of file +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', 'jquery'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('jquery')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery); + global.jquery = mod.exports; + } +})(this, function (module, exports, $) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + + global.$ = $; + global.jQuery = $; + + exports.default = $; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/layers/LayerBase.js b/lib/layers/LayerBase.js index 3742b68adf19864b0d9040155df8cfb9d2060b7b..00c86f5868c3cfca88805317e65a91a0fabb7c74 100644 --- a/lib/layers/LayerBase.js +++ b/lib/layers/LayerBase.js @@ -1,451 +1,361 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); - -var _makeGuid = require('../util/makeGuid'); - -var _makeGuid2 = _interopRequireDefault(_makeGuid); - -var _zoomResolutionConvert = require('../olHelpers/zoomResolutionConvert'); - -var zoomResolutionConvert = _interopRequireWildcard(_zoomResolutionConvert); - -var _provide = require('../util/provide'); - -var _provide2 = _interopRequireDefault(_provide); - -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', '../util/makeGuid', '../olHelpers/zoomResolutionConvert', '../util/provide'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('../util/makeGuid'), require('../olHelpers/zoomResolutionConvert'), require('../util/provide')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.makeGuid, global.zoomResolutionConvert, global.provide); + global.LayerBase = mod.exports; + } +})(this, function (module, exports, _jquery, _makeGuid, _zoomResolutionConvert, _provide) { + 'use strict'; -function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } + Object.defineProperty(exports, "__esModule", { + value: true + }); -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + var _jquery2 = _interopRequireDefault(_jquery); -var nm = (0, _provide2.default)('layers'); + var _makeGuid2 = _interopRequireDefault(_makeGuid); -/** - * The base layer class - * @abstract - */ + var zoomResolutionConvert = _interopRequireWildcard(_zoomResolutionConvert); -var LayerBase = (function () { - /** - * The base layer for all others - * @param {string} url - url for source - * @param {object} options - config - * @param {string} [options.id=makeGuid()] - layer id - * @param {string} [options.name=Unnamed Layer] - layer name - * @param {number} [options.opacity=1] - opacity - * @param {boolean} [options.visible=true] - default visible - * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 - * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 - * @param {object} [options.params={}] - the get parameters to include to retrieve the layer - * @param {number} [options.zIndex=0] - the z index for the layer - * @param {function} [options.loadCallback] - function to call on load, context this is the layer object - * @param {boolean} [options.legendCollapse=false] - if the legend item should be initially collapsed - * @param {boolean} [options.legendCheckbox=true] - if the legend item should have a checkbox for visibility - * @param {boolean} [options.legendContent=undefined] - additional content to add to the legend - */ + var _provide2 = _interopRequireDefault(_provide); - function LayerBase(url, options) { - _classCallCheck(this, LayerBase); + function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = {}; - options = options || {}; + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; + } + } - if (typeof url !== 'string') { - throw 'Invalid URL'; + newObj.default = obj; + return newObj; } - this._url = url; + } - this._params = _typeof(options.params) == 'object' ? options.params : {}; - this._legendCollapse = typeof options.legendCollapse == 'boolean' ? options.legendCollapse : false; - this._legendCheckbox = typeof options.legendCheckbox == 'boolean' ? options.legendCheckbox : true; + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } - this.id = options.id || (0, _makeGuid2.default)(); - this._name = options.name || 'Unnamed Layer'; - this.animate = false; - this._opacity = typeof options.opacity == 'number' ? options.opacity : 1; + 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; + }; - if (this._opacity > 1) { - this._opacity = 1; - } else if (this._opacity < 0) { - this._opacity = 0; + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); } + } - this._visible = typeof options.visible === 'boolean' ? options.visible : true; - - this._source = undefined; - this.olLayer = undefined; - this._loaded = false; - - this._maxResolution = zoomResolutionConvert.zoomToResolution(options.minZoom); - if (typeof this._maxResolution !== 'undefined') { - this._maxResolution += 0.00001; + 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); + } } - this._minResolution = zoomResolutionConvert.zoomToResolution(options.maxZoom); - - this._minZoom = typeof options.minZoom == 'number' ? options.minZoom : undefined; - this._maxZoom = typeof options.maxZoom == 'number' ? options.maxZoom : undefined; - this._zIndex = typeof options.zIndex == 'number' ? options.zIndex : 0; - this.loadCallback = typeof options.loadCallback == 'function' ? options.loadCallback : function () {}; + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); - this._legendContent = ''; - - if (this._legendCheckbox) { - this._legendContent += '<input type="checkbox" ' + (this.visible ? 'checked' : '') + ' ' + ('class="legend-check" id="' + this.id + '-legend-layer-check"><span></span>'); - this._legendContent += '<label for="' + this.id + '-legend-layer-check" class="legend-layer-name">' + this.name + '</label>'; - } else { - this._legendContent += '<label class="legend-layer-name">' + this.name + '</label>'; - } - - this._$legendDiv = null; - this._applyCollapseCalled = false; - this._addLegendContent(typeof options.legendContent === 'string' ? options.legendContent : undefined); - } + var nm = (0, _provide2.default)('layers'); /** - * base load function, sets _loaded = true if it is not already - * @protected - * @returns {boolean} if already loaded + * The base layer class + * @abstract */ - _createClass(LayerBase, [{ - key: '_load', - value: function _load() { - if (this.loaded == true) { - return true; - } else { - this._loaded = true; - - return false; - } - } - + var LayerBase = function () { /** - * Get the legend html, be sure to only add to the DOM once - * @returns {string} html for layer wrapped in a div + * The base layer for all others + * @param {string} url - url for source + * @param {object} options - config + * @param {string} [options.id=makeGuid()] - layer id + * @param {string} [options.name=Unnamed Layer] - layer name + * @param {number} [options.opacity=1] - opacity + * @param {boolean} [options.visible=true] - default visible + * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 + * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 + * @param {object} [options.params={}] - the get parameters to include to retrieve the layer + * @param {number} [options.zIndex=0] - the z index for the layer + * @param {function} [options.loadCallback] - function to call on load, context this is the layer object + * @param {boolean} [options.legendCollapse=false] - if the legend item should be initially collapsed + * @param {boolean} [options.legendCheckbox=true] - if the legend item should have a checkbox for visibility + * @param {boolean} [options.legendContent=undefined] - additional content to add to the legend */ - }, { - key: 'getLegendDiv', - value: function getLegendDiv() { - return '<div class="legend-layer-div" id="' + this.id + '-legend-layer-div">' + this._legendContent + '</div>'; - } - - /** - * - * @param {string|undefined} additionalContent - additional content to add to legend - * @private - */ + function LayerBase(url, options) { + _classCallCheck(this, LayerBase); - }, { - key: '_addLegendContent', - value: function _addLegendContent(additionalContent) { - additionalContent = typeof additionalContent == 'string' ? additionalContent : ''; + options = options || {}; - var addCollapse = additionalContent.indexOf('<ul>') > -1; - - if (addCollapse) { - additionalContent = '<span class="legend-items-expander" title="Expand/Collapse">▼</span>' + additionalContent; + if (typeof url !== 'string') { + throw 'Invalid URL'; } + this._url = url; - this._legendContent += additionalContent; + this._params = _typeof(options.params) == 'object' ? options.params : {}; + this._legendCollapse = typeof options.legendCollapse == 'boolean' ? options.legendCollapse : false; + this._legendCheckbox = typeof options.legendCheckbox == 'boolean' ? options.legendCheckbox : true; - this._$legendDiv = (0, _jquery2.default)('#' + this.id + '-legend-layer-div'); + this.id = options.id || (0, _makeGuid2.default)(); + this._name = options.name || 'Unnamed Layer'; + this.animate = false; + this._opacity = typeof options.opacity == 'number' ? options.opacity : 1; - if (this._$legendDiv.length > 0) { - this._$legendDiv.append(additionalContent); - this.applyCollapse(); + if (this._opacity > 1) { + this._opacity = 1; + } else if (this._opacity < 0) { + this._opacity = 0; } - } - /** - * add additional content to the legend - * @param {string} [additionalContent=] - additonal content to add - */ + this._visible = typeof options.visible === 'boolean' ? options.visible : true; - }, { - key: 'addLegendContent', - value: function addLegendContent(additionalContent) { - this._addLegendContent(additionalContent); - } - }, { - key: 'applyCollapse', - value: function applyCollapse() { - if (this._applyCollapseCalled) { - console.log('collapse already applied'); + this._source = undefined; + this.olLayer = undefined; + this._loaded = false; - return undefined; + this._maxResolution = zoomResolutionConvert.zoomToResolution(options.minZoom); + if (typeof this._maxResolution !== 'undefined') { + this._maxResolution += 0.00001; } + this._minResolution = zoomResolutionConvert.zoomToResolution(options.maxZoom); - this._$legendDiv = (0, _jquery2.default)('#' + this.id + '-legend-layer-div'); + this._minZoom = typeof options.minZoom == 'number' ? options.minZoom : undefined; + this._maxZoom = typeof options.maxZoom == 'number' ? options.maxZoom : undefined; + this._zIndex = typeof options.zIndex == 'number' ? options.zIndex : 0; - if (this._$legendDiv.length > 0) { + this.loadCallback = typeof options.loadCallback == 'function' ? options.loadCallback : function () {}; - var $expander = this._$legendDiv.find('.legend-items-expander'); - - if ($expander.length > 0) { - this._applyCollapseCalled = true; - - $expander.click(function () { - var $this = (0, _jquery2.default)(this); - - $this.siblings('ul').slideToggle(); - - if ($this.hasClass('legend-layer-group-collapsed')) { - $this.removeClass('legend-layer-group-collapsed'); - $this.html('▼'); - } else { - $this.addClass('legend-layer-group-collapsed'); - $this.html('▶'); - } - }); + this._legendContent = ''; - if (this._legendCollapse) { - $expander.trigger('click'); - } - } - } - } - - /** - * trick to refresh the layer - */ - - }, { - key: 'refresh', - value: function refresh() { - if (this.source) { - this.source.refresh(); - //let src = this.source; - //this.olLayer.setSource(undefined); - //this.olLayer.setSource(src); + if (this._legendCheckbox) { + this._legendContent += '<input type="checkbox" ' + (this.visible ? 'checked' : '') + ' ' + ('class="legend-check" id="' + this.id + '-legend-layer-check"><span></span>'); + this._legendContent += '<label for="' + this.id + '-legend-layer-check" class="legend-layer-name">' + this.name + '</label>'; + } else { + this._legendContent += '<label class="legend-layer-name">' + this.name + '</label>'; } - } - /** - * get the legend content - * @type {string} - */ - - }, { - key: 'legendContent', - get: function get() { - return this._legendContent; + this._$legendDiv = null; + this._applyCollapseCalled = false; + this._addLegendContent(typeof options.legendContent === 'string' ? options.legendContent : undefined); } /** - * set the legend content directly - * @param {string} newVal - new content + * base load function, sets _loaded = true if it is not already * @protected - */ - , - set: function set(newVal) { - this._legendContent = newVal; - } - - /** - * get the map get params - * @type {object} - */ - - }, { - key: 'params', - get: function get() { - return this._params; - } - - /** - * set the map get params - * @param {object} newParams - new get params - * @protected - */ - , - set: function set(newParams) { - this._params = newParams; - } - - /** - * get the minimum resolution - * @type {number|*} - */ - - }, { - key: 'minResolution', - get: function get() { - return this._minResolution; - } - - /** - * get the maximum resolution - * @type {number|*} + * @returns {boolean} if already loaded */ - }, { - key: 'maxResolution', - get: function get() { - return this._maxResolution; - } - /** - * get min zoom - * @type {number|*} - */ + _createClass(LayerBase, [{ + key: '_load', + value: function _load() { + if (this.loaded == true) { + return true; + } else { + this._loaded = true; - }, { - key: 'minZoom', - get: function get() { - return this._minZoom; - } + return false; + } + } + }, { + key: 'getLegendDiv', + value: function getLegendDiv() { + return '<div class="legend-layer-div" id="' + this.id + '-legend-layer-div">' + this._legendContent + '</div>'; + } + }, { + key: '_addLegendContent', + value: function _addLegendContent(additionalContent) { + additionalContent = typeof additionalContent == 'string' ? additionalContent : ''; - /** - * get max zoom - * @type {number|*} - */ + var addCollapse = additionalContent.indexOf('<ul>') > -1; - }, { - key: 'maxZoom', - get: function get() { - return this._maxZoom; - } + if (addCollapse) { + additionalContent = '<span class="legend-items-expander" title="Expand/Collapse">▼</span>' + additionalContent; + } - /** - * get the url - * @type {string} - */ + this._legendContent += additionalContent; - }, { - key: 'url', - get: function get() { - return this._url; - } + this._$legendDiv = (0, _jquery2.default)('#' + this.id + '-legend-layer-div'); - /** - * Get the layer visibility - * @type {boolean} - */ - - }, { - key: 'visible', - get: function get() { - return this._visible; - } - - /** - * Set the layer visibility - * @param {boolean} visibility - layer visibility - */ - , - set: function set(visibility) { - this._visible = visibility; - if (this.olLayer) { - this.olLayer.setVisible(this._visible); - if (visibility && !this._loaded) { - this._load(); + if (this._$legendDiv.length > 0) { + this._$legendDiv.append(additionalContent); + this.applyCollapse(); } } - } - - /** - * Get the layer opacity - * @type {number} - */ - - }, { - key: 'opacity', - get: function get() { - return this._opacity; - } - - /** - * Set the layer opacity - * @param {number} opacity - layer opacity - */ - , - set: function set(opacity) { - this._opacity = opacity; - if (this.olLayer) { - this.olLayer.setOpacity(this._opacity); + }, { + key: 'addLegendContent', + value: function addLegendContent(additionalContent) { + this._addLegendContent(additionalContent); } - } + }, { + key: 'applyCollapse', + value: function applyCollapse() { + if (this._applyCollapseCalled) { + console.log('collapse already applied'); - /** - * Get the layer name - * @type {string} - */ - - }, { - key: 'name', - get: function get() { - return this._name; - } + return undefined; + } - /** - * set the layer name - * @param {string} newName - the new name - */ - , - set: function set(newName) { - this._name = newName; - } + this._$legendDiv = (0, _jquery2.default)('#' + this.id + '-legend-layer-div'); - /** - * Check if the layer is loaded - * @type {boolean} - */ + if (this._$legendDiv.length > 0) { - }, { - key: 'loaded', - get: function get() { - return this._loaded; - } + var $expander = this._$legendDiv.find('.legend-items-expander'); - /** - * get the layer source - * @type {*} - */ + if ($expander.length > 0) { + this._applyCollapseCalled = true; - }, { - key: 'source', - get: function get() { - return this._source; - } + $expander.click(function () { + var $this = (0, _jquery2.default)(this); - /** - * get the z index - * @type {number} - */ + $this.siblings('ul').slideToggle(); - }, { - key: 'zIndex', - get: function get() { - return this._zIndex; - } + if ($this.hasClass('legend-layer-group-collapsed')) { + $this.removeClass('legend-layer-group-collapsed'); + $this.html('▼'); + } else { + $this.addClass('legend-layer-group-collapsed'); + $this.html('▶'); + } + }); - /** - * set the z index - * @param {number} newZ - new Z index - */ - , - set: function set(newZ) { - this._zIndex = newZ; - this.olLayer.setZIndex(this.zIndex); - } - }]); + if (this._legendCollapse) { + $expander.trigger('click'); + } + } + } + } + }, { + key: 'refresh', + value: function refresh() { + if (this.source) { + this.source.refresh(); + //let src = this.source; + //this.olLayer.setSource(undefined); + //this.olLayer.setSource(src); + } + } + }, { + key: 'legendContent', + get: function get() { + return this._legendContent; + }, + set: function set(newVal) { + this._legendContent = newVal; + } + }, { + key: 'params', + get: function get() { + return this._params; + }, + set: function set(newParams) { + this._params = newParams; + } + }, { + key: 'minResolution', + get: function get() { + return this._minResolution; + } + }, { + key: 'maxResolution', + get: function get() { + return this._maxResolution; + } + }, { + key: 'minZoom', + get: function get() { + return this._minZoom; + } + }, { + key: 'maxZoom', + get: function get() { + return this._maxZoom; + } + }, { + key: 'url', + get: function get() { + return this._url; + } + }, { + key: 'visible', + get: function get() { + return this._visible; + }, + set: function set(visibility) { + this._visible = visibility; + if (this.olLayer) { + this.olLayer.setVisible(this._visible); + if (visibility && !this._loaded) { + this._load(); + } + } + } + }, { + key: 'opacity', + get: function get() { + return this._opacity; + }, + set: function set(opacity) { + this._opacity = opacity; + if (this.olLayer) { + this.olLayer.setOpacity(this._opacity); + } + } + }, { + key: 'name', + get: function get() { + return this._name; + }, + set: function set(newName) { + this._name = newName; + } + }, { + key: 'loaded', + get: function get() { + return this._loaded; + } + }, { + key: 'source', + get: function get() { + return this._source; + } + }, { + key: 'zIndex', + get: function get() { + return this._zIndex; + }, + set: function set(newZ) { + this._zIndex = newZ; + this.olLayer.setZIndex(this.zIndex); + } + }]); - return LayerBase; -})(); + return LayerBase; + }(); -nm.LayerBase = LayerBase; -exports.default = LayerBase; -module.exports = exports['default']; \ No newline at end of file + nm.LayerBase = LayerBase; + exports.default = LayerBase; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/layers/LayerBaseVector.js b/lib/layers/LayerBaseVector.js index e1f95dd1f3279ac65a628f60ef1922a4f38f69c5..a93f0a8bf368784df65ee3a788b92d70f2847bd5 100644 --- a/lib/layers/LayerBaseVector.js +++ b/lib/layers/LayerBaseVector.js @@ -1,360 +1,353 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); - -var _set = function set(object, property, value, receiver) { var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent !== null) { set(parent, property, value, receiver); } } else if ("value" in desc && desc.writable) { desc.value = value; } else { var setter = desc.set; if (setter !== undefined) { setter.call(receiver, value); } } return value; }; - -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); - -var _LayerBase2 = require('./LayerBase'); - -var _LayerBase3 = _interopRequireDefault(_LayerBase2); - -var _mapMove = require('../olHelpers/mapMove'); - -var _mapMove2 = _interopRequireDefault(_mapMove); - -var _provide = require('../util/provide'); - -var _provide2 = _interopRequireDefault(_provide); - -var _ol = require('../ol/ol'); - -var _ol2 = _interopRequireDefault(_ol); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } - -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - -var nm = (0, _provide2.default)('layers'); - -/** - * The make mapMoveGetParams function takes the extent and the zoom level - * context is 'this' object, probably want to do something with this.mapMoveParams - * @callback mapMoveMakeGetParams - * @param {LayerBaseVector} lyr - * @param {object} extent - * @param {number} extent.minX - * @param {number} extent.minY - * @param {number} extent.maxX - * @param {number} extent.maxY - * @param {number} zoomLevel - */ - -/** - * The Vector layer base - * @augments LayerBase - * @abstract - */ +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', './LayerBase', '../olHelpers/mapMove', '../util/provide', '../ol/ol'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('./LayerBase'), require('../olHelpers/mapMove'), require('../util/provide'), require('../ol/ol')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.LayerBase, global.mapMove, global.provide, global.ol); + global.LayerBaseVector = mod.exports; + } +})(this, function (module, exports, _jquery, _LayerBase2, _mapMove, _provide, _ol) { + 'use strict'; -var LayerBaseVector = (function (_LayerBase) { - _inherits(LayerBaseVector, _LayerBase); + Object.defineProperty(exports, "__esModule", { + value: true + }); - /** - * The base vector layer - * @param {string} url - pass an empty string to prevent default load and add from a json source - * @param {object} options - config - * @param {string} [options.id] - layer id - * @param {string} [options.name=Unnamed Layer] - layer name - * @param {number} [options.opacity=1] - opacity - * @param {boolean} [options.visible=true] - default visible - * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 - * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 - * @param {object} [options.params={}] the get parameters to include to retrieve the layer - * @param {number} [options.zIndex=0] the z index for the layer - * @param {function} [options.loadCallback] function to call on load, context this is the layer object - * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed - * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility - * @param {boolean} [options.legendContent] additional content to add to the legend - * - * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible - * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined - * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move - * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called - * @param {mapMoveMakeGetParams} [options.mapMoveMakeGetParams=function(lyr, extent, zoomLevel){}] function to create additional map move params - * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages - * - */ + var _jquery2 = _interopRequireDefault(_jquery); - function LayerBaseVector(url, options) { - _classCallCheck(this, LayerBaseVector); + var _LayerBase3 = _interopRequireDefault(_LayerBase2); - //prevent regular load if no url has been provided + var _mapMove2 = _interopRequireDefault(_mapMove); - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerBaseVector).call(this, url, options)); + var _provide2 = _interopRequireDefault(_provide); - if (_this.url.trim() == '') { - _this._loaded = true; - } + var _ol2 = _interopRequireDefault(_ol); - _this._style = typeof options.style == 'undefined' ? undefined : options.style; + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } - if (_this.visible) { - _this._autoLoad = true; - } else { - _this._autoLoad = typeof options['autoLoad'] == 'boolean' ? options['autoLoad'] : false; + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); } + } - _this._onDemand = typeof options.onDemand == 'boolean' ? options.onDemand : false; - _this._onDemandDelay = typeof options.onDemandDelay == 'number' ? options.onDemandDelay : 300; - - if (options.mapMoveObj) { - _this._mapMove = options.mapMoveObj; - } else { - _this._mapMove = _this._onDemand ? _mapMove2.default : undefined; + 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); + } } - _this._mapMoveMakeGetParams = typeof options.mapMoveMakeGetParams == 'function' ? options.mapMoveMakeGetParams : function (lyr, extent, zoomLevel) { - return {}; + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; }; + }(); - if (_this._onDemand) { - _this._loaded = true; - _this._mapMoveParams = {}; - _this._mapMove.checkInit(); - _this._mapMove.addVectorLayer(_this); + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } - _this._source = new _ol2.default.source.Vector(); - - /** - * - * @type {ol.layer.Vector|ol.layer.Base} - */ - _this.olLayer = new _ol2.default.layer.Vector({ - source: _this._source, - visible: _this.visible, - style: _this.style, - minResolution: _this._minResolution, - maxResolution: _this._maxResolution, - zIndex: _this._zIndex - }); - return _this; + return call && (typeof call === "object" || typeof call === "function") ? call : self; } - /** - * dummy to be overridden - * @param {object} featureCollection - geojson or esrijson object - */ - - _createClass(LayerBaseVector, [{ - key: 'addFeatures', - value: function addFeatures(featureCollection) { - console.log('Layer vector base addFeatures is a placeholder and does nothing'); - } + var _set = function set(object, property, value, receiver) { + var desc = Object.getOwnPropertyDescriptor(object, property); - /** - * Before call to map move callback, can prevent call by returning false - * @param {number} zoom - zoom level - * @param {string} [evtType=undefined] undefined for initial load, otherwise one of 'change:center', 'change:resolution' - * @returns {boolean} if the call should proceed - */ + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); - }, { - key: 'mapMoveBefore', - value: function mapMoveBefore(zoom, evtType) { - if (this.minZoom !== undefined) { - if (zoom < this.minZoom) { - return false; - } + if (parent !== null) { + set(parent, property, value, receiver); } + } else if ("value" in desc && desc.writable) { + desc.value = value; + } else { + var setter = desc.set; - if (this.maxZoom !== undefined) { - if (zoom > this.maxZoom) { - return false; - } + if (setter !== undefined) { + setter.call(receiver, value); } - - return this.visible; } - /** - * callback to generate the parameters passed in the get request - * @param {object} extent - extent object - * @param {number} extent.minX - minX - * @param {number} extent.minY - minY - * @param {number} extent.maxX - maxX - * @param {number} extent.maxY - maxY - * @param {number} zoomLevel - zoom level - */ + return value; + }; - }, { - key: 'mapMoveMakeGetParams', - value: function mapMoveMakeGetParams(extent, zoomLevel) { - this._mapMoveParams = {}; - _jquery2.default.extend(this._mapMoveParams, this.params); - _jquery2.default.extend(this._mapMoveParams, this._mapMoveMakeGetParams(this, extent, zoomLevel)); - } + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); - /** - * callback function on map move - * @param {object} d - the json response - */ + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); + + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; - }, { - key: 'mapMoveCallback', - value: function mapMoveCallback(d) { - if (this.source) { - this._source.clear(); + if (getter === undefined) { + return undefined; } + + return getter.call(receiver); } + }; - /** - * clear features in the layer - */ + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } - }, { - key: 'clear', - value: function clear() { - if (this._source) { - this._source.clear(); + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true } - } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } - /** - * get on demand delay in miliseconds - * @type {number|*} - */ + var nm = (0, _provide2.default)('layers'); - }, { - key: 'onDemandDelay', - get: function get() { - return this._onDemandDelay; - } + /** + * The make mapMoveGetParams function takes the extent and the zoom level + * context is 'this' object, probably want to do something with this.mapMoveParams + * @callback mapMoveMakeGetParams + * @param {LayerBaseVector} lyr + * @param {object} extent + * @param {number} extent.minX + * @param {number} extent.minY + * @param {number} extent.maxX + * @param {number} extent.maxY + * @param {number} zoomLevel + */ - /** - * get if the layer is autoloaded - * @type {boolean} - */ + /** + * The Vector layer base + * @augments LayerBase + * @abstract + */ - }, { - key: 'autoLoad', - get: function get() { - return this._autoLoad; - } + var LayerBaseVector = function (_LayerBase) { + _inherits(LayerBaseVector, _LayerBase); /** - * get the style definition - * @type {ol.Style|styleFunc} + * The base vector layer + * @param {string} url - pass an empty string to prevent default load and add from a json source + * @param {object} options - config + * @param {string} [options.id] - layer id + * @param {string} [options.name=Unnamed Layer] - layer name + * @param {number} [options.opacity=1] - opacity + * @param {boolean} [options.visible=true] - default visible + * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 + * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 + * @param {object} [options.params={}] the get parameters to include to retrieve the layer + * @param {number} [options.zIndex=0] the z index for the layer + * @param {function} [options.loadCallback] function to call on load, context this is the layer object + * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed + * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility + * @param {boolean} [options.legendContent] additional content to add to the legend + * + * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible + * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined + * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move + * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called + * @param {mapMoveMakeGetParams} [options.mapMoveMakeGetParams=function(lyr, extent, zoomLevel){}] function to create additional map move params + * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages + * */ - }, { - key: 'style', - get: function get() { - return this._style; - } + function LayerBaseVector(url, options) { + _classCallCheck(this, LayerBaseVector); - /** - * set the style - * @param {ol.Style|styleFunc} style - the style or function - */ - , - set: function set(style) { - this._style = style; - this.olLayer.setStyle(this._style); - } + var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerBaseVector).call(this, url, options)); - /** - * get the map CRS if it is defined by the map move object - * @type {string|*} - */ + //prevent regular load if no url has been provided + if (_this.url.trim() == '') { + _this._loaded = true; + } + + _this._style = typeof options.style == 'undefined' ? undefined : options.style; - }, { - key: 'mapCrs', - get: function get() { - if (this._mapMove) { - return this._mapMove.map.getView().getProjection().getCode(); + if (_this.visible) { + _this._autoLoad = true; } else { - return undefined; + _this._autoLoad = typeof options['autoLoad'] == 'boolean' ? options['autoLoad'] : false; } - } - /** - * get the map move object - * @type {MapMoveCls|*} - */ + _this._onDemand = typeof options.onDemand == 'boolean' ? options.onDemand : false; + _this._onDemandDelay = typeof options.onDemandDelay == 'number' ? options.onDemandDelay : 300; - }, { - key: 'mapMove', - get: function get() { - return this._mapMove; - } + if (options.mapMoveObj) { + _this._mapMove = options.mapMoveObj; + } else { + _this._mapMove = _this._onDemand ? _mapMove2.default : undefined; + } - /** - * map move params - * @type {object} - */ + _this._mapMoveMakeGetParams = typeof options.mapMoveMakeGetParams == 'function' ? options.mapMoveMakeGetParams : function (lyr, extent, zoomLevel) { + return {}; + }; - }, { - key: 'mapMoveParams', - get: function get() { - return this._mapMoveParams; - } + if (_this._onDemand) { + _this._loaded = true; + _this._mapMoveParams = {}; + _this._mapMove.checkInit(); + _this._mapMove.addVectorLayer(_this); + } - /** - * Get the layer visibility - * @type {boolean} - */ - - }, { - key: 'visible', - get: function get() { - return _get(Object.getPrototypeOf(LayerBaseVector.prototype), 'visible', this); + _this._source = new _ol2.default.source.Vector(); + + /** + * + * @type {ol.layer.Vector|ol.layer.Base} + */ + _this.olLayer = new _ol2.default.layer.Vector({ + source: _this._source, + visible: _this.visible, + style: _this.style, + minResolution: _this._minResolution, + maxResolution: _this._maxResolution, + zIndex: _this._zIndex + }); + return _this; } /** - * Set the layer visibility - * @type {boolean} - * @override + * dummy to be overridden + * @param {object} featureCollection - geojson or esrijson object */ - , - set: function set(visibility) { - _set(Object.getPrototypeOf(LayerBaseVector.prototype), 'visible', visibility, this); - - if (this._onDemand) { - this.mapMove.triggerLyrLoad(this); - } - } - /** - * get the layer vector source - * @override - * @type {ol.source.Vector} - */ - }, { - key: 'source', - get: function get() { - return _get(Object.getPrototypeOf(LayerBaseVector.prototype), 'source', this); - } + _createClass(LayerBaseVector, [{ + key: 'addFeatures', + value: function addFeatures(featureCollection) { + console.log('Layer vector base addFeatures is a placeholder and does nothing'); + } + }, { + key: 'mapMoveBefore', + value: function mapMoveBefore(zoom, evtType) { + if (this.minZoom !== undefined) { + if (zoom < this.minZoom) { + return false; + } + } - /** - * array of ol features - * @type {Array.<ol.Feature>} - */ + if (this.maxZoom !== undefined) { + if (zoom > this.maxZoom) { + return false; + } + } - }, { - key: 'features', - get: function get() { - return this.source.getFeatures(); - } - }]); + return this.visible; + } + }, { + key: 'mapMoveMakeGetParams', + value: function mapMoveMakeGetParams(extent, zoomLevel) { + this._mapMoveParams = {}; + _jquery2.default.extend(this._mapMoveParams, this.params); + _jquery2.default.extend(this._mapMoveParams, this._mapMoveMakeGetParams(this, extent, zoomLevel)); + } + }, { + key: 'mapMoveCallback', + value: function mapMoveCallback(d) { + if (this.source) { + this._source.clear(); + } + } + }, { + key: 'clear', + value: function clear() { + if (this._source) { + this._source.clear(); + } + } + }, { + key: 'onDemandDelay', + get: function get() { + return this._onDemandDelay; + } + }, { + key: 'autoLoad', + get: function get() { + return this._autoLoad; + } + }, { + key: 'style', + get: function get() { + return this._style; + }, + set: function set(style) { + this._style = style; + this.olLayer.setStyle(this._style); + } + }, { + key: 'mapCrs', + get: function get() { + if (this._mapMove) { + return this._mapMove.map.getView().getProjection().getCode(); + } else { + return undefined; + } + } + }, { + key: 'mapMove', + get: function get() { + return this._mapMove; + } + }, { + key: 'mapMoveParams', + get: function get() { + return this._mapMoveParams; + } + }, { + key: 'visible', + get: function get() { + return _get(Object.getPrototypeOf(LayerBaseVector.prototype), 'visible', this); + }, + set: function set(visibility) { + _set(Object.getPrototypeOf(LayerBaseVector.prototype), 'visible', visibility, this); + + if (this._onDemand) { + this.mapMove.triggerLyrLoad(this); + } + } + }, { + key: 'source', + get: function get() { + return _get(Object.getPrototypeOf(LayerBaseVector.prototype), 'source', this); + } + }, { + key: 'features', + get: function get() { + return this.source.getFeatures(); + } + }]); - return LayerBaseVector; -})(_LayerBase3.default); + return LayerBaseVector; + }(_LayerBase3.default); -nm.LayerBaseVector = LayerBaseVector; -exports.default = LayerBaseVector; -module.exports = exports['default']; \ No newline at end of file + nm.LayerBaseVector = LayerBaseVector; + exports.default = LayerBaseVector; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/layers/LayerBaseVectorEsri.js b/lib/layers/LayerBaseVectorEsri.js index 846eba97f560c057705a6f08d390b3c2773e60a3..95777cecb6c5812fba018fd3a20104597b53f97f 100644 --- a/lib/layers/LayerBaseVectorEsri.js +++ b/lib/layers/LayerBaseVectorEsri.js @@ -1,250 +1,299 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); - -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); - -var _LayerBaseVector2 = require('./LayerBaseVector'); - -var _LayerBaseVector3 = _interopRequireDefault(_LayerBaseVector2); - -var _esriToOlStyle = require('../olHelpers/esriToOlStyle'); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', './LayerBaseVector', '../olHelpers/esriToOlStyle', '../olHelpers/mapMove', '../util/provide', '../ol/ol'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('./LayerBaseVector'), require('../olHelpers/esriToOlStyle'), require('../olHelpers/mapMove'), require('../util/provide'), require('../ol/ol')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.LayerBaseVector, global.esriToOlStyle, global.mapMove, global.provide, global.ol); + global.LayerBaseVectorEsri = mod.exports; + } +})(this, function (module, exports, _jquery, _LayerBaseVector2, _esriToOlStyle, _mapMove, _provide, _ol) { + 'use strict'; -var esriToOl = _interopRequireWildcard(_esriToOlStyle); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _mapMove = require('../olHelpers/mapMove'); + var _jquery2 = _interopRequireDefault(_jquery); -var _mapMove2 = _interopRequireDefault(_mapMove); + var _LayerBaseVector3 = _interopRequireDefault(_LayerBaseVector2); -var _provide = require('../util/provide'); + var esriToOl = _interopRequireWildcard(_esriToOlStyle); -var _provide2 = _interopRequireDefault(_provide); + var _mapMove2 = _interopRequireDefault(_mapMove); -var _ol = require('../ol/ol'); + var _provide2 = _interopRequireDefault(_provide); -var _ol2 = _interopRequireDefault(_ol); + var _ol2 = _interopRequireDefault(_ol); -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = {}; -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; + } + } -function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } + newObj.default = obj; + return newObj; + } + } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + 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; + }; -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** - * Created by gavorhes on 11/2/2015. - */ + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -var nm = (0, _provide2.default)('layers'); + 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); + } + } -/** - * Base layer for esri vector layers - * @augments LayerBaseVector - */ + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); -var LayerBaseVectorEsri = (function (_LayerBaseVector) { - _inherits(LayerBaseVectorEsri, _LayerBaseVector); + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } - /** - * The base vector layer - * @param {string} url - url for source - * @param {object} options - config - * @param {string} [options.id] - layer id - * @param {string} [options.name=Unnamed Layer] - layer name - * @param {number} [options.opacity=1] - opacity - * @param {boolean} [options.visible=true] - default visible - * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 - * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 - * @param {object} [options.params={}] the get parameters to include to retrieve the layer - * @param {number} [options.zIndex=0] the z index for the layer - * @param {function} [options.loadCallback] function to call on load, context this is the layer object - * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed - * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility - * @param {boolean} [options.legendContent] additional content to add to the legend - * - * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible - * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined - * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move - * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called - * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages - * - * @param {string} [options.where=1=1] the layer filter clause - * @param {string} [options.outFields=*] comma separated list of output fields, defaults to all - * @param {string} [options.format=pjson] the format the retrieve the data - * @param {number} [options.outSR=3857] the output spatial reference, defaults to web mercator - * @param {boolean} [options.useEsriStyle=false] if the map service style should be used - * @param {boolean} [options.collapseLegend=false] if the legend should be initially collapsed - * @param {number} [options.mapMoveMakeGetParams=function(extent, zoomLevel){}] function to create additional map move params - */ + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } - function LayerBaseVectorEsri(url, options) { - _classCallCheck(this, LayerBaseVectorEsri); + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); - if (_typeof(options.params) != 'object') { - options.params = {}; - } - options.params['where'] = options.where || '1=1'; - options.params['outFields'] = options.outFields || '*'; - options.params['f'] = options.format || 'pjson'; - options.params['outSR'] = options.outSR || 3857; + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerBaseVectorEsri).call(this, url, options)); + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; - _this._outSR = _this.params['outSR']; - _this._esriFormat = new _ol2.default.format.EsriJSON(); + if (getter === undefined) { + return undefined; + } - if (_this._url[_this._url.length - 1] !== '/') { - _this._url += '/'; + return getter.call(receiver); } + }; - _this._urlCopy = _this.url; - _this._url += 'query?callback=?'; - - if (_this.autoLoad || _this.visible) { - _this._load(); + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } - _this._useEsriStyle = typeof options.useEsriStyle == 'boolean' ? options.useEsriStyle : false; - - if (_this._useEsriStyle) { - _this.addLegendContent(); - } - return _this; + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + var nm = (0, _provide2.default)('layers'); + /** - * add additional content to the legend - * @param {string} [additionalContent=''] additional content to add to legend + * Base layer for esri vector layers + * @augments LayerBaseVector */ - _createClass(LayerBaseVectorEsri, [{ - key: 'addLegendContent', - value: function addLegendContent(additionalContent) { - var _this2 = this; + var LayerBaseVectorEsri = function (_LayerBaseVector) { + _inherits(LayerBaseVectorEsri, _LayerBaseVector); - if (!this._useEsriStyle) { - _get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), 'addLegendContent', this).call(this, additionalContent); - } else { - _jquery2.default.get(this._urlCopy + '?f=pjson&callback=?', {}, function (d) { - if (d['subLayers'].length > 0) { - alert('should only use single feature layers, not groups'); + /** + * The base vector layer + * @param {string} url - url for source + * @param {object} options - config + * @param {string} [options.id] - layer id + * @param {string} [options.name=Unnamed Layer] - layer name + * @param {number} [options.opacity=1] - opacity + * @param {boolean} [options.visible=true] - default visible + * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 + * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 + * @param {object} [options.params={}] the get parameters to include to retrieve the layer + * @param {number} [options.zIndex=0] the z index for the layer + * @param {function} [options.loadCallback] function to call on load, context this is the layer object + * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed + * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility + * @param {boolean} [options.legendContent] additional content to add to the legend + * + * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible + * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined + * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move + * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called + * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages + * + * @param {string} [options.where=1=1] the layer filter clause + * @param {string} [options.outFields=*] comma separated list of output fields, defaults to all + * @param {string} [options.format=pjson] the format the retrieve the data + * @param {number} [options.outSR=3857] the output spatial reference, defaults to web mercator + * @param {boolean} [options.useEsriStyle=false] if the map service style should be used + * @param {boolean} [options.collapseLegend=false] if the legend should be initially collapsed + * @param {number} [options.mapMoveMakeGetParams=function(extent, zoomLevel){}] function to create additional map move params + */ - return; - } + function LayerBaseVectorEsri(url, options) { + _classCallCheck(this, LayerBaseVectorEsri); - var newStyleAndLegend = esriToOl.makeFeatureServiceLegendAndSymbol(d); - _this2.style = newStyleAndLegend.style; - _get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), 'addLegendContent', _this2).call(_this2, newStyleAndLegend.legend); - }, 'json'); + if (_typeof(options.params) != 'object') { + options.params = {}; } - } + options.params['where'] = options.where || '1=1'; + options.params['outFields'] = options.outFields || '*'; + options.params['f'] = options.format || 'pjson'; + options.params['outSR'] = options.outSR || 3857; - /** - * add feature collection - * @param {object} featureCollection - features as esrijson - */ + var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerBaseVectorEsri).call(this, url, options)); - }, { - key: 'addFeatures', - value: function addFeatures(featureCollection) { - var feats = this._esriFormat.readFeatures(featureCollection); - this.source.addFeatures(feats); - } + _this._outSR = _this.params['outSR']; + _this._esriFormat = new _ol2.default.format.EsriJSON(); - /** - * trigger load features - * @protected - * @returns {boolean} if already loaded - */ + if (_this._url[_this._url.length - 1] !== '/') { + _this._url += '/'; + } - }, { - key: '_load', - value: function _load() { - var _this3 = this; + _this._urlCopy = _this.url; + _this._url += 'query?callback=?'; - if (_get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), '_load', this).call(this)) { - return true; + if (_this.autoLoad || _this.visible) { + _this._load(); } - _jquery2.default.get(this._url, this.params, function (d) { - _this3.addFeatures(d); - _this3.loadCallback(_this3); - }, 'json').fail(function () { - _this3._loaded = false; - }); - - return false; - } - /** - * callback to generate the parameters passed in the get request - * @param {object} extent - extent object - * @param {number} extent.minX - minX - * @param {number} extent.minY - minY - * @param {number} extent.maxX - maxX - * @param {number} extent.maxY - maxY - * @param {number} zoomLevel - zoom level - */ + _this._useEsriStyle = typeof options.useEsriStyle == 'boolean' ? options.useEsriStyle : false; - }, { - key: 'mapMoveMakeGetParams', - value: function mapMoveMakeGetParams(extent, zoomLevel) { - _get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), 'mapMoveMakeGetParams', this).call(this, extent, zoomLevel); - this.mapMoveParams['geometry'] = extent.minX + ',' + extent.minY + ',' + extent.maxX + ',' + extent.maxY; - this.mapMoveParams['geometryType'] = 'esriGeometryEnvelope'; - this.mapMoveParams['spatialRel'] = 'esriSpatialRelIntersects'; - this.mapMoveParams['spatialRel'] = 'esriSpatialRelIntersects'; - this.mapMoveParams['inSR'] = 3857; - if (this._outSR == 3857) { - this.mapMoveParams['geometryPrecision'] = 1; + if (_this._useEsriStyle) { + _this.addLegendContent(); } + return _this; } /** - * Before call to map move callback, can prevent call by returning false - * @param {number} zoom - zoom level - * @param {string} [evtType=undefined] undefined for initial load, otherwise one of 'change:center', 'change:resolution' - * @returns {boolean} if the call should proceed + * add additional content to the legend + * @param {string} [additionalContent=''] additional content to add to legend */ - }, { - key: 'mapMoveBefore', - value: function mapMoveBefore(zoom, evtType) { - return _get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), 'mapMoveBefore', this).call(this, zoom, evtType); - //if (super.mapMoveBefore(zoom, evtType)){ - // //place holder for additional processing - // return true; - //} else { - // return false; - //} - } - /** - * callback function on map move - * @param {object} d - the json response - */ + _createClass(LayerBaseVectorEsri, [{ + key: 'addLegendContent', + value: function addLegendContent(additionalContent) { + var _this2 = this; - }, { - key: 'mapMoveCallback', - value: function mapMoveCallback(d) { - _get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), 'mapMoveCallback', this).call(this, d); - this.source.addFeatures(this._esriFormat.readFeatures(d)); - } - }]); + if (!this._useEsriStyle) { + _get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), 'addLegendContent', this).call(this, additionalContent); + } else { + _jquery2.default.get(this._urlCopy + '?f=pjson&callback=?', {}, function (d) { + if (d['subLayers'].length > 0) { + alert('should only use single feature layers, not groups'); + + return; + } + + var newStyleAndLegend = esriToOl.makeFeatureServiceLegendAndSymbol(d); + _this2.style = newStyleAndLegend.style; + _get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), 'addLegendContent', _this2).call(_this2, newStyleAndLegend.legend); + }, 'json'); + } + } + }, { + key: 'addFeatures', + value: function addFeatures(featureCollection) { + var feats = this._esriFormat.readFeatures(featureCollection); + this.source.addFeatures(feats); + } + }, { + key: '_load', + value: function _load() { + var _this3 = this; + + if (_get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), '_load', this).call(this)) { + return true; + } + _jquery2.default.get(this._url, this.params, function (d) { + _this3.addFeatures(d); + _this3.loadCallback(_this3); + }, 'json').fail(function () { + _this3._loaded = false; + }); + + return false; + } + }, { + key: 'mapMoveMakeGetParams', + value: function mapMoveMakeGetParams(extent, zoomLevel) { + _get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), 'mapMoveMakeGetParams', this).call(this, extent, zoomLevel); + this.mapMoveParams['geometry'] = extent.minX + ',' + extent.minY + ',' + extent.maxX + ',' + extent.maxY; + this.mapMoveParams['geometryType'] = 'esriGeometryEnvelope'; + this.mapMoveParams['spatialRel'] = 'esriSpatialRelIntersects'; + this.mapMoveParams['spatialRel'] = 'esriSpatialRelIntersects'; + this.mapMoveParams['inSR'] = 3857; + if (this._outSR == 3857) { + this.mapMoveParams['geometryPrecision'] = 1; + } + } + }, { + key: 'mapMoveBefore', + value: function mapMoveBefore(zoom, evtType) { + return _get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), 'mapMoveBefore', this).call(this, zoom, evtType); + //if (super.mapMoveBefore(zoom, evtType)){ + // //place holder for additional processing + // return true; + //} else { + // return false; + //} + } + }, { + key: 'mapMoveCallback', + value: function mapMoveCallback(d) { + _get(Object.getPrototypeOf(LayerBaseVectorEsri.prototype), 'mapMoveCallback', this).call(this, d); + this.source.addFeatures(this._esriFormat.readFeatures(d)); + } + }]); - return LayerBaseVectorEsri; -})(_LayerBaseVector3.default); + return LayerBaseVectorEsri; + }(_LayerBaseVector3.default); -nm.LayerBaseVectorEsri = LayerBaseVectorEsri; -exports.default = LayerBaseVectorEsri; -module.exports = exports['default']; \ No newline at end of file + nm.LayerBaseVectorEsri = LayerBaseVectorEsri; + exports.default = LayerBaseVectorEsri; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/layers/LayerBaseVectorGeoJson.js b/lib/layers/LayerBaseVectorGeoJson.js index cd0b210f782c46c71fbbb1462a07a43c0c71ebc7..9496bbc27107ecb3328b6f29e0d53507f26a5c1f 100644 --- a/lib/layers/LayerBaseVectorGeoJson.js +++ b/lib/layers/LayerBaseVectorGeoJson.js @@ -1,153 +1,211 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', './LayerBaseVector', '../util/provide', '../ol/ol'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('./LayerBaseVector'), require('../util/provide'), require('../ol/ol')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.LayerBaseVector, global.provide, global.ol); + global.LayerBaseVectorGeoJson = mod.exports; + } +})(this, function (module, exports, _jquery, _LayerBaseVector2, _provide, _ol) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); + Object.defineProperty(exports, "__esModule", { + value: true + }); -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; }; })(); + var _jquery2 = _interopRequireDefault(_jquery); -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + var _LayerBaseVector3 = _interopRequireDefault(_LayerBaseVector2); -var _jquery = require('../jquery'); + var _provide2 = _interopRequireDefault(_provide); -var _jquery2 = _interopRequireDefault(_jquery); + var _ol2 = _interopRequireDefault(_ol); -var _LayerBaseVector2 = require('./LayerBaseVector'); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var _LayerBaseVector3 = _interopRequireDefault(_LayerBaseVector2); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -var _provide = require('../util/provide'); + 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); + } + } -var _provide2 = _interopRequireDefault(_provide); + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); -var _ol = require('../ol/ol'); + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -var _ol2 = _interopRequireDefault(_ol); + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; + + if (getter === undefined) { + return undefined; + } -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** - * Created by gavorhes on 11/2/2015. - */ + return getter.call(receiver); + } + }; -var nm = (0, _provide2.default)('layers'); + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } -/** - * The Vector GeoJson Layer - * @augments LayerBaseVector - */ + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } -var LayerBaseVectorGeoJson = (function (_LayerBaseVector) { - _inherits(LayerBaseVectorGeoJson, _LayerBaseVector); + var nm = (0, _provide2.default)('layers'); /** - * @param {string|undefined|null} url - resource url, set to '' to make blank layer - * @param {object} options - config - * @param {string} [options.id] - layer id - * @param {string} [options.name=Unnamed Layer] - layer name - * @param {number} [options.opacity=1] - opacity - * @param {boolean} [options.visible=true] - default visible - * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 - * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 - * @param {object} [options.params={}] the get parameters to include to retrieve the layer - * @param {number} [options.zIndex=0] the z index for the layer - * @param {function} [options.loadCallback] function to call on load, context this is the layer object - * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed - * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility - * @param {boolean} [options.legendContent] additional content to add to the legend - * - * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible - * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined - * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move - * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called - * - * @param {object} [options.transform={}] SR transform, set as false for no transform - * @param {string} options.transform.dataProjection=EPSG:4326 the data CRS - * @param {string} options.transform.featureProjection=EPSG:3857 the feature/map CRS - * @param {mapMoveMakeGetParams} [options.mapMoveMakeGetParams=function(lyr, extent, zoomLevel){}] function to create additional map move params - * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages + * The Vector GeoJson Layer + * @augments LayerBaseVector */ - function LayerBaseVectorGeoJson(url, options) { - _classCallCheck(this, LayerBaseVectorGeoJson); + var LayerBaseVectorGeoJson = function (_LayerBaseVector) { + _inherits(LayerBaseVectorGeoJson, _LayerBaseVector); - url = typeof url == 'string' ? url : ''; + /** + * @param {string|undefined|null} url - resource url, set to '' to make blank layer + * @param {object} options - config + * @param {string} [options.id] - layer id + * @param {string} [options.name=Unnamed Layer] - layer name + * @param {number} [options.opacity=1] - opacity + * @param {boolean} [options.visible=true] - default visible + * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 + * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 + * @param {object} [options.params={}] the get parameters to include to retrieve the layer + * @param {number} [options.zIndex=0] the z index for the layer + * @param {function} [options.loadCallback] function to call on load, context this is the layer object + * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed + * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility + * @param {boolean} [options.legendContent] additional content to add to the legend + * + * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible + * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined + * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move + * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called + * + * @param {object} [options.transform={}] SR transform, set as false for no transform + * @param {string} options.transform.dataProjection=EPSG:4326 the data CRS + * @param {string} options.transform.featureProjection=EPSG:3857 the feature/map CRS + * @param {mapMoveMakeGetParams} [options.mapMoveMakeGetParams=function(lyr, extent, zoomLevel){}] function to create additional map move params + * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages + */ - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerBaseVectorGeoJson).call(this, url, options)); + function LayerBaseVectorGeoJson(url, options) { + _classCallCheck(this, LayerBaseVectorGeoJson); - _this._geoJsonFormat = new _ol2.default.format.GeoJSON(); + url = typeof url == 'string' ? url : ''; - _this._transform = options.transform || {}; - _this._transform.dataProjection = _this._transform.dataProjection || "EPSG:4326"; - _this._transform.featureProjection = _this._transform.featureProjection || "EPSG:3857"; + var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerBaseVectorGeoJson).call(this, url, options)); - if (_this.autoLoad || _this.visible) { - _this._load(); - } - return _this; - } + _this._geoJsonFormat = new _ol2.default.format.GeoJSON(); - /** - * add feature collection - * @param {object} featureCollection - as geojson object - */ + _this._transform = options.transform || {}; + _this._transform.dataProjection = _this._transform.dataProjection || "EPSG:4326"; + _this._transform.featureProjection = _this._transform.featureProjection || "EPSG:3857"; - _createClass(LayerBaseVectorGeoJson, [{ - key: 'addFeatures', - value: function addFeatures(featureCollection) { - if (this._transform.dataProjection == 'EPSG:3857' && this._transform.featureProjection == 'EPSG:3857') { - this._source.addFeatures(this._geoJsonFormat.readFeatures(featureCollection)); - } else { - this._source.addFeatures(this._geoJsonFormat.readFeatures(featureCollection, this._transform)); + if (_this.autoLoad || _this.visible) { + _this._load(); } + return _this; } /** - * trigger load features - * @protected - * @returns {boolean} if already loaded + * add feature collection + * @param {object} featureCollection - as geojson object */ - }, { - key: '_load', - value: function _load() { - var _this2 = this; - if (_get(Object.getPrototypeOf(LayerBaseVectorGeoJson.prototype), '_load', this).call(this)) { - return true; + _createClass(LayerBaseVectorGeoJson, [{ + key: 'addFeatures', + value: function addFeatures(featureCollection) { + if (this._transform.dataProjection == 'EPSG:3857' && this._transform.featureProjection == 'EPSG:3857') { + this._source.addFeatures(this._geoJsonFormat.readFeatures(featureCollection)); + } else { + this._source.addFeatures(this._geoJsonFormat.readFeatures(featureCollection, this._transform)); + } } + }, { + key: '_load', + value: function _load() { + var _this2 = this; + + if (_get(Object.getPrototypeOf(LayerBaseVectorGeoJson.prototype), '_load', this).call(this)) { + return true; + } + + _jquery2.default.get(this._url, this._params, function (d) { + _this2.addFeatures(d); + _this2.loadCallback(_this2); + }, 'json').fail(function () { + this._loaded = false; + }); + + return false; + } + }, { + key: 'mapMoveCallback', + value: function mapMoveCallback(d) { + _get(Object.getPrototypeOf(LayerBaseVectorGeoJson.prototype), 'mapMoveCallback', this).call(this, d); + this._source.addFeatures(this._geoJsonFormat.readFeatures(d, this._transform)); + } + }]); - _jquery2.default.get(this._url, this._params, function (d) { - _this2.addFeatures(d); - _this2.loadCallback(_this2); - }, 'json').fail(function () { - this._loaded = false; - }); - - return false; - } - - /** - * callback function on map move - * @param {object} d the json response - * @override - */ - - }, { - key: 'mapMoveCallback', - value: function mapMoveCallback(d) { - _get(Object.getPrototypeOf(LayerBaseVectorGeoJson.prototype), 'mapMoveCallback', this).call(this, d); - this._source.addFeatures(this._geoJsonFormat.readFeatures(d, this._transform)); - } - }]); - - return LayerBaseVectorGeoJson; -})(_LayerBaseVector3.default); + return LayerBaseVectorGeoJson; + }(_LayerBaseVector3.default); -nm.LayerBaseVectorGeoJson = LayerBaseVectorGeoJson; -exports.default = LayerBaseVectorGeoJson; -module.exports = exports['default']; \ No newline at end of file + nm.LayerBaseVectorGeoJson = LayerBaseVectorGeoJson; + exports.default = LayerBaseVectorGeoJson; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/layers/LayerBaseXyzTile.js b/lib/layers/LayerBaseXyzTile.js index 82d511c6ba901841ce6c86600e44b7dd98b43e9a..72d3db56eeb70a4ec18b5074ad1c0a9ecdba157a 100644 --- a/lib/layers/LayerBaseXyzTile.js +++ b/lib/layers/LayerBaseXyzTile.js @@ -1,158 +1,241 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', './LayerBase', '../olHelpers/esriToOlStyle', '../util/provide', '../ol/ol'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('./LayerBase'), require('../olHelpers/esriToOlStyle'), require('../util/provide'), require('../ol/ol')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.LayerBase, global.esriToOlStyle, global.provide, global.ol); + global.LayerBaseXyzTile = mod.exports; + } +})(this, function (module, exports, _jquery, _LayerBase2, _esriToOlStyle, _provide, _ol) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); + Object.defineProperty(exports, "__esModule", { + value: true + }); -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; }; })(); + var _jquery2 = _interopRequireDefault(_jquery); -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + var _LayerBase3 = _interopRequireDefault(_LayerBase2); -var _jquery = require('../jquery'); + var esriToOl = _interopRequireWildcard(_esriToOlStyle); -var _jquery2 = _interopRequireDefault(_jquery); + var _provide2 = _interopRequireDefault(_provide); -var _LayerBase2 = require('./LayerBase'); + var _ol2 = _interopRequireDefault(_ol); -var _LayerBase3 = _interopRequireDefault(_LayerBase2); + function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = {}; -var _esriToOlStyle = require('../olHelpers/esriToOlStyle'); + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; + } + } -var esriToOl = _interopRequireWildcard(_esriToOlStyle); + newObj.default = obj; + return newObj; + } + } -var _provide = require('../util/provide'); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var _provide2 = _interopRequireDefault(_provide); + 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; + }; -var _ol = require('../ol/ol'); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -var _ol2 = _interopRequireDefault(_ol); + 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); + } + } -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** - * Created by gavorhes on 12/4/2015. - */ + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; + + if (getter === undefined) { + return undefined; + } + + return getter.call(receiver); + } + }; -var nm = (0, _provide2.default)('layers'); + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } -/** - * XYZ tile - * @augments LayerBase - */ + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } -var LayerBaseXyzTile = (function (_LayerBase) { - _inherits(LayerBaseXyzTile, _LayerBase); + var nm = (0, _provide2.default)('layers'); /** - * The XYZ tile layer - * @param {string} url - url for source - * @param {object} options - config - * @param {string} [options.id] - layer id - * @param {string} [options.name=Unnamed Layer] - layer name - * @param {number} [options.opacity=1] - opacity - * @param {boolean} [options.visible=true] - default visible - * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 - * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 - * @param {object} [options.params={}] the get parameters to include to retrieve the layer - * @param {number} [options.zIndex=0] the z index for the layer - * @param {function} [options.loadCallback] function to call on load, context this is the layer object - * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed - * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility - * @param {boolean} [options.legendContent] additional content to add to the legend - * @param {boolean} [options.useEsriStyle=false] if the map service style should be used + * XYZ tile + * @augments LayerBase */ - function LayerBaseXyzTile(url, options) { - _classCallCheck(this, LayerBaseXyzTile); + var LayerBaseXyzTile = function (_LayerBase) { + _inherits(LayerBaseXyzTile, _LayerBase); - var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerBaseXyzTile).call(this, url, options)); - - _this2._source = new _ol2.default.source.XYZ({ url: _this2.url == '' ? undefined : _this2.url }); - _this2.olLayer = new _ol2.default.layer.Tile({ - source: _this2._source, - visible: _this2.visible, - opacity: _this2.opacity, - minResolution: _this2._minResolution, - maxResolution: _this2._maxResolution, - zIndex: _this2._zIndex - }); + /** + * The XYZ tile layer + * @param {string} url - url for source + * @param {object} options - config + * @param {string} [options.id] - layer id + * @param {string} [options.name=Unnamed Layer] - layer name + * @param {number} [options.opacity=1] - opacity + * @param {boolean} [options.visible=true] - default visible + * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 + * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 + * @param {object} [options.params={}] the get parameters to include to retrieve the layer + * @param {number} [options.zIndex=0] the z index for the layer + * @param {function} [options.loadCallback] function to call on load, context this is the layer object + * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed + * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility + * @param {boolean} [options.legendContent] additional content to add to the legend + * @param {boolean} [options.useEsriStyle=false] if the map service style should be used + */ - _this2._useEsriStyle = typeof options.useEsriStyle == 'boolean' ? options.useEsriStyle : false; + function LayerBaseXyzTile(url, options) { + _classCallCheck(this, LayerBaseXyzTile); - if (_this2._useEsriStyle) { - _this2.addLegendContent(); - } - return _this2; - } + var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerBaseXyzTile).call(this, url, options)); - /** - * add additional content to the legend - * @param {string} [additionalContent=''] additional content for legend - */ + _this2._source = new _ol2.default.source.XYZ({ url: _this2.url == '' ? undefined : _this2.url }); + _this2.olLayer = new _ol2.default.layer.Tile({ + source: _this2._source, + visible: _this2.visible, + opacity: _this2.opacity, + minResolution: _this2._minResolution, + maxResolution: _this2._maxResolution, + zIndex: _this2._zIndex + }); - _createClass(LayerBaseXyzTile, [{ - key: 'addLegendContent', - value: function addLegendContent(additionalContent) { - var _this3 = this; + _this2._useEsriStyle = typeof options.useEsriStyle == 'boolean' ? options.useEsriStyle : false; - if (!this._useEsriStyle) { - _get(Object.getPrototypeOf(LayerBaseXyzTile.prototype), 'addLegendContent', this).call(this, additionalContent); - } else { - var _ret = (function () { - var urlCopy = _this3.url; - - var mapServerIndex = urlCopy.toLowerCase().indexOf('mapserver'); - if (mapServerIndex > -1) { - urlCopy = urlCopy.slice(0, mapServerIndex + 9); - } else { - return { - v: undefined - }; - } - - if (urlCopy[urlCopy.length - 1] !== '/') { - urlCopy += '/'; - } - - urlCopy += 'legend?f=pjson&callback=?'; - - var _this = _this3; - var superAddLegend = _get(Object.getPrototypeOf(LayerBaseXyzTile.prototype), 'addLegendContent', _this3); - - _jquery2.default.get(urlCopy, {}, function (d) { - var newHtml = esriToOl.makeMapServiceLegend(d); - superAddLegend.call(_this, newHtml); - }, 'json'); - })(); - - if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; + if (_this2._useEsriStyle) { + _this2.addLegendContent(); } + return _this2; } /** - * - * @returns {ol.source.XYZ} the vector source + * add additional content to the legend + * @param {string} [additionalContent=''] additional content for legend */ - }, { - key: 'source', - get: function get() { - return _get(Object.getPrototypeOf(LayerBaseXyzTile.prototype), 'source', this); - } - }]); - return LayerBaseXyzTile; -})(_LayerBase3.default); + _createClass(LayerBaseXyzTile, [{ + key: 'addLegendContent', + value: function addLegendContent(additionalContent) { + var _this3 = this; + + if (!this._useEsriStyle) { + _get(Object.getPrototypeOf(LayerBaseXyzTile.prototype), 'addLegendContent', this).call(this, additionalContent); + } else { + var _ret = function () { + var urlCopy = _this3.url; + + var mapServerIndex = urlCopy.toLowerCase().indexOf('mapserver'); + if (mapServerIndex > -1) { + urlCopy = urlCopy.slice(0, mapServerIndex + 9); + } else { + return { + v: void 0 + }; + } + + if (urlCopy[urlCopy.length - 1] !== '/') { + urlCopy += '/'; + } + + urlCopy += 'legend?f=pjson&callback=?'; + + var _this = _this3; + var superAddLegend = _get(Object.getPrototypeOf(LayerBaseXyzTile.prototype), 'addLegendContent', _this3); + + _jquery2.default.get(urlCopy, {}, function (d) { + var newHtml = esriToOl.makeMapServiceLegend(d); + superAddLegend.call(_this, newHtml); + }, 'json'); + }(); + + if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; + } + } + }, { + key: 'source', + get: function get() { + return _get(Object.getPrototypeOf(LayerBaseXyzTile.prototype), 'source', this); + } + }]); + + return LayerBaseXyzTile; + }(_LayerBase3.default); -nm.LayerBaseXyzTile = LayerBaseXyzTile; -exports.default = LayerBaseXyzTile; -module.exports = exports['default']; \ No newline at end of file + nm.LayerBaseXyzTile = LayerBaseXyzTile; + exports.default = LayerBaseXyzTile; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/layers/LayerEsriMapServer.js b/lib/layers/LayerEsriMapServer.js index 59f01c7a31e3fdbc0ddd2b65d6734f64ac23efaf..7b4191c0e186e7e36223cbab662861d3b3bdbccc 100644 --- a/lib/layers/LayerEsriMapServer.js +++ b/lib/layers/LayerEsriMapServer.js @@ -1,227 +1,299 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', './LayerBase', '../olHelpers/esriToOlStyle', '../olHelpers/mapPopup', '../util/provide', '../ol/ol'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('./LayerBase'), require('../olHelpers/esriToOlStyle'), require('../olHelpers/mapPopup'), require('../util/provide'), require('../ol/ol')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.LayerBase, global.esriToOlStyle, global.mapPopup, global.provide, global.ol); + global.LayerEsriMapServer = mod.exports; + } +})(this, function (module, exports, _jquery, _LayerBase2, _esriToOlStyle, _mapPopup, _provide, _ol) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); + Object.defineProperty(exports, "__esModule", { + value: true + }); -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; }; })(); + var _jquery2 = _interopRequireDefault(_jquery); -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + var _LayerBase3 = _interopRequireDefault(_LayerBase2); -var _jquery = require('../jquery'); + var esriToOl = _interopRequireWildcard(_esriToOlStyle); -var _jquery2 = _interopRequireDefault(_jquery); + var _mapPopup2 = _interopRequireDefault(_mapPopup); -var _LayerBase2 = require('./LayerBase'); + var _provide2 = _interopRequireDefault(_provide); -var _LayerBase3 = _interopRequireDefault(_LayerBase2); + var _ol2 = _interopRequireDefault(_ol); -var _esriToOlStyle = require('../olHelpers/esriToOlStyle'); + function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = {}; -var esriToOl = _interopRequireWildcard(_esriToOlStyle); + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; + } + } -var _mapPopup = require('../olHelpers/mapPopup'); + newObj.default = obj; + return newObj; + } + } -var _mapPopup2 = _interopRequireDefault(_mapPopup); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var _provide = require('../util/provide'); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -var _provide2 = _interopRequireDefault(_provide); + 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); + } + } -var _ol = require('../ol/ol'); + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); -var _ol2 = _interopRequireDefault(_ol); + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** - * Created by gavorhes on 12/7/2015. - */ + if (getter === undefined) { + return undefined; + } -var nm = (0, _provide2.default)('layers'); + return getter.call(receiver); + } + }; -/** - * esri mapserver layer - * @augments LayerBase - */ + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } -var LayerEsriMapServer = (function (_LayerBase) { - _inherits(LayerEsriMapServer, _LayerBase); + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } + + var nm = (0, _provide2.default)('layers'); /** - * The base layer for all others - * @param {string} url - resource url - * @param {object} options - config - * @param {string} [options.id] - layer id - * @param {string} [options.name=Unnamed Layer] - layer name - * @param {number} [options.opacity=1] - opacity - * @param {boolean} [options.visible=true] - default visible - * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 - * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 - * @param {object} [options.params={}] the get parameters to include to retrieve the layer - * @param {number} [options.zIndex=0] the z index for the layer - * @param {function} [options.loadCallback] function to call on load, context this is the layer object - * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed - * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility - * @param {boolean} [options.legendContent] additional content to add to the legend - * @param {boolean} [options.addPopup=false] if a popup should be added + * esri mapserver layer + * @augments LayerBase */ - function LayerEsriMapServer(url, options) { - _classCallCheck(this, LayerEsriMapServer); + var LayerEsriMapServer = function (_LayerBase) { + _inherits(LayerEsriMapServer, _LayerBase); + + /** + * The base layer for all others + * @param {string} url - resource url + * @param {object} options - config + * @param {string} [options.id] - layer id + * @param {string} [options.name=Unnamed Layer] - layer name + * @param {number} [options.opacity=1] - opacity + * @param {boolean} [options.visible=true] - default visible + * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 + * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 + * @param {object} [options.params={}] the get parameters to include to retrieve the layer + * @param {number} [options.zIndex=0] the z index for the layer + * @param {function} [options.loadCallback] function to call on load, context this is the layer object + * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed + * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility + * @param {boolean} [options.legendContent] additional content to add to the legend + * @param {boolean} [options.addPopup=false] if a popup should be added + */ - var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerEsriMapServer).call(this, url, options)); + function LayerEsriMapServer(url, options) { + _classCallCheck(this, LayerEsriMapServer); - _this2._source = new _ol2.default.source.TileArcGISRest({ url: _this2.url == '' ? undefined : _this2.url }); + var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerEsriMapServer).call(this, url, options)); - _this2.olLayer = new _ol2.default.layer.Tile({ - source: _this2._source, - visible: _this2.visible, - opacity: _this2.opacity, - minResolution: _this2._minResolution, - maxResolution: _this2._maxResolution, - zIndex: _this2._zIndex - }); + _this2._source = new _ol2.default.source.TileArcGISRest({ url: _this2.url == '' ? undefined : _this2.url }); + + _this2.olLayer = new _ol2.default.layer.Tile({ + source: _this2._source, + visible: _this2.visible, + opacity: _this2.opacity, + minResolution: _this2._minResolution, + maxResolution: _this2._maxResolution, + zIndex: _this2._zIndex + }); - options.addPopup = typeof options.addPopup == 'boolean' ? options.addPopup : false; + options.addPopup = typeof options.addPopup == 'boolean' ? options.addPopup : false; - _this2._esriFormat = new _ol2.default.format.EsriJSON(); - _this2._popupRequest = null; + _this2._esriFormat = new _ol2.default.format.EsriJSON(); + _this2._popupRequest = null; - _this2.addLegendContent(); + _this2.addLegendContent(); - if (options.addPopup) { - _mapPopup2.default.addMapServicePopup(_this2); + if (options.addPopup) { + _mapPopup2.default.addMapServicePopup(_this2); + } + return _this2; } - return _this2; - } - /** - * add additional content to the legend - * @param {string} [additionalContent=''] additional content for legend - */ + /** + * add additional content to the legend + * @param {string} [additionalContent=''] additional content for legend + */ - _createClass(LayerEsriMapServer, [{ - key: 'addLegendContent', - value: function addLegendContent(additionalContent) { - var urlCopy = this.url; - if (urlCopy[urlCopy.length - 1] !== '/') { - urlCopy += '/'; - } + _createClass(LayerEsriMapServer, [{ + key: 'addLegendContent', + value: function addLegendContent(additionalContent) { + var urlCopy = this.url; - urlCopy += 'legend?f=pjson&callback=?'; + if (urlCopy[urlCopy.length - 1] !== '/') { + urlCopy += '/'; + } - var _this = this; - var superAddLegend = _get(Object.getPrototypeOf(LayerEsriMapServer.prototype), 'addLegendContent', this); + urlCopy += 'legend?f=pjson&callback=?'; - _jquery2.default.get(urlCopy, {}, function (d) { - var newHtml = esriToOl.makeMapServiceLegend(d); - superAddLegend.call(_this, newHtml); - }, 'json'); - } - }, { - key: 'getPopupInfo', - value: function getPopupInfo(queryParams) { - if (!this.visible) { - return; + var _this = this; + var superAddLegend = _get(Object.getPrototypeOf(LayerEsriMapServer.prototype), 'addLegendContent', this); + + _jquery2.default.get(urlCopy, {}, function (d) { + var newHtml = esriToOl.makeMapServiceLegend(d); + superAddLegend.call(_this, newHtml); + }, 'json'); } + }, { + key: 'getPopupInfo', + value: function getPopupInfo(queryParams) { + if (!this.visible) { + return; + } - var urlCopy = this.url; + var urlCopy = this.url; - if (urlCopy[urlCopy.length - 1] != '/') { - urlCopy += '/'; - } + if (urlCopy[urlCopy.length - 1] != '/') { + urlCopy += '/'; + } - urlCopy += 'identify?callback=?'; + urlCopy += 'identify?callback=?'; - var _this = this; + var _this = this; - if (this._popupRequest != null) { - this._popupRequest.abort(); - } + if (this._popupRequest != null) { + this._popupRequest.abort(); + } - this._popupRequest = _jquery2.default.get(urlCopy, queryParams, function (d) { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + this._popupRequest = _jquery2.default.get(urlCopy, queryParams, function (d) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; - try { - for (var _iterator = d['results'][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var r = _step.value; + try { + for (var _iterator = d['results'][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var r = _step.value; - var popupHtml = '<table class="esri-popup-table">'; - for (var a in r['attributes']) { - if (r['attributes'].hasOwnProperty(a)) { - var attrVal = r['attributes'][a]; + var popupHtml = '<table class="esri-popup-table">'; - if (attrVal == null || attrVal.toString().toLowerCase() == 'null') { - continue; - } + for (var a in r['attributes']) { + if (r['attributes'].hasOwnProperty(a)) { + var attrVal = r['attributes'][a]; - var attr = a; - if (attr.length > 14) { - attr = attr.slice(0, 11) + '...'; - } + if (attrVal == null || attrVal.toString().toLowerCase() == 'null') { + continue; + } + + var attr = a; + if (attr.length > 14) { + attr = attr.slice(0, 11) + '...'; + } - popupHtml += '<tr><td>' + attr + '</td><td>' + attrVal + '</td></tr>'; + popupHtml += '<tr><td>' + attr + '</td><td>' + attrVal + '</td></tr>'; + } } - } - popupHtml += '</table>'; + popupHtml += '</table>'; - _mapPopup2.default.addMapServicePopupContent(_this._esriFormat.readFeature(r), _this, popupHtml, r['layerName']); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); + _mapPopup2.default.addMapServicePopupContent(_this._esriFormat.readFeature(r), _this, popupHtml, r['layerName']); } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; } finally { - if (_didIteratorError) { - throw _iteratorError; + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } } } - } - }, 'json').always(function () { - _this._popupRequest = null; - }); - } - - /** - * overwrite the base load - * @protected - */ - - }, { - key: '_load', - value: function _load() {} - - /** - * - * @returns {ol.source.TileArcGISRest} the vector source - */ - - }, { - key: 'source', - get: function get() { - return _get(Object.getPrototypeOf(LayerEsriMapServer.prototype), 'source', this); - } - }]); + }, 'json').always(function () { + _this._popupRequest = null; + }); + } + }, { + key: '_load', + value: function _load() {} + }, { + key: 'source', + get: function get() { + return _get(Object.getPrototypeOf(LayerEsriMapServer.prototype), 'source', this); + } + }]); - return LayerEsriMapServer; -})(_LayerBase3.default); + return LayerEsriMapServer; + }(_LayerBase3.default); -nm.LayerEsriMapServer = LayerEsriMapServer; -exports.default = LayerEsriMapServer; -module.exports = exports['default']; \ No newline at end of file + nm.LayerEsriMapServer = LayerEsriMapServer; + exports.default = LayerEsriMapServer; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/layers/LayerItsInventory.js b/lib/layers/LayerItsInventory.js index f54f6baa48f316a28652a608022b6b34692b084a..7da94ad0d208a3652e4cfcdaacb1069f56392f17 100644 --- a/lib/layers/LayerItsInventory.js +++ b/lib/layers/LayerItsInventory.js @@ -1,413 +1,484 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', './LayerBaseVectorGeoJson', '../olHelpers/mapMove', '../olHelpers/mapPopup', '../util/provide', '../ol/ol'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('./LayerBaseVectorGeoJson'), require('../olHelpers/mapMove'), require('../olHelpers/mapPopup'), require('../util/provide'), require('../ol/ol')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.LayerBaseVectorGeoJson, global.mapMove, global.mapPopup, global.provide, global.ol); + global.LayerItsInventory = mod.exports; + } +})(this, function (module, exports, _jquery, _LayerBaseVectorGeoJson, _mapMove, _mapPopup, _provide, _ol) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); + Object.defineProperty(exports, "__esModule", { + value: true + }); -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; }; })(); + var _jquery2 = _interopRequireDefault(_jquery); -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + var _LayerBaseVectorGeoJson2 = _interopRequireDefault(_LayerBaseVectorGeoJson); -var _jquery = require('../jquery'); + var _mapMove2 = _interopRequireDefault(_mapMove); -var _jquery2 = _interopRequireDefault(_jquery); + var _mapPopup2 = _interopRequireDefault(_mapPopup); -var _LayerBaseVectorGeoJson = require('./LayerBaseVectorGeoJson'); + var _provide2 = _interopRequireDefault(_provide); -var _LayerBaseVectorGeoJson2 = _interopRequireDefault(_LayerBaseVectorGeoJson); + var _ol2 = _interopRequireDefault(_ol); -var _mapMove = require('../olHelpers/mapMove'); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var _mapMove2 = _interopRequireDefault(_mapMove); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -var _mapPopup = require('../olHelpers/mapPopup'); + 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); + } + } -var _mapPopup2 = _interopRequireDefault(_mapPopup); + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); -var _provide = require('../util/provide'); + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -var _provide2 = _interopRequireDefault(_provide); + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -var _ol = require('../ol/ol'); + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); -var _ol2 = _interopRequireDefault(_ol); + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + if (getter === undefined) { + return undefined; + } -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + return getter.call(receiver); + } + }; -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } -function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } /** - * Created by gavorhes on 12/8/2015. - */ + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } -var nm = (0, _provide2.default)('layers'); + 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; + }; -function checkStyleNumber(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig) { - "use strict" + var nm = (0, _provide2.default)('layers'); - //make sure one and only one configuration is defined; - ; - var configCount = 0; - if (typeof itsIcon == 'string') { - configCount++; - } + function checkStyleNumber(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig) { + "use strict"; - if ((typeof itsLineStyle === 'undefined' ? 'undefined' : _typeof(itsLineStyle)) == 'object') { - itsLineStyle.width = typeof itsLineStyle.width == 'number' ? itsLineStyle.width : 5; - itsLineStyle.color = typeof itsLineStyle.color == 'string' ? itsLineStyle.color : 'red'; - configCount++; - } + //make sure one and only one configuration is defined; - if ((typeof itsIconConfig === 'undefined' ? 'undefined' : _typeof(itsIconConfig)) == 'object') { - itsIconConfig.defaultName = itsIconConfig.defaultName || 'Other'; + var configCount = 0; + if (typeof itsIcon == 'string') { + configCount++; + } - if (typeof itsIconConfig.iconArray == 'undefined') { - itsIconConfig.iconArray = []; + if ((typeof itsLineStyle === 'undefined' ? 'undefined' : _typeof(itsLineStyle)) == 'object') { + itsLineStyle.width = typeof itsLineStyle.width == 'number' ? itsLineStyle.width : 5; + itsLineStyle.color = typeof itsLineStyle.color == 'string' ? itsLineStyle.color : 'red'; + configCount++; } - configCount++; - } + if ((typeof itsIconConfig === 'undefined' ? 'undefined' : _typeof(itsIconConfig)) == 'object') { + itsIconConfig.defaultName = itsIconConfig.defaultName || 'Other'; - if ((typeof itsLineConfig === 'undefined' ? 'undefined' : _typeof(itsLineConfig)) == 'object') { - itsLineConfig.defaultName = itsLineConfig.defaultName || 'Other'; - itsLineConfig.defaultWidth = itsLineConfig.defaultWidth || 5; - itsLineConfig.defaultColor = itsLineConfig.defaultColor || 'red'; + if (typeof itsIconConfig.iconArray == 'undefined') { + itsIconConfig.iconArray = []; + } - if (typeof itsLineConfig.lineArray == 'undefined') { - itsLineConfig.lineArray = []; + configCount++; } - // set the width if not defined - for (var i = 0; i < itsLineConfig.lineArray.length; i++) { - if (itsLineConfig.lineArray[i].length == 3) { - itsLineConfig.lineArray[i].push(5); + if ((typeof itsLineConfig === 'undefined' ? 'undefined' : _typeof(itsLineConfig)) == 'object') { + itsLineConfig.defaultName = itsLineConfig.defaultName || 'Other'; + itsLineConfig.defaultWidth = itsLineConfig.defaultWidth || 5; + itsLineConfig.defaultColor = itsLineConfig.defaultColor || 'red'; + + if (typeof itsLineConfig.lineArray == 'undefined') { + itsLineConfig.lineArray = []; } - } - configCount++; - } + // set the width if not defined + for (var i = 0; i < itsLineConfig.lineArray.length; i++) { + if (itsLineConfig.lineArray[i].length == 3) { + itsLineConfig.lineArray[i].push(5); + } + } - if (configCount > 1) { - throw 'Only one style config can be defined'; + configCount++; + } + + if (configCount > 1) { + throw 'Only one style config can be defined'; + } } -} - -/** - * - * @param {string} [itsIcon=undefined] the ITS device type icon image see http://transportal.cee.wisc.edu/its/inventory/icons/ - * - * @param {object} [itsLineStyle=undefined] A single line style - * @param {string} itsLineStyle.color the line color as rgb or hex - * @param {number} [itsLineStyle.width=5] the line width - * - * @param {object} [itsIconConfig=undefined] The icon subtype configuration - * @param {string} itsIconConfig.prop The property used to define icon attribute symbolization - * @param {string} itsIconConfig.defaultName The default name to be used if no other match is found - * @param {string} itsIconConfig.defaultIcon The default icon to be used for no other matches - * @param {object} [itsIconConfig.iconArray=[]] an array, items with format [property, name, img] - * - * @param {object} [itsLineConfig=undefined] The property used to define icon attribute symbolization - * @param {string} itsLineConfig.prop The property used to define icon attribute symbolization - * @param {string} [itsLineConfig.defaultName=Other] The default name to be used if no other match is found - * @param {string} [itsLineConfig.defaultColor=red] The default line color to be used for no other matches - * @param {number} [itsLineConfig.defaultWidth=5] The default line width to be used for no other matches - * @param {object} [itsLineConfig.lineArray=[]] an array, items with format [property, name, color, optional width] - * @returns {*} undefined, style, or style function - */ -function defineStyle(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig) { - "use strict"; - - checkStyleNumber(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig); - - var _iconUrlRoot = 'http://transportal.cee.wisc.edu/its/inventory/icons/'; - - if (itsIcon) { - return new _ol2.default.style.Style({ - image: new _ol2.default.style.Icon({ src: _iconUrlRoot + itsIcon }) - }); - } else if (itsLineStyle) { - return new _ol2.default.style.Style({ - stroke: new _ol2.default.style.Stroke({ - color: itsLineStyle.color, - width: itsLineStyle.width - }) - }); - } else if (itsIconConfig) { - return function (feature) { - var symbolProp = feature.getProperties()[itsIconConfig.prop]; - var iconUrl = _iconUrlRoot + itsIconConfig.defaultIcon; - for (var i = 0; i < itsIconConfig.iconArray.length; i++) { - var thisProp = itsIconConfig.iconArray[i]; + /** + * + * @param {string} [itsIcon=undefined] the ITS device type icon image see http://transportal.cee.wisc.edu/its/inventory/icons/ + * + * @param {object} [itsLineStyle=undefined] A single line style + * @param {string} itsLineStyle.color the line color as rgb or hex + * @param {number} [itsLineStyle.width=5] the line width + * + * @param {object} [itsIconConfig=undefined] The icon subtype configuration + * @param {string} itsIconConfig.prop The property used to define icon attribute symbolization + * @param {string} itsIconConfig.defaultName The default name to be used if no other match is found + * @param {string} itsIconConfig.defaultIcon The default icon to be used for no other matches + * @param {object} [itsIconConfig.iconArray=[]] an array, items with format [property, name, img] + * + * @param {object} [itsLineConfig=undefined] The property used to define icon attribute symbolization + * @param {string} itsLineConfig.prop The property used to define icon attribute symbolization + * @param {string} [itsLineConfig.defaultName=Other] The default name to be used if no other match is found + * @param {string} [itsLineConfig.defaultColor=red] The default line color to be used for no other matches + * @param {number} [itsLineConfig.defaultWidth=5] The default line width to be used for no other matches + * @param {object} [itsLineConfig.lineArray=[]] an array, items with format [property, name, color, optional width] + * @returns {*} undefined, style, or style function + */ + function defineStyle(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig) { + "use strict"; - if (symbolProp.trim().toLocaleLowerCase() == thisProp[0].trim().toLocaleLowerCase()) { - iconUrl = _iconUrlRoot + thisProp[2]; - break; - } - } + checkStyleNumber(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig); - return [new _ol2.default.style.Style({ - image: new _ol2.default.style.Icon({ src: iconUrl }) - })]; - }; - } else if (itsLineConfig) { - return function (feature) { - var symbolProp = feature.getProperties()[itsLineConfig.prop]; - var colr = itsLineConfig.defaultColor || 'red'; - var width = itsLineConfig.defaultWidth || 5; + var _iconUrlRoot = 'http://transportal.cee.wisc.edu/its/inventory/icons/'; - for (var i = 0; i < itsLineConfig.lineArray.length; i++) { - var thisProp = itsLineConfig.lineArray[i]; + if (itsIcon) { + return new _ol2.default.style.Style({ + image: new _ol2.default.style.Icon({ src: _iconUrlRoot + itsIcon }) + }); + } else if (itsLineStyle) { + return new _ol2.default.style.Style({ + stroke: new _ol2.default.style.Stroke({ + color: itsLineStyle.color, + width: itsLineStyle.width + }) + }); + } else if (itsIconConfig) { + return function (feature) { + var symbolProp = feature.getProperties()[itsIconConfig.prop]; + var iconUrl = _iconUrlRoot + itsIconConfig.defaultIcon; + + for (var i = 0; i < itsIconConfig.iconArray.length; i++) { + var thisProp = itsIconConfig.iconArray[i]; + + if (symbolProp.trim().toLocaleLowerCase() == thisProp[0].trim().toLocaleLowerCase()) { + iconUrl = _iconUrlRoot + thisProp[2]; + break; + } + } - if (symbolProp.trim().toLocaleLowerCase() == thisProp[0].trim().toLocaleLowerCase()) { - colr = thisProp[2]; - width = thisProp[3]; - break; + return [new _ol2.default.style.Style({ + image: new _ol2.default.style.Icon({ src: iconUrl }) + })]; + }; + } else if (itsLineConfig) { + return function (feature) { + var symbolProp = feature.getProperties()[itsLineConfig.prop]; + var colr = itsLineConfig.defaultColor || 'red'; + var width = itsLineConfig.defaultWidth || 5; + + for (var i = 0; i < itsLineConfig.lineArray.length; i++) { + var thisProp = itsLineConfig.lineArray[i]; + + if (symbolProp.trim().toLocaleLowerCase() == thisProp[0].trim().toLocaleLowerCase()) { + colr = thisProp[2]; + width = thisProp[3]; + break; + } } - } - return [new _ol2.default.style.Style({ - stroke: new _ol2.default.style.Stroke({ - color: colr, - width: width - }) - })]; - }; - } else { - return undefined; + return [new _ol2.default.style.Style({ + stroke: new _ol2.default.style.Stroke({ + color: colr, + width: width + }) + })]; + }; + } else { + return undefined; + } } -} - -/** - * - * @param {string} [itsIcon=undefined] the ITS device type icon image see http://transportal.cee.wisc.edu/its/inventory/icons/ - * - * @param {object} [itsLineStyle=undefined] A single line style - * @param {string} itsLineStyle.color the line color as rgb or hex - * @param {number} [itsLineStyle.width=5] the line width - * - * @param {object} [itsIconConfig=undefined] The icon subtype configuration - * @param {string} itsIconConfig.prop The property used to define icon attribute symbolization - * @param {string} itsIconConfig.defaultName The default name to be used if no other match is found - * @param {string} itsIconConfig.defaultIcon The default icon to be used for no other matches - * @param {object} [itsIconConfig.iconArray=[]] an array, items with format [property, name, img] - * - * @param {object} [itsLineConfig=undefined] The property used to define icon attribute symbolization - * @param {string} itsLineConfig.prop The property used to define icon attribute symbolization - * @param {string} [itsLineConfig.defaultName=Other] The default name to be used if no other match is found - * @param {string} [itsLineConfig.defaultColor=red] The default line color to be used for no other matches - * @param {number} [itsLineConfig.defaultWidth=5] The default line width to be used for no other matches - * @param {object} [itsLineConfig.lineArray=[]] an array, items with format [property, name, color, optional width] - * @returns {string} html to be added to the legend - */ -function defineLegend(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig) { - "use strict"; - - var iconHeight = 17; - - checkStyleNumber(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig); - - var _iconUrlRoot = 'http://transportal.cee.wisc.edu/its/inventory/icons/'; - - if (itsIcon) { - return '<img src="' + (_iconUrlRoot + itsIcon) + '" class="legend-layer-icon" height="' + iconHeight + '">'; - } else if (itsLineStyle) { - return '<hr style="height: ' + itsLineStyle.width + 'px; background-color: ' + itsLineStyle.color + '">'; - } else if (itsIconConfig) { - var outHtml = ''; - outHtml += '<ul>'; - - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = itsIconConfig.iconArray[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var a = _step.value; - - outHtml += '<li><span class="legend-layer-subitem">' + a[1] + '</span><img src="' + (_iconUrlRoot + a[2]) + '" class="legend-layer-icon" height="' + iconHeight + '">'; - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { + + /** + * + * @param {string} [itsIcon=undefined] the ITS device type icon image see http://transportal.cee.wisc.edu/its/inventory/icons/ + * + * @param {object} [itsLineStyle=undefined] A single line style + * @param {string} itsLineStyle.color the line color as rgb or hex + * @param {number} [itsLineStyle.width=5] the line width + * + * @param {object} [itsIconConfig=undefined] The icon subtype configuration + * @param {string} itsIconConfig.prop The property used to define icon attribute symbolization + * @param {string} itsIconConfig.defaultName The default name to be used if no other match is found + * @param {string} itsIconConfig.defaultIcon The default icon to be used for no other matches + * @param {object} [itsIconConfig.iconArray=[]] an array, items with format [property, name, img] + * + * @param {object} [itsLineConfig=undefined] The property used to define icon attribute symbolization + * @param {string} itsLineConfig.prop The property used to define icon attribute symbolization + * @param {string} [itsLineConfig.defaultName=Other] The default name to be used if no other match is found + * @param {string} [itsLineConfig.defaultColor=red] The default line color to be used for no other matches + * @param {number} [itsLineConfig.defaultWidth=5] The default line width to be used for no other matches + * @param {object} [itsLineConfig.lineArray=[]] an array, items with format [property, name, color, optional width] + * @returns {string} html to be added to the legend + */ + function defineLegend(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig) { + "use strict"; + + var iconHeight = 17; + + checkStyleNumber(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig); + + var _iconUrlRoot = 'http://transportal.cee.wisc.edu/its/inventory/icons/'; + + if (itsIcon) { + return '<img src="' + (_iconUrlRoot + itsIcon) + '" class="legend-layer-icon" height="' + iconHeight + '">'; + } else if (itsLineStyle) { + return '<hr style="height: ' + itsLineStyle.width + 'px; background-color: ' + itsLineStyle.color + '">'; + } else if (itsIconConfig) { + var outHtml = ''; + outHtml += '<ul>'; + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); + for (var _iterator = itsIconConfig.iconArray[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var a = _step.value; + + outHtml += '<li><span class="legend-layer-subitem">' + a[1] + '</span><img src="' + (_iconUrlRoot + a[2]) + '" class="legend-layer-icon" height="' + iconHeight + '">'; } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; } finally { - if (_didIteratorError) { - throw _iteratorError; + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } } } - } - - outHtml += '<li><span class="legend-layer-subitem">' + itsIconConfig.defaultName + '</span>' + ('<img src="' + (_iconUrlRoot + itsIconConfig.defaultIcon) + '" class="legend-layer-icon" height="' + iconHeight + '"></li>'); - outHtml += '</ul>'; - return outHtml; - } else if (itsLineConfig) { - var _outHtml = ''; - _outHtml += '<ul>'; - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; + outHtml += '<li><span class="legend-layer-subitem">' + itsIconConfig.defaultName + '</span>' + ('<img src="' + (_iconUrlRoot + itsIconConfig.defaultIcon) + '" class="legend-layer-icon" height="' + iconHeight + '"></li>'); + outHtml += '</ul>'; - try { - for (var _iterator2 = itsLineConfig.lineArray[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var ls = _step2.value; + return outHtml; + } else if (itsLineConfig) { + var _outHtml = ''; + _outHtml += '<ul>'; + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; - _outHtml += '<li><span class="legend-layer-subitem">' + ls[1] + '</span>' + ('<hr style="height: ' + ls[3] + 'px; background-color: ' + ls[2] + '">'); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { try { - if (!_iteratorNormalCompletion2 && _iterator2.return) { - _iterator2.return(); + for (var _iterator2 = itsLineConfig.lineArray[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var ls = _step2.value; + + _outHtml += '<li><span class="legend-layer-subitem">' + ls[1] + '</span>' + ('<hr style="height: ' + ls[3] + 'px; background-color: ' + ls[2] + '">'); } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; } finally { - if (_didIteratorError2) { - throw _iteratorError2; + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } } } - } - _outHtml += '<li><span class="legend-layer-subitem">' + itsLineConfig.defaultName + '</span>' + ('<hr style="height: ' + itsLineConfig.defaultWidth + 'px; background-color: ' + itsLineConfig.defaultColor + '"></li>'); - _outHtml += '</ul>'; + _outHtml += '<li><span class="legend-layer-subitem">' + itsLineConfig.defaultName + '</span>' + ('<hr style="height: ' + itsLineConfig.defaultWidth + 'px; background-color: ' + itsLineConfig.defaultColor + '"></li>'); + _outHtml += '</ul>'; - return _outHtml; - } else { - return ''; + return _outHtml; + } else { + return ''; + } } -} - -/** - * Its Layer class - * @augments LayerBaseVectorGeoJson - */ - -var LayerItsInventory = (function (_LayerBaseVectorGeoJs) { - _inherits(LayerItsInventory, _LayerBaseVectorGeoJs); /** - * ITS device layer, types available at http://transportal.cee.wisc.edu/its/inventory/ - * @param {object} options - config - * @param {string} [options.id] - layer id - * @param {string} [options.name=Unnamed Layer] - layer name - * @param {number} [options.opacity=1] - opacity - * @param {boolean} [options.visible=true] - default visible - * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 - * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 - * @param {object} [options.params={}] the get parameters to include to retrieve the layer - * @param {number} [options.zIndex=0] the z index for the layer - * @param {function} [options.loadCallback] function to call on load, context this is the layer object - * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed - * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility - * @param {boolean} [options.legendContent] additional content to add to the legend - * - * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible - * @param {object|*} [options.style=undefined] the layer style, use openlayers default style if not defined - * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move - * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called - * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages - * - * @param {string} options.itsType the ITS device type, use the url flag at http://transportal.cee.wisc.edu/its/inventory/ - * @param {boolean} [options.addPopup=true] if the popup should be added automatically - * - * @param {string} [options.itsIcon=undefined] the ITS device type icon image see http://transportal.cee.wisc.edu/its/inventory/icons/ - * - * @param {object} [options.itsLineStyle=undefined] A single line style - * @param {string} options.itsLineStyle.color the line color as rgb or hex - * @param {number} [options.itsLineStyle.width=5] the line width - * - * @param {object} [options.itsIconConfig=undefined] The icon subtype configuration - * @param {string} options.itsIconConfig.prop The property used to define icon attribute symbolization - * @param {string} options.itsIconConfig.defaultName The default name to be used if no other match is found - * @param {string} options.itsIconConfig.defaultIcon The default icon to be used for no other matches - * @param {object} [options.itsIconConfig.iconArray=[]] an array, items with format [property, name, img] - * - * @param {object} [options.itsLineConfig=undefined] The property used to define icon attribute symbolization - * @param {string} options.itsLineConfig.prop The property used to define icon attribute symbolization - * @param {string} [options.itsLineConfig.defaultName=Other] The default name to be used if no other match is found - * @param {string} [options.itsLineConfig.defaultColor=red] The default line color to be used for no other matches - * @param {number} [options.itsLineConfig.defaultWidth] The default line width to be used for no other matches - * @param {object} [options.itsLineConfig.lineArray=[]] an array, items with format [property, name, color, optional width = 5] + * Its Layer class + * @augments LayerBaseVectorGeoJson */ - function LayerItsInventory(options) { - _classCallCheck(this, LayerItsInventory); - - if (typeof options.itsType !== 'string') { - throw 'its type must be defined'; - } - - var addToLegend = ''; + var LayerItsInventory = function (_LayerBaseVectorGeoJs) { + _inherits(LayerItsInventory, _LayerBaseVectorGeoJs); + + /** + * ITS device layer, types available at http://transportal.cee.wisc.edu/its/inventory/ + * @param {object} options - config + * @param {string} [options.id] - layer id + * @param {string} [options.name=Unnamed Layer] - layer name + * @param {number} [options.opacity=1] - opacity + * @param {boolean} [options.visible=true] - default visible + * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 + * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 + * @param {object} [options.params={}] the get parameters to include to retrieve the layer + * @param {number} [options.zIndex=0] the z index for the layer + * @param {function} [options.loadCallback] function to call on load, context this is the layer object + * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed + * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility + * @param {boolean} [options.legendContent] additional content to add to the legend + * + * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible + * @param {object|*} [options.style=undefined] the layer style, use openlayers default style if not defined + * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move + * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called + * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages + * + * @param {string} options.itsType the ITS device type, use the url flag at http://transportal.cee.wisc.edu/its/inventory/ + * @param {boolean} [options.addPopup=true] if the popup should be added automatically + * + * @param {string} [options.itsIcon=undefined] the ITS device type icon image see http://transportal.cee.wisc.edu/its/inventory/icons/ + * + * @param {object} [options.itsLineStyle=undefined] A single line style + * @param {string} options.itsLineStyle.color the line color as rgb or hex + * @param {number} [options.itsLineStyle.width=5] the line width + * + * @param {object} [options.itsIconConfig=undefined] The icon subtype configuration + * @param {string} options.itsIconConfig.prop The property used to define icon attribute symbolization + * @param {string} options.itsIconConfig.defaultName The default name to be used if no other match is found + * @param {string} options.itsIconConfig.defaultIcon The default icon to be used for no other matches + * @param {object} [options.itsIconConfig.iconArray=[]] an array, items with format [property, name, img] + * + * @param {object} [options.itsLineConfig=undefined] The property used to define icon attribute symbolization + * @param {string} options.itsLineConfig.prop The property used to define icon attribute symbolization + * @param {string} [options.itsLineConfig.defaultName=Other] The default name to be used if no other match is found + * @param {string} [options.itsLineConfig.defaultColor=red] The default line color to be used for no other matches + * @param {number} [options.itsLineConfig.defaultWidth] The default line width to be used for no other matches + * @param {object} [options.itsLineConfig.lineArray=[]] an array, items with format [property, name, color, optional width = 5] + */ + + function LayerItsInventory(options) { + _classCallCheck(this, LayerItsInventory); + + if (typeof options.itsType !== 'string') { + throw 'its type must be defined'; + } - // define a style with the helper function if it is not explicitly defined - if (typeof options.style == 'undefined') { - options.style = defineStyle(options.itsIcon, options.itsLineStyle, options.itsIconConfig, options.itsLineConfig); - addToLegend = defineLegend(options.itsIcon, options.itsLineStyle, options.itsIconConfig, options.itsLineConfig); - } + var addToLegend = ''; - options.params = _typeof(options.params) == 'object' ? options.params : {}; - _jquery2.default.extend(options.params, { format: 'JSON', resource: options.itsType }); + // define a style with the helper function if it is not explicitly defined + if (typeof options.style == 'undefined') { + options.style = defineStyle(options.itsIcon, options.itsLineStyle, options.itsIconConfig, options.itsLineConfig); + addToLegend = defineLegend(options.itsIcon, options.itsLineStyle, options.itsIconConfig, options.itsLineConfig); + } - //add any additional content to the legend + options.params = _typeof(options.params) == 'object' ? options.params : {}; + _jquery2.default.extend(options.params, { format: 'JSON', resource: options.itsType }); - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerItsInventory).call(this, 'http://transportal.cee.wisc.edu/its/inventory/', options)); + var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerItsInventory).call(this, 'http://transportal.cee.wisc.edu/its/inventory/', options)); - _this.addLegendContent(addToLegend); + //add any additional content to the legend + _this.addLegendContent(addToLegend); - options.addPopup = typeof options.addPopup == 'boolean' ? options.addPopup : true; + options.addPopup = typeof options.addPopup == 'boolean' ? options.addPopup : true; - if (options.addPopup) { - _mapPopup2.default.addVectorPopup(_this, function (props) { - return '<iframe src="http://transportal.cee.wisc.edu/its/inventory/?feature=' + props['featureGuid'] + '" ' + 'height="250" width="350"></iframe>'; - }); + if (options.addPopup) { + _mapPopup2.default.addVectorPopup(_this, function (props) { + return '<iframe src="http://transportal.cee.wisc.edu/its/inventory/?feature=' + props['featureGuid'] + '" ' + 'height="250" width="350"></iframe>'; + }); + } + return _this; } - return _this; - } - /** - * callback to generate the parameters passed in the get request - * @callback makeGetParams - * @param {object} extent - extent object - * @param {number} extent.minX - minX - * @param {number} extent.minY - minY - * @param {number} extent.maxX - maxX - * @param {number} extent.maxY - maxY - * @param {number} zoomLevel - zoom level - */ - - _createClass(LayerItsInventory, [{ - key: 'mapMoveMakeGetParams', - value: function mapMoveMakeGetParams(extent, zoomLevel) { - _get(Object.getPrototypeOf(LayerItsInventory.prototype), 'mapMoveMakeGetParams', this).call(this, extent, zoomLevel); - var lowerLeft = new _ol2.default.geom.Point([extent.minX, extent.minY]); - lowerLeft.transform(this.mapCrs, "EPSG:4326"); - var lowerLeftCoordinates = lowerLeft.getCoordinates(); - var upperRight = new _ol2.default.geom.Point([extent.maxX, extent.maxY]); - upperRight.transform(this.mapCrs, "EPSG:4326"); - var upperRightCoordinates = upperRight.getCoordinates(); - - _jquery2.default.extend(this.mapMoveParams, { - L: lowerLeftCoordinates[0], - R: upperRightCoordinates[0], - B: lowerLeftCoordinates[1], - T: upperRightCoordinates[1] - }); - } - }]); + /** + * callback to generate the parameters passed in the get request + * @callback makeGetParams + * @param {object} extent - extent object + * @param {number} extent.minX - minX + * @param {number} extent.minY - minY + * @param {number} extent.maxX - maxX + * @param {number} extent.maxY - maxY + * @param {number} zoomLevel - zoom level + */ + + + _createClass(LayerItsInventory, [{ + key: 'mapMoveMakeGetParams', + value: function mapMoveMakeGetParams(extent, zoomLevel) { + _get(Object.getPrototypeOf(LayerItsInventory.prototype), 'mapMoveMakeGetParams', this).call(this, extent, zoomLevel); + var lowerLeft = new _ol2.default.geom.Point([extent.minX, extent.minY]); + lowerLeft.transform(this.mapCrs, "EPSG:4326"); + var lowerLeftCoordinates = lowerLeft.getCoordinates(); + var upperRight = new _ol2.default.geom.Point([extent.maxX, extent.maxY]); + upperRight.transform(this.mapCrs, "EPSG:4326"); + var upperRightCoordinates = upperRight.getCoordinates(); + + _jquery2.default.extend(this.mapMoveParams, { + L: lowerLeftCoordinates[0], + R: upperRightCoordinates[0], + B: lowerLeftCoordinates[1], + T: upperRightCoordinates[1] + }); + } + }]); - return LayerItsInventory; -})(_LayerBaseVectorGeoJson2.default); + return LayerItsInventory; + }(_LayerBaseVectorGeoJson2.default); -nm.LayerItsInventory = LayerItsInventory; -exports.default = LayerItsInventory; -module.exports = exports['default']; \ No newline at end of file + nm.LayerItsInventory = LayerItsInventory; + exports.default = LayerItsInventory; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/layers/LayerRealEarthTile.js b/lib/layers/LayerRealEarthTile.js index d697a03bdab107e57b7a409d112b51634f60f1d9..9915a5647f4ff8017d9add9dcb34d9b29f06ff97 100644 --- a/lib/layers/LayerRealEarthTile.js +++ b/lib/layers/LayerRealEarthTile.js @@ -1,91 +1,122 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); - -var _LayerBaseXyzTile2 = require('./LayerBaseXyzTile'); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', './LayerBaseXyzTile', '../mixin/RealEarthAnimateTile', '../util/provide', 'es6-mixins'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('./LayerBaseXyzTile'), require('../mixin/RealEarthAnimateTile'), require('../util/provide'), require('es6-mixins')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.LayerBaseXyzTile, global.RealEarthAnimateTile, global.provide, global.es6Mixins); + global.LayerRealEarthTile = mod.exports; + } +})(this, function (module, exports, _jquery, _LayerBaseXyzTile2, _RealEarthAnimateTile, _provide, mixIns) { + 'use strict'; -var _LayerBaseXyzTile3 = _interopRequireDefault(_LayerBaseXyzTile2); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _RealEarthAnimateTile = require('../mixin/RealEarthAnimateTile'); + var _jquery2 = _interopRequireDefault(_jquery); -var _RealEarthAnimateTile2 = _interopRequireDefault(_RealEarthAnimateTile); + var _LayerBaseXyzTile3 = _interopRequireDefault(_LayerBaseXyzTile2); -var _provide = require('../util/provide'); + var _RealEarthAnimateTile2 = _interopRequireDefault(_RealEarthAnimateTile); -var _provide2 = _interopRequireDefault(_provide); + var _provide2 = _interopRequireDefault(_provide); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** - * Created by gavorhes on 11/4/2015. - */ + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -var mixIns = require('es6-mixins'); -var nm = (0, _provide2.default)('layers'); + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } -/** - * Real earth tile - * @augments LayerBaseXyzTile - */ + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } -var LayerRealEarthTile = (function (_LayerBaseXyzTile) { - _inherits(LayerRealEarthTile, _LayerBaseXyzTile); + var nm = (0, _provide2.default)('layers'); /** - * The base layer for all others - * @param {object} options - config - * @param {string} [options.id] - layer id - * @param {string} [options.name=Unnamed Layer] - layer name - * @param {number} [options.opacity=1] - opacity - * @param {boolean} [options.visible=true] - default visible - * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 - * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 - * @param {object} [options.params={}] the get parameters to include to retrieve the layer - * @param {number} [options.zIndex=0] the z index for the layer - * @param {function} [options.loadCallback] function to call on load, context this is the layer object - * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed - * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility - * @param {boolean} [options.legendContent] additional content to add to the legend - * - * @param {string} options.products - the products to request - * @param {boolean} [options.hasTimes=false] If the layer is time dependent, fixed set of dates - * @param {boolean} [options.animate=false] if the layer should be animated + * Real earth tile + * @augments LayerBaseXyzTile */ - function LayerRealEarthTile(options) { - _classCallCheck(this, LayerRealEarthTile); - - options.animate = typeof options.animate == 'boolean' ? options.animate : false; - if (!options.animate) { - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerRealEarthTile).call(this, 'http://realearth.ssec.wisc.edu/api/image?products=' + options.products + '&x={x}&y={y}&z={z}', options)); - - _this._products = options.products; - } else { - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerRealEarthTile).call(this, '', options)); - - _this._products = options.products; - - if (!_this.timeInit) { - mixIns([_RealEarthAnimateTile2.default], _this); + var LayerRealEarthTile = function (_LayerBaseXyzTile) { + _inherits(LayerRealEarthTile, _LayerBaseXyzTile); + + /** + * The base layer for all others + * @param {object} options - config + * @param {string} [options.id] - layer id + * @param {string} [options.name=Unnamed Layer] - layer name + * @param {number} [options.opacity=1] - opacity + * @param {boolean} [options.visible=true] - default visible + * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 + * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 + * @param {object} [options.params={}] the get parameters to include to retrieve the layer + * @param {number} [options.zIndex=0] the z index for the layer + * @param {function} [options.loadCallback] function to call on load, context this is the layer object + * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed + * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility + * @param {boolean} [options.legendContent] additional content to add to the legend + * + * @param {string} options.products - the products to request + * @param {boolean} [options.hasTimes=false] If the layer is time dependent, fixed set of dates + * @param {boolean} [options.animate=false] if the layer should be animated + */ + + function LayerRealEarthTile(options) { + _classCallCheck(this, LayerRealEarthTile); + + options.animate = typeof options.animate == 'boolean' ? options.animate : false; + if (!options.animate) { + var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerRealEarthTile).call(this, 'http://realearth.ssec.wisc.edu/api/image?products=' + options.products + '&x={x}&y={y}&z={z}', options)); + + _this._products = options.products; + } else { + var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerRealEarthTile).call(this, '', options)); + + _this._products = options.products; + + if (!_this.timeInit) { + mixIns([_RealEarthAnimateTile2.default], _this); + } + _this.timeInit(); } - _this.timeInit(); + return _possibleConstructorReturn(_this); } - return _possibleConstructorReturn(_this); - } - return LayerRealEarthTile; -})(_LayerBaseXyzTile3.default); + return LayerRealEarthTile; + }(_LayerBaseXyzTile3.default); -nm.LayerRealEarthTile = LayerRealEarthTile; -exports.default = LayerRealEarthTile; -module.exports = exports['default']; \ No newline at end of file + nm.LayerRealEarthTile = LayerRealEarthTile; + exports.default = LayerRealEarthTile; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/layers/LayerRealEarthVector.js b/lib/layers/LayerRealEarthVector.js index ac7404414c752034d22a7c1edcaef34cc5f3cd2f..97b669c5fe9b3b565a9779a1d4231b347d36aee9 100644 --- a/lib/layers/LayerRealEarthVector.js +++ b/lib/layers/LayerRealEarthVector.js @@ -1,97 +1,130 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _LayerBaseVectorGeoJson = require('./LayerBaseVectorGeoJson'); - -var _LayerBaseVectorGeoJson2 = _interopRequireDefault(_LayerBaseVectorGeoJson); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', './LayerBaseVectorGeoJson', '../mixin/RealEarthAnimateVector', '../util/provide', 'es6-mixins'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./LayerBaseVectorGeoJson'), require('../mixin/RealEarthAnimateVector'), require('../util/provide'), require('es6-mixins')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.LayerBaseVectorGeoJson, global.RealEarthAnimateVector, global.provide, global.es6Mixins); + global.LayerRealEarthVector = mod.exports; + } +})(this, function (module, exports, _LayerBaseVectorGeoJson, _RealEarthAnimateVector, _provide, mixIns) { + 'use strict'; -var _RealEarthAnimateVector = require('../mixin/RealEarthAnimateVector'); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _RealEarthAnimateVector2 = _interopRequireDefault(_RealEarthAnimateVector); + var _LayerBaseVectorGeoJson2 = _interopRequireDefault(_LayerBaseVectorGeoJson); -var _provide = require('../util/provide'); + var _RealEarthAnimateVector2 = _interopRequireDefault(_RealEarthAnimateVector); -var _provide2 = _interopRequireDefault(_provide); + var _provide2 = _interopRequireDefault(_provide); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** - * Created by gavorhes on 11/13/2015. - */ + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -var mixIns = require('es6-mixins'); -var nm = (0, _provide2.default)('layers'); + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } -/** - * Vector real earth vector - * @augments LayerBaseVectorGeoJson - */ + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } -var LayerVectorRealEarth = (function (_LayerBaseVectorGeoJs) { - _inherits(LayerVectorRealEarth, _LayerBaseVectorGeoJs); + var nm = (0, _provide2.default)('layers'); /** - * Real Earth vector layer - * @param {object} options - config - * @param {string} [options.id] - layer id - * @param {string} [options.name=Unnamed Layer] - layer name - * @param {number} [options.opacity=1] - opacity - * @param {boolean} [options.visible=true] - default visible - * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 - * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 - * @param {object} [options.params={}] the get parameters to include to retrieve the layer - * @param {number} [options.zIndex=0] the z index for the layer - * @param {function} [options.loadCallback] function to call on load, context this is the layer object - * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed - * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility - * @param {boolean} [options.legendContent] additional content to add to the legend - * - * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible - * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined - * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move - * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called - * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages - * - * @param {object} [options.transform={}] SR transform, set as false for no transform - * @param {string} options.transform.dataProjection=EPSG:4326 the data CRS - * @param {string} options.transform.featureProjection=EPSG:3857 the feature/map CRS - * - * @param {string} options.products real earth products identifier - * @param {boolean} [options.animate=false] if the layer should be animated + * Vector real earth vector + * @augments LayerBaseVectorGeoJson */ - function LayerVectorRealEarth(options) { - _classCallCheck(this, LayerVectorRealEarth); - - options.animate = typeof options.animate == 'boolean' ? options.animate : false; - if (!options.animate) { - options.params = { products: options.products }; - - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerVectorRealEarth).call(this, 'http://realearth.ssec.wisc.edu/api/shapes', options)); - } else { - options.autoLoad = false; - - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerVectorRealEarth).call(this, '', options)); - - _this._products = options.products; - if (!_this.timeInit) { - mixIns([_RealEarthAnimateVector2.default], _this); + var LayerVectorRealEarth = function (_LayerBaseVectorGeoJs) { + _inherits(LayerVectorRealEarth, _LayerBaseVectorGeoJs); + + /** + * Real Earth vector layer + * @param {object} options - config + * @param {string} [options.id] - layer id + * @param {string} [options.name=Unnamed Layer] - layer name + * @param {number} [options.opacity=1] - opacity + * @param {boolean} [options.visible=true] - default visible + * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28 + * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28 + * @param {object} [options.params={}] the get parameters to include to retrieve the layer + * @param {number} [options.zIndex=0] the z index for the layer + * @param {function} [options.loadCallback] function to call on load, context this is the layer object + * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed + * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility + * @param {boolean} [options.legendContent] additional content to add to the legend + * + * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible + * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined + * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move + * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called + * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages + * + * @param {object} [options.transform={}] SR transform, set as false for no transform + * @param {string} options.transform.dataProjection=EPSG:4326 the data CRS + * @param {string} options.transform.featureProjection=EPSG:3857 the feature/map CRS + * + * @param {string} options.products real earth products identifier + * @param {boolean} [options.animate=false] if the layer should be animated + */ + + function LayerVectorRealEarth(options) { + _classCallCheck(this, LayerVectorRealEarth); + + options.animate = typeof options.animate == 'boolean' ? options.animate : false; + if (!options.animate) { + options.params = { products: options.products }; + + var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerVectorRealEarth).call(this, 'http://realearth.ssec.wisc.edu/api/shapes', options)); + } else { + options.autoLoad = false; + + var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(LayerVectorRealEarth).call(this, '', options)); + + _this._products = options.products; + if (!_this.timeInit) { + mixIns([_RealEarthAnimateVector2.default], _this); + } + _this.timeInit(); } - _this.timeInit(); + return _possibleConstructorReturn(_this); } - return _possibleConstructorReturn(_this); - } - return LayerVectorRealEarth; -})(_LayerBaseVectorGeoJson2.default); + return LayerVectorRealEarth; + }(_LayerBaseVectorGeoJson2.default); -nm.LayerVectorRealEarth = LayerVectorRealEarth; -exports.default = LayerVectorRealEarth; -module.exports = exports['default']; \ No newline at end of file + nm.LayerVectorRealEarth = LayerVectorRealEarth; + exports.default = LayerVectorRealEarth; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/mixin/RealEarthAnimate.js b/lib/mixin/RealEarthAnimate.js index 10d592c016b24b32caa73b0febdb90add90c0f5a..2d684287a6b8cf447f7369d6435d3a4c79a79218 100644 --- a/lib/mixin/RealEarthAnimate.js +++ b/lib/mixin/RealEarthAnimate.js @@ -1,192 +1,187 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); /** - * Created by gavorhes on 12/4/2015. - */ - -var _provide = require('../util/provide'); - -var _provide2 = _interopRequireDefault(_provide); - -var _mapPopup = require('../olHelpers/mapPopup'); - -var _mapPopup2 = _interopRequireDefault(_mapPopup); - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../util/provide', '../olHelpers/mapPopup', '../jquery'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../util/provide'), require('../olHelpers/mapPopup'), require('../jquery')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.provide, global.mapPopup, global.jquery); + global.RealEarthAnimate = mod.exports; + } +})(this, function (module, exports, _provide, _mapPopup, _jquery) { + 'use strict'; -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + Object.defineProperty(exports, "__esModule", { + value: true + }); -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + var _provide2 = _interopRequireDefault(_provide); -var nm = (0, _provide2.default)('mixin'); + var _mapPopup2 = _interopRequireDefault(_mapPopup); -/** - * The GMT offset time in minutes - * @type {number} - */ -var offsetMinutes = new Date().getTimezoneOffset(); + var _jquery2 = _interopRequireDefault(_jquery); -/** - * Mixin to get the product times - * Be sure to call getTimeInit after the mixin has been applied - */ + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var RealEarthAnimate = (function () { - function RealEarthAnimate() { - _classCallCheck(this, RealEarthAnimate); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } } - _createClass(RealEarthAnimate, [{ - key: 'load', - - /** - * override base layer load - */ - value: function load() {} - }, { - key: 'timeInit', - - /** - * Call this after the mixin has been applied - */ - value: function timeInit() { - if (!this._products) { - throw 'this mixin must be applied to one of the RealEarth layer objects with this.products defined'; + 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); } - - this._rawDateStrings = []; - this._localDates = []; - this.localTimes = []; - this._animateEnabled = true; - this._loaded = true; - this._currentTime = undefined; - this._currentIndex = undefined; - - var _this = this; - - _jquery2.default.get('http://realearth.ssec.wisc.edu/api/products', { products: this._products }, function (d) { - if (d.length == 0) { - console.log(this._products + ' layer not available or does not have times'); - - return; - } - d = d[0]; - for (var i = 0; i < d['times'].length; i++) { - _this._loadDates.call(_this, d['times'][i]); - } - _this.loadCallback.call(_this); - _this._loadLatest.call(_this); - }, 'json'); } - /** - * - * @returns {boolean} if animation enabled - */ - - }, { - key: '_loadDates', - - /** - * Given the raw time string, add to the arrays to keep track of dates and cache - * @param {string} inString - input string to parse - * @returns {string} the converted string - * @protected - */ - value: function _loadDates(inString) { - var yr = inString.slice(0, 4); - var month = inString.slice(4, 6); - var d = inString.slice(6, 8); - var hr = inString.slice(9, 11); - var mn = inString.slice(11, 13); - var sec = inString.slice(13, 15); - - var rawDateStr = inString.replace('.', '_'); - this._rawDateStrings.push(rawDateStr); - - var dteStr = month + '/' + d + '/' + yr + ' ' + hr + ':' + mn + ':' + sec; - var newDte = new Date(dteStr); - newDte.setMinutes(newDte.getMinutes() - offsetMinutes); - this._localDates.push(newDte); - this.localTimes.push(newDte.getTime()); - - return rawDateStr; + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + var nm = (0, _provide2.default)('mixin'); + + /** + * The GMT offset time in minutes + * @type {number} + */ + var offsetMinutes = new Date().getTimezoneOffset(); + + /** + * Mixin to get the product times + * Be sure to call getTimeInit after the mixin has been applied + */ + + var RealEarthAnimate = function () { + function RealEarthAnimate() { + _classCallCheck(this, RealEarthAnimate); } - /** - * - * @protected - * @returns {boolean} if should continue - */ - - }, { - key: '_loadLatest', - value: function _loadLatest() { - _mapPopup2.default.closePopup(); - if (this.localTimes.length > 0) { - this._currentIndex = this.localTimes.length - 1; - - return true; - } else { - return false; + _createClass(RealEarthAnimate, [{ + key: 'load', + value: function load() {} + }, { + key: 'timeInit', + value: function timeInit() { + if (!this._products) { + throw 'this mixin must be applied to one of the RealEarth layer objects with this.products defined'; + } + + this._rawDateStrings = []; + this._localDates = []; + this.localTimes = []; + this._animateEnabled = true; + this._loaded = true; + this._currentTime = undefined; + this._currentIndex = undefined; + + var _this = this; + + _jquery2.default.get('http://realearth.ssec.wisc.edu/api/products', { products: this._products }, function (d) { + if (d.length == 0) { + console.log(this._products + ' layer not available or does not have times'); + + return; + } + d = d[0]; + for (var i = 0; i < d['times'].length; i++) { + _this._loadDates.call(_this, d['times'][i]); + } + _this.loadCallback.call(_this); + _this._loadLatest.call(_this); + }, 'json'); } - } + }, { + key: '_loadDates', + value: function _loadDates(inString) { + var yr = inString.slice(0, 4); + var month = inString.slice(4, 6); + var d = inString.slice(6, 8); + var hr = inString.slice(9, 11); + var mn = inString.slice(11, 13); + var sec = inString.slice(13, 15); + + var rawDateStr = inString.replace('.', '_'); + this._rawDateStrings.push(rawDateStr); + + var dteStr = month + '/' + d + '/' + yr + ' ' + hr + ':' + mn + ':' + sec; + var newDte = new Date(dteStr); + newDte.setMinutes(newDte.getMinutes() - offsetMinutes); + this._localDates.push(newDte); + this.localTimes.push(newDte.getTime()); + + return rawDateStr; + } + }, { + key: '_loadLatest', + value: function _loadLatest() { + _mapPopup2.default.closePopup(); + if (this.localTimes.length > 0) { + this._currentIndex = this.localTimes.length - 1; - /** - * - * @param {number} theTime - the time - * @returns {boolean} true if new index, false if the same or below lowest value - */ - - }, { - key: 'setLayerTime', - value: function setLayerTime(theTime) { - if (!this.visible) { - return false; + return true; + } else { + return false; + } } + }, { + key: 'setLayerTime', + value: function setLayerTime(theTime) { + if (!this.visible) { + return false; + } - this._currentTime = theTime; + this._currentTime = theTime; - var newIndex = undefined; + var newIndex = void 0; - if (theTime < this.localTimes[0]) { - return false; - } else if (theTime > this.localTimes[this.localTimes.length - 1]) { - newIndex = this.localTimes.length - 1; - } + if (theTime < this.localTimes[0]) { + return false; + } else if (theTime > this.localTimes[this.localTimes.length - 1]) { + newIndex = this.localTimes.length - 1; + } - for (var i = 0; i < this.localTimes.length; i++) { - if (this.localTimes[i] >= theTime) { - newIndex = i; - break; + for (var i = 0; i < this.localTimes.length; i++) { + if (this.localTimes[i] >= theTime) { + newIndex = i; + break; + } } - } - if (newIndex == this._currentIndex) { - return false; - } else { - this._currentIndex = newIndex; - _mapPopup2.default.closePopup(); + if (newIndex == this._currentIndex) { + return false; + } else { + this._currentIndex = newIndex; + _mapPopup2.default.closePopup(); - return true; + return true; + } } - } - }, { - key: 'animationEnabled', - get: function get() { - return this._animateEnabled; - } - }]); + }, { + key: 'animationEnabled', + get: function get() { + return this._animateEnabled; + } + }]); - return RealEarthAnimate; -})(); + return RealEarthAnimate; + }(); -nm.RealEarthAnimate = RealEarthAnimate; -exports.default = RealEarthAnimate; -module.exports = exports['default']; \ No newline at end of file + nm.RealEarthAnimate = RealEarthAnimate; + exports.default = RealEarthAnimate; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/mixin/RealEarthAnimateTile.js b/lib/mixin/RealEarthAnimateTile.js index 60effdb6f4c722121f9a50335a487ee8b3324ae9..de4f60aadb67097b7b87de34f6b5a6b89290531f 100644 --- a/lib/mixin/RealEarthAnimateTile.js +++ b/lib/mixin/RealEarthAnimateTile.js @@ -1,98 +1,164 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', './RealEarthAnimate', '../util/provide'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./RealEarthAnimate'), require('../util/provide')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.RealEarthAnimate, global.provide); + global.RealEarthAnimateTile = mod.exports; + } +})(this, function (module, exports, _RealEarthAnimate2, _provide) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); + Object.defineProperty(exports, "__esModule", { + value: true + }); -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; }; })(); + var _RealEarthAnimate3 = _interopRequireDefault(_RealEarthAnimate2); -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + var _provide2 = _interopRequireDefault(_provide); -var _RealEarthAnimate2 = require('./RealEarthAnimate'); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var _RealEarthAnimate3 = _interopRequireDefault(_RealEarthAnimate2); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -var _provide = require('../util/provide'); + 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); + } + } -var _provide2 = _interopRequireDefault(_provide); + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** - * Created by gavorhes on 12/4/2015. - */ + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); -var nm = (0, _provide2.default)('mixin'); + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; -/** - * Animate real earth tile - * @augments RealEarthAnimate - */ + if (getter === undefined) { + return undefined; + } -var RealEarthAnimateTile = (function (_RealEarthAnimate) { - _inherits(RealEarthAnimateTile, _RealEarthAnimate); + return getter.call(receiver); + } + }; - function RealEarthAnimateTile() { - _classCallCheck(this, RealEarthAnimateTile); + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } - return _possibleConstructorReturn(this, Object.getPrototypeOf(RealEarthAnimateTile).apply(this, arguments)); + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - _createClass(RealEarthAnimateTile, [{ - key: 'load', + var nm = (0, _provide2.default)('mixin'); - /** - * override base layer load - */ - value: function load() { - _get(Object.getPrototypeOf(RealEarthAnimateTile.prototype), 'load', this).call(this); - } - }, { - key: 'timeInit', - value: function timeInit() { - _get(Object.getPrototypeOf(RealEarthAnimateTile.prototype), 'timeInit', this).call(this); - this._sourceUrls = []; - } - }, { - key: '_loadDates', - value: function _loadDates(inString) { - var rawDte = _get(Object.getPrototypeOf(RealEarthAnimateTile.prototype), '_loadDates', this).call(this, inString); - var dteProductUrl = 'http://realearth.ssec.wisc.edu/api/image?products=' + this._products + '_' + rawDte + '&x={x}&y={y}&z={z}'; - this._sourceUrls.push(dteProductUrl); - } + /** + * Animate real earth tile + * @augments RealEarthAnimate + */ - /** - * @protected - */ + var RealEarthAnimateTile = function (_RealEarthAnimate) { + _inherits(RealEarthAnimateTile, _RealEarthAnimate); - }, { - key: '_loadLatest', - value: function _loadLatest() { - if (_get(Object.getPrototypeOf(RealEarthAnimateTile.prototype), '_loadLatest', this).call(this)) { - this._source.setUrl(this._sourceUrls[this._sourceUrls.length - 1]); - } + function RealEarthAnimateTile() { + _classCallCheck(this, RealEarthAnimateTile); + + return _possibleConstructorReturn(this, Object.getPrototypeOf(RealEarthAnimateTile).apply(this, arguments)); } - }, { - key: 'setLayerTime', - value: function setLayerTime(theTime) { - if (_get(Object.getPrototypeOf(RealEarthAnimateTile.prototype), 'setLayerTime', this).call(this, theTime)) { - if (this.olLayer.getZIndex() < 0) { - this.olLayer.setZIndex(0); + + _createClass(RealEarthAnimateTile, [{ + key: 'load', + value: function load() { + _get(Object.getPrototypeOf(RealEarthAnimateTile.prototype), 'load', this).call(this); + } + }, { + key: 'timeInit', + value: function timeInit() { + _get(Object.getPrototypeOf(RealEarthAnimateTile.prototype), 'timeInit', this).call(this); + this._sourceUrls = []; + } + }, { + key: '_loadDates', + value: function _loadDates(inString) { + var rawDte = _get(Object.getPrototypeOf(RealEarthAnimateTile.prototype), '_loadDates', this).call(this, inString); + var dteProductUrl = 'http://realearth.ssec.wisc.edu/api/image?products=' + this._products + '_' + rawDte + '&x={x}&y={y}&z={z}'; + this._sourceUrls.push(dteProductUrl); + } + }, { + key: '_loadLatest', + value: function _loadLatest() { + if (_get(Object.getPrototypeOf(RealEarthAnimateTile.prototype), '_loadLatest', this).call(this)) { + this._source.setUrl(this._sourceUrls[this._sourceUrls.length - 1]); } - this._source.setUrl(this._sourceUrls[this._currentIndex]); - } else { - this.olLayer.setZIndex(-1); } - } - }]); + }, { + key: 'setLayerTime', + value: function setLayerTime(theTime) { + if (_get(Object.getPrototypeOf(RealEarthAnimateTile.prototype), 'setLayerTime', this).call(this, theTime)) { + if (this.olLayer.getZIndex() < 0) { + this.olLayer.setZIndex(0); + } + this._source.setUrl(this._sourceUrls[this._currentIndex]); + } else { + this.olLayer.setZIndex(-1); + } + } + }]); - return RealEarthAnimateTile; -})(_RealEarthAnimate3.default); + return RealEarthAnimateTile; + }(_RealEarthAnimate3.default); -nm.RealEarthAnimateTile = RealEarthAnimateTile; -exports.default = RealEarthAnimateTile; -module.exports = exports['default']; \ No newline at end of file + nm.RealEarthAnimateTile = RealEarthAnimateTile; + exports.default = RealEarthAnimateTile; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/mixin/RealEarthAnimateVector.js b/lib/mixin/RealEarthAnimateVector.js index b1084d3c63dd3c86c624730e60886caf1db38f97..56541c749f994fe1eecd0c418489bf7d927efa4c 100644 --- a/lib/mixin/RealEarthAnimateVector.js +++ b/lib/mixin/RealEarthAnimateVector.js @@ -1,156 +1,185 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', './RealEarthAnimate', '../util/provide', 'jquery'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./RealEarthAnimate'), require('../util/provide'), require('jquery')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.RealEarthAnimate, global.provide, global.jquery); + global.RealEarthAnimateVector = mod.exports; + } +})(this, function (module, exports, _RealEarthAnimate2, _provide, $) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); + Object.defineProperty(exports, "__esModule", { + value: true + }); -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; }; })(); + var _RealEarthAnimate3 = _interopRequireDefault(_RealEarthAnimate2); -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + var _provide2 = _interopRequireDefault(_provide); -var _RealEarthAnimate2 = require('./RealEarthAnimate'); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var _RealEarthAnimate3 = _interopRequireDefault(_RealEarthAnimate2); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -var _provide = require('../util/provide'); + 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); + } + } -var _provide2 = _interopRequireDefault(_provide); + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** - * Created by gavorhes on 12/4/2015. - */ + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); -var nm = (0, _provide2.default)('mixin'); -var $ = require('jquery'); + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; -/** - * class mixin to animate RealEarth vector layers - * @augments RealEarthAnimate - */ + if (getter === undefined) { + return undefined; + } -var RealEarthAnimateVector = (function (_RealEarthAnimate) { - _inherits(RealEarthAnimateVector, _RealEarthAnimate); + return getter.call(receiver); + } + }; - function RealEarthAnimateVector() { - _classCallCheck(this, RealEarthAnimateVector); + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } - return _possibleConstructorReturn(this, Object.getPrototypeOf(RealEarthAnimateVector).apply(this, arguments)); + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } - _createClass(RealEarthAnimateVector, [{ - key: 'load', + var nm = (0, _provide2.default)('mixin'); - /** - * override base layer load - */ - value: function load() { - _get(Object.getPrototypeOf(RealEarthAnimateVector.prototype), 'load', this).call(this); - } - }, { - key: 'timeInit', - - /** - * Call this after the mixin has been applied - */ - value: function timeInit() { - _get(Object.getPrototypeOf(RealEarthAnimateVector.prototype), 'timeInit', this).call(this); - this._rawTimesLookup = {}; - this._dataCache = []; - } + var RealEarthAnimateVector = function (_RealEarthAnimate) { + _inherits(RealEarthAnimateVector, _RealEarthAnimate); - /** - * Given the raw time string, add to the arrays to keep track of dates and cache - * @param {string} inString - input date string - * @protected - */ - - }, { - key: '_loadDates', - value: function _loadDates(inString) { - var rawDte = _get(Object.getPrototypeOf(RealEarthAnimateVector.prototype), '_loadDates', this).call(this, inString); - this._dataCache.push(null); - this._rawTimesLookup[rawDte] = null; - } + function RealEarthAnimateVector() { + _classCallCheck(this, RealEarthAnimateVector); - /** - * @protected - */ + return _possibleConstructorReturn(this, Object.getPrototypeOf(RealEarthAnimateVector).apply(this, arguments)); + } - }, { - key: '_loadLatest', - value: function _loadLatest() { - if (_get(Object.getPrototypeOf(RealEarthAnimateVector.prototype), '_loadLatest', this).call(this)) { - this._loadAtTimeIndex.call(this, this._currentIndex); + _createClass(RealEarthAnimateVector, [{ + key: 'load', + value: function load() { + _get(Object.getPrototypeOf(RealEarthAnimateVector.prototype), 'load', this).call(this); } - } - // - //http://realearth.ssec.wisc.edu/api/image?products=nexrhres_20160108_212500&x=1&y=5&z=4 - // - // 20160108.205500 - // http://realearth.ssec.wisc.edu/api/image?products=nexrhres_20160108_205500&x=34&y=46&z=7 - - /** - * Load the features at the date index specified - * @param {number} i the index of the features to be loaded by date - * @param {boolean} [setAsSource=true] set to false to trigger cache load only - * @private - */ - - }, { - key: '_loadAtTimeIndex', - value: function _loadAtTimeIndex(i, setAsSource) { - var _this3 = this; - - setAsSource = typeof setAsSource == 'boolean' ? setAsSource : true; - if (this._dataCache[i] != null) { - this.source.clear(); - this._loadFeatures(this._dataCache[i]); - } else { - (function () { - var _this = _this3; - $.get('http://realearth.ssec.wisc.edu:80/api/shapes', { products: _this3._products + '_' + _this3._rawDateStrings[i] }, function (d) { - _this._dataCache[i] = d; - _this._rawTimesLookup[_this._rawDateStrings[i]] = d; - if (setAsSource) { - _this.source.clear(); - _this._loadFeatures.call(_this, _this._dataCache[i]); - } - }, 'json'); - })(); + }, { + key: 'timeInit', + value: function timeInit() { + _get(Object.getPrototypeOf(RealEarthAnimateVector.prototype), 'timeInit', this).call(this); + this._rawTimesLookup = {}; + this._dataCache = []; } - } - - /** - * helper to load the features at the index specified - * @param {object} geojObj - the geojson object - * @private - */ - - }, { - key: '_loadFeatures', - value: function _loadFeatures(geojObj) { - this.source.addFeatures(this._geoJsonFormat.readFeatures(geojObj, this._transform)); - } - }, { - key: 'setLayerTime', - value: function setLayerTime(theTime) { - if (_get(Object.getPrototypeOf(RealEarthAnimateVector.prototype), 'setLayerTime', this).call(this, theTime)) { - this._loadAtTimeIndex(this._currentIndex); - } else { - this.source.clear(); + }, { + key: '_loadDates', + value: function _loadDates(inString) { + var rawDte = _get(Object.getPrototypeOf(RealEarthAnimateVector.prototype), '_loadDates', this).call(this, inString); + this._dataCache.push(null); + this._rawTimesLookup[rawDte] = null; } - } - }]); + }, { + key: '_loadLatest', + value: function _loadLatest() { + if (_get(Object.getPrototypeOf(RealEarthAnimateVector.prototype), '_loadLatest', this).call(this)) { + this._loadAtTimeIndex.call(this, this._currentIndex); + } + } + }, { + key: '_loadAtTimeIndex', + value: function _loadAtTimeIndex(i, setAsSource) { + var _this3 = this; + + setAsSource = typeof setAsSource == 'boolean' ? setAsSource : true; + if (this._dataCache[i] != null) { + this.source.clear(); + this._loadFeatures(this._dataCache[i]); + } else { + (function () { + var _this = _this3; + $.get('http://realearth.ssec.wisc.edu:80/api/shapes', { products: _this3._products + '_' + _this3._rawDateStrings[i] }, function (d) { + _this._dataCache[i] = d; + _this._rawTimesLookup[_this._rawDateStrings[i]] = d; + if (setAsSource) { + _this.source.clear(); + _this._loadFeatures.call(_this, _this._dataCache[i]); + } + }, 'json'); + })(); + } + } + }, { + key: '_loadFeatures', + value: function _loadFeatures(geojObj) { + this.source.addFeatures(this._geoJsonFormat.readFeatures(geojObj, this._transform)); + } + }, { + key: 'setLayerTime', + value: function setLayerTime(theTime) { + if (_get(Object.getPrototypeOf(RealEarthAnimateVector.prototype), 'setLayerTime', this).call(this, theTime)) { + this._loadAtTimeIndex(this._currentIndex); + } else { + this.source.clear(); + } + } + }]); - return RealEarthAnimateVector; -})(_RealEarthAnimate3.default); + return RealEarthAnimateVector; + }(_RealEarthAnimate3.default); -nm.RealEarthAnimateVector = RealEarthAnimateVector; -exports.default = RealEarthAnimateVector; -module.exports = exports['default']; \ No newline at end of file + nm.RealEarthAnimateVector = RealEarthAnimateVector; + exports.default = RealEarthAnimateVector; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/ol/ol.js b/lib/ol/ol.js index 5230dce847e9ba600116dcd8b1f50e6654bbd52d..9766fd48114ad0583c91296275afc7459466a8b4 100644 --- a/lib/ol/ol.js +++ b/lib/ol/ol.js @@ -1,9 +1,21 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', './ol-build'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./ol-build')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.olBuild); + global.ol = mod.exports; + } +})(this, function (module, exports, ol) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); -var ol = require('./ol-build'); - -exports.default = ol; -module.exports = exports['default']; \ No newline at end of file + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.default = ol; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/SortedFeatures.js b/lib/olHelpers/SortedFeatures.js index 4294b620ad9a0a85f499e00711d09e1b11f745f0..953e5fb80d82842697ff56a19e100700540b7519 100644 --- a/lib/olHelpers/SortedFeatures.js +++ b/lib/olHelpers/SortedFeatures.js @@ -1,136 +1,175 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); /** - * Created by gavorhes on 12/23/2015. - */ +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../util/provide'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../util/provide')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.provide); + global.SortedFeatures = mod.exports; + } +})(this, function (module, exports, _provide) { + 'use strict'; -var _provide = require('../util/provide'); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _provide2 = _interopRequireDefault(_provide); + var _provide2 = _interopRequireDefault(_provide); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } + 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; + }; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -var nm = (0, _provide2.default)('olHelpers'); + 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); + } + } -/** - * take an array of features and sort by a given property name - */ + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); -var SortedFeatures = (function () { + var nm = (0, _provide2.default)('olHelpers'); /** - * - * @param {Array<ol.Feature>} features array of ol features - * @param {string} propertyName - the property name to use for lookup + * take an array of features and sort by a given property name */ - function SortedFeatures(features, propertyName) { - var _this2 = this; + var SortedFeatures = function () { - _classCallCheck(this, SortedFeatures); + /** + * + * @param {Array<ol.Feature>} features array of ol features + * @param {string} propertyName - the property name to use for lookup + */ - this.sortedFeatures = features; - this.propertyName = propertyName; + function SortedFeatures(features, propertyName) { + var _this2 = this; - if (this.sortedFeatures.length > 0) { - (function () { - _this2._propertyType = _typeof(_this2.sortedFeatures[0].getProperties()[_this2.propertyName]); + _classCallCheck(this, SortedFeatures); - var _this = _this2; - _this2.sortedFeatures.sort(function (a, b) { - if (_this._propertyType == 'number') { - return a['getProperties']()[_this.propertyName] - b['getProperties']()[_this.propertyName]; - } else if (_this._propertyType == 'string') { - return a['getProperties']()[_this.propertyName] > b['getProperties']()[_this.propertyName]; - } - }); - })(); - } - } + this.sortedFeatures = features; + this.propertyName = propertyName; - /** - * recursive search to find the value - * @param {number|string} propertyValue - the property value to search for - * @param {boolean} [exactMatch=false] if only an exact match should be returned - * @param {Array} [sortedFeatures=this.sortedFeatures] - the candidate features - * @returns {ol.Feature|undefined} the feature matching the lookup - */ + if (this.sortedFeatures.length > 0) { + (function () { + _this2._propertyType = _typeof(_this2.sortedFeatures[0].getProperties()[_this2.propertyName]); - _createClass(SortedFeatures, [{ - key: 'getFeature', - value: function getFeature(propertyValue, exactMatch, sortedFeatures) { - if (typeof sortedFeatures == 'undefined') { - sortedFeatures = this.sortedFeatures; + var _this = _this2; + _this2.sortedFeatures.sort(function (a, b) { + if (_this._propertyType == 'number') { + return a['getProperties']()[_this.propertyName] - b['getProperties']()[_this.propertyName]; + } else if (_this._propertyType == 'string') { + return a['getProperties']()[_this.propertyName] > b['getProperties']()[_this.propertyName]; + } + }); + })(); } + } - if (typeof exactMatch !== 'boolean') { - exactMatch = false; - } + /** + * recursive search to find the value + * @param {number|string} propertyValue - the property value to search for + * @param {boolean} [exactMatch=false] if only an exact match should be returned + * @param {Array} [sortedFeatures=this.sortedFeatures] - the candidate features + * @returns {ol.Feature|undefined} the feature matching the lookup + */ - if (sortedFeatures.length == 0) { - return undefined; - } - if (sortedFeatures.length == 1) { + _createClass(SortedFeatures, [{ + key: 'getFeature', + value: function getFeature(propertyValue, exactMatch, sortedFeatures) { + if (typeof sortedFeatures == 'undefined') { + sortedFeatures = this.sortedFeatures; + } + + if (typeof exactMatch !== 'boolean') { + exactMatch = false; + } + + if (sortedFeatures.length == 0) { + return undefined; + } + + if (sortedFeatures.length == 1) { + if (exactMatch) { + if (sortedFeatures[0].getProperties()[this.propertyName] == propertyValue) { + return sortedFeatures[0]; + } else { + return undefined; + } + } else { + return sortedFeatures[0]; + } + } + + var lowProp = sortedFeatures[0].getProperties()[this.propertyName]; + var highProp = sortedFeatures[sortedFeatures.length - 1].getProperties()[this.propertyName]; + if (exactMatch) { - if (sortedFeatures[0].getProperties()[this.propertyName] == propertyValue) { + if (lowProp == propertyValue) { return sortedFeatures[0]; - } else { + } else if (propertyValue < lowProp) { + return undefined; + } else if (highProp == propertyValue) { + return sortedFeatures[sortedFeatures.length - 1]; + } else if (propertyValue > highProp) { return undefined; } } else { - return sortedFeatures[0]; + if (propertyValue <= lowProp) { + return sortedFeatures[0]; + } else if (propertyValue >= highProp) { + return sortedFeatures[sortedFeatures.length - 1]; + } } - } - var lowProp = sortedFeatures[0].getProperties()[this.propertyName]; - var highProp = sortedFeatures[sortedFeatures.length - 1].getProperties()[this.propertyName]; + var midIndex = Math.floor(sortedFeatures.length / 2); + var midFeature = sortedFeatures[midIndex]; + var midProperty = midFeature.getProperties()[this.propertyName]; - if (exactMatch) { - if (lowProp == propertyValue) { - return sortedFeatures[0]; - } else if (propertyValue < lowProp) { - return undefined; - } else if (highProp == propertyValue) { - return sortedFeatures[sortedFeatures.length - 1]; - } else if (propertyValue > highProp) { - return undefined; + if (midProperty === propertyValue) { + return midFeature; } - } else { - if (propertyValue <= lowProp) { - return sortedFeatures[0]; - } else if (propertyValue >= highProp) { - return sortedFeatures[sortedFeatures.length - 1]; - } - } - - var midIndex = Math.floor(sortedFeatures.length / 2); - var midFeature = sortedFeatures[midIndex]; - var midProperty = midFeature.getProperties()[this.propertyName]; - if (midProperty === propertyValue) { - return midFeature; - } - - if (propertyValue < midProperty) { - return this.getFeature(propertyValue, exactMatch, sortedFeatures.slice(0, midIndex)); - } else { - return this.getFeature(propertyValue, exactMatch, sortedFeatures.slice(midIndex)); + if (propertyValue < midProperty) { + return this.getFeature(propertyValue, exactMatch, sortedFeatures.slice(0, midIndex)); + } else { + return this.getFeature(propertyValue, exactMatch, sortedFeatures.slice(midIndex)); + } } - } - }]); + }]); - return SortedFeatures; -})(); + return SortedFeatures; + }(); -nm.SortedFeatures = SortedFeatures; -exports.default = SortedFeatures; -module.exports = exports['default']; \ No newline at end of file + nm.SortedFeatures = SortedFeatures; + exports.default = SortedFeatures; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/esriToOlStyle.js b/lib/olHelpers/esriToOlStyle.js index da6cfbc7f89280401845cf58fd3363336da80ed4..354e6327cfa2b1a1275caa67fc9373a7d61b281a 100644 --- a/lib/olHelpers/esriToOlStyle.js +++ b/lib/olHelpers/esriToOlStyle.js @@ -1,476 +1,511 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['exports', '../util/provide', '../ol/ol'], factory); + } else if (typeof exports !== "undefined") { + factory(exports, require('../util/provide'), require('../ol/ol')); + } else { + var mod = { + exports: {} + }; + factory(mod.exports, global.provide, global.ol); + global.esriToOlStyle = mod.exports; + } +})(this, function (exports, _provide, _ol) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.makeFeatureServiceLegendAndSymbol = makeFeatureServiceLegendAndSymbol; -exports.makeMapServiceLegend = makeMapServiceLegend; + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.makeFeatureServiceLegendAndSymbol = makeFeatureServiceLegendAndSymbol; + exports.makeMapServiceLegend = makeMapServiceLegend; -var _provide = require('../util/provide'); + var _provide2 = _interopRequireDefault(_provide); -var _provide2 = _interopRequireDefault(_provide); + var _ol2 = _interopRequireDefault(_ol); -var _ol = require('../ol/ol'); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var _ol2 = _interopRequireDefault(_ol); + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** - * Created by gavorhes on 1/4/2016. - */ + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -var nm = (0, _provide2.default)('olHelpers.esriToOlStyle'); + var nm = (0, _provide2.default)('olHelpers.esriToOlStyle'); -/** - * This callback is displayed as part of the Requester class. - * @callback styleFunc - * @param {ol.Feature} feat - openlayers feature - * @param {number} resolution - map resolution - */ + /** + * This callback is displayed as part of the Requester class. + * @callback styleFunc + * @param {ol.Feature} feat - openlayers feature + * @param {number} resolution - map resolution + */ -/** - * - * @param {Array<number>} colorArray - input color array - * @param {number} opacity - the opacity 0 to 1 - * @returns {string} rgba string - * @private - */ -function _colorArrayToRgba(colorArray, opacity) { - "use strict"; + /** + * + * @param {Array<number>} colorArray - input color array + * @param {number} opacity - the opacity 0 to 1 + * @returns {string} rgba string + * @private + */ + function _colorArrayToRgba(colorArray, opacity) { + "use strict"; - return 'rgba(' + colorArray[0] + ',' + colorArray[1] + ',' + colorArray[2] + ',' + opacity + ')'; -} + return 'rgba(' + colorArray[0] + ',' + colorArray[1] + ',' + colorArray[2] + ',' + opacity + ')'; + } -/** - * escape html charcters - * @param {string} str - input string - * @returns {string} escaped string - */ -function htmlEscape(str) { - return String(str).replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>'); -} + /** + * escape html charcters + * @param {string} str - input string + * @returns {string} escaped string + */ + function htmlEscape(str) { + return String(str).replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>'); + } -nm.htmlEscape = htmlEscape; + nm.htmlEscape = htmlEscape; -var CommonSymbol = + var CommonSymbol = -/** - * - * @param symbolObj - * @param {number} opacity - */ -function CommonSymbol(symbolObj, opacity) { - _classCallCheck(this, CommonSymbol); + /** + * + * @param symbolObj + * @param {number} opacity + */ + function CommonSymbol(symbolObj, opacity) { + _classCallCheck(this, CommonSymbol); + + this.symbolObj = symbolObj; + this.opacity = opacity; + this.olStyle = undefined; + this.legendHtml = ''; + }; + + var PointSymbol = function (_CommonSymbol) { + _inherits(PointSymbol, _CommonSymbol); + + function PointSymbol(symbolObj, opacity) { + _classCallCheck(this, PointSymbol); + + var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(PointSymbol).call(this, symbolObj, opacity)); + + switch (_this2.symbolObj['type']) { + case 'esriSMS': + var innerColor = _colorArrayToRgba(_this2.symbolObj.color, _this2.opacity); + var outerColor = _colorArrayToRgba(_this2.symbolObj.outline.color, _this2.opacity); + var outlineWidth = _this2.symbolObj.outline.width; + var radius = _this2.symbolObj.size; + + _this2.olStyle = new _ol2.default.style.Style({ + image: new _ol2.default.style.Circle({ + radius: radius, + fill: new _ol2.default.style.Fill({ + color: innerColor + }), + stroke: new _ol2.default.style.Stroke({ color: outerColor, width: outlineWidth }) + }) + }); + _this2.legendHtml = '<span class="legend-layer-icon" style="color: ' + innerColor + '">●</span>'; + break; + case 'esriPMS': + _this2.olStyle = new _ol2.default.style.Style({ + image: new _ol2.default.style.Icon({ src: 'data:image/png;base64,' + _this2.symbolObj['imageData'] }) + }); + _this2.legendHtml = '<img class="legend-layer-icon" height="17" src="data:image/png;base64,' + _this2.symbolObj['imageData'] + '">'; + break; + default: + console.log(_this2.symbolObj); + alert('Point symbol does not handle symbol type: ' + _this2.symbolObj['type']); + } + return _this2; + } - this.symbolObj = symbolObj; - this.opacity = opacity; - this.olStyle = undefined; - this.legendHtml = ''; -}; + return PointSymbol; + }(CommonSymbol); + + var LineSymbol = function (_CommonSymbol2) { + _inherits(LineSymbol, _CommonSymbol2); + + function LineSymbol(symbolObj, opacity) { + _classCallCheck(this, LineSymbol); + + var _this3 = _possibleConstructorReturn(this, Object.getPrototypeOf(LineSymbol).call(this, symbolObj, opacity)); + + switch (_this3.symbolObj['type']) { + case 'esriSLS': + var innerColor = _colorArrayToRgba(_this3.symbolObj.color, _this3.opacity); + var lineWidth = _this3.symbolObj.width; + + _this3.olStyle = new _ol2.default.style.Style({ + stroke: new _ol2.default.style.Stroke({ + color: innerColor, + //lineDash: [4], + width: lineWidth + }) + }); + + _this3.legendHtml = '<span class="legend-layer-icon" '; + _this3.legendHtml += 'style="'; + _this3.legendHtml += 'background-color: ' + innerColor + ';'; + _this3.legendHtml += 'width: 40px;'; + _this3.legendHtml += 'height: 4px;'; + _this3.legendHtml += 'position: relative;'; + _this3.legendHtml += 'display: inline-block;'; + _this3.legendHtml += 'top: -1px;'; + _this3.legendHtml += '"></span>'; + break; + default: + console.log(_this3.symbolObj); + alert('Line symbol does not handle symbol type: ' + _this3.symbolObj['type']); + } + return _this3; + } -var PointSymbol = (function (_CommonSymbol) { - _inherits(PointSymbol, _CommonSymbol); + return LineSymbol; + }(CommonSymbol); - function PointSymbol(symbolObj, opacity) { - _classCallCheck(this, PointSymbol); + var PolygonSymbol = function (_CommonSymbol3) { + _inherits(PolygonSymbol, _CommonSymbol3); - var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(PointSymbol).call(this, symbolObj, opacity)); + function PolygonSymbol(symbolObj, opacity) { + _classCallCheck(this, PolygonSymbol); - switch (_this2.symbolObj['type']) { - case 'esriSMS': - var innerColor = _colorArrayToRgba(_this2.symbolObj.color, _this2.opacity); - var outerColor = _colorArrayToRgba(_this2.symbolObj.outline.color, _this2.opacity); - var outlineWidth = _this2.symbolObj.outline.width; - var radius = _this2.symbolObj.size; + var _this4 = _possibleConstructorReturn(this, Object.getPrototypeOf(PolygonSymbol).call(this, symbolObj, opacity)); - _this2.olStyle = new _ol2.default.style.Style({ - image: new _ol2.default.style.Circle({ - radius: radius, + switch (_this4.symbolObj['type']) { + case 'esriSFS': + var innerColor = _colorArrayToRgba(_this4.symbolObj.color, _this4.opacity); + var outerColor = _colorArrayToRgba(_this4.symbolObj.outline.color, _this4.opacity); + var outlineWidth = _this4.symbolObj.outline.width; + + _this4.olStyle = new _ol2.default.style.Style({ + stroke: new _ol2.default.style.Stroke({ + color: outerColor, + //lineDash: [4], + width: outlineWidth + }), fill: new _ol2.default.style.Fill({ color: innerColor - }), - stroke: new _ol2.default.style.Stroke({ color: outerColor, width: outlineWidth }) - }) - }); - _this2.legendHtml = '<span class="legend-layer-icon" style="color: ' + innerColor + '">●</span>'; - break; - case 'esriPMS': - _this2.olStyle = new _ol2.default.style.Style({ - image: new _ol2.default.style.Icon({ src: 'data:image/png;base64,' + _this2.symbolObj['imageData'] }) - }); - _this2.legendHtml = '<img class="legend-layer-icon" height="17" src="data:image/png;base64,' + _this2.symbolObj['imageData'] + '">'; - break; - default: - console.log(_this2.symbolObj); - alert('Point symbol does not handle symbol type: ' + _this2.symbolObj['type']); - } - return _this2; - } - - return PointSymbol; -})(CommonSymbol); - -var LineSymbol = (function (_CommonSymbol2) { - _inherits(LineSymbol, _CommonSymbol2); - - function LineSymbol(symbolObj, opacity) { - _classCallCheck(this, LineSymbol); - - var _this3 = _possibleConstructorReturn(this, Object.getPrototypeOf(LineSymbol).call(this, symbolObj, opacity)); - - switch (_this3.symbolObj['type']) { - case 'esriSLS': - var innerColor = _colorArrayToRgba(_this3.symbolObj.color, _this3.opacity); - var lineWidth = _this3.symbolObj.width; - - _this3.olStyle = new _ol2.default.style.Style({ - stroke: new _ol2.default.style.Stroke({ - color: innerColor, - //lineDash: [4], - width: lineWidth - }) - }); - - _this3.legendHtml = '<span class="legend-layer-icon" '; - _this3.legendHtml += 'style="'; - _this3.legendHtml += 'background-color: ' + innerColor + ';'; - _this3.legendHtml += 'width: 40px;'; - _this3.legendHtml += 'height: 4px;'; - _this3.legendHtml += 'position: relative;'; - _this3.legendHtml += 'display: inline-block;'; - _this3.legendHtml += 'top: -1px;'; - _this3.legendHtml += '"></span>'; - break; - default: - console.log(_this3.symbolObj); - alert('Line symbol does not handle symbol type: ' + _this3.symbolObj['type']); - } - return _this3; - } - - return LineSymbol; -})(CommonSymbol); - -var PolygonSymbol = (function (_CommonSymbol3) { - _inherits(PolygonSymbol, _CommonSymbol3); - - function PolygonSymbol(symbolObj, opacity) { - _classCallCheck(this, PolygonSymbol); - - var _this4 = _possibleConstructorReturn(this, Object.getPrototypeOf(PolygonSymbol).call(this, symbolObj, opacity)); - - switch (_this4.symbolObj['type']) { - case 'esriSFS': - var innerColor = _colorArrayToRgba(_this4.symbolObj.color, _this4.opacity); - var outerColor = _colorArrayToRgba(_this4.symbolObj.outline.color, _this4.opacity); - var outlineWidth = _this4.symbolObj.outline.width; - - _this4.olStyle = new _ol2.default.style.Style({ - stroke: new _ol2.default.style.Stroke({ - color: outerColor, - //lineDash: [4], - width: outlineWidth - }), - fill: new _ol2.default.style.Fill({ - color: innerColor - }) - }); - - _this4.legendHtml = '<span class="legend-layer-icon" '; - _this4.legendHtml += 'style="'; - _this4.legendHtml += 'background-color: ' + innerColor + ';'; - _this4.legendHtml += 'border: solid ' + outerColor + ' 1px;'; - _this4.legendHtml += 'width: 40px;'; - _this4.legendHtml += 'height: 9px;'; - _this4.legendHtml += 'position: relative;'; - _this4.legendHtml += 'display: inline-block;'; - _this4.legendHtml += 'top: 2px;'; - _this4.legendHtml += '"></span>'; - break; + }) + }); + + _this4.legendHtml = '<span class="legend-layer-icon" '; + _this4.legendHtml += 'style="'; + _this4.legendHtml += 'background-color: ' + innerColor + ';'; + _this4.legendHtml += 'border: solid ' + outerColor + ' 1px;'; + _this4.legendHtml += 'width: 40px;'; + _this4.legendHtml += 'height: 9px;'; + _this4.legendHtml += 'position: relative;'; + _this4.legendHtml += 'display: inline-block;'; + _this4.legendHtml += 'top: 2px;'; + _this4.legendHtml += '"></span>'; + break; - default: - console.log(_this4.symbolObj); - alert('Polygon symbol does handle symbol type: ' + _this4.symbolObj['type']); + default: + console.log(_this4.symbolObj); + alert('Polygon symbol does handle symbol type: ' + _this4.symbolObj['type']); + } + return _this4; } - return _this4; - } - return PolygonSymbol; -})(CommonSymbol); + return PolygonSymbol; + }(CommonSymbol); -var SymbolGenerator = function SymbolGenerator(esriResponse) { - _classCallCheck(this, SymbolGenerator); + var SymbolGenerator = function SymbolGenerator(esriResponse) { + _classCallCheck(this, SymbolGenerator); - this.opacity = (100 - (esriResponse['drawingInfo']['transparency'] || 0)) / 100; - this.renderer = esriResponse['drawingInfo']['renderer']; - this.olStyle = undefined; - this.legendHtml = ''; -}; + this.opacity = (100 - (esriResponse['drawingInfo']['transparency'] || 0)) / 100; + this.renderer = esriResponse['drawingInfo']['renderer']; + this.olStyle = undefined; + this.legendHtml = ''; + }; -var SingleSymbol = (function (_SymbolGenerator) { - _inherits(SingleSymbol, _SymbolGenerator); + var SingleSymbol = function (_SymbolGenerator) { + _inherits(SingleSymbol, _SymbolGenerator); - /** - * - * @param {object} esriResponse - layer info - * @param {Constructor|*} SymbolClass - the symbol class to use - */ + /** + * + * @param {object} esriResponse - layer info + * @param {Constructor|*} SymbolClass - the symbol class to use + */ - function SingleSymbol(esriResponse, SymbolClass) { - _classCallCheck(this, SingleSymbol); + function SingleSymbol(esriResponse, SymbolClass) { + _classCallCheck(this, SingleSymbol); - var _this5 = _possibleConstructorReturn(this, Object.getPrototypeOf(SingleSymbol).call(this, esriResponse)); + var _this5 = _possibleConstructorReturn(this, Object.getPrototypeOf(SingleSymbol).call(this, esriResponse)); - _this5.symbol = _this5.renderer['symbol']; - var symbolObj = new SymbolClass(_this5.symbol, _this5.opacity); - _this5.olStyle = symbolObj.olStyle; - _this5.legendHtml = symbolObj.legendHtml; - return _this5; - } + _this5.symbol = _this5.renderer['symbol']; + var symbolObj = new SymbolClass(_this5.symbol, _this5.opacity); + _this5.olStyle = symbolObj.olStyle; + _this5.legendHtml = symbolObj.legendHtml; + return _this5; + } - return SingleSymbol; -})(SymbolGenerator); + return SingleSymbol; + }(SymbolGenerator); -var UniqueValueSymbol = (function (_SymbolGenerator2) { - _inherits(UniqueValueSymbol, _SymbolGenerator2); + var UniqueValueSymbol = function (_SymbolGenerator2) { + _inherits(UniqueValueSymbol, _SymbolGenerator2); - /** - * - * @param {object} esriResponse - layer info - * @param {Constructor|*} SymbolClass - the Symbol class definition - */ + /** + * + * @param {object} esriResponse - layer info + * @param {Constructor|*} SymbolClass - the Symbol class definition + */ - function UniqueValueSymbol(esriResponse, SymbolClass) { - _classCallCheck(this, UniqueValueSymbol); + function UniqueValueSymbol(esriResponse, SymbolClass) { + _classCallCheck(this, UniqueValueSymbol); - var _this6 = _possibleConstructorReturn(this, Object.getPrototypeOf(UniqueValueSymbol).call(this, esriResponse)); + var _this6 = _possibleConstructorReturn(this, Object.getPrototypeOf(UniqueValueSymbol).call(this, esriResponse)); - _this6.uniqueValueInfos = _this6.renderer['uniqueValueInfos']; - _this6.propertyName = _this6.renderer['field1']; - _this6.defaultSymbol = _this6.renderer['defaultSymbol']; + _this6.uniqueValueInfos = _this6.renderer['uniqueValueInfos']; + _this6.propertyName = _this6.renderer['field1']; + _this6.defaultSymbol = _this6.renderer['defaultSymbol']; - if (_this6.defaultSymbol) { - var symbolObj = new SymbolClass(_this6.defaultSymbol, _this6.opacity); - _this6.defaultStyle = symbolObj.olStyle; - _this6.defaultLabelHtml = '<span class="legend-layer-subitem">' + htmlEscape(_this6.renderer['defaultLabel']) + '</span>' + symbolObj.legendHtml; - } else { - _this6.defaultStyle = undefined; - _this6.defaultLabelHtml = 'other'; - } - - _this6.valueArray = []; - _this6.labelArray = []; - _this6.legendArray = []; - _this6.propertyStyleLookup = {}; + if (_this6.defaultSymbol) { + var symbolObj = new SymbolClass(_this6.defaultSymbol, _this6.opacity); + _this6.defaultStyle = symbolObj.olStyle; + _this6.defaultLabelHtml = '<span class="legend-layer-subitem">' + htmlEscape(_this6.renderer['defaultLabel']) + '</span>' + symbolObj.legendHtml; + } else { + _this6.defaultStyle = undefined; + _this6.defaultLabelHtml = 'other'; + } - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + _this6.valueArray = []; + _this6.labelArray = []; + _this6.legendArray = []; + _this6.propertyStyleLookup = {}; - try { - for (var _iterator = _this6.uniqueValueInfos[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var uniqueVal = _step.value; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; - _this6.labelArray.push(uniqueVal['label']); - _this6.valueArray.push(uniqueVal['value']); - var uniqueSym = new SymbolClass(uniqueVal.symbol, _this6.opacity); - _this6.legendArray.push('<span class="legend-layer-subitem">' + htmlEscape(uniqueVal['label']) + '</span>' + uniqueSym.legendHtml); - _this6.propertyStyleLookup[uniqueVal['value']] = uniqueSym.olStyle; - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); + for (var _iterator = _this6.uniqueValueInfos[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var uniqueVal = _step.value; + + _this6.labelArray.push(uniqueVal['label']); + _this6.valueArray.push(uniqueVal['value']); + var uniqueSym = new SymbolClass(uniqueVal.symbol, _this6.opacity); + _this6.legendArray.push('<span class="legend-layer-subitem">' + htmlEscape(uniqueVal['label']) + '</span>' + uniqueSym.legendHtml); + _this6.propertyStyleLookup[uniqueVal['value']] = uniqueSym.olStyle; } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; } finally { - if (_didIteratorError) { - throw _iteratorError; + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } } } - } - var _this = _this6; + var _this = _this6; - _this6.olStyle = function (feature, resolution) { - var checkProperties = feature.getProperties(); - var checkProperty = checkProperties[_this.propertyName]; - - var returnValue = undefined; - if (_this.propertyStyleLookup[checkProperty] !== undefined) { - returnValue = [_this.propertyStyleLookup[checkProperty]]; - } else { - returnValue = [_this.defaultStyle]; - } + _this6.olStyle = function (feature, resolution) { + var checkProperties = feature.getProperties(); + var checkProperty = checkProperties[_this.propertyName]; - return returnValue; - }; + var returnValue = void 0; + if (_this.propertyStyleLookup[checkProperty] !== undefined) { + returnValue = [_this.propertyStyleLookup[checkProperty]]; + } else { + returnValue = [_this.defaultStyle]; + } - if (_this6.defaultLabelHtml !== null) { - _this6.legendArray.push(_this6.defaultLabelHtml); - } + return returnValue; + }; - _this6.legendHtml = '<ul>'; - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; + if (_this6.defaultLabelHtml !== null) { + _this6.legendArray.push(_this6.defaultLabelHtml); + } - try { - for (var _iterator2 = _this6.legendArray[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var h = _step2.value; + _this6.legendHtml = '<ul>'; + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; - _this6.legendHtml += '<li>' + h + '</li>'; - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { try { - if (!_iteratorNormalCompletion2 && _iterator2.return) { - _iterator2.return(); + for (var _iterator2 = _this6.legendArray[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var h = _step2.value; + + _this6.legendHtml += '<li>' + h + '</li>'; } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; } finally { - if (_didIteratorError2) { - throw _iteratorError2; + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } } } + + _this6.legendHtml += '</ul>'; + return _this6; } - _this6.legendHtml += '</ul>'; - return _this6; - } + return UniqueValueSymbol; + }(SymbolGenerator); - return UniqueValueSymbol; -})(SymbolGenerator); - -/** - * style and legend object - * @typedef {object} styleAndLegend - * @property {styleFunc} style - style function - * @property {string} legend - legend content - */ - -/** - * - * @param {object} esriResponse - layer info - * @returns {styleAndLegend} style and legend object - */ - -function makeFeatureServiceLegendAndSymbol(esriResponse) { - "use strict"; - - var renderer = esriResponse['drawingInfo']['renderer']; - var symbolLegendOut = null; - - switch (renderer['type']) { - case 'simple': - switch (esriResponse['geometryType']) { - case 'esriGeometryPoint': - symbolLegendOut = new SingleSymbol(esriResponse, PointSymbol); - break; - case 'esriGeometryPolyline': - symbolLegendOut = new SingleSymbol(esriResponse, LineSymbol); - break; - case 'esriGeometryPolygon': - symbolLegendOut = new SingleSymbol(esriResponse, PolygonSymbol); - break; - default: - console.log(esriResponse); - alert(esriResponse['geometryType'] + ' not handled'); - } - break; - case 'uniqueValue': - switch (esriResponse['geometryType']) { - case 'esriGeometryPoint': - symbolLegendOut = new UniqueValueSymbol(esriResponse, PointSymbol); - break; - case 'esriGeometryPolyline': - symbolLegendOut = new UniqueValueSymbol(esriResponse, LineSymbol); - break; - case 'esriGeometryPolygon': - symbolLegendOut = new UniqueValueSymbol(esriResponse, PolygonSymbol); - break; - default: - console.log(esriResponse); - alert(esriResponse['geometryType'] + ' not handled'); - } - break; - default: - alert('not handled renderer type: ' + renderer['type']); - } + /** + * style and legend object + * @typedef {object} styleAndLegend + * @property {styleFunc} style - style function + * @property {string} legend - legend content + */ - if (symbolLegendOut == null) { - return { style: undefined, legend: '' }; - } else { - return { style: symbolLegendOut.olStyle, legend: symbolLegendOut.legendHtml }; + /** + * + * @param {object} esriResponse - layer info + * @returns {styleAndLegend} style and legend object + */ + function makeFeatureServiceLegendAndSymbol(esriResponse) { + "use strict"; + + var renderer = esriResponse['drawingInfo']['renderer']; + var symbolLegendOut = null; + + switch (renderer['type']) { + case 'simple': + switch (esriResponse['geometryType']) { + case 'esriGeometryPoint': + symbolLegendOut = new SingleSymbol(esriResponse, PointSymbol); + break; + case 'esriGeometryPolyline': + symbolLegendOut = new SingleSymbol(esriResponse, LineSymbol); + break; + case 'esriGeometryPolygon': + symbolLegendOut = new SingleSymbol(esriResponse, PolygonSymbol); + break; + default: + console.log(esriResponse); + alert(esriResponse['geometryType'] + ' not handled'); + } + break; + case 'uniqueValue': + switch (esriResponse['geometryType']) { + case 'esriGeometryPoint': + symbolLegendOut = new UniqueValueSymbol(esriResponse, PointSymbol); + break; + case 'esriGeometryPolyline': + symbolLegendOut = new UniqueValueSymbol(esriResponse, LineSymbol); + break; + case 'esriGeometryPolygon': + symbolLegendOut = new UniqueValueSymbol(esriResponse, PolygonSymbol); + break; + default: + console.log(esriResponse); + alert(esriResponse['geometryType'] + ' not handled'); + } + break; + default: + alert('not handled renderer type: ' + renderer['type']); + } + + if (symbolLegendOut == null) { + return { style: undefined, legend: '' }; + } else { + return { style: symbolLegendOut.olStyle, legend: symbolLegendOut.legendHtml }; + } } -} -nm.makeFeatureServiceLegendAndSymbol = makeFeatureServiceLegendAndSymbol; + nm.makeFeatureServiceLegendAndSymbol = makeFeatureServiceLegendAndSymbol; -/** - * - * @param {object} lyrObject - the layer as defined in the response - * @param {boolean} [iconsOnly=false] use only icons - * @returns {string} legend html - */ -function mapServiceLegendItem(lyrObject, iconsOnly) { + /** + * + * @param {object} lyrObject - the layer as defined in the response + * @param {boolean} [iconsOnly=false] use only icons + * @returns {string} legend html + */ + function mapServiceLegendItem(lyrObject, iconsOnly) { - iconsOnly = typeof iconsOnly == 'boolean' ? iconsOnly : false; - var layerName = lyrObject['layerName']; - var legendItems = lyrObject['legend']; - var legendHtml = ''; + iconsOnly = typeof iconsOnly == 'boolean' ? iconsOnly : false; + var layerName = lyrObject['layerName']; + var legendItems = lyrObject['legend']; + var legendHtml = ''; - if (legendItems.length == 1) { - legendHtml = '<img class="legend-layer-icon" height="17" src="data:image/png;base64,' + legendItems[0]['imageData'] + '">'; - } else { - legendHtml += '<span class="legend-items-expander" title="Expand/Collapse">▼</span><ul>'; - for (var i = 0; i < legendItems.length; i++) { - legendHtml += '<li>'; - legendHtml += '<span class="legend-layer-subitem">' + htmlEscape(legendItems[i]['label']) + '</span>'; - legendHtml += '<img class="legend-layer-icon" height="17" src="data:image/png;base64,' + legendItems[i]['imageData'] + '">'; - legendHtml += '</li>'; + if (legendItems.length == 1) { + legendHtml = '<img class="legend-layer-icon" height="17" src="data:image/png;base64,' + legendItems[0]['imageData'] + '">'; + } else { + legendHtml += '<span class="legend-items-expander" title="Expand/Collapse">▼</span><ul>'; + for (var i = 0; i < legendItems.length; i++) { + legendHtml += '<li>'; + legendHtml += '<span class="legend-layer-subitem">' + htmlEscape(legendItems[i]['label']) + '</span>'; + legendHtml += '<img class="legend-layer-icon" height="17" src="data:image/png;base64,' + legendItems[i]['imageData'] + '">'; + legendHtml += '</li>'; + } + legendHtml += '</ul>'; } - legendHtml += '</ul>'; - } - if (!iconsOnly) { - legendHtml = '<span class="legend-layer-subitem">' + layerName + '</span>' + legendHtml; - } + if (!iconsOnly) { + legendHtml = '<span class="legend-layer-subitem">' + layerName + '</span>' + legendHtml; + } - return legendHtml; -} + return legendHtml; + } -/** - * make map service legent - * @param {object} esriResponse - layer info - * @returns {string} legend content - */ -function makeMapServiceLegend(esriResponse) { - "use strict"; + /** + * make map service legent + * @param {object} esriResponse - layer info + * @returns {string} legend content + */ + function makeMapServiceLegend(esriResponse) { + "use strict"; - var newLegendHtml = ''; + var newLegendHtml = ''; - var layers = esriResponse['layers']; + var layers = esriResponse['layers']; - if (layers.length == 1) { - newLegendHtml += mapServiceLegendItem(layers[0], true); - } else { - newLegendHtml += '<ul>'; - for (var i = 0; i < layers.length; i++) { - newLegendHtml += '<li>' + mapServiceLegendItem(layers[i]) + '</li>'; + if (layers.length == 1) { + newLegendHtml += mapServiceLegendItem(layers[0], true); + } else { + newLegendHtml += '<ul>'; + for (var i = 0; i < layers.length; i++) { + newLegendHtml += '<li>' + mapServiceLegendItem(layers[i]) + '</li>'; + } + newLegendHtml += '</ul>'; } - newLegendHtml += '</ul>'; - } - return newLegendHtml; -} + return newLegendHtml; + } -nm.makeMapServiceLegend = makeMapServiceLegend; \ No newline at end of file + nm.makeMapServiceLegend = makeMapServiceLegend; +}); \ No newline at end of file diff --git a/lib/olHelpers/mapInteractionBase.js b/lib/olHelpers/mapInteractionBase.js index 22d93cc8d466e2c86087dd76bd899c08be631011..8d6a6b22ab7630ddae1317e2a9ebce2a24e8f863 100644 --- a/lib/olHelpers/mapInteractionBase.js +++ b/lib/olHelpers/mapInteractionBase.js @@ -1,112 +1,125 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); /** - * Created by gavorhes on 12/8/2015. - */ - -var _provide = require('../util/provide'); - -var _provide2 = _interopRequireDefault(_provide); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../util/provide'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../util/provide')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.provide); + global.mapInteractionBase = mod.exports; + } +})(this, function (module, exports, _provide) { + 'use strict'; -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + Object.defineProperty(exports, "__esModule", { + value: true + }); -var nm = (0, _provide2.default)('olHelpers'); + var _provide2 = _interopRequireDefault(_provide); -/** - * base interaction - */ + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var MapInteractionBase = (function () { + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } - /** - * map interaction base - * @param {string} subtype - the interaction subtype - */ + 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); + } + } - function MapInteractionBase(subtype) { - _classCallCheck(this, MapInteractionBase); + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); - this._map = undefined; - this._initialized = false; - this._subtype = subtype; - } + var nm = (0, _provide2.default)('olHelpers'); /** - * base initializer, returns true for already initialized - * @param {ol.Map} theMap - the ol Map - * @returns {boolean} true for already initialized + * base interaction */ - _createClass(MapInteractionBase, [{ - key: 'init', - value: function init(theMap) { - if (!this._initialized) { - this._map = theMap; - this._initialized = true; - - return false; - } - - return true; - } + var MapInteractionBase = function () { /** - * get reference to the ol map object - * @returns {ol.Map} the map object + * map interaction base + * @param {string} subtype - the interaction subtype */ - }, { - key: '_checkInit', + function MapInteractionBase(subtype) { + _classCallCheck(this, MapInteractionBase); - /** - * Check the initialization status and throw exception if not valid yet - * @protected - */ - value: function _checkInit() { - if (!this.initialized) { - var msg = this._subtype + ' object not initialized'; - alert(msg); - console.log(msg); - throw msg; - } + this._map = undefined; + this._initialized = false; + this._subtype = subtype; } /** - * Check the initialization status and throw exception if not valid yet + * base initializer, returns true for already initialized + * @param {ol.Map} theMap - the ol Map + * @returns {boolean} true for already initialized */ - }, { - key: 'checkInit', - value: function checkInit() { - this._checkInit(); - } - }, { - key: 'map', - get: function get() { - return this._map; - } - /** - * get if is initialized - * @returns {boolean} is initialized - */ + _createClass(MapInteractionBase, [{ + key: 'init', + value: function init(theMap) { + if (!this._initialized) { + this._map = theMap; + this._initialized = true; - }, { - key: 'initialized', - get: function get() { - return this._initialized; - } - }]); + return false; + } + + return true; + } + }, { + key: '_checkInit', + value: function _checkInit() { + if (!this.initialized) { + var msg = this._subtype + ' object not initialized'; + alert(msg); + console.log(msg); + throw msg; + } + } + }, { + key: 'checkInit', + value: function checkInit() { + this._checkInit(); + } + }, { + key: 'map', + get: function get() { + return this._map; + } + }, { + key: 'initialized', + get: function get() { + return this._initialized; + } + }]); - return MapInteractionBase; -})(); + return MapInteractionBase; + }(); -nm.MapInteractionBase = MapInteractionBase; -exports.default = MapInteractionBase; -module.exports = exports['default']; \ No newline at end of file + nm.MapInteractionBase = MapInteractionBase; + exports.default = MapInteractionBase; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/mapMove.js b/lib/olHelpers/mapMove.js index dfd819f2af5e0f05a014403463e13d823513a9c0..aa5a9a61a498e5c785bfd2a835bb576b80cce8f3 100644 --- a/lib/olHelpers/mapMove.js +++ b/lib/olHelpers/mapMove.js @@ -1,21 +1,30 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', './mapMoveCls'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./mapMoveCls')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.mapMoveCls); + global.mapMove = mod.exports; + } +})(this, function (module, exports, _mapMoveCls) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _mapMoveCls = require('./mapMoveCls'); + var _mapMoveCls2 = _interopRequireDefault(_mapMoveCls); -var _mapMoveCls2 = _interopRequireDefault(_mapMoveCls); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * The single map move object catch is that it is common to multimap pages - * @type {MapMoveCls} - */ -exports.default = new _mapMoveCls2.default(); /** - * Created by gavorhes on 11/3/2015. - */ - -module.exports = exports['default']; \ No newline at end of file + exports.default = new _mapMoveCls2.default(); + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/mapMoveCls.js b/lib/olHelpers/mapMoveCls.js index d039c8e29af559d86fac67cd6f37192a59046616..cf14d031fe0cd3166a5630274dd3b6381a8e47d1 100644 --- a/lib/olHelpers/mapMoveCls.js +++ b/lib/olHelpers/mapMoveCls.js @@ -1,341 +1,377 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); - -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', './mapInteractionBase', '../util/checkDefined', '../util/provide', '../util/makeGuid'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('./mapInteractionBase'), require('../util/checkDefined'), require('../util/provide'), require('../util/makeGuid')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.mapInteractionBase, global.checkDefined, global.provide, global.makeGuid); + global.mapMoveCls = mod.exports; + } +})(this, function (module, exports, _jquery, _mapInteractionBase, _checkDefined, _provide, _makeGuid) { + 'use strict'; -var _mapInteractionBase = require('./mapInteractionBase'); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _mapInteractionBase2 = _interopRequireDefault(_mapInteractionBase); + var _jquery2 = _interopRequireDefault(_jquery); -var _checkDefined = require('../util/checkDefined'); + var _mapInteractionBase2 = _interopRequireDefault(_mapInteractionBase); -var checkDefined = _interopRequireWildcard(_checkDefined); + var checkDefined = _interopRequireWildcard(_checkDefined); -var _provide = require('../util/provide'); + var _provide2 = _interopRequireDefault(_provide); -var _provide2 = _interopRequireDefault(_provide); + var _makeGuid2 = _interopRequireDefault(_makeGuid); -var _makeGuid = require('../util/makeGuid'); + function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = {}; -var _makeGuid2 = _interopRequireDefault(_makeGuid); + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; + } + } -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + newObj.default = obj; + return newObj; + } + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + 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); + } + } -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** - * Created by gavorhes on 11/3/2015. - */ + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); -var nm = (0, _provide2.default)('olHelpers'); + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -/** - * assists with map move interactions, trigger callback functions - * @augments MapInteractionBase - */ + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -var MapMoveCls = (function (_MapInteractionBase) { - _inherits(MapMoveCls, _MapInteractionBase); + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); - /** - * constructor called implicitly - */ + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); - function MapMoveCls() { - _classCallCheck(this, MapMoveCls); + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; - var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(MapMoveCls).call(this, 'map move')); + if (getter === undefined) { + return undefined; + } - _this2._arrLyrRequest = []; - _this2._arrLyrTimeout = []; - _this2._arrLayer = []; - _this2._lookupLayer = {}; + return getter.call(receiver); + } + }; - _this2._mapMoveCallbacks = []; - _this2._mapMoveCallbacksLookup = {}; - _this2._mapMoveCallbackDelays = []; - _this2._mapMoveCallbackContext = []; - _this2._mapMoveCallbackTimeout = []; + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } - _this2._mapExtent = undefined; - _this2._zoomLevel = undefined; - return _this2; + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + var nm = (0, _provide2.default)('olHelpers'); + /** - * initialize the map move object - * @param {ol.Map} theMap - the ol map + * assists with map move interactions, trigger callback functions + * @augments MapInteractionBase */ - _createClass(MapMoveCls, [{ - key: 'init', - value: function init(theMap) { - if (_get(Object.getPrototypeOf(MapMoveCls.prototype), 'init', this).call(this, theMap)) { - return; - } + var MapMoveCls = function (_MapInteractionBase) { + _inherits(MapMoveCls, _MapInteractionBase); - var _this = this; + /** + * constructor called implicitly + */ - this.map.getView().on(['change:center', 'change:resolution'], function (e) { + function MapMoveCls() { + _classCallCheck(this, MapMoveCls); - _this._updateMapExtent(); + var _this2 = _possibleConstructorReturn(this, Object.getPrototypeOf(MapMoveCls).call(this, 'map move')); - // trigger the layer updates - for (var i = 0; i < _this._arrLayer.length; i++) { - _this.triggerLyrLoad(_this._arrLayer[i], i, e.type); - } + _this2._arrLyrRequest = []; + _this2._arrLyrTimeout = []; + _this2._arrLayer = []; + _this2._lookupLayer = {}; - // trigger the map callbacks - for (var _i = 0; _i < _this._mapMoveCallbacks.length; _i++) { - _this.triggerMoveCallback(_i, e.type); - } - }); - } - }, { - key: '_updateMapExtent', - value: function _updateMapExtent() { - var theView = this.map.getView(); - this._zoomLevel = theView.getZoom(); - - var extentArray = theView.calculateExtent(this.map.getSize()); - - this._mapExtent = { - minX: extentArray[0], - minY: extentArray[1], - maxX: extentArray[2], - maxY: extentArray[3] - }; + _this2._mapMoveCallbacks = []; + _this2._mapMoveCallbacksLookup = {}; + _this2._mapMoveCallbackDelays = []; + _this2._mapMoveCallbackContext = []; + _this2._mapMoveCallbackTimeout = []; + + _this2._mapExtent = undefined; + _this2._zoomLevel = undefined; + return _this2; } /** - * return the map extent + * initialize the map move object + * @param {ol.Map} theMap - the ol map */ - }, { - key: 'triggerLyrLoad', - /** - * Trigger the layer load - * @param {LayerBaseVector|*} lyr - the layer being acted on - * @param {number} [index=undefined] - index of the layer - * @param {string|*} [eventType=undefined] the event triggering the load, as 'change:center' or 'change:resolution' - */ - value: function triggerLyrLoad(lyr, index, eventType) { - var _this3 = this; - - if (checkDefined.undefinedOrNull(lyr) && checkDefined.undefinedOrNull(index)) { - throw 'need to define lyr or index'; - } else if (checkDefined.definedAndNotNull(lyr) && checkDefined.undefinedOrNull(index)) { - index = this._arrLayer.indexOf(lyr); - } else if (checkDefined.undefinedOrNull(lyr) && checkDefined.definedAndNotNull(index)) { - lyr = this._arrLayer[index]; - } + _createClass(MapMoveCls, [{ + key: 'init', + value: function init(theMap) { + if (_get(Object.getPrototypeOf(MapMoveCls.prototype), 'init', this).call(this, theMap)) { + return; + } - // clear the timeout - if (this._arrLyrTimeout[index] != null) { - clearTimeout(this._arrLyrTimeout[index]); - this._arrLyrTimeout[index] = null; - } + var _this = this; - // abort if necessary and clear the request - if (this._arrLyrRequest[index] != null && this._arrLyrRequest[index] != 4) { - this._arrLyrRequest[index].abort(); - this._arrLyrRequest[index] = null; - } + this.map.getView().on(['change:center', 'change:resolution'], function (e) { - // dummy callback used if before load returns false - var callbackFunc = function callbackFunc() {}; - - if (lyr.mapMoveBefore(this._zoomLevel, eventType)) { - (function () { - lyr.mapMoveMakeGetParams(_this3._mapExtent, _this3._zoomLevel); - - var _this = _this3; - - callbackFunc = function callbackFunc() { - function innerFunction(theLayer, theIndex) { - var _innerThis = this; - this._arrLyrRequest[theIndex] = _jquery2.default.get(theLayer.url, theLayer.mapMoveParams, function (d) { - /** - * @type {LayerBaseVector} - */ - theLayer.mapMoveCallback(d); - theLayer.loadCallback(); - }, 'json').fail(function (jqXHR) { - if (jqXHR.statusText != 'abort') { - console.log('failed'); - console.log(theLayer.url); - console.log(theLayer.mapMoveParams); - } - }).always(function () { - _innerThis._arrLyrTimeout[theIndex] = null; - _innerThis._arrLyrRequest[theIndex] = null; - }); - } - innerFunction.call(_this, lyr, index); - }; - })(); - } else { - lyr.clear(); - } - this._arrLyrTimeout[index] = setTimeout(callbackFunc, lyr.onDemandDelay); - } + _this._updateMapExtent(); - /** - * trigger the map move call back at the given index - * @param {number} ind - the index of the layer - * @param {string|*} [eventType=undefined] the event triggering the load as 'change:center' or 'change:resolution' - * @param {string} [functionId=undefined] the function id used to reference the added callback function - */ + // trigger the layer updates + for (var i = 0; i < _this._arrLayer.length; i++) { + _this.triggerLyrLoad(_this._arrLayer[i], i, e.type); + } - }, { - key: 'triggerMoveCallback', - value: function triggerMoveCallback(ind, eventType, functionId) { - - if (typeof ind == 'undefined' && typeof functionId == 'undefined') { - throw 'either the function index or the id must be defined'; + // trigger the map callbacks + for (var _i = 0; _i < _this._mapMoveCallbacks.length; _i++) { + _this.triggerMoveCallback(_i, e.type); + } + }); } - - if (typeof ind !== 'number') { - ind = this._mapMoveCallbacks.indexOf(this._mapMoveCallbacksLookup[functionId]); + }, { + key: '_updateMapExtent', + value: function _updateMapExtent() { + var theView = this.map.getView(); + this._zoomLevel = theView.getZoom(); + + var extentArray = theView.calculateExtent(this.map.getSize()); + + this._mapExtent = { + minX: extentArray[0], + minY: extentArray[1], + maxX: extentArray[2], + maxY: extentArray[3] + }; } + }, { + key: 'triggerLyrLoad', + value: function triggerLyrLoad(lyr, index, eventType) { + var _this3 = this; + + if (checkDefined.undefinedOrNull(lyr) && checkDefined.undefinedOrNull(index)) { + throw 'need to define lyr or index'; + } else if (checkDefined.definedAndNotNull(lyr) && checkDefined.undefinedOrNull(index)) { + index = this._arrLayer.indexOf(lyr); + } else if (checkDefined.undefinedOrNull(lyr) && checkDefined.definedAndNotNull(index)) { + lyr = this._arrLayer[index]; + } - if (ind < 0) { - console.log('function not found'); + // clear the timeout + if (this._arrLyrTimeout[index] != null) { + clearTimeout(this._arrLyrTimeout[index]); + this._arrLyrTimeout[index] = null; + } - return; - } + // abort if necessary and clear the request + if (this._arrLyrRequest[index] != null && this._arrLyrRequest[index] != 4) { + this._arrLyrRequest[index].abort(); + this._arrLyrRequest[index] = null; + } - // clear the timeout - if (this._mapMoveCallbackTimeout[ind] != null) { - clearTimeout(this._mapMoveCallbackTimeout[ind]); - this._mapMoveCallbackTimeout[ind] = null; + // dummy callback used if before load returns false + var callbackFunc = function callbackFunc() {}; + + if (lyr.mapMoveBefore(this._zoomLevel, eventType)) { + (function () { + lyr.mapMoveMakeGetParams(_this3._mapExtent, _this3._zoomLevel); + + var _this = _this3; + + callbackFunc = function callbackFunc() { + function innerFunction(theLayer, theIndex) { + var _innerThis = this; + this._arrLyrRequest[theIndex] = _jquery2.default.get(theLayer.url, theLayer.mapMoveParams, function (d) { + /** + * @type {LayerBaseVector} + */ + theLayer.mapMoveCallback(d); + theLayer.loadCallback(); + }, 'json').fail(function (jqXHR) { + if (jqXHR.statusText != 'abort') { + console.log('failed'); + console.log(theLayer.url); + console.log(theLayer.mapMoveParams); + } + }).always(function () { + _innerThis._arrLyrTimeout[theIndex] = null; + _innerThis._arrLyrRequest[theIndex] = null; + }); + } + innerFunction.call(_this, lyr, index); + }; + })(); + } else { + lyr.clear(); + } + this._arrLyrTimeout[index] = setTimeout(callbackFunc, lyr.onDemandDelay); } + }, { + key: 'triggerMoveCallback', + value: function triggerMoveCallback(ind, eventType, functionId) { - var ctx = this._mapMoveCallbackContext[ind]; - var theFunc = this._mapMoveCallbacks[ind]; + if (typeof ind == 'undefined' && typeof functionId == 'undefined') { + throw 'either the function index or the id must be defined'; + } - var _this = this; + if (typeof ind !== 'number') { + ind = this._mapMoveCallbacks.indexOf(this._mapMoveCallbacksLookup[functionId]); + } - var f = function f() { - if (ctx !== null) { - theFunc.call(ctx, _this._mapExtent, _this._zoomLevel, eventType); - } else { - theFunc(_this._mapExtent, _this._zoomLevel, eventType); + if (ind < 0) { + console.log('function not found'); + + return; } - }; - this._mapMoveCallbackTimeout[ind] = setTimeout(f, this._mapMoveCallbackDelays[ind]); - } + // clear the timeout + if (this._mapMoveCallbackTimeout[ind] != null) { + clearTimeout(this._mapMoveCallbackTimeout[ind]); + this._mapMoveCallbackTimeout[ind] = null; + } - /** - * Add a layer to the interaction - * @param {LayerBaseVector|*} lyr - layer to add - * @param {boolean} [triggerOnAdd=true] - if the layer should be loaded on add - */ + var ctx = this._mapMoveCallbackContext[ind]; + var theFunc = this._mapMoveCallbacks[ind]; + + var _this = this; - }, { - key: 'addVectorLayer', - value: function addVectorLayer(lyr, triggerOnAdd) { - if (this._arrLayer.indexOf(lyr) > -1) { - console.log('already added ' + lyr.name + ' to map move'); + var f = function f() { + if (ctx !== null) { + theFunc.call(ctx, _this._mapExtent, _this._zoomLevel, eventType); + } else { + theFunc(_this._mapExtent, _this._zoomLevel, eventType); + } + }; - return; + this._mapMoveCallbackTimeout[ind] = setTimeout(f, this._mapMoveCallbackDelays[ind]); } - this._checkInit(); + }, { + key: 'addVectorLayer', + value: function addVectorLayer(lyr, triggerOnAdd) { + if (this._arrLayer.indexOf(lyr) > -1) { + console.log('already added ' + lyr.name + ' to map move'); - this._arrLyrRequest.push(null); - this._arrLyrTimeout.push(null); - this._arrLayer.push(lyr); - this._lookupLayer[lyr.id] = lyr; + return; + } + this._checkInit(); - triggerOnAdd = typeof triggerOnAdd == 'boolean' ? triggerOnAdd : true; + this._arrLyrRequest.push(null); + this._arrLyrTimeout.push(null); + this._arrLayer.push(lyr); + this._lookupLayer[lyr.id] = lyr; - if (triggerOnAdd) { - if (this._mapExtent === undefined) { - this._updateMapExtent(); + triggerOnAdd = typeof triggerOnAdd == 'boolean' ? triggerOnAdd : true; + + if (triggerOnAdd) { + if (this._mapExtent === undefined) { + this._updateMapExtent(); + } + this.triggerLyrLoad(lyr, this._arrLayer.length - 1); } - this.triggerLyrLoad(lyr, this._arrLayer.length - 1); } - } + }, { + key: 'addCallback', + value: function addCallback(func, context, delay, triggerOnAdd, functionId) { - /** - * This callback is displayed as a global member. - * @callback mapMoveCallbackFunction - * @param {object} extent - extent object - * @param {number} extent.minX - minX - * @param {number} extent.minY - minY - * @param {number} extent.maxX - maxX - * @param {number} extent.maxY - maxY - * @param {number} zoomLevel - zoom level - * @param {string} [evtType=undefined] undefined for initial load, otherwise one of 'change:center', 'change:resolution' - */ + if (this._mapMoveCallbacks.indexOf(func) > -1) { + console.log('this function already added to map move'); - /** - * add a callback to the map move event - * @param {mapMoveCallbackFunction} func - callback function - * @param {*} context - the context to use for this function - * @param {number} [delay=50] the delay before call load - * @param {boolean} [triggerOnAdd=true] if the layer should be loaded on add to mapMove - * @param {string} [functionId=undefined] optional id to reference the function later for outside triggering - */ + return; + } + this._checkInit(); + if (!functionId) { + functionId = (0, _makeGuid2.default)(); + } - }, { - key: 'addCallback', - value: function addCallback(func, context, delay, triggerOnAdd, functionId) { + this._mapMoveCallbacks.push(func); + this._mapMoveCallbacksLookup[functionId] = func; + this._mapMoveCallbackDelays.push(typeof delay == 'number' ? delay : 50); + this._mapMoveCallbackContext.push(checkDefined.definedAndNotNull(context) ? context : null); + this._mapMoveCallbackTimeout.push(null); - if (this._mapMoveCallbacks.indexOf(func) > -1) { - console.log('this function already added to map move'); + triggerOnAdd = typeof triggerOnAdd == 'boolean' ? triggerOnAdd : true; - return; - } - this._checkInit(); - if (!functionId) { - functionId = (0, _makeGuid2.default)(); + if (triggerOnAdd) { + if (this._mapExtent === undefined) { + this._updateMapExtent(); + } + this.triggerMoveCallback(this._mapMoveCallbacks.length - 1); + } } - - this._mapMoveCallbacks.push(func); - this._mapMoveCallbacksLookup[functionId] = func; - this._mapMoveCallbackDelays.push(typeof delay == 'number' ? delay : 50); - this._mapMoveCallbackContext.push(checkDefined.definedAndNotNull(context) ? context : null); - this._mapMoveCallbackTimeout.push(null); - - triggerOnAdd = typeof triggerOnAdd == 'boolean' ? triggerOnAdd : true; - - if (triggerOnAdd) { - if (this._mapExtent === undefined) { + }, { + key: 'mapExtent', + get: function get() { + if (!this._mapExtent) { this._updateMapExtent(); } - this.triggerMoveCallback(this._mapMoveCallbacks.length - 1); - } - } - }, { - key: 'mapExtent', - get: function get() { - if (!this._mapExtent) { - this._updateMapExtent(); - } - return this._mapExtent; - } - }]); + return this._mapExtent; + } + }]); - return MapMoveCls; -})(_mapInteractionBase2.default); + return MapMoveCls; + }(_mapInteractionBase2.default); -nm.MapMoveCls = MapMoveCls; -exports.default = MapMoveCls; -module.exports = exports['default']; \ No newline at end of file + nm.MapMoveCls = MapMoveCls; + exports.default = MapMoveCls; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/mapPopup.js b/lib/olHelpers/mapPopup.js index 54d957ffd002cac260fe37a5b52208fd9d3bb047..53db86c2c554a8869c10a8548f880c909bcbfd8b 100644 --- a/lib/olHelpers/mapPopup.js +++ b/lib/olHelpers/mapPopup.js @@ -1,21 +1,30 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', './mapPopupCls'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./mapPopupCls')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.mapPopupCls); + global.mapPopup = mod.exports; + } +})(this, function (module, exports, _mapPopupCls) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _mapPopupCls = require('./mapPopupCls'); + var _mapPopupCls2 = _interopRequireDefault(_mapPopupCls); -var _mapPopupCls2 = _interopRequireDefault(_mapPopupCls); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * The single popup object catch is that it is common to multimap pages - * @type {MapPopupCls} - */ -exports.default = new _mapPopupCls2.default(); /** - * Created by gavorhes on 11/3/2015. - */ - -module.exports = exports['default']; \ No newline at end of file + exports.default = new _mapPopupCls2.default(); + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/mapPopupCls.js b/lib/olHelpers/mapPopupCls.js index 1548f5bc5f808760265925f66dd822340ca49360..c53b98bca1c659d33ab89113297433d2b15d096c 100644 --- a/lib/olHelpers/mapPopupCls.js +++ b/lib/olHelpers/mapPopupCls.js @@ -1,644 +1,628 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; - -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; }; })(); /** - * Created by gavorhes on 11/3/2015. - */ - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', './mapInteractionBase', '../olHelpers/propertiesZoomStyle', '../util/provide', '../ol/ol'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('./mapInteractionBase'), require('../olHelpers/propertiesZoomStyle'), require('../util/provide'), require('../ol/ol')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.mapInteractionBase, global.propertiesZoomStyle, global.provide, global.ol); + global.mapPopupCls = mod.exports; + } +})(this, function (module, exports, _jquery, _mapInteractionBase, _propertiesZoomStyle, _provide, _ol) { + 'use strict'; -var _mapInteractionBase = require('./mapInteractionBase'); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _mapInteractionBase2 = _interopRequireDefault(_mapInteractionBase); + var _jquery2 = _interopRequireDefault(_jquery); -var _propertiesZoomStyle = require('../olHelpers/propertiesZoomStyle'); + var _mapInteractionBase2 = _interopRequireDefault(_mapInteractionBase); -var _propertiesZoomStyle2 = _interopRequireDefault(_propertiesZoomStyle); + var _propertiesZoomStyle2 = _interopRequireDefault(_propertiesZoomStyle); -var _provide = require('../util/provide'); + var _provide2 = _interopRequireDefault(_provide); -var _provide2 = _interopRequireDefault(_provide); + var _ol2 = _interopRequireDefault(_ol); -var _ol = require('../ol/ol'); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var _ol2 = _interopRequireDefault(_ol); + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } -function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + var _get = function get(object, property, receiver) { + if (object === null) object = Function.prototype; + var desc = Object.getOwnPropertyDescriptor(object, property); -function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; -var nm = (0, _provide2.default)('olHelpers'); + if (getter === undefined) { + return undefined; + } -var _FeatureLayerProperties = (function () { + return getter.call(receiver); + } + }; - /** - * - * @param {ol.Feature} feature the feature - * @param {LayerBaseVector|*} layer - the layer in the popup - * @param {number} layerIndex - index of the layer - * @param {ol.layer.Vector} selectionLayer - the ol selection layer - * @param {string} [esriLayerName=undefined] - esri layer name - */ + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } - function _FeatureLayerProperties(feature, layer, layerIndex, selectionLayer, esriLayerName) { - _classCallCheck(this, _FeatureLayerProperties); + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } - this.feature = feature; - this.layer = layer; - this.layerIndex = layerIndex; - this.selectionLayer = selectionLayer; - this.popupContent = ''; - this.esriLayerName = typeof esriLayerName == 'string' ? esriLayerName : undefined; + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } } - _createClass(_FeatureLayerProperties, [{ - key: 'layerName', - get: function get() { - if (typeof this.esriLayerName == 'string') { - return this.esriLayerName; - } else { - return this.layer.name; + 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 _FeatureLayerProperties; -})(); + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + var nm = (0, _provide2.default)('olHelpers'); + + var _FeatureLayerProperties = function () { -/** - * map popup class - * @augments MapInteractionBase - */ + /** + * + * @param {ol.Feature} feature the feature + * @param {LayerBaseVector|*} layer - the layer in the popup + * @param {number} layerIndex - index of the layer + * @param {ol.layer.Vector} selectionLayer - the ol selection layer + * @param {string} [esriLayerName=undefined] - esri layer name + */ -var MapPopupCls = (function (_MapInteractionBase) { - _inherits(MapPopupCls, _MapInteractionBase); + function _FeatureLayerProperties(feature, layer, layerIndex, selectionLayer, esriLayerName) { + _classCallCheck(this, _FeatureLayerProperties); - /** - * Definition for openlayers style function - * @callback olStyleFunction - * ¶m feature the openlayers vector feature - * $param - */ + this.feature = feature; + this.layer = layer; + this.layerIndex = layerIndex; + this.selectionLayer = selectionLayer; + this.popupContent = ''; + this.esriLayerName = typeof esriLayerName == 'string' ? esriLayerName : undefined; + } - /** - * Definition for popup changed callback functions - * @callback popupChangedFunction - * @param $popContent jquery reference to the popup content - */ + _createClass(_FeatureLayerProperties, [{ + key: 'layerName', + get: function get() { + if (typeof this.esriLayerName == 'string') { + return this.esriLayerName; + } else { + return this.layer.name; + } + } + }]); - /** - * map popup constructor - */ + return _FeatureLayerProperties; + }(); - function MapPopupCls() { - _classCallCheck(this, MapPopupCls); + var MapPopupCls = function (_MapInteractionBase) { + _inherits(MapPopupCls, _MapInteractionBase); - var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(MapPopupCls).call(this, 'map popup')); + /** + * Definition for openlayers style function + * @callback olStyleFunction + * ¶m feature the openlayers vector feature + * $param + */ - _this._arrPopupLayerIds = []; - _this._arrPopupLayerNames = []; /** - * - * @type {Array<LayerBaseVector>} - * @private + * Definition for popup changed callback functions + * @callback popupChangedFunction + * @param $popContent jquery reference to the popup content */ - _this._arrPopupLayers = []; - _this._arrPopupOlLayers = []; - _this._arrPopupContentFunction = []; - _this._$popupContainer = undefined; - _this._$popupContent = undefined; - _this._$popupCloser = undefined; - _this._popupOverlay = undefined; - _this._selectionLayers = []; - _this._selectionLayerLookup = {}; - _this._mapClickFunctions = []; - - //let a = function($jqueryContent){console.log($jqueryContent)}; - //this._popupChangedLookup = {'a': a}; - _this._popupChangedFunctions = []; + /** - * - * @type {Array<LayerEsriMapServer>} - * @private + * map popup constructor */ - _this._esriMapServiceLayers = []; - _this._popupOpen = false; - _this._popupCoordinate = null; + function MapPopupCls() { + _classCallCheck(this, MapPopupCls); + + var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(MapPopupCls).call(this, 'map popup')); + + _this._arrPopupLayerIds = []; + _this._arrPopupLayerNames = []; + /** + * + * @type {Array<LayerBaseVector>} + * @private + */ + _this._arrPopupLayers = []; + _this._arrPopupOlLayers = []; + _this._arrPopupContentFunction = []; + _this._$popupContainer = undefined; + _this._$popupContent = undefined; + _this._$popupCloser = undefined; + _this._popupOverlay = undefined; + _this._selectionLayers = []; + _this._selectionLayerLookup = {}; + _this._mapClickFunctions = []; + + //let a = function($jqueryContent){console.log($jqueryContent)}; + //this._popupChangedLookup = {'a': a}; + _this._popupChangedFunctions = []; + /** + * + * @type {Array<LayerEsriMapServer>} + * @private + */ + _this._esriMapServiceLayers = []; + + _this._popupOpen = false; + _this._popupCoordinate = null; + + /** + * + * @type {Array.<_FeatureLayerProperties>} + */ + _this._passThroughLayerFeatureArray = []; + + _this._currentPopupIndex = -1; + _this._popupContentLength = 0; + + return _this; + } /** - * - * @type {Array.<_FeatureLayerProperties>} + * map popup initialization + * @param {ol.Map} theMap - the ol map */ - _this._passThroughLayerFeatureArray = []; - _this._currentPopupIndex = -1; - _this._popupContentLength = 0; - return _this; - } + _createClass(MapPopupCls, [{ + key: 'init', + value: function init(theMap) { + var _this2 = this; - /** - * map popup initialization - * @param {ol.Map} theMap - the ol map - */ + if (_get(Object.getPrototypeOf(MapPopupCls.prototype), 'init', this).call(this, theMap)) { + return; + } + var $map = (0, _jquery2.default)('#' + this.map.getTarget()); - _createClass(MapPopupCls, [{ - key: 'init', - value: function init(theMap) { - var _this2 = this; + $map.append('<div class="ol-popup">' + '<a href="#" class="ol-popup-closer"></a>' + '<div class="popup-content"></div>' + '</div>'); - if (_get(Object.getPrototypeOf(MapPopupCls.prototype), 'init', this).call(this, theMap)) { - return; - } - var $map = (0, _jquery2.default)('#' + this.map.getTarget()); + this._$popupContainer = $map.find('.ol-popup'); + this._$popupContent = $map.find('.popup-content'); + this._$popupCloser = $map.find('.ol-popup-closer'); - $map.append('<div class="ol-popup">' + '<a href="#" class="ol-popup-closer"></a>' + '<div class="popup-content"></div>' + '</div>'); + this._popupOverlay = new _ol2.default.Overlay({ + element: this._$popupContainer[0], + autoPan: true, + autoPanAnimation: { + duration: 250 + } + }); - this._$popupContainer = $map.find('.ol-popup'); - this._$popupContent = $map.find('.popup-content'); - this._$popupCloser = $map.find('.ol-popup-closer'); + this._map.addOverlay(this._popupOverlay); - this._popupOverlay = new _ol2.default.Overlay({ - element: this._$popupContainer[0], - autoPan: true, - autoPanAnimation: { - duration: 250 - } - }); - - this._map.addOverlay(this._popupOverlay); - - this._$popupCloser.click(function () { - _this2.closePopup(); - }); - - // display popup on click - this._map.on('singleclick', function (evt) { - _this2.closePopup(); - _this2._popupCoordinate = evt.coordinate; - - if (_this2._esriMapServiceLayers.length > 0) { - var queryParams = { - geometry: evt.coordinate.join(','), - geometryType: 'esriGeometryPoint', - layers: 'all', - sr: _this2._map.getView().getProjection().getCode().split(':')[1], - mapExtent: _this2._map.getView().calculateExtent(_this2._map.getSize()).join(','), - imageDisplay: _this2._map.getSize().join(',') + ',96', - returnGeometry: true, - tolerance: 15, - f: 'pjson' - }; - - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; + this._$popupCloser.click(function () { + _this2.closePopup(); + }); - try { - for (var _iterator = _this2._esriMapServiceLayers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var l = _step.value; + // display popup on click + this._map.on('singleclick', function (evt) { + _this2.closePopup(); + _this2._popupCoordinate = evt.coordinate; + + if (_this2._esriMapServiceLayers.length > 0) { + var queryParams = { + geometry: evt.coordinate.join(','), + geometryType: 'esriGeometryPoint', + layers: 'all', + sr: _this2._map.getView().getProjection().getCode().split(':')[1], + mapExtent: _this2._map.getView().calculateExtent(_this2._map.getSize()).join(','), + imageDisplay: _this2._map.getSize().join(',') + ',96', + returnGeometry: true, + tolerance: 15, + f: 'pjson' + }; + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; - l.getPopupInfo(queryParams, _this2._selectionLayerLookup[l.id]); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); + for (var _iterator = _this2._esriMapServiceLayers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var l = _step.value; + + l.getPopupInfo(queryParams, _this2._selectionLayerLookup[l.id]); } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; } finally { - if (_didIteratorError) { - throw _iteratorError; + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } } } } - } - var layerFeatureObjectArray = _this2._featuresAtPixel(evt.pixel); + var layerFeatureObjectArray = _this2._featuresAtPixel(evt.pixel); - /** - * - * @type {Array.<_FeatureLayerProperties>} - */ - _this2._passThroughLayerFeatureArray = []; - _this2._currentPopupIndex = -1; + /** + * + * @type {Array.<_FeatureLayerProperties>} + */ + _this2._passThroughLayerFeatureArray = []; + _this2._currentPopupIndex = -1; - for (var i = 0; i < layerFeatureObjectArray.length; i++) { - var featObj = layerFeatureObjectArray[i]; + for (var i = 0; i < layerFeatureObjectArray.length; i++) { + var featObj = layerFeatureObjectArray[i]; - var props = featObj.feature.getProperties(); + var props = featObj.feature.getProperties(); - var popupContentResponse = _this2._arrPopupContentFunction[featObj.layerIndex](props, _this2._$popupContent); + var popupContentResponse = _this2._arrPopupContentFunction[featObj.layerIndex](props, _this2._$popupContent); - //skip if return was false - if (popupContentResponse === false) { - //continue; - } else if (typeof popupContentResponse == 'string') { - featObj.popupContent = popupContentResponse; - _this2._passThroughLayerFeatureArray.push(featObj); - } else { - featObj.selectionLayer.getSource().addFeature(featObj.feature); - } - } + //skip if return was false + if (popupContentResponse === false) { + //continue; + } else if (typeof popupContentResponse == 'string') { + featObj.popupContent = popupContentResponse; + _this2._passThroughLayerFeatureArray.push(featObj); + } else { + featObj.selectionLayer.getSource().addFeature(featObj.feature); + } + } - _this2._popupContentLength = _this2._passThroughLayerFeatureArray.length; + _this2._popupContentLength = _this2._passThroughLayerFeatureArray.length; - _this2._currentPopupIndex = -1; + _this2._currentPopupIndex = -1; - var popupHtml = '<div class="ol-popup-nav">'; - popupHtml += '<span class="previous-popup ol-popup-nav-arrow">◀</span>'; - popupHtml += '<span class="next-popup ol-popup-nav-arrow">▶</span>'; - popupHtml += '<span class="current-popup-item-number" style="font-weight: bold;"></span>'; - popupHtml += '<span> of </span>'; - popupHtml += '<span class="popup-content-length" style="font-weight: bold;">' + _this2._popupContentLength + '</span>'; - popupHtml += '<span> - </span>'; - popupHtml += '<span class="current-popup-layer-name"></span>'; - popupHtml += '</div>'; - popupHtml += '<div class="ol-popup-inner">'; + var popupHtml = '<div class="ol-popup-nav">'; + popupHtml += '<span class="previous-popup ol-popup-nav-arrow">◀</span>'; + popupHtml += '<span class="next-popup ol-popup-nav-arrow">▶</span>'; + popupHtml += '<span class="current-popup-item-number" style="font-weight: bold;"></span>'; + popupHtml += '<span> of </span>'; + popupHtml += '<span class="popup-content-length" style="font-weight: bold;">' + _this2._popupContentLength + '</span>'; + popupHtml += '<span> - </span>'; + popupHtml += '<span class="current-popup-layer-name"></span>'; + popupHtml += '</div>'; + popupHtml += '<div class="ol-popup-inner">'; - popupHtml += '</div>'; + popupHtml += '</div>'; - _this2._$popupContent.html(popupHtml); + _this2._$popupContent.html(popupHtml); - _this2._$popupContent.find('.previous-popup').click(function () { - if (_this2._popupContentLength == 1) { - return; - } + _this2._$popupContent.find('.previous-popup').click(function () { + if (_this2._popupContentLength == 1) { + return; + } - if (_this2._currentPopupIndex == 0) { - _this2._currentPopupIndex = _this2._popupContentLength - 1; - } else { - _this2._currentPopupIndex--; - } - _this2._triggerFeatSelect(); - }); + if (_this2._currentPopupIndex == 0) { + _this2._currentPopupIndex = _this2._popupContentLength - 1; + } else { + _this2._currentPopupIndex--; + } + _this2._triggerFeatSelect(); + }); - var nextPopup = _this2._$popupContent.find('.next-popup'); + var nextPopup = _this2._$popupContent.find('.next-popup'); - nextPopup.click(function () { - if (_this2._popupContentLength == 1 && _this2._currentPopupIndex > -1) { - return; - } + nextPopup.click(function () { + if (_this2._popupContentLength == 1 && _this2._currentPopupIndex > -1) { + return; + } - if (_this2._currentPopupIndex == _this2._popupContentLength - 1) { - _this2._currentPopupIndex = 0; - } else { - _this2._currentPopupIndex++; + if (_this2._currentPopupIndex == _this2._popupContentLength - 1) { + _this2._currentPopupIndex = 0; + } else { + _this2._currentPopupIndex++; + } + _this2._triggerFeatSelect(); + }); + + if (_this2._popupContentLength > 0) { + nextPopup.trigger('click'); + _this2._popupOverlay.setPosition(_this2._popupCoordinate); + _this2._$popupContent.scrollTop(0); + _this2._popupOpen = true; } - _this2._triggerFeatSelect(); }); - if (_this2._popupContentLength > 0) { - nextPopup.trigger('click'); - _this2._popupOverlay.setPosition(_this2._popupCoordinate); - _this2._$popupContent.scrollTop(0); - _this2._popupOpen = true; - } - }); - - //change mouse cursor when over marker - this._map.on('pointermove', function (e) { - if (e.dragging) { - return; - } - var pixel = _this2.map.getEventPixel(e.originalEvent); - var hit = _this2.map.hasFeatureAtPixel(pixel, function (lyrCandidate) { - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = _this2._arrPopupOlLayers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var olLayer = _step2.value; + //change mouse cursor when over marker + this._map.on('pointermove', function (e) { + if (e.dragging) { + return; + } + var pixel = _this2.map.getEventPixel(e.originalEvent); + var hit = _this2.map.hasFeatureAtPixel(pixel, function (lyrCandidate) { + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; - if (lyrCandidate == olLayer) { - return true; - } - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { try { - if (!_iteratorNormalCompletion2 && _iterator2.return) { - _iterator2.return(); + for (var _iterator2 = _this2._arrPopupOlLayers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var olLayer = _step2.value; + + if (lyrCandidate == olLayer) { + return true; + } } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; } finally { - if (_didIteratorError2) { - throw _iteratorError2; + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } } } - } - return false; + return false; + }); + _this2.map.getTargetElement().style.cursor = hit ? 'pointer' : ''; }); - _this2.map.getTargetElement().style.cursor = hit ? 'pointer' : ''; - }); - } - - /** - * helper to select features - * @private - */ + } + }, { + key: '_triggerFeatSelect', + value: function _triggerFeatSelect() { + var $currentPopupItemNumber = this._$popupContent.find('.current-popup-item-number'); + var $innerPopup = this._$popupContent.find('.ol-popup-inner'); + var $layerNameSpan = this._$popupContent.find('.current-popup-layer-name'); + this.clearSelection(); + var lyrFeatObj = this._passThroughLayerFeatureArray[this._currentPopupIndex]; + $currentPopupItemNumber.html((this._currentPopupIndex + 1).toFixed()); + $layerNameSpan.html(lyrFeatObj.layerName); + $innerPopup.html(lyrFeatObj.popupContent); + lyrFeatObj.selectionLayer.getSource().addFeature(lyrFeatObj.feature); + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; - }, { - key: '_triggerFeatSelect', - value: function _triggerFeatSelect() { - var $currentPopupItemNumber = this._$popupContent.find('.current-popup-item-number'); - var $innerPopup = this._$popupContent.find('.ol-popup-inner'); - var $layerNameSpan = this._$popupContent.find('.current-popup-layer-name'); - this.clearSelection(); - var lyrFeatObj = this._passThroughLayerFeatureArray[this._currentPopupIndex]; - $currentPopupItemNumber.html((this._currentPopupIndex + 1).toFixed()); - $layerNameSpan.html(lyrFeatObj.layerName); - $innerPopup.html(lyrFeatObj.popupContent); - lyrFeatObj.selectionLayer.getSource().addFeature(lyrFeatObj.feature); - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = this._popupChangedFunctions[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var f = _step3.value; - - f(this._$popupContent); - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { try { - if (!_iteratorNormalCompletion3 && _iterator3.return) { - _iterator3.return(); + for (var _iterator3 = this._popupChangedFunctions[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var f = _step3.value; + + f(this._$popupContent); } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; } finally { - if (_didIteratorError3) { - throw _iteratorError3; + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } } } } - } - - /** - * - * @param {ol.Feature} feature - the ol feature - * @param {LayerEsriMapServer} lyr - the map server layer - * @param {string} popupContent - popup content - * @param {string} esriName - esri layer name - */ - - }, { - key: 'addMapServicePopupContent', - value: function addMapServicePopupContent(feature, lyr, popupContent, esriName) { + }, { + key: 'addMapServicePopupContent', + value: function addMapServicePopupContent(feature, lyr, popupContent, esriName) { - var featLayerObject = new _FeatureLayerProperties(feature, lyr, this._popupContentLength, this._selectionLayerLookup[lyr.id], esriName); - featLayerObject.popupContent = popupContent; + var featLayerObject = new _FeatureLayerProperties(feature, lyr, this._popupContentLength, this._selectionLayerLookup[lyr.id], esriName); + featLayerObject.popupContent = popupContent; - this._passThroughLayerFeatureArray.push(featLayerObject); - this._popupContentLength++; + this._passThroughLayerFeatureArray.push(featLayerObject); + this._popupContentLength++; - (0, _jquery2.default)('.popup-content-length').html(this._popupContentLength.toFixed()); + (0, _jquery2.default)('.popup-content-length').html(this._popupContentLength.toFixed()); - if (!this._popupOpen) { - this._$popupContent.find('.next-popup').trigger('click'); + if (!this._popupOpen) { + this._$popupContent.find('.next-popup').trigger('click'); - this._popupOverlay.setPosition(this._popupCoordinate); - this._$popupContent.scrollTop(0); - this._popupOpen = true; + this._popupOverlay.setPosition(this._popupCoordinate); + this._$popupContent.scrollTop(0); + this._popupOpen = true; + } } - } + }, { + key: '_featuresAtPixel', + value: function _featuresAtPixel(pixel) { + var _this3 = this; - /** - * - * @param {ol.Pixel} pixel - the ol pixel - * @returns {Array.<_FeatureLayerProperties>} - feature layer properties - * @private - */ + var layerFeatureObjectArray = []; + this.map.forEachFeatureAtPixel(pixel, function (feature, layer) { + var lyrIndex = _this3._arrPopupOlLayers.indexOf(layer); - }, { - key: '_featuresAtPixel', - value: function _featuresAtPixel(pixel) { - var _this3 = this; - - var layerFeatureObjectArray = []; - this.map.forEachFeatureAtPixel(pixel, function (feature, layer) { - var lyrIndex = _this3._arrPopupOlLayers.indexOf(layer); + if (lyrIndex > -1) { + layerFeatureObjectArray.push(new _FeatureLayerProperties(feature, _this3._arrPopupLayers[lyrIndex], lyrIndex, _this3._selectionLayers[lyrIndex])); + } + }); - if (lyrIndex > -1) { - layerFeatureObjectArray.push(new _FeatureLayerProperties(feature, _this3._arrPopupLayers[lyrIndex], lyrIndex, _this3._selectionLayers[lyrIndex])); + return layerFeatureObjectArray; + } + }, { + key: 'closePopup', + value: function closePopup() { + this._checkInit(); + this._popupOpen = false; + this._popupOverlay.setPosition(undefined); + this._$popupCloser[0].blur(); + this.clearSelection(); + this._$popupContent.html(''); + + return false; + } + }, { + key: 'addPopupChangedFunction', + value: function addPopupChangedFunction(chgFunction) { + this._popupChangedFunctions.push(chgFunction); + } + }, { + key: '_addPopupLayer', + value: function _addPopupLayer(lyr, selectionStyle) { + this._checkInit(); + + selectionStyle = selectionStyle || {}; + selectionStyle.color = selectionStyle.color || 'rgba(255,170,0,0.5)'; + selectionStyle.width = selectionStyle.width || 10; + + var theStyle = void 0; + + if (selectionStyle.olStyle) { + theStyle = selectionStyle.olStyle; + } else { + theStyle = new _ol2.default.style.Style({ + stroke: new _ol2.default.style.Stroke({ + color: selectionStyle.color, + width: selectionStyle.width + }), + image: new _ol2.default.style.Circle({ + radius: 7, + fill: new _ol2.default.style.Fill({ color: selectionStyle.color }), + stroke: new _ol2.default.style.Stroke({ color: selectionStyle.color, width: 1 }) + }), + fill: new _ol2.default.style.Fill({ + color: selectionStyle.color + }) + }); } - }); - - return layerFeatureObjectArray; - } - }, { - key: 'closePopup', - value: function closePopup() { - this._checkInit(); - this._popupOpen = false; - this._popupOverlay.setPosition(undefined); - this._$popupCloser[0].blur(); - this.clearSelection(); - this._$popupContent.html(''); - - return false; - } - }, { - key: 'addPopupChangedFunction', - - /** - * - * @param {popupChangedFunction} chgFunction - popup change function - */ - value: function addPopupChangedFunction(chgFunction) { - this._popupChangedFunctions.push(chgFunction); - } - - /** - * - * @param {LayerBase|*} lyr - the layer being acted on - * @param {object} [selectionStyle={}] the selection style configuration - * @param {string} [selectionStyle.color=rgba(255,170,0,0.5)] the selection color - * @param {number} [selectionStyle.width=10] the selection width for linear features - * @param {object|function} [selectionStyle.olStyle=undefined] an openlayers style object or function - * @returns {ol.layer.Vector} the new selection layer - * @private - */ - - }, { - key: '_addPopupLayer', - value: function _addPopupLayer(lyr, selectionStyle) { - this._checkInit(); - - selectionStyle = selectionStyle || {}; - selectionStyle.color = selectionStyle.color || 'rgba(255,170,0,0.5)'; - selectionStyle.width = selectionStyle.width || 10; - var theStyle = undefined; - - if (selectionStyle.olStyle) { - theStyle = selectionStyle.olStyle; - } else { - theStyle = new _ol2.default.style.Style({ - stroke: new _ol2.default.style.Stroke({ - color: selectionStyle.color, - width: selectionStyle.width - }), - image: new _ol2.default.style.Circle({ - radius: 7, - fill: new _ol2.default.style.Fill({ color: selectionStyle.color }), - stroke: new _ol2.default.style.Stroke({ color: selectionStyle.color, width: 1 }) - }), - fill: new _ol2.default.style.Fill({ - color: selectionStyle.color - }) + var selectionLayer = new _ol2.default.layer.Vector({ + source: new _ol2.default.source.Vector(), + style: theStyle, + zIndex: 100 }); - } - - var selectionLayer = new _ol2.default.layer.Vector({ - source: new _ol2.default.source.Vector(), - style: theStyle, - zIndex: 100 - }); - - this._selectionLayers.push(selectionLayer); - this._selectionLayerLookup[lyr.id] = selectionLayer; - this.map.addLayer(selectionLayer); - - return selectionLayer; - } - - /** - * The popup callback function - * @callback popupCallback - * @param {object} featureProperties - the feature properties - * @param {jQuery} jqRef reference to the div content to do some async stuff inside the div - * @returns {string} the html content to be added to the popup - */ - - /** - * Add popup to the map - * @param {LayerBase|*} lyr The layer that the popup with act on - * @param {popupCallback} popupContentFunction - popup content function that makes popup info - * @param {object} [selectionStyle={}] the selection style configuration - * @param {string} [selectionStyle.color=rgba(255,170,0,0.5)] the selection color - * @param {number} [selectionStyle.width=10] the selection width for linear features - * @param {object|function} [selectionStyle.olStyle=undefined] an openlayers style object or function - * @returns {object} a reference to the ol selection layer - */ - }, { - key: 'addVectorPopup', - value: function addVectorPopup(lyr, popupContentFunction, selectionStyle) { - var selectionLayer = this._addPopupLayer(lyr, selectionStyle); - this._arrPopupLayerIds.push(lyr.id); - this._arrPopupLayerNames.push(lyr.name); - this._arrPopupLayers.push(lyr); - this._arrPopupOlLayers.push(lyr.olLayer); - this._arrPopupContentFunction.push(popupContentFunction); - - return selectionLayer; - } - }, { - key: 'removeVectorPopup', + this._selectionLayers.push(selectionLayer); + this._selectionLayerLookup[lyr.id] = selectionLayer; + this.map.addLayer(selectionLayer); - /** - * - * @param {LayerBase} lyr - layer - */ - value: function removeVectorPopup(lyr) { - var idx = this._arrPopupLayerIds.indexOf(lyr.id); - - if (idx > -1) { - this._arrPopupLayerIds.splice(idx, 1); - this._arrPopupLayerNames.splice(idx, 1); - this._arrPopupLayers.splice(idx, 1); - this._arrPopupOlLayers.splice(idx, 1); - this._arrPopupContentFunction.splice(idx, 1); - this._selectionLayers.splice(idx, 1); - delete this._selectionLayerLookup[lyr.id]; + return selectionLayer; } - } - - /** - * - * @param {LayerEsriMapServer} lyr - map server layer - * @param {object} [selectionStyle={}] the selection style configuration - * @param {string} [selectionStyle.color=rgba(255,170,0,0.5)] the selection color - * @param {number} [selectionStyle.width=10] the selection width for linear features - * @param {object|function} [selectionStyle.olStyle=undefined] an openlayers style object or function - * @returns {object} a reference to the ol selection layer - */ - - }, { - key: 'addMapServicePopup', - value: function addMapServicePopup(lyr, selectionStyle) { - var selectionLayer = this._addPopupLayer(lyr, selectionStyle); - this._esriMapServiceLayers.push(lyr); - - return selectionLayer; - } - }, { - key: 'clearSelection', - value: function clearSelection() { - this._checkInit(); - for (var i = 0; i < this._selectionLayers.length; i++) { - this._selectionLayers[i].getSource().clear(); + }, { + key: 'addVectorPopup', + value: function addVectorPopup(lyr, popupContentFunction, selectionStyle) { + var selectionLayer = this._addPopupLayer(lyr, selectionStyle); + this._arrPopupLayerIds.push(lyr.id); + this._arrPopupLayerNames.push(lyr.name); + this._arrPopupLayers.push(lyr); + this._arrPopupOlLayers.push(lyr.olLayer); + this._arrPopupContentFunction.push(popupContentFunction); + + return selectionLayer; } - var _iteratorNormalCompletion4 = true; - var _didIteratorError4 = false; - var _iteratorError4 = undefined; - - try { - for (var _iterator4 = this._mapClickFunctions[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { - var f = _step4.value; + }, { + key: 'removeVectorPopup', + value: function removeVectorPopup(lyr) { + var idx = this._arrPopupLayerIds.indexOf(lyr.id); + + if (idx > -1) { + this._arrPopupLayerIds.splice(idx, 1); + this._arrPopupLayerNames.splice(idx, 1); + this._arrPopupLayers.splice(idx, 1); + this._arrPopupOlLayers.splice(idx, 1); + this._arrPopupContentFunction.splice(idx, 1); + this._selectionLayers.splice(idx, 1); + delete this._selectionLayerLookup[lyr.id]; + } + } + }, { + key: 'addMapServicePopup', + value: function addMapServicePopup(lyr, selectionStyle) { + var selectionLayer = this._addPopupLayer(lyr, selectionStyle); + this._esriMapServiceLayers.push(lyr); - f(); + return selectionLayer; + } + }, { + key: 'clearSelection', + value: function clearSelection() { + this._checkInit(); + for (var i = 0; i < this._selectionLayers.length; i++) { + this._selectionLayers[i].getSource().clear(); } - } catch (err) { - _didIteratorError4 = true; - _iteratorError4 = err; - } finally { + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + try { - if (!_iteratorNormalCompletion4 && _iterator4.return) { - _iterator4.return(); + for (var _iterator4 = this._mapClickFunctions[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var f = _step4.value; + + f(); } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; } finally { - if (_didIteratorError4) { - throw _iteratorError4; + try { + if (!_iteratorNormalCompletion4 && _iterator4.return) { + _iterator4.return(); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } } } } - } - }, { - key: 'addMapClickFunction', - - /** - * Add a function to be called when the map is clicked but before any popups are implemented - * @param {function} func - the map click function - */ - value: function addMapClickFunction(func) { - this._mapClickFunctions.push(func); - } - }]); + }, { + key: 'addMapClickFunction', + value: function addMapClickFunction(func) { + this._mapClickFunctions.push(func); + } + }]); - return MapPopupCls; -})(_mapInteractionBase2.default); + return MapPopupCls; + }(_mapInteractionBase2.default); -nm.MapPopupCls = MapPopupCls; -exports.default = MapPopupCls; -module.exports = exports['default']; \ No newline at end of file + nm.MapPopupCls = MapPopupCls; + exports.default = MapPopupCls; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/propertiesZoomStyle.js b/lib/olHelpers/propertiesZoomStyle.js index fcf5d3f3f137f310348e745261d51b89286980b9..aac268f4b82746428fc23c87b906b242a9017d21 100644 --- a/lib/olHelpers/propertiesZoomStyle.js +++ b/lib/olHelpers/propertiesZoomStyle.js @@ -1,50 +1,79 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../util/provide', './zoomResolutionConvert'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../util/provide'), require('./zoomResolutionConvert')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.provide, global.zoomResolutionConvert); + global.propertiesZoomStyle = mod.exports; + } +})(this, function (module, exports, _provide, _zoomResolutionConvert) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _provide = require('../util/provide'); + var _provide2 = _interopRequireDefault(_provide); -var _provide2 = _interopRequireDefault(_provide); + var zoomResolutionConvert = _interopRequireWildcard(_zoomResolutionConvert); -var _zoomResolutionConvert = require('./zoomResolutionConvert'); + function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; + } else { + var newObj = {}; -var zoomResolutionConvert = _interopRequireWildcard(_zoomResolutionConvert); + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; + } + } -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + newObj.default = obj; + return newObj; + } + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -/** - * Created by gavorhes on 12/14/2015. - */ + /** + * Created by gavorhes on 12/14/2015. + */ -var nm = (0, _provide2.default)('olHelpers'); + var nm = (0, _provide2.default)('olHelpers'); -/** - * A style function based on properties and zoom level, wraps normal feature, resolution function - * @callback propertiesZoomStyle - * @param {object} properties the feature properties - * @param {number} zoom level - * - */ + /** + * A style function based on properties and zoom level, wraps normal feature, resolution function + * @callback propertiesZoomStyle + * @param {object} properties the feature properties + * @param {number} zoom level + * + */ -/** - * wrapper to define a style function by properties and zoom level - * @param {propertiesZoomStyle|*} styleFunc - style function - * @returns {function|*} new function - */ -function propertiesZoomStyle(styleFunc) { - if (styleFunc == undefined) { - return undefined; - } + /** + * wrapper to define a style function by properties and zoom level + * @param {propertiesZoomStyle|*} styleFunc - style function + * @returns {function|*} new function + */ + function propertiesZoomStyle(styleFunc) { + if (styleFunc == undefined) { + return undefined; + } - return function (feature, resolution) { - styleFunc(feature.getProperties(), zoomResolutionConvert.resolutionToZoom(resolution)); - }; -} + return function (feature, resolution) { + styleFunc(feature.getProperties(), zoomResolutionConvert.resolutionToZoom(resolution)); + }; + } -nm.propertiesZoomStyle = propertiesZoomStyle; -exports.default = propertiesZoomStyle; -module.exports = exports['default']; \ No newline at end of file + nm.propertiesZoomStyle = propertiesZoomStyle; + exports.default = propertiesZoomStyle; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/quickMap.js b/lib/olHelpers/quickMap.js index 9d626a56ab6449be7cc7a9d9e94807e52d6a629c..8f9c08d034dd7b0a99a5d2f7a7798737711d774b 100644 --- a/lib/olHelpers/quickMap.js +++ b/lib/olHelpers/quickMap.js @@ -1,57 +1,67 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', './quickMapBase', '../util/provide', './mapMove', './mapPopup'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./quickMapBase'), require('../util/provide'), require('./mapMove'), require('./mapPopup')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.quickMapBase, global.provide, global.mapMove, global.mapPopup); + global.quickMap = mod.exports; + } +})(this, function (module, exports, _quickMapBase, _provide, _mapMove, _mapPopup) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); + Object.defineProperty(exports, "__esModule", { + value: true + }); -var _quickMapBase = require('./quickMapBase'); + var _quickMapBase2 = _interopRequireDefault(_quickMapBase); -var _quickMapBase2 = _interopRequireDefault(_quickMapBase); + var _provide2 = _interopRequireDefault(_provide); -var _provide = require('../util/provide'); + var _mapMove2 = _interopRequireDefault(_mapMove); -var _provide2 = _interopRequireDefault(_provide); + var _mapPopup2 = _interopRequireDefault(_mapPopup); -var _mapMove = require('./mapMove'); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -var _mapMove2 = _interopRequireDefault(_mapMove); + /** + * Created by gavorhes on 12/15/2015. + */ -var _mapPopup = require('./mapPopup'); + var nm = (0, _provide2.default)('olHelpers'); -var _mapPopup2 = _interopRequireDefault(_mapPopup); + /** + * Sets up a map with some default parameters and initializes + * mapMove and mapPopup + * + * @param {object} [options={}] config options + * @param {string} [options.divId=map] map div id + * @param {object} [options.center={}] center config object + * @param {number} [options.center.x=-10018378] center x, web mercator x or lon + * @param {number} [options.center.y=5574910] center y, web mercator y or lat + * @param {number} [options.zoom=7] zoom level + * @param {number} [options.minZoom=undefined] min zoom + * @param {number} [options.maxZoom=undefined] max zoom + * @param {boolean} [options.baseSwitcher=true] if add base map switcher + * @param {boolean} [options.fullScreen=false] if add base map switcher + * @returns {ol.Map} the ol map + */ + function quickMap(options) { + var m = (0, _quickMapBase2.default)(options); + _mapMove2.default.init(m); + _mapPopup2.default.init(m); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + return m; + } -/** - * Created by gavorhes on 12/15/2015. - */ - -var nm = (0, _provide2.default)('olHelpers'); - -/** - * Sets up a map with some default parameters and initializes - * mapMove and mapPopup - * - * @param {object} [options={}] config options - * @param {string} [options.divId=map] map div id - * @param {object} [options.center={}] center config object - * @param {number} [options.center.x=-10018378] center x, web mercator x or lon - * @param {number} [options.center.y=5574910] center y, web mercator y or lat - * @param {number} [options.zoom=7] zoom level - * @param {number} [options.minZoom=undefined] min zoom - * @param {number} [options.maxZoom=undefined] max zoom - * @param {boolean} [options.baseSwitcher=true] if add base map switcher - * @param {boolean} [options.fullScreen=false] if add base map switcher - * @returns {ol.Map} the ol map - */ -function quickMap(options) { - var m = (0, _quickMapBase2.default)(options); - _mapMove2.default.init(m); - _mapPopup2.default.init(m); - - return m; -} - -nm.quickMap = quickMap; -exports.default = quickMap; -module.exports = exports['default']; \ No newline at end of file + nm.quickMap = quickMap; + exports.default = quickMap; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/quickMapBase.js b/lib/olHelpers/quickMapBase.js index f7c2b1e8b49faad19fb0a99dbe3a7e5a2f9b712b..a41864ea3d022bc59ff4a45f15594411bf3586b9 100644 --- a/lib/olHelpers/quickMapBase.js +++ b/lib/olHelpers/quickMapBase.js @@ -1,122 +1,134 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _jquery = require('../jquery'); - -var _jquery2 = _interopRequireDefault(_jquery); - -var _provide = require('../util/provide'); - -var _provide2 = _interopRequireDefault(_provide); - -var _ol = require('../ol/ol'); - -var _ol2 = _interopRequireDefault(_ol); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var nm = (0, _provide2.default)('olHelpers'); - -/** - * Sets up a map with some default parameters and initializes - * mapMove and mapPopup - * - * @param {object} [options={}] config options - * @param {string} [options.divId=map] map div id - * @param {object} [options.center={}] center config object - * @param {number} [options.center.x=-10018378] center x, web mercator x or lon - * @param {number} [options.center.y=5574910] center y, web mercator y or lat - * @param {number} [options.zoom=7] zoom level - * @param {number} [options.minZoom=undefined] min zoom - * @param {number} [options.maxZoom=undefined] max zoom - * @param {boolean} [options.baseSwitcher=true] if add base map switcher - * @param {boolean} [options.fullScreen=false] if add base map switcher - * @returns {ol.Map} the ol map - */ -/** - * Created by gavorhes on 3/25/2016. - */ - -/** - * Created by gavorhes on 12/15/2015. - */ - -function quickMapBase(options) { - options = options || {}; - options.divId = options.divId || 'map'; - options.center = options.center || {}; - options.center.x = typeof options.center.x == 'number' ? options.center.x : -10018378; - options.center.y = typeof options.center.y == 'number' ? options.center.y : 5574910; - options.zoom = typeof options.zoom == 'number' ? options.zoom : 7; - options.baseSwitcher = typeof options.baseSwitcher == 'boolean' ? options.baseSwitcher : true; - options.fullScreen = typeof options.fullScreen == 'boolean' ? options.fullScreen : false; - - var $mapDiv = (0, _jquery2.default)('#' + options.divId); - $mapDiv.css('position', 'relative'); - - var osmLayer = new _ol2.default.layer.Tile({ source: new _ol2.default.source.OSM() }); - var satLayer = new _ol2.default.layer.Tile({ visible: false, source: new _ol2.default.source.MapQuest({ layer: 'sat' }) }); - - var osmCss = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAADQ1NDk5OURFREtLS1FHSFlZWGJRVGJiYWdmZWxsbHRmaXBpanN0c3V0dHp5eX5+fIVzd4F3eeV0jud5juZ8k4aHhomHhoyGh5eGj5OVlJiVlZiYl5qZmJydnKOTlaKZmqKdnaOioaqqqKuzsbOvrrSysLa3tbW4uLm6ub27ub+/vbGXwbCZwbCgxLKlxrOqyLStybO3yrSxyrWzzbW2y7a1zbK4y7W6zbW8y760yrTAzbTFzrPKzrLOzrTJzrTOzr7CwbXC0LXK0LTO0L3I0bPQz7TQz7PS0bXQ0LnR0brW1bzT0r7U077V1Lzc2dqNqteUsdyXscaquuOHneaGmueHnOeJnuiBleiKn+eNoOiOoOWUpOiRo+iSpeiUpeqYpumaqOmdrPSynemgruSqtOmisOmlsuuqtequuOW1vOuxu+uxvOq1ve+xvPK0pvW3o/W5pfO5qvS7qfCwvMOuwc2/wNenxNyyzNe/0Nq31Nq51dy72Oy3wOu4wOu+xey4wO+6xO2+xfTAr/TCsvfFtPHLvvTJuMPDwMfHxcXKyc3DxMvFyMvLyM3PzcDV08DV1MTX1cbY1s7X1sjZ1sra2Mnd3M7b2c7c2tfH1tnB1t7F2d7M29fX1tLY1tDd2tHe3NTf3NnS19rZ1tva2Nnf3t3d28rh3tXg3Nnh3tzj393k39ni4N7k4N7n5uXDyOfLz+zAxu3CyOzEyezKzeDJ3eLM3uvP0u3P0ePf2+7R0u7Q1u/U0+7U1ezc0+7a2e/d2+3f3vbFzvLOwfHN0PPQw/TUx/LWyvLYzPDQ1fPe0ubc4vve4uHh3+nh3+/h2u/h3vHj2vHl3uHm4eTn4uDp5ebo4+Xo5ODq6ebq6OTv6+nl4+/j4O7l4e7n5ujp4+np5Ozq5e7s5urt6O7t6Orw6u7x6u3x7vPj5PDl4fDo4vDq5fDt5vDu6PDv7PTv6fDx6vHx7fH17fXw6fXy7fb07/bz8fT18vn38vr39fr48/r59Pr6+P3++//+/gAAALNTSk0AAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGHRFWHRTb2Z0d2FyZQBwYWludC5uZXQgNC4wLjlsM35OAAAFNElEQVRIS1VVCZxVUxi/9l0UIUT2bMnY43bVI2c0Y01kSWIaS0j2JEtkN41piomZrPPKQ2aQ7JKImOZlnm2493TJzDufuU1Zi+v/fee+mZ//793vnPOd7zvfes5zDBEZkBBjAcIjb+Iiotqgdhat8AMK0vl7/R9N7GiWtshqIr+EZ5gYKibyUsXY1l/mfFpssvUlWQ0FkU3gy4+RB/+kwYcO8pRSnldcOU/r2lAHARSwk2ORgEmOdC1EsuRiYSqMPwwroMIraZk5V2fYJQjCKfZrRmh3gSAZi2i4b7wSylWu8EqZwS59JkFUaW96JbNSc+CEUmt4rorwuZmWdDaoc+uZETuQlTCU5xYzR7muUnVUVo+BcRhre/VwUpasgJwhH7JkYIYA0sNxhmCwUK+lw6vCKBZehw01dEiyw4Q4aE0Z4ahDhKaFQsGnJ2BgqKoTBsNjFy0SlW6whRAZTdm8DBJmkBZhDi1j4xJQBk6ywrWUTymaCxac8lROcdauRGzQSNtA7EHUYhXyEwhhgjFUqRuO+rauhF1awFpzCsmwUbjIFBR0u1bKtyGpulW/H/cVVzkyGaIWTIR9pFAV6GK2gPMXMX8gPk9zzxXgI1kimcAltEYr+cjio1imlKpEa9rOipLm+p+CZ6Bw//qd1/f/O+GwMxbSLpyoZEcwkyh2jIks+3hmdd2jWUw4scxNysnHxU7nSspTRcJjCZGL3IsjsYJMMg5mwgx7gaIOLBFCogAgBBoNa9w+DE6I+Bs7FTgwwrJbHjWDgpYo2KwtBTcYEDuloC9geQw+k2RGnPGpTaOlq7AS+YICUz4DZVaX2TiNDhuYfTtY4geLi0IoCm3XccwM9hx4kU28StQEljDs3ZEpFGA+8dKzLmV9ymIwF5FOGn2GdJM8KLHDJbXyiYVMG9MRTLiXGGg2QKaxM3khPSRrwM9zEIardxU2w/EiA0gOeYKHzDR0V7/QGV3lKIA9ktrDArxO3gdA+k6SKoBiVwcm7NjZb9+Hnztg282TuHVZ9LOISFNt9MgyCetZVczSxnyDbl17Penq6mqpg1IhRaEO2aVLUO4/r17H8tTv6f13h71dduvZI3Y+uMdWksNSauLovJw5hsqiPIUvt0ku7/iBeUR3sksmomYWtRbAjbiLfv2lX9/V7LVG4uYnUZXhQ7f2OPCZEx9wrYWTcePEQqPEML8pl4mMdr/jlXlvHiRiJ2+MSTFY4TTSYStuvz2R/JXh+PPeGXm055J+3/YDWuNu3R3DArPutyg0ZgykMVDU9Ndm22+wYalr2rse48CnsTIFcMn73vfhNrktx1EUcZnPv6ah3Yy5cDTRdBEoGoBeah71dqFyjZDJLkWk3N3v4uuktssjWpzciMPxQeHj8nMKzcGuB0tAyzFhdCKOYWv4HwOQVwIxLG99a6uvH3sJCyO3h+k4EZ+G7+xj5f4XXksoaGrdMRzSc8ARA8+cdOuk2x6fffNNt5x+Ro1omPlrT/CQDlcNlpx4NBIWXhkx7Y3Zp3ofNR7Uv89Om/beW0TLIynHv3vs1VsOFpSWSXvfuPUf9BrRFyxgXdHoKJnQFegPOovvzz59ntrzye240ig8UQ3lDI2VqwagrKIQcLXNFL3wglN2OHdBQ6/vI3kENDVBwRb3k1XtczFbjWn4EzMYi7CF3129+JTYuRSdrGuS92g5dpqn6qXoJQs5xmL8p+Wt4hLbt0mx2OLNZR2bbPy8zJNQGFM/f/CfXZekRYFjGCWjIJpM+WiCzGBPWHhoyaAsjRT/B2Gy5yzYJkwUAAAAAElFTkSuQmCC')"; - var aerialCss = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQALBgIMDQgOBwQOEQcTBwUSCwoVDAwdBw8ZDgUREwYUGAYZFQYZGgkTFQoVGQsZFAwZHBMeDhIbFBEbHAwWIA4bIREcIQ4hCQwjFw4lHBgkDB8sDxUiExIiGhAoGxohFRshGRorHQcrKQsiIQwmKgooJA0pKQ81Jw8yLRMiIxImKxUrJREuKhslJB0rIhooKRUuMBMyLhkwJhozKh48LxUzMRM9MBwzMiUvFCMtGiMwEiwzFCgzHDI+GSIsISkvJSQxIiM2LiY5Jic+Lyk0JSo0Ky49JSs9KSU1NSM7NCs2NS8+NDM1JzU9Ljg7IDJCHS1DLSNAMitCMSxIOjREITZLIDZJKDlFIjpFKztKJT1LKzJBMzpHMD1JMjpKPD1RKjlQNC1DQj5QQEA8MEJGJkBKJUJNK0lLLEJMMkVMPEpONENSLUdZL0pTLkpaLkRUMkRSPEVZMktUM0pVOklZMklZNEpcNU1ZMk1ZNUxfMk5dNkxcOVFUM1RUOFJbNVFZOVNYPVFdOVJdPFVaOVVaPVVdOlVdPVpaNlpdO0phN01hOlBiN1NhPFNoP1piPWFbPmRjPENOQEtPSURTQkJVS0xVQk1VSkxbQkxcS0heUVFXRFRcQlJfTFxeQlpeS05lQk1kSFRjQVRjSlZpQ1tkQlxlSlxpRF1rSVVnUVtlU1llXF9tU1xoXlxwSl9ramRfQmJlQ2FhSWFlSWFlTmVlSWRmTGFoQWFpRWFsRmVpRWVtRmNsSmtlRGpqRmpsS2BmWGRsUmFrW2ptUmZyR2RxTGpxTWVyU2RyW2d5V2tzUmt0WW15VG15WXFuTHNtVnFxTXF4T3h0TnJzUnJ1XHJ4VXN6Wnp0VHx1W315VXp8XGR0YGx0YHVzZXJ0aHR9ZXV+aHl9YHOCXXqBXXeCYHyCY3iEaHyIYn+JaXqKcYB5WIN6Y4SCXoCDZIGEaYCIZoOLa4iCaImJbIOOdYuMco6OeIuVcpOKbZKPc5aQb5eXe5ufg6KjhAAAAAAAAAAAAAAAAOGCeQgAAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGHRFWHRTb2Z0d2FyZQBwYWludC5uZXQgNC4wLjlsM35OAAAH80lEQVRISy1WbXQUVxm+6wqnk3Zmpxl2FG2EGg92C8GDlWptVTwa+uF3xcKmDfFzCUzDsJNsunXipglJXJbrtJWmwZNSnHD3jojRgUIm2UumIZ0JZ7JByrALbMWW0IBW8aRa4+cf76TeX3Nm3uc+z/s+7/vugl4r/aMTrT4e1pPTqnnmJNn5AyUzRnrRle/qE33dsvrBtAQVoxtpZNK3zSzYjUjviWO2Ag+R77dl7W36n/1Ep9KBPG/S+Py0PkjU/gPKQGqwTHryiWYFAXSvMairsio7SjyNsnCzh0qKImV9/7mhfHQZx2yN1O+7rXUm33MUPaboOkAJHaoIdXfJj2xWeyD8jMFEXkvIu5qzpU988gWB5zl+GS+sFe55trEVPdWZB2miq8bBVkNFO2R0qnrfkiXhcJhtDNXE6tbW97/s9O9/7ZfVhx86/CwrROpfvvxboMqeLsuqPr1j44qEwDNMOBximUiYoU8sw7BC/a7T72uEnyJDlGxZ9KcglZRyuqqrv/tSZErgOI4NgRBTIw9EmHAoFGZZnp6aGaJ2GTxfxYs8kKVUQh7WB5hQeC3LsUxoxVKW14l3BX2WcoUYPiZyLLe8teZ+iuT4GGhvV5KpKWkpyzxEr2MZgQ1xdRjfRBoH+2k6lIHjKTHPPBo8CSJISqqq4wGGOcWylIGlgvgNX1Gd8vF5f+IUIwb30ng+Gg2QfBRIMvy0jG8SVkYo4N0zvUXVRztbJ/L6xL7lUZEXBEHkuZqlS6gEAUgKJurnhFtfpACOYd8b/hVbJPqwi44a6KA0sPVjIi/SIyxb3u8KlAJ0S8jRVgrlW+nVHPdrhiXCxu42d86ByksDc80P3MkJFBFQ8Ho1lQegpWJRWFGsDsRwwv7pIyvuQW0ZkrX6NDVFbqcvaQI8vbyqzt5AARrsbKx5yhQEGs+wPO56bOK+0rcwMrOKkpUbZWYxV04UeZZv/cBKFhRL6Qdv9y4LfEDA7/thg7tTmv1a5/GnO0wl0dQg80wglZaHUmxRvjwAHOfyN0mxrpqLUpcjsK3NHYMo4R1o6eho2ZyIb2FoeOC3ILK8kZ2HQMOuWywGXUkJBCeTbYFS0+ym1h2/6UgmvnrvKYZZtIEXGf75C2cIAp5LHNd71x7uPoTjakrWH9e3KFpaatjUvJUysFw0KrLMYMW2lTg4PeUQx6kJEALvxXEmCdVyPLHtCSjBhc01XCjIgafxou+PE6KC1dhxSCwoBCc+N4P3btM84pmdSSjJnjO/nvY4LQfVyz5/I+v6IwjUOMjy+MVCxIbKupTJaEktp7cTKU42Pvjh2m/8cSpC6aPsaX/MHSuUQLVVsIa4RUTs/r/BVAexNdjdnsNG7j/rV93xheLMzKnFrPeTEQchCyCcKb25aAIn7lrAertrZwyNXM8N6zfWrFo3d2SmOEcF83x/r+OOFgrAHYWF7cELjhV7UQo/6WAIUVl9JFl8a//HZ66VpbY3I9QKZqPru77lA+iOWAIr0hKxHCmmr0othSyeIl5y3qt4xT8gSNrKEZozs8Els67rgsLOZ+ygzwMfbtNhobfgzpEyGnz7htPtzUi6PuOoj7K0WF/MXiUFxwGajRD1hjYXHXI9p406qOyinp5/tiWcDHY0jIu4n64Qfq7kliB2gemag9QbOia0PbbDMbd43SHuvxFxrAocxins7MX5Kqbe1QixKBxoV4//PfAgGCu+Rlm4SvZizyDH+0reDHp92iO0BuX3bCfItl0PEwvYLqpwXG2MHlGsQ4S8pMJZv1JGmHiEoHQDdOjwmVlEP/nE9ADKjI8xLI0OOGITfy0SbeG/C2jKUDGSlDhM9I3IpK9iup6XnbRNC7yqueNsJCCIiXzdQhnaGN+46umnEdy5U5UbUJ48LFM9GkJo8BdDOiAZ7ZIQbKhYLMqvhU2wmNxjEAsS2AI7y4nWF64duePbk7YV3zvAVLEMD9AxJRNa3KDUibV7DjnkuprMEYjScFNcaR2ceP2u9R/5k1052Ryme5phAFRswlHjAudiP4dOy7CaxLgdJh9vUlU1702/+LPa1U9fvPi9qlA4XEUBJc3dFlpsR457IDl1iPqLp7o81NQgyV19iYU38uTiv975Pd3SiwQcsGjx+v4/6fl5T7EOOMTCtpbKxfemsQq/3olQZcminADAAI0cuGLHaHOFxbuGvRk/Z9u7CULqoVR6NE0yx1avj30oRhc/jWUoIALGxkz0dg1Dl9iaI7LqOOXKsXJFwjiuEAi70Jra2nW1PL08zLBhZsMABpW5csI7TPfew9ipFKcn5k1i+1KyCWKjC3W/8dF1d666+RaabBVTFTHacjoojBNDh0NDxk+IPTlwfqJkWpbnpFHXIbLbmpxEQ3ff/Z0g/mauXsoln9wDRjy/NHsQFw3P6vWuTJ43/+FZrk2cvAFRipCKdfD9y2+pjRj78s0KdCUDKJvdV91ChngV38T20TM+gghjpJaPlpFr2xbEz5g4A/NGt5rNwdwmYGeeeMXBSLHHUIc+6RsojRH9VTUm3/mLf/64b470XvoxoTKhlMBQ2jMEzo2PjxdGMppmn1RM24bWFJqaQv4BcuJa2Sam7Zokq1ldCsz06NCBHrhwqVQYpfFj42NZexz1EW9SR/kT58nEeQKJb2fPXjjp0u/YUkwHEgLeOnf2nOuf1TRTM02CLKLTPy60/x1CCztqn7Ev+BdsC3m+30decQvW/wBNTwU+CfUQAQAAAABJRU5ErkJggg==')"; - - if (options.baseSwitcher) { - var switcherContent = '<div class="base-map-switcher" title="Toggle Base Layer" style="'; - switcherContent += 'position: absolute; top: 70px; left: 4px; border: solid black 1px; '; - switcherContent += 'height: 50px; width: 50px; z-index: 10; border-radius: 4px; background: ' + aerialCss + ';'; - switcherContent += '"></div>'; - $mapDiv.append(switcherContent); - - $mapDiv.find('.base-map-switcher').click(function () { - "use strict"; - - osmLayer.setVisible(!osmLayer.getVisible()); - satLayer.setVisible(!satLayer.getVisible()); - - if (osmLayer.getVisible()) { - (0, _jquery2.default)(this).css('background', aerialCss); - } else { - (0, _jquery2.default)(this).css('background', osmCss); - } - }); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', '../jquery', '../util/provide', '../ol/ol'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('../jquery'), require('../util/provide'), require('../ol/ol')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.jquery, global.provide, global.ol); + global.quickMapBase = mod.exports; } +})(this, function (module, exports, _jquery, _provide, _ol) { + 'use strict'; - if (options.zoom < 0 || options.zoom > 28) { - throw 'zoom out of range'; - } + Object.defineProperty(exports, "__esModule", { + value: true + }); - if (options.center.x >= -180 && options.center.x <= 180 && options.center.y >= -90 && options.center.y <= 90) { - var p = new _ol2.default.geom.Point([options.center.x, options.center.y]); - p.transform("EPSG:4326", "EPSG:3857"); - var coordinates = p.getCoordinates(); - options.center.x = coordinates[0]; - options.center.y = coordinates[1]; - } + var _jquery2 = _interopRequireDefault(_jquery); - var map = new _ol2.default.Map({ - layers: [osmLayer, satLayer], - target: options.divId, - controls: _ol2.default.control.defaults({ - attributionOptions: { collapsible: false } - }), - view: new _ol2.default.View({ - center: [options.center.x, options.center.y], - zoom: options.zoom, - minZoom: options.minZoom, - maxZoom: options.maxZoom - }) - }); + var _provide2 = _interopRequireDefault(_provide); - if (options.fullScreen) { - map.addControl(new _ol2.default.control.FullScreen()); + var _ol2 = _interopRequireDefault(_ol); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; } - return map; -} + var nm = (0, _provide2.default)('olHelpers'); + + /** + * Sets up a map with some default parameters and initializes + * mapMove and mapPopup + * + * @param {object} [options={}] config options + * @param {string} [options.divId=map] map div id + * @param {object} [options.center={}] center config object + * @param {number} [options.center.x=-10018378] center x, web mercator x or lon + * @param {number} [options.center.y=5574910] center y, web mercator y or lat + * @param {number} [options.zoom=7] zoom level + * @param {number} [options.minZoom=undefined] min zoom + * @param {number} [options.maxZoom=undefined] max zoom + * @param {boolean} [options.baseSwitcher=true] if add base map switcher + * @param {boolean} [options.fullScreen=false] if add base map switcher + * @returns {ol.Map} the ol map + */ + /** + * Created by gavorhes on 3/25/2016. + */ + + /** + * Created by gavorhes on 12/15/2015. + */ + + function quickMapBase(options) { + options = options || {}; + options.divId = options.divId || 'map'; + options.center = options.center || {}; + options.center.x = typeof options.center.x == 'number' ? options.center.x : -10018378; + options.center.y = typeof options.center.y == 'number' ? options.center.y : 5574910; + options.zoom = typeof options.zoom == 'number' ? options.zoom : 7; + options.baseSwitcher = typeof options.baseSwitcher == 'boolean' ? options.baseSwitcher : true; + options.fullScreen = typeof options.fullScreen == 'boolean' ? options.fullScreen : false; + + var $mapDiv = (0, _jquery2.default)('#' + options.divId); + $mapDiv.css('position', 'relative'); + + var osmLayer = new _ol2.default.layer.Tile({ source: new _ol2.default.source.OSM() }); + var satLayer = new _ol2.default.layer.Tile({ visible: false, source: new _ol2.default.source.MapQuest({ layer: 'sat' }) }); + + var osmCss = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAADQ1NDk5OURFREtLS1FHSFlZWGJRVGJiYWdmZWxsbHRmaXBpanN0c3V0dHp5eX5+fIVzd4F3eeV0jud5juZ8k4aHhomHhoyGh5eGj5OVlJiVlZiYl5qZmJydnKOTlaKZmqKdnaOioaqqqKuzsbOvrrSysLa3tbW4uLm6ub27ub+/vbGXwbCZwbCgxLKlxrOqyLStybO3yrSxyrWzzbW2y7a1zbK4y7W6zbW8y760yrTAzbTFzrPKzrLOzrTJzrTOzr7CwbXC0LXK0LTO0L3I0bPQz7TQz7PS0bXQ0LnR0brW1bzT0r7U077V1Lzc2dqNqteUsdyXscaquuOHneaGmueHnOeJnuiBleiKn+eNoOiOoOWUpOiRo+iSpeiUpeqYpumaqOmdrPSynemgruSqtOmisOmlsuuqtequuOW1vOuxu+uxvOq1ve+xvPK0pvW3o/W5pfO5qvS7qfCwvMOuwc2/wNenxNyyzNe/0Nq31Nq51dy72Oy3wOu4wOu+xey4wO+6xO2+xfTAr/TCsvfFtPHLvvTJuMPDwMfHxcXKyc3DxMvFyMvLyM3PzcDV08DV1MTX1cbY1s7X1sjZ1sra2Mnd3M7b2c7c2tfH1tnB1t7F2d7M29fX1tLY1tDd2tHe3NTf3NnS19rZ1tva2Nnf3t3d28rh3tXg3Nnh3tzj393k39ni4N7k4N7n5uXDyOfLz+zAxu3CyOzEyezKzeDJ3eLM3uvP0u3P0ePf2+7R0u7Q1u/U0+7U1ezc0+7a2e/d2+3f3vbFzvLOwfHN0PPQw/TUx/LWyvLYzPDQ1fPe0ubc4vve4uHh3+nh3+/h2u/h3vHj2vHl3uHm4eTn4uDp5ebo4+Xo5ODq6ebq6OTv6+nl4+/j4O7l4e7n5ujp4+np5Ozq5e7s5urt6O7t6Orw6u7x6u3x7vPj5PDl4fDo4vDq5fDt5vDu6PDv7PTv6fDx6vHx7fH17fXw6fXy7fb07/bz8fT18vn38vr39fr48/r59Pr6+P3++//+/gAAALNTSk0AAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGHRFWHRTb2Z0d2FyZQBwYWludC5uZXQgNC4wLjlsM35OAAAFNElEQVRIS1VVCZxVUxi/9l0UIUT2bMnY43bVI2c0Y01kSWIaS0j2JEtkN41piomZrPPKQ2aQ7JKImOZlnm2493TJzDufuU1Zi+v/fee+mZ//793vnPOd7zvfes5zDBEZkBBjAcIjb+Iiotqgdhat8AMK0vl7/R9N7GiWtshqIr+EZ5gYKibyUsXY1l/mfFpssvUlWQ0FkU3gy4+RB/+kwYcO8pRSnldcOU/r2lAHARSwk2ORgEmOdC1EsuRiYSqMPwwroMIraZk5V2fYJQjCKfZrRmh3gSAZi2i4b7wSylWu8EqZwS59JkFUaW96JbNSc+CEUmt4rorwuZmWdDaoc+uZETuQlTCU5xYzR7muUnVUVo+BcRhre/VwUpasgJwhH7JkYIYA0sNxhmCwUK+lw6vCKBZehw01dEiyw4Q4aE0Z4ahDhKaFQsGnJ2BgqKoTBsNjFy0SlW6whRAZTdm8DBJmkBZhDi1j4xJQBk6ywrWUTymaCxac8lROcdauRGzQSNtA7EHUYhXyEwhhgjFUqRuO+rauhF1awFpzCsmwUbjIFBR0u1bKtyGpulW/H/cVVzkyGaIWTIR9pFAV6GK2gPMXMX8gPk9zzxXgI1kimcAltEYr+cjio1imlKpEa9rOipLm+p+CZ6Bw//qd1/f/O+GwMxbSLpyoZEcwkyh2jIks+3hmdd2jWUw4scxNysnHxU7nSspTRcJjCZGL3IsjsYJMMg5mwgx7gaIOLBFCogAgBBoNa9w+DE6I+Bs7FTgwwrJbHjWDgpYo2KwtBTcYEDuloC9geQw+k2RGnPGpTaOlq7AS+YICUz4DZVaX2TiNDhuYfTtY4geLi0IoCm3XccwM9hx4kU28StQEljDs3ZEpFGA+8dKzLmV9ymIwF5FOGn2GdJM8KLHDJbXyiYVMG9MRTLiXGGg2QKaxM3khPSRrwM9zEIardxU2w/EiA0gOeYKHzDR0V7/QGV3lKIA9ktrDArxO3gdA+k6SKoBiVwcm7NjZb9+Hnztg282TuHVZ9LOISFNt9MgyCetZVczSxnyDbl17Penq6mqpg1IhRaEO2aVLUO4/r17H8tTv6f13h71dduvZI3Y+uMdWksNSauLovJw5hsqiPIUvt0ku7/iBeUR3sksmomYWtRbAjbiLfv2lX9/V7LVG4uYnUZXhQ7f2OPCZEx9wrYWTcePEQqPEML8pl4mMdr/jlXlvHiRiJ2+MSTFY4TTSYStuvz2R/JXh+PPeGXm055J+3/YDWuNu3R3DArPutyg0ZgykMVDU9Ndm22+wYalr2rse48CnsTIFcMn73vfhNrktx1EUcZnPv6ah3Yy5cDTRdBEoGoBeah71dqFyjZDJLkWk3N3v4uuktssjWpzciMPxQeHj8nMKzcGuB0tAyzFhdCKOYWv4HwOQVwIxLG99a6uvH3sJCyO3h+k4EZ+G7+xj5f4XXksoaGrdMRzSc8ARA8+cdOuk2x6fffNNt5x+Ro1omPlrT/CQDlcNlpx4NBIWXhkx7Y3Zp3ofNR7Uv89Om/beW0TLIynHv3vs1VsOFpSWSXvfuPUf9BrRFyxgXdHoKJnQFegPOovvzz59ntrzye240ig8UQ3lDI2VqwagrKIQcLXNFL3wglN2OHdBQ6/vI3kENDVBwRb3k1XtczFbjWn4EzMYi7CF3129+JTYuRSdrGuS92g5dpqn6qXoJQs5xmL8p+Wt4hLbt0mx2OLNZR2bbPy8zJNQGFM/f/CfXZekRYFjGCWjIJpM+WiCzGBPWHhoyaAsjRT/B2Gy5yzYJkwUAAAAAElFTkSuQmCC')"; + var aerialCss = "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQALBgIMDQgOBwQOEQcTBwUSCwoVDAwdBw8ZDgUREwYUGAYZFQYZGgkTFQoVGQsZFAwZHBMeDhIbFBEbHAwWIA4bIREcIQ4hCQwjFw4lHBgkDB8sDxUiExIiGhAoGxohFRshGRorHQcrKQsiIQwmKgooJA0pKQ81Jw8yLRMiIxImKxUrJREuKhslJB0rIhooKRUuMBMyLhkwJhozKh48LxUzMRM9MBwzMiUvFCMtGiMwEiwzFCgzHDI+GSIsISkvJSQxIiM2LiY5Jic+Lyk0JSo0Ky49JSs9KSU1NSM7NCs2NS8+NDM1JzU9Ljg7IDJCHS1DLSNAMitCMSxIOjREITZLIDZJKDlFIjpFKztKJT1LKzJBMzpHMD1JMjpKPD1RKjlQNC1DQj5QQEA8MEJGJkBKJUJNK0lLLEJMMkVMPEpONENSLUdZL0pTLkpaLkRUMkRSPEVZMktUM0pVOklZMklZNEpcNU1ZMk1ZNUxfMk5dNkxcOVFUM1RUOFJbNVFZOVNYPVFdOVJdPFVaOVVaPVVdOlVdPVpaNlpdO0phN01hOlBiN1NhPFNoP1piPWFbPmRjPENOQEtPSURTQkJVS0xVQk1VSkxbQkxcS0heUVFXRFRcQlJfTFxeQlpeS05lQk1kSFRjQVRjSlZpQ1tkQlxlSlxpRF1rSVVnUVtlU1llXF9tU1xoXlxwSl9ramRfQmJlQ2FhSWFlSWFlTmVlSWRmTGFoQWFpRWFsRmVpRWVtRmNsSmtlRGpqRmpsS2BmWGRsUmFrW2ptUmZyR2RxTGpxTWVyU2RyW2d5V2tzUmt0WW15VG15WXFuTHNtVnFxTXF4T3h0TnJzUnJ1XHJ4VXN6Wnp0VHx1W315VXp8XGR0YGx0YHVzZXJ0aHR9ZXV+aHl9YHOCXXqBXXeCYHyCY3iEaHyIYn+JaXqKcYB5WIN6Y4SCXoCDZIGEaYCIZoOLa4iCaImJbIOOdYuMco6OeIuVcpOKbZKPc5aQb5eXe5ufg6KjhAAAAAAAAAAAAAAAAOGCeQgAAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGHRFWHRTb2Z0d2FyZQBwYWludC5uZXQgNC4wLjlsM35OAAAH80lEQVRISy1WbXQUVxm+6wqnk3Zmpxl2FG2EGg92C8GDlWptVTwa+uF3xcKmDfFzCUzDsJNsunXipglJXJbrtJWmwZNSnHD3jojRgUIm2UumIZ0JZ7JByrALbMWW0IBW8aRa4+cf76TeX3Nm3uc+z/s+7/vugl4r/aMTrT4e1pPTqnnmJNn5AyUzRnrRle/qE33dsvrBtAQVoxtpZNK3zSzYjUjviWO2Ag+R77dl7W36n/1Ep9KBPG/S+Py0PkjU/gPKQGqwTHryiWYFAXSvMairsio7SjyNsnCzh0qKImV9/7mhfHQZx2yN1O+7rXUm33MUPaboOkAJHaoIdXfJj2xWeyD8jMFEXkvIu5qzpU988gWB5zl+GS+sFe55trEVPdWZB2miq8bBVkNFO2R0qnrfkiXhcJhtDNXE6tbW97/s9O9/7ZfVhx86/CwrROpfvvxboMqeLsuqPr1j44qEwDNMOBximUiYoU8sw7BC/a7T72uEnyJDlGxZ9KcglZRyuqqrv/tSZErgOI4NgRBTIw9EmHAoFGZZnp6aGaJ2GTxfxYs8kKVUQh7WB5hQeC3LsUxoxVKW14l3BX2WcoUYPiZyLLe8teZ+iuT4GGhvV5KpKWkpyzxEr2MZgQ1xdRjfRBoH+2k6lIHjKTHPPBo8CSJISqqq4wGGOcWylIGlgvgNX1Gd8vF5f+IUIwb30ng+Gg2QfBRIMvy0jG8SVkYo4N0zvUXVRztbJ/L6xL7lUZEXBEHkuZqlS6gEAUgKJurnhFtfpACOYd8b/hVbJPqwi44a6KA0sPVjIi/SIyxb3u8KlAJ0S8jRVgrlW+nVHPdrhiXCxu42d86ByksDc80P3MkJFBFQ8Ho1lQegpWJRWFGsDsRwwv7pIyvuQW0ZkrX6NDVFbqcvaQI8vbyqzt5AARrsbKx5yhQEGs+wPO56bOK+0rcwMrOKkpUbZWYxV04UeZZv/cBKFhRL6Qdv9y4LfEDA7/thg7tTmv1a5/GnO0wl0dQg80wglZaHUmxRvjwAHOfyN0mxrpqLUpcjsK3NHYMo4R1o6eho2ZyIb2FoeOC3ILK8kZ2HQMOuWywGXUkJBCeTbYFS0+ym1h2/6UgmvnrvKYZZtIEXGf75C2cIAp5LHNd71x7uPoTjakrWH9e3KFpaatjUvJUysFw0KrLMYMW2lTg4PeUQx6kJEALvxXEmCdVyPLHtCSjBhc01XCjIgafxou+PE6KC1dhxSCwoBCc+N4P3btM84pmdSSjJnjO/nvY4LQfVyz5/I+v6IwjUOMjy+MVCxIbKupTJaEktp7cTKU42Pvjh2m/8cSpC6aPsaX/MHSuUQLVVsIa4RUTs/r/BVAexNdjdnsNG7j/rV93xheLMzKnFrPeTEQchCyCcKb25aAIn7lrAertrZwyNXM8N6zfWrFo3d2SmOEcF83x/r+OOFgrAHYWF7cELjhV7UQo/6WAIUVl9JFl8a//HZ66VpbY3I9QKZqPru77lA+iOWAIr0hKxHCmmr0othSyeIl5y3qt4xT8gSNrKEZozs8Els67rgsLOZ+ygzwMfbtNhobfgzpEyGnz7htPtzUi6PuOoj7K0WF/MXiUFxwGajRD1hjYXHXI9p406qOyinp5/tiWcDHY0jIu4n64Qfq7kliB2gemag9QbOia0PbbDMbd43SHuvxFxrAocxins7MX5Kqbe1QixKBxoV4//PfAgGCu+Rlm4SvZizyDH+0reDHp92iO0BuX3bCfItl0PEwvYLqpwXG2MHlGsQ4S8pMJZv1JGmHiEoHQDdOjwmVlEP/nE9ADKjI8xLI0OOGITfy0SbeG/C2jKUDGSlDhM9I3IpK9iup6XnbRNC7yqueNsJCCIiXzdQhnaGN+46umnEdy5U5UbUJ48LFM9GkJo8BdDOiAZ7ZIQbKhYLMqvhU2wmNxjEAsS2AI7y4nWF64duePbk7YV3zvAVLEMD9AxJRNa3KDUibV7DjnkuprMEYjScFNcaR2ceP2u9R/5k1052Ryme5phAFRswlHjAudiP4dOy7CaxLgdJh9vUlU1702/+LPa1U9fvPi9qlA4XEUBJc3dFlpsR457IDl1iPqLp7o81NQgyV19iYU38uTiv975Pd3SiwQcsGjx+v4/6fl5T7EOOMTCtpbKxfemsQq/3olQZcminADAAI0cuGLHaHOFxbuGvRk/Z9u7CULqoVR6NE0yx1avj30oRhc/jWUoIALGxkz0dg1Dl9iaI7LqOOXKsXJFwjiuEAi70Jra2nW1PL08zLBhZsMABpW5csI7TPfew9ipFKcn5k1i+1KyCWKjC3W/8dF1d666+RaabBVTFTHacjoojBNDh0NDxk+IPTlwfqJkWpbnpFHXIbLbmpxEQ3ff/Z0g/mauXsoln9wDRjy/NHsQFw3P6vWuTJ43/+FZrk2cvAFRipCKdfD9y2+pjRj78s0KdCUDKJvdV91ChngV38T20TM+gghjpJaPlpFr2xbEz5g4A/NGt5rNwdwmYGeeeMXBSLHHUIc+6RsojRH9VTUm3/mLf/64b470XvoxoTKhlMBQ2jMEzo2PjxdGMppmn1RM24bWFJqaQv4BcuJa2Sam7Zokq1ldCsz06NCBHrhwqVQYpfFj42NZexz1EW9SR/kT58nEeQKJb2fPXjjp0u/YUkwHEgLeOnf2nOuf1TRTM02CLKLTPy60/x1CCztqn7Ev+BdsC3m+30decQvW/wBNTwU+CfUQAQAAAABJRU5ErkJggg==')"; + + if (options.baseSwitcher) { + var switcherContent = '<div class="base-map-switcher" title="Toggle Base Layer" style="'; + switcherContent += 'position: absolute; top: 70px; left: 4px; border: solid black 1px; '; + switcherContent += 'height: 50px; width: 50px; z-index: 10; border-radius: 4px; background: ' + aerialCss + ';'; + switcherContent += '"></div>'; + $mapDiv.append(switcherContent); + + $mapDiv.find('.base-map-switcher').click(function () { + "use strict"; + + osmLayer.setVisible(!osmLayer.getVisible()); + satLayer.setVisible(!satLayer.getVisible()); + + if (osmLayer.getVisible()) { + (0, _jquery2.default)(this).css('background', aerialCss); + } else { + (0, _jquery2.default)(this).css('background', osmCss); + } + }); + } + + if (options.zoom < 0 || options.zoom > 28) { + throw 'zoom out of range'; + } + + if (options.center.x >= -180 && options.center.x <= 180 && options.center.y >= -90 && options.center.y <= 90) { + var p = new _ol2.default.geom.Point([options.center.x, options.center.y]); + p.transform("EPSG:4326", "EPSG:3857"); + var coordinates = p.getCoordinates(); + options.center.x = coordinates[0]; + options.center.y = coordinates[1]; + } + + var map = new _ol2.default.Map({ + layers: [osmLayer, satLayer], + target: options.divId, + controls: _ol2.default.control.defaults({ + attributionOptions: { collapsible: false } + }), + view: new _ol2.default.View({ + center: [options.center.x, options.center.y], + zoom: options.zoom, + minZoom: options.minZoom, + maxZoom: options.maxZoom + }) + }); + + if (options.fullScreen) { + map.addControl(new _ol2.default.control.FullScreen()); + } + + return map; + } -nm.quickMapBase = quickMapBase; -exports.default = quickMapBase; -module.exports = exports['default']; \ No newline at end of file + nm.quickMapBase = quickMapBase; + exports.default = quickMapBase; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/quickMapMulti.js b/lib/olHelpers/quickMapMulti.js index 443fba045e9491086020fe51e7b06c0fd8b2c4be..16ebdda1011217a32c411b0465d672ac6cdae279 100644 --- a/lib/olHelpers/quickMapMulti.js +++ b/lib/olHelpers/quickMapMulti.js @@ -1,66 +1,76 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _quickMapBase = require('./quickMapBase'); - -var _quickMapBase2 = _interopRequireDefault(_quickMapBase); - -var _provide = require('../util/provide'); - -var _provide2 = _interopRequireDefault(_provide); - -var _mapMoveCls = require('./mapMoveCls'); - -var _mapMoveCls2 = _interopRequireDefault(_mapMoveCls); - -var _mapPopupCls = require('./mapPopupCls'); - -var _mapPopupCls2 = _interopRequireDefault(_mapPopupCls); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * Created by gavorhes on 12/15/2015. - */ - -var nm = (0, _provide2.default)('olHelpers'); - -/** - * @typedef {object} quickMapMultiReturn - * @property {ol.Map} map The X Coordinate - * @property {MapMoveCls} mapMove The Y Coordinate - * @property {MapPopupCls} mapPopup The Y Coordinate - */ - -/** - * Sets up a map with some default parameters and initializes - * mapMove and mapPopup - * - * @param {object} [options={}] config options - * @param {string} [options.divId=map] map div id - * @param {object} [options.center={}] center config object - * @param {number} [options.center.x=-10018378] center x, web mercator x or lon - * @param {number} [options.center.y=5574910] center y, web mercator y or lat - * @param {number} [options.zoom=7] zoom level - * @param {number} [options.minZoom=undefined] min zoom - * @param {number} [options.maxZoom=undefined] max zoom - * @param {boolean} [options.baseSwitcher=true] if add base map switcher - * @param {boolean} [options.fullScreen=false] if add base map switcher - * @returns {quickMapMultiReturn} return map, map move, and map popup objects - */ -function quickMapMulti(options) { - var m = (0, _quickMapBase2.default)(options); - var mov = new _mapMoveCls2.default(); - var pop = new _mapPopupCls2.default(); - mov.init(m); - pop.init(m); - - return { map: m, mapMove: mov, mapPopup: pop }; -} - -nm.quickMapMulti = quickMapMulti; -exports.default = quickMapMulti; -module.exports = exports['default']; \ No newline at end of file +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', './quickMapBase', '../util/provide', './mapMoveCls', './mapPopupCls'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./quickMapBase'), require('../util/provide'), require('./mapMoveCls'), require('./mapPopupCls')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.quickMapBase, global.provide, global.mapMoveCls, global.mapPopupCls); + global.quickMapMulti = mod.exports; + } +})(this, function (module, exports, _quickMapBase, _provide, _mapMoveCls, _mapPopupCls) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var _quickMapBase2 = _interopRequireDefault(_quickMapBase); + + var _provide2 = _interopRequireDefault(_provide); + + var _mapMoveCls2 = _interopRequireDefault(_mapMoveCls); + + var _mapPopupCls2 = _interopRequireDefault(_mapPopupCls); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + + /** + * Created by gavorhes on 12/15/2015. + */ + + var nm = (0, _provide2.default)('olHelpers'); + + /** + * @typedef {object} quickMapMultiReturn + * @property {ol.Map} map The X Coordinate + * @property {MapMoveCls} mapMove The Y Coordinate + * @property {MapPopupCls} mapPopup The Y Coordinate + */ + + /** + * Sets up a map with some default parameters and initializes + * mapMove and mapPopup + * + * @param {object} [options={}] config options + * @param {string} [options.divId=map] map div id + * @param {object} [options.center={}] center config object + * @param {number} [options.center.x=-10018378] center x, web mercator x or lon + * @param {number} [options.center.y=5574910] center y, web mercator y or lat + * @param {number} [options.zoom=7] zoom level + * @param {number} [options.minZoom=undefined] min zoom + * @param {number} [options.maxZoom=undefined] max zoom + * @param {boolean} [options.baseSwitcher=true] if add base map switcher + * @param {boolean} [options.fullScreen=false] if add base map switcher + * @returns {quickMapMultiReturn} return map, map move, and map popup objects + */ + function quickMapMulti(options) { + var m = (0, _quickMapBase2.default)(options); + var mov = new _mapMoveCls2.default(); + var pop = new _mapPopupCls2.default(); + mov.init(m); + pop.init(m); + + return { map: m, mapMove: mov, mapPopup: pop }; + } + + nm.quickMapMulti = quickMapMulti; + exports.default = quickMapMulti; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/olHelpers/zoomResolutionConvert.js b/lib/olHelpers/zoomResolutionConvert.js index 7ceddee8dc1f02de0acc0783f016757fc4ba6872..5428ae2b9ab22ac792d5df1247dd215558643fbf 100644 --- a/lib/olHelpers/zoomResolutionConvert.js +++ b/lib/olHelpers/zoomResolutionConvert.js @@ -1,87 +1,103 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['exports', '../util/provide'], factory); + } else if (typeof exports !== "undefined") { + factory(exports, require('../util/provide')); + } else { + var mod = { + exports: {} + }; + factory(mod.exports, global.provide); + global.zoomResolutionConvert = mod.exports; + } +})(this, function (exports, _provide) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.zoomToResolution = zoomToResolution; -exports.resolutionToZoom = resolutionToZoom; + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.zoomToResolution = zoomToResolution; + exports.resolutionToZoom = resolutionToZoom; -var _provide = require('../util/provide'); + var _provide2 = _interopRequireDefault(_provide); -var _provide2 = _interopRequireDefault(_provide); + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + var nm = (0, _provide2.default)('olHelpers.zoomResolutionConvert'); /** + * Created by gavorhes on 12/14/2015. + */ -var nm = (0, _provide2.default)('olHelpers.zoomResolutionConvert'); /** - * Created by gavorhes on 12/14/2015. - */ + var _zoomResLookup = [156543.03392804097, //0 + 78271.51696402048, //1 + 39135.75848201024, //2 + 19567.87924100512, //3 + 9783.93962050256, //4 + 4891.96981025128, //5 + 2445.98490512564, //6 + 1222.99245256282, //7 + 611.49622628141, //8 + 305.748113140705, //9 + 152.8740565703525, //10 + 76.43702828517625, //11 + 38.21851414258813, //12 + 19.109257071294063, //13 + 9.554628535647032, //14 + 4.777314267823516, //15 + 2.388657133911758, //16 + 1.194328566955879, //17 + 0.5971642834779395, //18 + 0.29858214173896974, //19 + 0.14929107086948487, //20 + 0.07464553543474244, //21 + 0.03732276771737122, //22 + 0.01866138385868561, //23 + 0.009330691929342804, //24 + 0.004665345964671402, //25 + 0.002332672982335701, //26 + 0.0011663364911678506, //27 + 0.0005831682455839253 //28 + ]; -var _zoomResLookup = [156543.03392804097, //0 -78271.51696402048, //1 -39135.75848201024, //2 -19567.87924100512, //3 -9783.93962050256, //4 -4891.96981025128, //5 -2445.98490512564, //6 -1222.99245256282, //7 -611.49622628141, //8 -305.748113140705, //9 -152.8740565703525, //10 -76.43702828517625, //11 -38.21851414258813, //12 -19.109257071294063, //13 -9.554628535647032, //14 -4.777314267823516, //15 -2.388657133911758, //16 -1.194328566955879, //17 -0.5971642834779395, //18 -0.29858214173896974, //19 -0.14929107086948487, //20 -0.07464553543474244, //21 -0.03732276771737122, //22 -0.01866138385868561, //23 -0.009330691929342804, //24 -0.004665345964671402, //25 -0.002332672982335701, //26 -0.0011663364911678506, //27 -0.0005831682455839253 //28 -]; + /** + * Get the resolution given the zoom level + * @param {number} zoomLevel - the zoom level + * @returns {number|*} the map resolution + */ + function zoomToResolution(zoomLevel) { + "use strict"; -/** - * Get the resolution given the zoom level - * @param {number} zoomLevel - the zoom level - * @returns {number|*} the map resolution - */ -function zoomToResolution(zoomLevel) { - "use strict"; + if (typeof zoomLevel == 'number') { + if (zoomLevel % 1 === 0 && zoomLevel >= 0 && zoomLevel <= 28) { + return _zoomResLookup[zoomLevel]; + } else { + console.log('invalid zoom level provided: ' + zoomLevel); - if (typeof zoomLevel == 'number') { - if (zoomLevel % 1 === 0 && zoomLevel >= 0 && zoomLevel <= 28) { - return _zoomResLookup[zoomLevel]; + return undefined; + } } else { - console.log('invalid zoom level provided: ' + zoomLevel); - return undefined; } - } else { - return undefined; } -} -nm.zoomToResolution = zoomToResolution; + nm.zoomToResolution = zoomToResolution; -/** - * Get resolution from the zoom level - * @param {number} resolution - the resolution - * @returns {number|*} the zoom level - */ -function resolutionToZoom(resolution) { - for (var i = 0; i < _zoomResLookup.length; i++) { - if (resolution >= _zoomResLookup[i]) { - return i; + /** + * Get resolution from the zoom level + * @param {number} resolution - the resolution + * @returns {number|*} the zoom level + */ + function resolutionToZoom(resolution) { + for (var i = 0; i < _zoomResLookup.length; i++) { + if (resolution >= _zoomResLookup[i]) { + return i; + } } - } - return 0; -} + return 0; + } -nm.resolutionToZoom = resolutionToZoom; \ No newline at end of file + nm.resolutionToZoom = resolutionToZoom; +}); \ No newline at end of file diff --git a/lib/rectangle.js b/lib/rectangle.js index 6f8c7cfce26b70eb6227de02e8a8957e22fb016b..ac7b2257d1efbf755c5249d32c19474af30db3d7 100644 --- a/lib/rectangle.js +++ b/lib/rectangle.js @@ -1,107 +1,122 @@ -/** - * Created by gavorhes on 4/13/2016. - */ -// ES6 introduces "classes". For people familiar with -// object oriented languages such as Java as C++ this -// is nothing out of the ordinary. -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -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; }; })(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var Rectangle = (function () { - // The constructor will be executed if you initiate a - // "Rectangle" object with - // - // new Rectangle(width, height) - // - - function Rectangle(width, height) { - _classCallCheck(this, Rectangle); - - this.width = width; - this.height = height; - this.bird = 10; - this.cat = 10; - this.cat = 10; - this.cat = 10; - this.cat = 11; - console.log('bird'); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports); + global.rectangle = mod.exports; } - - // This is also a new feature of ES6. The "get" keyword - // is used to define a "getter". - // - // This means that if you access the "height" like this: - // - // let rectangle = new Rectangle(5, 7); - // console.log(rectangle.width); - // - // The code below will be executed. - - _createClass(Rectangle, [{ - key: 'height', - get: function get() { - return this._height; +})(this, function (module, exports) { + /** + * Created by gavorhes on 4/13/2016. + */ + // ES6 introduces "classes". For people familiar with + // object oriented languages such as Java as C++ this + // is nothing out of the ordinary. + "use strict"; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); } + } - // This defines a "setter". If you write something like: - // - // let rectangle = new Rectangle(5, 7); - // rectangle.height = 10; - // - // the code in the method will be executed with an - // argument of value 10. - , - set: function set(value) { - if (typeof value !== 'number') { - throw new Error('"height" must be a number.'); + 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); } - - this._height = value; } - }, { - key: 'width', - get: function get() { - return this._width; - }, - set: function set(value) { - if (typeof value !== 'number') { - throw new Error('"width" must be a number.'); - } - this._width = value; - } + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); - // This getter calculates the area of the rectangle. + var Rectangle = function () { + // The constructor will be executed if you initiate a + // "Rectangle" object with + // + // new Rectangle(width, height) + // - }, { - key: 'area', - get: function get() { - return this.width * this.height; + function Rectangle(width, height) { + _classCallCheck(this, Rectangle); + + this.width = width; + this.height = height; + this.bird = 10; + this.cat = 10; + this.cat = 10; + this.cat = 10; + this.cat = 11; + console.log('bird'); } - // This calculates its circumference. + // This is also a new feature of ES6. The "get" keyword + // is used to define a "getter". + // + // This means that if you access the "height" like this: + // + // let rectangle = new Rectangle(5, 7); + // console.log(rectangle.width); + // + // The code below will be executed. - }, { - key: 'circumference', - get: function get() { - return 2 * this.width + 2 * this.height; - } - }]); - return Rectangle; -})(); + _createClass(Rectangle, [{ + key: 'height', + get: function get() { + return this._height; + }, + set: function set(value) { + if (typeof value !== 'number') { + throw new Error('"height" must be a number.'); + } + + this._height = value; + } + }, { + key: 'width', + get: function get() { + return this._width; + }, + set: function set(value) { + if (typeof value !== 'number') { + throw new Error('"width" must be a number.'); + } + + this._width = value; + } + }, { + key: 'area', + get: function get() { + return this.width * this.height; + } + }, { + key: 'circumference', + get: function get() { + return 2 * this.width + 2 * this.height; + } + }]); -exports.default = Rectangle; -// -//// We export the Rectangle class so it can -//// be require()'d in other files. -//module.exports = Rectangle; + return Rectangle; + }(); -module.exports = exports['default']; \ No newline at end of file + exports.default = Rectangle; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/test-import.js b/lib/test-import.js index 597f0551bbd88abfd0d121865c0d1c128e4a6c72..9e7b494118741edec8e374a45da0097c97ece2f8 100644 --- a/lib/test-import.js +++ b/lib/test-import.js @@ -1,88 +1,88 @@ -'use strict'; - -var _rectangle = require('./rectangle'); - -var _rectangle2 = _interopRequireDefault(_rectangle); - -var _makeGuid = require('./util/makeGuid'); - -var _makeGuid2 = _interopRequireDefault(_makeGuid); - -var _quickMap = require('./olHelpers/quickMap'); - -var _quickMap2 = _interopRequireDefault(_quickMap); - -var _LayerBaseVectorEsri = require('./layers/LayerBaseVectorEsri'); - -var _LayerBaseVectorEsri2 = _interopRequireDefault(_LayerBaseVectorEsri); - -var _LayerBaseVectorGeoJson = require('./layers/LayerBaseVectorGeoJson'); - -var _LayerBaseVectorGeoJson2 = _interopRequireDefault(_LayerBaseVectorGeoJson); - -var _esriToOlStyle = require('./olHelpers/esriToOlStyle'); - -var _esriToOlStyle2 = _interopRequireDefault(_esriToOlStyle); - -var _mapMoveCls = require('./olHelpers/mapMoveCls'); - -var _mapMoveCls2 = _interopRequireDefault(_mapMoveCls); - -var _mapPopupCls = require('./olHelpers/mapPopupCls'); - -var _mapPopupCls2 = _interopRequireDefault(_mapPopupCls); - -var _SortedFeatures = require('./olHelpers/SortedFeatures'); - -var _SortedFeatures2 = _interopRequireDefault(_SortedFeatures); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -console.log(_makeGuid2.default); /** - * Created by gavorhes on 5/9/2016. - */ - -var g = 10; -console.log('here'); -console.log('here'); -console.log('here'); -var m = 8; - -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); - -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); -g = 10; -var myNew = 14; - -console.log(_makeGuid2.default); -g = 10; -console.log('here'); -console.log('here'); -console.log('here'); -m = 8; - -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); - -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); -console.log('here'); -g = 10; -myNew = 26; \ No newline at end of file +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['./rectangle', './util/makeGuid', './olHelpers/quickMap', './layers/LayerBaseVectorEsri', './layers/LayerBaseVectorGeoJson', './olHelpers/esriToOlStyle', './olHelpers/mapMoveCls', './olHelpers/mapPopupCls', './olHelpers/SortedFeatures'], factory); + } else if (typeof exports !== "undefined") { + factory(require('./rectangle'), require('./util/makeGuid'), require('./olHelpers/quickMap'), require('./layers/LayerBaseVectorEsri'), require('./layers/LayerBaseVectorGeoJson'), require('./olHelpers/esriToOlStyle'), require('./olHelpers/mapMoveCls'), require('./olHelpers/mapPopupCls'), require('./olHelpers/SortedFeatures')); + } else { + var mod = { + exports: {} + }; + factory(global.rectangle, global.makeGuid, global.quickMap, global.LayerBaseVectorEsri, global.LayerBaseVectorGeoJson, global.esriToOlStyle, global.mapMoveCls, global.mapPopupCls, global.SortedFeatures); + global.testImport = mod.exports; + } +})(this, function (_rectangle, _makeGuid, _quickMap, _LayerBaseVectorEsri, _LayerBaseVectorGeoJson, _esriToOlStyle, _mapMoveCls, _mapPopupCls, _SortedFeatures) { + 'use strict'; + + var _rectangle2 = _interopRequireDefault(_rectangle); + + var _makeGuid2 = _interopRequireDefault(_makeGuid); + + var _quickMap2 = _interopRequireDefault(_quickMap); + + var _LayerBaseVectorEsri2 = _interopRequireDefault(_LayerBaseVectorEsri); + + var _LayerBaseVectorGeoJson2 = _interopRequireDefault(_LayerBaseVectorGeoJson); + + var _esriToOlStyle2 = _interopRequireDefault(_esriToOlStyle); + + var _mapMoveCls2 = _interopRequireDefault(_mapMoveCls); + + var _mapPopupCls2 = _interopRequireDefault(_mapPopupCls); + + var _SortedFeatures2 = _interopRequireDefault(_SortedFeatures); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + + console.log(_makeGuid2.default); /** + * Created by gavorhes on 5/9/2016. + */ + + var g = 10; + console.log('here'); + console.log('here'); + console.log('here'); + var m = 8; + + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + g = 10; + var myNew = 14; + + console.log(_makeGuid2.default); + g = 10; + console.log('here'); + console.log('here'); + console.log('here'); + m = 8; + + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + console.log('here'); + g = 10; + myNew = 26; +}); \ No newline at end of file diff --git a/lib/util/checkDefined.js b/lib/util/checkDefined.js index 24ef65ce64cfb8781135a5c075277327e5520157..d7edb6be734fc159ca3c2aedb310ec90f2096281 100644 --- a/lib/util/checkDefined.js +++ b/lib/util/checkDefined.js @@ -1,44 +1,60 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.undefinedOrNull = undefinedOrNull; -exports.definedAndNotNull = definedAndNotNull; - -var _provide = require('./provide'); - -var _provide2 = _interopRequireDefault(_provide); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var nm = (0, _provide2.default)('util.checkDefined'); - -/** - * check if the input is undefined or null - * @param {*} input - input pointer - * @returns {boolean} true undefined or null - */ -/** - * Created by gavorhes on 12/11/2015. - */ -function undefinedOrNull(input) { - "use strict"; - - return typeof input === 'undefined' || input === null; -} - -nm.undefinedOrNull = undefinedOrNull; - -/** - * check if the input is defined and not null - * @param {*} input - input pointer - * @returns {boolean} true defined and not null - */ -function definedAndNotNull(input) { - "use strict"; - - return !undefinedOrNull(input); -} - -nm.definedAndNotNull = definedAndNotNull; \ No newline at end of file +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['exports', './provide'], factory); + } else if (typeof exports !== "undefined") { + factory(exports, require('./provide')); + } else { + var mod = { + exports: {} + }; + factory(mod.exports, global.provide); + global.checkDefined = mod.exports; + } +})(this, function (exports, _provide) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.undefinedOrNull = undefinedOrNull; + exports.definedAndNotNull = definedAndNotNull; + + var _provide2 = _interopRequireDefault(_provide); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + + var nm = (0, _provide2.default)('util.checkDefined'); + + /** + * check if the input is undefined or null + * @param {*} input - input pointer + * @returns {boolean} true undefined or null + */ + /** + * Created by gavorhes on 12/11/2015. + */ + function undefinedOrNull(input) { + "use strict"; + + return typeof input === 'undefined' || input === null; + } + + nm.undefinedOrNull = undefinedOrNull; + + /** + * check if the input is defined and not null + * @param {*} input - input pointer + * @returns {boolean} true defined and not null + */ + function definedAndNotNull(input) { + "use strict"; + + return !undefinedOrNull(input); + } + + nm.definedAndNotNull = definedAndNotNull; +}); \ No newline at end of file diff --git a/lib/util/colors.js b/lib/util/colors.js index dea6959b8c32860cad2fa8ef93e7e47e5aa78e42..d6cbeb9bfa3bbeb547e4ace58df01446ae15885a 100644 --- a/lib/util/colors.js +++ b/lib/util/colors.js @@ -1,194 +1,223 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.rgb2hex = rgb2hex; -exports.hexAlphaToRgbOrRgba = hexAlphaToRgbOrRgba; -exports.rgbToRgba = rgbToRgba; -exports.makeBlueGreenRedGradient = makeBlueGreenRedGradient; -exports.makeBlueGreenRedGradientZScore = makeBlueGreenRedGradientZScore; - -var _provide = require('./provide'); - -var _provide2 = _interopRequireDefault(_provide); - -var _checkDefined = require('./checkDefined'); - -var chk = _interopRequireWildcard(_checkDefined); - -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * Created by gavorhes on 11/3/2015. - */ - -var nm = (0, _provide2.default)('util.colors'); - -/** - * helper function to convert to hex - * @param {number|string} x - the number to convert to hex - * @returns {string} number as hex - * @private - */ -function _hex(x) { - var hexDigits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]; - - return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16]; -} - -/** - * converts an RGB string to hex - * @param {string} rgb - rgb color - * @returns {string} rbg as hex - */ -function rgb2hex(rgb) { - var rgb1 = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); - - return ("#" + _hex(rgb1[1]) + _hex(rgb1[2]) + _hex(rgb1[3])).toUpperCase(); -} - -nm.rgb2hex = rgb2hex; - -/** - * Convert hex string to RGB or RGBA string - * @param {string} hexString - hex color string - * @param {number} [alphaVal=undefined] Alpha value - * @returns {string} - rgb or rgba color - */ -function hexAlphaToRgbOrRgba(hexString, alphaVal) { - hexString = hexString.charAt(0) == "#" ? hexString.substring(1, 7) : hexString; - var r = parseInt(hexString.substring(0, 2), 16).toString() || '0'; - var g = parseInt(hexString.substring(2, 4), 16).toString() || '0'; - var b = parseInt(hexString.substring(4, 6), 16).toString() || '0'; - if (alphaVal) { - return 'rgba(' + r + ',' + g + ',' + b + ',' + alphaVal + ')'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['exports', './provide', './checkDefined'], factory); + } else if (typeof exports !== "undefined") { + factory(exports, require('./provide'), require('./checkDefined')); } else { - return 'rgba(' + r + ',' + g + ',' + b + ')'; + var mod = { + exports: {} + }; + factory(mod.exports, global.provide, global.checkDefined); + global.colors = mod.exports; } -} - -nm.hexAlphaToRgbOrRgba = hexAlphaToRgbOrRgba; - -/** - * adds alpha value to rgb string 'rgb(r, b, g)', returns 'rgba(r, g, b, a)' - * @param {string} rgb - rgb color - * @param {number} alpha - alpha value 0 to 1 - * @returns {string} rgba color - */ -function rgbToRgba(rgb, alpha) { - var pieces = rgb.split(','); - pieces[0] = pieces[0].replace('rgb', 'rgba'); - pieces[2] = pieces[2].replace(')', ''); - pieces.push(' ' + alpha.toFixed(1) + ')'); - - return pieces.join(','); -} - -nm.rgbToRgba = rgbToRgba; - -/** - * @typedef {function} colorLookupByNumber - * @param {number} num - the number to use to retrieve the color - * @returns {string} rgb color - */ - -/** - * Make a blue green red gradient - * @param {number} minVal - minimum value - * @param {number} maxVal - maximum value - * @param {boolean} flipColors - if the colors should be flipped - * @returns {colorLookupByNumber} color lookup function - */ -function makeBlueGreenRedGradient(minVal, maxVal, flipColors) { - - if (typeof flipColors != "boolean") { - flipColors = false; - } - - return function (theVal) { - var r = undefined, - g = undefined, - b = undefined; - var ratio = undefined; +})(this, function (exports, _provide, _checkDefined) { + 'use strict'; - if (chk.undefinedOrNull(theVal)) { - return 'rgb(100,100,100)'; - } + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.rgb2hex = rgb2hex; + exports.hexAlphaToRgbOrRgba = hexAlphaToRgbOrRgba; + exports.rgbToRgba = rgbToRgba; + exports.makeBlueGreenRedGradient = makeBlueGreenRedGradient; + exports.makeBlueGreenRedGradientZScore = makeBlueGreenRedGradientZScore; - var percent = (theVal - minVal) / (maxVal - minVal); + var _provide2 = _interopRequireDefault(_provide); - if (flipColors == true) { - percent = 1 - percent; - } + var chk = _interopRequireWildcard(_checkDefined); - if (percent >= 1) { - r = 255; - g = 0; - b = 0; - } else if (percent <= 0) { - r = 0; - g = 0; - b = 255; - } else if (percent < .25) { - // green up, blue constant - r = 0; - g = Math.floor(255 * percent / 0.25); - b = 255; - } else if (percent < 0.50) { - //blue down, green constant - ratio = (percent - 0.25) / 0.25; - r = 0; - g = 255; - b = 255 - Math.floor(255 * ratio); - } else if (percent < 0.75) { - // red up, green constant - ratio = (percent - 0.5) / 0.25; - r = Math.floor(255 * ratio); - g = 255; - b = 0; + function _interopRequireWildcard(obj) { + if (obj && obj.__esModule) { + return obj; } else { - // green down, red constant - ratio = (percent - 0.75) / 0.25; - r = 255; - g = 255 - Math.floor(255 * ratio); - b = 0; + var newObj = {}; + + if (obj != null) { + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; + } + } + + newObj.default = obj; + return newObj; } + } + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } - r = r.toFixed(); - g = g.toFixed(); - b = b.toFixed(); + /** + * Created by gavorhes on 11/3/2015. + */ - return 'rgb(' + r + ',' + g + ',' + b + ')'; - }; -} + var nm = (0, _provide2.default)('util.colors'); -nm.makeBlueGreenRedGradient = makeBlueGreenRedGradient; + /** + * helper function to convert to hex + * @param {number|string} x - the number to convert to hex + * @returns {string} number as hex + * @private + */ + function _hex(x) { + var hexDigits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]; -/** - * Create a function that will return colors based on a gradient - * @param {number} median - median value - * @param {number} stdDev - standard deviation - * @param {boolean} flipColors - if the colors should be flipped - * @returns {colorLookupByNumber} color lookup function - */ -function makeBlueGreenRedGradientZScore(median, stdDev, flipColors) { + return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16]; + } - var grd = makeBlueGreenRedGradient(-2.5, 2.5, flipColors); + /** + * converts an RGB string to hex + * @param {string} rgb - rgb color + * @returns {string} rbg as hex + */ + function rgb2hex(rgb) { + var rgb1 = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); - return function (theVal) { + return ("#" + _hex(rgb1[1]) + _hex(rgb1[2]) + _hex(rgb1[3])).toUpperCase(); + } - var zScore = undefined; - if (theVal == null) { - zScore = null; + nm.rgb2hex = rgb2hex; + + /** + * Convert hex string to RGB or RGBA string + * @param {string} hexString - hex color string + * @param {number} [alphaVal=undefined] Alpha value + * @returns {string} - rgb or rgba color + */ + function hexAlphaToRgbOrRgba(hexString, alphaVal) { + hexString = hexString.charAt(0) == "#" ? hexString.substring(1, 7) : hexString; + var r = parseInt(hexString.substring(0, 2), 16).toString() || '0'; + var g = parseInt(hexString.substring(2, 4), 16).toString() || '0'; + var b = parseInt(hexString.substring(4, 6), 16).toString() || '0'; + if (alphaVal) { + return 'rgba(' + r + ',' + g + ',' + b + ',' + alphaVal + ')'; } else { - zScore = (theVal - median) / stdDev; + return 'rgba(' + r + ',' + g + ',' + b + ')'; + } + } + + nm.hexAlphaToRgbOrRgba = hexAlphaToRgbOrRgba; + + /** + * adds alpha value to rgb string 'rgb(r, b, g)', returns 'rgba(r, g, b, a)' + * @param {string} rgb - rgb color + * @param {number} alpha - alpha value 0 to 1 + * @returns {string} rgba color + */ + function rgbToRgba(rgb, alpha) { + var pieces = rgb.split(','); + pieces[0] = pieces[0].replace('rgb', 'rgba'); + pieces[2] = pieces[2].replace(')', ''); + pieces.push(' ' + alpha.toFixed(1) + ')'); + + return pieces.join(','); + } + + nm.rgbToRgba = rgbToRgba; + + /** + * @typedef {function} colorLookupByNumber + * @param {number} num - the number to use to retrieve the color + * @returns {string} rgb color + */ + + /** + * Make a blue green red gradient + * @param {number} minVal - minimum value + * @param {number} maxVal - maximum value + * @param {boolean} flipColors - if the colors should be flipped + * @returns {colorLookupByNumber} color lookup function + */ + function makeBlueGreenRedGradient(minVal, maxVal, flipColors) { + + if (typeof flipColors != "boolean") { + flipColors = false; } - return grd(zScore); - }; -} + return function (theVal) { + var r = void 0, + g = void 0, + b = void 0; + var ratio = void 0; + + if (chk.undefinedOrNull(theVal)) { + return 'rgb(100,100,100)'; + } + + var percent = (theVal - minVal) / (maxVal - minVal); + + if (flipColors == true) { + percent = 1 - percent; + } + + if (percent >= 1) { + r = 255; + g = 0; + b = 0; + } else if (percent <= 0) { + r = 0; + g = 0; + b = 255; + } else if (percent < .25) { + // green up, blue constant + r = 0; + g = Math.floor(255 * percent / 0.25); + b = 255; + } else if (percent < 0.50) { + //blue down, green constant + ratio = (percent - 0.25) / 0.25; + r = 0; + g = 255; + b = 255 - Math.floor(255 * ratio); + } else if (percent < 0.75) { + // red up, green constant + ratio = (percent - 0.5) / 0.25; + r = Math.floor(255 * ratio); + g = 255; + b = 0; + } else { + // green down, red constant + ratio = (percent - 0.75) / 0.25; + r = 255; + g = 255 - Math.floor(255 * ratio); + b = 0; + } + + r = r.toFixed(); + g = g.toFixed(); + b = b.toFixed(); + + return 'rgb(' + r + ',' + g + ',' + b + ')'; + }; + } + + nm.makeBlueGreenRedGradient = makeBlueGreenRedGradient; + + /** + * Create a function that will return colors based on a gradient + * @param {number} median - median value + * @param {number} stdDev - standard deviation + * @param {boolean} flipColors - if the colors should be flipped + * @returns {colorLookupByNumber} color lookup function + */ + function makeBlueGreenRedGradientZScore(median, stdDev, flipColors) { + + var grd = makeBlueGreenRedGradient(-2.5, 2.5, flipColors); + + return function (theVal) { + + var zScore = void 0; + if (theVal == null) { + zScore = null; + } else { + zScore = (theVal - median) / stdDev; + } + + return grd(zScore); + }; + } -nm.makeBlueGreenRedGradientZScore = makeBlueGreenRedGradientZScore; \ No newline at end of file + nm.makeBlueGreenRedGradientZScore = makeBlueGreenRedGradientZScore; +}); \ No newline at end of file diff --git a/lib/util/dateConvert.js b/lib/util/dateConvert.js index 2c6a1b204cb5b90efef71cc6bd393e9c96487998..547537c716542762296009ab5a1f49b7f1c88ecf 100644 --- a/lib/util/dateConvert.js +++ b/lib/util/dateConvert.js @@ -1,62 +1,78 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['exports', './provide'], factory); + } else if (typeof exports !== "undefined") { + factory(exports, require('./provide')); + } else { + var mod = { + exports: {} + }; + factory(mod.exports, global.provide); + global.dateConvert = mod.exports; + } +})(this, function (exports, _provide) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.dateToYyyyMmDdHhMmSs = dateToYyyyMmDdHhMmSs; + exports.dateToYyyyMmDdHh000 = dateToYyyyMmDdHh000; + + var _provide2 = _interopRequireDefault(_provide); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.dateToYyyyMmDdHhMmSs = dateToYyyyMmDdHhMmSs; -exports.dateToYyyyMmDdHh000 = dateToYyyyMmDdHh000; + var nm = (0, _provide2.default)('util.dateConvert'); /** + * Created by gavorhes on 11/4/2015. + */ -var _provide = require('./provide'); + function leadingPad(inNum) { + var strNum = inNum.toFixed(); + if (strNum.length < 2) { + strNum = '0' + strNum; + } -var _provide2 = _interopRequireDefault(_provide); + return strNum; + } + + nm.leadingPad = leadingPad; + + /** + * Given a date return a string in the format YYYY-mm-dd hh:MM:SS + * @param {Date} dte to convert + * @returns {string} the formatted date string + */ + function dateToYyyyMmDdHhMmSs(dte) { + var yr = dte.getYear() + 1900; + var month = leadingPad(dte.getMonth() + 1); + var day = leadingPad(dte.getDate()); + var hrs = leadingPad(dte.getHours()); + var mns = leadingPad(dte.getMinutes()); + var secs = leadingPad(dte.getSeconds()); + + return yr + '-' + month + '-' + day + ' ' + hrs + ':' + mns + ':' + secs; + } -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + nm.dateToYyyyMmDdHhMmSs = dateToYyyyMmDdHhMmSs; -var nm = (0, _provide2.default)('util.dateConvert'); /** - * Created by gavorhes on 11/4/2015. - */ + /** + * Given a date return a string in the format YYYYmmdd_hh0000 + * @param {Date} dte the input date + * @returns {string} the formatted date string + */ + function dateToYyyyMmDdHh000(dte) { + var yr = dte.getYear() + 1900; + var month = leadingPad(dte.getMonth() + 1); + var day = leadingPad(dte.getDate()); + var hrs = leadingPad(dte.getHours()); -function leadingPad(inNum) { - var strNum = inNum.toFixed(); - if (strNum.length < 2) { - strNum = '0' + strNum; + return '' + yr + month + day + '_' + hrs + '0000'; } - return strNum; -} - -nm.leadingPad = leadingPad; - -/** - * Given a date return a string in the format YYYY-mm-dd hh:MM:SS - * @param {Date} dte to convert - * @returns {string} the formatted date string - */ -function dateToYyyyMmDdHhMmSs(dte) { - var yr = dte.getYear() + 1900; - var month = leadingPad(dte.getMonth() + 1); - var day = leadingPad(dte.getDate()); - var hrs = leadingPad(dte.getHours()); - var mns = leadingPad(dte.getMinutes()); - var secs = leadingPad(dte.getSeconds()); - - return yr + '-' + month + '-' + day + ' ' + hrs + ':' + mns + ':' + secs; -} - -nm.dateToYyyyMmDdHhMmSs = dateToYyyyMmDdHhMmSs; - -/** - * Given a date return a string in the format YYYYmmdd_hh0000 - * @param {Date} dte the input date - * @returns {string} the formatted date string - */ -function dateToYyyyMmDdHh000(dte) { - var yr = dte.getYear() + 1900; - var month = leadingPad(dte.getMonth() + 1); - var day = leadingPad(dte.getDate()); - var hrs = leadingPad(dte.getHours()); - - return '' + yr + month + day + '_' + hrs + '0000'; -} - -nm.dateToYyyyMmDdHh000 = dateToYyyyMmDdHh000; \ No newline at end of file + nm.dateToYyyyMmDdHh000 = dateToYyyyMmDdHh000; +}); \ No newline at end of file diff --git a/lib/util/formatString.js b/lib/util/formatString.js index e7abfc4062335595d891db5c71ca091ee0ee8df7..31e1a64f5f30c92c8372ab12c2b0d3957494e675 100644 --- a/lib/util/formatString.js +++ b/lib/util/formatString.js @@ -1,44 +1,58 @@ -'use strict'; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports); + global.formatString = mod.exports; + } +})(this, function (module, exports) { + 'use strict'; -Object.defineProperty(exports, "__esModule", { - value: true -}); -/** - * Created by gavorhes on 10/30/2015. - */ - -if (!String.prototype.format) { + Object.defineProperty(exports, "__esModule", { + value: true + }); /** - * helper function for string replacement to keep code clean - * usage - * var aString = 'some{0}stuff{1}replaced'; - * var c = 'cat'; - * var b = 'bird'; - * aString.format(c, b) returns 'somecatstuffbirdreplaced' - * prettier than - * 'some' + c + 'stuff' + b + 'replaced' - * but same effect - * adapted to take a single array that is used for replacement by position ie - * var arrReplacements = [c, b]; - * aString.format(arrReplacements) - * @returns {string} converted string + * Created by gavorhes on 10/30/2015. */ - String.prototype.format = function () { - var args = arguments; - for (var i = 0; i < args.length; i++) { - args[i] = args[i] !== null ? args[i] : ''; - } - //if the first argument is an array, use that - if (args[0].constructor == Array) { - args = args[0]; - } + if (!String.prototype.format) { + /** + * helper function for string replacement to keep code clean + * usage + * var aString = 'some{0}stuff{1}replaced'; + * var c = 'cat'; + * var b = 'bird'; + * aString.format(c, b) returns 'somecatstuffbirdreplaced' + * prettier than + * 'some' + c + 'stuff' + b + 'replaced' + * but same effect + * adapted to take a single array that is used for replacement by position ie + * var arrReplacements = [c, b]; + * aString.format(arrReplacements) + * @returns {string} converted string + */ + String.prototype.format = function () { + var args = arguments; + for (var i = 0; i < args.length; i++) { + args[i] = args[i] !== null ? args[i] : ''; + } + + //if the first argument is an array, use that + if (args[0].constructor == Array) { + args = args[0]; + } - return this.replace(/{(\d+)}/g, function (match, number) { - return typeof args[number] != 'undefined' ? args[number] : match; - }); - }; -} + return this.replace(/{(\d+)}/g, function (match, number) { + return typeof args[number] != 'undefined' ? args[number] : match; + }); + }; + } -exports.default = undefined; -module.exports = exports['default']; \ No newline at end of file + exports.default = undefined; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/util/makeGuid.js b/lib/util/makeGuid.js index ee2e35ad41c1a1881e9bd31755c73bb88ebb0a20..8b7ba0a42c1c78ce6e9f76fbf8b8f5f1f3472075 100644 --- a/lib/util/makeGuid.js +++ b/lib/util/makeGuid.js @@ -1,33 +1,49 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _provide = require('./provide'); - -var _provide2 = _interopRequireDefault(_provide); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var nm = (0, _provide2.default)('util'); - -/** - * guids are used to uniquely identify groups and features - * @returns {string} a new guid - */ -/** - * Created by gavorhes on 11/3/2015. - */ - -function makeGuid() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r = Math.random() * 16 | 0, - v = c == 'x' ? r : r & 0x3 | 0x8; - - return v.toString(16); +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports', './provide'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports, require('./provide')); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports, global.provide); + global.makeGuid = mod.exports; + } +})(this, function (module, exports, _provide) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true }); -} -nm.makeGuid = makeGuid; -exports.default = makeGuid; -module.exports = exports['default']; \ No newline at end of file + + var _provide2 = _interopRequireDefault(_provide); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + + var nm = (0, _provide2.default)('util'); + + /** + * guids are used to uniquely identify groups and features + * @returns {string} a new guid + */ + /** + * Created by gavorhes on 11/3/2015. + */ + + function makeGuid() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + var r = Math.random() * 16 | 0, + v = c == 'x' ? r : r & 0x3 | 0x8; + + return v.toString(16); + }); + } + nm.makeGuid = makeGuid; + exports.default = makeGuid; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/lib/util/provide.js b/lib/util/provide.js index 0029bd451fddfe3d9f2cb9a6ef9e0dc2e72707a3..2b838359a78381ad373c8609132833883eb93743 100644 --- a/lib/util/provide.js +++ b/lib/util/provide.js @@ -1,42 +1,56 @@ -'use strict'; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -/** - * Created by gavorhes on 12/10/2015. - */ - -/** - * create a namespace on the gv object - * @param {string} namespace to create - * @returns {object} object representing the namespace - */ -function provide(namespace) { - "use strict"; - - if (typeof window.gv == 'undefined') { - window.gv = {}; +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['module', 'exports'], factory); + } else if (typeof exports !== "undefined") { + factory(module, exports); + } else { + var mod = { + exports: {} + }; + factory(mod, mod.exports); + global.provide = mod.exports; } +})(this, function (module, exports) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + /** + * Created by gavorhes on 12/10/2015. + */ + + /** + * create a namespace on the gv object + * @param {string} namespace to create + * @returns {object} object representing the namespace + */ + function provide(namespace) { + "use strict"; + + if (typeof window.gv == 'undefined') { + window.gv = {}; + } + + var parts = namespace.split('.'); + var nameSpace = window.gv; - var parts = namespace.split('.'); - var nameSpace = window.gv; + for (var i = 0; i < parts.length; i++) { + var newObject = nameSpace[parts[i]]; - for (var i = 0; i < parts.length; i++) { - var newObject = nameSpace[parts[i]]; + if (typeof newObject == 'undefined') { + nameSpace[parts[i]] = {}; + } - if (typeof newObject == 'undefined') { - nameSpace[parts[i]] = {}; + nameSpace = nameSpace[parts[i]]; } - nameSpace = nameSpace[parts[i]]; + return nameSpace; } - return nameSpace; -} - -provide('util'); -window.gv.util.provide = provide; + provide('util'); + window.gv.util.provide = provide; -exports.default = provide; -module.exports = exports['default']; \ No newline at end of file + exports.default = provide; + module.exports = exports['default']; +}); \ No newline at end of file diff --git a/package.json b/package.json index 9d5d027358e8ac03f19d9cf6aeb198e84a06c60b..5bedc4ac59196696da54d4e8bae2156367dd6cc3 100644 --- a/package.json +++ b/package.json @@ -15,11 +15,12 @@ "ol": "node node_modules/openlayers/tasks/build.js src/ol/ol-config.json src/ol/ol-build.js & COPY /Y src\\ol\\ol-build.js lib\\ol\\ol-build.js", "lint": "eslint src/**/*.js", "jsdoc": "jsdoc -r -d doc src", - "src2lib": "babel src --out-dir lib --ignore ol-build.js --presets es2015 --plugins add-module-exports" + "src2lib": "babel src --out-dir lib --ignore ol-build.js" }, "author": "TOPS Lab", "license": "ISC", "devDependencies": { + "babel-cli": "^6.9.0", "babel-plugin-add-module-exports": "^0.2.0", "babel-plugin-transform-es2015-modules-umd": "^6.8.0", "babel-preset-es2015": "^6.6.0", @@ -28,6 +29,7 @@ "expect": "^1.20.1", "jasmine": "^2.4.1", "jasmine-core": "^2.4.1", + "jsdoc-babel": "^0.1.0", "karma": "^0.13.22", "karma-chai": "^0.1.0", "karma-coverage": "^1.0.0", diff --git a/projects/itsMap.js b/projects/itsMap.js index 1a721a32e6d7bfe46e7c9d592e672ed6f59a1704..fef646b0d289e46c16eb93dcd0137a412a44e5d0 100644 --- a/projects/itsMap.js +++ b/projects/itsMap.js @@ -6,7 +6,18 @@ require('babel-polyfill'); import quickMap from '../lib/olHelpers/quickMap'; -import ItsLayerCollection from '../src/collections/ItsLayerCollection'; + + + +import quickMap from '../lib/olHelpers/quickMap'; +import co from '../lib/util/colors'; + +const c = require('../lib/util/colors'); + + + + +import ItsLayerCollection from '../lib/collections/ItsLayerCollection'; import LayerLegend from '../src/collections/LayerLegend'; diff --git a/src/gulp-helpers.js b/src/gulp-helpers.js index 2ed331ff200c32a2324c88bd3c41969d08502677..250942f7d5271afa7bec666e546a6f8b024fc156 100644 --- a/src/gulp-helpers.js +++ b/src/gulp-helpers.js @@ -73,8 +73,10 @@ export function bundleEs2015(inputFile, outFile, production) { bundler.transform(babelify.configure({ + global: true, presets: ["es2015"], - ignore: /ol\-build\.js|jquery\.min|\/node_modules\/(?!webmapsjs\/)|\/node_modules\/webmapsjs\/(?!lib\/)/ + ignore: /ol\-build\.js|jquery\.min/ + // ignore: /ol\-build\.js|jquery\.min|\/node_modules\/(?!webmapsjs\/)|\/node_modules\/webmapsjs\/(?!lib\/)/ })); if (!production) { diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000000000000000000000000000000000000..585bd377c2f523772d7259bc309b06afbae4deee --- /dev/null +++ b/src/index.js @@ -0,0 +1,8 @@ +/** + * Created by gavorhes on 5/20/2016. + */ + +import _LayerBase from './layers/LayerBase'; + +export const LayerBase = _LayerBase; + diff --git a/src/jquery.js b/src/jquery.js index 84800781988e94838697f3f161911693ee6e6b67..1e41f2cb4bedcd06fd64c592a458ba1a3c7382b1 100644 --- a/src/jquery.js +++ b/src/jquery.js @@ -1,6 +1,9 @@ /** * Created by gavorhes on 5/3/2016. */ -global.jQuery = require('jquery'); +const $ = require('jquery'); -export default global.jQuery; \ No newline at end of file +global.$ = $; +global.jQuery = $; + +export default $;