Last active
October 17, 2016 22:13
-
-
Save green3g/48121b3e204e6d022c685b8c0a61ada0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
'dijit/form/Button', | |
'dojo/dom', | |
'dojo/i18n!./nls/main' | |
], function(Button, dom, i18n) { | |
var updateFeature = function(data) { | |
// get the feature layer | |
var layer = data._layer; | |
// update the attribute (increment it once) | |
data.attributes.SumRating++; | |
// update the data | |
layer.applyEdits(null, [data]); | |
dom.byId('rating').innerHTML = data.attributes.SumRating; | |
}; | |
return { | |
map: true, | |
mapClickMode: true, | |
mapRightClickMenu: true, | |
identifyLayerInfos: true, | |
identifyTolerance: 5, | |
draggable: false, | |
// config object definition: | |
// {<layer id>:{ | |
// <sub layer number>:{ | |
// <pop-up definition, see link below> | |
// } | |
// }, | |
// <layer id>:{ | |
// <sub layer number>:{ | |
// <pop-up definition, see link below> | |
// } | |
// } | |
// } | |
// for details on pop-up definition see: https://developers.arcgis.com/javascript/jshelp/intro_popuptemplate.html | |
identifies: { | |
pointsOfInterest: { | |
0: { | |
content: function(data) { | |
//give it time for the identify popup to show | |
setTimeout(function() { | |
//see if we already liked this feature | |
if(localStorage.getItem('like' + data.attributes.OBJECTID)){ | |
return; | |
} | |
var button = new Button({ | |
id: 'likeButton' + data.attributes.OBJECTID, | |
onClick: function() { | |
updateFeature(data); | |
// remember that we liked this feature | |
localStorage.setItem('like' + data.attributes.OBJECTID, true); | |
button.set('disabled', true); | |
}, | |
label: '<i class="fa fa-thumbs-up"></i> Like!' | |
}, 'likeButton'); | |
}, 500); | |
//return some html for the identify popup | |
return '<div id="rating">' + | |
data.attributes.SumRating + | |
'</div> likes so far <div id="likeButton"></div>'; | |
} | |
} | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment