Does anybody know the relationship between the members of an Android Itemized Overlay list and when draw() is called. Specifically, I'm trying to find out if draw is called once for each Overlay or once only for the whole set.
Thanks,
R.
I overrode draw() in my ProjectOverlay extends ItemizedOverlay class and in it I loop though the population of the overlay list like so:
for (int ctr = 0; ctr < overlayList.size(); ctr++)
I haven't tested other ways of drawing the screen, because this seems to be working fine.
As far as I understand it, draw() is called once each time the map moves (when you touch the screen and move your finger). By once, I mean that if you want to draw text on each overlay (a name or something) you must loop through your ArrayList in your overriden draw().
As far as I can tell, it's called twice for each visible item. However, I haven't been able to find out which item it's being called for, thus making any recalculation of drawable items difficult (to say the least)
Related
I have an android app I have written, that basically has a custom overlay, in this overlay I have overwritten the DRAW method to draw something on a canvas and at the end of my DRAW override, I call the super DRAW passing in the canvas I have painted.. the result is, every time the map is modified in anyway my custom overlay is redrawn as expected.
Now, I am trying to accomplish the same thing on iPhone and am getting a little confused.
Basically I need something drawn in the top right corner of the map every time a redraw occurs of the map. The drawin will change change with every update as well so can't simply be put a view over the map and pass touches through etc.
So, I guess the question is, what is the euivalent of the DRAW method in iOS.. how would I roughly accomplish this same thing? There are MKOverlayView in the API, but there seem to be some significant differences.. So, how do I put something say at 10x10 over the map, whos size is variable and make sure every time the map is moved, scaled or otherwised interacted with this object is redrawn at location 10x10 on the screen.
The docs for MKMapView state that you should not subclass MKMapView, so you can't / shouldn't override the drawRect method. You could add a UIView, though, and override drawRect to do your custom drawing.
I have an OnDraw method which draws a set of rectangles [ like an indoor map].On the touch event, a new Activity Intent is called.After the new activity is called,I want to know, how to redraw the rectangles on the buttonClick event( showing a new path in the map).
Below i have mentioned what ive done so far.
1.I have drawn a map on a surface view using DrawRect()
2.Then I catch the rectangle coordinates onTouch event
3.Using a webService, i calculate a shortest path to a location
4.After catching the touched rectangle coordinates, i jump in to a new activity
5.I want to re draw my map(including the path) when i click A button on the new activity
Please give me an idea about how to override and redraw the On Draw method???
Thank you!
If I understand correctly, I think you just need to call View.invalidate() on your view to cause it to re-draw. I'm confused as to why you are switching activities, however. It sounds like you should just do your webservice call in an AsyncTask and then in it's onPostExecute(), call invalidate() on your view to cause it to re-draw with whatever data you have now given it.
However, it sounds like you may not have actually implemented your own View class but instead are drawing directly to the surfaceView? I would read up on how to make your own subclass of View. It's really not that hard.
I have a very specific component to realize. I don't really know how to do it.
The component is a segmented bar with a cursor that can select any segment. A segment selection should update the number of segment in the bar. A segment could have two "state" which is represented with 2 differents graphics.
IE :
This may sound like a rating Bar but i really don't know how to proceed (new with java and android).
Should i use Rating Bar and just change the stars by segments ?
Should i extend RatingBar (how ?) ?
Any help will be appreciated
Looks like you're going to have to write your own view. Don't worry - it's not so difficult (I did my first one without any sweat after 2 days of doing Android). Basically you have a class which extends View and you override the onDraw function which draws directly to the supplied Canvas. Make sure you override the onMeasure function too or your view will have no height!
Have a look at the android page on Building Custom Components - a quick google or stack overflow search will give you many hints as to how to proceed too.
Once you work out how to write a custom view (start with a small prototype) then you just need the logic of how this specific controller works. I'd probably have a collection to hold each of your segments, with each item being a class representing your data. In your onDraw then you just have to process the collection and draw to the screen.
To get your touch to zoom, override the onTouchEventmethod, which will give you a MotionEvent object which you can call getX() and getY() on to return the coordinates of where the user touched your view - from there you can work out what segment the user touched and process the zoom.
Let me know if you need any more help.
This doesnt look to hard to achieve.
Create a custom view, override onDraw() and go from there; each section probably would be a rectangle, and since you know how many sections there are you can divide the with to the amount of sections, and draw them on the correct positions.
Override ontouch and check the motionevent for click locations, do a hit test to figure out which segment is clicked on, then set a boolean zoom to true, invalidate the view such that it gets redrawn and draw just the zoomed segments.
You would probably want to back this up by a simple array containing the state for each of the sections.
I am developing an Android mapping application and I have managed to work Google's ItemizedOverlay tutorial into my code. I'm plotting my little circle on the map nicely.
However, I would like to label my tiny symbol with its title -- all the time. I'm going to be dropping a few different symbols on my map and the able to display their labels would be a BIG help. I got the onTap method working, but when you tap the screen, it takes over the whole display -- which is not very helpful.
I haven't managed to find a thing about this on the internet, so I'm not optimistic, but if anybody's got any sort of suggestion, that would be much appreciated.
Not sure what onTap has to do with this or what you mean by "it takes over the whole display," but I think to display labels you'll have to draw them yourself. You could do this in a couple ways. One would be to override the ItemizedOverlay.draw method directly, and iterate through each one of your GeoPoints and draw the title directly onto the Canvas at some small offset to that location. Another possible way would be to return a custom marker; instead of just returning the symbol, you could create a Picture by drawing the circle and then drawing some text next to it, and then you would be able to wrap this in a PictureDrawable and use that as the marker for your overlay item.
My onTap method looks like this:
protected boolean onTap (int index)
{
OverlayItem item = mOverlays.get (index);
AlertDialog.Builder dialog = new AlertDialog.Builder (mContext);
dialog.setTitle (item.getTitle());
dialog.setMessage (item.getSnippet());
dialog.show();
return true;
}
The calling application passes in its context (this) when it instantiates the Itemized Overlay. I'm still not really sure what that means, but I save the passed-in context in mContext, and use it in onTap(). I can't really take credit for it, naturally, since somebody else posted in to the Internet. It does display the Overlay's information on the screen, but (unfortunately for me) not in a manner that I'm happy with.
I'm working on overriding the draw method, but that's been much interrupted and is still in its early stages. I'll post it here if there's any interest.
R.
I'm trying to draw a route onto my MapView.
I've extended Overlay and implemented the draw() method.
The route is displayed properly, although while debugging,
I added a breakpoint on draw(), and noticed it is being called constantly.
I only want it to be re-drawn if someone moves the map or zooms (the draw take into account these changes when drawing the route)
What can cause this ?
There are two draw methods that can be overridden.
void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
Desc: Draw the overlay over the map.
boolean draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow, long when)
Desc: Draw call for animated overlays.
I originally overrided the second one.
After changing to the first method, it worked out.
i think the draw method is called repeatedly because the of the background being redrawn constantly. try setting the "MapView.ReticleDrawMode" to DRAW_RETICLE_UNDER. This basically tells the mapView to draw the reticle under the overlays. So overlay's draw method will not be called when the background is recalled. this fixed the issue for me.
for more info, look here: MapView Api
I got tripped up when I didn't realize that the draw method get's called not only any markers that you draw, BUT also the shadow of those markers. So as an example, if you have two markers and you have shadows set to true (which is the default setting), then you'll have the draw method being called 4 times (once for each marker, once for each shadow of the markers)!
After further review, the Overlay draw() does actually work as described in the documentation. One draw for shadow = true, and one for shadow = false.
The interesting thing is that the specific overlay draw() method responds as advertized for each element drawn in the MapView. For example, in my case, it seems to respond for each the google map, the Google logo drawn on the map, and then the particular overlay I have drawn myself. Obviously twice for each (shadow true|false).
This is probably the intended way to render the maps. I haven't found or spent enough time researching for this information.
Also, in my own case, I have a transparent panel rendered over my map with CheckBox(s) and TextView widgets. The TextView forces the draw() method to run non-stop since the textview is always listening for input and hence triggering the redrawn of the overlay.
In my app, I have an indefinite progress bar (e.g. spinning circle) show when I'm loading network data for the map. When the network data is finished loading, I was setting the progress bar's visibility to invisible. However, this caused the map to continuously redraw as it seems that any animation (I'm guessing) which takes place over the map will cause the map itself to redraw. Simple solution to this is to set the visibility to gone instead. E.g. change this:
ProgressBar loadingIcon = (ProgressBar) findViewById(R.id.loadingIcon);
...
//Network data now finished loading...
loadingIcon.setVisibility(View.INVISIBLE);
to this:
loadingIcon.setVisibility(View.GONE);
which removes it entirely from the map, no longer animates over it and therefore does not cause draw() to be called a indefinitely.
For me it looks like a strange bug - sometimes the draw method is called continously, sometimes not.
see here.
I know this is an old problem, but I just now encountered it. This is a "for what it's worth" post.
The draw loop turned out to be a coding error on my part. According to the doc, if the draw routine returns true, it is asking for an immediate update. If false is returned, only two passes are made for each overlay; one for shadow true and one for shadow false. I was returning true which resulted in a constant update. After I changed to returning false, only two passes per overlay occurred. No loop.
You can simply add this to your ItemizedOverlay class:
#Override public void draw( Canvas c, MapView m, boolean shadow ) { super.draw( c, m, false );}
This will remove the shadow from your mapview overlay.