Comments (2)
I'm doing a first try and think that can be done by modifying tileLoadFunction
in source
parameter passed to _register
method in source.component.ts
before setting the source to openlayers instance. Something like this seems to work with a xyz-source:
protected _register(source: any) {
const token = 'my-token';
// function for AJAX request (this should be part of tileLoadFunction)
const request = (url, token) => {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status === 200) {
resolve(xhr);
} else if (xhr.readyState === 4 && xhr.status !== 200) {
reject(Error(xhr.statusText));
}
};
xhr.open('GET', url);
xhr.responseType = 'blob';
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.send();
})
};
// openlayers custom load function, should be passed as a parameter or already set as source.tileLoadFunction
const tileLoadFunction = (imageTile: any, url) => {
request(url, token)
.then((xhr: any) => {
const resp = xhr.response;
const imagen = URL.createObjectURL(resp);
imageTile.getImage().src = imagen;
URL.revokeObjectURL(resp);
})
.catch(() => {
imageTile.getImage().src = '#';
})
}
if (this.host) {
// set the function as source.tileLoadFunction
source.tileLoadFunction = tileLoadFunction;
this.host.instance.setSource(source);
}
if (this.raster) {
this.raster.sources = [source];
}
}
My Idea is to add an @input property in xyz.component so the function can be passed when using the component as this:
<aol-layer-tile [visible]="true">
<aol-source-xyz
url="https://my-server.com/{z}/{x}/{y}.png"
[tileLoadFunction]="myCustomTileLoadFunction"
opaque="false"
crossOrigin=""
>
</aol-source-xyz>
</aol-layer-tile>
and then set to the source object in one this 2 places:
- xyz.component.ngAfterContentInit()
- source.component._register()
I also guess, that this functionality could be added to other source components, but do not know which ones should support this kind of functionality.
Any thoughts on this approach?
Thanks
from ngx-openlayers.
Finally I found that the xyz component has a property for that
@Input() tileLoadFunction?: TileLoadFunctionType;
also de geoson component has a property for that
@Input() loader?: ol.FeatureLoader;
but in the second case I needed to acces geojson component openlayers instance property inside de loader function, so I needed to modify slightly de component ngOnInit() method. The resulting code is this for geojson.component.ts
ngOnInit() {
// @NOTE loader function is binded to this in order to have access to this.intance when executing the loader function
this.loader = this.loader.bind(this);
this.format = new format.GeoJSON();
this.instance = new source.Vector(this);
this.host.instance.setSource(this.instance);
}
I also have to solve some typescript errors due to using the library source code in my Angular 8 aplication.
If you want a pull request or integrate the changes in the library just let me know.
from ngx-openlayers.
Related Issues (20)
- ⚠️ Migration OL5 and next release steps ⚠️ HOT 2
- Warnings in console about OL objects
- next version with OL5 and definitely typed has compile errors
- Ngx-openlayers is extremely slow HOT 1
- Point with altitude with ol-cesium
- cluster preformance HOT 1
- How to show current geolocation HOT 1
- Vulnerabilities reported by npm audit HOT 1
- Angular 9 >> ERROR in Symbol MapComponent declared in...is not exported from..../ngx-openlayers/dist/index.js HOT 8
- Mouse issue on next build HOT 6
- How to access the OpenLayers API? HOT 3
- not work in Angular 9 HOT 2
- feat: Angular 10 Support HOT 4
- How to capture a mouse over event on a <aol-feature> with OpenLayer HOT 3
- <aol-overlay> can't getPosition HOT 3
- Why did you stop supporting? HOT 2
- The map is not showing inside a modal HOT 1
- Update HOT 1
- Update to Angular 16 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-openlayers.