diff --git a/server/src/main/java/org/elasticsearch/common/geo/GeoFormatterFactory.java b/server/src/main/java/org/elasticsearch/common/geo/GeoFormatterFactory.java index fae7f3f804524..335c2bf6712fa 100644 --- a/server/src/main/java/org/elasticsearch/common/geo/GeoFormatterFactory.java +++ b/server/src/main/java/org/elasticsearch/common/geo/GeoFormatterFactory.java @@ -9,62 +9,71 @@ package org.elasticsearch.common.geo; import org.elasticsearch.geometry.Geometry; -import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileUtils; +import java.util.Collections; +import java.util.HashMap; import java.util.List; -import java.util.Locale; +import java.util.Map; import java.util.function.Function; /** - * Output formatters for geo fields. Adds support for vector tiles. + * Output formatters for geo fields support extensions such as vector tiles. + * + * This class is an extensible version of a static GeometryFormatterFactory */ -public class GeoFormatterFactory { +public class GeoFormatterFactory { - @FunctionalInterface - public interface VectorTileEngine { + /** + * Defines an extension point for geometry formatter + * @param + */ + public interface FormatterFactory { /** - * Returns a formatter for a specific tile. + * Format name */ - Function, List> getFormatter(int z, int x, int y, int extent); + String getName(); + + /** + * Generates a formatter builder that parses the formatter configuration and generates a formatter + */ + Function, List>> getFormatterBuilder(); } - private static final String MVT = "mvt"; + private final Map, List>>> factories; + + /** + * Creates an extensible geo formatter. The extension points can be added as a list of factories + */ + public GeoFormatterFactory(List> factories) { + Map, List>>> factoriesBuilder = new HashMap<>(); + for (FormatterFactory factory : factories) { + if(factoriesBuilder.put(factory.getName(), factory.getFormatterBuilder()) != null) { + throw new IllegalArgumentException("More then one formatter factory with the name [" + factory.getName() + + "] was configured"); + } + + } + this.factories = Collections.unmodifiableMap(factoriesBuilder); + } /** * Returns a formatter by name + * + * The format can contain an optional parameters in parentheses such as "mvt(1/2/3)". Parameterless formats are getting resolved + * using standard GeometryFormatterFactory and formats with parameters are getting resolved using factories specified during + * construction. */ - public static Function, List> getFormatter(String format, Function toGeometry, - VectorTileEngine mvt) { + public Function, List> getFormatter(String format, Function toGeometry) { final int start = format.indexOf('('); if (start == -1) { return GeometryFormatterFactory.getFormatter(format, toGeometry); } final String formatName = format.substring(0, start); - if (MVT.equals(formatName) == false) { + Function, List>> factory = factories.get(formatName); + if (factory == null) { throw new IllegalArgumentException("Invalid format: " + formatName); } final String param = format.substring(start + 1, format.length() - 1); - // we expect either z/x/y or z/x/y@extent - final String[] parts = param.split("@", 3); - if (parts.length > 2) { - throw new IllegalArgumentException( - "Invalid mvt formatter parameter [" + param + "]. Must have the form \"zoom/x/y\" or \"zoom/x/y@extent\"." - ); - } - final int extent = parts.length == 2 ? Integer.parseInt(parts[1]) : 4096; - final String[] tileBits = parts[0].split("/", 4); - if (tileBits.length != 3) { - throw new IllegalArgumentException( - "Invalid tile string [" + parts[0] + "]. Must be three integers in a form \"zoom/x/y\"." - ); - } - final int z = GeoTileUtils.checkPrecisionRange(Integer.parseInt(tileBits[0])); - final int tiles = 1 << z; - final int x = Integer.parseInt(tileBits[1]); - final int y = Integer.parseInt(tileBits[2]); - if (x < 0 || y < 0 || x >= tiles || y >= tiles) { - throw new IllegalArgumentException(String.format(Locale.ROOT, "Zoom/X/Y combination is not valid: %d/%d/%d", z, x, y)); - } - return mvt.getFormatter(z, x, y, extent); + return factory.apply(param); } } diff --git a/server/src/main/java/org/elasticsearch/common/geo/SimpleFeatureFactory.java b/server/src/main/java/org/elasticsearch/common/geo/SimpleFeatureFactory.java index a72ee2ec12d5c..9f61d8b26e2c9 100644 --- a/server/src/main/java/org/elasticsearch/common/geo/SimpleFeatureFactory.java +++ b/server/src/main/java/org/elasticsearch/common/geo/SimpleFeatureFactory.java @@ -9,7 +9,6 @@ package org.elasticsearch.common.geo; import org.apache.lucene.util.BitUtil; -import org.elasticsearch.common.geo.SphericalMercatorUtils; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.geometry.Rectangle; import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileUtils; diff --git a/server/src/main/java/org/elasticsearch/common/geo/SimpleVectorTileFormatter.java b/server/src/main/java/org/elasticsearch/common/geo/SimpleVectorTileFormatter.java new file mode 100644 index 0000000000000..8e7a28f1c4624 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/common/geo/SimpleVectorTileFormatter.java @@ -0,0 +1,66 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.common.geo; + +import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileUtils; + +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.function.Function; + +/** + * A facade for SimpleFeatureFactory that converts it into FormatterFactory for use in GeoPointFieldMapper + */ +public class SimpleVectorTileFormatter implements GeoFormatterFactory.FormatterFactory { + + public static final String MVT = "mvt"; + + @Override + public String getName() { + return MVT; + } + + @Override + public Function, List>> getFormatterBuilder() { + return params -> { + int[] parsed = parse(params); + final SimpleFeatureFactory featureFactory = new SimpleFeatureFactory(parsed[0], parsed[1], parsed[2], parsed[3]); + return points -> Collections.singletonList(featureFactory.points(points)); + }; + } + + /** + * Parses string in the format we expect either z/x/y or z/x/y@extent to an array of integer parameters + */ + public static int[] parse(String param) { + // we expect either z/x/y or z/x/y@extent + final String[] parts = param.split("@", 3); + if (parts.length > 2) { + throw new IllegalArgumentException( + "Invalid mvt formatter parameter [" + param + "]. Must have the form \"zoom/x/y\" or \"zoom/x/y@extent\"." + ); + } + final int extent = parts.length == 2 ? Integer.parseInt(parts[1]) : 4096; + final String[] tileBits = parts[0].split("/", 4); + if (tileBits.length != 3) { + throw new IllegalArgumentException( + "Invalid tile string [" + parts[0] + "]. Must be three integers in a form \"zoom/x/y\"." + ); + } + final int z = GeoTileUtils.checkPrecisionRange(Integer.parseInt(tileBits[0])); + final int tiles = 1 << z; + final int x = Integer.parseInt(tileBits[1]); + final int y = Integer.parseInt(tileBits[2]); + if (x < 0 || y < 0 || x >= tiles || y >= tiles) { + throw new IllegalArgumentException(String.format(Locale.ROOT, "Zoom/X/Y combination is not valid: %d/%d/%d", z, x, y)); + } + return new int[]{z, x, y, extent}; + } +} diff --git a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java index 943c3f860edd5..c93bce31496ef 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java @@ -25,7 +25,7 @@ import org.elasticsearch.common.geo.GeoUtils; import org.elasticsearch.common.geo.GeometryFormatterFactory; import org.elasticsearch.common.geo.ShapeRelation; -import org.elasticsearch.common.geo.SimpleFeatureFactory; +import org.elasticsearch.common.geo.SimpleVectorTileFormatter; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.support.MapXContentParser; @@ -225,6 +225,10 @@ protected String contentType() { public static class GeoPointFieldType extends AbstractGeometryFieldType implements GeoShapeQueryable { + private static final GeoFormatterFactory GEO_FORMATTER_FACTORY = new GeoFormatterFactory<>( + Collections.singletonList(new SimpleVectorTileFormatter()) + ); + private final FieldValues scriptValues; private GeoPointFieldType(String name, boolean indexed, boolean stored, boolean hasDocValues, @@ -245,11 +249,7 @@ public String typeName() { @Override protected Function, List> getFormatter(String format) { - return GeoFormatterFactory.getFormatter(format, p -> new Point(p.getLon(), p.getLat()), - (z, x, y, extent) -> { - final SimpleFeatureFactory featureFactory = new SimpleFeatureFactory(z, x, y, extent); - return points -> org.elasticsearch.core.List.of(featureFactory.points(points)); - }); + return GEO_FORMATTER_FACTORY.getFormatter(format, p -> new Point(p.getLon(), p.getLat())); } @Override diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/VectorTileExtension.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/GeometryFormatterExtension.java similarity index 56% rename from x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/VectorTileExtension.java rename to x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/GeometryFormatterExtension.java index 8fb6331f6cbe4..38c6bd309ac2d 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/VectorTileExtension.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/GeometryFormatterExtension.java @@ -10,11 +10,14 @@ import org.elasticsearch.common.geo.GeoFormatterFactory; import org.elasticsearch.geometry.Geometry; +import java.util.List; -public interface VectorTileExtension { +/** + * Extension point for geometry formatters + */ +public interface GeometryFormatterExtension { /** - * Get the vector tile engine. This is called when user ask for the MVT format on the field API. - * We are only expecting one instance of a vector tile engine coming from the vector tile module. + * Get a list of geometry formatters. */ - GeoFormatterFactory.VectorTileEngine getVectorTileEngine(); + List> getGeometryFormatterFactories(); } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java index 2cc5f68c9b511..59127d66506cc 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialPlugin.java @@ -10,8 +10,10 @@ import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.geo.GeoFormatterFactory; import org.elasticsearch.common.xcontent.ContextParser; import org.elasticsearch.geo.GeoPlugin; +import org.elasticsearch.geometry.Geometry; import org.elasticsearch.index.mapper.Mapper; import org.elasticsearch.ingest.Processor; import org.elasticsearch.license.LicenseUtils; @@ -54,6 +56,7 @@ import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType; import java.util.Collection; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -77,7 +80,7 @@ protected XPackLicenseState getLicenseState() { } // register the vector tile factory from a different module - private final SetOnce vectorTileExtension = new SetOnce<>(); + private final SetOnce> geoFormatterFactory = new SetOnce<>(); @Override public List> getActions() { @@ -90,7 +93,7 @@ public Map getMappers() { mappers.put(ShapeFieldMapper.CONTENT_TYPE, ShapeFieldMapper.PARSER); mappers.put(PointFieldMapper.CONTENT_TYPE, PointFieldMapper.PARSER); mappers.put(GeoShapeWithDocValuesFieldMapper.CONTENT_TYPE, - new GeoShapeWithDocValuesFieldMapper.TypeParser(vectorTileExtension.get())); + new GeoShapeWithDocValuesFieldMapper.TypeParser(geoFormatterFactory.get())); return Collections.unmodifiableMap(mappers); } @@ -215,6 +218,9 @@ private ContextParser checkLicense(ContextParser realP @Override public void loadExtensions(ExtensionLoader loader) { // we only expect one vector tile extension that comes from the vector tile module. - loader.loadExtensions(VectorTileExtension.class).forEach(vectorTileExtension::set); + List> formatterFactories = new ArrayList<>(); + loader.loadExtensions(GeometryFormatterExtension.class).stream().map(GeometryFormatterExtension::getGeometryFormatterFactories) + .forEach(formatterFactories::addAll); + geoFormatterFactory.set(new GeoFormatterFactory<>(formatterFactories)); } } diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java index a63c90adb1109..d40df689feccd 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java @@ -18,14 +18,15 @@ import org.elasticsearch.common.geo.GeoFormatterFactory; import org.elasticsearch.common.geo.GeoShapeUtils; import org.elasticsearch.common.geo.GeometryParser; -import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.geo.Orientation; +import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.logging.DeprecationCategory; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.geometry.Geometry; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.mapper.AbstractShapeGeometryFieldMapper; import org.elasticsearch.index.mapper.ContentPath; +import org.elasticsearch.index.mapper.DocumentParserContext; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.GeoShapeFieldMapper; import org.elasticsearch.index.mapper.GeoShapeIndexer; @@ -34,13 +35,11 @@ import org.elasticsearch.index.mapper.LegacyGeoShapeFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.Mapper; -import org.elasticsearch.index.mapper.DocumentParserContext; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MappingParserContext; import org.elasticsearch.index.query.QueryShardException; import org.elasticsearch.index.query.SearchExecutionContext; import org.elasticsearch.search.lookup.SearchLookup; -import org.elasticsearch.xpack.spatial.VectorTileExtension; import org.elasticsearch.xpack.spatial.index.fielddata.plain.AbstractLatLonShapeIndexFieldData; import org.elasticsearch.xpack.spatial.search.aggregations.support.GeoShapeValuesSourceType; @@ -95,13 +94,13 @@ public static class Builder extends FieldMapper.Builder { final Parameter> meta = Parameter.metaParam(); private final Version version; - private final VectorTileExtension vectorTileExtension; + private final GeoFormatterFactory geoFormatterFactory; public Builder(String name, Version version, boolean ignoreMalformedByDefault, boolean coerceByDefault, - VectorTileExtension vectorTileExtension) { + GeoFormatterFactory geoFormatterFactory) { super(name); this.version = version; - this.vectorTileExtension = vectorTileExtension; + this.geoFormatterFactory = geoFormatterFactory; this.ignoreMalformed = ignoreMalformedParam(m -> builder(m).ignoreMalformed.get(), ignoreMalformedByDefault); this.coerce = coerceParam(m -> builder(m).coerce.get(), coerceByDefault); this.hasDocValues @@ -133,7 +132,7 @@ public GeoShapeWithDocValuesFieldMapper build(ContentPath contentPath) { hasDocValues.get(), orientation.get().value(), parser, - vectorTileExtension, + geoFormatterFactory, meta.get()); return new GeoShapeWithDocValuesFieldMapper(name, ft, multiFieldsBuilder.build(this, contentPath), copyTo.build(), @@ -144,13 +143,12 @@ public GeoShapeWithDocValuesFieldMapper build(ContentPath contentPath) { public static final class GeoShapeWithDocValuesFieldType extends AbstractShapeGeometryFieldType implements GeoShapeQueryable { - private final VectorTileExtension vectorTileExtension; - + private final GeoFormatterFactory geoFormatterFactory; public GeoShapeWithDocValuesFieldType(String name, boolean indexed, boolean hasDocValues, Orientation orientation, GeoShapeParser parser, - VectorTileExtension vectorTileExtension, Map meta) { + GeoFormatterFactory geoFormatterFactory, Map meta) { super(name, indexed, false, hasDocValues, parser, orientation, meta); - this.vectorTileExtension = vectorTileExtension; + this.geoFormatterFactory = geoFormatterFactory; } public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, Supplier searchLookup) { @@ -184,22 +182,16 @@ public Query geoShapeQuery(Geometry shape, String fieldName, ShapeRelation relat @Override protected Function, List> getFormatter(String format) { - return GeoFormatterFactory.getFormatter(format, Function.identity(), - (z, x, y, extent) -> { - if (vectorTileExtension == null) { - throw new IllegalArgumentException("vector tile format is not supported"); - } - return vectorTileExtension.getVectorTileEngine().getFormatter(z, x, y, extent); - }); + return geoFormatterFactory.getFormatter(format, Function.identity()); } } public static class TypeParser implements Mapper.TypeParser { - private final VectorTileExtension vectorTileExtension; + private final GeoFormatterFactory geoFormatterFactory; - public TypeParser(VectorTileExtension vectorTileExtension) { - this.vectorTileExtension = vectorTileExtension; + public TypeParser(GeoFormatterFactory geoFormatterFactory) { + this.geoFormatterFactory = geoFormatterFactory; } @Override @@ -221,7 +213,7 @@ public Mapper.Builder parse(String name, Map node, MappingParser parserContext.indexVersionCreated(), ignoreMalformedByDefault, coerceByDefault, - vectorTileExtension); + geoFormatterFactory); } builder.parse(name, parserContext, node); return builder; @@ -276,7 +268,7 @@ public FieldMapper.Builder getMergeBuilder() { builder.version, builder.ignoreMalformed.getDefaultValue().value(), builder.coerce.getDefaultValue().value(), - builder.vectorTileExtension + builder.geoFormatterFactory ).init(this); } diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldTypeTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldTypeTests.java index 986e114ed6783..b109f44b01d20 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldTypeTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldTypeTests.java @@ -8,6 +8,7 @@ package org.elasticsearch.xpack.spatial.index.mapper; import org.elasticsearch.Version; +import org.elasticsearch.common.geo.GeoFormatterFactory; import org.elasticsearch.geo.GeometryTestUtils; import org.elasticsearch.geometry.Geometry; import org.elasticsearch.geometry.utils.WellKnownText; @@ -15,7 +16,7 @@ import org.elasticsearch.index.mapper.FieldTypeTestCase; import org.elasticsearch.index.mapper.GeoShapeFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; -import org.elasticsearch.xpack.vectortile.SpatialVectorTileExtension; +import org.elasticsearch.xpack.vectortile.SpatialGeometryFormatterExtension; import org.elasticsearch.xpack.vectortile.feature.FeatureFactory; import org.hamcrest.Matchers; @@ -91,8 +92,10 @@ public void testFetchVectorTile() throws IOException { } private void fetchVectorTile(Geometry geometry) throws IOException { + final GeoFormatterFactory geoFormatterFactory = new GeoFormatterFactory<>( + new SpatialGeometryFormatterExtension().getGeometryFormatterFactories()); final MappedFieldType mapper - = new GeoShapeWithDocValuesFieldMapper.Builder("field", Version.CURRENT, false, false, new SpatialVectorTileExtension()) + = new GeoShapeWithDocValuesFieldMapper.Builder("field", Version.CURRENT, false, false, geoFormatterFactory) .build(new ContentPath()).fieldType(); final int z = randomIntBetween(1, 10); int x = randomIntBetween(0, (1 << z) - 1); diff --git a/x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/SpatialGeometryFormatterExtension.java b/x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/SpatialGeometryFormatterExtension.java new file mode 100644 index 0000000000000..cf9cb1c09438c --- /dev/null +++ b/x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/SpatialGeometryFormatterExtension.java @@ -0,0 +1,50 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +package org.elasticsearch.xpack.vectortile; + +import org.elasticsearch.common.geo.GeoFormatterFactory; +import org.elasticsearch.common.geo.SimpleVectorTileFormatter; +import org.elasticsearch.geometry.Geometry; +import org.elasticsearch.geometry.GeometryCollection; +import org.elasticsearch.xpack.spatial.GeometryFormatterExtension; +import org.elasticsearch.xpack.vectortile.feature.FeatureFactory; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.function.Function; + +/** + * Unique implementation of VectorTileExtension so we can transform geometries + * into its vector tile representation from the spatial module. + */ +public class SpatialGeometryFormatterExtension implements GeometryFormatterExtension { + + @Override + public List> getGeometryFormatterFactories() { + return Collections.singletonList(new GeoFormatterFactory.FormatterFactory() { + @Override + public String getName() { + return SimpleVectorTileFormatter.MVT; + } + + @Override + public Function, List>> getFormatterBuilder() { + + return (params) -> { + int[] parsed = SimpleVectorTileFormatter.parse(params); + final FeatureFactory featureFactory = new FeatureFactory(parsed[0], parsed[1], parsed[2], parsed[3]); + return geometries -> { + final Geometry geometry = (geometries.size() == 1) ? geometries.get(0) : new GeometryCollection<>(geometries); + return new ArrayList<>(featureFactory.getFeatures(geometry)); + }; + }; + } + }); + } +} diff --git a/x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/SpatialVectorTileExtension.java b/x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/SpatialVectorTileExtension.java deleted file mode 100644 index 261199c24c9ef..0000000000000 --- a/x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/SpatialVectorTileExtension.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -package org.elasticsearch.xpack.vectortile; - -import org.elasticsearch.common.geo.GeoFormatterFactory; -import org.elasticsearch.geometry.Geometry; -import org.elasticsearch.geometry.GeometryCollection; -import org.elasticsearch.xpack.spatial.VectorTileExtension; -import org.elasticsearch.xpack.vectortile.feature.FeatureFactory; - -import java.util.ArrayList; - -/** - * Unique implementation of VectorTileExtension so we can transform geometries - * into its vector tile representation from the spatial module. - */ -public class SpatialVectorTileExtension implements VectorTileExtension { - - @Override - public GeoFormatterFactory.VectorTileEngine getVectorTileEngine() { - return (z, x, y, extent) -> { - final FeatureFactory featureFactory = new FeatureFactory(z, x, y, extent); - return geometries -> { - final Geometry geometry = (geometries.size() == 1) ? geometries.get(0) : new GeometryCollection<>(geometries); - return new ArrayList<>(featureFactory.getFeatures(geometry)); - }; - }; - } -} diff --git a/x-pack/plugin/vector-tile/src/main/resources/META-INF/services/org.elasticsearch.xpack.spatial.VectorTileExtension b/x-pack/plugin/vector-tile/src/main/resources/META-INF/services/org.elasticsearch.xpack.spatial.GeometryFormatterExtension similarity index 78% rename from x-pack/plugin/vector-tile/src/main/resources/META-INF/services/org.elasticsearch.xpack.spatial.VectorTileExtension rename to x-pack/plugin/vector-tile/src/main/resources/META-INF/services/org.elasticsearch.xpack.spatial.GeometryFormatterExtension index 5f2a083ea5410..f4ef92b29d66a 100644 --- a/x-pack/plugin/vector-tile/src/main/resources/META-INF/services/org.elasticsearch.xpack.spatial.VectorTileExtension +++ b/x-pack/plugin/vector-tile/src/main/resources/META-INF/services/org.elasticsearch.xpack.spatial.GeometryFormatterExtension @@ -5,4 +5,4 @@ # 2.0. # -org.elasticsearch.xpack.vectortile.SpatialVectorTileExtension +org.elasticsearch.xpack.vectortile.SpatialGeometryFormatterExtension