Scaling and positioning a new path element on a raphael.js paper - javascript

I have a world map using raphael.js with a few countries highlighted using paths. My client has asked that I add China as a highlighted country. I located another raphael.js map with China in it and imported the coordinates.
It worked fine except that the position of the vector and it's size are not correct for the world map I am using. The z-index appears to also need to be increased.
I can bring element up by calling thismap.world.cn.toFront(); after it is drawn but the other elements do not require this so I am assuming I can adjust z-index with a coordinate edit?
Is it possible to manually scale and position the element? Are there GUI tools for manipulating the coordinates or do I need to use scale() in raphael.js to manipulate the element?
Coords look like
cn: "M777.533,179.567l-2.325,1.451l-2.326-0.871v-2.323l1.163-1.453l3.196-0.581h1.455l0.581,0.872l-1.163,1.451L777.533,179.567zM825.204,94.194l4.651,0.871l3.488,1.742l0.871,2.614h4.361l2.325-0.872l4.651-0.871l-1.454,2.323l-1.163,1.162l-0.871,2.904l-2.034,2.613l-3.198-0.291l-2.325,0.871l0.581,2.324l-0.29,3.194l-1.454,0.291v1.161l-1.744-1.451l-1.163,1.451l-4.067,1.162l0.289,1.453h-2.325l-1.452-0.872l-1.745,2.032l-3.198,1.453l-2.033,1.742l-3.781,0.871l-2.033,1.162l-3.197,0.871l1.452-1.453l-0.58-1.16l2.325-1.742l-1.455-1.453l-2.324,1.162l-3.197,1.742l-1.745,1.742l-2.615,0.291l-1.452,1.16l1.452,1.743l2.326,0.581v1.162l2.325,0.872l2.906-2.033l2.616,1.162h1.744l0.289,1.452l-3.777,0.871l-1.454,1.452l-2.615,1.453l-1.453,1.742l3.196,1.742l0.872,2.614l1.743,2.613l1.745,2.033v2.033l-1.745,0.581l0.873,1.453l1.455,0.87l-0.292,2.324l-0.873,2.323h-1.452l-2.034,3.194l-2.326,3.484l-2.327,3.195l-3.778,2.613l-4.069,2.323l-2.905,0.291l-1.744,1.162l-0.873-0.871l-1.743,1.452l-3.779,1.451l-2.906,0.291l-0.872,2.904l-1.454,0.29l-0.873-2.033l0.584-1.162l-3.488-0.872l-1.455,0.581l-2.615-0.87l-1.454-0.873l0.581-1.742l-2.615-0.581l-1.452-0.871l-2.328,1.451l-2.615,0.291h-2.034l-1.454,0.58l-1.453,0.582l0.29,2.903h-1.455l-0.289-0.581v-1.161l-2.034,0.87l-1.163-0.581l-2.035-1.162l0.872-2.033l-1.743-0.581l-0.873-2.613l-2.905,0.58l0.29-3.484l2.615-2.323l0.291-2.033l-0.291-2.323l-1.161-0.581l-0.873-1.452h-1.455l-3.194-0.291l1.161-1.161l-1.455-1.743l-2.034,1.162l-2.033-0.581l-3.198,1.742l-2.615,2.033l-2.326,0.29l-1.162-0.872h-1.453l-2.035-0.58l-1.454,0.58l-1.743,2.033l-0.292-2.033l-1.744,0.582L713,154.013l-2.906-0.581l-2.326-1.162l-2.034-0.581l-1.162-1.452l-1.454-0.291l-2.615-1.742l-2.326-0.871l-1.162,0.581l-3.781-2.033l-2.615-1.742l-0.873-2.904l2.036,0.291v-1.453l-1.163-1.161l0.293-2.324l-2.908-3.194l-4.361-1.161l-0.87-2.033l-2.036-1.451l-0.58-0.582l-0.292-1.742v-1.161l-1.743-0.582l-0.874,0.291l-0.579-2.324l0.579-0.871l-0.289-0.581l2.615-1.162l2.036-0.58l2.906,0.291l0.871-1.744l3.489-0.29l1.162-1.162l4.362-1.451l0.289-0.581l-0.289-1.743l2.033-0.581l-2.617-4.646l5.524-1.162l1.452-0.58l2.034-4.938l5.232,0.873l1.744-1.162v-2.904l2.328-0.291l2.033-1.742l1.163-0.29l0.581,2.032l2.326,1.452l4.067,0.872l1.746,2.323l-0.873,3.194l0.873,1.162l3.197,0.582l3.778,0.29l3.488,1.742l1.743,0.291l1.163,2.613l1.455,1.453h3.196l5.522,0.58l3.78-0.291l2.615,0.291l4.069,1.743h3.489l1.162,0.871l3.197-1.451l4.361-0.873l4.359-0.29l3.198-0.871l1.745-1.452l2.033-0.871l-0.581-0.872l-0.873-1.161l1.454-1.742l1.745,0.29l2.614,0.581l2.908-1.452l4.069-1.162l2.034-1.742l2.035-0.872l4.07-0.29l2.034,0.29l0.291-1.162l-2.325-1.741l-2.326-0.872l-2.036,0.872l-2.904-0.291l-1.455,0.291l-0.581-1.162l1.744-2.613l1.453-2.324l3.197,1.162l4.068-1.742v-1.162l2.328-2.903l1.452-0.872v-1.452l-1.452-0.871l2.325-1.162l3.486-0.58h3.491l4.067,0.58l2.617,1.162l1.744,2.903l0.871,1.161l0.874,1.453L825.204,94.194z",
And current map with China drawn looks like:

