Comments (2)
In an effort to answer my question above, I'm attempting to patch the UrlTileProvider
class in @nativescript/google-maps/index.android.js
by adding a setUrl
method and then referencing the specified url in the getTileUrl
method, similar to what I was doing on Android with the prior plugin. Here's the code:
export class UrlTileProvider extends TileProvider {
constructor(callback, size = 256) {
super(null);
this._callback = callback;
this._url = "";
const ref = new WeakRef(this);
const provider = com.google.android.gms.maps.model.UrlTileProvider.extend({
setUrl(url) {
const owner = ref.get(); // returns undefined
owner._url = url;
},
getTileUrl(x, y, zoom) {
const owner = ref.get();
if (owner) {
if (owner._url.length > 0) {
var url = owner._url.replace('{x}', x).replace('{y}', y).replace('{z}', zoom);
return new java.net.URL(url);
}
else {
return new java.net.URL(owner._callback(x, y, zoom) || null);
}
}
return null;
},
});
this._native = new provider(size, size);
}
get native() {
return this._native;
}
}
The problem is that in setUrl
, ref.get()
returns undefined, even though it resolves successfully in getTileUrl
. I suspect this is simply a WeakRef issue, but I'm not sure how to proceed.
from plugins.
I've had a chance to look at this further... setting the tileOverlay transparency via tileOverlay.native.setTransparency()
does indeed work. The problem in my case is with the tileProvider. All the tiles were the same, thus alternating the transparencies of the tileOverlays had no visible effect, since there was no change in the image.
What I'm doing is animating weather radar on a map, getting the 6 most recent radar images and alternating the transparencies to create the animation. My code was based on this question - note the different tileProvider implementations between iOS and Android.
This code works just fine on iOS, and is similar to the code referenced above:
import { GoogleMap, MapView, MarkerOptions, CameraUpdate, UrlTileProvider } from '@nativescript/google-maps';
for (let timestamp of timestamps) {
const tileProvider = new UrlTileProvider((x, y, z) => {
return `https://tilecache.rainviewer.com/v2/radar/${timestamp}/256/${z}/${x}/${y}/4/1_0.png`;
}, 256);
...
}
The same code on Android returns images that are all identical. I believe it has to do with how the URL is composed in the tileProvider callback, and that the same timestamp is used for all images. I suspect this because it would explain all the images being the same, and because the sample code for Android referenced above has a specific method for setting the url to be returned, setUrl()
and which is then referenced by the getTileUrl(x,y,z)
method.
When I try using this code with the @nativescript/google-maps
plugin, I get the error
Error: java.lang.NullPointerException: tileProvider must not be null.
when I try to add the tileOverlay:
let newTileOverlay = map.addTileOverlay(tileOverlayOptions);
So, the question now becomes is there a way to modify the url returned by the tileProvider callback on Android?
from plugins.
Related Issues (20)
- [imagepicker] Exception if built in --release mode: `Error: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/documentfile/provider/DocumentFile;` HOT 3
- nativescript-onesignal plugin is failing with Java no class found errors HOT 2
- [@nativescript/imagepicker] Awaiting image selection on iOS doesn't also wait for the picker to be fully closed
- NativeScript IOS: Photo uploads to server are randomly failing with slow networks(LTE 1 or 2 bars) HOT 1
- Nativescript Angular IOS : Domain=NSURLErrorDomain Code=-1001 "The request timed out." when uploading files HOT 1
- [@nativescript/google-maps] Are there any feature utils for clustering or heat map?
- [@nativescript/imagepicker] Error when trying to display a chosen picture HOT 4
- Push notifications do not work if the App is in Background HOT 1
- Unable to create Google Maps custom infoWindow on iOS HOT 1
- [@nativescript/google-signin] Interfaces is not defined in worker HOT 2
- Build failure for latest @nativescript/background-http v6.0.1 HOT 4
- [@nativescript/datetimepicker] Bug in datetimepicker callback showing false date
- [@nativescript/geolocation] unable to compile Android version as I get a `Execution failed for task ':app:checkDebugDuplicateClasses'.` HOT 19
- @nativescript/imagepicker does not show selected image after app is build in release mode HOT 7
- imagepicker with NativeScript Vue is not working HOT 2
- [@nativescript/google-maps] New Android Google Maps SDK renderer HOT 1
- [nativescript-videorecorder] iOS: Cancelling camera does not resolve.
- myLocationButtonEnabled not working on iOS HOT 1
- [@nativescript/google-maps]: Support for MapId for styling through Google Cloud
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 plugins.