Is it possible to display mapbox coordinates inside a dynamic url? - reactjs

I'm working on a mapbox app and I need to make a dynamic URL to reflect mapbox info like lat, long and zoom level.
ex: /?city=London&zoom=1&lat=30&lng=140. On page load map should be centred and zoomed accordingly. How to read/write page URL?

Just activate the hash : true in the Map initial settings
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/outdoors-v11',
center: [128, 47],
zoom: 16.5,
pitch: 60,
hash: true // just add this
});
It’s not the same param names but you’ll have the same information

Related

Extract/save the waypoint/coordinates from a MapBox MapboxDirections in react

I have added MapboxDirections control to by map using the normal method, which is working.
map.current = new mapboxgl.Map({
container: mapContainer.current,
style: 'mapbox://styles/mapbox/outdoors-v11',
center: [lng, lat],
zoom: zoom
});
directions.current = new MapboxDirections({
accessToken: mapboxgl.accessToken,
unit: 'metric',
profile: 'mapbox/cycling'
});
map.current.addControl(directions.current, 'top-left');
I want to add a SAVE button allowing me to get all the waypoints/coordinates of the route (that I can see on the map) but I cannot find a way to extract the coordinates out of the mapboxgl.Map or MapboxDirections object. I want to be able to save/download the results to a file.
Any ideas?

MapBox direction with more than 25 waypoints in react

I am integrating MapBox Direction API in react. I have more than 25 waypoints (around 500). How do I use all using "mapbox-gl-directions". Because, I can't send not more than 25 wp. So, how can I send multiple request with 25 wp each time 25. How?
Below is my sample code:
componentDidMount() {
let directions = new MapboxDirections({
accessToken: mapboxgl.accessToken,
unit: 'metric',
profile: 'mapbox/driving',
interactive: false,
controls: false
});
this.map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [3.1026, 36.6686],
//center: [this.state.lng, this.state.lat],
zoom: 10
});
this.map.on('load', function() {
directions.setOrigin([-117.1425, 32.63638889]);
directions.addWaypoint(0, [-117.1425, 32.63638889]);
directions.addWaypoint(1, [-117.195, 32.75416667]);
---
---
directions.addWaypoint(23, [-116.5012667, 32.92583333]);
directions.setDestination([-116.5616667, 32.93583333]);
})
this.map.addControl(directions, 'top-left');
}```
Any suggestion? Thanks in advance.
You could break the waypoints up into 25 waypoints chunks and request directions from the Directions API before loading the map. Then you could join the response route JSON objects to one route object, which you can then use in the same way as the single route object in terms of drawing it on the map.

How to use the new Grayscale maps

The Azure maps blog states Grayscale maps: A dark-gray map style is for users who want to have a darker scale representation of a map.
How can you enable this in the Javascript implementation?
see the code sample at https://codepen.io/azuremaps/pen/WKOQRq. We will have
documentation up soon.
style: "grayscale_dark"
You can set style: "grayscale_dark" when you define the map.
var map = new atlas.Map("map", {
center: mapCenterPosition,
zoom: 15,
style: "grayscale_dark"
});
You can also just create a control on the map that allows you to switch between different modes:
map.addControl(new atlas.control.StyleControl(), { position: "top-right" });

Why panning google map updates angularjs scope var?

Kind of an odd question/hard to find an answer. I'm relatively new to using angularjs and have a problem i'm confused about.
I've set up a google map using http://angular-ui.github.io/angular-google-maps/#!/ and have an issue.
So i have a $scope.homeBase where i am setting a lat & long for the owners 'Home Base', i want to use that location to set the on load map center, & a pin to show the location. So in my mind cool, set the one var and use it in both locations. Wrong.
So this works on load, but every time i pan the map, i guess it re-sets the map center location, which in turn binds to the map marker and sends the marker to the middle of the screen, on every pan.
Is there anyway to have the two not bound? or have separate vars? without them bound?
i thought a simple 'var homebase' would remove binding and not update the var. instead of using scope but it still binds?
This perhaps is a newb question but i appreciate any pointing in proper direction.
Thanks again
here's my code.
// uiGmapGoogleMapApi is a promise, The "then" callback function provides a maps object.
uiGmapGoogleMapApi.then(function() {
// Setting homebase coords, these will come from firebase
$scope.homeBase = { latitude: -34.18405, longitude: 150.71319 };
// Set default map.
$scope.map = {
center: $scope.homeBase,
pan: true,
zoom: 14,
events: {
click: function(){
}
}
};
// Set homebase marker.
$scope.homebaseMarker = {
id: 0,
coords: $scope.homeBase,
options: { draggable: false },
};
});
I was able to set the center on page load via
angular.copy(var)

3D map visualization in Angular Google Maps

Preamble
I'm using Angular Google Maps to indicate the location of different buildings across a campus. My initilization goes as follows:
$scope.map = {
control: {},
center:
{
latitude: $scope.Item.Latitude,
longitude: $scope.Item.Longitude
},
zoom: 16,
options: {
streetViewControl: true,
maxZoom: 20,
minZoom: 8,
mapTypeId: google.maps.MapTypeId.HYBRID
},
showTraffic: true,
showBicycling: true,
events: {
blacklist: ['drag', 'dragend', 'dragstart', 'center_changed']
}
};
That works flawlessly for the following visualization:
However, I just noticed that there is 3D data available for the region, and I would like to have it renderized as such:
Question
Is it possible, via Angular Google Maps, to configure my initialization in such a way as to show the map as indicated?
Bonus Question
...would it be possible to programatically have the 'camera' spin around the marker (or the center)?
This is the Map link for the reference images:
https://www.google.com/maps/#40.9570608,-76.8816097,179a,20y,180h,41.69t/data=!3m1!1e3
The best you can get with the Google Maps Javascript API is the 45° imagery.
Not like the 3D map visualization, 45° imagery only has:
1) the 45° tile...
2) 4 angels (0, 90, 180, 270)
3) only has SATELLITE mode. (Road names and other maps elements isn't shown even the maps is in HYBRID)
4) it is not available everywhere over the globe. (for example, 40.9570608,-76.8816097)
Look at this example for more information.
http://jsfiddle.net/u1qcf892/

Resources