The answer is to use the translate(x,y) method eg
thismap.world.cn.translate(300, 100);
and the scale() method.

Related

Is there a way to configure Cesium entities to be displayed as ICRF?

My question is very similar to another one already solved.
I have to display a moving entity along with its path in ICRF. I previously had it working using CZML. But now I am replacing the CZML objects to entities. To configurate the entity's position I am using SampledPositionProperty and setting the reference frame in the constructor. The displayed result seems to be Earth fixed because the path looks like a spiral instead of an ellipse.
new SampledPositionProperty(ReferenceFrame.INERTIAL);
The shape of the path comes from the coordinates passed into the SampledPositionProperty.
You need to make sure the coordinates you're passing in have already been transformed into ICRF coordinates, forming an ellipse, not the Earth-fixed coordinates in the shape of a spiral.
Cesium will simply draw whatever shape you give it. The choice of reference frame on the SampledPositionProperty constructor there only controls whether your shape will be fixed to the Earth, or aligned to the ICRF frame over time, but it doesn't change the actual shape. So if you give it a spiral path, it will show you a spiral path. The conversion between coordinate systems is up to you (but can be done using Cesium helper functions, if needed).

How to retrieve the length and width of the drawn shape in google maps?

Using the google maps api, how do i get the dimensions of the drawn shape?
I want to get the dimensions and add some sort of labels on top of the drawn shape.
Here's an img showing what i'm trying to do
The event argument on overlay event doesn't show the length and width of the drawn shape. Hope somebody can help me with a solution for this. Thanks
You can use the getBounds() method of your Polygon to get the coordinates, and then use the latlng to compute for the distance.
This SO question has an Javascript implementation of how to compute the distance :
http://www.movable-type.co.uk/scripts/latlong.html

How can I rotate an overlay image on Google Maps?

I'm trying to place a series of overlays onto a Google Map. I'm following along with the sample code for ground overlays, but that only allows me to dictate image placement using north/south/east/west boundaries. The works as long as my image is a rectangle and oriented along longitude and latitude lines. I'd really like to be able to accurately place an image, including custom scale and angular orientation. That doesn't seem possible with a ground overlay.
So here's a possible use case. I'm building a website to help city planners test parking availability.
The city planner uses a Google map on the analysis website to select an area of the street with a polygon select tool.
The website script tests the selected polygon area for parking availability.
When we're done with the evaluation, I'd like the site to paste random images of cars into the page so the user can better visualize what's available.
I can create a rectangular plan view of a car, but I'm unable to figure out how to rotate the image by X degrees as required. Perpendicular to North/South/East/West (NSEW) is no problem, but I'm unable to angle it.
This should work no matter how the original map is oriented. The goal is the user sees a proposed solution, complete in the current map view, and to scale.
Obviously the image would have to be perfectly scaled to the visible map, and that's fairly easy to do (a minor latitude length adjustment may be required.)
(In this image, the city planner has just selected the area of interest via polygon selection tool. The next step is to evaluate the area, and paste in some parked cars, aligned and in scale!)
All the Google mapping native overlay tools I'm looking at rely on LatLngBounds class, hence the NSEW perpendicular alignment problem. I know I can calculate the desired angle, go to a php server, rotate a .png image with transparent background, per php imagerotate, but that seems like such a hack for a geo-mapping exercise. I could also pre-rotate the cars in a .png file and save them as red_car_15degrees.png, blue_car_30degrees.png, white_pickup_45degrees.png, (three different cars x 5 degree increments from 0 to 45 degrees) but that too, just feels like a hack.
Is there anyway to create a custom map overlay at a given desired orientation angle, so I can layer in the cars to show the city planner what's available? Many thanks.
I would draw and rotate in a <canvas> and then out that on.
EDIT:
place on canvas, ctx.rotate, c.toDataUrl(), and overlay that on your map.

How to scale a svg map to display on the web

I would like to add an interactive map of Europe on my website, as part of a web development course I am taking.
I am trying to use the raphael javascript library for that purpose. I tried to adapt the following example (map of Australia) from the raphaeljs website:
http://raphaeljs.com/australia.html
I am planning to use the following map of Europe, as a replacement for the map in the above example:
http://commons.wikimedia.org/wiki/File:Blank_map_of_Europe.svg
However, the coordinates from the svg file takes values between [0-1400] for the width and [0-1200] for the height. This is much too large to display on a webpage. Instead I would like to scale the map to, for instance, 700x600 pixels.
Is it possible to easily scale the map without having to change all the coordinates (there are thousands of them) manually?
Thanks for your help.
I think you should be able to scale your viewBox, so something like and it should scale ok.
I'm guessing in Raphael it may need something like...
var paper = Raphael('paper');
paper.setViewBox(0,0,1400,1400);

Use 3d model as icon without scaling in Google Earth Plugin

There're two types of objects we can place on the google earth.
The first one is 3d models - they have real size and they scale with dependency on the camera position.
The second one is icons and labels - they overlay the map and do not scale while the camera moves.
So is there a possibility to use 3d models like icons? That means I want to switch my png-icons with beauty 3d-models that do not scale and that have icon's behavior.
I know that there's access to the camera and object positions, and we can rescale 3d object with dependency on the distance every time when the camera or an object moves, but I believe there's simpler way without all these calculations and observables.
I would say no, there is no simple way to achieve this.
As you say, an icon doesn't have any geometry other than a location, but a 3D model is specifically defined by its location and its length, width, height, etc. Yes you could calculate the scaling and attempt to redraw the model based on the current view, but that wouldn't be trivial and I really doubt that the results would be very pleasing.

Categories

Resources