Displaying a point of interest on a map is the simplest but most extensive application. For example, a company wants to add a simple map on its home page to display the location of the company. In this lecture, I will briefly introduce the concept of shape: A shape can be a vertex, line, polygon, etc. When initializing a shape object, you can determine the specific shape type based on different input parameters of the initialization function: veshapetype. pushpin, veshapetype. polygon, veshapetype. polyline. Shape initialization example:
VaR shape = new veshape (veshapetype. pushpin, map. getcenter (); initialize a shape of the point of interest (pushpin ).In this initialization example, the map. getcenter () method is used to obtain the longitude and latitude of the central position of the current map as the point of interest to be displayed. We can also customize a location: New velatlong (39.9012, 116.3902), that is:
VaR shape = new veshape (veshapetype. pushpin, new velatlong (39.9012, 116.3902 ));I will explain the initialization of lines and polygon in subsequent lectures. Next, let's take a look at the specific implementation code for adding a point of interest. We define a function for adding a point of interest:
Function addpushpin ()
{
VaR shape = new veshape (veshapetype. pushpin, new velatlong (39.9012, 116.3902 ));
Shape. settitle ('interest point ');
Shape. setdescription ('My points ');
Map. addshape (SHAPE );
}
This function first initializes a shape object as pushpin, and then sets the title and specific description of the point of interest. Finally, call the addshape method of the map class to add a shape on the basic map. Similarly, we need to add a link (or a button) to the html body to allow users to control and add points of interest:
<Div> <a href = '# 'onclick = 'addpushpin ();'> add interest points </a> </div>Add the above two pieces of code to the Code for displaying the map in the first lecture. Then you can experience the function of adding points of interest. Of course, sometimes we do not want to manually add a button, but to automatically display a point of interest during map loading. At this time, we need to modify the getmap function:
Function getmap ()
{
Map = new vemap ('mymap ');
Map. loadmap ();
Addpushpin ()
}
You can implement these two methods by yourself!