How can i clear map without using leaflet layer?
Get your map, and then call:
map.removeLayer(yourGeoJSON);
as yourGeoJSON is the variable name for the geoJSON you want to remove. I usually keep track of what I add in an array.
Related
I need to perform automated actions on individual markers on my map, but based on all the answers I'm finding online I will first need to store references to my markers in my script. However, I am not creating the markers explicitly. Instead it seems the markers are being generated when I load a collection of points from geojson using the map.addSource() and map.addLayer() methods.
For an MCVE see here.
How can I get references to the generated markers using this method?
You are confusing Markers (HTML elements that sit above the map) with a symbol layer (graphical elements that exist within the map). Symbol layers don't generate markers, and there are no "references" to get.
Say I add a Control.Layers object on a map like this:
L.control.layers(baseLayers, overlays).addTo(someMap)
When I am later given the someMap object what is the proper way to obtain the layer control from it? E.g. I was hoping something like:
let controls = someMap.getControls();
... where I would then presumably be able to iterate and use the typeof operator to find the control I am interested in.
The closest I have found in answering the question is this SO answer which suggests extending the L.Control class and overriding onAdd in order to store a custom property on the map object. I find it hard to be believe it needs to be so convoluted as that. Plus, even if that approach was taken, how I am supposed to know that my overridden onAdd method does everything that the implementation in the original Layers Control.Layers does?
The way it is implemented, adding a control to a map just leaves the control object with reference to the map object.
This means that the map object is unaware of the controls it has created (EDIT I should say: controls that were added to the map)
I guess there was no need for that. If you have a use case that shows this is a problem, you should open an issue.
So, I'm afraid the answer you already have is the right one.
I want to restyle every feature on a vectorgrid. The specific problem is when you select a section of a bus route, potentially by just a mouse-over, i want to light up all the sections which contain common routes. I have a style callback function. How do I tell Leaflet that I have changed the rules on what colours to use etc.
I'm writing MapBox vector tiles using geotrellis vectorpipe.
see here for the basic flow: https://geotrellis.github.io/vectorpipe/usage.html
Typically GeoJson Features can have an id field, so that Features can be rolled up into FeatureCollections. I need to make use of this field, but vectorpipe doesn't (natively) have this capability.
This is the Feature type used, and you can see it only has space for 1) a Geometry and 2) a data object D (which ends up populating properties in the output). There is no spot for an id.
https://geotrellis.github.io/scaladocs/latest/index.html#geotrellis.vector.Feature
Upstream there's a method called writeFeatureJsonWithID() that does let you inject an id field into a Feature when writing GeoJson.
https://github.com/locationtech/geotrellis/blob/master/vector/src/main/scala/geotrellis/vector/io/json/FeatureFormats.scala#L41-L49
My question is this:
I have worked through the vectorpipe code (https://github.com/geotrellis/vectorpipe), and I can't figure out if/where the data ever exists as GeoJson in a way where I can override and inject the id, maybe using the writeFeatureJsonWithID() or something I write explicitly. A lot of conversions are implicit, but it also may never explicitly sit as json.
Any ideas for how to get an id field in the final GeoJson written to vector tiles?
EDIT
Right now I think the trick is going to be finding a way to override .unfeature() method here:
https://github.com/locationtech/geotrellis/blob/master/vectortile/src/main/scala/geotrellis/vectortile/Layer.scala
The problem is that the internal.vector_tile.Tile is private, so I can construct it without forking the project.
Ended up having to fork geotrellis, hard-code a metadata => id function in Layer.unfeature() and compile locally to include in my project. Not ideal, but it works fine.
Also opened an issue here: https://github.com/locationtech/geotrellis/issues/2884
With the Bing v7 AJAX control, if it contains several polygons/polylines, and I want to remove all of them at once, how do I go about doing this? I suppose I can loop through the map.Entities collection and inspect each to see if it is a poly* object, but I was wondering if there is an easier way?
When there's a need to handle a group of elements easily I usually place them on an EntityCollection. Then, you can just hide/remove that layer.
Check out this example. It hides the entities instead of removing them, but the principle is the same.