-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor lasso, centralize service requests
- Loading branch information
1 parent
5bc9014
commit e5ba9ba
Showing
7 changed files
with
175 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
export * from './types' | ||
export { getWfsFeatures } from './wfs' | ||
export { | ||
getVectorFeaturesByBboxRequest, | ||
getVectorFeaturesByFeatureRequest, | ||
} from './vector' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { rawLayerList } from '@masterportal/masterportalapi' | ||
import { Feature } from 'ol' | ||
|
||
const supportedFormats = ['OAF', 'WFS'] | ||
|
||
export const getVectorFeaturesByBboxRequest = ({ | ||
bbox, | ||
fetchLayerId, | ||
projectionCode, | ||
}: { | ||
bbox: number[] | ||
fetchLayerId: string | ||
projectionCode: string | ||
}) => { | ||
const serviceDefinition = rawLayerList.getLayerWhere({ id: fetchLayerId }) | ||
if (!supportedFormats.includes(serviceDefinition.typ)) { | ||
throw new Error( | ||
`@polar/lib-get-features#getVectorFeaturesByBboxRequest: Layer with ID "${fetchLayerId}" of type "${serviceDefinition.typ}" used to retrieve vector data, but is not within the range of supported types [${supportedFormats}].` | ||
) | ||
} | ||
|
||
const [codeName, codeNumber] = projectionCode.split(':') | ||
|
||
const url = | ||
serviceDefinition.typ === 'OAF' | ||
? [ | ||
serviceDefinition.url, | ||
'collections', | ||
serviceDefinition.collection, | ||
`items?f=json&limit=100&bbox=${bbox}&bbox-crs=http://www.opengis.net/def/crs/${codeName}/0/${codeNumber}&crs=http://www.opengis.net/def/crs/${codeName}/0/${codeNumber}`, | ||
].join('/') | ||
: `${serviceDefinition.url}${[ | ||
`?service=${serviceDefinition.typ}`, | ||
`version=${serviceDefinition.version}`, | ||
`request=GetFeature`, | ||
`srsName=${projectionCode}`, | ||
`typeName=${serviceDefinition.featureType}`, | ||
`bbox=${bbox},${projectionCode}`, | ||
].join('&')}` | ||
|
||
return fetch(url) | ||
} | ||
|
||
export const getVectorFeaturesByFeatureRequest = ({ | ||
feature, | ||
fetchLayerId, | ||
projectionCode, | ||
}: { | ||
feature: Feature | ||
fetchLayerId: string | ||
projectionCode: string | ||
}) => { | ||
const bbox = feature.getGeometry()?.getExtent?.() | ||
|
||
if (typeof bbox === 'undefined') { | ||
throw new Error( | ||
'@polar/lib-get-features#getVectorFeaturesByFeatureRequest: Given feature had no extent.' | ||
) | ||
} | ||
|
||
return getVectorFeaturesByBboxRequest({ | ||
bbox, | ||
fetchLayerId, | ||
projectionCode, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.