Get your own customer support community
 

Is it possible to make draggable markers ?

Hello MM ! I'm trying to make draggable markers for a project by adding some several events type in MarkerEvent (MarkerEvent.MARKER_MOUSE_DOWN + MARKER_MOUSE_UP ) and adding accordingly mouseEvents captured in MarkerClip (then disptaching).

I also add
[Event(name="markerMouseUp", type="com.modestmaps.events.MarkerEvent")]
[Event(name="markerMouseDown", type="com.modestmaps.events.MarkerEvent")]
in both Map.as and MarkerClip.as.

But I'm stuck with an error when I try to add my new events type to a markerClip (mrk.addEventListener(MarkerEvent.MARKER_MOUSE_DOWN, this.markerHandler);)

throw me

1119: Access of possibly undefined property MARKER_MOUSE_DOWN through a reference with static type Class.
 
happy I’m confident
Inappropriate?
2 people have this question

  • nadous
    Inappropriate?
    WHO ! I'm sorry to use your time for the previous crap I wrote, I was just NOT using the modified sources when compiling in Flash (while I was coding in FDT with modified sources, so no errors was shawn)...

    Sorry Sorry sorry...
     
    silly I’m amused
  • nadous
    Inappropriate?
    But I'm still stuck... Well in fact it works pretty well excepting the fact that the markers display updates accordingly to the new location only once I panned then released the map, which seems to be a recurrent issue for others (apparently due to a Event.RENDER we need to call somewhere with stage.invalidate() or dirty = true). Well I tried a lot and I could not find the way to fix it. I did not change a lot in MarkerClip.as, I just add a MOUSE_UP and MOUSE_DOWN listener and the callback looks simple ;

    private function onMarkerMouseUp(event:MouseEvent):void {
    stopDrag();
    var marker:DisplayObject = event.target as DisplayObject;
    updateLocation(marker);
    }

    still, the problem remains...
     
    indifferent I’m exhausted Excl_3
  • nadous
    Inappropriate?
    Alright I continue to respond my own post...
    And I answer to it ! Yes i'ts possible...

    1- in MarkerClip, add listeners and callbacks
    protected function onMarkerUp(event:MouseEvent):void {
    var marker:DisplayObject = event.target as DisplayObject;
    var location:Location = getMarkerLocation(marker);
    dispatchEvent(new MarkerEvent(MarkerEvent.MARKER_UP, marker, location, event.localX, event.localY, true));
    }

    protected function onMarkerDown(event:MouseEvent):void {
    var marker:DisplayObject = event.target as DisplayObject;
    var location:Location = getMarkerLocation(marker);
    dispatchEvent(new MarkerEvent(MarkerEvent.MARKER_DOWN, marker, location, event.localX, event.localY, true));
    }

    2- updates MarkerEvent (forget the IDestroyable Interface, Destroyable object, and destroy method, they came from casalib). I also extend from MouseEvent so I super localX and localY.

    package com.modestmaps.events {
    import com.modestmaps.geo.Location;

    import org.casalib.core.Destroyable;
    import org.casalib.core.IDestroyable;

    import flash.display.DisplayObject;
    import flash.events.MouseEvent;

    public class MarkerEvent extends MouseEvent implements IDestroyable {
    // these are prefixed marker to avoid conflicts with MouseEvent
    public static const MARKER_ROLL_OVER:String = 'markerRollOver';
    public static const MARKER_ROLL_OUT:String = 'markerRollOut';
    public static const MARKER_CLICK:String = 'markerClick';
    public static const MARKER_DOWN:String = 'markerDown';
    public static const MARKER_UP:String = 'markerUp';

    protected var _marker:DisplayObject;
    protected var _location:Location;
    protected var _localX:Number;
    protected var _localY:Number;

    private var destroyable:Destroyable;

    public function MarkerEvent(type:String, marker:DisplayObject, location:Location, localX:Number = 0, localY:Number = 0, bubbles:Boolean = true, cancelable:Boolean = false) {
    super(type, bubbles, cancelable, localX, localY);
    _marker = marker;
    _location = location;
    destroyable = new Destroyable();
    }

    public function get marker():DisplayObject {
    return _marker;
    }

    public function get location():Location {
    return _location;
    }

    public function get destroyed():Boolean {
    return destroyable.destroyed;
    }

    public function destroy():void {
    _marker = null;
    _location = null;
    destroyable.destroy();
    }
    }
    }

    3 back on your main class (Map + MarkerClip + MarkerEvent) I do a simple switch case ;

    var pin:Pin = $evt.marker;

    case MarkerEvent.MARKER_UP :
    pin.stopDrag();
    trace($evt.localX, $evt.localY);
    var p:Point = new Point(mouseX - $evt.localX, mouseY - $evt.localY);
    var loc:Location = minimap.pointLocation(p);
    mrk.setMarkerLocation(pin, new Location(loc.lat, loc.lon));
    mrk.updateClip(pin);
    break;

    You're good to go !
     
    happy I’m happy
    Sprite_screen 1 person says this answers the question
  • Comment_icon
    Hooray, I'm glad you managed without us! Sorry for the delay in responding to this one.
User_default_medium