Mapbox Android SDK - querySourceFeatures at a given coordinate - mapbox

I use Mapbox Tileset API and generated a custom tileset (it's a huge 400MB of GeoJSON data) uploaded to Mapbox servers, and added to our style in the studio as a custom fill layer.
This way I can show our custom areas (as polygons) of the world with green (visited) and red (remaining) locations with using expressions only.
I would like to tell if a point (GPS coordinate) is within a polygon of the tileset source/layer and which one, even if the app is in the background (GPS tracking is running in the background and I would like to notify the user when they are within a polygon).
Using queryRenderedFeatures would be great, but unfortunately, it doesn't work when the app is in the background or the user's position is outside of the current viewport.
Is there any solution to get the list of the features at a GPS coordinate even if it's outside of the viewport?
Another requirement is that, it should work when the device is offline, so the Tilequery API won't help.
Downloading the offline data of our style with a limited zoom range working perfectly, I can see my custom source-layer (polygons) even if the device is offline.
So I think there should be a way to query the tileset-source when the device is offline too.
Currently, I generate a simplified GeoJSON file and use it with turf#points-within-polygon when the device is offline, but there're gaps, sometimes polygons are covering each other (due to the simplifying) etc... if I make the tolerance level lower the file is going to be too large to download and store it offline, so this is not really a solution just a poor workaround.
Can I make a PIP (point-in-polygon) query for a custom Tileset source even outside of the viewport, when the app is in the background and the device is offline?

Assuming this is your actual question:
Can I make a PIP (point-in-polygon) query for a custom Tileset source even outside of the viewport, when the app is in the background and the device is offline?
If the device is offline, then any solution that requires fetching tiles on demand (like a tileset in Mapbox-GL or TileQuery) is out.
You said storing the whole GeoJSON is out, because it's too big.
I think the remaining solution is to generate a single-zoom-level tileset and store it locally, then query it with something like query-mbtiles.

Related

LeafletJS offline support

Am using leafletJS for showing offline maps using openstreet tiles and its working fine. We need to use atlast tool to generate tiles and able to do that. But how to handle case that if generated tiles are not matching with latitude and longitude which are coming from services then in leaflet is showing markers but background map tiles are not loading (I know it wont match so its not showing :) ) but is there any way / approach which I can figure out that latitude and longitude provided are not in range or in sync of map tiles generated for offline so that I can show meaningful message to end users and accordingly user / admin will take actions?
I can imagine three approaches to this:
If you know which tiles you are generating (often times you are generating tiles in a bounding-box) you could hardcode that bounding-box and check if the given coordinate is inside or outside before adding the marker or jumping to the coordinate.
This question (leaflet - tile loading - error event) details a way to detect when Leaflet can't load a tile (for whatever reason: tile does not exist, no connection, ...). Maybe you could inform the user using that tileerror event.
You could convert the coordinate into its Slippy-Tilename equivalent and try to manually request that tile from your server / storage (for example using the Fetch-API). The conversion process is detailed (with code!) on the Openstreetmap-Wiki (https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#ECMAScript_.28JavaScript.2FActionScript.2C_etc..29)

Amount of requests on mapbox tile using flutter_map

I have recently implemented the flutter plugin called flutter_map, using the Mapbox tiles, and would like to know how you guys manage to count the network requests for the Static Tiles. Is it supposed to make a request for every move (zoom in, zoom out, move around, etc.) on the map itself? Is that the intended functioning or is there a way to diminish the number of requests made?Amount of requests made after zooming/panning
Is it supposed to make a request for every move (zoom in, zoom out, move around, etc.) on the map itself?
Yes indeed. The package supports static raster tiles, which means they must be re-downloaded if they change - such as on move or zoom events.
There isn't much in the way you can do about this, as it's a kind-of standard. This is why you'll find a similar thing in other mapping libraries, such as Leaflet.js and others.
See https://docs.mapbox.com/api/maps/static-tiles/ for potential ways to reduce costs whilst maintaining standards.

Is there a way to create searchable Area with Google Maps in Flutter (using google_maps_flutter)?

Let's say you want to build an app where people can find out whether the location the users are on has a risk of being flooded. You want to be able to create flood zone areas on the map and compare the user geolocation relative to the area. How do I do that with google_maps_flutter? or is there any other way to do it with plugins in flutter?
What I have in mind right now is to create polygons on the map and perform some geometric operations with it (if that is even possible). I have Esri SHP files which I will export to json and parse it in flutter and then use the results to draw polygons of the areas.
no code just yet..
You can make use of 'overlay widgets' in Flutter. You can draw, say a circle, indicating a flood zone with colour and radius in accordance with the probability (or other parameters).
Depending on how you want to display, you can create a separate UI control to display the comparision with reference to the user's geo-location.

Custom drawing layer in Mapbox GL JS (and Leaflet)

I'm starting research to add a user feature to an existing map built in Mapbox GL JS (wrapped in an Angular 2+ application). What I need to do, is allow a user to be able to draw and rotate ellipses and text labels over the top of a map, and be able to save screen captures of the result.
I'm coming into this with no experience in Mapbox or Leaflet, so I have a lot to figure out. My first goal is to determine if I can do this in Mapbox directly (with a plugin?), of if I will need to render a canvas over the top of my map with some third-part drawing library (I have a lot of experience with those).
The obvious advantage to doing this in Mapbox directly would be that we might still be able zoom and pan.
The Mapbox-gl-draw library lets the user author features in a map, but probably not to the extent you need.
If the features the user creates don't need to live "in map space" (ie, the map is static, and the labels are statically positioned over the top, for printing), working directly on a canvas will give you much more flexibility. You'll also have access to a much wider variety of libraries.

Use an Image as an MKOverlayView (iPhone MKMapKit)

We want to use MapKit / MKOverlayView to create a map that looks totally customized. We would create a PNG that has the local streets / points of interest, and match that up to MapKit map.
I am finding some info that seems to infer that this is possible, but all the tutorials and examples I find are dealing with drawing lines and polygons, which is not what we want.
I have also considered the possibility of creating the PNG, grabbing the user's location and mathematically calculating their position on the image... but that seems like a bigger task than potentially using a MKOverlayView
Any ideas about how to get started would be much appreciated.
You could start by looking at Open Maps I believe you can customise their maps by creating your own XML file (different styles of roads etc..) You can then download the map tiles as PNGs or lazy load them in your app.
Google maps on the other hand you are not allowed to modify or store in you application.
However if you choose the open maps approach you have to effectively roll your own MapKit. This is tricky but very much possible. Start by looking at the apple developer videos on tiled scroll views.