Display real-time vehicle tracks

Source: Internet
Author: User

/*************************************** *****************/
// Function: Display real-time vehicle tracks
/*************************************** ****************/

VaR trackrealtimeiconurl = "./app_themes/vehicles/carrun"; // default vehicle icon
VaR tracklasticonurl;
VaR trackrealtimerecordnum = 0;
VaR trackpoint; // location displayed on the map
VaR trackmap; // map obtained separately
VaR trackpointgroup; // set of points on the map
VaR lastresult; // The data received last time
VaR trackline; // trajectory line

// Obtain the map object
Trackmap = $ find ("trackrealtimemap ");
If (trackmap! = NULL)
{
Spatialreference = trackmap. get_spatialreference ();
Trackmap. add_zoomcompleted (function () {trackmap. refreshgraphics (true )});
Trackmap. add_pancompleted (function () {trackmap. refreshgraphics (true )});
}

// Obtain the map coordinate system
VaR spatialreference;
If (trackmap! = NULL)
Spatialreference = trackmap. get_spatialreference ();

// Extjs used here, that is, after the page content is fully loaded, execute thisCode
Ext. onready (function (){
// Process the data transmitted from the page
Processtrackrealtimeinfo (passinfo );
// Start real-time data acquisition in five seconds
SetTimeout (FIG, 5000 );
});

// Real-time Data Acquisition Function
Function gettrackrealtimeinfo ()
{
// The exejs Ajax solution is used here. You can use the Asp.net Ajax solution.
Coolite. ajaxmethods. getgpsinfo (tracktmlid, tracklasttime, {success: processtrackrealtimeinfo}); // Ajax Method
SetTimeout (gettrackrealtimeinfo, 10000); // call cyclically. The interval is 10 seconds.
}

// Process the acquired data in real time
Function processtrackrealtimeinfo (result)
{
If (result. Updated = 1) // The retrieved data is updated before processing.
{
Tracklasttime = result. gpstime; // you can specify the time for the next query.
If (lastresult! = NULL) // determine whether the current data coordinate is the same as the previous data coordinate.
{
If (result. speed = 0 & lastresult. speed = 0)
{
// Do not update the map or do anything
}
Else
{
If (lastresult. Lon! = Result. Lon | lastresult. LAT! = Result. LAT)
{
Updategpsposition (result); // draw on the map
}
}
}
Else
{
Updategpsposition (result); // draw on the map
}
Lastresult = result;
}
}

// Update the display of GPS data on the map
Function updategpsposition (result)
{
// First, determine whether there is any,
If (trackmap = NULL)
{
Trackmap = $ find ("trackrealtimemap ");
If (trackmap = NULL)
Return;
Spatialreference = trackmap. get_spatialreference ();
Trackmap. add_zoomcompleted (function () {trackmap. refreshgraphics (true )});
Trackmap. add_pancompleted (function () {trackmap. refreshgraphics (true )});
}

If (trackpoint = NULL) // create a GPS point if the GPS point does not exist. Otherwise, only update it.
{
// Add
Inittrackpointgroup ();
Createtrackpoint (result );
}
Else
{
Updatetrackpoint (result); // update location and attribute information
}
Updatetrackline (result); // updates the track line
// When the current GPS position is out of the field of view, move it to the center of the map
VaR trackmapenvelope = trackmap. get_extent ();
If (result. Lon <trackmapenvelope. get_xmin () |
Result. Lon> trackmapenvelope. get_xmax () |
Result. LAT <trackmapenvelope. get_ymin () |
Result. LAT> trackmapenvelope. get_ymax ())
{
VaR Pt = new ESRI. ADF. geometries. Point (result. Lon, result. Lat, spatialreference );
Trackmap. Panto (PT, true );
}


// Force re-draw the graphicfeature drawn on the map
Trackmap. refreshgraphics (true );
}

// Create a point on the map and set the map's field of view
Function createtrackpoint (gpsinfo)
{
Trackpointgroup. Clear ();
Trackmap. refreshgraphics (true );
VaR carurl = getcaricondirect (trackrealtimeiconurl, gpsinfo. Direction );
Tracklasticonurl = carurl;
VaR carpoint = new ESRI. ADF. geometries. Point (gpsinfo. Lon, gpsinfo. Lat, spatialreference );
VaR carmarkersymbol = new ESRI. ADF. Graphics. markersymbol (carurl, "Pointer"); // displays the conformity when an unselected state is created.

Trackpoint = $ create (ESRI. ADF. Graphics. graphicfeature, {"Geometry": carpoint, // create graphicfeature and add it to graphicsfeaturegroup
"Symbol": carmarkersymbol });

Trackpointgroup. Add (trackpoint );
Trackmap. Zoom (trackmap. get_minzoom (), carpoint, false );
Trackmap. Zoom (150, carpoint, false); // 250trackmap. get_maxzoom ()
Binit = true;
}

// Update the vertex Information
Function updatetrackpoint (gpsinfo)
{
Trackmap. refreshgraphics (true );

// Obtain the value of each object
VaR carurl = getcaricondirect (trackrealtimeiconurl, gpsinfo. Direction );
// Update coordinate information
VaR Pt = new ESRI. ADF. geometries. Point (gpsinfo. Lon, gpsinfo. Lat, spatialreference );
Trackpoint. set_geometry (PT );
If (carurl! = Tracklasticonurl)
{
Trackpoint. get_symbol (). set_imageurl (carurl); // update the image display.
Tracklasticonurl = carurl;
}
Trackmap. refreshgraphics (true );
}

// Update the track line
Function updatetrackline (gpsinfo)
{
If (lastresult = NULL) // if no data exists last time, it indicates that only one data point is uploaded, and a line cannot be created at only one point.
Return;

VaR newpath = new ESRI. ADF. geometries. coordinatecollection ();
VaR newpt = new ESRI. ADF. geometries. Point (gpsinfo. Lon, gpsinfo. Lat, spatialreference );
VaR lastpt = new ESRI. ADF. geometries. Point (lastresult. Lon, lastresult. Lat, spatialreference );
Newpath. Add (lastpt );
Newpath. Add (newpt );
If (trackline! = NULL) // If a trajectory exists, only its coordinates are updated.
{
Trackline. get_geometry (). addpath (newpath );
}
Else
{// Create a line if it does not exist
VaR newpolyline = new ESRI. ADF. geometries. polyline (newpath, spatialreference );
VaR tracklinesymbol = new ESRI. ADF. Graphics. linesymbol ();
Tracklinesymbol. set_linecolor ('blue ');
Tracklinesymbol. set_width (3 );
Tracklinesymbol. set_cursor ('crosshair ');
Tracklinesymbol. set_opacity (0.7 );
Trackline = $ create (ESRI. ADF. Graphics. graphicfeature, {"ID": trackrealtimerecordnum. tostring (),
"Geometry": newpolyline,
"Symbol": tracklinesymbol });

Trackmap. addgraphic (trackline );
}

Trackmap. refreshgraphics (true );
}

// Initialize graphicfeaturegroup
Function inittrackpointgroup ()
{
If (trackpointgroup = NULL)
{
// Use ASP. NET Ajax $ create to create a new graphic feature group and define type, properties, events.
Trackpointgroup = $ create (ESRI. ADF. Graphics. graphicfeaturegroup, {"ID": "trackpointgroup"}); //, "maptips": maptips

// Add the graphic feature group to the map.
Trackmap. addgraphic (trackpointgroup );
}
}

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.