Zoom to point cluster on click in arcgis api javascript - arcgis-js-api

I have tried this.
map.add(pointLayer);
pointLayer.on("click", function (event) {
pointLayer.event.graphic
map.centerAndZoom(event.graphic.geometry, 4);
});
but it is not executed. I am trying to create a function on click event.

It seems the problem is that you are treating event.graphic.geometry as a Point, which is what map.centerAndZoom is expecting, but if you print it out you will realize it is not:
{
"x": -9177389.169799313,
"y": 4247317.642662031,
"spatialReference": {
"wkid": 102100
}
}
So, you would have to create a point like this:
map.addLayer(pointLayer);
pointLayer.on("click", function (event) {
map.centerAndZoom(new Point(event.graphic.geometry),18);
});
Here you can see a live demo using ArcGIS API for JavaScript 3.x.
If you have the chance, I highly recommend you to start using 4.x as soon as possible. Just in case anyone needs it, here is the same demo using ArcGIS API for JavaScript 4.x (and ESM modules).

Related

dojo JsonRest call not working

I'm trying to call my RESTful service from dojo. All I can see from debugger is, it tries to call the service but it doen't reach there. There are no errors. I can see the 'hello' alert.
define(["dojo/store/JsonRest","dojo/domReady!"],
function(JsonRest){
alert("Hello");
var rest = new JsonRest({
target: "/my/rest/call"
});
}
);
I's following this page from dojotoolkit.
But if i call using a declare then it works.
define(["dojo/store/JsonRest","dojo/_base/declare","dojo/domReady!"],
function(JsonRest, declare){
var rest = declare(JsonRest);
var restResult = new rest({
target: "/my/rest/call"
});
}
);
What am I doing wrong here?
error messages in console:
You're not following that tutorial to the letter. The difference is that you're using define and not require. Dojo's define is used in combination with declare to create new Dojo classes. Dojo's require is used to load and use existing classes. The link below is a recommended read and in your case pay special attention to the 'Requiring modules' and 'Defining modules' parts:
https://dojotoolkit.org/documentation/tutorials/1.8/modules/
If you use require like in that tutorial, it works perfectly:
require([
'dojo/store/JsonRest',
], function(
JsonRest
) {
new JsonRest({
target: 'some/resource/'
}).get(1).then(function (item) {
alert(JSON.stringify(item));
});
});
Here's a working example on Plunker: http://plnkr.co/edit/ZhsO67BFpWB5Txqy0Zl9?p=preview

How to get all artists of a user (Spotify Api 1.x)?

I'm trying to get a list of Artists for a user. It was very easy in the 0.x Api, but now i can't do it.
require([
'$api/models',
'$api/location#Location',
'$api/library#Library',
'$api/search#Search',
'$api/toplists#Toplist',
'$views/buttons',
'$views/list#List',
'$views/image#Image'
], function(models, Location, Library, Search, Toplist, buttons, List, Image) {
var librarys = Library.forCurrentUser();
console.log("LIBRARY", librarys);
librarys.load("artists").done(
function(artists) {
console.log(artists);
artists.load('owner').done(function(snapshot) {
console.log("SNAP",snapshot);
});
});
});
I get a response of "Library.forCurrentUser();" but everything i try next fails. There is no error or something, but either "librarys.load("artists")" nor "librarys.snapshot()" works.
By loading "artists" from the library, you're actually not getting artists back in the callback function, but a library that has loaded the artists. Since you almost never need to have everything loaded, it's better for performance if you specify what you want to have loaded. If you wanted to load tracks as well as artists, simply use "artists", "tracks" as load parameter.
If you want to see the Artists in the current user's library, you can do like so:
require(['$api/library#Library'], function(Library) {
Library.forCurrentUser().load("artists").done(function(library) {
library.artists.snapshot().done(function(snapshot) {
for (var i = 0; i < snapshot.length; i++) {
console.log(snapshot.get(i).name);
}
});
});
});
Hope this helps.
Edit: This is working for the Spotify Apps API version 1.25.1.

How to use dojox/mobile/ScrollablePane Events

ScrollablePane in dojo mobile have some event that we can use as they have mentioned in their API documentation. I try to use the as follows.
leftPane.on("onTouchEnd", function(e){
alert("sss");
});
(leftPane is a ScrollablePane) This does not work. But this works when I use a event like "click". I search throughout the net for a example but didn't find a one. Can someone help me out here.
Thank you.
use:
aspect.after(leftPane, 'onTouchEnd', function(e) { });
dojo/on is tricky when it comes to the event naming - you could start by ditching the "on" prefix. Most likely, simply changing onTouchEnd to touchend would work
The Dojo event system changed significantly between 1.6 and 1.7. The new on function and the Evented mixin is the recommended way of handling events in widgets, but there are some backward-compatibility functions in the _WidgetBase class.
In short, you can either use the legacy dojo.connect function, the new aspect function (which implementes the "connect to normal javascript method" functionality of the old dojo.connect), or use the new on method in the _WidgetBase class that is a bridge between the two.
1. dojo.connect(leftPane, 'onTouchEnd', function(e) { });
2. aspect.after(leftPane, 'onTouchEnd', function(e) { }, true); // <-- the 'true' is important!
3. leftPane.on('touchend', function(e) { });
YMMV on (3) depending on whether the widget was updated to provide this bridging.

