I noticed that the saved map is always one/two scales smaller than the map I viewed.
I passed the current map extent to save map. I guess is the ratio of width/height does not match the ration of width/height of saved image.
how can I find the appropriate width/height of the image to save in order to keep the current map scale? in that case, I understand that I might lose some portions of map, correct?
Thanks,
Saved map image not the same scale of the viewed?
Hi guangming,
A workaround is that we send the extent of client Map to controller by an ajax firstly. Then set the CurrentExtent of server map as extent passed by client. Then the server side map has a same scale as client side, the saved image should work.
Hope it helps and any question please feel free to let us know.
Thanks,
Kevin
that’s what I did!
are you sure that will? It did not for me.
Hi guangming,
Is it appropriate for you guys to generate
the image size same as Map size? Please
follow below codes and have a try? This works on our end.
Client:
function
saveMap() {
var
params = { mapExtent: Map1.getOpenLayersMap().getExtent(), w: Map1.size.w, he: Map1.size.h };
Map1.ajaxCallAction(
'@ViewContext.RouteData.Values["Controller"].ToString()'
,
'ClickEvent'
, params, mapCallback);
}
Controller:
[MapActionFilter]
public
void
ClickEvent(Map map, GeoCollection<
object
> args)
{
var points = args[0].ToString().Split(
','
).Select(item =>
double
.Parse(item)).ToArray();
RectangleShape extent =
new
RectangleShape(points[0], points[3], points[2], points[1]);
map.CurrentExtent = extent;
Bitmap image = map.GetBitmap(
int
.Parse(args[1].ToString()),
int
.Parse(args[2].ToString()) - 400);
image.Save(Path.Combine(Environment.GetEnvironmentVariable(
"TEMP"
),
"map.png"
));
}
Please feel free to let us know if this not works.
Thanks,
Kevin
what you see is what you get: if the map scales do not match, it is a problem.
I did figure it out. now I know more about how your API work together. thanks,
Hi Guangming,
I am glad to know Kevin’s code help you know more about our APIs.
Regards,
Don