[OpenLayers-Dev] Lost scope in tileUrlFunction when extending ol.source.VectorTile (MVT)
Christian Mayer
ml-cm at meggsimum.de
Thu Oct 12 08:20:20 PDT 2017
Hi Roman,
you are absolutely right and your explanation brings it to the point. I
wasn't aware that the 'tileUrlFunction' should not be overwritten
directly. I changed my code according to your suggestion it works perfectly.
Thanks you very much! Great help!
Cheers
Chris
On 12.10.2017 14:48, Roman Zoller wrote:
> As far as I understand, the ol.source.VectorTile class wasn't
> specifically designed to have tileUrlFunction as a function that can
> be overriden and that will be called with a specific this context.
>
> I think the general idea is that you can just pass any function as
> options.tileUrlFunction, and it just happened to be called with a this
> context of the class before version 4.2.0, but I guess this was never
> really an intended feature.
>
> For your specific issue, I think you could rename the function in your
> class to avoid confusion, e.g.
>
> ol.source.GWCVT.prototype.defaultTileUrlFunction =
> function(tileCoord, pixelRatio, projection) {
> // ...
> };
>
> and then pass it as options.tileUrlFunction to the super class in your
> constructor, with correctly bound this:
>
> ol.source.GWCVT = function(options) {
> var tileUrlFunction = options.tileUrlFunction ||
> this.defaultTileUrlFunction.bind(this);
>
> ol.source.VectorTile.call(this, {
> tileUrlFunction: tileUrlFunction,
> ...
> });
> };
>
> Hope that helps!
>
> Cheers,
>
> Roman
>
> On Thu, Oct 12, 2017 at 2:33 PM, Christian Mayer <ml-cm at meggsimum.de
> <mailto:ml-cm at meggsimum.de>> wrote:
>
> Hi again,
>
> here is some more information in addition to my previous mail:
>
> The problem occurs for VectorTiles in GeoJSON format as well. So
> there must be a more general problem with extending the
> ol.source.VectorTile (or the way I do it).
> The change / problem seems to be introduced with Version 4.2.0.
> With version 4.1.1 everything works as expected.
>
> Cheers
> Chris
>
>
> On 12.10.2017 13:45, Christian Mayer wrote:
>>
>> Hi all,
>>
>> I extended the class ol.source.VectorTile in order to load
>> VectorTiles in different formats (GeoJSON and MVT) from a local
>> GWC cache. While upgrading from OpenLayers v3.20 to OpenLayers
>> v4.x it seems that for MVT the scope in the "tileUrlFunction"
>> gets lost. It seems to be "window". For GeoJSON-based VectorTiles
>> everything is still running fine.
>>
>> Below you find the crutial parts of my class:
>>
>> ol.inherits(ol.source.GWCVT, ol.source.VectorTile);
>>
>> ol.source.GWCVT.prototype.tileUrlFunction =
>> function(tileCoord, pixelRatio, projection) {
>>
>> // here 'this' becomes 'window' in the second call
>>
>> // assembling the URL
>> // ...
>>
>> }
>>
>> ol.source.GWCVT.prototype.setTileUrlFunction =
>> function(tileUrlFunction) {
>>
>> ol.source.VectorTile.prototype.setTileUrlFunction.call(this,
>> tileUrlFunction);
>> };
>>
>> Thanks for any hint!
>>
>> Cheers
>> Chris
>>
>>
>> _______________________________________________
>> Dev mailing list
>> Dev at lists.osgeo.org <mailto:Dev at lists.osgeo.org>
>> https://lists.osgeo.org/mailman/listinfo/openlayers-dev
>> <https://lists.osgeo.org/mailman/listinfo/openlayers-dev>
>
>
> _______________________________________________
> Dev mailing list
> Dev at lists.osgeo.org <mailto:Dev at lists.osgeo.org>
> https://lists.osgeo.org/mailman/listinfo/openlayers-dev
> <https://lists.osgeo.org/mailman/listinfo/openlayers-dev>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20171012/ad28c40e/attachment-0001.html>
More information about the Dev
mailing list