OL 4.2 with TypeScript:How to extend index.d.ts?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

OL 4.2 with TypeScript:How to extend index.d.ts?

italavera
I'm using Openlayers v4.2.0 with typescript so I installed the typesDefinition with npm install --save @types/openlayers 
I need to execute the method getFullTileRange() from ol.tilegrid.TileGrid type  but is not defined in the type definition from @types/openlayers (index.d.ts).
First I get a compilation error because getFullTileRange method is not declared in index.d.ts. I try to modify index.d.ts adding this method (inside my IDE to skip compilation errors) but running my app I  get this exection error

TypeError: tileGrid.getFullTileRange is not a function.

How can I extend index.d.ts to execute that function?

Thanks!




_______________________________________________
Users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: OL 4.2 with TypeScript:How to extend index.d.ts?

Olivier Guyot
Hi,

This function is not part of the public API, hence the fact it is not exposed in Typescript definitions. You could still use it without errors by casting the ol.tilegrid.Tilegrid object to `any`, like so:
(tilegridObj as any).getFullTileRange()
Although that is obviously not the recommended way to go.

As for the execution error, Typescript would have nothing to do with that so there's probably a problem with how the tilegrid object is created.

--
camptocamp
INNOVATIVE SOLUTIONS
BY OPEN SOURCE EXPERTS

Olivier Guyot
Geospatial Developer
+33 4 58 48 20 28

On Mon, Aug 7, 2017 at 4:49 PM, Ignacio Talavera <[hidden email]> wrote:
I'm using Openlayers v4.2.0 with typescript so I installed the typesDefinition with npm install --save @types/openlayers 
I need to execute the method getFullTileRange() from ol.tilegrid.TileGrid type  but is not defined in the type definition from @types/openlayers (index.d.ts).
First I get a compilation error because getFullTileRange method is not declared in index.d.ts. I try to modify index.d.ts adding this method (inside my IDE to skip compilation errors) but running my app I  get this exection error

TypeError: tileGrid.getFullTileRange is not a function.

How can I extend index.d.ts to execute that function?

Thanks!




_______________________________________________
Users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/openlayers-users


_______________________________________________
Users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: OL 4.2 with TypeScript:How to extend index.d.ts?

italavera
Thanks! perhaps I'm trying the wrong way. I',m using vector-tile from geoserver and I get the same problem mentioned here so I try to use ol.source.Vector with ol.loadingstrategy.tile as loading strategy as follows.
.......................................................................................
strategy: ol.loadingstrategy.tile(tileGrid),
url: function(extent, resolution) {
        var tileCoord = tileGrid.getTileCoordForCoordAndResolution(ol.extent.getCenter(extent), resolution);
        var z = tileCoord[0];
        var x = tileCoord[1];
        var y = tileCoord[2];
        var range = tileGrid.getFullTileRange(z);
        y = range.getHeight() + tileCoord[2];// I need the range to transofrm 'Y' coordinate to fit  in geoserver tile range.
        return '/geoserver/gwc/service/tms/1.0.0/' +layer +'@EPSG%3A'+projection_epsg_no+'@geojson/'+z+'/'+ x+'/'+ y+'.geojson';
   }

Is there any workaround?



On Mon, Aug 7, 2017 at 12:46 PM, Olivier Guyot <[hidden email]> wrote:
Hi,

This function is not part of the public API, hence the fact it is not exposed in Typescript definitions. You could still use it without errors by casting the ol.tilegrid.Tilegrid object to `any`, like so:
(tilegridObj as any).getFullTileRange()
Although that is obviously not the recommended way to go.

As for the execution error, Typescript would have nothing to do with that so there's probably a problem with how the tilegrid object is created.

--
camptocamp
INNOVATIVE SOLUTIONS
BY OPEN SOURCE EXPERTS

Olivier Guyot
Geospatial Developer
<a href="tel:+33%204%2058%2048%2020%2028" value="+33458482028" target="_blank">+33 4 58 48 20 28

