Advertisement
Guest User

new script geoloc+movement.

a guest
Oct 24th, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.34 KB | None | 0 0
  1.  
  2. //http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer
  3. (function () {
  4. if (typeof jQuery === "undefined" || jQuery == null ) {
  5. var done = false;
  6. var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement;
  7. var script = document.createElement('script');
  8. script.type= 'text/javascript';
  9. script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
  10.  
  11.  
  12.  
  13. script.onload = script.onreadystatechange = function() {
  14. if ( !done && (!this.readyState || /loaded|complete/.test( script.readyState ))) {
  15. done = true;
  16.  
  17. var jQueryObj = jQuery.noConflict();
  18. jQueryLoadCallback(jQueryObj);
  19. // Handle memory leak in IE
  20. script.onload = script.onreadystatechange = null;
  21. if ( head && script.parentNode ) {
  22. head.removeChild( script );
  23. }
  24. script = undefined;
  25. }
  26. };
  27.  
  28.  
  29. // Use insertBefore instead of appendChild to circumvent an IE6 bug - die IE6, just die! A.Z.
  30. // head.insertBefore( script, head.firstChild );
  31. head.appendChild(script);
  32. } else {
  33. jQueryLoadCallback();
  34. }
  35.  
  36.  
  37.  
  38. function jQueryLoadCallback() {
  39. var jQueryObj = (typeof arguments[0] === "undefined" || arguments[0] == null || !arguments[0]) ? jQuery : arguments[0];
  40.  
  41. (function ($) {
  42.  
  43. var parseJson = function(jsonString) { Logger.fatal("Using parseJson stub.."); }
  44. var version = parseFloat($.fn.jquery);
  45. if (version >= 1.1) {
  46. parseJson = $.parseJSON;
  47. } else if (window.JSON && window.JSON.parse) {
  48. parseJson = window.JSON.parse;
  49. }
  50.  
  51. var CGMPGlobal = {};
  52. var GoogleMapOrchestrator = (function() {
  53.  
  54. var builder = {};
  55. var googleMap = {};
  56. var initMap = function initMap(map, bubbleAutoPan, zoom, mapType) {
  57. googleMap = map;
  58.  
  59. var mapTypeIds = [];
  60. for(var type in google.maps.MapTypeId) {
  61. mapTypeIds.push(google.maps.MapTypeId[type]);
  62. }
  63. googleMap.setOptions({
  64. zoom: 6,
  65. mapTypeId: google.maps.MapTypeId.ROADMAP,
  66. mapTypeControlOptions: {mapTypeIds: mapTypeIds}
  67. });
  68.  
  69.  
  70. /*
  71. * Licensed under the Apache License, Version 2.0 (the "License");
  72. * you may not use this file except in compliance with the License.
  73. * You may obtain a copy of the License at
  74. *
  75. * http://www.apache.org/licenses/LICENSE-2.0
  76. *
  77. * Unless required by applicable law or agreed to in writing, software
  78. * distributed under the License is distributed on an "AS IS" BASIS,
  79. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  80. * See the License for the specific language governing permissions and
  81. * limitations under the License.
  82. */
  83.  
  84. /**
  85. * @name GeolocationMarker for Google Maps v3
  86. * @version version 1.0
  87. * @author Chad Killingsworth [chadkillingsworth at missouristate.edu]
  88. * Copyright 2012 Missouri State University
  89. * @fileoverview
  90. * This library uses geolocation to add a marker and accuracy circle to a map.
  91. * The marker position is automatically updated as the user position changes.
  92. */
  93.  
  94. /**
  95. * @constructor
  96. * @extends {google.maps.MVCObject}
  97. * @param {google.maps.Map=} opt_map
  98. * @param {(google.maps.MarkerOptions|Object.<string>)=} opt_markerOpts
  99. * @param {(google.maps.CircleOptions|Object.<string>)=} opt_circleOpts
  100. */
  101. function GeolocationMarker(opt_map, opt_markerOpts, opt_circleOpts) {
  102.  
  103. var markerOpts = {
  104. 'clickable': false,
  105. 'cursor': 'pointer',
  106. 'draggable': false,
  107. 'flat': true,
  108. 'icon': {
  109. 'url': 'https://google-maps-utility-library-v3.googlecode.com/svn/trunk/geolocationmarker/images/gpsloc.png',
  110. 'size': new google.maps.Size(34, 34),
  111. 'scaledSize': new google.maps.Size(17, 17),
  112. 'origin': new google.maps.Point(0, 0),
  113. 'anchor': new google.maps.Point(8, 8)
  114. },
  115. // This marker may move frequently - don't force canvas tile redraw
  116. 'optimized': false,
  117. 'position': new google.maps.LatLng(0, 0),
  118. 'title': 'Current location',
  119. 'zIndex': 2
  120. };
  121.  
  122. if(opt_markerOpts) {
  123. markerOpts = this.copyOptions_(markerOpts, opt_markerOpts);
  124. }
  125.  
  126. var circleOpts = {
  127. 'clickable': false,
  128. 'radius': 0,
  129. 'strokeColor': '1bb6ff',
  130. 'strokeOpacity': .4,
  131. 'fillColor': '61a0bf',
  132. 'fillOpacity': .4,
  133. 'strokeWeight': 1,
  134. 'zIndex': 1
  135. };
  136.  
  137. if(opt_circleOpts) {
  138. circleOpts = this.copyOptions_(circleOpts, opt_circleOpts);
  139. }
  140.  
  141. this.marker_ = new google.maps.Marker(markerOpts);
  142. this.circle_ = new google.maps.Circle(circleOpts);
  143.  
  144. /**
  145. * @expose
  146. * @type {number?}
  147. */
  148. this.accuracy = null;
  149.  
  150. /**
  151. * @expose
  152. * @type {google.maps.LatLng?}
  153. */
  154. this.position = null;
  155.  
  156. /**
  157. * @expose
  158. * @type {google.maps.Map?}
  159. */
  160. this.map = null;
  161.  
  162. this.set('minimum_accuracy', null);
  163.  
  164. this.set('position_options', /** GeolocationPositionOptions */
  165. ({enableHighAccuracy: true, maximumAge: 1000}));
  166.  
  167. this.circle_.bindTo('map', this.marker_);
  168.  
  169. if(opt_map) {
  170. this.setMap(opt_map);
  171. }
  172. }
  173. GeolocationMarker.prototype = new google.maps.MVCObject;
  174.  
  175. /**
  176. * @override
  177. * @expose
  178. * @param {string} key
  179. * @param {*} value
  180. */
  181. GeolocationMarker.prototype.set = function(key, value) {
  182. if (/^(?:position|accuracy)$/i.test(key)) {
  183. throw '\'' + key + '\' is a read-only property.';
  184. } else if (/map/i.test(key)) {
  185. this.setMap(/** @type {google.maps.Map} */ (value));
  186. } else {
  187. google.maps.MVCObject.prototype.set.apply(this, arguments);
  188. }
  189. };
  190.  
  191. /**
  192. * @private
  193. * @type {google.maps.Marker}
  194. */
  195. GeolocationMarker.prototype.marker_ = null;
  196.  
  197. /**
  198. * @private
  199. * @type {google.maps.Circle}
  200. */
  201. GeolocationMarker.prototype.circle_ = null;
  202.  
  203. /** @return {google.maps.Map} */
  204. GeolocationMarker.prototype.getMap = function() {
  205. return this.map;
  206. };
  207.  
  208. /** @return {GeolocationPositionOptions} */
  209. GeolocationMarker.prototype.getPositionOptions = function() {
  210. return /** @type GeolocationPositionOptions */(this.get('position_options'));
  211. };
  212.  
  213. /** @param {GeolocationPositionOptions|Object.<string, *>} positionOpts */
  214. GeolocationMarker.prototype.setPositionOptions = function(positionOpts) {
  215. this.set('position_options', positionOpts);
  216. };
  217.  
  218. /** @return {google.maps.LatLng?} */
  219. GeolocationMarker.prototype.getPosition = function() {
  220. return this.position;
  221. };
  222.  
  223. /** @return {google.maps.LatLngBounds?} */
  224. GeolocationMarker.prototype.getBounds = function() {
  225. if (this.position) {
  226. return this.circle_.getBounds();
  227. } else {
  228. return null;
  229. }
  230. };
  231.  
  232. /** @return {number?} */
  233. GeolocationMarker.prototype.getAccuracy = function() {
  234. return this.accuracy;
  235. };
  236.  
  237. /** @return {number?} */
  238. GeolocationMarker.prototype.getMinimumAccuracy = function() {
  239. return /** @type {number?} */ (this.get('minimum_accuracy'));
  240. };
  241.  
  242. /** @param {number?} accuracy */
  243. GeolocationMarker.prototype.setMinimumAccuracy = function(accuracy) {
  244. this.set('minimum_accuracy', accuracy);
  245. };
  246.  
  247. /**
  248. * @private
  249. * @type {number}
  250. */
  251. GeolocationMarker.prototype.watchId_ = -1;
  252.  
  253. /** @param {google.maps.Map} map */
  254. GeolocationMarker.prototype.setMap = function(map) {
  255. this.map = map;
  256. this.notify('map');
  257. if (map) {
  258. this.watchPosition_();
  259. } else {
  260. this.marker_.unbind('position');
  261. this.circle_.unbind('center');
  262. this.circle_.unbind('radius');
  263. this.accuracy = null;
  264. this.position = null;
  265. navigator.geolocation.clearWatch(this.watchId_);
  266. this.watchId_ = -1;
  267. this.marker_.setMap(map);
  268. }
  269. };
  270.  
  271. /** @param {google.maps.MarkerOptions|Object.<string>} markerOpts */
  272. GeolocationMarker.prototype.setMarkerOptions = function(markerOpts) {
  273. this.marker_.setOptions(this.copyOptions_({}, markerOpts));
  274. };
  275.  
  276. /** @param {google.maps.CircleOptions|Object.<string>} circleOpts */
  277. GeolocationMarker.prototype.setCircleOptions = function(circleOpts) {
  278. this.circle_.setOptions(this.copyOptions_({}, circleOpts));
  279. };
  280.  
  281. /**
  282. * @private
  283. * @param {GeolocationPosition} position
  284. */
  285. GeolocationMarker.prototype.updatePosition_ = function(position) {
  286. var newPosition = new google.maps.LatLng(position.coords.latitude,
  287. position.coords.longitude), mapNotSet = this.marker_.getMap() == null;
  288.  
  289. if(mapNotSet) {
  290. if (this.getMinimumAccuracy() != null &&
  291. position.coords.accuracy > this.getMinimumAccuracy()) {
  292. return;
  293. }
  294. this.marker_.setMap(this.map);
  295. this.marker_.bindTo('position', this);
  296. this.circle_.bindTo('center', this, 'position');
  297. this.circle_.bindTo('radius', this, 'accuracy');
  298. }
  299.  
  300. if (this.accuracy != position.coords.accuracy) {
  301. // The local set method does not allow accuracy to be updated
  302. google.maps.MVCObject.prototype.set.call(this, 'accuracy', position.coords.accuracy);
  303. }
  304.  
  305. if (mapNotSet || this.position == null ||
  306. !this.position.equals(newPosition)) {
  307. // The local set method does not allow position to be updated
  308. google.maps.MVCObject.prototype.set.call(this, 'position', newPosition);
  309. }
  310. };
  311.  
  312. /**
  313. * @private
  314. * @return {undefined}
  315. */
  316. GeolocationMarker.prototype.watchPosition_ = function() {
  317. var self = this;
  318.  
  319. if(navigator.geolocation) {
  320. this.watchId_ = navigator.geolocation.watchPosition(
  321. function(position) { self.updatePosition_(position); },
  322. function(e) { google.maps.event.trigger(self, "geolocation_error", e); },
  323. this.getPositionOptions());
  324. }
  325. };
  326.  
  327. /**
  328. * @private
  329. * @param {Object.<string,*>} target
  330. * @param {Object.<string,*>} source
  331. * @return {Object.<string,*>}
  332. */
  333. GeolocationMarker.prototype.copyOptions_ = function(target, source) {
  334. for(var opt in source) {
  335. if(GeolocationMarker.DISALLOWED_OPTIONS[opt] !== true) {
  336. target[opt] = source[opt];
  337. }
  338. }
  339. return target;
  340. };
  341.  
  342. /**
  343. * @const
  344. * @type {Object.<string, boolean>}
  345. */
  346. GeolocationMarker.DISALLOWED_OPTIONS = {
  347. 'map': true,
  348. 'position': true,
  349. 'radius': true
  350. };
  351.  
  352. GeoMarker = new GeolocationMarker();
  353. GeoMarker.setCircleOptions({fillColor: '#808080'});
  354.  
  355. google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() {
  356. map.setCenter(this.getPosition());
  357. map.fitBounds(this.getBounds());
  358. map.setZoom(18);
  359. });
  360.  
  361. google.maps.event.addListener(GeoMarker, 'geolocation_error', function(e) {
  362. alert('There was an error obtaining your position. Message: ' + e.message);
  363. });
  364.  
  365. GeoMarker.setMap(map);
  366.  
  367.  
  368.  
  369. // Try HTML5 geolocation
  370. if(navigator.geolocation)
  371.  
  372.  
  373. {
  374. navigator.geolocation.getCurrentPosition(function(position) {
  375. var pos = new google.maps.LatLng(position.coords.latitude,
  376. position.coords.longitude);
  377.  
  378.  
  379. var directionsService = new google.maps.DirectionsService();
  380. var directionsDisplay = new google.maps.DirectionsRenderer();
  381. var infowindow = new google.maps.InfoWindow({
  382.  
  383.  
  384. });
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391. });
  392. } else {
  393. // Browser doesn't support Geolocation
  394. handleNoGeolocation(false);
  395. }
  396. }
  397.  
  398.  
  399.  
  400. function handleNoGeolocation(errorFlag) {
  401. if (errorFlag) {
  402. var content = 'Error: The Geolocation service failed.';
  403. } else {
  404. var content = 'Error: Your browser doesn\'t support geolocation.';
  405. }
  406.  
  407. var options = {
  408. map: map,
  409. position: new google.maps.LatLng(60, 105),
  410. content: content
  411. };
  412.  
  413. var infowindow = new google.maps.InfoWindow(options);
  414. map.setCenter(options.position);
  415. }
  416.  
  417.  
  418.  
  419.  
  420. var setMapControls = function setMapControls(mapControlOptions) {
  421. googleMap.setOptions(mapControlOptions);
  422. }
  423.  
  424. return {
  425. initMap: initMap,
  426. setMapControls: setMapControls
  427. }
  428. })();
  429.  
  430.  
  431. var LayerBuilder = (function() {
  432.  
  433. var googleMap = {};
  434.  
  435. var init = function init(map) {
  436. googleMap = map;
  437. }
  438.  
  439. var buildTrafficLayer = function buildTrafficLayer() {
  440. var trafficLayer = new google.maps.TrafficLayer();
  441. trafficLayer.setMap(googleMap);
  442. }
  443.  
  444. var buildBikeLayer = function buildBikeLayer() {
  445. var bikeLayer = new google.maps.BicyclingLayer();
  446. bikeLayer.setMap(googleMap);
  447. }
  448.  
  449. var buildPanoramioLayer = function buildPanoramioLayer(userId) {
  450. if (typeof google.maps.panoramio == "undefined" || !google.maps.panoramio || google.maps.panoramio == null ) {
  451. Logger.error("We cannot access Panoramio library. Aborting..");
  452. return false;
  453. }
  454. var panoramioLayer = new google.maps.panoramio.PanoramioLayer();
  455. if (panoramioLayer) {
  456. if (userId != null && userId != "") {
  457. panoramioLayer.setUserId(userId);
  458. }
  459. panoramioLayer.setMap(googleMap);
  460. } else {
  461. Logger.error("Could not instantiate Panoramio object. Aborting..");
  462. }
  463. }
  464.  
  465. var buildKmlLayer = function buildKmlLayer(url) {
  466. if (url.toLowerCase().indexOf("http") < 0) {
  467. Logger.error("KML URL must start with HTTP(S). Aborting..");
  468. return false;
  469. }
  470.  
  471. var kmlLayer = new google.maps.KmlLayer(url/*, {preserveViewport: true}*/);
  472. google.maps.event.addListener(kmlLayer, "status_changed", function() {
  473. kmlLayerStatusEventCallback(kmlLayer);
  474. });
  475. google.maps.event.addListener(kmlLayer, 'defaultviewport_changed', function() {
  476. //var bounds = kmlLayer.getDefaultViewport();
  477. //googleMap.setCenter(bounds.getCenter());
  478. });
  479.  
  480. kmlLayer.setMap(googleMap);
  481. }
  482.  
  483. function kmlLayerStatusEventCallback(kmlLayer) {
  484. var kmlStatus = kmlLayer.getStatus();
  485. if (kmlStatus == google.maps.KmlLayerStatus.OK) {
  486. //Hmmm...
  487. } else {
  488. var msg = '';
  489. switch(kmlStatus) {
  490.  
  491. case google.maps.KmlLayerStatus.DOCUMENT_NOT_FOUND:
  492. msg = CGMPGlobal.errors.kmlNotFound;
  493. break;
  494. case google.maps.KmlLayerStatus.DOCUMENT_TOO_LARGE:
  495. msg = CGMPGlobal.errors.kmlTooLarge;
  496. break;
  497. case google.maps.KmlLayerStatus.FETCH_ERROR:
  498. msg = CGMPGlobal.errors.kmlFetchError;
  499. break;
  500. case google.maps.KmlLayerStatus.INVALID_DOCUMENT:
  501. msg = CGMPGlobal.errors.kmlDocInvalid;
  502. break;
  503. case google.maps.KmlLayerStatus.INVALID_REQUEST:
  504. msg = CGMPGlobal.errors.kmlRequestInvalid;
  505. break;
  506. case google.maps.KmlLayerStatus.LIMITS_EXCEEDED:
  507. msg = CGMPGlobal.errors.kmlLimits;
  508. break;
  509. case google.maps.KmlLayerStatus.TIMED_OUT:
  510. msg = CGMPGlobal.errors.kmlTimedOut;
  511. break;
  512. case google.maps.KmlLayerStatus.UNKNOWN:
  513. msg = CGMPGlobal.errors.kmlUnknown;
  514. break;
  515. }
  516. if (msg != '') {
  517. var error = CGMPGlobal.errors.kml.replace("[MSG]", msg);
  518. error = error.replace("[STATUS]", kmlStatus);
  519. Errors.alertError(error);
  520. Logger.error("Google returned KML error: " + msg + " (" + kmlStatus + ")");
  521. Logger.error("KML file: " + kmlLayer.getUrl());
  522. }
  523. }
  524. }
  525.  
  526. return {
  527. init: init,
  528. buildKmlLayer: buildKmlLayer,
  529. buildTrafficLayer: buildTrafficLayer,
  530. buildBikeLayer: buildBikeLayer,
  531. buildPanoramioLayer: buildPanoramioLayer
  532. }
  533. })();
  534.  
  535.  
  536.  
  537.  
  538. var MarkerBuilder = function () {
  539.  
  540. var markers, storedAddresses, badAddresses, wasBuildAddressMarkersCalled, timeout, directionControlsBinded,
  541. googleMap, csvString, bubbleAutoPan, originalExtendedBounds, originalMapCenter, updatedZoom, mapDivId,
  542. geocoder, bounds, infowindow, streetViewService, directionsRenderer, directionsService;
  543.  
  544.  
  545. var init = function init(map, autoPan) {
  546.  
  547. googleMap = map;
  548. mapDivId = googleMap.getDiv().id;
  549. bubbleAutoPan = autoPan;
  550.  
  551. google.maps.event.addListener(googleMap, 'click', function () {
  552. resetMap();
  553. });
  554.  
  555. markers = [];
  556. badAddresses = [];
  557. storedAddresses = [];
  558.  
  559.  
  560. updatedZoom = 5;
  561.  
  562. timeout = null;
  563. csvString = null;
  564. originalMapCenter = null;
  565. originalExtendedBounds = null;
  566.  
  567. directionControlsBinded = false;
  568. wasBuildAddressMarkersCalled = false;
  569.  
  570. geocoder = new google.maps.Geocoder();
  571. bounds = new google.maps.LatLngBounds();
  572. infowindow = new google.maps.InfoWindow();
  573. streetViewService = new google.maps.StreetViewService();
  574.  
  575. directionsService = new google.maps.DirectionsService();
  576.  
  577. rendererOptions = {
  578. draggable: true
  579. };
  580. directionsRenderer = new google.maps.DirectionsRenderer(rendererOptions);
  581. directionsRenderer.setPanel(document.getElementById('rendered-directions-placeholder-' + mapDivId));
  582. }
  583.  
  584. var isBuildAddressMarkersCalled = function isBuildAddressMarkersCalled() {
  585. return wasBuildAddressMarkersCalled;
  586. }
  587.  
  588. var buildAddressMarkers = function buildAddressMarkers(markerLocations, isGeoMashap, isBubbleContainsPostLink) {
  589.  
  590. wasBuildAddressMarkersCalled = true;
  591. csvString = Utils.trim(markerLocations);
  592. csvString = Utils.searchReplace(csvString, "'", "");
  593.  
  594. if (isGeoMashap === "true") {
  595. var json = parseJson(csvString);
  596.  
  597. if (isBubbleContainsPostLink === "true") {
  598. parseJsonStructure(json, true);
  599. } else if (isBubbleContainsPostLink === "false") {
  600. parseJsonStructure(json, false);
  601. }
  602. queryGeocoderService();
  603.  
  604. } else if (isGeoMashap == null || isGeoMashap === "false") {
  605. parseCsv();
  606. queryGeocoderService();
  607. }
  608. }
  609.  
  610.  
  611. function resetMap() {
  612. if (originalExtendedBounds != null) {
  613. if (googleMap.getCenter() != originalExtendedBounds.getCenter()) {
  614. //Logger.info("Panning map back to its original bounds center: " + originalExtendedBounds.getCenter());
  615. googleMap.fitBounds(originalExtendedBounds);
  616. googleMap.setCenter(originalExtendedBounds.getCenter());
  617. }
  618. } else if (originalMapCenter != null) {
  619. //Logger.info("Panning map back to its original center: " + originalMapCenter + " and updated zoom: " + updatedZoom);
  620. googleMap.setCenter(originalMapCenter);
  621. googleMap.setZoom(updatedZoom);
  622. }
  623. }
  624.  
  625. function resetDirectionAddressFields(dirDivId) {
  626. $(dirDivId + ' input#a_address').val('');
  627. $(dirDivId + ' input#b_address').val('');
  628. $(dirDivId + ' input#a_address').removeClass('d_error');
  629. $(dirDivId + ' input#b_address').removeClass('d_error');
  630. }
  631.  
  632. function attachEventlistener(marker, markersElement) {
  633.  
  634. var localBubbleData = buildBubble(marker.content, markersElement);
  635. var dirDivId = 'div#direction-controls-placeholder-' + mapDivId;
  636. var targetDiv = $("div#rendered-directions-placeholder-" + mapDivId);
  637.  
  638. google.maps.event.addListener(marker, 'click', function () {
  639.  
  640. resetDirectionAddressFields(dirDivId);
  641.  
  642. $(dirDivId).fadeOut();
  643. directionsRenderer.setMap(null);
  644. targetDiv.html("");
  645. targetDiv.hide();
  646. $(dirDivId + ' button#print_sub').hide();
  647.  
  648. validateMarkerStreetViewExists(marker, localBubbleData, dirDivId);
  649. attachEventstoDirectionControls(marker, localBubbleData, dirDivId, targetDiv);
  650.  
  651. infowindow.setContent(localBubbleData.bubbleContent);
  652. infowindow.setOptions({disableAutoPan: bubbleAutoPan == "true" ? false : true });
  653. infowindow.open(googleMap, this);
  654. });
  655. }
  656.  
  657. function attachEventstoDirectionControls(marker, localBubbleData, dirDivId, targetDiv) {
  658.  
  659. var parentInfoBubble = 'div#bubble-' + localBubbleData.bubbleHolderId;
  660.  
  661.  
  662.  
  663. var addy = marker.content;
  664. addy = addy.replace("Lat/Long: ", "");
  665.  
  666.  
  667.  
  668. $(parentInfoBubble + ' a.dirToHereTrigger').live("click", function() {
  669. var thisId = this.id;
  670. if (thisId == 'toHere-' + localBubbleData.bubbleHolderId) {
  671. $(dirDivId).fadeIn();
  672. $(dirDivId + ' input#a_address').val('');
  673. $(dirDivId + ' input#radio_km').attr("checked", "checked");
  674. }
  675. });
  676.  
  677. $(parentInfoBubble + ' a.dirFromHereTrigger').live("click", function() {
  678. var thisId = this.id;
  679. if (thisId == 'fromHere-' + localBubbleData.bubbleHolderId) {
  680. $(dirDivId).fadeIn();
  681. $(dirDivId + ' input#a_address').val(addy);
  682. $(dirDivId + ' input#b_address').val('');
  683. $(dirDivId + ' input#radio_km').attr("checked", "checked");
  684. }
  685. });
  686.  
  687. $(dirDivId + ' div.d_close-wrapper').live("click", function(event) {
  688.  
  689. resetDirectionAddressFields(dirDivId);
  690.  
  691. $(this).parent().fadeOut();
  692. directionsRenderer.setMap(null);
  693. targetDiv.html("");
  694. targetDiv.hide();
  695. $(dirDivId + ' button#print_sub').hide();
  696. resetMap();
  697.  
  698. return false;
  699. });
  700. }
  701.  
  702. function validateMarkerStreetViewExists(marker, localBubbleData, dirDivId) {
  703.  
  704. streetViewService.getPanoramaByLocation(marker.position, 50, function (streetViewPanoramaData, status) {
  705. if (status === google.maps.StreetViewStatus.OK) {
  706. // ok
  707. $('a#trigger-' + localBubbleData.bubbleHolderId).live("click", function() {
  708.  
  709. var panoramaOptions = {
  710. navigationControl: true,
  711. enableCloseButton: true,
  712. addressControl: false,
  713. linksControl: true,
  714. scrollwheel: false,
  715. addressControlOptions: {
  716. position: google.maps.ControlPosition.BOTTOM
  717. },
  718. position: marker.position,
  719. pov: {
  720. heading: 165,
  721. pitch:0,
  722. zoom:1
  723. }
  724. };
  725.  
  726. var pano = new google.maps.StreetViewPanorama(document.getElementById("bubble-" + localBubbleData.bubbleHolderId), panoramaOptions);
  727. pano.setVisible(true);
  728.  
  729. google.maps.event.addListener(infowindow, 'closeclick', function() {
  730.  
  731. resetDirectionAddressFields(dirDivId);
  732. $(dirDivId).fadeOut();
  733.  
  734. if (pano != null) {
  735. pano.unbind("position");
  736. pano.setVisible(false);
  737. }
  738.  
  739. pano = null;
  740. });
  741.  
  742. google.maps.event.addListener(pano, 'closeclick', function() {
  743. if (pano != null) {
  744. pano.unbind("position");
  745. pano.setVisible(false);
  746. $('div#bubble-' + localBubbleData.bubbleHolderId).css("background", "none");
  747. }
  748.  
  749. pano = null;
  750. });
  751.  
  752. });
  753. } else {
  754. // no street view available in this range, or some error occurred
  755. //Logger.warn("There is not street view available for this marker location: " + marker.position + " status: " + status);
  756. $('a#trigger-' + localBubbleData.bubbleHolderId).live("click", function(e) {
  757. e.preventDefault();
  758. });
  759. $('a#trigger-' + localBubbleData.bubbleHolderId).attr("style", "text-decoration: none !important; color: #ddd !important");
  760.  
  761. google.maps.event.addListener(infowindow, 'domready', function () {
  762. $('a#trigger-' + localBubbleData.bubbleHolderId).removeAttr("href");
  763. $('a#trigger-' + localBubbleData.bubbleHolderId).attr("style", "text-decoration: none !important; color: #ddd !important");
  764. });
  765. }
  766. });
  767. }
  768.  
  769.  
  770. function bindDirectionControlsToEvents() {
  771.  
  772. var dirDivId = 'div#direction-controls-placeholder-' + mapDivId;
  773. var targetDiv = $("div#rendered-directions-placeholder-" + mapDivId);
  774.  
  775. $(dirDivId + ' a#reverse-btn').live("click", function(e) {
  776.  
  777. var old_a_addr = $(dirDivId + ' input#a_address').val();
  778. var old_b_addr = $(dirDivId + ' input#b_address').val();
  779.  
  780. $(dirDivId + ' input#a_address').val(old_b_addr);
  781. $(dirDivId + ' input#b_address').val(old_a_addr);
  782. return false;
  783. });
  784.  
  785. $(dirDivId + ' a#d_options_show').live("click", function() {
  786. $(dirDivId + ' a#d_options_hide').show();
  787. $(dirDivId + ' a#d_options_show').hide();
  788. $(dirDivId + ' div#d_options').show();
  789. return false;
  790. });
  791.  
  792. $(dirDivId + ' a#d_options_hide').live("click", function() {
  793. $(dirDivId + ' a#d_options_hide').hide();
  794. $(dirDivId + ' a#d_options_show').show();
  795. $(dirDivId + ' div#d_options').hide();
  796. $(dirDivId + ' input#avoid_hway').removeAttr("checked");
  797. $(dirDivId + ' input#avoid_tolls').removeAttr("checked");
  798. $(dirDivId + ' input#radio_km').removeAttr("checked");
  799. $(dirDivId + ' input#radio_miles').attr("checked", "checked");
  800. return false;
  801. });
  802.  
  803. $(dirDivId + ' button#d_sub').live("click", function() {
  804. var old_a_addr = $(dirDivId + ' input#a_address').val();
  805. var old_b_addr = $(dirDivId + ' input#b_address').val();
  806. var halt = false;
  807. if (old_a_addr == null || old_a_addr == '') {
  808. $(dirDivId + ' input#a_address').addClass('d_error');
  809. halt = true;
  810. }
  811.  
  812. if (old_b_addr == null || old_b_addr == '') {
  813. $(dirDivId + ' input#b_address').addClass('d_error');
  814. halt = true;
  815. }
  816.  
  817. if (!halt) {
  818.  
  819. $(dirDivId + ' button#d_sub').attr('disabled', 'disabled').html("Please wait..");
  820. // Query direction service
  821. var travelMode = google.maps.DirectionsTravelMode.DRIVING;
  822. if ($(dirDivId + ' a#dir_w_btn').hasClass('selected')) {
  823. travelMode = google.maps.DirectionsTravelMode.WALKING;
  824. }
  825.  
  826. var is_avoid_hway = $(dirDivId + ' input#avoid_hway').is(":checked");
  827. var is_avoid_tolls = $(dirDivId + ' input#avoid_tolls').is(":checked");
  828. var is_miles = $(dirDivId + ' input#radio_miles').is(":checked");
  829. var unitSystem = google.maps.DirectionsUnitSystem.METRIC;
  830.  
  831. var request = {
  832. origin: old_a_addr,
  833. destination: old_b_addr,
  834. travelMode: travelMode,
  835. provideRouteAlternatives: true
  836. };
  837.  
  838. if (is_avoid_hway) {
  839. request.avoidHighways = true;
  840. }
  841.  
  842. if (is_avoid_tolls) {
  843. request.avoidTolls = true;
  844. }
  845.  
  846. if (is_miles) {
  847. request.unitSystem = google.maps.DirectionsUnitSystem.IMPERIAL;
  848. } else {
  849. request.unitSystem = google.maps.DirectionsUnitSystem.METRIC;
  850. }
  851.  
  852. directionsService.route(request, function(response, status) {
  853.  
  854. if (status == google.maps.DirectionsStatus.OK) {
  855. targetDiv.html("");
  856. targetDiv.show();
  857. directionsRenderer.setMap(googleMap);
  858. directionsRenderer.setDirections(response);
  859. $(dirDivId + ' button#d_sub').removeAttr('disabled').html("Get directions");
  860. $(dirDivId + ' button#print_sub').fadeIn();
  861. infowindow.close();
  862.  
  863. } else {
  864. //Logger.error('Could not route directions from "' + old_a_addr + '" to "' + old_b_addr + '", got result from Google: ' + status);
  865. targetDiv.html("<span style='font-size: 12px; font-weight: bold; color: red'>Could not route directions from<br />'" + old_a_addr + "' to<br />'" + old_b_addr + "'<br />Got result from Google: [" + status + "]</span>");
  866.  
  867. $(dirDivId + ' button#print_sub').hide();
  868. $(dirDivId + ' button#d_sub').removeAttr('disabled').html("Get directions");
  869. }
  870. });
  871. }
  872. });
  873.  
  874. $(dirDivId + ' button#print_sub').live("click", function() {
  875. var old_a_addr = $(dirDivId + ' input#a_address').val();
  876. var old_b_addr = $(dirDivId + ' input#b_address').val();
  877.  
  878. var dirflag = "d";
  879. if ($(dirDivId + ' a#dir_w_btn').hasClass('selected')) {
  880. dirflag = "w";
  881. }
  882.  
  883. var url = "http://maps.google.com/?saddr=" + old_a_addr + "&daddr=" + old_b_addr + "&dirflg=" + dirflag + "&pw=2";
  884. var is_miles = $(dirDivId + ' input#radio_miles').is(":checked");
  885. if (is_miles) {
  886. url += "&doflg=ptm";
  887. }
  888.  
  889. window.open( url );
  890. return false;
  891. });
  892.  
  893. $(dirDivId + ' input#a_address').live("change focus", function() {
  894. $(dirDivId + ' input#a_address').removeClass('d_error');
  895. return false;
  896. });
  897.  
  898. $(dirDivId + ' input#b_address').live("change focus", function() {
  899. $(dirDivId + ' input#b_address').removeClass('d_error');
  900. return false;
  901. });
  902.  
  903.  
  904. $(dirDivId + ' .kd-button').live("click", function() {
  905. var thisId = this.id;
  906.  
  907. if (thisId == 'dir_d_btn') {
  908. if ($(dirDivId + ' a#dir_d_btn').hasClass('selected')) {
  909. //Logger.warn("Driving travel mode is already selected");
  910. } else {
  911. $(dirDivId + ' a#dir_d_btn').addClass('selected');
  912. $(dirDivId + ' a#dir_w_btn').removeClass('selected');
  913. }
  914. } else if (thisId == 'dir_w_btn') {
  915. if ($(dirDivId + ' a#dir_w_btn').hasClass('selected')) {
  916. //Logger.warn("Walking travel mode is already selected");
  917. } else {
  918. $(dirDivId + ' a#dir_w_btn').addClass('selected');
  919. $(dirDivId + ' a#dir_d_btn').removeClass('selected');
  920. }
  921. }
  922.  
  923. return false;
  924. });
  925.  
  926. }
  927.  
  928. function buildBubble(contentFromMarker, markersElement) {
  929.  
  930. var localBubbleData = [];
  931. var randomNumber = Math.floor(Math.random() * 111111);
  932.  
  933. randomNumber = randomNumber + "-" + mapDivId;
  934.  
  935. var bubble = "<div id='bubble-" + randomNumber + "' style='height: 130px !important; width: 300px !important;' class='bubble-content'>";
  936. //var bubble = document.createElement("div");
  937. //bubble.id = "bubble-" + randomNumber;
  938. //bubble.setAttribute("class", "bubble-content");
  939. //bubble.style.cssText = "height: 330px !important; width: 300px !important;";
  940.  
  941.  
  942. if (!markersElement.geoMashup) {
  943. bubble += "<h4>" + CGMPGlobal.translations.address + ":</h4>";
  944. bubble += "<p class='custom-bubble-text'>" + contentFromMarker + "</p>";
  945. if (markersElement.customBubbleText != '') {
  946. //var decodedHtml = $("<p></p>").html(markersElement.customBubbleText).text();
  947. bubble += "<p class='custom-bubble-text'>" + markersElement.customBubbleText + "</p>";
  948. }
  949. } else {
  950. var substr = markersElement.postTitle.substring(0, 600);
  951. bubble += "";
  952. bubble += "<p class='geo-mashup-post-title'><a title='Original post: " + markersElement.postTitle + "' href='" +markersElement.postLink+ "'>" + substr + "..</a></p>";
  953. bubble += "<p class='geo-mashup-post-excerpt'>" + markersElement.postExcerpt + "</p>";
  954. }
  955.  
  956. bubble += "<div class='custom-bubble-links-section'>";
  957. bubble += "<hr />";
  958. bubble += "<p class='custom-bubble-text'>" + CGMPGlobal.translations.directions + ": <a id='toHere-" + randomNumber + "' class='dirToHereTrigger' href='javascript:void(0);'>" + CGMPGlobal.translations.toHere + "</a> - <a id='fromHere-" + randomNumber + "' class='dirFromHereTrigger' href='javascript:void(0);'>" + CGMPGlobal.translations.fromHere + "</a> | <a id='trigger-" + randomNumber + "' class='streetViewTrigger' href='javascript:void(0);'>" + CGMPGlobal.translations.streetView + "</a></p>";
  959. bubble += "</div></div>";
  960.  
  961. return {bubbleHolderId : randomNumber, bubbleContent: bubble};
  962. }
  963.  
  964. function parseCsv() {
  965. var locations = csvString.split("|");
  966.  
  967. //Logger.info("Exploded CSV into locations: " + locations);
  968.  
  969. for (var i = 0; i < locations.length; i++) {
  970. var target = locations[i];
  971. if (target != null && target != "") {
  972. target = Utils.trim(target);
  973. if (target == "") {
  974. //Logger.warn("Given extra marker address is empty");
  975. continue;
  976. }
  977. pushGeoDestination(target, (i + 1));
  978. }
  979. }
  980. }
  981.  
  982. function parseJsonStructure(json, infoBubbleContainPostLink) {
  983.  
  984. var index = 1;
  985. $.each(json, function() {
  986. if (this.excerpt == null) {
  987. this.excerpt = '';
  988. }
  989. //Logger.info("Looping over JSON object:\n\tTitle: " + this.title + "\n\tAddy: " + this.addy + "\n\tLink: " + this.permalink + "\n\tExcerpt: " + this.excerpt);
  990. var targetArr = this.addy.split(CGMPGlobal.sep);
  991. targetArr[0] = this.location;
  992. addGeoPoint(index, targetArr, this.title, this.permalink, this.excerpt, infoBubbleContainPostLink);
  993. index ++;
  994. });
  995. Logger.info("Have " + (index - 1) + " destinations for marker Geo mashup..");
  996. }
  997.  
  998. function pushGeoDestination(target, index) {
  999.  
  1000. var targetArr = target.split(CGMPGlobal.sep);
  1001.  
  1002. if (Utils.isNumeric(targetArr[0])) {
  1003. addGeoPoint(index, targetArr, '', '', '', false);
  1004. } else if (Utils.isAlphaNumeric(targetArr[0])) {
  1005. storeAddress(index, targetArr, '', '', '', false);
  1006. } else {
  1007. storeAddress(index, targetArr, '', '', '', false);
  1008. //Logger.warn("Unknown type of geo destination in regexp: " + targetArr[0] + ", fallingback to store it as an address");
  1009. }
  1010. }
  1011.  
  1012. function storeAddress(zIndex, targetArr, postTitle, postLink, postExcerpt, geoMashup) {
  1013.  
  1014. if (targetArr[2] != null) {
  1015. if (targetArr[2].indexOf("No description provided") != -1) {
  1016. targetArr[2] = '';
  1017. }
  1018. } else {
  1019. targetArr[2] = '';
  1020. }
  1021. //Logger.info("Storing address: " + targetArr[0] + " for marker-to-be for the map ID: " + mapDivId);
  1022. storedAddresses.push({
  1023. address: targetArr[0],
  1024. animation: google.maps.Animation.DROP,
  1025. zIndex: zIndex,
  1026. markerIcon: targetArr[1],
  1027. customBubbleText: targetArr[2],
  1028. postTitle: postTitle,
  1029. postLink: postLink,
  1030. postExcerpt: postExcerpt,
  1031. geoMashup: geoMashup
  1032. });
  1033. }
  1034.  
  1035. function addGeoPoint(zIndex, targetArr, postTitle, postLink, postExcerpt, geoMashup) {
  1036.  
  1037. var latlngArr = [];
  1038. if (targetArr[0].indexOf(",") != -1) {
  1039. latlngArr = targetArr[0].split(",");
  1040. } else if (targetArr[0].indexOf(";") != -1) {
  1041. latlngArr = targetArr[0].split(";");
  1042. }
  1043.  
  1044. if (latlngArr.length == 0) {
  1045. //Logger.warn("Exploded lat/long array has length of zero");
  1046. return false;
  1047. }
  1048.  
  1049. latlngArr[0] = Utils.trim(latlngArr[0]);
  1050. latlngArr[1] = Utils.trim(latlngArr[1]);
  1051.  
  1052. if (latlngArr[0] == '' || latlngArr[1] == '') {
  1053. //Logger.warn("Lat or Long are empty string");
  1054. return false;
  1055. }
  1056.  
  1057. targetArr[0] = new google.maps.LatLng(parseFloat(latlngArr[0]), parseFloat(latlngArr[1]));
  1058. storeAddress(zIndex, targetArr, postTitle, postLink, postExcerpt, geoMashup);
  1059. }
  1060.  
  1061. function queryGeocoderService() {
  1062. clearTimeout(timeout);
  1063. if (storedAddresses.length > 0) {
  1064. var element = storedAddresses.shift();
  1065.  
  1066. if (element.address instanceof google.maps.LatLng) {
  1067. //Logger.info("No need to query Geo service for [" + element.address + "]. Have left " + storedAddresses.length + " items to process!");
  1068. buildLocationFromCoords(element);
  1069. //setBounds();
  1070. } else {
  1071. //Logger.info("Passing [" + element.address + "] to Geo service. Have left " + storedAddresses.length + " items to process!");
  1072. var geocoderRequest = {"address": element.address};
  1073. geocoder.geocode(geocoderRequest, function (results, status) {
  1074. geocoderCallback(results, status, element);
  1075. });
  1076. }
  1077. } else {
  1078.  
  1079. setBounds();
  1080.  
  1081. if (badAddresses.length > 0) {
  1082. var msg = "";
  1083. $.each(badAddresses, function (index, addy) {
  1084. msg += "&nbsp;&nbsp;&nbsp;<b>" + (1 + index) + ". " + addy + "</b><br />";
  1085. });
  1086.  
  1087. Errors.alertError(CGMPGlobal.errors.badAddresses.replace('[REPLACE]', msg));
  1088. }
  1089. badAddresses = [];
  1090. }
  1091. }
  1092.  
  1093. function setBounds() {
  1094.  
  1095. if (markers.length > 1) {
  1096. $.each(markers, function (index, marker) {
  1097. if (!bounds.contains(marker.position)) {
  1098. bounds.extend(marker.position);
  1099. }
  1100. });
  1101. originalExtendedBounds = bounds;
  1102. if (bounds != null) {
  1103. googleMap.fitBounds(bounds);
  1104. }
  1105. } else if (markers.length == 1) {
  1106. googleMap.setCenter(markers[0].position);
  1107. updatedZoom = googleMap.getZoom();
  1108. originalMapCenter = googleMap.getCenter();
  1109. }
  1110. }
  1111.  
  1112. function buildLocationFromCoords(element) {
  1113. var addressPoint = element.address;
  1114.  
  1115. element.address = "Lat/Long: " + addressPoint.lat().toFixed(6) + ", " + addressPoint.lng().toFixed(6);
  1116. instrumentMarker(addressPoint, element);
  1117. queryGeocoderService();
  1118. }
  1119.  
  1120. function geocoderCallback(results, status, element) {
  1121. if (status == google.maps.GeocoderStatus.OK) {
  1122. var addressPoint = results[0].geometry.location;
  1123. instrumentMarker(addressPoint, element);
  1124. timeout = setTimeout(function() { queryGeocoderService(); }, 2500);
  1125. } else if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
  1126. setBounds();
  1127. storedAddresses.push(element);
  1128. timeout = setTimeout(function() { queryGeocoderService(); }, 200);
  1129. } else if (status == google.maps.GeocoderStatus.ZERO_RESULTS) {
  1130. //Logger.warn("Got ZERO results for [" + element.address + "]. Have left " + markers.length + " items to process");
  1131. badAddresses.push(element.address);
  1132. timeout = setTimeout(function() { queryGeocoderService(); }, 250);
  1133. }
  1134.  
  1135. }
  1136.  
  1137.  
  1138. function instrumentMarker(point, element) {
  1139. var marker = new google.maps.Marker({
  1140. position: point,
  1141. title: element.address.replace("<br />", " :: "),
  1142. content: element.address,
  1143. zIndex: (element.zIndex + 1000),
  1144. map: googleMap
  1145. });
  1146. if (marker) {
  1147.  
  1148. if (element.markerIcon) {
  1149. var markerIcon = element.markerIcon;
  1150. if (typeof markerIcon == "undefined" || markerIcon === "undefined") {
  1151. markerIcon = '1-default.png';
  1152. }
  1153. marker.setIcon(CGMPGlobal.customMarkersUri + markerIcon);
  1154.  
  1155. var shadow = null;
  1156. var defaultMarkers = ['1-default.png', '2-default.png'];
  1157. var defaultPins = ['4-default.png', '5-default.png', '6-default.png', '7-default.png'];
  1158.  
  1159. if ($.inArray(markerIcon, defaultMarkers) != -1) {
  1160. var url = CGMPGlobal.customMarkersUri + "msmarker.shadow.png";
  1161. shadow = buildMarkerImage(url, 59, 32, 0, 0, 16, 33);
  1162. } else if ($.inArray(markerIcon, defaultPins) != -1) {
  1163. var url = CGMPGlobal.customMarkersUri + "msmarker.shadow.png";
  1164. shadow = buildMarkerImage(url, 59, 32, 0, 0, 21, 34);
  1165. } else if (markerIcon.indexOf('3-default') != -1) {
  1166. var url = CGMPGlobal.customMarkersUri + "beachflag_shadow.png";
  1167. shadow = buildMarkerImage(url, 37, 32, 0, 0, 10, 33);
  1168. } else {
  1169. shadow = buildMarkerImage(CGMPGlobal.customMarkersUri + "shadow.png", 68, 37, 0, 0, 32, 38);
  1170. }
  1171.  
  1172. marker.setShadow(shadow);
  1173. }
  1174.  
  1175. attachEventlistener(marker, element);
  1176. if (!directionControlsBinded) {
  1177. bindDirectionControlsToEvents();
  1178. directionControlsBinded = true;
  1179. }
  1180.  
  1181. markers.push(marker);
  1182. }
  1183. }
  1184.  
  1185. function buildMarkerImage(url, sizeX, sizeY, pointAX, pointAY, pointBX, pointBY) {
  1186.  
  1187. var image = new google.maps.MarkerImage(url,
  1188. new google.maps.Size(sizeX, sizeY),
  1189. new google.maps.Point(pointAX, pointAY),
  1190. new google.maps.Point(pointBX, pointBY));
  1191.  
  1192. return image;
  1193. }
  1194.  
  1195. return {
  1196. init: init,
  1197. buildAddressMarkers: buildAddressMarkers,
  1198. isBuildAddressMarkersCalled: isBuildAddressMarkersCalled
  1199. }
  1200. };
  1201.  
  1202.  
  1203.  
  1204. var Utils = (function() {
  1205. var isNumeric = function isNumeric(subject) {
  1206. var numericRegex = /^([0-9?(\-.,;\s{1,})]+)$/;
  1207. return numericRegex.test(subject);
  1208. }
  1209. var isAlphaNumeric = function isAlphaNumeric(subject) {
  1210. var addressRegex = /^([a-zA-Z0-9?(/\-.,\s{1,})]+)$/;
  1211. return addressRegex.test(subject);
  1212. }
  1213. var trim = function trim(subject) {
  1214. var leftTrimRegex = /^\s\s*/;
  1215. var rightTrimRegex = /\s\s*$/;
  1216. var trimRegex = /^\s+|\s+$/g;
  1217. return subject.replace(trimRegex, '');
  1218. }
  1219. var searchReplace = function searchReplace(subject, search, replace) {
  1220. return subject.replace(new RegExp(search, "g"), replace);
  1221. }
  1222. return {
  1223. isNumeric: isNumeric,
  1224. isAlphaNumeric: isAlphaNumeric,
  1225. trim: trim,
  1226. searchReplace: searchReplace
  1227. }
  1228. })();
  1229.  
  1230.  
  1231.  
  1232. var Logger = (function() {
  1233. var info = function info(message) {
  1234. var msg = "Info :: " + message;
  1235. print(msg);
  1236. }
  1237. var raw = function raw(msg) {
  1238. print(msg);
  1239. }
  1240. var warn = function warn(message) {
  1241. var msg = "Warning :: " + message;
  1242. print(msg);
  1243. }
  1244. var error = function error(message) {
  1245. var msg = "Error :: " + message;
  1246. print(msg);
  1247. }
  1248. var fatal = function fatal(message) {
  1249. var msg = "Fatal :: " + message;
  1250. print(msg);
  1251. }
  1252. var print = function print(message) {
  1253. if ( $.browser.msie ) {
  1254. //Die... die... die.... why dont you just, die???
  1255. } else {
  1256. if ($.browser.mozilla && parseInt($.browser.version) >= 1 ) {
  1257. console.log(message);
  1258. } else if ($.browser.webkit && parseInt($.browser.version) >= 534) {
  1259. console.log(message);
  1260. } else if ($.browser.opera && parseInt($.browser.version) >= 11 ) {
  1261. console.log(message);
  1262. }
  1263. }
  1264. }
  1265.  
  1266. return {
  1267. info: info,
  1268. raw: raw,
  1269. warn: warn,
  1270. error: error,
  1271. fatal: fatal
  1272. }
  1273. })();
  1274.  
  1275.  
  1276. var Errors = (function() {
  1277.  
  1278. var alertError = function alertError(content) {
  1279.  
  1280. var mask = $('<div id="cgmp-popup-mask"/>');
  1281. var id = Math.random().toString(36).substring(3);
  1282. var shortcode_dialog = $('<div id="' + id + '" class="cgmp-popup-shortcode-dialog cgmp-popup-window">');
  1283. shortcode_dialog.html("<div class='dismiss-container'><a class='dialog-dismiss' href='javascript:void(0)'>×</a></div><p style='text-align: left; padding: 10px 10px 0 10px'>" + content + "</p><div align='center'><input type='button' class='close-dialog' value='Close' /></div>");
  1284.  
  1285. $('body').append(mask);
  1286. $('body').append(shortcode_dialog);
  1287.  
  1288. var maskHeight = $(document).height();
  1289. var maskWidth = $(window).width();
  1290. $('#cgmp-popup-mask').css({'width':maskWidth,'height':maskHeight, 'opacity':0.1});
  1291.  
  1292. if ($("#cgmp-popup-mask").length == 1) {
  1293. $('#cgmp-popup-mask').show();
  1294. }
  1295.  
  1296. var winH = $(window).height();
  1297. var winW = $(window).width();
  1298. $("div#" + id).css('top', winH/2-$("div#" + id).height()/2);
  1299. $("div#" + id).css('left', winW/2-$("div#" + id).width()/2);
  1300. $("div#" + id).fadeIn(500);
  1301. $('.cgmp-popup-window .close-dialog').click(function (e) {
  1302. close_dialog(e, $(this));
  1303. });
  1304. $('.cgmp-popup-window .dialog-dismiss').click(function (e) {
  1305. close_dialog(e, $(this));
  1306. });
  1307.  
  1308. function close_dialog(e, object) {
  1309. e.preventDefault();
  1310.  
  1311. var parentDialog = $(object).closest("div.cgmp-popup-shortcode-dialog");
  1312. if (parentDialog) {
  1313. $(parentDialog).remove();
  1314. }
  1315.  
  1316. if ($("div.cgmp-popup-shortcode-dialog").length == 0) {
  1317. $('#cgmp-popup-mask').remove();
  1318. }
  1319. }
  1320.  
  1321. $('#cgmp-popup-mask').click(function () {
  1322. $(this).remove();
  1323. $('.cgmp-popup-window').remove();
  1324. });
  1325. $(window).resize(function () {
  1326. var box = $('.window');
  1327. var maskHeight = $(document).height();
  1328. var maskWidth = $(window).width();
  1329. $('#cgmp-popup-mask').css({'width':maskWidth,'height':maskHeight});
  1330. var winH = $(window).height();
  1331. var winW = $(window).width();
  1332. box.css('top', winH/2 - box.height()/2);
  1333. box.css('left', winW/2 - box.width()/2);
  1334. });
  1335. }
  1336.  
  1337. return {
  1338. alertError: alertError
  1339. }
  1340. })();
  1341.  
  1342.  
  1343. //$(document).ready(function() {
  1344.  
  1345. if ($('object#global-data-placeholder').length == 0) {
  1346. //Logger.fatal("The global HTML <object> element is undefined. Aborting map generation .. d[-_-]b");
  1347. return;
  1348. }
  1349.  
  1350. var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement;
  1351. var link = document.createElement('link');
  1352. link.type= 'text/css';
  1353. link.rel = 'stylesheet';
  1354. link.href = $("object#global-data-placeholder").find("param#cssHref").val();
  1355. link.media = 'screen';
  1356. head.appendChild(link);
  1357.  
  1358. CGMPGlobal.sep = $("object#global-data-placeholder").find("param#sep").val();
  1359. CGMPGlobal.customMarkersUri = $("object#global-data-placeholder").find("param#customMarkersUri").val();
  1360. CGMPGlobal.errors = $("object#global-data-placeholder").find("param#errors").val();
  1361.  
  1362. CGMPGlobal.errors = parseJson(CGMPGlobal.errors);
  1363. CGMPGlobal.translations = $("object#global-data-placeholder").find("param#translations").val();
  1364. CGMPGlobal.translations = parseJson(CGMPGlobal.translations);
  1365.  
  1366. var version = parseFloat($.fn.jquery);
  1367. if (version < 1.1) {
  1368. alert(CGMPGlobal.errors.oldJquery);
  1369. //Logger.fatal("Client uses jQuery older than the version 1.3.0. Aborting map generation ..");
  1370. return false;
  1371. }
  1372.  
  1373. if (typeof google == "undefined" || !google) {
  1374. Errors.alertError(CGMPGlobal.errors.msgNoGoogle);
  1375. //Logger.fatal("We do not have reference to Google API. Aborting map generation ..");
  1376. return false;
  1377. } else if (typeof GMap2 != "undefined" && GMap2) {
  1378. Errors.alertError(CGMPGlobal.errors.msgApiV2);
  1379. //Logger.fatal("It looks like the webpage has reference to GMap2 object from Google API v2. Aborting map generation ..");
  1380. return false;
  1381. }
  1382.  
  1383. CGMPGlobal.language = $("object#global-data-placeholder").find("param#language").val();
  1384. google.load('maps', '3', {other_params:'sensor=true&libraries=panoramio&language=' + CGMPGlobal.language, callback: function () { google_map_api_callback(); }});
  1385.  
  1386. function google_map_api_callback() {
  1387.  
  1388. $("object.cgmp-json-string-placeholder").each(function (index, element) {
  1389.  
  1390. var currentElementId = $(element).attr('id');
  1391. var jsonString = $(element).find('param#json-string-' + currentElementId).val();
  1392. jsonString = Utils.searchReplace(jsonString, "'", "");
  1393. jsonString = jsonString.replace("&quot;", "");
  1394.  
  1395. var json = parseJson(jsonString);
  1396.  
  1397. if (typeof json == "undefined" || !json) {
  1398. //Logger.fatal("We did not parse JSON from OBJECT param. Aborting map generation ..");
  1399. return false;
  1400. }
  1401.  
  1402. if ($('div#' + json.id).length > 0) {
  1403.  
  1404. var googleMap = new google.maps.Map(document.getElementById(json.id));
  1405.  
  1406. GoogleMapOrchestrator.initMap(googleMap, json.bubbleautopan, parseInt(json.zoom), json.maptype);
  1407. LayerBuilder.init(googleMap);
  1408. var markerBuilder = new MarkerBuilder();
  1409. markerBuilder.init(googleMap, json.bubbleautopan);
  1410.  
  1411.  
  1412. var controlOptions = {
  1413. mapTypeControl: (json.maptypecontrol === 'true'),
  1414. panControl: (json.pancontrol === 'true'),
  1415. zoomControl: (json.zoomcontrol === 'true'),
  1416. scaleControl: (json.scalecontrol === 'true'),
  1417. scrollwheel: (json.scrollwheelcontrol === 'true'),
  1418. streetViewControl: (json.streetviewcontrol === 'true'),
  1419. tilt: (json.tiltfourtyfive === 'true' ? 45 : null),
  1420. draggable: (json.draggable === 'true'),
  1421. overviewMapControl: true,
  1422. overviewMapControlOptions: {opened: false}
  1423. };
  1424. GoogleMapOrchestrator.setMapControls(controlOptions);
  1425.  
  1426. if (json.showpanoramio === "true") {
  1427. LayerBuilder.buildPanoramioLayer(json.panoramiouid);
  1428. }
  1429.  
  1430. if (json.showbike === "true") {
  1431. LayerBuilder.buildBikeLayer();
  1432. }
  1433. if (json.showtraffic === "true") {
  1434. LayerBuilder.buildTrafficLayer();
  1435. }
  1436.  
  1437. if (json.kml != null && Utils.trim(json.kml) != '') {
  1438. LayerBuilder.buildKmlLayer(json.kml);
  1439. } else {
  1440.  
  1441. if (json.markerlist != null && Utils.trim(json.markerlist) != '') {
  1442. markerBuilder.buildAddressMarkers(json.markerlist, json.addmarkermashup, json.addmarkermashupbubble);
  1443. }
  1444.  
  1445. var isBuildAddressMarkersCalled = markerBuilder.isBuildAddressMarkersCalled();
  1446. if (!isBuildAddressMarkersCalled) {
  1447. Errors.alertError(CGMPGlobal.errors.msgMissingMarkers);
  1448. }
  1449. }
  1450. } else {
  1451. //Logger.fatal("It looks like the map DIV placeholder ID [" + json.id + "] does not exist in the page!");
  1452. }
  1453. });
  1454.  
  1455. }
  1456. //});
  1457. }(jQueryObj));
  1458. }
  1459. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement