tchen-vuelayers
Version:
Web map Vue components with the power of OpenLayers
111 lines (93 loc) • 3.02 kB
JavaScript
/**
* VueLayers
* Web map Vue components with the power of OpenLayers
*
* @package vuelayers
* @author Vladimir Vershinin <ghettovoice@gmail.com>
* @version 0.11.1
* @license MIT
* @copyright (c) 2017-2019, Vladimir Vershinin <ghettovoice@gmail.com>
*/
import _classCallCheck from '@babel/runtime-corejs2/helpers/esm/classCallCheck';
import _createClass from '@babel/runtime-corejs2/helpers/esm/createClass';
import _possibleConstructorReturn from '@babel/runtime-corejs2/helpers/esm/possibleConstructorReturn';
import _getPrototypeOf from '@babel/runtime-corejs2/helpers/esm/getPrototypeOf';
import _get from '@babel/runtime-corejs2/helpers/esm/get';
import _inherits from '@babel/runtime-corejs2/helpers/esm/inherits';
import BaseGeoJSON from 'ol/format/GeoJSON';
import MVT from 'ol/format/MVT';
import TopoJSON from 'ol/format/TopoJSON';
import { isEmpty } from '../util/minilo';
import { EPSG_4326 } from './consts';
import { createCircularPolygon } from './geom';
import { transformPoint } from './proj';
import { isCircle } from './util';
/**
* @param {Object} [options]
* @return {GeoJSON}
*/
function createGeoJsonFmt(options) {
return new GeoJSON(options);
}
/**
* @param {Object} [options]
* @return {TopoJSON}
*/
function createTopoJsonFmt(options) {
return new TopoJSON(options);
}
/**
* @param [options]
* @return {MVT}
*/
function createMvtFmt(options) {
return new MVT(options);
}
var GeoJSON =
/*#__PURE__*/
function (_BaseGeoJSON) {
_inherits(GeoJSON, _BaseGeoJSON);
function GeoJSON() {
_classCallCheck(this, GeoJSON);
return _possibleConstructorReturn(this, _getPrototypeOf(GeoJSON).apply(this, arguments));
}
_createClass(GeoJSON, [{
key: "writeGeometryObject",
value: function writeGeometryObject(geometry, options) {
if (isCircle(geometry)) {
geometry = createCircularPolygon(transformPoint(geometry.getCenter(), options.featureProjection || this.defaultFeatureProjection, EPSG_4326), geometry.getRadius());
options.featureProjection = EPSG_4326;
}
return _get(_getPrototypeOf(GeoJSON.prototype), "writeGeometryObject", this).call(this, geometry, options);
}
}, {
key: "writeFeatureObject",
value: function writeFeatureObject(feature, options) {
var object =
/** @type {Object} */
{
'type': 'Feature'
};
var id = feature.getId();
if (id !== undefined) {
object.id = id;
}
var geometry = feature.getGeometry();
if (geometry) {
object.geometry = this.writeGeometryObject(geometry, options);
} else {
object.geometry = null;
}
var properties = feature.getProperties();
delete properties[feature.getGeometryName()];
if (!isEmpty(properties)) {
object.properties = properties;
} else {
object.properties = null;
}
return object;
}
}]);
return GeoJSON;
}(BaseGeoJSON);
export { createGeoJsonFmt, createTopoJsonFmt, createMvtFmt };