I am new to ArcGIS. I am using an API to bookmark locations on a map. When a specific location is clicked (eg. Galway bay), the map will then zoom in to that location.
<script>
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.form.DropDownButton");
dojo.require("esri.map");
dojo.require("esri.dijit.Bookmarks");
dojo.require("esri/dijit/HomeButton");
dojo.require("dojo/domReady!");
var map, bookmarks, home;
function init() {
map = new esri.Map("map", {
basemap: "oceans",
center: [-7.5, 53],
zoom: 6
});
The list of location, which a user can select is generated using JavaScript like the example below. You use spatial reference to locate a point on a map and then give it a name.
// Bookmarks can be specified as an array of objects with the structure:
// { extent: <esri.geometry.Extent>, name: <some string> }
var bookmarks_list = [{
"extent": {
"spatialReference": {
"wkid": 102100
},
"xmin": -1882000,
"ymin": 6638000,
"xmax": -316000,
"ymax": 7583000
},
"name": "Full View....."
}, {
"extent": {
"spatialReference": {
"wkid": 102100
},
"xmin": -1020761,
"ymin": 7009798,
"xmax": -996800,
"ymax": 7048100
},
"name": "Galway Bay"
}, {
"extent": {
"spatialReference": {
"wkid": 102100
},
"xmin": -939400,
"ymin": 6756000,
"xmax": -890400,
"ymax": 6785500
},
"name": "Cork Harbour"
}, {
"extent": {
"spatialReference": {
"wkid": 102100
},
"xmin": -1123000,
"ymin": 6839100,
"xmax": -1074100,
"ymax": 6868600
},
"name": "Tralee Bay"
} ];
// Create the bookmark widget
bookmarks = new esri.dijit.Bookmarks({
map: map,
bookmarks: bookmarks_list
}, dojo.byId('bookmarks'));
//show map on load
dojo.ready(init);
home.startup();
</script>
My question is, how do I get the JavaScript "name" value e.g. Galway Bay and pass it to a c# function ? How do you related c# and JavaScript? I am new to this so I would appreciated any advice thanks
As you've mentioned C# and JavaScript my guess is you're hosting your application in a .Net environment. However, the JavaScript API runs client side only so I'm not sure what you want to use C# to actually do? If it is that you want the server side to do something in response to something happening on the client, then you'd probably want to call a web server running on your server and supply it any client side properties. I use the .Net Web API for this.
You probably want to read up a bit more on:
the ESRI JavaScript API (https://developers.arcgis.com/javascript/),
the dojo request module for calling a webservice (http://dojotoolkit.org/documentation/tutorials/1.10/ajax/)
the ASP.Net Web API (http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api).
One other thing: I note you are using older Dojo syntax (pre v1.7) which is an easy mistake to make given that ESRI and even Dojo themselves haven't updated all their tutorials to the 1.7+ syntax. But if you are starting a new project I would make sense to use the new syntax from the start. The dojo site has another tutorial about the differences (same link as above, just go up a level).
Create an event handler for a mouse click on a bookmark. In the event handler, send an Ajax request to your C# based default.apx page or Url passing in the bookmark name as a querystring.
Here is an example. I couldn't get the bookmark event click to pass any data, so I used Jquery. I also added a 1 second delay to ensure the bookmarks finished loading.
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
setTimeout(function () {
$("#bookmarks .esriBookmarkLabel").click(function () {
$.get("default.aspx?bookmarkName=" + $(this).html(), function (data) {
$(".result").html(data);
});
});
},1000);
</script>
Related
I have created a bot with MS Bot SDK. Then, I want to get the page URL where I'm hosting the bot. I just inject the script to a page to host the bot. But, does anyone who knows how to get the current page URL from C#?
I can see someone is trying to use Activity for getting the URL, but I can't find the right property from Activity.
I just inject the script to a page to host the bot. But, does anyone who knows how to get the current page URL from C#?
If you embed webchat in your web site and you want to get the URL of the web page where you embed the webchat, you can try the following approach to get the URL and pass it to your bot.
Pass the URL to bot:
<script>
var urlref = window.location.href;
BotChat.App({
directLine: { secret: "{directline_secret}" },
user: { id: 'You', pageurl: urlref},
bot: { id: '{bot_id}' },
resize: 'detect'
}, document.getElementById("bot"));
</script>
Retrieve the URL in bot application:
if (activity.From.Properties["pageurl"] != null)
{
var urlref= activity.From.Properties["pageurl"].ToString();
}
ChannelData was designed to enable sending custom information from client to bot, and back. Similar to Fei Han's answer, you can intercept outgoing messages and provide custom ChannelData for every activity sent.
<script>
var dl = new BotChat.DirectLine({
secret: 'yourdlsecret',
webSocket: false,
pollingInterval: 1000,
});
var urlref = window.location.href;
BotChat.App({
botConnection: {
...dl,
postActivity: activity => dl.postActivity({
...activity,
channelData: { pageurl: urlref }
})
},
user: { id: 'userid' },
bot: { id: 'botid' },
resize: 'detect'
}, document.getElementById("bot"));
</script>
Then, in the bot:
I use Graph API Explorer User Data Permissions and check "user_friends" ,
use FQL Query to fill in "/me/friends", I can get it below:
{
"data": [
{
"name": "xxx",
"id": "750725034949941"
}
],
"paging": {
"next": "https://graph.facebook.com/v2.2/1569963793218579/friends?limit=25&offset=25& __after_id=enc_AexiIZhvUUA7W93CyCbEKqop8pgwMeZe0FVYg2fNQIrAxRs7nDvv1nuUG_aoKR8JOxUf29FXPlsfg9xVsGgDDToj"
},
"summary": {
"total_count": 1
}
}
But I use Unity app to call FB.Login("user_friends,email,public_actions",callback);
then call FB.API("/me/friends")
I only get the result below:
{"data":[],"summary":{"total_count":1}}
How to modify C# code to get friendList detail?
That´s a new feature of v2.0: You only get the friends who authorized your App too. If no other friend authorized your App, data will be empty. Also, FQL is deprecated.
I have been trying to pull in information from my web API into my application.
Currently i am just trying to pull in data not submit it yet. The API is working and running as a service on my system.
It is returning data in json format an example of the data returned by the WEB API.
[
{
"$id": "1",
"id": "6c32e378-0f06-45da-9dda-0515c813cd5d",
"application_name": "FDB INTERFACE",
"description": "Interface for FDB decision support",
"active": true,
"tbl_update_header": []
},
{
"$id": "2",
"id": "58f68624-3803-43ff-b866-0a507ea85459",
"application_name": "HPM",
"description": "Helix Health Practice Manager",
"active": true,
"tbl_update_header": []
},
This is my page just to try and get the some data to display
<html>
<head>
<title></title>
<script src="~/Scripts/jquery-2.1.1.js"></script>
<script type="text/javascript">
$.ajax({
type: "GET",
url: "http://localhost:9981/API/Application",
processData: true,
data: {},
dataType: "json",
error: function (jqXHR, textStatus, errorThrown) {
// debug here
alert(jqXHR);
},
//error: function(error, data){
// console.log(error)
//},
success: function (data) {
//Clear the div displaying the results
$("productView").empty();
//Create a table and append the table body
var $table = $('<table border="2">');
var $tbody = $table.append('<tbody />').children('tbody');
//data - return value from the web api method
for (var i = 0; i < data.lenght; i++) {
//adda new row to the table
var $trow = $tbody.append('<tr />').children('tr:last');
//add a new column to display name
var $tcol = $trow.append('<td/>').children('td:last').append(data[i].id);
//add a new column to display description
var $tcol = $trow.append('<td/>').children('td:last').append(data[i].description);
}
//display the table in the div
$table.appendTo('#productView');
}
});
</script>
</head>
<body>
<div id="productView"></div>
</body>
</html>
The page loaded but is empty and no error is returned from any section.
I run the web page from chrome/FF/IE none of them show error in dev mode and VS shows no errors. I am not sure if i am parsing the data wrong or calling to the wrong part of the json to display the data.
I must be doing something silly at this point but just cant get pass this part.
you can also set this property in your js file before ajax call
$.support.cors = true;
There is a typo in your success method...
success: function (data) {
//Clear the div displaying the results
$("productView").empty();
//Create a table and append the table body
var $table = $('<table border="2">');
var $tbody = $table.append('tbody /').children('tbody');
//data - return value from the web api method
for (var i = 0; i < data.length; i++){
//adda new row to the table
var $trow=$tbody.append('<tr />').children('tr:last');
//add a new column to display name
var $tcol = $trow.append('<td/>').children('td:last').append(data[i].application_name);
//add a new column to display description
var $tcol = $trow.append('<td/>').children('td:last').append(data[i].description);
//add a new column to display active
var $tcol = $trow.append('<td/>').children('td:last').append(data[i].active);
}
//display the table in the div
$table.appendTo('#productView');
It should be data.length and not data.lenght.
Success. The issue was with CORS. also with the spelling mistake of data.length
The code works fine and the results are what i was wanting to get . Thank you all for your assist.
To fix the issue i had to enable CORS in iis server side to allow cross domain access.
Your code above has a success function, but not an error function.
Try setting an error function, and then see what happens :
data: {},
dataType: "json",
error: function(jqXHR, textStatus, errorThrown ) {
// debug here
alert(jqXHR);
},
success: function() ...
I've got problem because I don't know how to read extjs data from my filtr
var search = new Ext.FormPanel({
renderTo: 'search',
frame: true,
items: [searchForm],
button: [{
text:'Search',
handler: function(){
store.ClearFilter();
var productValue = Ext.getCmp('filtrName').getValue();
var filters = [{
fn: function(item){
return (new RegExp(productValue).test(item. get('Name')));
}
}];
store.filter(filters);
}
}]
)}
Filter working fine but I need to connect it with server side but don't know how.
For example to take value from start limit etc to pagin side variable names are similar but here I don't have any clue how to get it
Please help
One option is to save the filter in the data store, which you can easily access from controller.
For example, inside the button handler,
store.filters = [{
fn: function (item) {
return (new RegExp(productValue).test(item.get('Name')));
}
}];
store.filter(store.filters);
And store.filters will be the one you can access from the controller. Hope it helps
I am attempting to get the Comments Feed from a video entry using the YouTube API for .NET. I am working on a program in WPF and C#, but can't seem for the life of me to figure out how to retrieve this feed.
I tried looking at the YouTube API Developer's Guide, but it seems to be missing some information about Comment Feeds (near the bottom of the page).
This has changed in version 3 of the YouTube API. There is a new endpoint called commentThreads/list which allows you to return a thread of comments for a resource.
If you want to return a list of comments on a video resource, set up a GET request with part=id,snippet and videoId=[VIDEO_ID]. I'll be using https://www.youtube.com/watch?v=HwNIDcwfRLY as an example:
HTTP GET https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&videoId=HwNIDcwfRLY&key={YOUR_API_KEY}
Let's use the first comment returned as an example:
{
"kind": "youtube#commentThread",
"etag": "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/jhK_kJqnNF8_fiRI_o7w6ehubv8\"",
"id": "z120sfshyxzewt1nx23sevyr1vu1jd2pr04",
"snippet": {
"videoId": "HwNIDcwfRLY",
"topLevelComment": {
"kind": "youtube#comment",
"etag": "\"DsOZ7qVJA4mxdTxZeNzis6uE6ck/h903NemnXx-8Hfe6lRIYCFERSe4\"",
"id": "z120sfshyxzewt1nx23sevyr1vu1jd2pr04",
"snippet": {
"authorDisplayName": "mach-a-chine seahawksgoonie",
"authorProfileImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50",
"authorChannelUrl": "http://www.youtube.com/channel/UCBmJ0sw7plIZHLvhfz7oo_w",
"authorChannelId": {
"value": "UCBmJ0sw7plIZHLvhfz7oo_w"
},
"videoId": "HwNIDcwfRLY",
"textDisplay": "",
"authorGoogleplusProfileUrl": "https://plus.google.com/102274783439566633837",
"canRate": true,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2016-02-05T03:42:35.158Z",
"updatedAt": "2016-02-05T03:42:35.158Z"
}
},
"canReply": true,
"totalReplyCount": 0,
"isPublic": true
}
}
Note that the comment isn't actually in this topLevelComment object. textDisplay returns the empty string, which is a known issue with the YouTube API. We need to make an additional request to commentThreads/list with id=[COMMENT_ID], where [COMMENT_ID] is topLevelComment.id:
HTTP GET https://www.googleapis.com/youtube/v3/commentThreads?part=id%2Csnippet&id=z120sfshyxzewt1nx23sevyr1vu1jd2pr04&key={YOUR_API_KEY}
The resulting response's snippet dictionary will have the user's comment as the value for the textDisplay key:
"snippet": {
"authorDisplayName": "mach-a-chine seahawksgoonie",
"authorProfileImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=50",
"authorChannelUrl": "http://www.youtube.com/channel/UCBmJ0sw7plIZHLvhfz7oo_w",
"authorChannelId": {
"value": "UCBmJ0sw7plIZHLvhfz7oo_w"
},
"videoId": "HwNIDcwfRLY",
"textDisplay": "my next ring tone! yeah boy!\ufeff",
"authorGoogleplusProfileUrl": "https://plus.google.com/102274783439566633837",
"canRate": true,
"viewerRating": "none",
"likeCount": 0,
"publishedAt": "2016-02-05T03:42:35.158Z",
"updatedAt": "2016-02-05T03:42:35.158Z"
}
}
The comment is: "my next ring tone! yeah boy!"
Note that you can also pass in a list of up to 50 comma-separated id or videoId strings of comment objects to retrieve per API call.
See the Retrieve comments for a video guide for additional information and sample code.
YouTubeRequest request = ... // Your request object
Video v = ... // Your video object
Feed<Comment> comments = request.GetComments(v);
comments.entries will contain all the comments for the video v as Comment objects, so you don't need to mess with the feed at all.