Adding markers in Flex
I'm working with the Subversion Trunk (r 719) and Flex 3 / AS3, trying to implement markers on a custom map. My markers aren't showing up, though. If I trace out the coordinate of the marker, it claims to be at position (0,-0.05) (that's absolute x,y coordinates, not Lat/Long).
I've looked through the Flex resources here and some of the answers are very old, others I can almost make sense out of.
So what should I be thinking about for attaching markers to a map in Flex? It doesn't appear to be as simple as:
(MapMarker is my own component, based on mx:Button)
I've looked through the Flex resources here and some of the answers are very old, others I can almost make sense out of.
So what should I be thinking about for attaching markers to a map in Flex? It doesn't appear to be as simple as:
var tmarker:MapMarker = new MapMarker();
tmarker.name="marker01";
campusMap.map.putMarker(new Location(1.2,1.99),tmarker);
trace(":::" + " " + tmarker.x + "," + tmarker.y);
(MapMarker is my own component, based on mx:Button)
2
people have this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?As with most questions about Flex and Modest Maps, you're somewhat on your own I'm afraid. That said, it looks like you're not afraid of the actionscript end of things, which is helpful.
Using Flex components as markers is tricky I think because there's nothing to tell the markers what size they should be or when to draw. I believe this is handled by UIComponent in Flex normally.
If you replace your Flex Button-y MapMarker with one that simply extends Sprite, does that work? It should be as simple as:
public class MapMarker extends Sprite
{
public function Marker()
{
graphics.beginFill(0x000000);
graphics.drawCircle(0,0,5);
graphics.endFill();
}
}
If that shows up, then it's an issue with using Flex classes as a base class for markers I think. You'll need to figure out how to provide measurements for the marker and how to tell it to redraw itself. That's way out of the scope of what Modest Maps supports right now, but there's plenty of room in the flex package for contributions :)
I’m undecided
1 person says
this answers the question
-
Inappropriate?Incidentally, if marker.x and marker.y are somewhere around 0, it should be showing up in the middle of your map. MarkerClip positions itself such that 0,0 is in the center of the map (this makes animating the zoom a whole lot easier).
This makes it all the more likely that the reason your marker isn't showing up is because it doesn't have any children or anything drawn to its own graphics. -
Inappropriate?Aha! There's my problem. Just using a sprite instead of Flex piece worked. Rather than try to get a Flex peice to work, I think I'll just put some logic in the sprite.
An earlier response had a lot of stuff about having to write and attach your own marker-clip, etc, which no longer seems to be the case and makes me happy.
I don't know how much I can contribute to the Flex package (still getting my feet wet with Flex) but if I can contribute something I will!
I’m making progress.
-
Inappropriate?I am able to use Flex-component-based markers with a couple of minor changes to the ModestMaps code (svn trunk, r 773) -- changed the declaration of com.modestmaps.Map and com.modestmaps.overlays.MarkerClip to extend mx.core.UIComponent instead of flash.display.Sprite.
Note, I have not done much testing on this and it changes the ModestMaps core so it's no longer compatible with pure ActionScript projects -- but in the limited use case of my current project, this was an easy fix that does the job.
I’m happy
-
Jay: Have you shared your recent code using UIComponent as the basis for Flex markers? I found some of your earlier code (MMTestFixed and MMPolylineDemo) but neither has markers, and is older than you post 1 month ago re: Flex markers based on UIComponent.
Thanks,
Homer -
homer: here's what I did to make flex markers work:
changed the class declaration from "extends Sprite"
to "extends UIComponent" in two classes:- com.modestmaps.Map and
- com.modestmaps.overlays.MarkerClip
- added "import mx.core.UIComponent" to both classes.
Good luck! -
Thanks Jay. I can now get a map with your markers; however, when I try to borrow your code for myMap.zoom, myMap.center, etc. it throws errors about access to undefined property zoom, center, etc. Is there anything else I need to change? -
Homer: hard to say without seeing your code (can you post it?)... one possibility is if you mistakenly try to set zoom and center on an instance of Map instead of MapComponent, since Map does not provide setters for those properties. -
You were right! I somehow switched back to standard Map.as vs. MapComponent.as. I had a changed my xmlns specifcation and dropped the .flex.* part. (I am going crazy trying so many Flex Marker samples.)
I can't post the code in it's current form, but will strip it down to the basics is need be.
Now that I can specify map.zoom/center/provider, per your help, the next problem is it fails on map.putMarker. I borrowed the marker code from the AS3 Sample code. It worked as long as I was using Map.as. What is the equivalent to map.putMarker for MapComponent.as? I'll check your Polyline example. I seem to remember comments there about markers for adding the polyline overlay.
I can't tell you how much I appreciate this. I thought I was getting a hang of Flex/AS3 until I ran into this problem (switching from Google to Modest Maps.) Now I see I'm still a babe in the woods, but learning as fast as I can! -
I don't know if this is right, but it seems to work.
I changed from:
myMap.putMarker(loc, marker);
to:
myMap.map.putMarker(loc, marker) and it works!
I found the latter in Tom Lauck's example of Yahoo Style Flex Markers post.
- http://deseloper.org/read/2008/01/mod... -
Homer: correct, there is no putMarker method available on MapComponent, so you have to drill down to get to the underlying Map object (MapComponent is just a Flex-friendly(ish) wrapper for the real Map object). Sounds like you are getting the hang of it, but feel free to contact me directly if you get stuck again... I've probably been there. Jay (jay.wood@uniontrib.com). -
Inappropriate?I would benefit from a beginners guide to MM, especially how to use markers. I am using Flex 3.
I know Modest Maps is intended for experienced developers and designers. Unfortunately, I am more of a newbie to maps in general, and AS/Flex specifics.
I built a map people like a lot with the Google Maps Flash API, but now I need to adapt it for MM. I need the following features.
- 2000 markers across the US, growing eventually to about 5000
- change marker size by zoom level: small when zoomed out and larger as you zoom in
- hide and show markers for various criteria. Like the excellent Oakland Crimefighters site. Awesome! This is how I want to code when I grow up. ;-)
- use Flex Effects on markers (e.g. Glow a marker if you click an associated grid element, to help find it amongst many others in a dense display.
- change marker color depending on context of map display.
I have found several good examples, some with code and some without. Most of them have either written their own marker classes and/or changed core MM classes. This is beyond my current ability, but if this is what is required, then I will jump in and enjoy learning new techniques. If there is a best practice doc for using markers in Flex, it would be much appreciated.
I'm excited to be using Modest Maps. Still hard to believe something this cool is available for free.
Homer.
I’m thankful
-
I found the Wiki explaining how to compile the as3 samples.
- http://modestmaps.mapstraction.com/tr...
That should explain a lot about what I listed above re: marker usage.
I'm not sure how to translate the as3 code to Flex 3 code, but this is a big head start. Thanks to David Knape for the main as3 sample app.
Loading Profile...



EMPLOYEE
