Google map API tagging Layer Management (original)

Source: Internet
Author: User

Google map API annotation is added to a single map. When there are many annotations and multiple data types in the map, it is difficult to manage these annotations. There is no definition of the annotation layer in the API, but only the global superposition layer concept. As follows:

Enum gmappane

These constants define the stack layer to display their own layered systems on the map. Icons, shadows, information windows, shadow on Information windows, and transparent mouse events of captured objects all have different layers.

From this we can see that the stack layer is not used for the management of the layer for labeling.

Therefore, we implemented a Google map layer management. To facilitate the development of your project functions. Allows you to manage different types of data and data simultaneously on a map.

Layer Management consists of two classes: layer and layermanage.

The layer completes the addition and removal of the annotation, defines the visible level of the layer, and displays and hides the layer.

Layermanage: adds a layer to the map to obtain the layer.

Layer class definition

Code
// Layer class
// Name: layer name
// Zoommax: maximum visible level of the layer
// Zoommin: Minimum visible level of the layer
Layer = function (name, zoommax, zoommin ){
This. Name = Name;
This. zoommax = 19;
This. zoommin = 0;
If (typeof (zoommax )! = "Undefined ")
{
This. zoommax = zoommax;
}
If (typeof (zoommin )! = "Undefined ")
{
This. zoommin = zoommin;
}

This. Map = NULL;
This. Display = false;
This. zoomdisplay = false;

This. Markers = {};

}

 

Add and remove tags

Code
// Add a label to the Layer
Layer. Prototype. addmarker = function (Marker ){
Marker. guid = createguid ();
This. Markers [marker. guid] = marker;

If (this. map! = NULL & this. Display)
{
This. Map. addoverlay (Marker );
}
}
// Remove a annotation from the Layer
Layer. Prototype. removemarker = function (Marker ){
If (this. map! = NULL)
{
This. Map. removeoverlay (Marker );
}

Delete this. Markers [marker. guid];

}

Display and hide Layers

Code
// Add all labels in the layer to the map
Layer. Prototype. Show = function (){
If (this. map! = NULL &&(! This. Display ))
{
If (this. isinzoom (this. Map. getzoom ()))
{
For (var k in this. Markers ){
This. Map. addoverlay (this. Markers [k]);
}
This. zoomdisplay = true;
}
This. Display = true;
}
}
// Remove all labels from the layer from the map
Layer. Prototype. Hide = function (){
If (this. map! = NULL)
{
For (var k in this. Markers ){
This. Map. removeoverlay (this. Markers [k]);
}
}

This. Display = false;

}

 

Layer Management Code:

 

Code
// Annotation management class
Layermanage = function (MAP ){
This. Layers = {};
Layers = This. layers;
This. Map = map;
Gevent. addlistener (MAP, 'zoomend', function (oldlevel, newlevel ){
For (var k in layers ){
Layers [K]. updatazoom (newlevel );
}
});
}
// Add a Layer
Layermanage. Prototype. addlayer = function (layer ){
If (typeof (this. Layers [layer. Name])! = "Undefined" & this. Layers [layer. Name]! = NULL ){
Alert ('layer already exists! ');
Return;
}
This. Layers [layer. Name] = layer;
This. Layers [layer. Name]. Map = This. Map;
This. Layers [layer. Name]. Show ();
}
// Remove a Layer
Layermanage. Prototype. removelayer = function (name ){
If (typeof (this. Layers [name])! = "Undefined" & this. Layers [name]! = NULL)
{
This. Layers [name]. Hide ();
This. Layers [name]. Map = NULL;
Layer = This. Layers [name];
Delete this. Layers [name];
Return layer;
}
Return NULL;
}
// Obtain the Layer
Layermanage. Prototype. getlayer = function (name ){
Return this. Layers [name];
}

 

The above is the main code for Layer Management.

Google map layer management demo

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.