From a200ec8cf8a48782d897111aa131833428891576 Mon Sep 17 00:00:00 2001 From: Vladimir Vershinin Date: Thu, 11 Feb 2021 14:13:22 +0300 Subject: [PATCH 1/6] WIP performance tuning --- tests/app.vue | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/app.vue b/tests/app.vue index 18351d2c..d9b25dfc 100644 --- a/tests/app.vue +++ b/tests/app.vue @@ -14,37 +14,42 @@ - - - + + From e1506629af11d527883fbcf3730bb491a828ea30 Mon Sep 17 00:00:00 2001 From: Vladimir Vershinin Date: Mon, 22 Mar 2021 17:23:55 +0300 Subject: [PATCH 2/6] Rollback to non-rounded coordinates #413 --- src/ol-ext/coord.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ol-ext/coord.js b/src/ol-ext/coord.js index 8d8681d9..e6e2951c 100644 --- a/src/ol-ext/coord.js +++ b/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 From 39f86315f238feec3506d10c7a86bcc2d22d3582 Mon Sep 17 00:00:00 2001 From: Vladimir Vershinin Date: Mon, 22 Mar 2021 18:15:30 +0300 Subject: [PATCH 3/6] Fix incorrect serialization of internal cluster features #414 --- src/ol-ext/format.js | 23 +++++++++++++++++++++-- src/ol-ext/geojson.js | 29 +++-------------------------- tests/app.vue | 13 +++++-------- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/ol-ext/format.js b/src/ol-ext/format.js index 15bf4e0d..1ccee3e1 100644 --- a/src/ol-ext/format.js +++ b/src/ol-ext/format.js @@ -3,7 +3,8 @@ import { GeoJSON as BaseGeoJSON, MVT } from 'ol/format' import { Circle, LineString } from 'ol/geom' import { isEmpty } from 'ol/obj' import { getLength } from 'ol/sphere' -import { clonePlainObject, isArray, isFunction, noop, omit } from '../utils' +import { clonePlainObject, isArray, isFunction, map, noop, omit } from '../utils' +import { isGeoJSONFeature } from './geojson' import { createCircularPolygon, isCircleGeom } from './geom' import { EPSG_4326, transformDistance, transformPoint } from './proj' @@ -107,7 +108,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 + }) } } @@ -177,6 +187,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) } diff --git a/src/ol-ext/geojson.js b/src/ol-ext/geojson.js index aa023f4d..6a8d17ec 100644 --- a/src/ol-ext/geojson.js +++ b/src/ol-ext/geojson.js @@ -1,6 +1,5 @@ -import { Feature } from 'ol' import GeometryType from 'ol/geom/GeometryType' -import { get, isArray, isPlainObject } from '../utils' +import { isArray, isPlainObject } from '../utils' import { COORD_PRECISION } from './coord' import { createGeoJsonFmt } from './format' import { EPSG_3857, EPSG_4326 } from './proj' @@ -34,22 +33,11 @@ export function writeGeoJsonFeature ( ) { if (!feature) return - const geoJsonFeature = getGeoJsonFmt().writeFeatureObject(feature, { + return getGeoJsonFmt().writeFeatureObject(feature, { featureProjection, dataProjection, decimals, }) - - if (Array.isArray(get(geoJsonFeature, 'properties.features'))) { - geoJsonFeature.properties.features = geoJsonFeature.properties.features.map(feature => { - if (feature instanceof Feature) { - return writeGeoJsonFeature(feature, featureProjection, dataProjection, decimals) - } - return feature - }) - } - - return geoJsonFeature } /** @@ -67,22 +55,11 @@ export function readGeoJsonFeature ( ) { if (!geoJsonFeature) return - const feature = getGeoJsonFmt().readFeature(geoJsonFeature, { + return getGeoJsonFmt().readFeature(geoJsonFeature, { featureProjection, dataProjection, decimals, }) - - if (Array.isArray(feature.get('features'))) { - feature.set('features', feature.get('features').map(feature => { - if (isPlainObject(feature)) { - return readGeoJsonFeature(feature, featureProjection, dataProjection, decimals) - } - return feature - })) - } - - return feature } /** diff --git a/tests/app.vue b/tests/app.vue index d9b25dfc..12ca3fa8 100644 --- a/tests/app.vue +++ b/tests/app.vue @@ -14,18 +14,18 @@ - + + + From 849660174dc007d495b16f25347b3261dd01d96f Mon Sep 17 00:00:00 2001 From: Vladimir Vershinin Date: Sat, 27 Mar 2021 14:56:27 +0300 Subject: [PATCH 4/6] Fix circular dependency --- src/ol-ext/format.js | 130 +++++++++++++++++++++++++++++++++++++++++- src/ol-ext/geojson.js | 128 ----------------------------------------- src/ol-ext/index.js | 1 - 3 files changed, 127 insertions(+), 132 deletions(-) delete mode 100644 src/ol-ext/geojson.js diff --git a/src/ol-ext/format.js b/src/ol-ext/format.js index 1ccee3e1..03039fc2 100644 --- a/src/ol-ext/format.js +++ b/src/ol-ext/format.js @@ -1,12 +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, map, noop, omit } from '../utils' -import { isGeoJSONFeature } from './geojson' +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] @@ -225,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) +} diff --git a/src/ol-ext/geojson.js b/src/ol-ext/geojson.js deleted file mode 100644 index 6a8d17ec..00000000 --- a/src/ol-ext/geojson.js +++ /dev/null @@ -1,128 +0,0 @@ -import GeometryType from 'ol/geom/GeometryType' -import { isArray, isPlainObject } from '../utils' -import { COORD_PRECISION } from './coord' -import { createGeoJsonFmt } from './format' -import { EPSG_3857, EPSG_4326 } from './proj' -import { createStyle, dumpStyle } from './style' - -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) -} diff --git a/src/ol-ext/index.js b/src/ol-ext/index.js index f2d6fec3..b90050bf 100644 --- a/src/ol-ext/index.js +++ b/src/ol-ext/index.js @@ -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' From 32857a2bdfaa3cbb6701742f7f1423f6518c1c4e Mon Sep 17 00:00:00 2001 From: Vladimir Vershinin Date: Sat, 27 Mar 2021 14:57:17 +0300 Subject: [PATCH 5/6] Update some of dev dependencies to fix test run --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1b6c55ca..c7ac3972 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", From d768e1823fabdd09268ad6c2c4ed706946b9c68a Mon Sep 17 00:00:00 2001 From: Vladimir Vershinin Date: Sat, 27 Mar 2021 14:58:02 +0300 Subject: [PATCH 6/6] Release v0.12.0-rc.22 Fix #413, #414 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c7ac3972..7488ed3a 100644 --- a/package.json +++ b/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 ", "scripts": {