convert world to pixel

Topics: Algorithms, SharpMap Project, Web Controls
Jan 28, 2009 at 10:28 AM
i have a world point with the real geometry and i need to draw graphics point(in ajaxmap with function in class) but i need to convert world point to pixel of in map

i converted sharpmap_pixeltomap forumla to revers but it isn't work

have you any idea?
Jan 28, 2009 at 11:25 AM
Edited Jan 28, 2009 at 11:26 AM
The method Map.WorldToImage converts a point in real-world coordinates to the image coordinates and Map.ImageToWorld does the reverse hth jd
Jan 29, 2009 at 10:28 PM
thanks johndiss i need this function ajaxmap.js in ajax map control and write this with map.worldtoimage

function SharpMap_MapToPixel(x,y,obj){
     var p=new Object();
     p.x = Math.round(((x - obj.minX) * obj.container.offsetWidth) / obj.zoom );
     p.y = Math.round(((( obj.maxY - y)*obj.container.offsetWidth)/obj.zoom));
     return p;

in mnormal ajax map use wz_jzgraphics and in ajaxmap.js use all function in wz_jzgraphics with jg keyword i need to know where is define jg??? and can i define the new object from this file and use it????
Jan 29, 2009 at 10:37 PM
Hi navid, I am afraid I dont really follow.. but if you are trying to locate the declaration of bit of javascript code you may find the firebug plugin for firefox useful.. hth jd
Jan 30, 2009 at 1:58 PM
thanks johndiss i use this extention and i see defention in DOM but i unknow location of this defination.
i have one question
in ajaxmap call all function in solation call twice
once ajaxMap.Map = MapHelper.InitializeMap(new System.Drawing.Size(10, 10));
and  once ajaxMap.ResponseFormat = "maphandler.aspx?MAP=SimpleWorld&Width=[WIDTH]&Height=[HEIGHT]&Zoom=[ZOOM]&X=[X]&Y=[Y]&Layers=[LAYERS]";

this wont be problem in performance and speed???
Feb 2, 2009 at 7:27 PM
Hi navid_Pmb, I still dont really follow, I think you may mean the wz_jsgraphics library from But as far as I know this has no defined link with sharpmap /ajax map control. You should be able to draw over the map with it though. I have used it in other projects myself - but it is a little bit slow for drawing in 'real time' (i.e mouse move events) you may like to consider svg(mozilla) or vml(IE) as an alternative.
I dont understand what issue you were meaning with the InitializeMap and ResponseFormat. InitializeMap just sets the layers and styles and ResponseFormat is just a string into which params get substituted.
hth jd
Feb 3, 2009 at 6:58 AM
Edited Feb 3, 2009 at 7:06 AM
thanks johndiss for your help about jsgraphic i 'm using jzgraphic for  draw buffer or source and taarget for routing(with pgrourouting) and in last draw new feature in layers if i can.
about InitializeMap and ResponseFormat yes i know
but calll InitializeMap  in page load and then
set my responseFormat is
      Map.ResponseFormat = "maphandler.aspx?MAP=SimpleWorld&Width=[WIDTH]&Height=[HEIGHT]&Zoom=[ZOOM]&X=[X]&Y=[Y]&Layers=[LAYERS]"

and in maphandler.aspx i call again InitializeMap  for take map

this calling proof to twic calling InitializeMap 

and my InitializeMap  is very long and calling and Analise and read cooke or session and then set map with this parameter, to conclude i anxious for performance of my web sit in big data
Feb 3, 2009 at 9:23 AM
Hi navid, Perhaps you could use the 'useCache' flag then, that way the image is both setup and rendered in one pass and the url of the cached image is sent - not the parameters with which to build it. However, like I mentioned in another post, it is unlikeley to be reused so it would make sense to remove it from cache after it has been used the first time -  otherwise you will heamorrage memory very quickly. hth jd