/* * Copyright (c) 2005 Andriy Bidochko. * http://www.mapbuilder.net * * The script has been generated by MapBuilder.net service and released to the customer under * The GNU General Public License (GPL), which can be found at: http://www.opensource.org/licenses/gpl-license.php * * This program is free software; you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation; * either version 2 of the License, or any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ /* ******************************************************************************* */ /* MapBuilder Grouping Classes used to organize locations into Master/Child groups */ /* This class represents a group of markers (child) */ function MBLocationGroup(name){ this.GroupName = name; this.aMarkers = new Array(); this.aMarkersIcons = new Array(); this.aMarkerIDs = new Array(); this.addMarker = function(marker, markerid, iconimg){ len = this.aMarkers.length; this.aMarkers[len] = marker; this.aMarkersIcons[len] = iconimg; this.aMarkerIDs[len] = markerid; } // Bind markers to the map this.showMarkersOnMap = function(mapid){ // Loop through markers for (i = 0; i < this.aMarkers.length; i++) { this.aMarkers[i].icon.image = this.aMarkersIcons[i] ; mapid.addOverlay(this.aMarkers[i]); } } // Bind markers to the select obj this.showMarkersOnSelect = function(selectobj){ //Clear the second select box. selectobj.options.length = 0; // Loop through markers for (i = 0; i < this.aMarkers.length; i++) { aMarkerInfo = aLocations[this.aMarkerIDs[i]]; selectobj.options[i] = new Option(aMarkerInfo[1], this.aMarkerIDs[i]); } } } /* Basic Group Definition Class. Used to track map center, zoom level */ function MBGroupDefinition (name, longt, latt, zoomlevel){ this.Name = name; this.Long = longt; this.Latt = latt; this.ZoomLevel = zoomlevel; } /* This class represents a master group */ function MBGroup(){ this.aGroups = new Array(); this.aRegisteredGroups = new Array(); this.aGroupMarkers = new Array(); this.RegisterGroup = function(group, longt, latt, zoomlevel){ // Do we deal with existing group? NewGroup = true; for (i = 0; i < this.aGroups.length; i++) { if (this.aGroups[i] == group) { GroupID = i; NewGroup = false; break; } } // Add new group if (NewGroup) { GroupID = this.addGroup(group); } // Create object this.aRegisteredGroups[GroupID] = new MBGroupDefinition(group, longt, latt, zoomlevel); } this.addGroup = function(group){ len = this.aGroups.length; this.aGroups[len] = group; //Add markers object this.aGroupMarkers[len] = new MBLocationGroup(group); return len; } this.addMarker = function(group, marker, markerid, iconimg){ // Do we deal with existing group? NewGroup = true; for (i = 0; i < this.aGroups.length; i++) { if (this.aGroups[i] == group) { GroupID = i; NewGroup = false; break; } } // Add new group if (NewGroup) { GroupID = this.addGroup(group); } // Add marker this.aGroupMarkers[GroupID].addMarker(marker, markerid, iconimg); } //Show markers by group name this.showMarkers = function(group, mapid){ // Do we deal with existing group? FoundGroup = false; for (i = 0; i < this.aGroups.length; i++) { if (this.aGroups[i] == group) { GroupID = i; FoundGroup = true; break; } }; // Add new group if (FoundGroup) { //alert("y"+this.aGroupMarkers[GroupID].aMarkers.length) this.aGroupMarkers[GroupID].showMarkersOnMap(mapid); } else { return; } } //Show markers by group ID this.showMarkersByID = function(groupid, mapid, selectobj){ if (typeof(this.aGroupMarkers[groupid]) == 'undefined') return; //Use MBGroupDefinition info to center and zoom map if (typeof(this.aRegisteredGroups[groupid]) != 'undefined') { // a GPoint represents a lat/lng, x is the longitude, and y is the latitude in decimal notation mapid.centerAndZoom(new GPoint(this.aRegisteredGroups[groupid].Long, this.aRegisteredGroups[groupid].Latt), this.aRegisteredGroups[groupid].ZoomLevel); } // Show markers on the map this.aGroupMarkers[groupid].showMarkersOnMap(mapid); //Show marker on second select object this.aGroupMarkers[groupid].showMarkersOnSelect(selectobj); } // set value for the select object this.setGroupBox = function(selectobj){ for (i = 0; i < this.aGroups.length; i++) { selectobj.options[i] = new Option(this.aGroups[i], i); }; } } function ShowLocations(group, mapid, selectobj) { // Clear Map mapid.clearOverlays(); // Load locations MyMBGroup.showMarkersByID(group, mapid, selectobj); }