Adding markers on top of MapNik

160 views
Skip to first unread message

diego

unread,
Dec 5, 2012, 3:05:32 PM12/5/12
to opensca...@googlegroups.com
HI all. I'm trying to put some markers on top of a MapNik layer. What I'm doing is adding a VectorLayer and then adding markers there. The problem is a projections issue, I think. Markers don't show exactlty where I click, but with some offset. This is my code:

                this.iMarkersLayer = new VectorLayer ('_markers');
                this.iMarkersLayer.projection = "EPSG:900913";
                this.iMarkersLayer.style = Style.getDefaultPointStyle();
                this.theMap.map.addLayer (this.iMarkersLayer);
                this.theMap.addEventListener (MouseEvent.CLICK, this.handleMapClick);

            private function handleMapClick (event:MouseEvent):void
            {
                var lPixel        :Pixel = new Pixel;
                var lLocation    :Location;
               
                // Get clicked coordinates
                lPixel.x = event.localX;
                lPixel.y = event.localY;
                lLocation = this.theMap.map.getLocationFromMapPx (lPixel);

                // Add marker
                this.iMarkersLayer.addFeature (new Marker (new org.openscales.geometry.Point (aLocation.lon, aLocation.lat)));
            }           

What am I doing wrong?

TIA

Diego.

Shaun

unread,
Sep 5, 2013, 6:30:49 AM9/5/13
to opensca...@googlegroups.com
I'm stuck with the same problem at the moment, did you have any luck?

Diego Marrero

unread,
Sep 14, 2013, 5:56:00 AM9/14/13
to openscales-dev
Yes, I figured out. The trick is obtaining x and y like this:

                lPixel.x = this.theMap.mouseX;            // this.theMap is my openscales:Map (fxMap) control
                lPixel.y = this.theMap.mouseY;

event.localX and event.localY do not work well. Hope that helps

Regards.

Diego.






2013/9/5 Shaun <shaunwill...@googlemail.com>

--
You received this message because you are subscribed to the Google Groups "openscales-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openscales-de...@googlegroups.com.

To post to this group, send email to opensca...@googlegroups.com.
Visit this group at http://groups.google.com/group/openscales-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Shonbh

unread,
Sep 23, 2013, 10:05:44 PM9/23/13
to opensca...@googlegroups.com
In my case, it run okie:
My map like that:

<Map id="fxMap" width="100%"  height="100%"  projection="EPSG:900913" >
        <Mapnik name="Mapnik" />

Handle mouse click event:

var clickHandler:ClickHandler = new ClickHandler(fxMap.map, true);
clickHandler.click=setLocationForrouting; // when mouse click to run function setLocationForrouting

function setLocationForrouting as following:

private var from_layer:VectorLayer=new VectorLayer("fromLayer");
[Embed (source="../src/icons/start.png")]
public var startIcon:Class;

lonlat = fxMap.map.getLocationFromMapPx(pixel);
drawStartPoint(lonlat);
var startImage:Bitmap = new startIcon();
 var startMarker:CustomMarker=CustomMarker.createDisplayObjectMarker(startImage,startPoint,null,10,-15);
 from_layer.addFeature(startMarker);
 fxMap.map.addLayer(from_layer);

Hope that help !

Bui

Shonbh

unread,
Sep 23, 2013, 10:11:08 PM9/23/13
to opensca...@googlegroups.com


On Tuesday, September 24, 2013 9:05:44 AM UTC+7, Shonbh wrote:
In my case, it run okie:
My map like that:

<Map id="fxMap" width="100%"  height="100%"  projection="EPSG:900913" >
        <Mapnik name="Mapnik" />

Handle mouse click event:

var clickHandler:ClickHandler = new ClickHandler(fxMap.map, true);
clickHandler.click=setLocationForrouting; // when mouse click to run function setLocationForrouting

function setLocationForrouting as following:

private var from_layer:VectorLayer=new VectorLayer("fromLayer");
[Embed (source="../src/icons/start.png")]
public var startIcon:Class;

private function setLocationForrouting(pixel:Pixel):void{
lonlat = fxMap.map.getLocationFromMapPx(pixel);
Reply all
Reply to author
Forward
0 new messages