Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webmapsjs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glenn Vorhes
webmapsjs
Commits
353ed43c
Commit
353ed43c
authored
5 years ago
by
Glenn Vorhes
Browse files
Options
Downloads
Patches
Plain Diff
sorted features
parent
6aabab11
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dist/olHelpers/SortedFeatures.js
+26
-27
26 additions, 27 deletions
dist/olHelpers/SortedFeatures.js
dist/olHelpers/SortedFeatures.js.map
+1
-1
1 addition, 1 deletion
dist/olHelpers/SortedFeatures.js.map
src/olHelpers/SortedFeatures.ts
+26
-26
26 additions, 26 deletions
src/olHelpers/SortedFeatures.ts
with
53 additions
and
54 deletions
dist/olHelpers/SortedFeatures.js
+
26
−
27
View file @
353ed43c
...
...
@@ -17,33 +17,32 @@ class SortedFeatures {
constructor
(
features
,
propertyName
)
{
this
.
sortedFeatures
=
features
;
this
.
propertyName
=
propertyName
;
if
(
this
.
sortedFeatures
.
length
>
0
)
{
this
.
_propertyType
=
typeof
this
.
sortedFeatures
[
0
].
getProperties
()[
this
.
propertyName
];
// let __this = this;
this
.
sortedFeatures
.
sort
((
a
,
b
)
=>
{
if
(
this
.
_propertyType
==
'
number
'
)
{
let
aMinusB
=
a
.
getProperties
()[
this
.
propertyName
]
-
b
.
getProperties
()[
this
.
propertyName
];
if
(
aMinusB
==
0
)
{
return
0
;
}
else
{
return
aMinusB
>
0
?
1
:
-
1
;
}
}
else
if
(
this
.
_propertyType
==
'
string
'
)
{
let
propA
=
a
.
getProperties
()[
this
.
propertyName
]
||
''
;
let
propB
=
b
.
getProperties
()[
this
.
propertyName
]
||
''
;
propA
=
propA
.
toString
().
trim
();
propB
=
propB
.
toString
().
trim
();
if
(
propA
==
propB
)
{
return
0
;
}
else
{
return
propA
>
propB
?
1
:
0
;
}
}
});
}
// if (this.sortedFeatures.length > 0) {
// this._propertyType = typeof this.sortedFeatures[0].getProperties()[this.propertyName];
//
// // let __this = this;
// this.sortedFeatures.sort( (a: Feature, b: Feature) : number =>{
// if (this._propertyType == 'number'){
// let aMinusB = a.getProperties()[this.propertyName] - b.getProperties()[this.propertyName];
// if (aMinusB == 0){
// return 0;
// } else {
// return aMinusB > 0 ? 1 : -1;
// }
// } else if (this._propertyType == 'string'){
// let propA = a.getProperties()[this.propertyName] || '';
// let propB = b.getProperties()[this.propertyName] || '';
// propA = propA.toString().trim();
// propB = propB.toString().trim();
//
// if (propA == propB){
// return 0;
// } else {
// return propA > propB ? 1 : 0;
// }
// }
// });
// }
}
/**
* recursive search to find the value
...
...
This diff is collapsed.
Click to expand it.
dist/olHelpers/SortedFeatures.js.map
+
1
−
1
View file @
353ed43c
{"version":3,"file":"SortedFeatures.js","sourceRoot":"","sources":["../../src/olHelpers/SortedFeatures.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,6CAAsC;AAEtC,IAAI,EAAE,GAAG,iBAAO,CAAC,WAAW,CAAC,CAAC;AAE9B;;GAEG;AACH,MAAa,cAAc;IAKvB;;;;OAIG;IACH,YAAY,QAAmB,EAAE,YAAoB;QACjD,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;YAChC,I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AAI,aAAa,IAAI,QAAQ,EAAC;gBACjC,OAAO,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aACpD;SACJ;QAED,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,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,IAAI,WAAW,KAAM,aAAa,EAAC;YAC/B,OAAO,UAAU,CAAC;SACrB;QAED,IAAI,aAAa,GAAG,WAAW,EAAC;YAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,UAAU,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;SACxF;aAAM;YACH,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,UAAU,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;SACrF;IACL,CAAC;CACJ;AA1GD,wCA0GC;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 Feature from 'ol/Feature';\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<Feature>;\r\n propertyName: string;\r\n _propertyType: string;\r\n\r\n /**\r\n *\r\n * @param {Array<Feature>} features array of ol features\r\n * @param {string} propertyName - the property name to use for lookup\r\n */\r\n constructor(features: 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( (a: Feature, b: Feature) : 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 {Feature|undefined} the feature matching the lookup\r\n */\r\n getFeature(propertyValue: number|string, exactMatch: boolean = false, sortedFeatures? :Array<Feature>): 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,6CAAsC;AAEtC,IAAI,EAAE,GAAG,iBAAO,CAAC,WAAW,CAAC,CAAC;AAE9B;;GAEG;AACH,MAAa,cAAc;IAKvB;;;;OAIG;IACH,YAAY,QAAmB,EAAE,YAAoB;QACjD,IAAI,CAAC,cAAc,GAAG,QAAQ,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QAEjC,wCAAwC;QACxC,6FAA6F;QAC7F,EAAE;QACF,4BAA4B;QAC5B,sEAAsE;QACtE,+CAA+C;QAC/C,yGAAyG;QACzG,iCAAiC;QACjC,4BAA4B;QAC5B,uBAAuB;QACvB,+CAA+C;QAC/C,gBAAgB;QAChB,sDAAsD;QACtD,sEAAsE;QACtE,sEAAsE;QACtE,+CAA+C;QAC/C,+CAA+C;QAC/C,EAAE;QACF,mCAAmC;QACnC,4BAA4B;QAC5B,uBAAuB;QACvB,gDAAgD;QAChD,gBAAgB;QAChB,YAAY;QACZ,UAAU;QACV,IAAI;IACR,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,aAA4B,EAAE,aAAsB,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AI,QAAQ,EAAC;gBACjC,OAAO,cAAc,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aACpD;SACJ;QAED,IAAI,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,GAAG,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,IAAI,WAAW,KAAM,aAAa,EAAC;YAC/B,OAAO,UAAU,CAAC;SACrB;QAED,IAAI,aAAa,GAAG,WAAW,EAAC;YAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,UAAU,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;SACxF;aAAM;YACH,OAAO,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,UAAU,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;SACrF;IACL,CAAC;CACJ;AA1GD,wCA0GC;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 Feature from 'ol/Feature';\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<Feature>;\r\n propertyName: string;\r\n _propertyType: string;\r\n\r\n /**\r\n *\r\n * @param {Array<Feature>} features array of ol features\r\n * @param {string} propertyName - the property name to use for lookup\r\n */\r\n constructor(features: 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( (a: Feature, b: Feature) : 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 {Feature|undefined} the feature matching the lookup\r\n */\r\n getFeature(propertyValue: number|string, exactMatch: boolean = false, sortedFeatures? :Array<Feature>): 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
This diff is collapsed.
Click to expand it.
src/olHelpers/SortedFeatures.ts
+
26
−
26
View file @
353ed43c
...
...
@@ -22,32 +22,32 @@ export class SortedFeatures {
this
.
sortedFeatures
=
features
;
this
.
propertyName
=
propertyName
;
if
(
this
.
sortedFeatures
.
length
>
0
)
{
this
.
_propertyType
=
typeof
this
.
sortedFeatures
[
0
].
getProperties
()[
this
.
propertyName
];
// let __this = this;
this
.
sortedFeatures
.
sort
(
(
a
:
Feature
,
b
:
Feature
)
:
number
=>
{
if
(
this
.
_propertyType
==
'
number
'
){
let
aMinusB
=
a
.
getProperties
()[
this
.
propertyName
]
-
b
.
getProperties
()[
this
.
propertyName
];
if
(
aMinusB
==
0
){
return
0
;
}
else
{
return
aMinusB
>
0
?
1
:
-
1
;
}
}
else
if
(
this
.
_propertyType
==
'
string
'
){
let
propA
=
a
.
getProperties
()[
this
.
propertyName
]
||
''
;
let
propB
=
b
.
getProperties
()[
this
.
propertyName
]
||
''
;
propA
=
propA
.
toString
().
trim
();
propB
=
propB
.
toString
().
trim
();
if
(
propA
==
propB
){
return
0
;
}
else
{
return
propA
>
propB
?
1
:
0
;
}
}
});
}
//
if (this.sortedFeatures.length > 0) {
//
this._propertyType = typeof this.sortedFeatures[0].getProperties()[this.propertyName];
//
//
// let __this = this;
//
this.sortedFeatures.sort( (a: Feature, b: Feature) : number =>{
//
if (this._propertyType == 'number'){
//
let aMinusB = a.getProperties()[this.propertyName] - b.getProperties()[this.propertyName];
//
if (aMinusB == 0){
//
return 0;
//
} else {
//
return aMinusB > 0 ? 1 : -1;
//
}
//
} else if (this._propertyType == 'string'){
//
let propA = a.getProperties()[this.propertyName] || '';
//
let propB = b.getProperties()[this.propertyName] || '';
//
propA = propA.toString().trim();
//
propB = propB.toString().trim();
//
//
if (propA == propB){
//
return 0;
//
} else {
//
return propA > propB ? 1 : 0;
//
}
//
}
//
});
//
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment