I am trying to add an overlay to iOS MapKit in order to show floor plans. However, I am unsure about the best way of doing this. If I add the floor plans by using an MKOverlay, will the floor plans be loaded lazily or do I need to find out which part of the map is being displayed and update overlays thereafter? I also looked at using MKTileOverlay, as it is using lazy loading, but I have the impression that it should be used for completely covering of the map and not only to add to the existing one. Is this correct?
Yes, you are right MKTileOverlay can cover whole map with tiles and Yes it is using lazy loading.
Use MKOverlay if you are not willing to replace native look and fill of map. You can also achieve lazy loading for MKOverlay too.
Note: MKTileOverlay will not remove your already existing MKAnnotations and MKOverlay.
MKOverlay is a protocol, not a class. You want MKTileOverlay as of iOS 7. Things are lazy loaded according to what portion of the map is currently shown.
You might find this useful as a reference on how the tiles are numbered and organized:
https://www.mapbox.com/foundations/how-web-maps-work/
As for covering Apple's map, this will happen by default, but you can also adjust the MKOverlayLevel used to place it between Apple's base map and labels layer, or you can use canReplaceMapContent = YES if you want to disable Apple's maps entirely.
Related
I need to add Compass or rotation with Map. This is my code. I am using Custom marker. I know we can add compass with MKMapView. But I have added many features to the Map using Map class like custom View Markers, longPress pin drop etc. Therefore, moving to MKMapView would be like redoing everything from scratch again.
Map(coordinateRegion: $mapRegion , annotationItems: viewModel.locations) { location in
MapAnnotation(coordinate: location.coordinate) {
MarkerView(location: location)
}
}
Anybody can tell me how I can do compass rotation with Map.
Thanks
You may be able to set these properties on the underlying view via the Introspect framework. It does not handle Map() out of the box, so you would have to follow the section on implementing your own selector. As the project's Read Me states, there are some caveats:
Please note that this introspection method might break in future SwiftUI releases. Future implementations might not use the same hierarchy, or might not use UIKit elements that are being looked for. Though the library is unlikely to crash, the .introspect() method will not be called in those cases.
I have also found that you need to really be careful and heavily test which property you set (or update) when and where.
How does one get a list (array) of currently visible overlay from a MapkitView?
Background - for example I want to show direction arrows to the center of certain Overlay types on my mapkitview, however how do I get the visible ones? There seems to be no way to do this I can see? So do I need to got through all overlays (actually ~8000) and do my own check to see what would be showing on the screen? Seems a waste if MapKit would have already effectively done this as part of deciding what overlays need to be displayed at a given time.
I've been tinkering with some similar problems and the most efficient way I could figure out was to add the overlays as annotations as well, since MKOverlay implements MKAnnotation. Then you would be able to use annotationsInMapRect for the currently displayed mapRect. However this would also return any regular MKAnnotations, and only uses the calculated middle of the overlay. The only way (so far as I figured) to only get the overlays would be to iterate over each overlay and use:
-(BOOL)intersectsMapRect:(MKMapRect)mapRect;
on the currently visible mapRect.
If you found another way I'd be happy to hear!
Hi i'm writing a iOS tiled Map component in Monotouch that requires me to remove and add a large number of (markers)UIViews from a parent UiView as part of the Main thread.
I am specifically implementing clustering for the pins. As they become to close together they cluster into nodes displaying the number of pins the node represents. Depending on the zoom level i need to add and remove pins as they move in and out of nodes
Adding the views is fine as this can be done in bulk with
_parentView.AddSubviews (viewsToAdd.ToArray());
plus it can be chunked.
but the remove is killing my performance as each individual view has to be removed with a
view.RemoveFromSuperview ();
view.Dispose ();
Is there any way to speed up the operation?
I looked into putting the views into an NsArray and using performSelector remove from superview but i couldn't find the correct syntax for that in mono touch
thanks Luke
I think you should consider recycling your views instead of disposing them and creating new ones. This is something Apple's MKMapView provides, but you don't mention if you are using it or not. It works by adding a number of MKPlacemark objects, that are represented by MKAnnotationView recyclable views as you scroll around the map.
There is a reasonable example in Xamarin's Field Service App of using MKMapView's DequeueReusableAnnotation method. Scroll down to the MapViewDelegate nested class.
If you are using another map library, like Google Maps, you should consider keeping a Queue<T> of your views in order to recycle them. That way you can merely call AddSubview and RemoveFromSuperview and not create new objects over and over.
I have a map view and I want to add a variable radius like in the find friends app, allowing the user to drag to make the radius smaller or bigger. How do I do this? Is there any prebuilt functionality that allows you to do this easily?
MKCircle is the class you are looking for. It conforms to the MKAnnotation protocol, so you can just use it like any other annotation. Use the MKCircleView class for the actual drawing of the circle (also check the available sample code).
It can be possible by just using a custom MKAnnotationView that shows a circle? That will maintain size as you zoom around.
I wanna accomplish the following, i wanna display a static map image that i have on UIMapView to use the benefits of the zooming and annotation, i've search very hard and i came up with these solution.
There is a library called route-me that give you the ability to customize the map, change the color of the map, specify a predefined road and building, highlight them, but it didn't help me in my issue.
I've looked on apple example that using the MKOverLay class, HazardMap, KMLViewer but they are not showing how to use an image to replace it with the map.
All i want is to display a map image that i have for a place and use it in UIMapView. can anyone put me in the right direction.
Thx in advance.
I replied to this question in this other post. Maybe it helps you:
How do I create an image overlay and add to MKMapView?