WebGIS Simulation Based on GPS Real-Time Signal

Source: Internet
Author: User
Tags polyline

I was very interested in real-time GPS display a long time ago. Generally, the tracking systems used by logistics or other companies that need to monitor are c/s, later, I saw B/S-based
Example, mainly based on AGS
Developed by jsapi. I have also specifically asked people to confirm my speculation about the technical implementation process, that is, the client regularly accesses a specified WebService to obtain GPS signals. However
And then display it on the map.

I did not find the GPS signal simulation software, so I wrote a random coordinate Generation Service, which can provide coordinates within a specified range:

Gpspoint
Class Code:

Public class gpspoint

{

Private int X;


Private int y;

Public gpspoint ()

{

}


Public int x

{

Get {return X ;}


Set {x = value ;}

}

Public int y

{


Get {return y ;}

Set {Y = value ;}

}


Public String createjson ()

{

Stringbuilder
Jsonstring = new stringbuilder ();

Jsonstring. append ("{");


Jsonstring. append ("/" gpspoint /":[");


Jsonstring. append ("/" "+ X. tostring () +"/"," + "/" + Y. tostring () +
"/"");

Jsonstring. append ("]}");

Return
Jsonstring. tostring ();

}

}

The WebService method:


[Webmethod]

Public String creategpsinfo ()

{


Random Ram = new random ();

Int x = Ram. Next (586742,621 223 );


Int y = Ram. Next (89212,117 049 );

Gpspoint Pt = new
Gpspoint ();

PT. x = X;

PT. Y = y;


Return pt. createjson ();

}

The. net20 WebService is annoying because it does not exist.
The method returns the data to the client in JSON format. Therefore, I also wrote an ashx file to return the data in JSON format:

Public
Void processrequest (httpcontext context)

{


Context. response. contenttype = "text/plain ";

GPS =
New GPS ();


Context. response. Write (GPS. creategpsinfo ());

}

What should I do on the client?
Request and display the GPS service on a regular basis? This is not complicated.

 

Let's continue to talk about how to display real-time GPS signals on WebGIS of B/S architecture. in the previous article, I used a web service to generate a random coordinate point. And
It must be able to trigger a request to access the service on a regular basis. JS originally has two functions: setTimeout and setinterval. To facilitate management, I used
EXT timer is complete.

The following is the request sending function:

VaR gpstask = function (){


Ext. Ajax. Request ({


URL: 'http: // nbjbt/cad2gis_service/getgpspoint. ashx ',


Method: 'post ',


Headers: {'content-type': 'application/JSON; charset = UTF-8 '},


Success: function (response, options ){},


Failure: function (response, options ){}

});

}

How to send and stop
Sending is also very simple. The following startgpstask function can run the gpstask function every five seconds, and the stopgpstask function will stop this trigger.
(The Ext. taskmgr. Stop method cannot stop triggering a specific function. Why ?!) :

Function
Startgpstask (){

Ext. taskmgr. Start ({

Run: gpstask,


Interval: 5000

});

}

Function stopgpstask (){


Ext. taskmgr. stopall ();

}

Obviously, the rest of the display is the position of the graphic object in a dynamic graphics layer.
Changing and changing the current center of the map, this process is naturally completed in the success processing function. The specific operation process is not complex, that is, to generate
Path, then add it to the polyline, clear the graph layer, assign the new polyline to the graphic, and then add the graphic to the graph layer.
Constantly changing the central position of a map forms a dynamic effect. The specific code is complicated, but not difficult.

 

The following is an example of implementation:

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.