Where are working dojox.storage AMD examples?

I can't seem to find dojox.storage documented somewhere recently. Is dojox.storage broken in 1.7 (AMD)? It appears the unit-tests aren't even working. The example at /dojo-release-1.7.2-src/dojox/storage/tests/test_storage.html doesn't seem to work at all on FF or IE.
What is the recommended approach to using a local storage? In our case we'd like to use HTML5 storage that falls back on cookie storage when not available.
Below example from http://dojotoolkit.org/reference-guide/1.8/dojox/storage.html It's working on Dojo 1.7 and above.
dojo.require("dojox.storage");
var storageProvider=null;
dojo.addOnLoad(function(){
dojox.storage.manager.initialize();
storageProvider=dojox.storage.manager.getProvider();
storageProvider.initialize();
var myObject={key1:true};
storageProvider.put("myValue", myObject, function(status, keyName){
alert("value put in "+keyName);
});
});
According to http://dojotoolkit.org/reference-guide/1.8/dojox/storage.html and http://bugs.dojotoolkit.org/ticket/14465, dojox.storage isn't expected to work with AMD and won't be for a while.
That said, this did work for me in dojo 1.8.3:
require(["dojox/storage", "dojo/ready"], function (storage, ready) {
ready(function() {
var storageProvider = dojox.storage.manager.getProvider();
storageProvider.initialize();
var vals = storageProvider.get("InventoryMainSelectionHistory");
var i = 1;
});
});
As for DoJo 1.9.2, dojox.storage test (/dojox/storage/tests/test_storage.html) wasn't working. After nearer inspection it happened to be initialization issue in that particular code:
// wait until the storage system is finished loading
dojo.addOnLoad(function(){
// is the storage already loaded?
if(dojox.storage.manager.isInitialized() == false){
dojo.connect(dojox.storage.manager, "loaded", TestStorage, TestStorage.initialize);
}else{
dojo.connect(dojo, "loaded", TestStorage, TestStorage.initialize);
}
});
The listener has registered waiting for event "loaded" on dojo, that wasn't called in newer DoJo version. After changing the code:
dojo.addOnLoad(function(){
TestStorage.initialize();
});
the example functions (for LocalStorageProvider) in both FireFox and IE 10.

InAppPurchases not working on PhoneGap App

I'm having some problems trying to get running inAppPurchases inside my iPhone phoneGap-based app.
I got the inAppPurchase-plugin on gitHub https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/InAppPurchaseManager
Then i created my developer account, purchased de u$d 99, and made my inAppPurchase Catalog
Created my iTunes Connect account to get a Test User for this.
I placed all the plugins file where it says... And, if i try to run "alert(typeof window.plugins.inAppPurchaseManager)" it shows "object" so, plugins are being loaded correctly!
The problem appears when i try to do my purchase..
I logout my itunes account, run my binary inside my iphone, and when i make the purchase i should see a prompt asking me for my test account information in order to make a symbolic purchase! But it never happens!
The javascript code (very basic) im trying to run is the following
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady(event) {
window.plugins.inAppPurchaseManager.onPurchased = function(transactionIdentifier, productId, transactionReceipt) {
alert("purchased");
};
window.plugins.inAppPurchaseManager.onRestored = function(originalTransactionIdentifier, productId, originalTransactionReceipt) {
alert("restored");
};
window.plugins.inAppPurchaseManager.onFailed = function(errorCode, errorText) {
alert("error");
};
window.plugins.inAppPurchaseManager.requestProductData(
"com.mycompany.myproduct.myproductid",
function(productId, title, description, price) {
alert("data retrieved");
window.plugins.inAppPurchaseManager.makePurchase(productId, 1);
},
function(id) {
alert("Invalid product id: " + id);
}
);
}
Hope you can help me! thank you!
You need to call js functions like window.plugins.inAppPurchaseManager.onPurchased in html.index for these functions to work.i.e these functions call onPurchased in js and correspondingly it will call obj-C functions.
(js function in index.html)->(js function in js file)->(objective-C function)...is the sequence.
Are you getting any invalid product ID's back? There are a lot of gotchas on Apple's end. Try reading through this guide to find what you need to get the product info request to return valid products.