@@ -52,6 +52,14 @@ export const VectorElementDragResult = {
5252 } ,
5353} ;
5454
55+ let geojsonWriter : com . carto . geometry . GeoJSONGeometryWriter ;
56+ function getGeojsonWriter ( ) {
57+ if ( ! geojsonWriter ) {
58+ geojsonWriter = new com . carto . geometry . GeoJSONGeometryWriter ( ) ;
59+ }
60+ return geojsonWriter ;
61+ }
62+
5563export abstract class BaseVectorTileLayer < T extends com . carto . layers . VectorTileLayer , U extends VectorTileLayerOptions > extends TileLayer < T , U > {
5664 projection ?: Projection ;
5765 listener ?: IVectorTileEventListener ;
@@ -94,20 +102,31 @@ export abstract class BaseVectorTileLayer<T extends com.carto.layers.VectorTileL
94102 const geometry = feature . getGeometry ( ) ;
95103 let position = info . getClickPos ( ) ;
96104 let featurePos = geometry . getCenterPos ( ) ;
97-
105+ let projection : com . carto . projections . Projection ;
106+ const dataSourceProjection = this . getNative ( ) . getDataSource ( ) . getProjection ( ) ;
98107 if ( this . projection ) {
99- const layerProj = this . getNative ( ) . getDataSource ( ) . getProjection ( ) ;
100- const nProj = this . projection . getNative ( ) ;
101- featurePos = nProj . fromWgs84 ( layerProj . toWgs84 ( featurePos ) ) ;
102- position = nProj . fromWgs84 ( layerProj . toWgs84 ( position ) ) ;
108+ projection = this . projection . getNative ( ) ;
109+ featurePos = projection . fromWgs84 ( dataSourceProjection . toWgs84 ( featurePos ) ) ;
110+ position = projection . fromWgs84 ( dataSourceProjection . toWgs84 ( position ) ) ;
103111 }
112+ const geoFeature = {
113+ id : info . getFeatureId ( ) ,
114+ layer : info . getFeatureLayerName ( ) ,
115+ get geometry ( ) {
116+ const writer = getGeojsonWriter ( ) ;
117+ writer . setSourceProjection ( dataSourceProjection ) ;
118+ return JSON . parse ( getGeojsonWriter ( ) . writeGeometry ( geometry ) ) ;
119+ } ,
120+ properties : nativeVariantToJS ( info . getFeature ( ) . getProperties ( ) ) ,
121+ } ;
104122 return (
105123 this . listener . onVectorTileClicked . call ( this . listener , {
106124 clickType : info . getClickType ( ) . swigValue ( ) ,
107125 layer : this ,
108- featureId : info . getFeatureId ( ) ,
109- featureData : nativeVariantToJS ( info . getFeature ( ) . getProperties ( ) ) ,
110- featureLayerName : info . getFeatureLayerName ( ) ,
126+ feature : geoFeature ,
127+ featureId : geoFeature . id ,
128+ featureData : geoFeature . properties ,
129+ featureLayerName : geoFeature . layer ,
111130 featureGeometry : geometry ,
112131 featurePosition : fromNativeMapPos ( featurePos ) ,
113132 position : fromNativeMapPos ( position ) ,
@@ -216,7 +235,7 @@ export class VectorLayer extends BaseVectorLayer<com.carto.layers.VectorLayer, V
216235 if ( ! ! options . dataSource ) {
217236 const dataSource = options . dataSource . getNative ( ) ;
218237 if ( dataSource ) {
219- return new com . carto . layers . VectorLayer ( ( options . dataSource as VectorDataSource < any , any > ) . getNative ( ) ) ;
238+ return new com . carto . layers . VectorLayer ( options . dataSource . getNative ( ) ) ;
220239 }
221240 }
222241 return null ;
@@ -240,7 +259,7 @@ export class EditableVectorLayer extends BaseVectorLayer<com.carto.layers.Editab
240259 if ( ! ! options . dataSource ) {
241260 const dataSource = options . dataSource . getNative ( ) ;
242261 if ( dataSource ) {
243- const result = new com . carto . layers . EditableVectorLayer ( ( options . dataSource as VectorDataSource < any , any > ) . getNative ( ) ) ;
262+ const result = new com . carto . layers . EditableVectorLayer ( options . dataSource . getNative ( ) ) ;
244263 // result.setVectorEditEventListener(VectorEditEventListenerImpl.initWithOwner(new WeakRef(this)));
245264 // result.setVectorElementEventListener(VectorElementEventListenerImpl.initWithOwner(new WeakRef(this)));
246265 return result ;
0 commit comments