Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // initialize variables
- var infowindow = null;
- var directionDisplay;
- var directionsService = new google.maps.DirectionsService();
- var gmarkers = [];
- $(document).ready(function () { initialize(); });
- function initialize() {
- // directions
- directionsDisplay = new google.maps.DirectionsRenderer();
- var centerMap = new google.maps.LatLng(busipress_map_vars.center_lat , busipress_map_vars.center_long);
- var myOptions = {
- zoom: 4,
- center: centerMap,
- mapTypeId: google.maps.MapTypeId.TERRAIN
- }
- var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
- setMarkers(map, sites);
- infowindow = new google.maps.InfoWindow({
- content: "loading..."
- });
- var start = busipress_map_vars.path_start;
- var end = busipress_map_vars.path_end;
- var request = {
- origin:start,
- destination:end,
- travelMode: google.maps.DirectionsTravelMode.DRIVING
- };
- directionsService.route(request, function(response, status) {
- if (status == google.maps.DirectionsStatus.OK) {
- directionsDisplay.setDirections(response);
- }
- });
- directionsDisplay.setMap(map);
- }
- /**
- * show locations
- */
- var sites = busipress_map_vars.locations;
- /**
- * set markers on map
- */
- function setMarkers(map, markers) {
- for (var i = 0; i < markers.length; i++) {
- var sites = markers[i];
- // default icon
- var defaultIcon = new google.maps.MarkerImage(sites[4][0],
- // This marker is 32 pixels wide by 32 pixels tall.
- new google.maps.Size(sites[4][1], sites[4][2]),
- // The origin for this image is 0,0.
- new google.maps.Point(0,0),
- // The anchor for this image is the base of the flagpole at 0,32.
- new google.maps.Point((sites[4][1] / 2), sites[4][2]));
- // default shadow
- var shadow = new google.maps.MarkerImage(sites[6][0],
- // The shadow image is larger in the horizontal dimension
- // while the position and offset are the same as for the main image.
- new google.maps.Size(sites[6][1], sites[6][2]),
- new google.maps.Point(0,0),
- new google.maps.Point((sites[6][1] / 2), sites[6][2]));
- // active icion
- var activeIcon = new google.maps.MarkerImage(sites[5][0],
- // This marker is 20 pixels wide by 32 pixels tall.
- new google.maps.Size(sites[5][1], sites[5][2]),
- // The origin for this image is 0,0.
- new google.maps.Point(0,0),
- // The anchor for this image is the base of the flagpole at 0,32.
- new google.maps.Point((sites[5][1] / 2), sites[5][2]));
- var shape = {
- coord: [9,0,6,1,4,2,2,4,0,8,0,12,1,14,2,16,5,19,7,23,8,26,9,30,9,34,11,34,11,30,12,26,13,24,14,21,16,18,18,16,20,12,20,8,18,4,16,2,15,1,13,0],
- type: 'poly'
- };
- var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
- var marker = new google.maps.Marker({
- position: siteLatLng,
- map: map,
- title: sites[0],
- icon: defaultIcon,
- shadow: shadow,
- zIndex: 1,
- html: sites[3],
- myDefaultIcon: defaultIcon,
- myActiveIcon: activeIcon
- });
- google.maps.event.addListener(marker, "click", function () {
- for (var i = 0; i < gmarkers.length; i++) {
- gmarkers[i].setIcon(gmarkers[i].myDefaultIcon);
- }
- this.setIcon(marker[i].myActiveIcon);
- infowindow.setContent(this.html);
- infowindow.open(map, this);
- });
- gmarkers.push(marker);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement