Advertisement
Guest User

best cmgp.framework.min.js script with geo and from/to here

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