Hi
I am trying to let user drag the place marker I have placed on map. Afaik there is no internal support in lib for this, so trying to implement with available methods. What I have been trying is to catch label clicked event and then in pointer drag event handling, I move place accordingly. The patch would be as follows:
public void elementClicked(OnMapElement arg0)
{
// currently only one place.. so
markerDragStart = true;
}
.....
protected void pointerDragged(final int x, final int y) {
if (!initialized) {
return;
}
if (markerDragStart)
{
//remove existing place
//create place in specified x and y
}
else
{
mapDisplay.pointerDragged(x, y);
}
}
If the above method is correct, I need to specify the new place in x and y at any drag moment. But I can create place only with wgspoints. So I need to convert (x,y) to wgspoint. How to achieve this? (There was a thread with similar problem already posted sometime back)
Please help.
I suggest two approaches:
1) If possible use MapListener and MapClicked event, which just gives you point where user clicked.
2) Try to find out where user clicked.
For example following code works for me in Pointer events:
protected void pointerReleased(final int x, final int y) {
MapPos centerPos = map.getMap().wgsToMapPos(map.getCenterPoint().toInternalWgs(),map.getZoom());
int screenCenterX=(int) map.getWidth()/2;
int screenCenterY=(int) map.getHeight()/2;
final MapPos clickOnMap = new MapPos(centerPos.getX() - screenCenterX + x, centerPos
.getY() - screenCenterY + y, centerPos.getZoom());
final WgsPoint wgsPos = new WgsPoint(map.getMap().mapPosToWgs(clickOnMap).getX()/1000000D,map.getMap().mapPosToWgs(clickOnMap).getY()/1000000D);
System.out.println("clickOnMap wgsPoint = "+wgsPos);
map.addPlace(new Place(2, "Pressed", icon, wgsPos));
map.pointerReleased(x, y);
}
toInternalWgs() seems to be not available in the public library?! Is the manual equivalent of it would be just multiplying decimal lon,lat by 1000000?
Yes
Hi jaak,
Where do i find that pointerreleased() or pointerDragged() methods? Which listener i have to implement?
Thanks,
Kishore
Hi Jaak,
I am trying to implement it in Android. Not getting any solution. Please show me a way.
These pointer methods are for J2ME only, not in Android. There are other methods like onTouch in Android UI (View.OnTouchListener) which do similar things there.
Hi Jaak,
How do I get the Place object to move/remove, when I click on a Place marker?
And when I am dragging, the whole Mapview is moving and ACTION_MOVE action will be performed in OnTouchListener of MapView. Please help me out.
I am trying to use following logic using bbox but not working.. please help.. :(
if (markerDragStart)
{
double BBMaxLon;
double BBMaxLat;
double BBMinLon;
double BBMinLat;
double newLon;
double newLat;
synchronized(mapDisplay)
{
BBMaxLon = mapDisplay.getBoundingBox().getWgsMax().getLon();
BBMaxLat = mapDisplay.getBoundingBox().getWgsMax().getLat();
BBMinLon = mapDisplay.getBoundingBox().getWgsMin().getLon();
BBMinLat = mapDisplay.getBoundingBox().getWgsMin().getLat();
}
double perPixelLon = (BBMaxLon - BBMinLon)/getWidth();
double perPixelLat = (BBMaxLat - BBMinLat)/getHeight();
newLon = BBMinLon + x*perPixelLon;
newLat = BBMaxLat + y*perPixelLat;
synchronized(mapDisplay)
{
mapDisplay.removeAllPlaces();
Place currentPlace = new Place(1, new PlaceLabel("location"),
markerImage, new WgsPoint(newLon, newLat));
mapDisplay.addPlace(currentPlace);
mapDisplay.setMiddlePoint(currentPlace.getWgs());
}
}
else
{
mapDisplay.pointerDragged(x, y);
}
Parthiban Rajendran