Skip to content

Commit

Permalink
Polyfill ol enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ghettovoice committed Jul 31, 2022
1 parent c3d1ad5 commit 74df588
Show file tree
Hide file tree
Showing 24 changed files with 100 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/templateLanguages.xml

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"chai": "^4.2.0",
"chai-dom": "^1.8.2",
"chalk": "^4.1.0",
"chromedriver": "^100.0.0",
"chromedriver": "^103.0.0",
"coveralls": "^3.1.0",
"cssnano": "^4.1.10",
"docsify-cli": "^4.4.1",
Expand All @@ -90,7 +90,6 @@
"fs-extra": "^9.0.1",
"gh-pages": "^3.1.0",
"lodash": "^4.17.20",
"sass": "^1.43.4",
"nyc": "^15.1.0",
"postcss": "^7.0.35",
"postcss-import": "^12.0.1",
Expand All @@ -101,6 +100,7 @@
"rollup-plugin-re": "^1.0.7",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-vue": "^5.1.9",
"sass": "^1.43.4",
"sass-loader": "^10.1.0",
"sinon": "^9.2.1",
"sinon-chai": "^3.5.0",
Expand Down
3 changes: 1 addition & 2 deletions src/components/draw-interaction/interaction.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<script>
import { Collection } from 'ol'
import { noModifierKeys, shiftKeyOnly } from 'ol/events/condition'
import GeometryType from 'ol/geom/GeometryType'
import { Draw as DrawInteraction } from 'ol/interaction'
import { Vector as VectorSource } from 'ol/source'
import { merge as mergeObs, of as obsOf } from 'rxjs'
import { delay, first, map as mapObs, mapTo, mergeMap, tap } from 'rxjs/operators'
import { FRAME_TIME, interaction, makeChangeOrRecreateWatchers, styleContainer } from '../../mixins'
import { COORD_PRECISION, initializeFeature, roundLineCoords, writeGeoJsonFeature } from '../../ol-ext'
import { COORD_PRECISION, initializeFeature, roundLineCoords, writeGeoJsonFeature, GeometryType } from '../../ol-ext'
import { fromOlEvent as obsFromOlEvent, fromVueEvent as obsFromVueEvent } from '../../rx-ext'
import { assert, camelCase, instanceOf, isFunction, mergeDescriptors, upperFirst } from '../../utils'
Expand Down
3 changes: 1 addition & 2 deletions src/components/feature/circle-geom.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<script>
import { Circle } from 'ol/geom'
import GeometryType from 'ol/geom/GeometryType'
import { get as getProj } from 'ol/proj'
import { simpleGeometry } from '../../mixins'
import { isPointCoords, roundPointCoords, transformDistance } from '../../ol-ext'
import { isPointCoords, roundPointCoords, transformDistance, GeometryType } from '../../ol-ext'
import { assert, coalesce, constant, isEqual, isNumber, round } from '../../utils'
export default {
Expand Down
3 changes: 1 addition & 2 deletions src/components/feature/line-string-geom.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import { LineString } from 'ol/geom'
import GeometryType from 'ol/geom/GeometryType'
import { simpleGeometry } from '../../mixins'
import { isLineCoords } from '../../ol-ext'
import { isLineCoords, GeometryType } from '../../ol-ext'
import { assert, constant } from '../../utils'
export default {
Expand Down
3 changes: 1 addition & 2 deletions src/components/feature/multi-line-string-geom.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import { MultiLineString } from 'ol/geom'
import GeometryType from 'ol/geom/GeometryType'
import { simpleGeometry } from '../../mixins'
import { isMultiLineCoords } from '../../ol-ext'
import { isMultiLineCoords, GeometryType } from '../../ol-ext'
import { assert, constant } from '../../utils'
export default {
Expand Down
3 changes: 1 addition & 2 deletions src/components/feature/multi-point-geom.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import { MultiPoint } from 'ol/geom'
import GeometryType from 'ol/geom/GeometryType'
import { simpleGeometry } from '../../mixins'
import { isMultiPointCoords } from '../../ol-ext'
import { isMultiPointCoords, GeometryType } from '../../ol-ext'
import { assert, constant } from '../../utils'
export default {
Expand Down
3 changes: 1 addition & 2 deletions src/components/feature/multi-polygon-geom.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import { MultiPolygon } from 'ol/geom'
import GeometryType from 'ol/geom/GeometryType'
import { simpleGeometry } from '../../mixins'
import { isMultiPolygonCoords } from '../../ol-ext'
import { isMultiPolygonCoords, GeometryType } from '../../ol-ext'
import { assert, constant } from '../../utils'
export default {
Expand Down
3 changes: 1 addition & 2 deletions src/components/feature/point-geom.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import { Point } from 'ol/geom'
import GeometryType from 'ol/geom/GeometryType'
import { simpleGeometry } from '../../mixins'
import { isPointCoords } from '../../ol-ext'
import { isPointCoords, GeometryType } from '../../ol-ext'
import { assert, constant } from '../../utils'
export default {
Expand Down
3 changes: 1 addition & 2 deletions src/components/feature/polygon-geom.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import { Polygon } from 'ol/geom'
import GeometryType from 'ol/geom/GeometryType'
import { simpleGeometry } from '../../mixins'
import { isPolygonCoords } from '../../ol-ext'
import { isPolygonCoords, GeometryType } from '../../ol-ext'
import { assert, constant } from '../../utils'
export default {
Expand Down
10 changes: 8 additions & 2 deletions src/components/overlay/overlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@

<script>
import { Overlay } from 'ol'
import OverlayPositioning from 'ol/OverlayPositioning'
import { makeChangeOrRecreateWatchers, olCmp, projTransforms, waitForMap } from '../../mixins'
import { EPSG_3857, getOverlayId, initializeOverlay, roundPointCoords, setOverlayId } from '../../ol-ext'
import {
EPSG_3857,
getOverlayId,
initializeOverlay,
roundPointCoords,
setOverlayId,
OverlayPositioning,
} from '../../ol-ext'
import { fromOlChangeEvent as obsFromOlChangeEvent } from '../../rx-ext'
import {
addPrefix,
Expand Down
9 changes: 7 additions & 2 deletions src/components/wmts-source/source.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<script>
import { getHeight as getExtentHeight, getWidth as getExtentWidth } from 'ol/extent'
import ExtentCorner from 'ol/extent/Corner'
import { toSize } from 'ol/size'
import { WMTS as WMTSSource } from 'ol/source'
import { DEFAULT_MAX_ZOOM, DEFAULT_TILE_SIZE } from 'ol/tilegrid/common'
import WMTSTileGrid from 'ol/tilegrid/WMTS'
import { makeChangeOrRecreateWatchers, tileImageSource } from '../../mixins'
import { extentFromProjection, getCorner as getExtentCorner, roundExtent, roundPointCoords } from '../../ol-ext'
import {
extentFromProjection,
getCorner as getExtentCorner,
roundExtent,
roundPointCoords,
ExtentCorner,
} from '../../ol-ext'
import { coalesce, isArray, isFunction, isNumber, isString, noop, or, range } from '../../utils'
export default {
Expand Down
3 changes: 1 addition & 2 deletions src/mixins/simple-geometry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { boundingExtent as baseBoundingExtent } from 'ol/extent'
import GeometryLayout from 'ol/geom/GeometryLayout'
import GeometryType from 'ol/geom/GeometryType'
import { findPointOnSurface, isEqualCoord, roundCoords, roundPointCoords, transforms } from '../ol-ext'
import { findPointOnSurface, isEqualCoord, roundCoords, roundPointCoords, transforms, GeometryType } from '../ol-ext'
import { assert, clonePlainObject, coalesce, isArray, isEmpty, isEqual, negate } from '../utils'
import geometry from './geometry'
import { makeChangeOrRecreateWatchers } from './ol-cmp'
Expand Down
3 changes: 1 addition & 2 deletions src/mixins/source.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { get as getProj } from 'ol/proj'
import SourceState from 'ol/source/State'
import { EPSG_3857, getSourceId, initializeSource, setSourceId } from '../ol-ext'
import { EPSG_3857, getSourceId, initializeSource, setSourceId, SourceState } from '../ol-ext'
import { assert, coalesce, isArray, isEqual, isFunction, isString, mergeDescriptors, or } from '../utils'
import olCmp, { makeChangeOrRecreateWatchers } from './ol-cmp'
import projTransforms from './proj-transforms'
Expand Down
3 changes: 1 addition & 2 deletions src/mixins/wms-source.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import WMSServerType from 'ol/source/WMSServerType'
import { cleanSourceParams } from '../ol-ext'
import { cleanSourceParams, WMSServerType } from '../ol-ext'
import {
clonePlainObject,
coalesce,
Expand Down
2 changes: 1 addition & 1 deletion src/ol-ext/coord.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import GeometryType from 'ol/geom/GeometryType'
import { GeometryType } from './enums'
import { and, every, isArray, isEqual, isNumber, round } from '../utils'

export const COORD_PRECISION = 6
Expand Down
60 changes: 60 additions & 0 deletions src/ol-ext/enums.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
export const GeometryType = {
POINT: 'Point',
LINE_STRING: 'LineString',
LINEAR_RING: 'LinearRing',
POLYGON: 'Polygon',
MULTI_POINT: 'MultiPoint',
MULTI_LINE_STRING: 'MultiLineString',
MULTI_POLYGON: 'MultiPolygon',
GEOMETRY_COLLECTION: 'GeometryCollection',
CIRCLE: 'Circle',
}

export const ExtentCorner = {
BOTTOM_LEFT: 'bottom-left',
BOTTOM_RIGHT: 'bottom-right',
TOP_LEFT: 'top-left',
TOP_RIGHT: 'top-right',
}

export const OverlayPositioning = {
BOTTOM_LEFT: 'bottom-left',
BOTTOM_CENTER: 'bottom-center',
BOTTOM_RIGHT: 'bottom-right',
CENTER_LEFT: 'center-left',
CENTER_CENTER: 'center-center',
CENTER_RIGHT: 'center-right',
TOP_LEFT: 'top-left',
TOP_CENTER: 'top-center',
TOP_RIGHT: 'top-right',
}

export const SourceState = {
UNDEFINED: 'undefined',
LOADING: 'loading',
READY: 'ready',
ERROR: 'error',
}

export const WMSServerType = {
/**
* HiDPI support for [Carmenta Server](https://www.carmenta.com/en/products/carmenta-server)
* @api
*/
CARMENTA_SERVER: 'carmentaserver',
/**
* HiDPI support for [GeoServer](https://geoserver.org/)
* @api
*/
GEOSERVER: 'geoserver',
/**
* HiDPI support for [MapServer](https://mapserver.org/)
* @api
*/
MAPSERVER: 'mapserver',
/**
* HiDPI support for [QGIS](https://qgis.org/)
* @api
*/
QGIS: 'qgis',
}
10 changes: 5 additions & 5 deletions src/ol-ext/extent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// copy-paste from ol/extent
import { getBottomLeft, getBottomRight, getTopLeft, getTopRight } from 'ol/extent'
import Corner from 'ol/extent/Corner'
import { ExtentCorner } from './enums'
import { assert } from '../utils'

export function createOrUpdate (minX, minY, maxX, maxY, extent) {
Expand All @@ -16,13 +16,13 @@ export function createOrUpdate (minX, minY, maxX, maxY, extent) {

export function getCorner (extent, corner) {
let coordinate
if (corner === Corner.BOTTOM_LEFT) {
if (corner === ExtentCorner.BOTTOM_LEFT) {
coordinate = getBottomLeft(extent)
} else if (corner === Corner.BOTTOM_RIGHT) {
} else if (corner === ExtentCorner.BOTTOM_RIGHT) {
coordinate = getBottomRight(extent)
} else if (corner === Corner.TOP_LEFT) {
} else if (corner === ExtentCorner.TOP_LEFT) {
coordinate = getTopLeft(extent)
} else if (corner === Corner.TOP_RIGHT) {
} else if (corner === ExtentCorner.TOP_RIGHT) {
coordinate = getTopRight(extent)
} else {
assert(false, 'Invalid extent corner')
Expand Down
2 changes: 1 addition & 1 deletion src/ol-ext/format.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Feature } from 'ol'
import { GeoJSON as BaseGeoJSON, MVT } from 'ol/format'
import { Circle, LineString } from 'ol/geom'
import GeometryType from 'ol/geom/GeometryType'
import { isEmpty } from 'ol/obj'
import { getLength } from 'ol/sphere'
import { clonePlainObject, isArray, isFunction, isPlainObject, map, noop, omit } from '../utils'
import { COORD_PRECISION } from './coord'
import { GeometryType } from './enums'
import { createCircularPolygon, isCircleGeom } from './geom'
import { EPSG_3857, EPSG_4326, transformDistance, transformPoint } from './proj'
import { createStyle, dumpStyle } from './style'
Expand Down
2 changes: 1 addition & 1 deletion src/ol-ext/geom.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
Point,
Polygon,
} from 'ol/geom'
import GeometryType from 'ol/geom/GeometryType'
import { circular as circularPolygon } from 'ol/geom/Polygon'
import { v4 as uuid } from 'uuid'
import { isPlainObject } from '../utils'
import { COORD_PRECISION, roundCoords } from './coord'
import { GeometryType } from './enums'

/**
* @param {number|number[]} lonOrCoordinates
Expand Down
1 change: 1 addition & 0 deletions src/ol-ext/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './control'
export * from './coord'
export * from './enums'
export * from './extent'
export * from './feature'
export * from './format'
Expand Down
2 changes: 1 addition & 1 deletion src/ol-ext/proj.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import GeometryType from 'ol/geom/GeometryType'
import { fromLonLat, toLonLat, transform as baseTransform, transformExtent as baseTransformExtent } from 'ol/proj'
import { GeometryType } from './enums'
import { calcDistance, COORD_PRECISION, roundCoords, roundExtent } from './coord'

export const EPSG_4326 = 'EPSG:4326'
Expand Down
2 changes: 1 addition & 1 deletion src/ol-ext/style.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Geometry } from 'ol/geom'
import GeometryType from 'ol/geom/GeometryType'
import { Circle, Fill, Icon, Image as ImageStyle, RegularShape, Stroke, Style, Text } from 'ol/style'
import parseColor from 'parse-color'
import { v4 as uuid } from 'uuid'
import { GeometryType } from './enums'
import { addPrefix, filter, identity, isArray, isFunction, isNumeric, reduce } from '../utils'

function isStyle (style) {
Expand Down

0 comments on commit 74df588

Please sign in to comment.