Skip to content
Snippets Groups Projects
Commit bca4128a authored by Glenn Vorhes's avatar Glenn Vorhes
Browse files

add types to sorted features

parent 5f7271fe
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ import ol = require('custom-ol');
/**
* take an array of features and sort by a given property name
*/
declare class SortedFeatures {
export declare class SortedFeatures {
sortedFeatures: Array<ol.Feature>;
propertyName: string;
_propertyType: string;
......@@ -11,7 +11,7 @@ declare class SortedFeatures {
* @param {Array<ol.Feature>} features array of ol features
* @param {string} propertyName - the property name to use for lookup
*/
constructor(features: any, propertyName: any);
constructor(features: ol.Feature[], propertyName: string);
/**
* recursive search to find the value
* @param {number|string} propertyValue - the property value to search for
......
......@@ -112,6 +112,7 @@ var SortedFeatures = (function () {
};
return SortedFeatures;
}());
exports.SortedFeatures = SortedFeatures;
nm.SortedFeatures = SortedFeatures;
exports.default = SortedFeatures;
//# sourceMappingURL=SortedFeatures.js.map
\ No newline at end of file
{"version":3,"file":"SortedFeatures.js","sourceRoot":"","sources":["../../src/olHelpers/SortedFeatures.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,2CAAsC;AAEtC,IAAI,EAAE,GAAG,iBAAO,CAAC,WAAW,CAAC,CAAC;AAE9B;;GAEG;AACH;IAKI;;;;OAIG;IACH,wBAAY,QAAQ,EAAE,YAAY;QAC9B,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,CAAC,aAAa,GAAG,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAEtF,IAAI,QAAM,GAAG,IAAI,CAAC;YAClB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;gBACnC,EAA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AC,aAAa,EAAE,UAAU,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QACtF,CAAC;IACL,CAAC;IACL,qBAAC;AAAD,CAAC,AA1GD,IA0GC;AAED,EAAE,CAAC,cAAc,GAAG,cAAc,CAAC;AACnC,kBAAe,cAAc,CAAC","sourcesContent":["/**\r\n * Created by gavorhes on 12/23/2015.\r\n */\r\nimport provide from '../util/provide';\r\nimport ol = require('custom-ol');\r\nlet nm = provide('olHelpers');\r\n\r\n/**\r\n * take an array of features and sort by a given property name\r\n */\r\nclass SortedFeatures {\r\n sortedFeatures: Array<ol.Feature>;\r\n propertyName: string;\r\n _propertyType: string;\r\n\r\n /**\r\n *\r\n * @param {Array<ol.Feature>} features array of ol features\r\n * @param {string} propertyName - the property name to use for lookup\r\n */\r\n constructor(features, propertyName) {\r\n this.sortedFeatures = features;\r\n this.propertyName = propertyName;\r\n\r\n if (this.sortedFeatures.length > 0) {\r\n this._propertyType = typeof this.sortedFeatures[0].getProperties()[this.propertyName];\r\n\r\n let __this = this;\r\n this.sortedFeatures.sort(function (a, b) : number {\r\n if (__this._propertyType == 'number'){\r\n let aMinusB = a['getProperties']()[__this.propertyName] - b['getProperties']()[__this.propertyName];\r\n if (aMinusB == 0){\r\n return 0;\r\n } else {\r\n return aMinusB > 0 ? 1 : -1;\r\n }\r\n } else if (__this._propertyType == 'string'){\r\n let propA = a['getProperties']()[__this.propertyName] || '';\r\n let propB = b['getProperties']()[__this.propertyName] || '';\r\n propA = propA.toString().trim();\r\n propB = propB.toString().trim();\r\n\r\n if (propA == propB){\r\n return 0;\r\n } else {\r\n return propA > propB ? 1 : 0;\r\n }\r\n }\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * recursive search to find the value\r\n * @param {number|string} propertyValue - the property value to search for\r\n * @param {boolean} [exactMatch=false] if only an exact match should be returned\r\n * @param {Array} [sortedFeatures=this.sortedFeatures] - the candidate features\r\n * @returns {ol.Feature|undefined} the feature matching the lookup\r\n */\r\n getFeature(propertyValue, exactMatch: boolean = false, sortedFeatures? :Array<ol.Feature>): ol.Feature {\r\n if (typeof sortedFeatures == 'undefined'){\r\n sortedFeatures = this.sortedFeatures;\r\n }\r\n\r\n\r\n if (sortedFeatures.length == 0){\r\n return undefined;\r\n }\r\n\r\n if (sortedFeatures.length == 1){\r\n if (exactMatch){\r\n if (sortedFeatures[0].getProperties()[this.propertyName] == propertyValue){\r\n return sortedFeatures[0];\r\n } else {\r\n return undefined;\r\n }\r\n } else {\r\n return sortedFeatures[0];\r\n }\r\n }\r\n\r\n let lowProp = sortedFeatures[0].getProperties()[this.propertyName];\r\n let highProp = sortedFeatures[sortedFeatures.length - 1].getProperties()[this.propertyName];\r\n\r\n if (exactMatch){\r\n if (lowProp == propertyValue){\r\n return sortedFeatures[0];\r\n } else if (propertyValue < lowProp){\r\n return undefined;\r\n } else if (highProp == propertyValue){\r\n return sortedFeatures[sortedFeatures.length - 1];\r\n } else if (propertyValue > highProp){\r\n return undefined;\r\n }\r\n } else {\r\n if (propertyValue <= lowProp){\r\n return sortedFeatures[0];\r\n } else if (propertyValue >= highProp){\r\n return sortedFeatures[sortedFeatures.length - 1];\r\n }\r\n }\r\n\r\n let midIndex = Math.floor(sortedFeatures.length / 2);\r\n let midFeature = sortedFeatures[midIndex];\r\n let midProperty = midFeature.getProperties()[this.propertyName];\r\n\r\n if (midProperty === propertyValue){\r\n return midFeature;\r\n }\r\n\r\n if (propertyValue < midProperty){\r\n return this.getFeature(propertyValue, exactMatch, sortedFeatures.slice(0, midIndex));\r\n } else {\r\n return this.getFeature(propertyValue, exactMatch, sortedFeatures.slice(midIndex));\r\n }\r\n }\r\n}\r\n\r\nnm.SortedFeatures = SortedFeatures;\r\nexport default SortedFeatures;\r\n\r\n"]}
\ No newline at end of file
{"version":3,"file":"SortedFeatures.js","sourceRoot":"","sources":["../../src/olHelpers/SortedFeatures.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,2CAAsC;AAEtC,IAAI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CAAC,CAAC,CAAC;QACrD,IAAI,UAAU,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,WAAW,GAAG,UAAU,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAEhE,EAAE,CAAC,CAAC,WAAW,KAAM,aAAa,CAAC,CAAA,CAAC;YAChC,MAAM,CAAC,UAAU,CAAC;QACtB,CAAC;QAED,EAAE,CAAC,CAAC,aAAa,GAAG,WAAW,CAAC,CAAA,CAAC;YAC7B,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,UAAU,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;QACzF,CAAC;QAAC,IAAI,CAAC,CAAC;YACJ,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,UAAU,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QACtF,CAAC;IACL,CAAC;IACL,qBAAC;AAAD,CAAC,AA1GD,IA0GC;AA1GY,wCAAc;AA4G3B,EAAE,CAAC,cAAc,GAAG,cAAc,CAAC;AACnC,kBAAe,cAAc,CAAC","sourcesContent":["/**\r\n * Created by gavorhes on 12/23/2015.\r\n */\r\nimport provide from '../util/provide';\r\nimport ol = require('custom-ol');\r\nlet nm = provide('olHelpers');\r\n\r\n/**\r\n * take an array of features and sort by a given property name\r\n */\r\nexport class SortedFeatures {\r\n sortedFeatures: Array<ol.Feature>;\r\n propertyName: string;\r\n _propertyType: string;\r\n\r\n /**\r\n *\r\n * @param {Array<ol.Feature>} features array of ol features\r\n * @param {string} propertyName - the property name to use for lookup\r\n */\r\n constructor(features: ol.Feature[], propertyName: string) {\r\n this.sortedFeatures = features;\r\n this.propertyName = propertyName;\r\n\r\n if (this.sortedFeatures.length > 0) {\r\n this._propertyType = typeof this.sortedFeatures[0].getProperties()[this.propertyName];\r\n\r\n let __this = this;\r\n this.sortedFeatures.sort(function (a, b) : number {\r\n if (__this._propertyType == 'number'){\r\n let aMinusB = a['getProperties']()[__this.propertyName] - b['getProperties']()[__this.propertyName];\r\n if (aMinusB == 0){\r\n return 0;\r\n } else {\r\n return aMinusB > 0 ? 1 : -1;\r\n }\r\n } else if (__this._propertyType == 'string'){\r\n let propA = a['getProperties']()[__this.propertyName] || '';\r\n let propB = b['getProperties']()[__this.propertyName] || '';\r\n propA = propA.toString().trim();\r\n propB = propB.toString().trim();\r\n\r\n if (propA == propB){\r\n return 0;\r\n } else {\r\n return propA > propB ? 1 : 0;\r\n }\r\n }\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * recursive search to find the value\r\n * @param {number|string} propertyValue - the property value to search for\r\n * @param {boolean} [exactMatch=false] if only an exact match should be returned\r\n * @param {Array} [sortedFeatures=this.sortedFeatures] - the candidate features\r\n * @returns {ol.Feature|undefined} the feature matching the lookup\r\n */\r\n getFeature(propertyValue, exactMatch: boolean = false, sortedFeatures? :Array<ol.Feature>): ol.Feature {\r\n if (typeof sortedFeatures == 'undefined'){\r\n sortedFeatures = this.sortedFeatures;\r\n }\r\n\r\n\r\n if (sortedFeatures.length == 0){\r\n return undefined;\r\n }\r\n\r\n if (sortedFeatures.length == 1){\r\n if (exactMatch){\r\n if (sortedFeatures[0].getProperties()[this.propertyName] == propertyValue){\r\n return sortedFeatures[0];\r\n } else {\r\n return undefined;\r\n }\r\n } else {\r\n return sortedFeatures[0];\r\n }\r\n }\r\n\r\n let lowProp = sortedFeatures[0].getProperties()[this.propertyName];\r\n let highProp = sortedFeatures[sortedFeatures.length - 1].getProperties()[this.propertyName];\r\n\r\n if (exactMatch){\r\n if (lowProp == propertyValue){\r\n return sortedFeatures[0];\r\n } else if (propertyValue < lowProp){\r\n return undefined;\r\n } else if (highProp == propertyValue){\r\n return sortedFeatures[sortedFeatures.length - 1];\r\n } else if (propertyValue > highProp){\r\n return undefined;\r\n }\r\n } else {\r\n if (propertyValue <= lowProp){\r\n return sortedFeatures[0];\r\n } else if (propertyValue >= highProp){\r\n return sortedFeatures[sortedFeatures.length - 1];\r\n }\r\n }\r\n\r\n let midIndex = Math.floor(sortedFeatures.length / 2);\r\n let midFeature = sortedFeatures[midIndex];\r\n let midProperty = midFeature.getProperties()[this.propertyName];\r\n\r\n if (midProperty === propertyValue){\r\n return midFeature;\r\n }\r\n\r\n if (propertyValue < midProperty){\r\n return this.getFeature(propertyValue, exactMatch, sortedFeatures.slice(0, midIndex));\r\n } else {\r\n return this.getFeature(propertyValue, exactMatch, sortedFeatures.slice(midIndex));\r\n }\r\n }\r\n}\r\n\r\nnm.SortedFeatures = SortedFeatures;\r\nexport default SortedFeatures;\r\n\r\n"]}
\ No newline at end of file
......@@ -8,7 +8,7 @@ let nm = provide('olHelpers');
/**
* take an array of features and sort by a given property name
*/
class SortedFeatures {
export class SortedFeatures {
sortedFeatures: Array<ol.Feature>;
propertyName: string;
_propertyType: string;
......@@ -18,7 +18,7 @@ class SortedFeatures {
* @param {Array<ol.Feature>} features array of ol features
* @param {string} propertyName - the property name to use for lookup
*/
constructor(features, propertyName) {
constructor(features: ol.Feature[], propertyName: string) {
this.sortedFeatures = features;
this.propertyName = propertyName;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment