Hey, I posted this to the list a week or so ago. You can defn change
the color of the pins without remove+add - I do it for 400 pins with
no flickr or noticable jumps etc (ie, its 100% smooth)

Here's the post:

Have a look here:

https://gist.github.com/1184571


I set around 400 pins on a button press. it's instantanious.

you want to focus on:

RefreshPinColours() - line 384

GetViewForAnnotation. line 478

(I use a custom annotation - CycleAnnotation - to keep track of the
PinAnnotationView)

it's from this app:

http://www.fastchicken.co.nz/londonbikeapp

I think I "stole" the code from someone else to do the annotations,
and ported it from obj-c, tho that was 12 months ago, and to be
honest, I dont remember.

Hope that helps. It CAN be done :)




On Wed, Sep 7, 2011 at 14:48, Tomasz Cielecki <[email protected]> wrote:
> OK, I guess the solution probably will be to use the built in pins and
> the various colors they have or use images.
>
> I have been playing around with this solution and have run into a new
> problem. This is that I have to update the way pins look every 5
> seconds or so. Depending on some data I am loading in the background.
> Making some simple tests I have not found a nice solution to how to
> update the view of a pin. I could not find any methods allowing you to
> update the view or push a new view on a pin and nicely redrawing it.
> So I have been removing the pins updating the colors then adding new
> pins with the new colors. Which means that the pins will flicker every
> 5 seconds when they are removed and re-added with a new color. This
> also means in this timespan the pins are updating, the user cannot
> interact with the pin, which is a requirement.
>
> Do you know of a way to do this nicely? I have been searching the
> Internet and cannot seem to find any examples on how to doing this
> other than removing the pins and re-adding them. Also this seems need
> to be done on the main thread, as I have been trying to do it in a
> thread of it's own. This results in the old pin still being there
> until I zoom in on the map or somehow force the map to be re-drawn
> along with the pins.
>
>
>
> On Tue, Sep 6, 2011 at 4:19 PM, Mikkel Lønow <[email protected]> wrote:
>> Good.
>> Unfortunately, I haven't tried to draw circles that scales when zooming. You
>> could put a label on top of the annotation instead, which you can update
>> when you need to?
>>
>> On Tue, Sep 6, 2011 at 16:09, Tomasz Cielecki <[email protected]> wrote:
>>>
>>> OK, seems to work now. Thank you.
>>>
>>> Though I would still prefer if I could just draw a circle with text
>>> inside as I could imagine having images for every possible number that
>>> could appear inside the circle could be problematic to generate.
>>>
>>> MonoDroid/Android and Windows Phone 7 makes this possible and the
>>> overlay layer drawn on top of the map scales when you zoom in and out
>>> even though you have specified a radius.
>>>
>>> See these images for an example:
>>> http://imageshack.us/photo/my-images/18/device20110906153628.png/
>>> http://imageshack.us/photo/my-images/801/device20110906160751.png/
>>>
>>> This is the same effect I want. Preferably without using images. As
>>> both text and the color of the circle has to be updated sometimes.
>>>
>>> On Tue, Sep 6, 2011 at 1:11 PM, Mikkel Lønow <[email protected]> wrote:
>>> > It's working in MonoDevelop 2.6 RC2. Get it from the updater :) Make
>>> > sure to
>>> > set Build Action to Content.
>>> > Otherwise, you would have to copy them yourself.
>>> >
>>> > On Tue, Sep 6, 2011 at 13:08, Tomasz Cielecki <[email protected]>
>>> > wrote:
>>> >>
>>> >> So It seems the images are not included in the .app file. My guess
>>> >> this is not what I want :D Now how do I make them jump in there
>>> >> willingly?
>>> >>
>>> >> On Tue, Sep 6, 2011 at 9:11 AM, Mikkel Lønow <[email protected]> wrote:
>>> >> > It should be in bin/Debug/iPhoneSimulator. It's copied to the
>>> >> > simulator after compilation.
>>> >> >
>>> >> > On 06/09/2011, at 09.08, Tomasz Cielecki <[email protected]>
>>> >> > wrote:
>>> >> >
>>> >> >> Trouble is that I am currently using the Emulator to test my app.
>>> >> >> How
>>> >> >> do I find the .app package?
>>> >> >>
>>> >> >> I am using the latest stable version of MonoDevelop.
>>> >> >>
>>> >> >> On Mon, Sep 5, 2011 at 3:45 PM, Mikkel Lønow <[email protected]>
>>> >> >> wrote:
>>> >> >>> Right click / Ctrl click / two finger tab on the .app package and
>>> >> >>> select
>>> >> >>> Show Package Contents.
>>> >> >>> What version of MonoDevelop are you using?
>>> >> >>>
>>> >> >>> On Mon, Sep 5, 2011 at 15:42, Tomasz Cielecki
>>> >> >>> <[email protected]>
>>> >> >>> wrote:
>>> >> >>>>
>>> >> >>>> How do I make sure that they are actually copied into the .app
>>> >> >>>> package?
>>> >> >>>>
>>> >> >>>> On Mon, Sep 5, 2011 at 3:39 PM, Mikkel Lønow <[email protected]>
>>> >> >>>> wrote:
>>> >> >>>>> At first glance it looks correct.
>>> >> >>>>> Is Build Action for pin.png set to Content? Can you make sure
>>> >> >>>>> they
>>> >> >>>>> are
>>> >> >>>>> actually copied to the .app package? (there's a bug in some
>>> >> >>>>> versions
>>> >> >>>>> of
>>> >> >>>>> MonoDevelop where images would not be copied).
>>> >> >>>>> Mikkel
>>> >> >>>>> P.S. Replied to all.
>>> >> >>>>> On Mon, Sep 5, 2011 at 15:32, Tomasz Cielecki
>>> >> >>>>> <[email protected]>
>>> >> >>>>> wrote:
>>> >> >>>>>>
>>> >> >>>>>> I think your suggestion is more or less the same way I am
>>> >> >>>>>> implementing
>>> >> >>>>>> it.
>>> >> >>>>>>
>>> >> >>>>>> Code can be seen here https://gist.github.com/1194994 or:
>>> >> >>>>>>
>>> >> >>>>>> Here is my Main.cs file:
>>> >> >>>>>> using System;
>>> >> >>>>>> using System.Collections.Generic;
>>> >> >>>>>> using System.Linq;
>>> >> >>>>>> using MonoTouch.Foundation;
>>> >> >>>>>> using MonoTouch.UIKit;
>>> >> >>>>>> using LoadSiteList;
>>> >> >>>>>> using MonoTouch.MapKit;
>>> >> >>>>>> using MonoTouch.CoreLocation;
>>> >> >>>>>>
>>> >> >>>>>> namespace MapsStuff
>>> >> >>>>>> {
>>> >> >>>>>>
>>> >> >>>>>>
>>> >> >>>>>>        public class Application
>>> >> >>>>>>        {
>>> >> >>>>>>                static void Main (string[] args)
>>> >> >>>>>>                {
>>> >> >>>>>>                        UIApplication.Main (args);
>>> >> >>>>>>                }
>>> >> >>>>>>        }
>>> >> >>>>>>
>>> >> >>>>>>
>>> >> >>>>>>        // The name AppDelegate is referenced in the
>>> >> >>>>>> MainWindow.xib
>>> >> >>>>>> file.
>>> >> >>>>>>        public partial class AppDelegate : UIApplicationDelegate
>>> >> >>>>>>        {
>>> >> >>>>>>                UITabBarController tabBarController;
>>> >> >>>>>>                os4MapsViewController viewController;
>>> >> >>>>>>                MapsStuff.TableViewController viewController2;
>>> >> >>>>>>
>>> >> >>>>>>
>>> >> >>>>>>                // This method is invoked when the application
>>> >> >>>>>> has
>>> >> >>>>>> loaded
>>> >> >>>>>> its UI and
>>> >> >>>>>> its ready to run
>>> >> >>>>>>                public override bool FinishedLaunching
>>> >> >>>>>> (UIApplication
>>> >> >>>>>> app,
>>> >> >>>>>> NSDictionary options)
>>> >> >>>>>>                {
>>> >> >>>>>>                        window = new UIWindow
>>> >> >>>>>> (UIScreen.MainScreen.Bounds);
>>> >> >>>>>>                        tabBarController = new
>>> >> >>>>>> UITabBarController();
>>> >> >>>>>>
>>> >> >>>>>>                        viewController = new
>>> >> >>>>>> os4MapsViewController();
>>> >> >>>>>>                        viewController2 = new
>>> >> >>>>>> TableViewController();
>>> >> >>>>>>
>>> >> >>>>>>                        viewController.TabBarItem = new
>>> >> >>>>>> UITabBarItem
>>> >> >>>>>> ("Map",
>>> >> >>>>>> UIImage.FromFile("Images/103-map.png"), 0);
>>> >> >>>>>>                        viewController2.TabBarItem = new
>>> >> >>>>>> UITabBarItem
>>> >> >>>>>> ("List",
>>> >> >>>>>> UIImage.FromFile("Images/103-map.png"), 0);
>>> >> >>>>>>                        tabBarController.ViewControllers = new
>>> >> >>>>>> UIViewController[]
>>> >> >>>>>> {viewController, viewController2};
>>> >> >>>>>>
>>> >> >>>>>>                        window.AddSubview(tabBarController.View);
>>> >> >>>>>>                        // If you have defined a view, add it
>>> >> >>>>>> here:
>>> >> >>>>>>                        // window.AddSubview
>>> >> >>>>>> (navigationController.View);
>>> >> >>>>>>
>>> >> >>>>>>                        window.MakeKeyAndVisible ();
>>> >> >>>>>>
>>> >> >>>>>>                        return true;
>>> >> >>>>>>                }
>>> >> >>>>>>
>>> >> >>>>>>                // This method is required in iPhoneOS 3.0
>>> >> >>>>>>                public override void OnActivated (UIApplication
>>> >> >>>>>> application)
>>> >> >>>>>>                {
>>> >> >>>>>>                }
>>> >> >>>>>>        }
>>> >> >>>>>> }
>>> >> >>>>>>
>>> >> >>>>>> Next here is the os4MapsViewController.cs:
>>> >> >>>>>>
>>> >> >>>>>> using System;
>>> >> >>>>>> using System.Drawing;
>>> >> >>>>>> using System.Collections.Generic;
>>> >> >>>>>> using System.Diagnostics;
>>> >> >>>>>> using MonoTouch.Foundation;
>>> >> >>>>>> using MonoTouch.UIKit;
>>> >> >>>>>> using MonoTouch.MapKit;
>>> >> >>>>>> using MonoTouch.CoreLocation;
>>> >> >>>>>>
>>> >> >>>>>> namespace MapsStuff
>>> >> >>>>>> {
>>> >> >>>>>>        public class os4MapsViewController: UIViewController
>>> >> >>>>>>        {
>>> >> >>>>>>                private MKMapView _mapView { get; set; }
>>> >> >>>>>>                List<MapsStuff.MapAnnotation> pins;
>>> >> >>>>>>
>>> >> >>>>>>                public MKMapView MapView
>>> >> >>>>>>                {
>>> >> >>>>>>                        get { return _mapView; }
>>> >> >>>>>>                }
>>> >> >>>>>>
>>> >> >>>>>>                public os4MapsViewController () : base()
>>> >> >>>>>>                {}
>>> >> >>>>>>
>>> >> >>>>>>                public override void ViewDidLoad ()
>>> >> >>>>>>                {
>>> >> >>>>>>                        base.ViewDidLoad ();
>>> >> >>>>>>
>>> >> >>>>>>                        //
>>> >> >>>>>>                        // Create our map view and add it as as
>>> >> >>>>>> subview.
>>> >> >>>>>>                        //
>>> >> >>>>>>                        pins = CreateRandomPins();
>>> >> >>>>>>                        _mapView = new MKMapView();
>>> >> >>>>>>                        _mapView.Frame = new RectangleF (0, 0,
>>> >> >>>>>> this.View.Frame.Width,
>>> >> >>>>>> this.View.Frame.Height);
>>> >> >>>>>>                        _mapView.ShowsUserLocation = true;
>>> >> >>>>>>                        _mapView.MapType = MKMapType.Hybrid;
>>> >> >>>>>>                        _mapView.Delegate = new
>>> >> >>>>>> MapViewDelegate();
>>> >> >>>>>>                        foreach (MapAnnotation m in pins)
>>> >> >>>>>>                        {
>>> >> >>>>>>                                _mapView.AddAnnotation(m);
>>> >> >>>>>>                        }
>>> >> >>>>>>                        View.AddSubview(_mapView);
>>> >> >>>>>>                }
>>> >> >>>>>>
>>> >> >>>>>>                List<MapsStuff.MapAnnotation> CreateRandomPins()
>>> >> >>>>>>                {
>>> >> >>>>>>                        Random r = new Random();
>>> >> >>>>>>                        List<MapsStuff.MapAnnotation> locations =
>>> >> >>>>>> new
>>> >> >>>>>> List<MapsStuff.MapAnnotation>();
>>> >> >>>>>>                        for (int i = 0; i < 4; i++)
>>> >> >>>>>>                        {
>>> >> >>>>>>                                        locations.Add(
>>> >> >>>>>>                                              new
>>> >> >>>>>> MapsStuff.MapAnnotation(
>>> >> >>>>>>                                                  new
>>> >> >>>>>> CLLocationCoordinate2D(r.NextDouble() * 180,
>>> >> >>>>>> r.NextDouble() * 180),
>>> >> >>>>>>                                                  "test" + i,
>>> >> >>>>>>                                                  "sub" + i
>>> >> >>>>>>                                              ));
>>> >> >>>>>>                        }
>>> >> >>>>>>
>>> >> >>>>>>                        return locations;
>>> >> >>>>>>                }
>>> >> >>>>>>        }
>>> >> >>>>>>        public class MapViewDelegate : MKMapViewDelegate
>>> >> >>>>>>        {
>>> >> >>>>>>                public MapViewDelegate (): base()
>>> >> >>>>>>                {
>>> >> >>>>>>                }
>>> >> >>>>>>                public override MKAnnotationView
>>> >> >>>>>> GetViewForAnnotation
>>> >> >>>>>> (MKMapView
>>> >> >>>>>> mapView, NSObject annotation)
>>> >> >>>>>>                {
>>> >> >>>>>>                        var anv =
>>> >> >>>>>> mapView.DequeueReusableAnnotation("thislocation");
>>> >> >>>>>>                        if (anv == null)
>>> >> >>>>>>                        {
>>> >> >>>>>>                                Console.WriteLine("creating new
>>> >> >>>>>> MKAnnotationView");
>>> >> >>>>>>                                anv = new
>>> >> >>>>>> MKPinAnnotationView(annotation,
>>> >> >>>>>> "thislocation");
>>> >> >>>>>>                        }
>>> >> >>>>>>                        else
>>> >> >>>>>>                        {
>>> >> >>>>>>                                anv.Annotation = annotation;
>>> >> >>>>>>                        }
>>> >> >>>>>>                        anv.Image = new UIImage("pin.png");
>>> >> >>>>>>                        anv.CanShowCallout = true;
>>> >> >>>>>>                        return anv;
>>> >> >>>>>>                }
>>> >> >>>>>>        }
>>> >> >>>>>> }
>>> >> >>>>>>
>>> >> >>>>>> So both the referenced images in Main.cs and the ones in
>>> >> >>>>>> os4MapsViewController.cs are not shown
>>> >> >>>>>>
>>> >> >>>>>>
>>> >> >>>>>> http://imageshack.us/photo/my-images/850/screenshot20110905at323.png/
>>> >> >>>>>> <-- this image shows what I get on the emulator.
>>> >> >>>>>>
>>> >> >>>>>> pin.png lies in the root folder of my project. The other image
>>> >> >>>>>> lies
>>> >> >>>>>> in
>>> >> >>>>>> the folder Images in the project dir. None of them seems to show
>>> >> >>>>>> up.
>>> >> >>>>>>
>>> >> >>>>>> Any ideas? I know the code provided uses MKPinAnnotationView,
>>> >> >>>>>> but
>>> >> >>>>>> changing it to MKAnnotationView simply shows nothing.
>>> >> >>>>>>
>>> >> >>>>>> On Mon, Sep 5, 2011 at 2:48 PM, Mikkel Lønow <[email protected]>
>>> >> >>>>>> wrote:
>>> >> >>>>>>> Hi Tomasz,
>>> >> >>>>>>> I believe MKAnnotationView would be your best option. Use a
>>> >> >>>>>>> custom
>>> >> >>>>>>> MKMapViewDelegate and override GetViewForAnnotation where you
>>> >> >>>>>>> call
>>> >> >>>>>>> mapView.DequeueReusableAnnotation to reuse the annotation view
>>> >> >>>>>>> (or
>>> >> >>>>>>> create a
>>> >> >>>>>>> new if null). Here you can set your image to the annotation
>>> >> >>>>>>> view.
>>> >> >>>>>>> Feel free to share your implementation if you need more help.
>>> >> >>>>>>> Mikkel
>>> >> >>>>>>>
>>> >> >>>>>>> On Mon, Sep 5, 2011 at 14:01, Tomasz Cielecki
>>> >> >>>>>>> <[email protected]>
>>> >> >>>>>>> wrote:
>>> >> >>>>>>>>
>>> >> >>>>>>>> Hello MonoTouch list,
>>> >> >>>>>>>>
>>> >> >>>>>>>> I am in the midst of creating a iPhone app where I need a map
>>> >> >>>>>>>> with
>>> >> >>>>>>>> some circles, where the circle colors changes depending on the
>>> >> >>>>>>>> data
>>> >> >>>>>>>> received asynchronously in the background.
>>> >> >>>>>>>>
>>> >> >>>>>>>> So my first approach to this was to get a Map shown on the
>>> >> >>>>>>>> devices
>>> >> >>>>>>>> with a circle, which works fine. Only problem is that MKCircle
>>> >> >>>>>>>> takes
>>> >> >>>>>>>> a
>>> >> >>>>>>>> radius for that circle, which means the circle is only visible
>>> >> >>>>>>>> at
>>> >> >>>>>>>> some
>>> >> >>>>>>>> zoom level. So lets say the circle radius is 100 meters, then
>>> >> >>>>>>>> I
>>> >> >>>>>>>> have
>>> >> >>>>>>>> to zoom to almost the biggest zoom level to get to a point
>>> >> >>>>>>>> where
>>> >> >>>>>>>> I
>>> >> >>>>>>>> actually can see the circle, this is not the desirable
>>> >> >>>>>>>> behavior.
>>> >> >>>>>>>> I
>>> >> >>>>>>>> want to have the circle resize along with the zoom level, just
>>> >> >>>>>>>> like
>>> >> >>>>>>>> pins do.
>>> >> >>>>>>>>
>>> >> >>>>>>>> So I have also tried to use a custom image on
>>> >> >>>>>>>> MKPinAnnotationView
>>> >> >>>>>>>> and
>>> >> >>>>>>>> on MKAnnotationView, neither of them seems to show my custom
>>> >> >>>>>>>> image.
>>> >> >>>>>>>> The normal pin image shows when using MKPinAnnotationView. I
>>> >> >>>>>>>> have
>>> >> >>>>>>>> put
>>> >> >>>>>>>> the pin image in the root of my project and referencing it
>>> >> >>>>>>>> with
>>> >> >>>>>>>> the
>>> >> >>>>>>>> path "pin.png" (the name of the image is actually pin.png).
>>> >> >>>>>>>>
>>> >> >>>>>>>> So maybe someone here can help me find out what is wrong, or
>>> >> >>>>>>>> provide
>>> >> >>>>>>>> me with some examples on how to do this? I would prefer if I
>>> >> >>>>>>>> could
>>> >> >>>>>>>> use
>>> >> >>>>>>>> MKCircle and just choose the color. But using images could be
>>> >> >>>>>>>> a
>>> >> >>>>>>>> solution.
>>> >> >>>>>>>>
>>> >> >>>>>>>> --
>>> >> >>>>>>>> Med Venlig Hilsen / With Best Regards
>>> >> >>>>>>>> Tomasz Cielecki
>>> >> >>>>>>>> http://ostebaronen.dk
>>> >> >>>>>>>> _______________________________________________
>>> >> >>>>>>>> MonoTouch mailing list
>>> >> >>>>>>>> [email protected]
>>> >> >>>>>>>> http://lists.ximian.com/mailman/listinfo/monotouch
>>> >> >>>>>>>
>>> >> >>>>>>>
>>> >> >>>>>>
>>> >> >>>>>>
>>> >> >>>>>>
>>> >> >>>>>> --
>>> >> >>>>>> Med Venlig Hilsen / With Best Regards
>>> >> >>>>>> Tomasz Cielecki
>>> >> >>>>>> http://ostebaronen.dk
>>> >> >>>>>
>>> >> >>>>>
>>> >> >>>>
>>> >> >>>>
>>> >> >>>>
>>> >> >>>> --
>>> >> >>>> Med Venlig Hilsen / With Best Regards
>>> >> >>>> Tomasz Cielecki
>>> >> >>>> http://ostebaronen.dk
>>> >> >>>
>>> >> >>>
>>> >> >>
>>> >> >>
>>> >> >>
>>> >> >> --
>>> >> >> Med Venlig Hilsen / With Best Regards
>>> >> >> Tomasz Cielecki
>>> >> >> http://ostebaronen.dk
>>> >> >
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Med Venlig Hilsen / With Best Regards
>>> >> Tomasz Cielecki
>>> >> http://ostebaronen.dk
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Med Venlig Hilsen / With Best Regards
>>> Tomasz Cielecki
>>> http://ostebaronen.dk
>>
>>
>
>
>
> --
> Med Venlig Hilsen / With Best Regards
> Tomasz Cielecki
> http://ostebaronen.dk
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>



-- 
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to