I have a MKMapView with several annotations. These annotations differ from varios location all over Sweden. What I want to do is to zoom the map so all annotations show.
I do not want to position the map to my position (although I do want to show it), but want all annotations to show and center the map according those locations.
I.e. if one annotation would be "kiruna" (upper left sweden) and the otherone would be "stockholm" (middle right sweden), I want the map to show both. If the map would only show "uppsala" (above stockholm) and "stockholm", I want the map zo zoom that "uppsala" is in the top left and "stockholm" bottom middle/right.
How can I do this? I have the lat/lon positions ofcouce for every location.
Regards,
Paul Peelen
Dupe with plenty of material to solve your problem: Positioning MKMapView to show multiple annotations at once
Related
I'm trying to show a custom non-geographical map with CRS.simple as explained here:
In a CRS.Simple, one horizontal map unit is mapped to one horizontal
pixel, and idem with vertical
However, I wish to use an SVG vector image as an overlay, but I don't get how the map unit is decided in this case, since the vector images don't really have a resolution?
Also, how could set the CRS origin's location to a specific point?
Thanks for helping
I am working on a project using Leaflet. I want to place a label for objects on the map. I don’t want the label to appear on the map. I want the label placed above the map, but at the screen or div Left location from a latLng point.
I can’t seem to get the correct position using the functions available. Is there some example I can look at to give me insight? I would think Leaflet could do this.
The key here is to leverage the latLngToContainerPoint() method of L.Map - it will give you the pixel coordinates relative to the map container of the L.LatLng passed.
So create a container for a tick...
<div id="topbar"><span id="toptick">↓</span></div>
<div id="leaflet"></div>
...and use CSS to ensure it's on top of the map container, and has the same width. Then, run a function to translate the map point you want into an offset relative to the top-left corner of the map container...
function repositionEdges(){
var offset = map.latLngToContainerPoint(geopoint);
}
...run that after map initialization, and after every movement of the map...
repositionEdges();
map.on('move zoom', repositionEdges);
...and finally, inside that function, shift the tick horizontally tweaking its style...
function repositionEdges(){
var offset = map.latLngToContainerPoint(geopoint);
document.getElementById('toptick').style.left = offset.x + 'px';
}
You can see a working example at https://next.plnkr.co/edit/60qrWND50mCOQ11T?preview .
This is just one approach. The specific implementation will be different if you're using more than one point, or if you want to use <canvas> for drawing the ticks.
See also the graticule, edge scale bar and edge markers plugins from the Leaflet plugins list. Those plugins contain implementations of similar concepts.
I need icons (PNG) and polygons on my map. So I create icons as markers and polygons as polygons. Unfortunately regardless of creation order polygons are displayed "below" markers. I need is vice-versa. Is there a way, how to do it?
EDIT:
Correct default panes order in Leaflet 0.x: (from top-most to bottom-most)
objectsPane
popupPane
markerPane <= all markers icon (other than L.CircleMarker)
shadowPane <= all markers icon shadow
overlayPane <= all vectors (including L.CircleMarker)
tilePane
So just using the marker's icon shadow is not enough. You have to manually change the z-index of those panes in CSS (or through JS).
See also Leaflet: Polyline above Marker.
Original answer:
The stack order of vectors (like your polygons) and Markers is fixed in Leaflet 0.x. They are inserted into "panes" which order is (from top-most to bottom-most):
popupPane
markerPane <= all markers icon (other than L.CircleMarker)
overlayPane <= all vectors (including L.CircleMarker)
shadowPane <= all markers icon shadow
tilePane
So you should be able to easily workaround this fixed order by using the Marker's Icon shadow. If you still want the user to be able to click on your marker, simply use a transparent image for the normal icon, with the same size as your shadow image.
The situation is different in Leaflet 1.0. You can create your own panes (map.createPane), set their order by specifying their zIndex (possibly through CSS), and specify where your vectors and markers go by using their pane (and shadowPane for markers) option(s).
I'd like to colorize russian map with leaflet.But there is a problem with a region (Chukotka Autonomous Okrug), that is placed on the "bend" line of the map. Part of the region appears on the other part of the map (here's a link to the picture http://i.stack.imgur.com/cQSlG.png). I've already tried to use noWrap option, but it didn't help. Any help will be highly appreciated!
That happens when you cross the international dataline. What you want can be done but you've got to edit your geometries. In your case you would need to add 360 to every coordinate you encounter that's left of the prime meridian, thus every negative longitude. Mapbox has a nice example on the matter:
https://www.mapbox.com/mapbox.js/example/v1.0.0/cross-date-line/
I'm using leaflet for show raw itinerary to go to some markers.
I'm showing my itinerary with a leaflet polyline.
But I would like to be able to
How to hide and show a polyline in leaflet ?
I can do this :
$('.leaflet-overlay-pane').hide();
and
$('.leaflet-overlay-pane').show();
But this will show and hide all my polyline.
I would like to be able to hide and show them separately.
Thanks.
If you have a reference to the polyline
var polyline = L.polyline(...);
Then you can use
map.addLayer(polyline);//For show
map.removeLayer(polyline);// For hide
at the moment I think there is no native method to only hide/show, maybe in the 0.7 version
Other solution is to access to the object container, in a old commet from the maintainer
I don't think there's an easy solution, for tile layers at least. :( I'll try to handle this sooner.
For vectors, you can change path._container.style.display, and for markers - marker._image.style.display and marker._shadow.style.display.
Removing and adding objects on the map will also change the order of the layers (if you have more than one in your legend). The added objects will always be on top and not in the original order. I use setLatLng (markers) and setLatLngs (polylines and polygons) to do a quick trick without changing the order. Just change the latLngs to e.g.(1000,1000) outside your view.
var myLatLng0 = L.latLng(1000,1000);
var myObject = L.marker(myLatLng,{....});
myObject.latlng = myLatLng;
or
var myObject = L.polygon(myPath,{....});
myObject.path = myPath;
Hide / Show marker:
myObject.setLatLng(myLatLng0);
myObject.setLatLng(myObject.latlng);
Hide / Show polyline or polygon:
myObject.setLatLngs(myLatLng0);
myObject.setLatLngs(myObject.path);
Note: hiding polylines and polygons will also work with setLatLngs(false). setLatLng(false) for markers will give an error.