Does leaflet provide a method for determining which, if any, rendered point is within a polygon? Not by iterating over a bunch of shapes and checking bounds, but by using an rtree index, perhaps?
See the Leaflet plugins page, on which you'll find leaflet point-in-polygon and Leaflet.LayerIndex.
Related
Is there a way to render overlapping polygons without holes in multipolygon in Leaflet?
I found Leaflet has an open issue.
codesandbox.io
I am asking because I have a bound polygon that contains inner polygons.
I would need to drag them all together, but it doesn't work in canvas mode. It could work if I can render this as a multipolygon. This is a follow-up question on my previous question.
I'll just copy-paste my response to Leaflet bug #6173 :
I'm reading the OGC's Simple Feature Access specification (again), to remind myself about the formal definitions of Polygons and MultiPolygons. Let me quote page 31:
6.1.14 MultiPolygon
A MultiPolygon is a MultiSurface whose elements are Polygons.
The assertions for MultiPolygons are as follows.
a) The interiors of 2 Polygons that are elements of a MultiPolygon may not intersect.
Heck, it even comes with pretty pictures:
So, MultiPolygons which have overlapping members are not valid MultiPolygons. As such, I think Leaflet has no obligation to handle that invalid case.
See also #3763 (comment) (re: fillRule option for SVG renderer).
I am using React-Leaflet to display a Leaflet.js map. I use React-Leaflet GeoJSON (source here) to show a layer of polygons on the map.
Although I can vary the opacity of the fill (fillOpacity) of the polygon, I cannot find an option to fill the polygon with a pattern (e.g. checkers, stripes, etc.)
I have found a project (Leaflet.pattern) that supports adding fill patterns to Leaflet.js shapes, but it has not been adapted for use with React-Leaflet.
So my question is: How can I add patterns to React-Leaflet shapes, or adapt Leaflet.pattern for use with React-Leaflet? (for the latter, instructions on how to create custom React-Leaflet components are here, but I don't know how to do it for this case - it seems more complex than usual)
Take a look at the section in the docs about extending react-leaflet
If you are using react-leaflet v1 you can directly extend react-leaflet's GeoJSON class. If you are using v2 you'll need to extend the Path class instead. To understand why that's necessary take a look at this issue.
Once you've figured out which class to extend it's likely that most of your changes will need to happen in the createLeafletElementfunction and maybe the updateLeafletElement function.
Is it possible to apply fill-extrusion for a GeoJSON LineString feature?
Basically I'm looking for a way to draw lines (can be 1 line or multiple connected) in a 3d mode with z-offset.
If that's not possible, maybe this can be done with a polygon instead?
Like, converting my lines to polygons (how can i do that?)
What you're asking for isn't yet implemented, but ticketed in Mapbox GL JS at https://github.com/mapbox/mapbox-gl-js/issues/3993.
For now you'll need to opt for your second suggestion of converting the LineString feature to a Polygon. You can do this with turf's buffer function http://turfjs.org/docs#buffer.
The whole line/polygon will be offset at the same height, so depending on your application you could use turf's linkChunk http://turfjs.org/docs#lineChunk to get it broken up into smaller features which you assign different height properties to.
Is there a way to draw a vector layer with CorelDraw for example and place it on napboxgl and use it as geojson layers?
For example https://seatgeek.com/colorado-rapids-at-seattle-sounders-fc-tickets/mls/2017-10-22-1-pm/3700786
Are they using geojson or etc.? Or just some sort of vector format?
I can't use geojson as it is hard to draw with QGIS any straight lines or symmetrical objects. I just want to draw a lot of vector objects and use them as layers with mapboxGL(use mapbox as render method and interact with layers as with geojson)
Any suggestions how to do it? Or is there a way to draw with Corel and then place it on map with QGIS?
Thanks
UPD:
Now I am using Corel -> dxf export and then import it to QGIS, then save it as geojson. But have some glitches with displaying that geojson geometry in mapbox, so I have to draw another in QGIS over the imported(dxf) one.
Here is an example of the bug, should be just a green polygon like the gray one
UPDATE: my fault, I was using lines instead of polygons.
I think you can achieve this as follows:
Convert the Corel output to SVG
Create an HTML element containing the SVG (not necessarily added to DOM)
On your Mapbox map, add a Canvas source containing the canvas: see https://www.mapbox.com/mapbox-gl-js/api/#canvassource
Obviously you will need to determine the lat/lon of the corners of your image somehow.
I would like leaflet to connect points in polyline in the same order as they were passed into constructor (L.polyline(route, routeOptions).addTo(map) where route is an array of points), but it seems to me that polyline does not care about order at all. Any suggestions would be highly appreciated.
What makes you think that Leaflet polyline does not care at all about the order in the array of points (coordinates)?
L.polyline(arrayOfLatLngs) should draw a segmented line passing by all the specified coordinates in arrayOfLatLngs, in the order they are set in the array.
Demo: http://jsfiddle.net/ve2huzxw/91/
If it does not behave that way for you, please provide your code and if possible reproduce your issue online (e.g. on jsfiddle) so that people can investigate.