Drag and drop objects simultaneously [closed] - google-maps

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I face a problem... and am looking for a solution or an idea. I want to drag drop several objects (markers,polylines,...) simultaneously, but I do not know if this is possible ...
Does anyone have an idea ?
Thanks in advance !
Regards,
Sebastien
Thanks Nils !!!
You give me the good way !
Here you have how i've made it possible :
google.maps.event.addListener(window["Overlay" + i] , 'click', function(event) {
var path = this.getPath();
google.maps.event.addListener(path, 'set_at', function(indEdited,newLatLng){
var oo = this.getAt(indEdited);
diffLat = (newLatLng.lat() - oo.lat());
diffLng = (newLatLng.lng() - oo.lng());
moveOverlay(this,indEdited,diffLat,diffLng);
var temp = "Do you want to me the others overlays ?"
if (fromPath == lastPath )
{
if ( confirm(temp) ){
moveOthersOverlays(diffLat,diffLng);
}
}
});
});

The problem is that it's only markers that you can drag n' drop, so you must design the functionality with this in mind.
First we need to now the starting position, this is done with the dragstart event. Please not that you have to do this on all your markers.
var startLatLng;
google.maps.event.addListener(marker, 'dragstart', function(){
marker.getPosition()
});
You will utilize the function the drag event, and loop over all objects. I will utilize pseudo code here, let me know if it's something that is unclear. The assumption is that you save your markers in an array
google.maps.event.addListener(dragmarker, 'drag', function(){
end = dragmarker.getPosition();
for (marker in markers){
// Don't care about marker being dragged
if (dragmarker == marker)
continue;
current = marker.getPossition();
// Bellow we create a new position for the marker by calculating the difference
// and add it to the current possition of the marker
marker.setPosition(new google.maps.LatLng(
current.lat() + (end.lat() - start.lat()),
current.lng() + (end.lng() + start.lng()));
}
// Same same for the polylines but you will have to loop over the path
});
Please note that this will be really slow if there are alot of objects that you are moving around. But this works great for me when moving a couple of markers and a small polyline. Also, please note that the code is a bit crude, I just wanted to show how it's done. In my solution I'm storing my markers and polylines in objects that will update them self.
You can check out my code at this github repo

Related

Select multiple entities in a datasource with Cesium

I am trying to write a function where I can select multiple buildings of GeoJSON and/or CZML in Cesium
for example with the ctrl button held down, I will be able to create a list to select several buildings, and also change the color of the selected building as well.
I can change the color of one selected building now, and was told I should use the (entity.push) to add to the a list. but I'm still stuck!
Here is my initial code
*var scene = viewer.scene;
var handler = viewer.screenSpaceEventHandler;
handler.setInputAction(function(click) {
var pickedObject = scene.pick(click.position);
if (Cesium.defined(pickedObject) ) {
highlightedEntity= pickedObject.id;
// console.log (pickedObject.id);
} else{
highlightedEntity = undefined;
}
},Cesium.ScreenSpaceEventType.LEFT_CLICK);*
can someone help me out in completing it?
Here you can find a sample of the geojson

Dynamically change polygon position in cesium

I'm trying to draw few polygons that dynamically change their position.
The problem is that by using:
onUpdatePolygonData(data){
/// DO SOME CALCULATIONS TO GET point1, point2 point3...
if(Cesium.defined(entity.polygon)
entity.polygon.hierarchy = new Cesium.PolygonHierarchy([point1, point2, point3])
else entity.polygon = viewer.entities.add({
polygon = new Cesium.PolygonGraphics({
hierarchy: new Cesium.PolygonHierarchy([point1, point2, point3])
})
});
}
The result is disturbing blinking on the map.
Updating location occurs roughly once in 40ms though seems like frequency of updates have nothing to do with it.
Anyone knows a way to make the changes smoother?
Thanks for help,
David.
You need to use Callbackproperty, it executed every frame so it won't blink and be smoother.
In typescript you can write:
let poly = viewer.entities.add({
polygon: {
hierarchy: new CallbackProperty (() => {
return new PolygonHierarchy([point1, point2,
point3]) ;
}, false)
});

AS3, variables outside event handler function?

I have searched arond, but cant seem to find a proper answer to this. Lets say we have a super basic program which adds two numbers from 2 input text fields togehter and prints them out. Why cant i accses variables outside the event handler function? And what do i have to do in order to achieve this? The code is on a frame.
Why does this example not work? :
btn.addEventListener(MouseEvent.CLICK, cal);
var fnum:Number = Number(txt1.text);
var snum:Number = Number(txt2.text);
function cal(evt:MouseEvent){
txtOutput.text = String(fnum + snum);
}
And this example work?:
btn.addEventListener(MouseEvent.CLICK, cal);
function cal(evt:MouseEvent){
var fnum:Number = Number(txt1.text);
var snum:Number = Number(txt2.text);
txtOutput.text = String(fnum + snum);
}
I hate to be this guy, but I can't get it to replicate whats happening for you..
The only assumption that I can make is that the txt1.text & txt2.text aren't set yet when the button is clicked in example 1. Feel free to zip your project and dropbox it to me if you want me to investigate further :)

Best way to make this game AS3 [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm making a game as a part of my unit for uni but I don't know the best way of doing it as i'm new to AS3. I have 8 guests in a party each different and has different personalities, hobbies and interests. The game works like this, if you click on a guest and click anywhere on stage then that guest will move towards it. If you click on a guest and then click on another guest, the guest you clicked on first will move towards the guest you clicked on second and when they are close they will talk to each other.
All the 8 guests will share the same function and code in terms of the moving around. I have got the click and move part done but it was done on a Guest01 class but all the guest will have it the same. Should I create 8 different classes for each guest or should I do it using arrays. I really don't know how to start on this. Below is the code for click and move:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.*;
public class Guest01 extends MovieClip
{
var walkSpeed:Number = 5;
var oldPosX;
var oldPosY;
var myGlow:GlowFilter = new GlowFilter();
public function Guest01()
{
addEventListener(MouseEvent.MOUSE_OVER, addGlow);
}
public function addGlow(event:MouseEvent):void
{
filters = [myGlow];
addEventListener(MouseEvent.MOUSE_OUT, removeGlow);
addEventListener(MouseEvent.CLICK, ready);
}
function removeGlow(event:MouseEvent):void
{
filters = [];
}
public function ready(event:MouseEvent):void
{
filters = [myGlow];
stage.addEventListener(MouseEvent.MOUSE_DOWN, walk);
removeEventListener(MouseEvent.MOUSE_OUT, removeGlow);
}
function walk(event:MouseEvent):void
{
oldPosX = parent.mouseX;
oldPosY = parent.mouseY;
rotation = Math.atan2(oldPosY - y,oldPosX - x) / Math.PI * 180;
filters = [];
stage.removeEventListener(MouseEvent.MOUSE_DOWN, walk);
stage.addEventListener(Event.ENTER_FRAME, loop);
}
function loop(event:Event):void
{
var dx:Number = oldPosX - x;
var dy:Number = oldPosY - y;
var distance:Number = Math.sqrt((dx*dx)+(dy*dy));
if (distance<walkSpeed)
{
// if you are near the target, snap to it
x = oldPosX;
y = oldPosY;
removeEventListener(Event.ENTER_FRAME, loop);
}
else
{
x = x+Math.cos(rotation/180*Math.PI)*walkSpeed;
y = y+Math.sin(rotation/180*Math.PI)*walkSpeed;
}
}
}
}
I have got the click and move part done but it was done on a Guest01 class but all the guest will have it the same. Should I create 8 different classes for each guest or should I do it using arrays.
You should not create 8 different classes for 8 different Guests but you should try to re-use the classes and methods for different Guests.
I have 8 guests in a party each different and has different personalities, hobbies and interests.
You would want to create one Guest class and keep all the properties (personalities, hobbies etc.) as the variables in the class. You'll have to initialize the Class for different Guest in the start based on the profile the guest selects (or random). Also all the methods for Guest (like walk, glow etc.) would be the methods of the class itself.
Hope it helps to give you some direction.
Just tried to answer your question from a different post. You need to break down the game into simple actions like moving the user from one place to another, calculating the offset position a user should move to if they wan to move to another user, calculating the position of elements for displaying a users hobbies and interests, ect.
Have you ever programmed in an object oriented language before? There are some fundementles that you must have a firm grasp of before taking on a project like building a game. Based on your last post, your next focus should be the following methods.
Since you have already written a function for relocating a player based on a user click you should write the following functions:
Inside the clickToMove() function ( or whatever you called it). Write an if test to see if the relocating click selects an empty location or a location with a user on it. If the user is present you need to write another method for offsetting the position of the player that is to move, otherwise the players will be layered on top of each other.
I'm boarding a plane now will post again soon

Snap to nearest marker

i am using GoogleMaps and i have 2 or more markers and they are draggable.
I want to snap 2 markers if they are near and merge them into 1.
is this possible ?
Can someone give me pointers .. how i can realize that ?
You need to handle the drag event on the GMarker object. The trick is what do you do when you detect that you are near enough to another marker to snap them together. I played around a little with this and thought maybe hiding the currently dragged marker might be a good way to go.
GEvent.addListener(marker, "drag", function(point) {
// iterate over your points and for each otherPoint...
if (near (point, otherPoint))
{
// hide this marker
marker.hide ();
// move nearby marker to indicate merge?
// then delete the dragged marker on the dragend (if it was merged)
}
}
Not an entirely elegant solution, but it might suit your purposes.
Edit: I wondered if you were looking for the code to check nearby points, so I updated my example to do that:
function near (point1, point2)
{
sw = new GLatLng(point2.lat() - 0.005, point2.lng() - 0.005);
ne = new GLatLng(point2.lat() + 0.005, point2.lng() + 0.005);
var bounds = new GLatLngBounds(sw, ne);
if (bounds.contains (point1))
return true;
return false;
}