On Mon, Aug 7, 2017 at 4:49 PM, Ignacio Talavera <[hidden email]> wrote:
I'm using Openlayers v4.2.0 with typescript so I installed the typesDefinition with npm install --save @types/openlayers 
I need to execute the method getFullTileRange() from ol.tilegrid.TileGrid type  but is not defined in the type definition from @types/openlayers (index.d.ts).
First I get a compilation error because getFullTileRange method is not declared in index.d.ts. I try to modify index.d.ts adding this method (inside my IDE to skip compilation errors) but running my app I  get this exection error

TypeError: tileGrid.getFullTileRange is not a function.

How can I extend index.d.ts to execute that function?

Thanks!




_______________________________________________
Users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/openlayers-users




--
Ing Ignacio Talavera 

_______________________________________________
Users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: OL 4.2 with TypeScript:How to extend index.d.ts?

Olivier Guyot
You could try using tileGrid.getTileRangeForExtentAndResolution(extent, resolution) instead, although this is not part of the public API either.

Whichever way you chose, it doesn't make sense that your code gives you an execution error on tileGrid.getFullTileRange but not on tileGrid.getTileCoordForCoordAndResolution, as a ol.tilegrid.TileGrid should have both functions on its prototype. Are you sure this is the error you're getting?

--
camptocamp
INNOVATIVE SOLUTIONS
BY OPEN SOURCE EXPERTS

Olivier Guyot
Geospatial Developer
+33 4 58 48 20 28

On Mon, Aug 7, 2017 at 7:41 PM, Ignacio Talavera <[hidden email]> wrote:
Thanks! perhaps I'm trying the wrong way. I',m using vector-tile from geoserver and I get the same problem mentioned here so I try to use ol.source.Vector with ol.loadingstrategy.tile as loading strategy as follows.
.......................................................................................
strategy: ol.loadingstrategy.tile(tileGrid),
url: function(extent, resolution) {
        var tileCoord = tileGrid.getTileCoordForCoordAndResolution(ol.extent.getCenter(extent), resolution);
        var z = tileCoord[0];
        var x = tileCoord[1];
        var y = tileCoord[2];
        var range = tileGrid.getFullTileRange(z);
        y = range.getHeight() + tileCoord[2];// I need the range to transofrm 'Y' coordinate to fit  in geoserver tile range.
        return '/geoserver/gwc/service/tms/1.0.0/' +layer +'@EPSG%3A'+projection_epsg_no+'@geojson/'+z+'/'+ x+'/'+ y+'.geojson';
   }

Is there any workaround?



On Mon, Aug 7, 2017 at 12:46 PM, Olivier Guyot <[hidden email]> wrote:
Hi,

This function is not part of the public API, hence the fact it is not exposed in Typescript definitions. You could still use it without errors by casting the ol.tilegrid.Tilegrid object to `any`, like so:
(tilegridObj as any).getFullTileRange()
Although that is obviously not the recommended way to go.

As for the execution error, Typescript would have nothing to do with that so there's probably a problem with how the tilegrid object is created.

--
camptocamp
INNOVATIVE SOLUTIONS
BY OPEN SOURCE EXPERTS

Olivier Guyot
Geospatial Developer
<a href="tel:+33%204%2058%2048%2020%2028" value="+33458482028" target="_blank">+33 4 58 48 20 28

On Mon, Aug 7, 2017 at 4:49 PM, Ignacio Talavera <[hidden email]> wrote:
I'm using Openlayers v4.2.0 with typescript so I installed the typesDefinition with npm install --save @types/openlayers 
I need to execute the method getFullTileRange() from ol.tilegrid.TileGrid type  but is not defined in the type definition from @types/openlayers (index.d.ts).
First I get a compilation error because getFullTileRange method is not declared in index.d.ts. I try to modify index.d.ts adding this method (inside my IDE to skip compilation errors) but running my app I  get this exection error

TypeError: tileGrid.getFullTileRange is not a function.

How can I extend index.d.ts to execute that function?

Thanks!




_______________________________________________
Users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/openlayers-users




--
Ing Ignacio Talavera 


_______________________________________________
Users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/openlayers-users
Reply | Threaded
Open this post in threaded view
|

Re: OL 4.2 with TypeScript:How to extend index.d.ts?

italavera
Thanks, Finally I found a workaround instead of invoking getFullTileRange method.


