Draw a point on ESRI.ArcGIS.Mobile.WPF - wpf

I am using ESRI.ArcGIS.Mobile.WPF dll to access the Map.
Using MapDoubleClick event is giving me X and Y coordinates. I need help in drawing a point on the Map based on X and Y coordinates I get from the doubleclick event.
I see that Map.Invalidate() must be used but ArcGis Mobile for WPF do not have Invalidate()

Related

Single Axis Zoom in D3 & React

I am currently trying to make a simple graph using D3 and React, where it is possible to zoom in/out on both axes, or on one of the two axes separately. An example of such a graph made only with D3 is available here (http://bl.ocks.org/jgbos/9752277).
I managed to get the same behaviour using D3 and React, as you can see in this sandbox (https://codesandbox.io/s/objective-cohen-b92pr). This example works almost perfectly, but I sometimes see a "jump" when, for example, I zoom in on Y, then X and then both (see gif below).
My guess is that d3 stores a zoomTransform object {k, x, y} for each container (x-axis-listener, y-axis-listener & svg) on which the zoom event is called. I suppose we should be able to share the same instance of the object between all the containers, but so far I have not been successful.
Any guesses?
Thanks a lot !
There is a good reason why you can either have X and Y zoom separately, or have a single zoom factor in your graph (which applies to both X and Y), but you cannot have a situation where you can smoothly change them all. That's why:
A D3 zoom identity object has 3 attributes: x, y, k, where x and y are offsets from the initial pos (0,0) and k is the current zoom factor (1 by default).
Now, if you want to manage 3 separate zoom identities, you have actually 3 different objects {xV, yV, kV} for vertical zoom, {xH, yH, kH} for horizontal and {xG, yG, kG} for the global zoom. When you rescale, you can apply xV to xH, yH to yG and so on, but you cannot apply two different values (kV and kH) to one (kG), you will need to choose between them (otherwise you have a logical contradiction here).
UPD: You can, however, replace zoomBoth callback with mouseWheel event handler, take X and Y zoom identities, change both of them proportionally (divide or multiply to the same number) and then apply changed zoom identities to both X and Y scales. It's possible :)
I finally came up with a working solution, which can be found here: https://codesandbox.io/s/quirky-yalow-3y6q4. This is mainly a refacto in React of this code observable: https://observablehq.com/#d3/x-y-zoom.
I'm using only one global transform object in the dom, and using the useState hook to store the global transform previous value, and one transform object for each axis.
The actual and the previous global transforms object allows me to retrieve the parameters to pass to the transform.translate and transform.scale methods in order to update the axis transforms object accordingly to where my mouse is.
This feels really "hacky" to me and I there should be a more elegant way of doing this.

Plot a known pixel (x,y) from original image using custom Bing Maps WPF tiles

I am trying to use the Bing Maps WPF control to render custom map tiles from an image of a fictional game world map, but I also need to plot X,Y values on the map from the original world image (sort of like an in-world GPS).
The image is 5720x5720 and I already have working (in a different application) a function that manually crops, scales and redraws sections of the image and plots the pixelX and pixelY coordinates in a PictureBox. I would like to get the same functionality working using the map control.
I used this Photoshop plugin to cut the tiles from the original custom image (works like maptiler for google mapes)
https://github.com/bramus/photoshop-google-maps-tile-cutter/
The problem is I know the X,Y values to plot from the original image, but I'm not not quite sure how to calculate Lat/Long for drawing a point in the custom tile system.
<m:Map Name="Map">
<m:Map.Mode>
<!-- set empty map mode, i.e. remove default map layer -->
<m:MercatorMode/>
</m:Map.Mode>
<local:MyTileLayer UriFormat="file:///C:/map_tiles/{z}_{x}_{y}.jpg"/>
</m:Map>
The map is displaying great and everything looks fine using the custom map tiles. I found this link that provides a class for converting PixelXY to LatLong in the TileSystem, but they are all for realistic world points.
https://msdn.microsoft.com/en-us/library/bb259689.aspx
My custom map tiles are actually for a fictional map for a game so I don't believe the projection and earth-curvature calculations are needed in my situation.
How might I go about plotting a point accurately in the Bing Maps WPF control if I only know the X,Y pixel coordinates from the original untiled image?
Given that your 5720x5720px map image covers the standard Bing Maps (or Google Maps or OpenStreetMap) coordinate range of longitude = -180..180 and latitude = -85.0511..85.0511, the following method would convert from image pixel coordinates to lat/lon according to the Mercator projection:
public static void PixelXYToLatLon(
double pixelX, double pixelY, out double latitude, out double longitude)
{
var imageSize = 5720d;
var maxLatitude = 85.05112878; // = Math.Atan(Math.Sinh(Math.PI)) / Math.PI * 180d;
var y = (0.5 - pixelY / imageSize) * (2d * maxLatitude);
latitude = Math.Atan(Math.Sinh(y * Math.PI / 180d)) / Math.PI * 180d;
longitude = (pixelX / imageSize - 0.5) * 360d;
}
The imageSize variable might of course also be a method parameter.
If you use MapTiler (http://www.maptiler.com) to create the tiles you have two ways how to achieve what you want:
A) Map your game map to the artificial world with Lat/Lon coordinates
In this case you will map the world coordinates to your pixel coordinates. The tiles must be prepared in a correct way, same as those for real world maps.
To create the tiles with MapTiler you should follow this steps:
Choose "Mercator tiles" in the first step
Drop in your image file
Choose "Web mercator (EPSG:3857)" in the dropdown in the "Coordinate system" dialog - it is a square image of the whole world and you don't want to deform it.
Choose "Bounding box (West South East North)" in the dialog "Geographical location" and copy&paste in the input the world coordinates: "-20037508.342789244 -20037508.342789244 20037508.342789244 20037508.342789244"
Render the tiles
With this approach you can load the tiles in your Bing Maps WPF control and position the markers or other data by using Lat/Lon coordinates.
The point [0,0] is going to be center of the image, and you can calculate the other lat/lon coordinates appropriately.
See this page and source code down on the page:
http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
The globalmaptiles.py code embedded in the page is available in different languages including C# (.cs) if you need it. It has been ported by other people from our code.
B) Stay in raster coordinates
A different approach - where you create the map tiles in the original raster coordinates of the input file. There are no Lat/Lon involved, coordinate system is in pixels and you can draw markers and polygons in pixel coordinates as well. MapTiler gives you sample JavaScript viewer in Leaflet and in OpenLayers. Other viewers you have to patch yourself for using with pixel coordinates. To generate the tiles just choose "Raster tiles" - as in this tutorial: http://youtu.be/9iYKmRsGoxg?list=PLGHe6Moaz52PiQd1mO-S9QrCjqSn1v-ay
I expect the tiles made with your Photoshop plugin are going to be similar to the raster coordinates made with MapTiler.

Phonegap-Angular-HammerJs hybrid web application: Get X/Y for a hm-tap event

In our Phonegap-Angular-HammerJs hybrid web application, I am trying to get the X and Y coordinates for a hm-tap event. But I found hm-tap event does not have the clientX and clientY attributes like an ng-click event.
How can we find the X/Y coordinates for a hm-tap/hmTap event?
You should be able to access
ev.gesture.touches[0].pageX;

Getting Relative Position of a Rotating Camera

I have a Viewport3D with a 3D model composed of multiple smaller components centered at the origin. I'm animating the PerspectiveCamera to rotate about the Y-axis using an AnimationClock created from a DoubleAnimation to create a rotating effect on the model. In addition, I have another rotateTransform3D assigned to the camera's transformgroup to enable the user to orbit around and zoom in-out of the model using the mouse.
I want to be able to translate each component as it is being selected to move in front of the rotating camera. However, I don't know how to get the position of the camera relative to the 3D model because the coordinate system of camera is being animated and transformed by the user's input.
Is there a way to get the offset between two coordinate systems?
Any help or suggestions would be appreciated.
Thanks,

WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25).
When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)...
How can I achieve this?
Thanks!
Mark
Just use VisualTreeHelper.HitTest with the callback.
If you have a Viewport3D containing the model, you can just pass in a PointHitTestParameters containing the mouse location.
If you need to operate directly on a Visual3D, pass in a RayHitTestParameters computed from your camera parameters and the mouse location.
In either case your callback will be called with a RayTestHitResult, and if you hit a mesh it will be a RayMeshGeometry3DHitTestResult. This includes a Point3D property telling you the 3D point in space that was hit, and also the mesh and triangle that was hit.
See 3D Hit testing for more details.

Resources