Google Maps Development Summary (Markermanager)

Source: Internet
Author: User

Recently developed an application based on Google Maps, in the use of Google Maps provided by the API, want to get the map has been loaded in a landmark, but how can not get, they think of a Markermanager object,

In the code I declare an array to save the new marker object, and when you return the desired marker object, the foreground provides an ID value as long as you look in the array to see if there are objects equal in the Marker object ID, and some return. No words returned false. The Markermanager object provides several methods. This Markermanager object has a flaw, is when the map moves, the background returns the data, I is clears all existing marker object, reloads, wants to change to return the object if already some in the map does not reload, does not have the words reload, does not exist the deletion. This total and in a period of time after the revision completed, I hope to help you.

JavaScript Document


Landmark Management Objects
function Markermanager (_MAP)
{
var map;
var markerstack = new Array ();
var newmarkers = new Array ();
Map = _map;

Add landmarks
This.addmarker = function (markers)
{
for (i = 0; i < markers.length; i++)
{


var mylatlng = new Google.maps.LatLng (Markers[i].lat, MARKERS[I].LNG);
var id = markers[i].id;
var name = "Marker" +ID;
name = new Google.maps.Marker ({
POSITION:MYLATLNG,
Title:markers[i].name,
Icon:image,
Map:map,
Id:id,
Scope:markers[i].scope,
Minimum:markers[i].minimum
});


Attachsecretmessage (map, name);
Markerstack.push (name);
};
}

Re-loading of landmarks
This.reloadmarkers = function (_data) {
var length = _data.length;
if (_data.length <= 0)
return false;
This.removehistorymarkers (_data);
for (i = 0;i < length;i++) {
if (!this.getmarker (_data[i].id)) {
Newmarkers.push (_data[i]);
}
}
if (newmarkers) {
This.addmarker (newmarkers);
Newmarkers = [];
}

}

Delete marker that do not exist
This.removehistorymarkers = function (_data) {

for (var i =0 < markerstack.length; i++) {
if (!this.existmarker (_data,markerstack[i].id)) {
This.clearmarker (Markerstack[i],i);
}
}

}

Check if the history marker object exists in the new data
This.existmarker = function (_data, id) {
for (var i = 0; i < _data.length; i++) {
if (id = = _data[i].id)
return true;
}
return false;
}

Return number of landmarks
This.countmarker = function () {
return markerstack.length;
};


Return a landmark object by ID
This.getmarker = function (_id) {
if (markerstack.length <= 0)
return false;
for (var count = 0; count < markerstack.length; count++) {
if (markerstack[count].id = = _id)
return Markerstack[count];
}
return false;

}


Clear all Landmark objects
This.clearmarkers = function () {
for (i = 0; i< markerstack.length; i++) {
var marker = Markerstack[i];
Marker.setmap (NULL);
}
Markerstack = [];
}

Clear a landmark
This.clearmarker = function (_marker, i) {
_marker.setmap (NULL);
Markerstack.splice (i,1);

}


}

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.