Hot answers tagged

6

There is a hasLayer method provided by Leaflet. It's a Boolean that returns true if already on the map. See: http://leafletjs.com/reference.html#map-haslayer


3

In general, yes, in theory, yes, in practice, yes with a bit of work. There's no general general solution because you can't know how the data is coming from the server. The solution involves looking at the underlying Javascript and seeing what it does. Chances are it will be an AJAX call to a server that returns a geoJSON data set, but it could literally be ...


3

You have a JSON but Leaflet really likes geoJSONs, so you should convert the JSON to geoJSON first, or directly load a geoJSON. So for your example, if you have: var data =[{ "latitud": 43.526523590087891, "longitud": -5.6150951385498047 }, { "latitud": 43.511680603027344, "longitud": -5.6671133041381836 }, . //More Lat-Lng Points . { "latitud": ...


2

This is perfectly explained in the Leaflet API reference for map options.


2

The Leaflet way: L.map('map', {attributionControl: false, etc...}) A simple $('.leaflet-control-attribution').hide() or non jQuery document.getElementsByClassName( 'leaflet-control-attribution' )[0].style.display = 'none';. Vladimir himself says it's OK to remove it: https://groups.google.com/d/msg/leaflet-js/fA6M7fbchOs/JTNVhqdc7JcJ, but it seems like ...


2

Use two nested loops: for (var i = minLat; i <= maxLat; i+=0.03) { for (var j = minLng; j <= maxLng; j+=0.03) { arr.push([i,j]); } } Also, with a fixed distance between each coordinate pair. keep in mind that the earth is not a flat surface, so a difference of 0.03 degrees of longitude is not the same over different latitudes.


2

As ghybs suggests in the comment above, you may find the LeafletSlider plugin useful. It has some idiosyncrasies that make it unsuitable for some uses, but if all you need to do is step through consecutive years, it should suit your purposes fine. If you pass it a L.layerGroup object with the layers you want to use, it will place a JQueryUI slider control on ...


2

The L.geoJson() constructor is actually just a convenient tool to convert GeoJSON data into Leaflet vector / path object(s) (like L.polyline, L.polygon, etc.). It also attaches the extra information that may be contained in the GeoJSON data into the created Leaflet objects (in layer.feature.properties for example). Therefore, if the GPS track that you ...


2

Instead of creating a convex hull over a set of points with the same attributes, create a Voronoi tesselation of all points, then merge the Voronoi polygons of those points with the same attributes. There are lots of ways to process the information you may have, and what I just said is one idea on how to do it. Voronoi + merge might create multipolygons, ...


2

You can work with layer.bringToFront(), bringToBack() or setZIndex() to reorder your layers. If you want one layer to always be below all others you can listen for the layer's add event and then bring it to the back (and bring the other to the front the same way): var C300mVar1 = new L.geoJson(C300mVar1, { onEachFeature: function(feature, layer) { ...


2

To change the vehicle type, you would use: control.getRouter().options.urlParameters.vehicle = 'foot'; However, the router does not automatically recalculate the route when you change the parameters, so to get the foot directions to show up, you will need to request it again: control.route();


2

All controls in Leaflet should inherit the removeFrom method, so to remove your existing layerscontrol, you can use: map.layerscontrol.removeFrom(map);


2

The GeoJSON is valid and renders fine, see http://playground-leaflet.rhcloud.com/kogi/edit?html,output. However, the use of jquery to fetch it is not. Make sure the request is returning JSON (hint: use dataType: 'json' in your jquery ajax call), and do not stringify the result Ion the contrary, run JSON.parse() if all you've got is a string). If you ...


2

You have most probably inverted the Lat and Lng values in either Leaflet or PostGIS. Let's have: Point1: Lat: -12.99835864475412 / Lng: -38.506194949150085 Point2: Lat: -12.999215865191118 / Lng: -38.50590527057648 Point3: Lat: -38.506194949150085 / Lng: -12.99835864475412 (inverted from Point1) Point4: Lat: -38.50590527057648 / Lng: -12.999215865191118 ...


2

The reason the Haversine equation is used for the 4326 calculation is that this is a geographic coordinate system. That means that the coordinates are still on a sphere, they are not mathematically transformed to a flat surface. A projected coordinate system would have this equation or some similar construct already "built-in", so to speak. The Web Mercator ...


2

As an alternative to @Joran's approach, you can skip GeoJSON completely and just iterate through the points, creating instances of L.LatLng and L.Marker as you go, like: var points = [{ "latitud": 43.526523590087891, "longitud": -5.6150951385498047 }, { "latitud": 43.511680603027344, "longitud": -5.6671133041381836 }, ...


1

I would complete (although it can still be known how data come from the server) Spacedman's answer by saying that reverse-engineering the AJAX call to retrieve data with the finest granularity (at the level of each point) would give nothing but an important coding/development stage to accomplish first. Indeed, data aggregation (averaging and so on) is ...


1

A1: You're receiving an instance of L.LatLng. If you want those coordinates as an array, then just: var arr = [ latlng.lng, latlng.lat ]; Need an array containing just one element, which is an array of the two coordinates? Easy: var arr = [[ latlng.lng, latlng.lat ]]; A2: That indeed fires onLocationFound as fast as the browser's geolocation logic ...


1

No. Leaflet does not implement fancy reprojection. You will have better luck if you manually reproject your data from EPSG:4326 into EPSG:3857, and then use the EPSG:3857 coordinates into a Leaflet map with CRS.Simple. My tool of choice for reprojections is ogr2ogr, although you can do it in javascript only by using proj4js.


1

What kind of arrows do you want to display? I have just created a Leaflet plugin which shows the direction and the speed of wind. So if per chance you would like to show wind data, you can use my plugin: https://github.com/JoranBeaufort/Leaflet.windbarb Otherwise there is the marker rotate plugin: ...


1

See https://github.com/bbecquet/Leaflet.RotatedMarker. Alternatively, use a L.DivIcon and apply CSS transforms to its contents.


1

wheelPxPerZoomLevel: 150 is the option that it seems to be affecting the mouse wheel zoom "speed". // @option wheelPxPerZoomLevel: Number = 50 // How many scroll pixels (as reported by [L.DomEvent.getWheelDelta](#domevent-getwheeldelta)) // mean a change of one full zoom level. Smaller values will make wheel-zooming // faster (and vice versa). ...


1

WMS cannot handle properties of the features displayed in a bbox (it can only fetch properties of a feature given a point, read the docs for WMS's getFeatureInfo). What you might want to do is using a different approach, like doing a WFS request to geoserver, which will return the geometries and properties of all features inside a bounding box.


1

The legend does not depend on the existence of any particular layer. The part that you are missing here is a getColor function. Copying the one from the tutorial in question: function getColor(d) { return d > 1000 ? '#800026' : d > 500 ? '#BD0026' : d > 200 ? '#E31A1C' : d > 100 ? '#FC4E2A' : d ...


1

According to the answer here, Leaflet doesn't "remember" what and whether a layer was filtered, so you need to reinitialise the layer when your filter changes. Something like this... You'll need to store your data somewhere, and you'll need to call the function from your init function with the default value. (BTW if you're going to have more than two ...


1

Scale dependent rules need to be applied via min/max scale denominators. https://github.com/mapnik/mapnik/wiki/MinScaleDenominator Converting mapnik scales to map scales requires a conversion. The table below is a good start http://wiki.openstreetmap.org/wiki/MinScaleDenominator My example ended up working with something like below <Rule> ...


1

The answer to my own question is that the local firewall settings prevented me from downloading the tiles from OSM. The way how to solve it was to set proxy (from within R > link). The con of this solution is that the viewer still doesn`t deliver tiles as the proxy settings at the moment do not apply to RStudio Viewer. Although, the leaflet output appears ...


1

Yes, you can use layer.bringToFront() and layer.bringToBack() methods of leaflet. See the docs here.


1

While it isn't baked into leaflet, there is: https://github.com/robertleeplummerjr/Leaflet.glify which is based off of http://bl.ocks.org/Sumbera/c6fed35c377a46ff74c3 The demo loads 86,000 points and all the polygons behind them in about 0.06 seconds. If you position the map away from the the points and then pull them back into view you'll see what I mean. ...


1

I know this question is really old now, but if anyone get the same problem as he got, maybe this could be helpful ! Your piece of code seems to be good in theory. As I used arcGIS/Leaflet in exactly the same way. But yea, problem could come from missing spatial reference (or maybe incorrect format (image/png or image/jpeg). For the spatial reference, here ...



Only top voted, non community-wiki answers of a minimum length are eligible