I cannot get the fitBounds command to work on a project where I am bringing in data to a featureLayer using GeoJSON.
This:
map.fitBounds(pointsFeatureGroup.getBounds()); // Uncaught Error: Bounds are not valid. at e.fitBounds (leaflet.js:5)
and this:
var bounds = L.latLngBounds(pointsFeatureGroup); // Uncaught Error: Bounds are not valid. at e.fitBounds
map.fitBounds(bounds);
don't work
My simplified code is here:
https://github.com/DPB61/leafletjs_problem2
If I just bring in markers individually into a normal Layer then a command like this works:
map.fitBounds(PointsLayer.getBounds());
but that raises other issues with other functionality for which a features layer is required.
Am I doing something wrong?
The root cause is a classic asynchronous issue.
See How do I return the response from an asynchronous call?
At the time you call map.fitBounds(vesselsFeatureGroup.getBounds()), the vesselsFeatureGroup is still empty (no child layer), therefore Leaflet cannot compute bounds.
Simply call the getBounds and fitBounds within the callback of your asynchronous task ($.getJSON)
Related
Using the mapboxNavigation requestRoutes with the following options code. Getting a Failure callback complaining No suitable edges near location. The same points array used in Postman calling the Direction API returns successfully.
RouteOptions.Builder builder=RouteOptions.builder();
builder
.accessToken(getString(R.string.mapbox_access_token))
.profile(RouteUrl.PROFILE_DRIVING)
.language("en")
.user("mapbox")
.requestUuid(""+UUID.randomUUID())
.alternatives(true)
.geometries("geojson")
.steps(true)
.baseUrl("https://api.mapbox.com/directions/v5/mapbox/")
.coordinates(ptsList);
The problem is fixed after couple changes ...
The baseUrl for RouteOptions request is https://api.mapbox.com/
Commented out the call of geometries().
The following code successful the call of route request...
RouteOptions.Builder builder = RouteOptions.builder();
builder
.accessToken(getString(R.string.mapbox_access_token))
.profile(DirectionsCriteria.PROFILE_DRIVING)
.language("en")
.user("mapbox")
.requestUuid(""+ UUID.randomUUID())
.alternatives(true)
// .geometries(DirectionsCriteria.GEOMETRY_POLYLINE)
.steps(true)
.baseUrl("https://api.mapbox.com/")
.coordinates(ptsList);
I am using this plugin : https://github.com/perliedman/leaflet-routing-machine.
My code looks like this:
for(let i=0; i<markers.length; i++){
points.push(L.latLng(markers[i].latitude, markers[i].longitude))
}
this.routingControl = L.Routing.control({
waypoints: points
}).addTo(this.map);
When I pass points filled with different latitude/longitude, it draws the route fine. But let's imagine the following scenario. let's say that points array contains 3 items. each item contains latitude/longitude and let's say that those latitude/longitude are the same. So something like this:
34.72581233927868 -80.71105957031251
34.72581233927868 -80.71105957031251
34.72581233927868 -80.71105957031251
Now what Routing control does is as it can't draw the route, it automatically zooms in in the maximum way and in the console, it shows the errors. {"message":"Zoom level must be between 0-20."}
Workaround 1: after drawing routes, i decided to use settimeout after 1 second and there I zoom at 11 by myseslf. this way it zooms out, but in the console, errors still stay. How do I fix this?
If you know your input can be invalid, then the cleanest way would be to filter it on the way in to remove duplicates. If that's not possible for some reason and you want to let LRM determine if there's an error, then you can catch the error event with:
L.Routing.control({
...
})
.addTo(this.map)
.on('routingerror', function(e) {
// do your error action here - e.g. zoom out
})
For more information on handling errors in LRM, see https://www.liedman.net/leaflet-routing-machine/api/#eventobjects
I have a SAPUI5 application and when I press on items to visit the detail or object page it shows the following error message in the following part of the code
It is not supported to change the behavior at runtime.
showObject: function(oItem) {
var sObjectId = oItem.getBindingContext().getProperty("Partner");
this.getRouter().navTo("object", {
objectId: encodeURIComponent(sObjectId)
}, false);
},
Are you sure that's where you're getting it? I've only seen that error when working with certain controls the UploadCollection and trying to fire a method like oUploadCollection.setUploadUrl("/url") which is not supported at runtime.
Without setting a property and given the code above, the error doesn't make sense.
*A side note: without seeing where your showObject method is called, it's hard to say... but if showObject is called directly off the press event of the ListItem you need to call getSource() on the event object. Might be throwing an error there about getBindingContext() not being a function.
I am using MapQuest map with leaflet. The routes are being injected dynamically. When we add routes to the map, it takes time to finish the rendering.
I want to block the screen while the map is being rendered.
Is there any way(mapquest API or leaflet event) to know the map is ready or finished rendering so that I can stop the blocking of the screen.
I'm using Leaflet to add the routes. Something like this:
function (locations) {
const dir = MQ.routing.directions();
dir.route({ locations: locations });
comp.mqroute = MQ.routing.routeLayer({
directions: dir,
fitBounds: true,
draggable: false,
});
comp.map.addLayer(comp.mqroute);
}
This is a case of RTFM.
The fact that you're using MQ.routing.directions in your code tells me that you're using the Mapquest routing plugin for Leaflet, which has complete API documentation.
By reading that API documentation, one can notice a success event, I quote:
success
Fired when route data has been retrieved from the server and shapePoints have been decompressed. [...]
I have a heavy suspicion that you don't need to know when the route is rendered (meaning: when the lines have been displayed on the screen) but rather when then network requests for the route are finished (which is what takes most time). The time to actually render lines on the screen is usually negligible unless one is working with thousands of segments (after the automatic douglas-peucker simplification).
I also have a heavy suspicion that this is a XY problem, and that the root problem you're trying to solve is race conditions when the user is (re-)requesting routes too fast, to which the solution is just throttling the requests rather than blocking the UI.
How to use this success event is illustrated in MapQuest's Route Narrative example:
dir = MQ.routing.directions();
dir.on('success', function(data) {
// ...
// the code here will run once the route is ready
// ...
}
I want to perform click and scroll down action on a element .
* Already i tried with Action class
* javascript executor.
* Robot class
First I am trying to click on element and hold it for a while and then scroll till expected element finds but I am getting error as method has not yet been implemented.
WebDriverException: Method has not yet been implemented (WARNING: The server did not provide any stacktrace information)
1.The above error comes when your app is not matching with the current context
2.According to your code there is a need of context change of app environment you can change context using driver.context("YOUR APP CONTEXT NAME")
3.Some times there must be error in your code like it is not locating correct element or may be you are using unwanted method
Try above 2 points it might help you
if it is not working sorry for wasting your Testing time
Happy Testing