From a099229e9a31d1e695d3cfc24dd4c3a9812d46c6 Mon Sep 17 00:00:00 2001 From: Matt Driscoll Date: Tue, 11 Sep 2012 14:19:44 -0700 Subject: [PATCH] fixes --- SocialMedia/config/config.js | 5 +- SocialMedia/css/application.css | 47 +-- SocialMedia/css/slider.css | 4 - SocialMedia/images/ui/crosshairblue.cur | Bin 640 -> 0 bytes SocialMedia/index.html | 6 +- SocialMedia/js/application/common.js | 41 +-- SocialMedia/js/application/main.js | 6 +- SocialMedia/js/application/socialLayers.js | 338 ++++++--------------- SocialMedia/js/social/flickr.js | 169 ++++------- SocialMedia/js/social/twitter.js | 146 ++++----- SocialMedia/js/social/youtube.js | 155 ++++------ SocialMedia/readme.html | 3 - resources/configJSON.js | 21 -- 13 files changed, 280 insertions(+), 661 deletions(-) delete mode 100644 SocialMedia/images/ui/crosshairblue.cur diff --git a/SocialMedia/config/config.js b/SocialMedia/config/config.js index f1a7263..9b1a282 100644 --- a/SocialMedia/config/config.js +++ b/SocialMedia/config/config.js @@ -1,14 +1,13 @@ { "appid":"", "webmap":"4ff792a3962547caad2d924413c40985", - "socialDistance":"regional", "socialDisplay":"cluster", "showFlickr":true, "showFlickrConfig":true, "flickrChecked":true, "flickrSearch":"food", "flickrRange":"this_week", - "flickrKey":"", + "flickrKey":"ce3afb039084d0c6456a2ff15be448e7", "showYouTube":true, "showYouTubeConfig":true, "youtubeChecked":true, @@ -30,7 +29,6 @@ "sharingurl":"http://www.arcgis.com/sharing/rest/content/items", "portalUrl":"http://www.arcgis.com/", "bingMapsKey":"", - "crosshairImage":"images/ui/crosshairblue.cur", "defaultMenu":"social", "showSearchBox":true, "showShareMenu":true, @@ -42,7 +40,6 @@ "showGeolocation":true, "showAboutDialog":true, "showAboutDialogOnLoad":false, - "socialPoint":"", "locateName":"", "locatePoint":"", "sourceCountry":"USA" diff --git a/SocialMedia/css/application.css b/SocialMedia/css/application.css index 3c57032..bded2c8 100644 --- a/SocialMedia/css/application.css +++ b/SocialMedia/css/application.css @@ -408,7 +408,7 @@ background: -moz-linear-gradient(top, #f0f0f0 0%, #fefefe 100%); border-radius: 2px; } -.barButton .barIcon { +.barButton .barIcon, .inlineIcon { display: inline-block; vertical-align: text-bottom; width: 16px; @@ -1009,40 +1009,6 @@ background: -moz-linear-gradient(top, #bd362f 0%, #ee5f5b 100%); text-align: center; } -#settingsDialog .smallTxt { - font-size: 11px; - color: #666; - font-family: Arial, Helvetica, sans-serif; -} - -.resetCenter { - display: inline-block; - display: none; - width: 16px; - height: 16px; - vertical-align: text-top; - z-index: 2; - overflow: hidden; - cursor: pointer; - background: url(../images/ui/uiSprite.png?v=3.01) no-repeat -32px 0px; -} - -.locationButton { - margin-right: 10px; -} - -.locationButton .iconBlock { - display: inline-block; - width: 15px; - height: 15px; - vertical-align: top; - background: url(../images/ui/uiSprite.png?v=3.01) no-repeat -384px 0px; -} - -#socialUseCenter { - margin-left: 10px; -} - .socialIcon { background: url(../images/ui/uiSprite.png?v=3.01) no-repeat -160px -16px; } @@ -1082,17 +1048,6 @@ background: -moz-linear-gradient(top, #bd362f 0%, #ee5f5b 100%); margin-right: 10px; } -.formStyle .sliderTxt { - font-size: 12px; - display: inline-block; - line-height: 16px; - padding: 4px 0; -} - -.allOptions { - margin-top: 10px; -} - .twInfo { display: inline-block; height: 16px; diff --git a/SocialMedia/css/slider.css b/SocialMedia/css/slider.css index 54c37e9..3547172 100644 --- a/SocialMedia/css/slider.css +++ b/SocialMedia/css/slider.css @@ -43,10 +43,6 @@ width: 100px; } -.modernGrey #socialSlider .dijitSliderBarContainerH { - width: 60px; -} - .modernGrey .dijitSliderBar { border: 0; outline: 0; diff --git a/SocialMedia/images/ui/crosshairblue.cur b/SocialMedia/images/ui/crosshairblue.cur deleted file mode 100644 index e1a228316087a07c597dd8bfe4f1acce199a7f39..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 640 zcmV-`0)PDg00IC303aX$000000BQmN02TlM0EtjeM-2)Z3IG5A4M|8uQUCw|AOHXW zAP5Ek0047(dh`GQ010qNS#tmY3ljhU3ljkVnw%H_00JCIL_t(oh3%FLgl=@hzj$=prK1*b-Is1#f-1h>vvx;S>RjSv!=C7@e} z(jy=Nu~5^}6jS4`gN>AwlDk|(mixkkclX}?-iPC>D2DHIQ5{UWgQCDtn^-B*lk>87t&P8it|$M~%K`bScKSM3Z3I4i{_)pf^!6=i_X3Tl z%d<}am<}YXNtk~7sk!s!V^Wr_A$WpuZgzyR(JP~%3He?~oGm~{KUWcNN`Yw`a9U|SA=1K - - + + @@ -34,7 +34,7 @@ - + diff --git a/SocialMedia/js/application/common.js b/SocialMedia/js/application/common.js index 3dfc394..046f166 100644 --- a/SocialMedia/js/application/common.js +++ b/SocialMedia/js/application/common.js @@ -75,7 +75,7 @@ function configUrlParams() { // Set sharing links function setSharing(isPreviewPage) { // parameters to share - var urlParams = ['webmap', 'basemap', 'extent', 'locateName', 'layers', 'youtubeSearch', 'youtubeRange', 'youtubeChecked', 'twitterSearch', 'twitterChecked', 'flickrSearch', 'flickrRange', 'flickrChecked', 'socialDistance', 'socialPoint', 'socialDisplay', 'locatePoint']; + var urlParams = ['webmap', 'basemap', 'extent', 'locateName', 'layers', 'youtubeSearch', 'youtubeRange', 'youtubeChecked', 'twitterSearch', 'twitterChecked', 'flickrSearch', 'flickrRange', 'flickrChecked', 'socialDisplay', 'locatePoint']; if (urlParams) { configOptions.shareParams = ''; // for each parameter @@ -160,31 +160,6 @@ function setDefaultConfigOptions() { }; configOptions.previewPage = 'preview.html'; configOptions.homePage = 'index.html'; - configOptions.socialSliderValues = [{ - "label": i18n.viewer.distanceSlider.local, - "id": "local", // url param, don't localize - "values": { - "yt": 50, - "tw": 50, - "fl": 50 - } - }, { - "label": i18n.viewer.distanceSlider.regional, - "id": "regional", // url param, don't localize - "values": { - "yt": 300, - "tw": 300, - "fl": 300 - } - }, { - "label": i18n.viewer.distanceSlider.national, - "id": "national", // url param, don't localize - "values": { - "yt": 600, - "tw": 600, - "fl": 600 - } - }]; configOptions.flickrID = "flickr"; configOptions.flickrTitle = i18n.viewer.flickr.title; configOptions.flickrDescription = i18n.viewer.flickr.description; @@ -215,11 +190,6 @@ function setDefaultConfigOptions() { if (!configOptions.layerInfos) { configOptions.layerInfos = []; } - if (configOptions.socialPoint && typeof configOptions.socialPoint === 'string') { - configOptions.socialPoint = configOptions.socialPoint.split(','); - } else { - configOptions.socialPoint = []; - } if (configOptions.layers && typeof configOptions.layers === 'string') { configOptions.layers = configOptions.layers.split(','); } else { @@ -242,15 +212,6 @@ function setDefaultConfigOptions() { dirNode.attr("dir", "ltr"); dirNode.addClass('esriLtr'); } - // socialDistance - configOptions.socialSliderCurrent = 1; - if (configOptions.socialSliderValues) { - for (var i = 0; i < configOptions.socialSliderValues.length; i++) { - if (configOptions.socialDistance.toLowerCase() === configOptions.socialSliderValues[i].id) { - configOptions.socialSliderCurrent = i; - } - } - } } // make sure config options are correct diff --git a/SocialMedia/js/application/main.js b/SocialMedia/js/application/main.js index 52c83da..9d409f9 100644 --- a/SocialMedia/js/application/main.js +++ b/SocialMedia/js/application/main.js @@ -616,9 +616,13 @@ function configureAboutText() { draggable: true, modal: false, showTitle: true, - title: '' + i18n.viewer.about.title + title: i18n.viewer.about.title }; configOptions.aboutDialog = new dijit.Dialog(props, dojo.byId('aboutDialog')); + node = dojo.query('#aboutDialog .dijitDialogTitle')[0]; + if (node) { + node.innerHTML = '' + i18n.viewer.about.title; + } if (configOptions.showAboutDialogOnLoad) { configOptions.aboutDialog.show(); } diff --git a/SocialMedia/js/application/socialLayers.js b/SocialMedia/js/application/socialLayers.js index 53b9afe..df8b402 100644 --- a/SocialMedia/js/application/socialLayers.js +++ b/SocialMedia/js/application/socialLayers.js @@ -9,28 +9,6 @@ function toggleSettingsContent() { } } -// Get distances for social search based on vernacular slider -function getSocialDistance(socID) { - var distance = 500; - if (socID && configOptions.socialSliderValues) { - if (configOptions.socialSliderValues[configOptions.socialSliderCurrent]) { - distance = configOptions.socialSliderValues[configOptions.socialSliderCurrent].values[socID.toLowerCase()]; - } - } - return distance; -} - -// returns a nice geoPoint w/ a formatted string -function prettyGeoPoint(mapPoint) { - this.geo = esri.geometry.webMercatorToGeographic(mapPoint); - this.x_float = this.geo.x; - this.y_float = this.geo.y; - this.x = this.geo.x.toFixed(2); - this.y = this.geo.y.toFixed(2); - this.geoString = i18n.viewer.settings.latitude + ' ' + this.x + ' ' + i18n.viewer.settings.longitude + ' ' + this.y + ''; - return this; -} - // return date object for flickr dateFrom and dateTo function getFlickrDate(type) { var todate = new Date(); @@ -67,49 +45,20 @@ function getFlickrDate(type) { } } -// Sets social media search center point -function setMenuForLatLong(PGP, locationText) { - if (map && PGP && locationText) { - map.setMapCursor('default'); - if (locationText[0]) { - locationText[0].innerHTML = PGP.geoString; - } - locationText.next('.resetCenter').style('display', 'inline-block'); - dojo.query('#settingsDialog .locationButton').removeClass('buttonSelected'); - setSharing(); - } -} - // settings panel ui function configureSettingsUI() { var props = { style: "width: 400px", draggable: true, showTitle: true, - title: '
' + i18n.viewer.settings.title + '' + title: i18n.viewer.settings.title }; // new dijit.Dialog( configOptions.settingsDialog = new dijit.Dialog(props, dojo.byId('settingsDialog')); - // Social Slider - configOptions.socialSliderCurrent = parseInt(configOptions.socialSliderCurrent, 10); - var slider = new dijit.form.HorizontalSlider({ - name: "slider", - value: configOptions.socialSliderCurrent, - minimum: 0, - maximum: 2, - showButtons: false, - discreteValues: 3, - intermediateChanges: true, - style: "width:60px; display:inline-block; *display:inline; margin-right:10px; vertical-align:middle;", - onChange: function (value) { - var index = parseInt(value, 10); - if (configOptions.socialSliderValues[index]) { - dojo.query('#socialmi').text(configOptions.socialSliderValues[index].label); - configOptions.socialSliderCurrent = index; - configOptions.socialDistance = configOptions.socialSliderValues[index].id; - } - } - }, "socialSlider"); + var node = dojo.query('#settingsDialog .dijitDialogTitle')[0]; + if (node) { + node.innerHTML = '
' + i18n.viewer.settings.title + ''; + } // Settings Menu Config dojo.query(document).delegate("#cfgMenu .mapButton", "onclick,keyup", function (event) { @@ -174,42 +123,6 @@ function configureSettingsUI() { changeFlickr(); } }); - - dojo.query(document).delegate("#settingsDialog .locationButton", "onclick,keyup", function (event) { - if (event.type === 'click' || (event.type === 'keyup' && event.keyCode === 13)) { - dojo.query(this).addClass('buttonSelected'); - var locationText = dojo.query('#socialLocationText'); - locationText.next('.resetCenter').style('display', 'none'); - locationText.text(i18n.viewer.settings.locationText); - map.setMapCursor("url(" + configOptions.crosshairImage + "), auto"); - var PGP; - //click universal social geo choose and then... - configOptions.socialClickListener = dojo.connect(map, "onClick", function (evt) { - PGP = prettyGeoPoint(evt.mapPoint); - configOptions.socialPoint[0] = PGP.x; - configOptions.socialPoint[1] = PGP.y; - setMenuForLatLong(PGP, locationText); - clearDataPoints(); - updateSocialLayers(); - dojo.disconnect(configOptions.socialClickListener); - }); - } - }); - //set the passed variable for social geo - if (configOptions.socialPoint[0] && configOptions.socialPoint[1]) { - var prePoint = { - "x": configOptions.socialPoint[0], - "y": configOptions.socialPoint[1], - "geoString": i18n.viewer.settings.latitude + ' ' + configOptions.socialPoint[0] + ' ' + i18n.viewer.settings.longitude + ' ' + configOptions.socialPoint[1] + '' - }; - setMenuForLatLong(prePoint, dojo.query('#socialLocationText')); - } - // reset to center of map - dojo.query(document).delegate("#settingsDialog .resetCenter", "onclick,keyup", function (event) { - if (event.type === 'click' || (event.type === 'keyup' && event.keyCode === 13)) { - resetMenuForCenter(dojo.query(this)); - } - }); } function clearDataPoints() { @@ -234,9 +147,6 @@ function changeYouTube() { youtubeLayer.clear(); youtubeLayer.update({ searchTerm: configOptions.youtubeSearch, - distance: getSocialDistance("yt"), - socialSourceX: configOptions.socialPoint[0], - socialSourceY: configOptions.socialPoint[1], range: configOptions.youtubeRange }); } @@ -249,10 +159,7 @@ function changeTwitter() { setSharing(); twitterLayer.clear(); twitterLayer.update({ - searchTerm: configOptions.twitterSearch, - distance: getSocialDistance("tw"), - socialSourceX: configOptions.socialPoint[0], - socialSourceY: configOptions.socialPoint[1] + searchTerm: configOptions.twitterSearch }); } @@ -265,10 +172,7 @@ function changeFlickr() { setSharing(); flickrLayer.clear(); var updateObj = { - searchTerm: configOptions.flickrSearch, - distance: getSocialDistance("fl"), - socialSourceX: configOptions.socialPoint[0], - socialSourceY: configOptions.socialPoint[1] + searchTerm: configOptions.flickrSearch }; if (configOptions.flickrRange) { updateObj.dateFrom = getFlickrDate('from'); @@ -277,18 +181,6 @@ function changeFlickr() { flickrLayer.update(updateObj); } -// resets social media center point to map center -function resetMenuForCenter(btn) { - if (btn) { - configOptions.socialPoint[0] = ''; - configOptions.socialPoint[1] = ''; - var locationText = btn.prev('.smallTxt'); - locationText.text(i18n.viewer.settings.centerOfMap); - setSharing(); - btn.style('display', 'none'); - } -} - // gets string for social media popup title function getSmPopupTitle() { var graphic = configOptions.customPopup.getSelectedFeature(); @@ -356,9 +248,6 @@ function updateSocialLayers() { ytList.addClass("cLoading"); youtubeLayer.update({ searchTerm: configOptions.youtubeSearch, - distance: getSocialDistance("yt"), - socialSourceX: configOptions.socialPoint[0], - socialSourceY: configOptions.socialPoint[1], range: configOptions.youtubeRange }); } @@ -369,10 +258,7 @@ function updateSocialLayers() { if (dojo.hasClass(twList[0], "checked")) { twList.addClass("cLoading"); twitterLayer.update({ - searchTerm: configOptions.twitterSearch, - distance: getSocialDistance("tw"), - socialSourceX: configOptions.socialPoint[0], - socialSourceY: configOptions.socialPoint[1] + searchTerm: configOptions.twitterSearch }); } } @@ -382,10 +268,7 @@ function updateSocialLayers() { if (dojo.hasClass(flList[0], "checked")) { flList.addClass("cLoading"); var updateObj = { - searchTerm: configOptions.flickrSearch, - distance: getSocialDistance("fl"), - socialSourceX: configOptions.socialPoint[0], - socialSourceY: configOptions.socialPoint[1] + searchTerm: configOptions.flickrSearch }; if (configOptions.flickrRange) { updateObj.dateFrom = getFlickrDate('from'); @@ -399,11 +282,9 @@ function updateSocialLayers() { // reset social refresh timer function resetSocialRefreshTimer() { clearTimeout(configOptions.autoRefreshTimer); - if (!(configOptions.socialPoint[0] && configOptions.socialPoint[1])) { - configOptions.autoRefreshTimer = setTimeout(function () { - updateSocialLayers(); - }, 4000); - } + configOptions.autoRefreshTimer = setTimeout(function () { + updateSocialLayers(); + }, 4000); } // toggle social media layer on and off @@ -426,28 +307,19 @@ function toggleMapLayerSM(layerid) { configOptions.youtubeChecked = true; youtubeLayer.update({ searchTerm: configOptions.youtubeSearch, - distance: getSocialDistance("yt"), - socialSourceX: configOptions.socialPoint[0], - socialSourceY: configOptions.socialPoint[1], range: configOptions.youtubeRange }); break; case twID: configOptions.twitterChecked = true; twitterLayer.update({ - searchTerm: configOptions.twitterSearch, - distance: getSocialDistance("tw"), - socialSourceX: configOptions.socialPoint[0], - socialSourceY: configOptions.socialPoint[1] + searchTerm: configOptions.twitterSearch }); break; case flID: configOptions.flickrChecked = true; var updateObj = { - searchTerm: configOptions.flickrSearch, - distance: getSocialDistance("fl"), - socialSourceX: configOptions.socialPoint[0], - socialSourceY: configOptions.socialPoint[1] + searchTerm: configOptions.flickrSearch }; if (configOptions.flickrRange) { updateObj.dateFrom = getFlickrDate('from'); @@ -699,23 +571,6 @@ function insertSettingsHTML() { } } html += ''; - html += '
'; - html += '
'; - html += '
    '; - html += '
  • '; - html += ''; - html += '' + i18n.viewer.settings.centerOfMap + ''; - html += '
    '; - html += '
  • '; - html += '
  • '; - html += ''; - html += ''; - html += '' + configOptions.socialSliderValues[configOptions.socialSliderCurrent].label + ''; - html += '
    '; - html += '
  • '; - html += '
'; - html += '
'; - html += '
'; html += ''; var node = dojo.byId('settingsDialog'); if (node) { @@ -779,8 +634,6 @@ function configureSocialMedia() { if (configOptions.showFlickr) { flickrLayer = new social.flickr({ map: map, - autopage: true, - maxpage: 2, title: configOptions.flickrTitle, id: configOptions.flickrID, searchTerm: configOptions.flickrSearch, @@ -791,30 +644,7 @@ function configureSocialMedia() { popupHeight: configOptions.popupHeight, dateFrom: getFlickrDate('from'), dateTo: getFlickrDate('to'), - apiKey: configOptions.flickrKey, - distance: getSocialDistance("fl"), - onClear: function () { - var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.flickrID + '] .count')[0]; - if (node) { - node.innerHTML = ''; - } - }, - onUpdateEnd: function (totalCount) { - hideLoading(dojo.query('#socialMenu ul li[data-layer=' + configOptions.flickrID + ']'), dojo.query('#FLLoad')); - var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.flickrID + '] .keyword')[0]; - if (node) { - node.innerHTML = configOptions.flickrSearch; - } - var textCount = ''; - if (totalCount) { - textCount = ' (' + totalCount + ')' || ''; - } - node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.flickrID + '] .count')[0]; - if (node) { - node.innerHTML = textCount; - } - }, - onSetTitle: getSmPopupTitle + apiKey: configOptions.flickrKey }); clusterLayer.featureLayer.renderer.addValue({ value: configOptions.flickrID, @@ -826,8 +656,32 @@ function configureSocialMedia() { }), label: configOptions.flickrTitle }); - dojo.connect(flickrLayer, 'onUpdate', updateDataPoints); - dojo.connect(flickrLayer, 'onClear', updateDataPoints); + dojo.connect(flickrLayer, 'onUpdate', function () { + updateDataPoints(); + }); + dojo.connect(flickrLayer, 'onClear', function () { + updateDataPoints(); + var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.flickrID + '] .count')[0]; + if (node) { + node.innerHTML = ''; + } + }); + dojo.connect(flickrLayer, 'onUpdateEnd', function () { + var totalCount = flickrLayer.getStats().geoPoints; + hideLoading(dojo.query('#socialMenu ul li[data-layer=' + configOptions.flickrID + ']'), dojo.query('#FLLoad')); + var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.flickrID + '] .keyword')[0]; + if (node) { + node.innerHTML = configOptions.flickrSearch; + } + var textCount = ''; + if (totalCount) { + textCount = ' (' + totalCount + ')' || ''; + } + node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.flickrID + '] .count')[0]; + if (node) { + node.innerHTML = textCount; + } + }); // insert html insertSMItem({ visible: configOptions.flickrChecked, @@ -843,8 +697,6 @@ function configureSocialMedia() { if (configOptions.showTwitter) { twitterLayer = new social.twitter({ map: map, - autopage: true, - maxpage: 4, title: configOptions.twitterTitle, id: configOptions.twitterID, searchTerm: configOptions.twitterSearch, @@ -852,30 +704,7 @@ function configureSocialMedia() { symbolHeight: configOptions.twitterSymbol.height, symbolWidth: configOptions.twitterSymbol.width, popupWidth: configOptions.popupWidth, - popupHeight: configOptions.popupHeight, - distance: getSocialDistance("tw"), - onClear: function () { - var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.twitterID + '] .count')[0]; - if (node) { - node.innerHTML = ''; - } - }, - onUpdateEnd: function (totalCount) { - hideLoading(dojo.query('#socialMenu ul li[data-layer=' + configOptions.twitterID + ']'), dojo.query('#TWLoad')); - var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.twitterID + '] .keyword')[0]; - if (node) { - node.innerHTML = configOptions.twitterSearch; - } - var textCount = ''; - if (totalCount) { - textCount = ' (' + totalCount + ')' || ''; - } - node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.twitterID + '] .count')[0]; - if (node) { - node.innerHTML = textCount; - } - }, - onSetTitle: getSmPopupTitle + popupHeight: configOptions.popupHeight }); clusterLayer.featureLayer.renderer.addValue({ value: configOptions.twitterID, @@ -887,8 +716,32 @@ function configureSocialMedia() { }), label: configOptions.twitterTitle }); - dojo.connect(twitterLayer, 'onUpdate', updateDataPoints); - dojo.connect(twitterLayer, 'onClear', updateDataPoints); + dojo.connect(twitterLayer, 'onUpdate', function () { + updateDataPoints(); + }); + dojo.connect(twitterLayer, 'onClear', function () { + updateDataPoints(); + var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.twitterID + '] .count')[0]; + if (node) { + node.innerHTML = ''; + } + }); + dojo.connect(twitterLayer, 'onUpdateEnd', function () { + var totalCount = twitterLayer.getStats().geoPoints; + hideLoading(dojo.query('#socialMenu ul li[data-layer=' + configOptions.twitterID + ']'), dojo.query('#TWLoad')); + var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.twitterID + '] .keyword')[0]; + if (node) { + node.innerHTML = configOptions.twitterSearch; + } + var textCount = ''; + if (totalCount) { + textCount = ' (' + totalCount + ')' || ''; + } + node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.twitterID + '] .count')[0]; + if (node) { + node.innerHTML = textCount; + } + }); // insert html insertSMItem({ visible: configOptions.twitterChecked, @@ -904,8 +757,6 @@ function configureSocialMedia() { if (configOptions.showYouTube) { youtubeLayer = new social.youtube({ map: map, - autopage: true, - maxpage: 4, title: configOptions.youtubeTitle, id: configOptions.youtubeID, key: configOptions.youtubeKey, @@ -915,30 +766,7 @@ function configureSocialMedia() { symbolWidth: configOptions.youtubeSymbol.width, popupWidth: configOptions.popupWidth, popupHeight: configOptions.popupHeight, - range: configOptions.youtubeRange, - distance: getSocialDistance("yt"), - onClear: function () { - var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.youtubeID + '] .count')[0]; - if (node) { - node.innerHTML = ''; - } - }, - onUpdateEnd: function (totalCount) { - hideLoading(dojo.query('#socialMenu ul li[data-layer=' + configOptions.youtubeID + ']'), dojo.query('#YTLoad')); - var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.youtubeID + '] .keyword')[0]; - if (node) { - node.innerHTML = configOptions.youtubeSearch; - } - var textCount = ''; - if (totalCount) { - textCount = ' (' + totalCount + ')' || ''; - } - node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.youtubeID + '] .count')[0]; - if (node) { - node.innerHTML = textCount; - } - }, - onSetTitle: getSmPopupTitle + range: configOptions.youtubeRange }); clusterLayer.featureLayer.renderer.addValue({ value: configOptions.youtubeID, @@ -950,8 +778,32 @@ function configureSocialMedia() { }), label: configOptions.youtubeTitle }); - dojo.connect(youtubeLayer, 'onUpdate', updateDataPoints); - dojo.connect(youtubeLayer, 'onClear', updateDataPoints); + dojo.connect(youtubeLayer, 'onUpdate', function () { + updateDataPoints(); + }); + dojo.connect(youtubeLayer, 'onClear', function () { + updateDataPoints(); + var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.youtubeID + '] .count')[0]; + if (node) { + node.innerHTML = ''; + } + }); + dojo.connect(youtubeLayer, 'onUpdateEnd', function () { + var totalCount = youtubeLayer.getStats().geoPoints; + hideLoading(dojo.query('#socialMenu ul li[data-layer=' + configOptions.youtubeID + ']'), dojo.query('#YTLoad')); + var node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.youtubeID + '] .keyword')[0]; + if (node) { + node.innerHTML = configOptions.youtubeSearch; + } + var textCount = ''; + if (totalCount) { + textCount = ' (' + totalCount + ')' || ''; + } + node = dojo.query('#socialMenu .layer[data-layer=' + configOptions.youtubeID + '] .count')[0]; + if (node) { + node.innerHTML = textCount; + } + }); // insert html insertSMItem({ visible: configOptions.youtubeChecked, diff --git a/SocialMedia/js/social/flickr.js b/SocialMedia/js/social/flickr.js index 34dc82e..8198b7b 100644 --- a/SocialMedia/js/social/flickr.js +++ b/SocialMedia/js/social/flickr.js @@ -8,35 +8,32 @@ dojo.addOnLoad(function () { }, constructor: function (options) { this.i18n = dojo.i18n.getLocalization("esriTemplate", "flickr"); - this._map = options.map || null; - if (this._map === null) { + var socialInstance = this; + this.options = { + autopage: true, + maxpage: 6, + limit: 100, + title: '', + id: 'flickr', + searchTerm: '', + symbolUrl: '', + symbolHeight: 22.5, + symbolWidth: 18.75, + popupHeight: 200, + popupWidth: 290, + dateFrom: '', + dateTo: '', + apikey: '' + }; + dojo.safeMixin(this.options, options); + if (this.options.map === null) { throw this.i18n.error.reference; } - var socialInstance = this; - this.autopage = options.autopage || true; - this.maxpage = options.maxpage || 2; - this.limit = 100; if (location.protocol === "https:") { this.baseurl = "http://api.flickr.com/services/rest/"; } else { this.baseurl = "https://secure.flickr.com/services/rest/"; } - this.title = options.title || ''; - this.id = options.id || 'flickr'; - this.searchTerm = options.searchTerm || ''; - this.symbolUrl = options.symbolUrl; - this.symbolHeight = options.symbolHeight || 22.5; - this.symbolWidth = options.symbolWidth || 18.75; - this.popupHeight = options.popupHeight || 200; - this.popupWidth = options.popupWidth || 290; - this.dateFrom = options.dateFrom || ''; - this.dateTo = options.dateTo || ''; - this.apiKey = options.apiKey || ''; - this.getWindowContentCallback = options.getWindowContentCallback || false; - this.onClearFunction = options.onClear || false; - this.onUpdateEndFunction = options.onUpdateEnd || false; - this.onSetTitleFunction = options.onSetTitle || false; - this.distance = options.distance; this.featureCollection = { layerDefinition: { "geometryType": "esriGeometryPoint", @@ -45,16 +42,21 @@ dojo.addOnLoad(function () { "type": "simple", "symbol": { "type": "esriPMS", - "url": this.symbolUrl, - "contentType": "image/" + this.symbolUrl.substring(this.symbolUrl.lastIndexOf(".") + 1), - "width": this.symbolWidth, - "height": this.symbolHeight + "url": this.options.symbolUrl, + "contentType": "image/" + this.options.symbolUrl.substring(this.options.symbolUrl.lastIndexOf(".") + 1), + "width": this.options.symbolWidth, + "height": this.options.symbolHeight } } }, "fields": [{ "name": "OBJECTID", "type": "esriFieldTypeOID" + }, { + "name": "smType", + "type": "esriFieldTypeString", + "alias": "smType", + "length": 100 }, { "name": "id", "type": "esriFieldTypeString", @@ -91,29 +93,25 @@ dojo.addOnLoad(function () { }; this.infoTemplate = new esri.InfoTemplate(); this.infoTemplate.setTitle(function (graphic) { - if (this.onSetTitleFunction && typeof this.onSetTitleFunction === 'function') { - return this.onSetTitleFunction(graphic); - } else { - return socialInstance.title; - } + return socialInstance.options.title; }); this.infoTemplate.setContent(function (graphic) { return socialInstance.getWindowContent(graphic, socialInstance); }); this.featureLayer = new esri.layers.FeatureLayer(this.featureCollection, { - id: this.id, + id: this.options.id, outFields: ["*"], infoTemplate: this.infoTemplate, visible: false }); - this._map.addLayer(this.featureLayer); + this.options.map.addLayer(this.featureLayer); dojo.connect(this.featureLayer, "onClick", dojo.hitch(this, function (evt) { var query = new esri.tasks.Query(); - query.geometry = this.pointToExtent(this._map, evt.mapPoint, this.symbolWidth); + query.geometry = this.pointToExtent(this.options.map, evt.mapPoint, this.options.symbolWidth); var deferred = this.featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW); - this._map.infoWindow.setFeatures([deferred]); - this._map.infoWindow.show(evt.mapPoint); - this._map.infoWindow.resize(this.popupWidth, this.popupHeight); + this.options.map.infoWindow.setFeatures([deferred]); + this.options.map.infoWindow.show(evt.mapPoint); + this.options.map.infoWindow.resize(this.options.popupWidth, this.options.popupHeight); })); this.stats = { geoPoints: 0, @@ -126,15 +124,8 @@ dojo.addOnLoad(function () { this.loaded = true; }, update: function (options) { - if (options) { - this.searchTerm = options.searchTerm || this.searchTerm; - this.distance = options.distance || this.distance; - this.socialSourceX = options.socialSourceX; - this.socialSourceY = options.socialSourceY; - this.dateFrom = options.dateFrom; - this.dateTo = options.dateTo; - } - this.constructQuery(this.searchTerm); + dojo.safeMixin(this.options, options); + this.constructQuery(this.options.searchTerm); }, pointToExtent: function (map, point, toleranceInPixel) { var pixelWidth = map.extent.getWidth() / map.width; @@ -151,8 +142,8 @@ dojo.addOnLoad(function () { this.deferreds.length = 0; } // remove existing Photos - if (this._map.infoWindow.isShowing) { - this._map.infoWindow.hide(); + if (this.options.map.infoWindow.isShowing) { + this.options.map.infoWindow.hide(); } if (this.featureLayer.graphics.length > 0) { this.featureLayer.applyEdits(null, null, this.featureLayer.graphics); @@ -210,22 +201,24 @@ dojo.addOnLoad(function () { return esri.graphicsExtent(this.featureLayer.graphics); }, getRadius: function () { - var extent = this.extent || this._map.extent; + var map = this.options.map; + var extent = this.options.map.extent; + var center = extent.getCenter(); + this.maxRadius = 600; + var radius = Math.min(this.maxRadius, Math.ceil(esri.geometry.getLength(new esri.geometry.Point(extent.xmin, extent.ymin, map.spatialReference), new esri.geometry.Point(extent.xmax, extent.ymin, map.spatialReference)) * 3.281 / 5280 / 2)); + var dist = (radius) / 2; + dist = dist * 10; + dist = (dist * 160.934).toFixed(3); + dist = parseFloat(dist); + var geoPoint = new esri.geometry.Point(center.x, center.y, map.spatialReference); + minPoint = esri.geometry.webMercatorToGeographic(new esri.geometry.Point(geoPoint.x - dist, geoPoint.y - dist, map.spatialReference)); + maxPoint = esri.geometry.webMercatorToGeographic(new esri.geometry.Point(geoPoint.x + dist, geoPoint.y + dist, map.spatialReference)); return { - radius: 0, - center: extent.getCenter(), - units: "bbox" + minPoint: minPoint, + maxPoint: maxPoint }; }, - setSearchExtent: function (extent) { - this.extent = extent; - }, getWindowContent: function (graphic, socialInstance) { - if (socialInstance.getWindowContentCallback) { - if (typeof socialInstance.getWindowContentCallback === 'function') { - socialInstance.getWindowContentCallback(graphic); - } - } var date = new Date(parseInt(graphic.attributes.dateupload * 1000, 10)); var html = ''; html += '
'; @@ -242,54 +235,34 @@ dojo.addOnLoad(function () { return html; }, constructQuery: function (searchValue) { - var map = this._map; - var extent = this.extent || map.extent; var search = dojo.trim(searchValue); - var apiKey = this.apiKey; if (search.length === 0) { search = ""; } - var dist = (this.distance) / 2; - dist = dist * 10; - dist = (dist * 160.934).toFixed(3); - dist = parseFloat(dist); - var geoPoint; - // adjust for incoming geoSocialPoints - if (this.socialSourceX && this.socialSourceY) { - geoPoint = esri.geometry.geographicToWebMercator(new esri.geometry.Point(this.socialSourceX, this.socialSourceY, map.spatialReference)); - minPoint = esri.geometry.webMercatorToGeographic(new esri.geometry.Point(geoPoint.x - dist, geoPoint.y - dist, map.spatialReference)); - maxPoint = esri.geometry.webMercatorToGeographic(new esri.geometry.Point(geoPoint.x + dist, geoPoint.y + dist, map.spatialReference)); - } else { - var center = extent.getCenter(); - geoPoint = new esri.geometry.Point(center.x, center.y, map.spatialReference); - minPoint = esri.geometry.webMercatorToGeographic(new esri.geometry.Point(geoPoint.x - dist, geoPoint.y - dist, map.spatialReference)); - maxPoint = esri.geometry.webMercatorToGeographic(new esri.geometry.Point(geoPoint.x + dist, geoPoint.y + dist, map.spatialReference)); - } - var startDate = this.dateFrom; - var endDate = this.dateTo; + var radius = this.getRadius(); this.query = { - bbox: minPoint.x + "," + minPoint.y + "," + maxPoint.x + "," + maxPoint.y, + bbox: radius.minPoint.x + "," + radius.minPoint.y + "," + radius.maxPoint.x + "," + radius.maxPoint.y, extras: "description, date_upload, owner_name, geo, url_s", - per_page: this.limit, + per_page: this.options.limit, sort: 'date-posted-desc', safe_search: 2, + content_type: 1, tags: search, method: "flickr.photos.search", - api_key: apiKey, + api_key: this.options.apiKey, has_geo: 1, page: 1, format: "json" }; - if (endDate && startDate) { - this.query.max_taken_date = Math.round(endDate / 1000); - this.query.min_taken_date = Math.round(startDate / 1000); + if (this.options.dateTo && this.options.dateFrom) { + this.query.max_taken_date = Math.round(this.options.dateTo / 1000); + this.query.min_taken_date = Math.round(this.options.dateFrom / 1000); } // make the actual Flickr API call this.pageCount = 1; this.sendRequest(this.baseurl + "?" + dojo.objectToQuery(this.query)); }, sendRequest: function (url) { - var flTitle = this.title; // get the results from Flickr for each page var deferred = esri.request({ url: url, @@ -302,7 +275,7 @@ dojo.addOnLoad(function () { if (data.photos.photo.length > 0) { this.mapResults(data); // display results for multiple pages - if ((this.autopage) && (this.maxpage > this.pageCount) && (data.photos.page < data.photos.pages) && (this.query)) { + if ((this.options.autopage) && (this.options.maxpage > this.pageCount) && (data.photos.page < data.photos.pages) && (this.query)) { this.pageCount++; this.query.page++; this.sendRequest(this.baseurl + "?" + dojo.objectToQuery(this.query)); @@ -315,7 +288,7 @@ dojo.addOnLoad(function () { } } else { if (data.code === 100) { - console.log(data.code + ' - ' + flTitle + ': ' + data.message); + console.log(data.code + ' - ' + this.options.title + ': ' + data.message); } // No results found, try another search term this.onUpdateEnd(); @@ -345,7 +318,6 @@ dojo.addOnLoad(function () { return 1; // found and removed }, mapResults: function (j) { - var id = this.id; var socialInstance = this; if (j.error) { console.log("mapResults error: " + j.error); @@ -355,7 +327,7 @@ dojo.addOnLoad(function () { var b = []; var k = j.photos.photo; dojo.forEach(k, dojo.hitch(this, function (result) { - result.smType = id; + result.smType = this.options.id; // eliminate geo photos which we already have on the map if (this.geocoded_ids[result.id]) { return; @@ -392,24 +364,13 @@ dojo.addOnLoad(function () { this.featureLayer.applyEdits(b, null, null); this.onUpdate(); }, - onClear: function () { - if (this.onClearFunction) { - if (typeof this.onClearFunction === 'function') { - this.onClearFunction(); - } - } - }, + onClear: function () {}, onError: function (info) { this.onUpdateEnd(); }, onUpdate: function () {}, onUpdateEnd: function () { this.query = null; - if (this.onUpdateEndFunction) { - if (typeof this.onUpdateEndFunction === 'function') { - this.onUpdateEndFunction(this.dataPoints.length); - } - } } }); // end of class declaration }); // end of addOnLoad \ No newline at end of file diff --git a/SocialMedia/js/social/twitter.js b/SocialMedia/js/social/twitter.js index 5c25192..bfdeb63 100644 --- a/SocialMedia/js/social/twitter.js +++ b/SocialMedia/js/social/twitter.js @@ -8,35 +8,29 @@ dojo.addOnLoad(function () { }, constructor: function (options) { this.i18n = dojo.i18n.getLocalization("esriTemplate", "twitter"); - this._map = options.map || null; - if (this._map === null) { - throw this.i18n.error.reference; - } dojo.io.script.get({ url: location.protocol + '//platform.twitter.com/widgets.js' }); var socialInstance = this; - this.autopage = options.autopage || true; - this.maxpage = options.maxpage || 3; - this.limit = 100; - if (location.protocol === "https:") { - this.baseurl = "https://search.twitter.com/search.json"; - } else { - this.baseurl = "http://search.twitter.com/search.json"; + this.options = { + autopage: true, + maxpage: 6, + limit: 100, + title: '', + id: 'twitter', + searchTerm: '', + symbolUrl: '', + symbolHeight: 22.5, + symbolWidth: 18.75, + popupHeight: 200, + popupWidth: 290, + result_type: 'recent' + }; + dojo.safeMixin(this.options, options); + if (this.options.map === null) { + throw this.i18n.error.reference; } - this.title = options.title || ''; - this.id = options.id || 'twitter'; - this.searchTerm = options.searchTerm || ''; - this.symbolUrl = options.symbolUrl; - this.symbolHeight = options.symbolHeight || 22.5; - this.symbolWidth = options.symbolWidth || 18.75; - this.popupHeight = options.popupHeight || 200; - this.popupWidth = options.popupWidth || 290; - this.getWindowContentCallback = options.getWindowContentCallback || false; - this.onClearFunction = options.onClear || false; - this.onUpdateEndFunction = options.onUpdateEnd || false; - this.onSetTitleFunction = options.onSetTitle || false; - this.distance = options.distance; + this.baseurl = location.protocol + "//search.twitter.com/search.json"; this.featureCollection = { layerDefinition: { "geometryType": "esriGeometryPoint", @@ -45,16 +39,21 @@ dojo.addOnLoad(function () { "type": "simple", "symbol": { "type": "esriPMS", - "url": this.symbolUrl, - "contentType": "image/" + this.symbolUrl.substring(this.symbolUrl.lastIndexOf(".") + 1), - "width": this.symbolWidth, - "height": this.symbolHeight + "url": this.options.symbolUrl, + "contentType": "image/" + this.options.symbolUrl.substring(this.options.symbolUrl.lastIndexOf(".") + 1), + "width": this.options.symbolWidth, + "height": this.options.symbolHeight } } }, "fields": [{ "name": "OBJECTID", "type": "esriFieldTypeOID" + }, { + "name": "smType", + "type": "esriFieldTypeString", + "alias": "smType", + "length": 100 }, { "name": "created_at", "type": "esriFieldTypeDate", @@ -100,29 +99,25 @@ dojo.addOnLoad(function () { }; this.infoTemplate = new esri.InfoTemplate(); this.infoTemplate.setTitle(function (graphic) { - if (this.onSetTitleFunction && typeof this.onSetTitleFunction === 'function') { - return this.onSetTitleFunction(graphic); - } else { - return socialInstance.title; - } + return socialInstance.config.title; }); this.infoTemplate.setContent(function (graphic) { return socialInstance.getWindowContent(graphic, socialInstance); }); this.featureLayer = new esri.layers.FeatureLayer(this.featureCollection, { - id: this.id, + id: this.options.id, outFields: ["*"], infoTemplate: this.infoTemplate, visible: false }); - this._map.addLayer(this.featureLayer); + this.options.map.addLayer(this.featureLayer); dojo.connect(this.featureLayer, "onClick", dojo.hitch(this, function (evt) { var query = new esri.tasks.Query(); - query.geometry = this.pointToExtent(this._map, evt.mapPoint, this.symbolWidth); + query.geometry = this.pointToExtent(this.options.map, evt.mapPoint, this.options.symbolWidth); var deferred = this.featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW); - this._map.infoWindow.setFeatures([deferred]); - this._map.infoWindow.show(evt.mapPoint); - this._map.infoWindow.resize(this.popupWidth, this.popupHeight); + this.options.map.infoWindow.setFeatures([deferred]); + this.options.map.infoWindow.show(evt.mapPoint); + this.options.map.infoWindow.resize(this.options.popupWidth, this.options.popupHeight); })); this.stats = { geoPoints: 0, @@ -135,13 +130,8 @@ dojo.addOnLoad(function () { this.loaded = true; }, update: function (options) { - if (options) { - this.searchTerm = options.searchTerm || this.searchTerm; - this.distance = options.distance || this.distance; - this.socialSourceX = options.socialSourceX; - this.socialSourceY = options.socialSourceY; - } - this.constructQuery(this.searchTerm); + dojo.safeMixin(this.options, options); + this.constructQuery(this.options.searchTerm); }, pointToExtent: function (map, point, toleranceInPixel) { var pixelWidth = map.extent.getWidth() / map.width; @@ -183,8 +173,8 @@ dojo.addOnLoad(function () { this.deferreds.length = 0; } // remove existing tweets - if (this._map.infoWindow.isShowing) { - this._map.infoWindow.hide(); + if (this.options.map.infoWindow.isShowing) { + this.options.map.infoWindow.hide(); } if (this.featureLayer.graphics.length > 0) { this.featureLayer.applyEdits(null, null, this.featureLayer.graphics); @@ -228,25 +218,19 @@ dojo.addOnLoad(function () { } }, getRadius: function () { - var map = this._map; - var extent = this.extent || map.extent; - var radius = Math.min(932, Math.ceil(esri.geometry.getLength(new esri.geometry.Point(extent.xmin, extent.ymin, map.spatialReference), new esri.geometry.Point(extent.xmax, extent.ymin, map.spatialReference)) * 3.281 / 5280 / 2)); + var map = this.options.map; + var extent = map.extent; + this.maxRadius = 932; + var radius = Math.min(this.maxRadius, Math.ceil(esri.geometry.getLength(new esri.geometry.Point(extent.xmin, extent.ymin, map.spatialReference), new esri.geometry.Point(extent.xmax, extent.ymin, map.spatialReference)) * 3.281 / 5280 / 2)); radius = Math.round(radius, 0); + var geoPoint = esri.geometry.webMercatorToGeographic(extent.getCenter()); return { radius: radius, - center: map.extent.getCenter(), + center: geoPoint, units: "mi" }; }, - setSearchExtent: function (extent) { - this.extent = extent; - }, getWindowContent: function (graphic, socialInstance) { - if (socialInstance.getWindowContentCallback) { - if (typeof socialInstance.getWindowContentCallback === 'function') { - socialInstance.getWindowContentCallback(graphic); - } - } var date = new Date(graphic.attributes.created_at); var linkedText = socialInstance.parseURL(graphic.attributes.text); linkedText = socialInstance.parseUsername(linkedText); @@ -285,40 +269,26 @@ dojo.addOnLoad(function () { return html; }, constructQuery: function (searchValue) { - var map = this._map; - var radius = this.distance || this.getRadius().radius; + var radius = this.getRadius(); var search = dojo.trim(searchValue); if (search.length === 0) { search = ""; } - var extent = this.extent || map.extent; - var center = extent.getCenter(); - center = esri.geometry.webMercatorToGeographic(center); - var geoPoint; - if (this.socialSourceX && this.socialSourceY) { - geoPoint = new esri.geometry.Point(this.socialSourceX, this.socialSourceY, map.spatialReference); - } else { - geoPoint = new esri.geometry.Point(center.x, center.y, map.spatialReference); - } - var locale = false; var localeTmp = dojo.locale.split('-'); if (localeTmp[0]) { locale = localeTmp[0]; } - this.query = { q: search, - rpp: this.limit, - result_type: "recent", - geocode: geoPoint.y + "," + geoPoint.x + "," + radius + "mi", + rpp: this.options.limit, + result_type: this.options.result_type, + geocode: radius.center.y + "," + radius.center.x + "," + radius.radius + radius.units, page: 1 }; if (locale) { this.query.locale = locale; - } - // start Twitter API call of several pages this.pageCount = 1; this.sendRequest(this.baseurl + "?" + dojo.objectToQuery(this.query)); @@ -335,9 +305,10 @@ dojo.addOnLoad(function () { if (data.results.length > 0) { this.mapResults(data); // display results for multiple pages - if ((this.autopage) && (this.maxpage > this.pageCount) && (data.next_page !== undefined) && (this.query)) { + if ((this.options.autopage) && (this.options.maxpage > this.pageCount) && (data.next_page !== undefined) && (this.query)) { this.pageCount++; this.query.page++; + this.query.max_id = data.max_id; this.sendRequest(this.baseurl + "?" + dojo.objectToQuery(this.query)); } else { this.onUpdateEnd(); @@ -371,7 +342,6 @@ dojo.addOnLoad(function () { return 1; // found and removed }, mapResults: function (j) { - var id = this.id; var socialInstance = this; if (j.error) { console.log(this.i18n.error.general + ": " + j.error); @@ -381,7 +351,7 @@ dojo.addOnLoad(function () { var b = []; var k = j.results; dojo.forEach(k, dojo.hitch(this, function (result) { - result.smType = id; + result.smType = this.options.id; // eliminate Tweets which we have on the map if (this.geocoded_ids[result.id]) { return; @@ -455,7 +425,6 @@ dojo.addOnLoad(function () { } else { this.stats.noGeo++; } - })); this.featureLayer.applyEdits(b, null, null); this.onUpdate(); @@ -463,19 +432,8 @@ dojo.addOnLoad(function () { onUpdate: function () {}, onUpdateEnd: function () { this.query = null; - if (this.onUpdateEndFunction) { - if (typeof this.onUpdateEndFunction === 'function') { - this.onUpdateEndFunction(this.dataPoints.length); - } - } - }, - onClear: function () { - if (this.onClearFunction) { - if (typeof this.onClearFunction === 'function') { - this.onClearFunction(); - } - } }, + onClear: function () {}, onError: function (info) { this.onUpdateEnd(); } diff --git a/SocialMedia/js/social/youtube.js b/SocialMedia/js/social/youtube.js index 82f829c..74f2269 100644 --- a/SocialMedia/js/social/youtube.js +++ b/SocialMedia/js/social/youtube.js @@ -8,34 +8,27 @@ dojo.addOnLoad(function () { }, constructor: function (options) { this.i18n = dojo.i18n.getLocalization("esriTemplate", "youtube"); - this._map = options.map || null; - if (this._map === null) { - throw this.i18n.error.reference; - } var socialInstance = this; - this.autopage = options.autopage || true; - this.maxpage = options.maxpage || 4; - this.limit = 50; - if (location.protocol === "https:") { - this.baseurl = "https://gdata.youtube.com/feeds/api/videos"; - } else { - this.baseurl = "http://gdata.youtube.com/feeds/api/videos"; + this.options = { + autopage: true, + maxpage: 6, + limit: 50, + title: '', + id: 'youtube', + searchTerm: '', + symbolUrl: '', + symbolHeight: 22.5, + symbolWidth: 18.75, + popupHeight: 200, + popupWidth: 290, + key: '', + range: 'all_time' + }; + dojo.safeMixin(this.options, options); + if (this.options.map === null) { + throw this.i18n.error.reference; } - this.title = options.title || ''; - this.id = options.id || 'youtube'; - this.searchTerm = options.searchTerm || ''; - this.key = options.key || false; - this.symbolUrl = options.symbolUrl; - this.symbolHeight = options.symbolHeight || 22.5; - this.symbolWidth = options.symbolWidth || 18.75; - this.popupHeight = options.popupHeight || 200; - this.popupWidth = options.popupWidth || 290; - this.range = options.range || 'all_time'; - this.getWindowContentCallback = options.getWindowContentCallback || false; - this.onClearFunction = options.onClear || false; - this.onUpdateEndFunction = options.onUpdateEnd || false; - this.onSetTitleFunction = options.onSetTitle || false; - this.distance = options.distance; + this.baseurl = location.protocol + "//gdata.youtube.com/feeds/api/videos"; this.featureCollection = { layerDefinition: { "geometryType": "esriGeometryPoint", @@ -44,16 +37,21 @@ dojo.addOnLoad(function () { "type": "simple", "symbol": { "type": "esriPMS", - "url": this.symbolUrl, - "contentType": "image/" + this.symbolUrl.substring(this.symbolUrl.lastIndexOf(".") + 1), - "width": this.symbolWidth, - "height": this.symbolHeight + "url": this.options.symbolUrl, + "contentType": "image/" + this.options.symbolUrl.substring(this.options.symbolUrl.lastIndexOf(".") + 1), + "width": this.options.symbolWidth, + "height": this.options.symbolHeight } } }, "fields": [{ "name": "OBJECTID", "type": "esriFieldTypeOID" + }, { + "name": "smType", + "type": "esriFieldTypeString", + "alias": "smType", + "length": 100 }, { "name": "published", "type": "esriFieldTypeDate", @@ -108,29 +106,25 @@ dojo.addOnLoad(function () { }; this.infoTemplate = new esri.InfoTemplate(); this.infoTemplate.setTitle(function (graphic) { - if (this.onSetTitleFunction && typeof this.onSetTitleFunction === 'function') { - return this.onSetTitleFunction(graphic); - } else { - return socialInstance.title; - } + return socialInstance.options.title; }); this.infoTemplate.setContent(function (graphic) { return socialInstance.getWindowContent(graphic, socialInstance); }); this.featureLayer = new esri.layers.FeatureLayer(this.featureCollection, { - id: this.id, + id: this.options.id, outFields: ["*"], infoTemplate: this.infoTemplate, visible: false }); - this._map.addLayer(this.featureLayer); + this.options.map.addLayer(this.featureLayer); dojo.connect(this.featureLayer, "onClick", dojo.hitch(this, function (evt) { var query = new esri.tasks.Query(); - query.geometry = this.pointToExtent(this._map, evt.mapPoint, this.symbolWidth); + query.geometry = this.pointToExtent(this.options.map, evt.mapPoint, this.symbolWidth); var deferred = this.featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW); - this._map.infoWindow.setFeatures([deferred]); - this._map.infoWindow.show(evt.mapPoint); - this._map.infoWindow.resize(this.popupWidth, this.popupHeight); + this.options.map.infoWindow.setFeatures([deferred]); + this.options.map.infoWindow.show(evt.mapPoint); + this.options.map.infoWindow.resize(this.options.popupWidth, this.options.popupHeight); })); this.stats = { geoPoints: 0, @@ -143,14 +137,8 @@ dojo.addOnLoad(function () { this.loaded = true; }, update: function (options) { - if (options) { - this.searchTerm = options.searchTerm || this.searchTerm; - this.distance = options.distance || this.distance; - this.socialSourceX = options.socialSourceX; - this.socialSourceY = options.socialSourceY; - this.range = options.range || this.range; - } - this.constructQuery(this.searchTerm); + dojo.safeMixin(this.options, options); + this.constructQuery(this.options.searchTerm); }, pointToExtent: function (map, point, toleranceInPixel) { var pixelWidth = map.extent.getWidth() / map.width; @@ -191,8 +179,8 @@ dojo.addOnLoad(function () { this.deferreds.length = 0; } // remove existing videos - if (this._map.infoWindow.isShowing) { - this._map.infoWindow.hide(); + if (this.options.map.infoWindow.isShowing) { + this.options.map.infoWindow.hide(); } if (this.featureLayer.graphics.length > 0) { this.featureLayer.applyEdits(null, null, this.featureLayer.graphics); @@ -225,24 +213,19 @@ dojo.addOnLoad(function () { return esri.graphicsExtent(this.featureLayer.graphics); }, getRadius: function () { - var map = this._map; - var extent = this.extent || map.extent; - var radius = Math.min(621, Math.ceil(esri.geometry.getLength(new esri.geometry.Point(extent.xmin, extent.ymin, map.spatialReference), new esri.geometry.Point(extent.xmax, extent.ymin, map.spatialReference)) * 3.281 / 5280 / 2)); + var map = this.options.map; + var extent = map.extent; + this.maxRadius = 621; + var radius = Math.min(this.maxRadius, Math.ceil(esri.geometry.getLength(new esri.geometry.Point(extent.xmin, extent.ymin, map.spatialReference), new esri.geometry.Point(extent.xmax, extent.ymin, map.spatialReference)) * 3.281 / 5280 / 2)); + radius = Math.round(radius, 0); + var geoPoint = esri.geometry.webMercatorToGeographic(map.extent.getCenter()); return { radius: radius, - center: extent.getCenter(), + center: geoPoint, units: "mi" }; }, - setSearchExtent: function (extent) { - this.extent = extent; - }, getWindowContent: function (graphic, socialInstance) { - if (socialInstance.getWindowContentCallback) { - if (typeof socialInstance.getWindowContentCallback === 'function') { - socialInstance.getWindowContentCallback(graphic); - } - } var mdy = graphic.attributes.published.$t.substring(0, 10); var time = graphic.attributes.published.$t.substring(11, 19); var date = dojo.date.locale.parse(mdy + '-' + time, { @@ -268,36 +251,24 @@ dojo.addOnLoad(function () { return html; }, constructQuery: function (searchValue) { - // specify search radius - has to be smaller than 1500 kilometers (932 miles) - // by default, use a radius equal to half the width of the bottom border of the map - var map = this._map; - var radius = this.distance || this.getRadius().radius; + var radius = this.getRadius(); var search = dojo.trim(searchValue); if (search.length === 0) { search = ""; } - var range = this.range; - var extent = this.extent || map.extent; - var center = extent.getCenter(); - center = esri.geometry.webMercatorToGeographic(center); - var geoPoint; - if (this.socialSourceX && this.socialSourceY) { - geoPoint = this.socialSourceY + "," + this.socialSourceX; - } else { - geoPoint = center.y + "," + center.x; - } + var range = this.options.range; this.query = { "q": search, - "max-results": this.limit, + "max-results": this.options.limit, "v": 2, - "location": geoPoint, - "location-radius": radius + "mi", + "location": radius.center.y + "," + radius.center.x, + "location-radius": radius.radius + radius.units, "time": range, "start-index": 1, "alt": "json" }; - if (this.key) { - this.query.key = this.key; + if (this.options.key) { + this.query.key = this.options.key; } // make the actual YouTube API call this.pageCount = 1; @@ -316,9 +287,9 @@ dojo.addOnLoad(function () { if (data.feed.entry.length > 0) { this.mapResults(data); // display results from multiple pages - if ((this.autopage) && (this.maxpage > this.pageCount) && (data.feed.entry.length >= this.limit) && (this.query)) { + if ((this.options.autopage) && (this.options.maxpage > this.pageCount) && (data.feed.entry.length >= this.options.limit) && (this.query)) { this.pageCount++; - this.query["start-index"] += this.limit; + this.query["start-index"] += this.options.limit; this.sendRequest(this.baseurl + "?" + dojo.objectToQuery(this.query)); } else { this.onUpdateEnd(); @@ -355,7 +326,6 @@ dojo.addOnLoad(function () { return 1; // found and removed }, mapResults: function (j) { - var id = this.id; var socialInstance = this; if (j.error) { console.log(this.i18n.error.general + ": " + j.error); @@ -365,7 +335,7 @@ dojo.addOnLoad(function () { var b = []; var k = j.feed.entry; dojo.forEach(k, dojo.hitch(this, function (result) { - result.smType = id; + result.smType = this.options.id; // eliminate video ids which we already have on the map if (this.geocoded_ids[result.id.$t]) { return; @@ -406,21 +376,10 @@ dojo.addOnLoad(function () { this.featureLayer.applyEdits(b, null, null); this.onUpdate(); }, - onClear: function () { - if (this.onClearFunction) { - if (typeof this.onClearFunction === 'function') { - this.onClearFunction(); - } - } - }, + onClear: function () {}, onUpdate: function () {}, onUpdateEnd: function () { this.query = null; - if (this.onUpdateEndFunction) { - if (typeof this.onUpdateEndFunction === 'function') { - this.onUpdateEndFunction(this.dataPoints.length); - } - } }, onError: function (info) { this.onUpdateEnd(); diff --git a/SocialMedia/readme.html b/SocialMedia/readme.html index 73e0ddb..2369397 100644 --- a/SocialMedia/readme.html +++ b/SocialMedia/readme.html @@ -84,7 +84,6 @@

Configure the application

  • appid: The ID of the application which will set these configuration options.
  • webmap: The webmap ID is the unique combination of letters and numbers found on the end of the URL of your ArcGIS Online web map. To obtain the webmap ID, sign in to ArcGIS.com, navigate to your web map resource, open the web map in the ArcGIS Online viewer, and copy the last portion of the URL. If the URL appears like http://www.arcgis.com/home/webmap/viewer.html?webmap=d5e02a0c1f2b4ec399823fdd3c 2fdebd, your webmap ID is d5e02a0c1f2b4ec399823fdd3c2fdebd.
  • -
  • socialDistance: The social media search radius. The distance that the social media search will span. Valid options are: 'local', 'regional' or 'national'.
  • socialDisplay: Option to display as heatmap or cluster by default. Valid options are: 'cluster' or 'heatmap'.
  • showFlickr: Show Flickr on the social media layers menu.
  • showFlickrConfig: Allow configuration of Flickr and it's search terms.
  • @@ -113,7 +112,6 @@

    Configure the application

  • sharingurl: Portal sharing URL.
  • portalUrl: URL for portal.
  • bingMapsKey: An alpha-numeric key is required to display base maps by Bing Maps. When the value is a valid key, Bing Maps’ base map options are automatically added to the Basemap menu. If needed, generate a key by creating a developer account at http://www.bingmapsportal.com/ and selecting "Create or view keys".
  • -
  • crosshairImage: Cursor image used when plotting a social media location.
  • defaultMenu: Menu to be shown on page load. Valid options are: 'places', 'basemap', 'layers', 'social', 'legend' or 'none'.
  • showSearchBox: To add or remove the ‘Find a place’ search box to let users search for a place, set the value to true or false. If true, you must also provide a value for locatorURL.
  • @@ -128,7 +126,6 @@

    Configure the application

  • showGeolocation: To add or remove the option to find the current location of the user, set the value to true or false. When true, a link to My Current Location is displayed.
  • showAboutDialog: Show about button in user interface.
  • showAboutDialogOnLoad: Show about dialog on map load.
  • -
  • socialPoint: Search social media from this location instead of center of map extent. Format as x,y eg: 1234.12,-1234.12.
  • locateName: Use this title in info window on locate point.
  • locatePoint: Show this point on map load. Format as x,y eg: 1234.12,-1234.12.
  • sourceCountry: Country code to use for search geolocator service. View the list of country codes.
  • diff --git a/resources/configJSON.js b/resources/configJSON.js index 1840304..01e2173 100644 --- a/resources/configJSON.js +++ b/resources/configJSON.js @@ -118,26 +118,6 @@ "type":"paragraph", "value":"Opens the about dialog on page load." }, - { - "type":"string", - "fieldName":"socialDistance", - "tooltip":"Social Distance", - "label":"Social Distance:", - "options":[ - { - "label":"Local", - "value":"local" - }, - { - "label":"Regional", - "value":"regional" - }, - { - "label":"National", - "value":"national" - } - ] - }, { "type":"paragraph", "value":"Distance to search for social media." @@ -366,7 +346,6 @@ "showGeolocation":true, "showAboutDialog":true, "showAboutDialogOnLoad":false, - "socialDistance":"regional", "socialDisplay":"cluster", "showFlickr":true, "showFlickrConfig":true,