I'am trying to build a compass that heading to a annotation with Titanium on a map. It's already succeeded me to build a normal compass with the compass function in Titanium.
I am unable to make the compass point the right direction from the location. Has anyone a script or example what works?
if (Titanium.Geolocation.hasCompass){
var transform = Ti.UI.create2DMatrix();
// Settings
Titanium.Geolocation.showCalibration = true;
Titanium.Geolocation.headingFilter = 0;
Ti.Geolocation.getCurrentHeading(function(e){
if (e.error){
Titanium.API.info("error: " + e.error);
return;
}
var animationNorth = Titanium.UI.createAnimation({
transform : transform.rotate(e.heading.trueHeading),
duration : 50
});
// Rotate image to north
compassNorth.animate(animationNorth);
headingLabel.setText('geo - current heading: ' + e.heading.trueHeading);
});
Titanium.Geolocation.addEventListener('heading', function(e){
if (e.error){
Titanium.API.info("error: " + e.error);
return;
}
var animationNorth = Titanium.UI.createAnimation({
transform : transform.rotate(e.heading.trueHeading),
duration : 50
});
// Rotate image to north
compassNorth.animate(animationNorth);
headingLabel.setText('geo - current heading: ' + e.heading.trueHeading);
});
} else {
headingLabel.setText("No Compass on device");
}
Related
I want to get animation object.location in gwd when drag other object .
Animation Object is moving y axis and drag item is waiting to get that animation object x axis.
What should I do ?
Dragstart code event
gwd.dragger = this;
event = (event.changedTouches ? event.changedTouches[0] : event);
gwd.s = window.getComputedStyle ? getComputedStyle(this, null) : this.currentStyle;
gwd.dX = event.pageX - parseInt(gwd.s["left"]);
gwd.dY = event.pageY - parseInt(gwd.s["top"]);
Dragmove drag event
if (gwd.dragger) {
event = (event.changedTouches ? event.changedTouches[0] : event);
gwd.actions.events.setInlineStyle(gwd.dragger.id, "left:" + (event.pageX - gwd.dX) + "px; top:" + (event.pageY - gwd.dY) + "px");
}
Dragstop event
gwd.dragger = null;
I want to get animated item left and top values pixel when drag
You can see this my ads.
https://doc-14-10-adspreview.googleusercontent.com/preview/9o5bees06oeguhr10neq55qcti27eh7n/2ma5s2dmjnvulveo4uos4qfu7ifos8ps/1664409600000/90358308/previewuser/gwd.90358308?render=blank&creativeId=gwd.90358308&irsk=CICAgODErP3t8gE&ecId=AOgHqNpAgFX7nq3p6KSPl2n47gS0-gxu3Aa9jhkOsuFMEnrCJDOlIJQMG7XhxKQuzLKQN98dGl9n
I have a geojson polygon adding to the map with the click of a button. I also have the style of the polygon changing on the mousedown event on the geojson and the x/y coord pairs (the geojson geometry) printing to the console accessing it through the queryRenderedFeatures call on the API.
I am now wanting to make the polygon draggable like the point example (links below) on the mousedown event on the polygon and be able to move it on the map, updating the x/y coords of the polygon nodes throughout the mousedown event, but keeping the geojson size intact throughout the drag.
Is straight mapbox-gl-js the way to do this, or should I be feeding a pre-configured geojson polygon into a mapbox-gl-draw - draw polygon mode on a user's action?
Any suggestions or examples?
API Drag A Point Example
Drag A Point GitHub Code
Try this
var isDragging = false;
var startCoords;
map.on('click', function(e) {
var features = map.queryRenderedFeatures(e.point, { layers: ['polygon-layer'] });
var polygon = features[0];
if (!polygon) return;
startCoords = polygon.geometry.coordinates[0];
});
map.on('mousedown', function(e) {
isDragging = true;
});
map.on('mousemove', function(e) {
if (!isDragging) return;
var coords = map.unproject(e.point);
var delta = {
lng: coords.lng - startCoords[0],
lat: coords.lat - startCoords[1]
};
polygon.geometry.coordinates[0] = polygon.geometry.coordinates[0].map(function(coord) {
return [coord[0] + delta.lng, coord[1] + delta.lat];
});
map.getSource('polygon-source').setData(polygon);
});
map.on('mouseup', function(e) {
isDragging = false;
});
the polygon is being stored as a GeoJSON feature, and the polygon layer and source are named 'polygon-layer' and 'polygon-source', respectively. You will need to adjust these names to match your setup.
I built a map with Leaflet (inside a Qlikview extension) with many markers.
I want my users go to the map and when they double click on a marker, it displays coordinates.
With the following code, when I click on a marker, I have always coordinates of last marker fetched, not the selected one.
I want to put coordinates in latSel e lonSel variables.
for (var i=0,k=_this.Data.Rows.length;i<k;i++){
var row = _this.Data.Rows [i];
var latitude = parseFloat(row[0].text.replace(",","."));
var longitude = parseFloat(row[1].text.replace(",","."));
//Check to see coordinates are valid
if (latitude != NaN && latitude !='' && latitude <= 90 && latitude >= -90 && longitude != NaN && longitude !='' && longitude <= 180 && latitude >= -180) {
var latlng = new L.LatLng(latitude, longitude);
var poptext = 'Lat & Long:'+latlng+'<br/>'+ row[2].text +'<br/>'+ 'Measure: ' + row[4].text;
var marker = L.marker(latlng).addTo(map).bindPopup(poptext);
marker.on('dblclick', function(e){
latSel = marker.getLatLng().lat;
lonSel = marker.getLatLng().lng
//_this.Data.SelectTextsInColumn(0, true, latSel);
alert("latitude = " + latSel);
});
} else {
//
}
}
What I'm doing wrong?
Thanks in advance.
Assigning onClick listeners in loops can be a bit tricky (search for "javascript onclick loop" in your favourite search engine and you will find some solutions).
Instead of using the marker variable, in Leaflet you can use the variable this inside the callback which refers back to the marker, like so:
marker.on('dblclick', function(e){
latSel = this.getLatLng().lat;
lonSel = this.getLatLng().lng;
alert(latSel);
});
See demo code here: http://plnkr.co/edit/RU3SsoI6A16AYOQAq0xV?p=preview
How do I implement drag and drop for mobile devices in Snap.svg? Touch drag and drop does not seem to be built into the Snap.svg drag and drop functionality.
Here is an attempt to do a drag and drop that will work for either mouse or touch handlers.
It does a quick check on the first parameter to see if its a number (so a mouse drag ), or an object ( so a touchevent ).
It then takes the first element of the changedTouches list. I assume this should be sufficient, but maybe one would want to loop through the touches list if necessary.
The circle should work with either mouse or touch, the rect only with touch.
var s = Snap(400,400);
var rect = s.rect(20,20,40,40);
var circle = s.circle(60,150,50);
var move = function(dx,dy,x,y) {
var clientX, clientY;
if( (typeof dx == 'object') && ( dx.type == 'touchmove') ) {
clientX = dx.changedTouches[0].clientX;
clientY = dx.changedTouches[0].clientY;
dx = clientX - this.data('ox');
dy = clientY - this.data('oy');
}
this.attr({
transform: this.data('origTransform') + (this.data('origTransform') ? "T" : "t") + [dx, dy]
});
}
var start = function( x, y, ev) {
if( (typeof x == 'object') && ( x.type == 'touchstart') ) {
x.preventDefault();
this.data('ox', x.changedTouches[0].clientX );
this.data('oy', x.changedTouches[0].clientY );
}
this.data('origTransform', this.transform().local );
}
var stop = function() {
}
rect.touchstart( start );
rect.touchmove( move );
rect.touchend( stop );
circle.drag(move, start, stop )
jsfiddle
I just starting coding with Google Earth using the GEPlugin control for .Net and still got a lot to learn.
What has got me puzzled is when I try to drag a polygon.
The method below is called whenever the mousemove event fires and should be moving each point of the polygon while retaining the orginal shape of the polygon. The lat / long for each point is changed but the polygon does not move position on the map.
Will moving a point in a polygon cause it to redraw, do I need to call a method to force a redraw or perhaps do something else entirely?
Thanks!
private void DoMouseMove(IKmlMouseEvent mouseEvent)
{
if (isDragging)
{
mouseEvent.preventDefault();
var placemark = mouseEvent.getTarget() as IKmlPlacemark;
if (placemark == null)
{
return;
}
IKmlPolygon polygon = placemark.getGeometry() as IKmlPolygon;
if (polygon != null)
{
float latOffset = startLatLong.Latitude - mouseEvent.getLatitude();
float longOffset = startLatLong.Longitude - mouseEvent.getLongitude();
KmlLinearRingCoClass outer = polygon.getOuterBoundary();
KmlCoordArrayCoClass coordsArray = outer.getCoordinates();
for(int i = 0; i < coordsArray.getLength(); i++)
{
KmlCoordCoClass currentPoint = coordsArray.get(i);
currentPoint.setLatLngAlt(currentPoint.getLatitude() + latOffset,
currentPoint.getLongitude() + longOffset, 0);
}
}
}
}
Consider voting for these issues to be resolved
http://code.google.com/p/earth-api-utility-library/issues/detail?id=33
http://code.google.com/p/earth-api-samples/issues/detail?id=167
You may find some hints at the following link:
http://earth-api-utility-library.googlecode.com/svn/trunk/extensions/examples/ruler.html
UPDATE:
I've released the extension library: https://bitbucket.org/mutopia/earth
See https://bitbucket.org/mutopia/earth/src/master/sample/index.html to run it.
See the drag() method in the sample code class, which calls setDragMode() and addDragEvent() to enable dragging of the KmlPolygon.
I successfully implemented this using takeOverCamera in the earth-api-utility-library and three events:
setDragMode: function (mode) {
// summary:
// Sets dragging mode on and off
if (mode == this.dragMode) {
Log.info('Drag mode is already', mode);
} else {
this.dragMode = mode;
Log.info('Drag mode set', mode);
if (mode) {
this.addEvent(this.ge.getGlobe(), 'mousemove', this.dragMouseMoveCallback);
this.addEvent(this.ge.getGlobe(), 'mouseup', this.dragMouseUpCallback);
this.addEvent(this.ge.getView(), 'viewchange', this.dragViewChange, false);
} else {
this.removeEvent(this.ge.getGlobe(), 'mousemove', this.dragMouseMoveCallback);
this.removeEvent(this.ge.getGlobe(), 'mouseup', this.dragMouseUpCallback);
this.removeEvent(this.ge.getView(), 'viewchange', this.dragViewChange, false);
}
}
},
This is in a utility library within a much larger project. dragMode is a boolean which adds and removes events. These three events control what happens when you drag. addEvent and removeEvent are my own wrapper functions:
addEvent: function (targetObject, eventID, listenerCallback, capture) {
// summary:
// Convenience method for google.earth.addEventListener
capture = setDefault(capture, true);
google.earth.addEventListener(targetObject, eventID, listenerCallback, capture);
},
removeEvent: function (targetObject, eventID, listenerCallback, capture) {
// summary:
// Convenience method for google.earth.removeEventListener
capture = setDefault(capture, true);
google.earth.removeEventListener(targetObject, eventID, listenerCallback, capture);
},
Ignoring the minor details, all the important stuff is in the callbacks to those events. The mousedown event locks the camera and sets the polygon I'm dragging as the dragObject (it's just a variable I'm using). It saves the original lat long coordinates.
this.dragMouseDownCallback = lang.hitch(this, function (event) {
var obj = event.getTarget();
this.lockCamera(true);
this.setSelected(obj);
this.dragObject = obj;
this.dragLatOrigin = this.dragLatLast = event.getLatitude();
this.dragLngOrigin = this.dragLngLast = event.getLongitude();
}
The mousemove callback updates to the latest lat long coordinates:
this.dragMouseMoveCallback = lang.hitch(this, function (event) {
if (this.dragObject) {
var lat = event.getLatitude();
var lng = event.getLongitude();
var latDiff = lat - this.dragLatLast;
var lngDiff = lng - this.dragLngLast;
if (Math.abs(latDiff) > this.dragSensitivity || Math.abs(lngDiff > this.dragSensitivity)) {
this.addPolyCoords(this.dragObject, [latDiff, lngDiff]);
this.dragLatLast = lat;
this.dragLngLast = lng;
}
}
});
Here I'm using some fancy sensitivity values to prevent updating this too often. Finally, addPolyCoords is also my own function which adds lat long values to the existing coordinates of the polygon - effectively moving it across the globe. I do this with the built in setLatitude() and setLongitude() functions for each coordinate. You can get the coordinates like so, where polygon is a KmlPolyon object:
polygon.getGeometry().getOuterBoundary().getCoordinates()
And of course, the mousedown callback turns off the drag mode so that moving the mouse doesn't continue to drag the polygon:
this.dragMouseUpCallback = lang.hitch(this, function (event) {
if (this.dragObject) {
Log.info('Stop drag', this.dragObject.getType());
setTimeout(lang.hitch(this, function () {
this.lockCamera(false);
this.setSelected(null);
}), 100);
this._dragEvent(event);
this.dragObject = this.dragLatOrigin = this.dragLngOrigin = this.dragLatLast = this.dragLngLast = null;
}
});
And finally, _dragEvent is called to ensure that the final coordinates are the actual coordinates the mouse event finished with (and not the latest mousemove call):
_dragEvent: function (event) {
// summary:
// Helper function for moving drag object
var latDiff = event.getLatitude() - this.dragLatLast;
var lngDiff = event.getLongitude() - this.dragLngLast;
if (!(latDiff == 0 && lngDiff == 0)) {
this.addPolyCoords(this.dragObject, [latDiff, lngDiff]);
Log.info('Moved ' + latDiff + ', ' + lngDiff);
}
},
The mousemove callback isn't too important and can actually be ignored - the only reason I use it is to show the polygon moving as the user moves their mouse. Removing it will result in the object being moved when they lift their mouse up.
Hopefully this incredibly long answer gives you some insights into how to implement dragging in the Google Earth API. And I also plan to release my library in the future when I've ironed out the kinks :)