How to edit Feature position on map by draging? - arcgis

I need to move a feature position on a map, by dragging it on the map.
When using the map server, I'm able to do that, but I can't implement that on my HTML Map.
Couldn't find anything related to this on the documentation or searching for questions.
Thanks

Suppose your features are Graphic objects.
Add a mousedown event listener to the map
On map mousedown, verify if a feature intersect with a circle centered at the mousedown position (you will have to convert pixel to map units here);
If a feature intersects, add a map mousemove and a mouseup event listener
On map mousemove, modify the geometry of the feature with the position of the cursor (that will be easy for point feature, but more complex for polyline and polygon). Also you, should use a debounce or throttle function for this event listener to prevent over calculations.
On map mouseup, remove the mousemove and the mouseup event listeners
To calculate the radius of the circle, you will have to take in consideration the current extent of the map. Here is how you can calculate the radius:
function getSearchAtPointRadius(mapView) {
//20m if your map units are in meters
return 20 * (mapView.extent.xmax - mapView.extent.xmin) / mapView.width
}

Related

How can i get mouse click event element in cocoa

I receive events from clicks with a global monitor in macOS.
The NSEvent give me coordinates but i need to get the UIElement.
Using the accessibility API, i can get the focused element but i need the clicked element which is totaly different. For example, if i click on a textarea, i get a AXTextArea element. If i click on the application taskbar, the focused element remains AXTextArea which make sense. I want the element associated to the mouse event.
I found on the web a method called accessibilityHitTest which is supposed to retrieve the UIElement under a given NSPoint. I always get null so i am not sure this is supposed to work that way.
Maybe there is another function which retrieve the UIElement from a given point in the screen?
Here is what ive tried :
NSEvent *event; // My event received from global monitoring
id clickedObject = [self accessibilityHitTest:event.locationInWindow];
//This give me an error because self is not a NSWindow.
NSEvent *event; // My event received from global monitoring
id clickedObject =
[[NSApp keyWindow] accessibilityHitTest:event.locationInWindow];
//This give me null at every click.
Maybe this is not possible but i just which i could get the UIElement under my mouse click and not the focused UIElement.
You need to use AXUIElementCopyElementAtPosition() for this. Note that you have to be careful to provide the coordinates in the proper coordinate system. Since the event has no window associated with (because it's for a different app), NSEvent's locationInWindow uses the Cocoa coordinate system with the origin in the lower-left of the primary display, with y increasing in the up direction. AXUIElementCopyElementAtPosition() takes coordinates in the Core Graphics coordinate system with the origin in the upper-left of the primary display, with y increasing down. Basically, you do:
point.y = NSMaxY(NSScreen.screens[0].frame) - point.y;

How to listen active dragging event of an UWP UIElement?

How to track/listen active dragging event of UI Element in UWP. I added the flat CanDrag=true to enable the drag feature. Using the DragStarting and DragLeave can identify the start and end of drag. But want to get the X,Y coordinate of the UIElement on dragging. Any recommendation to achieve that? I dont want to use RenderTransform for this.
I don't think it's possible in standard Drag'n'Drop flow.
There're few options but they look like a crutch.
You may use manipulations and subscribe to Delta event. That's where RenderTransform comes in.
You may start some time loop and get visual position each frame. (The most crutchy idea)
Try to play wih IsHitTestVisible and subscribe to PointMove of some FrameworkElement behind.
Subscribe to PointEntered and PointExited to the elements you dragging over so they could fire events.
I prefer the first one. It's simple and it's plane.

How to add an onClick event handler to a canvas shape in Elm?

Is it possible to add an onClick event handler to Graphics.Collage.square?
I'd like to know the relative position of the click.
In Javascript, I could do something like this:
var canvas = document.getElementById('canvas');
var canvasPosition = {
x: canvas.offsetLeft,
y: canvas.offsetTop
};
canvas.addEventListener('click', function(event) {
console.log(event.x - canvasPosition.x, event.y - canvasPosition.y);
}, false);
Is that possible to do something similar in Elm?
Example would be appreciated.
In Elm, using the Canvas rendering, you should use the Mouse.clicks signal and react to changes in the signal. Here's a runnable example of how that would work:
import Graphics.Element exposing (Element, show)
import Mouse
clicks : Signal (Int, Int)
clicks =
Signal.sampleOn Mouse.clicks Mouse.position
main : Signal Element
main =
Signal.map show clicks
In essence, Mouse.clicks are the actual "events" we are interested in, so whenever one happens, we "sample" the Mouse.position signal to get the click position.
Signal.sampleOn produces a signal that updates with the value of the second parameter signal (here, the mouse position) whenever there is a change in the first parameter signal (here, the mouse clicks).
Now, just to get the result showing, we are also mapping the position to the show function in main.
You can also paste this code to http://elm-lang.org/try, compile and try clicking the right-hand side to see it working.
I implemented a proof-of-concept backbuffer test. It's pretty hacky but it might do the job.
If you don't like that, your only option is to find the mouse click location (which involves a very annoying conversion from the Mouse's top-left origin, y is down to Graphics.Collage's centered origin, y is up), and then do geometric collision detection. Which isn't too bad with circles and axis-aligned rectangles, but I get it, you want a general solution.
You can also consider using elm-svg which has typical DOM events like mouseenter, although I'm not sure how reliable the event dispatch is for e.g. convex shapes. Or you could abandon Elm entirely (sniff) and use D3.js with SVG.

How to apply UI virtualization to ScrollViewer in WinRT

Is it possible to apply UI virtualization to ScrollViewer in WinRT. In my application I am creating a line chart with the help of Polyline(Polyline embedded inside a scrollviewver). But in the current case, If it come more than 500 points. It blocks the UI during the time of interacting with the Map. So what I am trying to achieve is to apply kind of UI virtualization to scroll view. If anyone had any idea to solve this please help me.
The way I would handle a Polyline is I would break its data into sections, perhaps screen-wide ones (assuming horizontal-only scrolling), put a Canvas inside of the ScrollViewer, make the size (Width) of the Canvas the total size of the chart and put a few (say 5) Polyline controls in it and then on the ViewChanged event update the Polyline controls' Canvas.Left and Points properties to correspond to the area around the current view port of the ScrollViewer. That should give you smooth scrolling. Just don't add/remove or update the controls on each ViewChanged and only update Canvas.Left and Points when you need to - that is when you don't have a Polyline ready to display next to the current view port.

mouse coordinates in MouseHover event?

I know how to retrieve the mouse coordinate in a PictureBox.Click event though e
In a PictureBox.MouseHover, e does not return such information.
How do I get the mouse coordinates in a MouseHover event ? Is there a way ?
Thanks in advance.
Control.MouseHover "occurs when the mouse pointer rests on the control."
A typical use of MouseHover is to display a tool tip when the mouse pauses on a control within a specified area around the control (the "hover rectangle"). The pause required for this event to be raised is specified in milliseconds by the MouseHoverTime property.
So this event is not raised only whenever the mouse is over the control - there is a delay associated. So the position is somewhat irrelevant, as the mouse could have moved somewhat during that delay.
Do you really need to be using this event? As Dan-o mentioned, MouseMove passes a MouseEventArgs which does provide the coordinates, as you request. It may be the right option, depending on what exactly you're trying to do.
To get the mouse position at any time though, you can use the Cursor.Position property. This will give you the screen coordinates of the cursor. From here, you can call the Control.PointToClient method, to get the coordinates relative to a particular Control.