-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom sources #2920
Comments
Just a note for anyone tracking this: a fair amount of the custom source type API is documented under the hood, just marked private for now:
So, with that in mind, some specific steps before going public w/ this API:
@lucaswoj @mourner any additional suggestions, or thoughts on the right value of X? |
That plan looks good to me @anandthakker 😄 X could be 0 weeks. Building the "dynamic vector source" is what I'm after. |
We also are interested in exploring some of the custom source ideas for our map but we're worried about the instability of the existing API. Do you have a sense of how "beta" it is at this point? @anandthakker, how did it work for your project? |
@pwilczynski it's working well in our project, but I do think that there are very likely changes on the horizon, esp relating to some architectural changes in how the WebWorker code works (tracked here: #3034 ). I am not sure what the likely timeline is for that, but I've been holding off on the 'dynamic vector source' example that's blocking this ticket until after that change. |
@pwilczynski There are some big changes on the horizon for this API. I recommend looking at designs that don't require creating custom sources for the time being. |
Ah, this is very interesting to me. I've been messing around with creating and storing vector tiles in IndexedDB in this repo. I have hacked together a Leaflet module that loads tiles from IndexedDB, but haven't quite figured out how to get a custom mapbox-gl source. Looking forward to seeing more of this! |
Any progress on this Omnivore example? |
If you're just looking for CSV go GeoJSON, this is worth looking at: https://bl.ocks.org/danswick/effa94375f9ed24cea9f
… On Jun 14, 2017, at 5:17 PM, Thad Kerosky ***@***.***> wrote:
Any progress on this Omnivore example?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
That approach had some inconsistent async problems when I last tested it. For instance, in Chrome, the CSV data does not appear the second time you visit the link. |
I made a slightly hacky version of the mapbox-gl-topojson into mapbox-gl-csv which seems to work, see: |
I am not sure why, but public versions of Mapbox-GL-JS, even the version matching package.json that is public, 0.22.0 do not seem to have the required Edit: |
Here is another reference in the live codebase to the mapbox-gl-topojson though it does not show to use |
@thadk the custom source API ( Lines 950 to 960 in 6a64798
The true custom source API is something we're hoping to work on pretty soon ( 🤞 ), and you can track that work here: https://github.com/mapbox/mapbox-gl-js/projects/2 |
Is this custom source API still under active development? |
I'm looking into using this feature to load vector tiles from websql rigged with mbtiles content. Can someone share a working example of a custom source? I'm having a hard time understanding what I need to implement and how to inherit... |
Ok, Two days later I found some examples and I can wrap my head around how to implement this. Unfortunately, all the examples I found are basically creating a custom build of mapbox-gl-js and adding the relevant custom source. |
Any news on that @mourner @anandthakker ? We are trying to find an efficient way of presenting spatiotemporal data to Mapbox GL and so far have been very limited by: We would like to avoid forking or doing custom build at all costs. Thanks :) |
In case anyone is interested, I have created a fork of mapbox-gl-js here. |
@HarelM, thanks for your patch! It works great! This is exactly what I was looking for. I hope it will be merged to the main mapbox-gl-js repository, especially the "custom://" handler. It is extremely useful. |
Thanks @michalfapso. If anyone likes my solution above please up vote it, maybe if it gets enough up votes someone from mapbox would consider it. It is a very simple solution that doesn't involve a lot of code changes. |
In case anyone's following up on that: |
@nerik Can you share the relevant code? Service worker seems like the right solution to intercept mapbox tile requests - I have a problem with it since I write my app using Angular and I use dependency injection and all the goodies Angular provides that are not available when using a service worker, which makes the development with it much more complex... @mourner @anandthakker Any update regarding my question above? I would very much like to add my code to mapbox and reduce the need to manually updating my fork and creating a patch every time I want to update mapbox version. Also I think others can benefit from it (8 developers on this thread have found this useful :-)). |
@HarelM We have a PoC on a private repo, just invited you with read access. It's a react/CRA setup, but with not a lot added actually so you should get your bearings easily (Rollup compiles the sw at src/sw/index.js, client code is at src/App.js) |
@HarelM Thanks Harel for your idea. It's simple and clever, and solve our problem. I was trying to implement an extension Class of VectorTileSource and asociate it with a new sourcetype. But VectorTileSource is not public available so i also need to fork mapbox code. I hope this kind of extension will be available on mapbox in the future. |
@lasterra no problem :-) |
Any update on this? |
+1 on a solution for this. The ability to intercept loading tiles and access their imagery/data is essential for my mapping app. I'm currently using OpenLayers and their tileLoadFunction to load tiles and apply effects to them before they are rendered, or in some cases load the tile and access the header information per tile. But there doesn't seem to be a way to do this in Mapbox GL JS without resorting to hacks. |
For anyone interested, we ended up opting for the solution proposed by @HarelM (#2920 (comment)). Cheers. |
@nerik I'm not sure I fully understand your comment. |
@HarelM Sorry, what I meant was that we opted to fork Mapbox GL JS, as you did, instead of trying to hijack tile calls with a separated service worker.
Hope this helps |
Hi @HarelM we didn't develop a way to add custom sources but created a specific type instead to fit our needs, sadly I guess this won't work for you. A generic solution to add custom sources like you proposed didn't work for use because we wanted to reuse as much logic as possible from the
To explain a bit more about the auto updates, we mainly have two branches in the forked repo:
This simplifies us a lot the release process:
I'd recommend you to follow this workflow to keep your fork updated easily |
FYI I was able to create a custom Source that re-uses existing Source logic. The trick is to use undocumented I've only tested this with 3.0 beta, but probably it works on earlier versions? Here is an example that debounces the tile requests so you don't spam the tile server when the user uses scroll wheel flick to change zoom levels. import { Style, RasterSource } from "mapbox-gl";
import { Source } from "react-map-gl";
// available type definitions do not include a definition for the Style export
declare module "mapbox-gl" {
export const Style: any
}
const RasterTileSourceImpl = Style.getSourceType("raster")
const SOURCE_TYPE = "debounced_raster"
const DEBOUNCE_TIME = 100
class DebouncedRasterSourceImpl extends RasterTileSourceImpl {
constructor(...args: unknown[]) {
super(...args)
this.type = SOURCE_TYPE
}
loadTile(tile: any, callback: (e: null) => void) {
const timer = setTimeout(() => {
if (!tile.aborted) {
super.loadTile(tile, callback)
}
}, DEBOUNCE_TIME)
tile.request = {
cancel: () => clearTimeout(timer)
}
}
}
Style.setSourceType(SOURCE_TYPE, DebouncedRasterSourceImpl)
export type DebouncedRasterSourceProps = Omit<RasterSource, "type"> & {
id?: string
children?: any
}
export const DebouncedRasterTileSource = (props: DebouncedRasterSourceProps) => {
return (
<Source
{...props}
// @ts-ignore
type={SOURCE_TYPE}
/>
)
}
// example usage:
return (
<DebouncedRasterTileSource tiles={tiles} tileSize={tileSize}>
<Layer
type={"raster"}
paint={paint}
minzoom={minzoom}
maxzoom={maxzoom}
/>
</DebouncedRasterTileSource>
); |
The custom source API (
addType
, etc.) as implemented in #2667 is an undocumented / experimental feature. There's some private documentation inmapbox-gl-js/src/ui/map.js
Lines 950 to 960 in 6a64798
The true custom source API is something we're hoping to work on pretty soon ( 🤞 ), and you can track that work here: https://github.com/mapbox/mapbox-gl-js/projects/2
The text was updated successfully, but these errors were encountered: