AS3 quirks with markers, providers, navigation
I'm building a Flex app with your nice map,and have run into a few snags. I suspect they are mostly just things you haven't completed yet in your flex.Map object, but I thought I'd mention them because maybe it's something I've got wrong.
1. Markers can't be created too early. I had to wait for the map to be displayed and zoomed. If I remember correctly, the zoom caused some variable to be initialized that is used to create unique marker IDs. It will be great when flex.Map can manage the marker objects directly.
2. The geo coords don't wrap, so if you pan around the world the markers disappear. Is there a way to clamp the pan (and zoom) to a range?
3. Setting the provider property on flex.Map doesn't seem to work.
4. Is there an easy way to animate to a location or zoom level through an API call?
You can see the current state of the experiment at http://plwmodelworks.com/map.
Looking forward to the next AS3 update! Thanks for the great work.
1. Markers can't be created too early. I had to wait for the map to be displayed and zoomed. If I remember correctly, the zoom caused some variable to be initialized that is used to create unique marker IDs. It will be great when flex.Map can manage the marker objects directly.
2. The geo coords don't wrap, so if you pan around the world the markers disappear. Is there a way to clamp the pan (and zoom) to a range?
3. Setting the provider property on flex.Map doesn't seem to work.
4. Is there an easy way to animate to a location or zoom level through an API call?
You can see the current state of the experiment at http://plwmodelworks.com/map.
Looking forward to the next AS3 update! Thanks for the great work.
Follow this discussion to get notifications on your dashboard.
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?Any chance you'd be willing to share your code? You seem to have overcome the issues I've had with getting both nice panning and mouse-over response for markers. I'd like to know what your approach was.
I’m interested
-
Inappropriate?My approach is pretty simple:
I created the marker as a MovieClip in Flash, made that into a symbol (called SpotMarkerMC), then exported it as a .swc, and made an ActionScript class (public class SpotMarker extends SpotMarkerMC { ...). In my Flex app, I create instances of modestmaps.Marker that I give to the modestmaps.Map object using putMarker(), and instances of SpotMarker that I attach to the modestmaps.flex.Map object using addChild(). I have callbacks attached to the marker ENTER and LEAVE events that add and remove SpotMarkers from an active list. I have callbacks attached to the ZOOM and PAN events that update the position of each marker in the active list and clip the markers wrt the map boundary, by calling moveMarkers():
private function moveMarkers(event:MapEvent=null):void {
// For each active marker, move it, then see whether its
// visibility needs to be changed.
for (var markerId:String in _activeMarkers) {
var m:Marker = _allMarkers[markerId];
var pt:Point = _map.locationPoint(m.location, _flexMap.map);
var mClip:SpotMarker = _allMarkerClips[m.id];
// put the marker's hotspot at the desired location
mClip.x = pt.x - _markerOrigin.x;
mClip.y = pt.y - _markerOrigin.y;
// When marker leaves the map boundaries, hide it. This can happen
// before it is removed from the map (when its tile goes away).
// The reverse for showing it.
if (mClip.x < 0 || mClip.x > _flexMap.width ||
mClip.y < 0 || mClip.y > _flexMap.height) {
mClip.visible = false;
}
else {
mClip.visible = true;
}
}
}
I'm looking forward to checking out the latest update that was announced. Sounds like it will do more of the work to manage the markers.
As a side note: I spent way too much time trying to figure out the right way to export the Flash MovieClip symbol and make it into a proper Actionscript object. I got very confused trying to make it an actual Flex component. What I have now works as long as I compile it into my Flex app. If I tried to load the map marker symbol dynamically I guess I would have to have some sort of interface class defined so I could call methods on it.
So there you have it. In return, maybe someone can tell me how to get double-click events to come through. I can't seem to get any double-click event from the Map object or any of its containers. I set doubleClickEnabled to true and attach a listener, but nothing happens.
I’m still learning
-
Inappropriate?It seems like you need to set mouseChildren to false for double click to work. I've had some luck adding it to the map's tilegrid rather than the map itself. That way you don't have to disable interaction with markers:
map.grid.addEventListener(MouseEvent.DOUBLE_CLICK, onMapDoubleClick);
map.grid.doubleClickEnabled = true;
map.grid.mouseEnabled = true;
map.grid.mouseChildren = false;
...
private function onMapDoubleClick(event:MouseEvent):void
{
var p:Point = new Point(event.localX, event.localY);
var l:Location = map.pointLocation(p,map);
map.setCenter(l);
}
I’m unsure
-
Inappropriate?Gah, I spoke too soon. If you set map.grid.mouseChildren = false then the dragging won't work!
I’m frustrated
-
Inappropriate?I've just checked in double-click-to-center support for AS3. It's added to TileGrid.as's _well property. It can't easily be turned on/off right now, but if that's something people want they should let us know.
I also fixed the Flex component and checked in some more changes to the MarkerClip implementation - event passing for marker enter/leave was too slow with thousands of markers (see http://oakland.crimespotting.org) so now MarkerClip does simple bounds checking instead. Hopefully that's quick enough for now!
I’m happy
-
Inappropriate?NotSoFast - would you be willing to share your Flex project source to help a newbie get started with using ModestMaps in Flex?
-
Inappropriate?I'll second that request - we're not able to support the Flex app here at Stamen right now because we don't have a project that uses it. If someone else would like to maintain the flex part of the library we'd be glad to give them access to the repository and discuss with them how to get it right.
I’m wondering
-
Inappropriate?I am willing to share, especially if someone who is really in tune with Flex might take it and clean it up. I pieced it together from what I could learn in a hurry, and it contains several workarounds for things I couldn't figure out but might have simple answers. I have some immediate issues (2 of my machines went belly up on me yesterday, so I'm scrambling), but I'll try to recover the source ASAP. I wouldn't be the right person to maintain your Flex library: my Flex involvement is occasional, fleeting, and superficial.
I’m flattered
-
Inappropriate?notsofast, RandomEtc.,
I'm willing to try my hand at evolving the flex implementation of modest maps. Rather than starting from zero, it would be a big help to have your flex project source to begin with. We'll be spending a lot of time with the flex implementation of this lib and will share the results as the developments evolve. Let me know when you are able to recover the source and thanks for the gesture to share.
Loading Profile...




EMPLOYEE
