How to centralize and change the center of the leaflet map dynamically - leaflet

I have a map that covers the entire screen and I have a layer that overlays the map. That layer goes from bottom to top.
the user interacts with this layer by clicking on different options and these options draw markers on the map.
When I centralize the map, the markers are hidden behind the layer that superimposes the map, thus eliminating the visibility of the marker.
How could I centralize the map and then move it one third above the layer?
This question is a remake of
How can I change the location center of a map using Leaflet API?
Try doing it this way
var offset = map.getSize().y * 0.15;
map.panBy(new L.Point(0, -offset), {animate: false});
But every time I click on an option in the layer to create a marker, the map moves and I lose the center.
jsfiddle
Excuse the example image
The idea is that after the map makes the setView place its center above the blue layer that superimposes the map so as not to hide the markers.

Related

Style / Satellite - Is it possible to have Two different aesthetics on different zoom levels?

I am using mapbox to develop a map for a project, the map is being programmed with a global zoom out view and markers that allow you to click and zoom into the area (unclick and zoom out), basically it toggles between two views or zoom distances.
I want the close up view to be the satellite imagery. But the satellite imagery is confusing on the global view - and it would be better to move from a Mapbox style (dark / light) then when you click on a pointer you zoom into the satellite imagery.
Do let me know if this functionality exists and if possible pointers on how to implent?
Thanks!
B
It is possible to listen for zoom change. Once the zoom event has finished, the zoomEnd callback will be triggered.
In this callback you can get the zoom using the getZoom() method. Depending on your zoom level you can set your style. (e.g. Satellite or non-satellite)
// Initialize the map
var map = new mapboxgl.Map({ // map options });
// Set an event listener that fires
// just after a zoom transition finishes.
map.on('zoomend', function() {
var zoom = map.getZoom();
if(zoom < 10){
map.setStyle("mapbox://styles/mapbox/streets-v11");
}
});
You can construct your style in Mapbox Studio as a non-satellite style, but then add Mapbox Satellite as a layer with min zoom set such that it only shows up once zoomed in.

Mapbox gl repeat marker

I try to repeat a marker at the same coordinates when I am moving the map to infinity, in the same way that layers.
example : https://www.mapbox.com/mapbox-gl-js/example/geojson-polygon/
Has anyone found how to do that please?
If it's not possible, conversely is it possible to not repeat layers when you moving the map ?
Thank you
The Link example you provided is not using Markers to render the shaded area. It is using a feature, in this case a polygon, included in a layer (a layer can have many features).
In MapBox the rendered map is made up of any number of layers (including the tile data) which is rendered whenever you scroll or drag to a particular area of the map. For example as you keep dragging to the right in the map it will just keep rendering in the relevant layers and tiles.
The Marker functionality has a different purpose which is as a one off selected point which is useful for a user click or hover interaction.

Mapbox GL JS: Set Map Center or Bounds to show visible part of a layer

I have a layer with 7000+ polygons and am displaying a portion of the polygons in a web app using "setFilter" on map load. (The filter is choosing the polygons to display dynamically based on data from the url of the current page.)
However, I can't figure out how to make the map center on the particular polygons currently showing (the visible part of that layer), which means the user has to hunt around to find it. There can be multiple polygons visible at one time, and they are a range of different sizes. Any ideas?
If you have the feature collection of polygons that are visible on your map, you can use the turf-extent module to get the geographical extent of the visible polygons, and then call map.fitBounds(extent) to make all visible polygons within the viewport.

how to prevent wrapping of world map in mapbox?

I am using mapbox and featureGroup control.
World map is repeating horizontally.How can I prevent horizontal repeating of world map.
I have tried 'no-wrap:true' ,but this seems to work only for tile layer.
For featureGroup,Please suggest some way.
var map = L.mapbox.map(mapData, MapBoxAccess.mapBoxAccess.accessId);
var featureGroup = L.featureGroup().addTo($scope.map);
I am adding my polygons and polylines on featureGroup
Please find attached image for better understanding.
That actually is the intended behavior and features cannot repeat across the globe like this. If you wanted to prevent scrolling across the globe, you can set bounds over the map so that someone can't scroll or pan side to side. Also, there is a Leaflet method called WorldCopyJump which will also bounce the view back to the bounds.

How show circle around annotation how in google maps

I use MKMapView.
How to show circle around annotation how in google maps ( when show current user location).
This circle moving with animation to new location and radius of circle dependent from current zoom level.
The annotations themselves don't have a property for showing a circle but you can use a circle overlay with the same center as the coordinate of the annotation to achieve this effect, just like the image below (from one of my projects).
Note: the property for the center of the circle is called "coordinate", just as for the annotations.
The second part is animating the movement. You achieve this by animating the coordinate property of the circle overlay at the same time as the coordinate property of the annotation. This way they will both move together to the new location.
This question can help you with how to move and animate the position of an annotation. If you need the radius of the circle to change at the same time (e.g. when animating the coordinate) you just use Core Animation to animate it together with the coordinate.
Concerning changing the size depending on the zoom level, Map Kit will always handle this for you automatically with Overlays and Annotations so that they always cover the same area of the map, even as the map resizes. (The second image is the same annotations and overlays as below, just zoomed in on the ones to the left (closer to Stockholm in the first image)).