Whats wrong with this AS3 + Markers hack?
I'm using the AS3 code from Rev. 330 of the SVN trunk. I'm trying to hack in visible markers by adding "markr" buttons to the tile "well" sprite. (This makes panning look good.) For some reason the markers aren't responding to their mouse events. What's special about this "well" thats breaking mouse events (or what I'm doing wrong otherwise)?
Here's the relevant code:
// Grab an instance of the grid's "well"
var well:Sprite = Sprite(map.grid.getChildByName("well"));
// Create an event handler for marker clicks
function traceClick(event:MouseEvent):void{
trace("Real Target " + event.target + ":" + event.target.name);
trace("You clicked " + event.currentTarget + ":" + event.currentTarget.name);
trace("Bubbles? : " + event.bubbles);
}
// Create an event handler for map MarkerEvent.ENTER
function onMarkerEnters(ev:MarkerEvent):void {
var pointXY:Point = map.locationPoint( ev.location, well );
var mark:DisplayObject = well.addChild(new markr());
mark.name = ev.marker;
mark.x = pointXY.x;
mark.y = pointXY.y;
mark.addEventListener(MouseEvent.CLICK, traceClick);
}
map.addEventListener(MarkerEvent.ENTER, onMarkerEnters);
Here's the relevant code:
// Grab an instance of the grid's "well"
var well:Sprite = Sprite(map.grid.getChildByName("well"));
// Create an event handler for marker clicks
function traceClick(event:MouseEvent):void{
trace("Real Target " + event.target + ":" + event.target.name);
trace("You clicked " + event.currentTarget + ":" + event.currentTarget.name);
trace("Bubbles? : " + event.bubbles);
}
// Create an event handler for map MarkerEvent.ENTER
function onMarkerEnters(ev:MarkerEvent):void {
var pointXY:Point = map.locationPoint( ev.location, well );
var mark:DisplayObject = well.addChild(new markr());
mark.name = ev.marker;
mark.x = pointXY.x;
mark.y = pointXY.y;
mark.addEventListener(MouseEvent.CLICK, traceClick);
}
map.addEventListener(MarkerEvent.ENTER, onMarkerEnters);
1
person has 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?Hi Bill.
I'm not sure what specifically is wrong with the above code... BUT, I did just check-in a new version of Modest Maps for AS3 that includes better marker support.
There probably is a way to save a little bit of event dispatching overhead by adding things directly to the well, but that's messing around with bits of the library which we should be able to change without breaking your code, so I wouldn't recommend pursuing it.
So here's what's new:
The old function Map.putMarker registered a location/id with the map and sent you events when it moved in and out of view. That's still there, the API hasn't changed. But now Map.putMarker also takes a DisplayObject (e.g. Sprite) as an optional third parameter and takes care of moving that DisplayObject around for you. The API is a little funky at the moment because the id you pass to Map.putMarker has to match the DisplayObject.name, but it's working for us on a new project and it seems general enough to be in the library.
If this isn't flexible enough, you don't have to use the built-in Map.markerClip. You can also create your own (com.modestmaps.core.MarkerClip) and add it as a child of the map and directly call MarkerClip.attachMarker with your location and sprite. Again, the MarkerClip should take care of moving the marker around for you, including animating on zoom.
(Note for AS2 folks: the AS2 version has a similar implementation but due to the differences in creating MovieClips the way you handle adding things is slightly different.)
I’m coding
-
Inappropriate?How soon before flex.Map is updated to match the new constructor and init convention in modestmaps.Map?
I’m broken
-
Inappropriate?It appears that the modestmaps.Map object is instantiated later than before. Is there a recommended way to tell when it has been created so I can get the ref to the Map object from the flex.Map object? I was getting it in a callback attached to the Flex app's initialize event, but now it's coming back null.
I’m still broken
-
Inappropriate?Ah, seems I spoke too soon then. Sorry about that! We're so close to calling this 1.0 I'm going to bounce the next revision off my colleagues to make sure I don't break anything else. We should have a good answer for you this week.
I’m a dork
-
Inappropriate?I've had some issues with tiles not being flush after recentering (either via double click or API calls, AS3 codebase). Definitely something you'd want to fix before a V1.0. Let me know if you need code to recreate this.
I’m easy to impress
-
Inappropriate?The Map object is available by the time the creationComplete event on the flex.Map object occurs.
I’m less broken
-
Inappropriate?Hello,
First, thanks for this great work, I'm starting working with modestMap. It's great.
I've seen the problem with tiles not lining up correctly and I have an other problem : sometimes, modestmaps doesn't upload one tile correctly. Dos someone know why?
Thanks for your help.
Farf
Sorry for the English...
-
Inappropriate?I've summarized all deleted all the tile discontinuity stuff I'd thrown into this thread. Go here instead: http://getsatisfaction.com/modestmaps...
Loading Profile...



EMPLOYEE