strategy: ol.loadingstrategy.tile(tileGrid),
url: function(extent, resolution) {
        var tileCoord = tileGrid.getTileCoordForCoordAndResolution(ol.extent.getCenter(extent), resolution);
        var z = tileCoord[0];
        var x = tileCoord[1];
        var y = tileCoord[2];
        //var range = tileGrid.getFullTileRange(z);
        y = Math.pow(2, z) + y;//range.getHeight() + tileCoord[2];
        return '/geoserver/gwc/service/tms/1.0.0/' +layer +'@EPSG%3A'+projection_epsg_no+'@geojson/'+z+'/'+ x+'/'+ y+'.geojson';
   }

I

On Tue, Aug 8, 2017 at 4:27 AM, Olivier Guyot <[hidden email]> wrote:
You could try using tileGrid.getTileRangeForExtentAndResolution(extent, resolution) instead, although this is not part of the public API either.

Whichever way you chose, it doesn't make sense that your code gives you an execution error on tileGrid.getFullTileRange but not on tileGrid.getTileCoordForCoordAndResolution, as a ol.tilegrid.TileGrid should have both functions on its prototype. Are you sure this is the error you're getting?

--
camptocamp
INNOVATIVE SOLUTIONS
BY OPEN SOURCE EXPERTS

Olivier Guyot
Geospatial Developer
<a href="tel:+33%204%2058%2048%2020%2028" value="+33458482028" target="_blank">+33 4 58 48 20 28

On Mon, Aug 7, 2017 at 7:41 PM, Ignacio Talavera <[hidden email]> wrote:
Thanks! perhaps I'm trying the wrong way. I',m using vector-tile from geoserver and I get the same problem mentioned here so I try to use ol.source.Vector with ol.loadingstrategy.tile as loading strategy as follows.
.......................................................................................
strategy: ol.loadingstrategy.tile(tileGrid),
url: function(extent, resolution) {
        var tileCoord = tileGrid.getTileCoordForCoordAndResolution(ol.extent.getCenter(extent), resolution);
        var z = tileCoord[0];
        var x = tileCoord[1];
        var y = tileCoord[2];
        var range = tileGrid.getFullTileRange(z);
        y = range.getHeight() + tileCoord[2];// I need the range to transofrm 'Y' coordinate to fit  in geoserver tile range.
        return '/geoserver/gwc/service/tms/1.0.0/' +layer +'@EPSG%3A'+projection_epsg_no+'@geojson/'+z+'/'+ x+'/'+ y+'.geojson';
   }

Is there any workaround?



On Mon, Aug 7, 2017 at 12:46 PM, Olivier Guyot <[hidden email]> wrote:
Hi,

This function is not part of the public API, hence the fact it is not exposed in Typescript definitions. You could still use it without errors by casting the ol.tilegrid.Tilegrid object to `any`, like so:
(tilegridObj as any).getFullTileRange()
Although that is obviously not the recommended way to go.

As for the execution error, Typescript would have nothing to do with that so there's probably a problem with how the tilegrid object is created.

--
camptocamp
INNOVATIVE SOLUTIONS
BY OPEN SOURCE EXPERTS

Olivier Guyot
Geospatial Developer
<a href="tel:+33%204%2058%2048%2020%2028" value="+33458482028" target="_blank">+33 4 58 48 20 28

On Mon, Aug 7, 2017 at 4:49 PM, Ignacio Talavera <[hidden email]> wrote:
I'm using Openlayers v4.2.0 with typescript so I installed the typesDefinition with npm install --save @types/openlayers 
I need to execute the method getFullTileRange() from ol.tilegrid.TileGrid type  but is not defined in the type definition from @types/openlayers (index.d.ts).
First I get a compilation error because getFullTileRange method is not declared in index.d.ts. I try to modify index.d.ts adding this method (inside my IDE to skip compilation errors) but running my app I  get this exection error

TypeError: tileGrid.getFullTileRange is not a function.

How can I extend index.d.ts to execute that function?

Thanks!




_______________________________________________
Users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/openlayers-users




--
Ing Ignacio Talavera 




--
Ing Ignacio Talavera 

_______________________________________________
Users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/openlayers-users