Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ghettovoice committed Mar 27, 2021
2 parents 43459ea + d768e18 commit 1a2077d
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 164 deletions.
8 changes: 4 additions & 4 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "vuelayers",
"version": "0.12.0-rc.21",
"version": "0.12.0-rc.22",
"description": "Web map Vue components with the power of OpenLayers",
"author": "Vladimir Vershinin <ghettovoice@gmail.com>",
"scripts": {
Expand Down Expand Up @@ -73,11 +73,11 @@
"autoprefixer": "^9.8.6",
"babel-eslint": "^10.1.0",
"babel-plugin-istanbul": "^6.0.0",
"canvas": "^2.6.1",
"canvas": "^2.7.0",
"chai": "^4.2.0",
"chai-dom": "^1.8.2",
"chalk": "^4.1.0",
"chromedriver": "^87.0.0",
"chromedriver": "^89.0.0",
"coveralls": "^3.1.0",
"cssnano": "^4.1.10",
"docsify-cli": "^4.4.1",
Expand All @@ -100,7 +100,7 @@
"rollup": "^2.33.2",
"rollup-plugin-re": "^1.0.7",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-vue": "^5.1.9",
"rollup-plugin-vue": "^6.0.0",
"sass-loader": "^10.1.0",
"sinon": "^9.2.1",
"sinon-chai": "^3.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/ol-ext/coord.js
@@ -1,7 +1,7 @@
import GeometryType from 'ol/geom/GeometryType'
import { and, every, isArray, isEqual, isNumber, round } from '../utils'

export const COORD_PRECISION = 9
export const COORD_PRECISION = -1

export function roundExtent (extent, precision = COORD_PRECISION) {
if (!extent) return
Expand Down
149 changes: 146 additions & 3 deletions src/ol-ext/format.js
@@ -1,11 +1,14 @@
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, noop, omit } from '../utils'
import { clonePlainObject, isArray, isFunction, isPlainObject, map, noop, omit } from '../utils'
import { COORD_PRECISION } from './coord'
import { createCircularPolygon, isCircleGeom } from './geom'
import { EPSG_4326, transformDistance, transformPoint } from './proj'
import { EPSG_3857, EPSG_4326, transformDistance, transformPoint } from './proj'
import { createStyle, dumpStyle } from './style'

/**
* @param {Object} [options]
Expand Down Expand Up @@ -107,7 +110,16 @@ class GeoJSON extends BaseGeoJSON {
if (!isEmpty(properties)) {
object.properties = {
...object.properties || {},
...clonePlainObject(properties),
...clonePlainObject(omit(properties, 'features')),
}

if (isArray(properties.features)) {
object.properties.features = map(properties.features, feature => {
if (feature instanceof Feature) {
return this.writeFeatureObject(feature, options)
}
return feature
})
}
}

Expand Down Expand Up @@ -177,6 +189,15 @@ class GeoJSON extends BaseGeoJSON {
delete geoJSONFeature.properties[STYLE_SERIALIZE_PROP]
}

if (isArray(geoJSONFeature.properties.features)) {
geoJSONFeature.properties.features = map(geoJSONFeature.properties.features, feature => {
if (isGeoJSONFeature(feature)) {
return this.readFeatureFromObject(feature, options)
}
return feature
})
}

feature.setProperties(geoJSONFeature.properties, true)
}

Expand Down Expand Up @@ -206,3 +227,125 @@ class GeoJSON extends BaseGeoJSON {
return super.readGeometryFromObject(clonePlainObject(object), options)
}
}

let geoJsonFmt

export function getGeoJsonFmt () {
if (geoJsonFmt) {
return geoJsonFmt
}
return createGeoJsonFmt({
decimals: COORD_PRECISION,
styleReader: createStyle,
styleWriter: dumpStyle,
})
}

/**
* @param {Feature} feature
* @param {ProjectionLike|undefined} [featureProjection=EPSG:3857]
* @param {ProjectionLike|undefined} [dataProjection=EPSG:4326]
* @param {number} [decimals=COORD_PRECISION]
* @return {Object}
*/
export function writeGeoJsonFeature (
feature,
featureProjection = EPSG_3857,
dataProjection = EPSG_4326,
decimals = COORD_PRECISION,
) {
if (!feature) return

return getGeoJsonFmt().writeFeatureObject(feature, {
featureProjection,
dataProjection,
decimals,
})
}

/**
* @param {Object} geoJsonFeature
* @param {ProjectionLike|undefined} [featureProjection=EPSG:3857]
* @param {ProjectionLike|undefined} [dataProjection=EPSG:4326]
* @param {number} [decimals=COORD_PRECISION]
* @return {Feature}
*/
export function readGeoJsonFeature (
geoJsonFeature,
featureProjection = EPSG_3857,
dataProjection = EPSG_4326,
decimals = COORD_PRECISION,
) {
if (!geoJsonFeature) return

return getGeoJsonFmt().readFeature(geoJsonFeature, {
featureProjection,
dataProjection,
decimals,
})
}

/**
* @param {Geometry} geometry
* @param {ProjectionLike|undefined} [geometryProjection=EPSG:3857]
* @param {ProjectionLike|undefined} [dataProjection=EPSG:4326]
* @param {number} [decimals=COORD_PRECISION]
* @return {Object}
*/
export function writeGeoJsonGeometry (
geometry,
geometryProjection = EPSG_3857,
dataProjection = EPSG_4326,
decimals = COORD_PRECISION,
) {
if (!geometry) return

return getGeoJsonFmt().writeGeometryObject(geometry, {
featureProjection: geometryProjection,
dataProjection,
decimals,
})
}

/**
* @param {Object|Object} geoJsonGeometry
* @param {ProjectionLike|undefined} [geometryProjection=EPSG:3857]
* @param {ProjectionLike|undefined} [dataProjection=EPSG:4326]
* @param {number} [decimals=COORD_PRECISION]
* @return {Geometry}
*/
export function readGeoJsonGeometry (
geoJsonGeometry,
geometryProjection = EPSG_3857,
dataProjection = EPSG_4326,
decimals = COORD_PRECISION,
) {
if (!geoJsonGeometry) return

dataProjection = readProjection(geoJsonGeometry, dataProjection)

return getGeoJsonFmt().readGeometry(geoJsonGeometry, {
featureProjection: geometryProjection,
dataProjection,
decimals,
})
}

export function readProjection (geoJsonObj, defaultProjection) {
return getGeoJsonFmt().readProjection(geoJsonObj) || defaultProjection
}

/**
* @param {Object} feature
* @returns {boolean}
*/
export function isGeoJSONFeature (feature) {
return isPlainObject(feature) && feature.type === 'Feature' &&
isGeoJSONGeometry(feature.geometry)
}

export function isGeoJSONGeometry (geometry) {
return isPlainObject(geometry) &&
Object.values(GeometryType).includes(geometry.type) &&
isArray(geometry.coordinates)
}
151 changes: 0 additions & 151 deletions src/ol-ext/geojson.js

This file was deleted.

1 change: 0 additions & 1 deletion src/ol-ext/index.js
Expand Up @@ -3,7 +3,6 @@ export * from './coord'
export * from './extent'
export * from './feature'
export * from './format'
export * from './geojson'
export * from './geom'
export * from './interaction'
export * from './layer'
Expand Down

0 comments on commit 1a2077d

Please sign in to comment.