-
-
Notifications
You must be signed in to change notification settings - Fork 876
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Drawing over tile #941
Comments
Could you do it like the polyline/polygon layer code ? It's not quite clear why you need a tile callback or whatever (those have culling in the code if that's what you are trying to do). |
I need to modify exactly bitmap of the tile, cutting a hole in it, for example, etc |
My map layer isn't main layer and under it I have data which should be visible in some points and for this I need to cut map and make it transparent in some places |
Well, in the absence of any other replied, I'm not quite sure how to do it easily as is. The current system downloads as a png and displays it as an image widget. I'm not sure of a "simple" solution. However, you could probably adapt it and display that png with drawImage in a canvas. That may be easier to "edit", but may involve a fair bit of work to get their, not quite sure. You could also probably hack my vector tile code at https://github.com/ibrierley/flutter_map_vector_tiles (you can set drawImages: true and it will paint multiple tile images to a single canvas) but it's very beta atm and a lot of stuff will probably change (but equally I'm probably not against adding some simple bits like callbacks if helpful). It may depend slightly if you are looking for a single display edit, or want to specifically edit separate tiles for some reason (e.g so you could save that specific tile for reload). |
Just thinking about this some more as @eveetc mentioned it in the other issue as well.. If one needs to cut a hole in the "image", do you need access to the canvas at all ? Could you essentially be a tileprovider or something that takes a url grabs the png and cuts a hole in it ? Or use a clip or a mask maybe (will probably be performance implications). I think these issues are a case of the devil is in the detail, as to where the solution likely lies. |
Well essentially yes, it 100% works manipulating the tileprovider or tile location, when specific tiles are requested. |
Do you have any similar example out there somewhere of a similar type effect you are after ? (still failing to visualise it properly) |
There is a way to do that via leaflet: on event (class appears) "leaflet-tile-loaded" you can get a canvas and do whatever you want Can't share more, sorry |
I tried today very naive approach (I'm open to any comment, I'm sure it has its downsides) For now, it only renders a red square at the centre of the tile
|
One more question regarding this, how to convert between coordinates? For example, right now what I have:
How to understand bounds of 256x256 (or 512x512) tile in terms of XY (map's real, not that one, sent to tile provider) or LatLng? So I could draw exactly on the image in correct positions? What I want: I have LatLng, I want to draw there a thing –> I call some method to convert to coordinates, I understand if they intersect with current tile image or not and draw on it. What I currently found (data I can manipulate somehow):
|
Not sure if this helps, but https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames (for number 3) |
Very cool article! Huge thanks, I have a couple of questions (hope you know some answers, ha-ha)
|
No problem! Well, I'll answer question 2 first:I use this code to convert a final Crs crs = Epsg3857();
final nwPoint = crs
.latLngToPoint(bounds.northWest, zoomLevel.toDouble())
.unscaleBy(tileSize)
.floor();
final sePoint = crs
.latLngToPoint(bounds.southEast, zoomLevel.toDouble())
.unscaleBy(tileSize)
.ceil() -
CustomPoint(1, 1); However this is the opposite of what you need. I'd have a look at the
I can't guide you on exactly how to do this, because I stole this particular code for my plugin from Now in answer to question 1:Yes, that is true, because of a projection. Think of it like this: If you paint the Earth onto a balloon using ink that can come off, put the balloon into a tube, then blow it up, the Earth will now be on the tube. However, the top and bottom will be squashed, because you can't make a sphere into a flat surface. I strongly encourage you to watch this rather silly but informative video: https://www.youtube.com/watch?v=jtBV3GgQLg8, which gives more insight into this and a few other problems you'll likely come across using a mapping library. Therefore, (and don't quote me on this part, I'm less comfortable here) using a CRS projection above is recommended. Whether this deals with this problem, I don't know. You'll see at the bottom of the 'Zoom Levels' table on that page a comment saying this:
It then advises you to check this page, which you should definitely do: https://wiki.openstreetmap.org/wiki/Zoom_levels, it gives you much more information about zoom levels and m/pixels. I have no idea if you'll need this, but converting between device pixels (what OSM uses) and logical pixels (what Flutter uses) can be done using this formula: https://stackoverflow.com/a/60901354/11846040 Hope that covers some questions for you, sorry if it didn't help or was wrong (which is a chance)! |
Yeah, sounds like drawing over an image is much harder, than I thought |
For those, who may encounter this too, this resources probably can help (they look promising, but I haven't dived into them yet):
|
My dart code:
|
Being an idiot here, what's the difference between this and project/unproject ? |
@ibrierley what do you mean? |
Part of the essential code for leaflet/flutter_map is based on projections between screen and points, for example if you look at https://github.com/fleaflet/flutter_map/blob/master/lib/src/geo/crs/crs.dart and the crs project/unproject methods (line 407 & 418). |
Actually I've tried this code, but it didn't help me, so I didn't dive into that. Don't know what to say (Or maybe I didn't recognize something, so if I'm wrong, please point me) |
Just to expand a bit, to access those, I think normally you would access them via a plugin and use map.project(latLng). But you may be able to access them from wherever you are trying. (you may be able to access it direct though as well) |
One more question 😅 Does this library have a method to forcefully update tiles? Since I draw on them directly I need a method to mark tiles as "deprecated" or "dirty" or and invalidate them |
Unfortunately this is not yet possible, please see #667 for a PR with this feature added. |
Can we (as a hack) add a fake param to |
I'm not sure, I guess it might be possible? If you will try it, let me know if it works! :) |
Wanted to update my comment, but you've answered already, so I'll put it here: it didn't work :) |
Oh shame. Guess we'll have to 'protest' to merge that PR then! |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
This issue was closed because it has been stalled for 5 days with no activity. |
Hi, I need to modify a tile based on coords. For this purpose I need an access to canvas before display. Kind of a callback, which would be called right before tile is drawn:
Pseudocode:
For some reason, I can't use overlay and I need exactly the access to canvas to do all modifications there. Thanks for your help
The text was updated successfully, but these errors were encountered: