Saving and getting information from Titanium MapView Annotation - titanium

I have the following code that creates a new annotation on my .js:
//Create annotation
var new_annotation = Titanium.Map.createAnnotation({
latitude:10,
longitude:30,
title:"Title",
pincolor:Titanium.Map.ANNOTATION_RED,
customdata:"My custom data",
animate:true,
rightButton: Titanium.UI.iPhone.SystemButton.DISCLOSURE,
myid:1
});
$.mapview.addAnnotation(new_annotation);
All information like title, latitude and longitude is available on my click function:
function doClick(evt){
alert("title: " + evt.title);
alert("customdata: " + evt.customdata);
};
However customdata is "undefined".
How can save and retrieve data from a Titanium MapView Annotation? Why the data is "undefined"?

You are adding your customdata object to the annotation itself, the evt object that is passed into the click event listener is defined in the DOCS as passing the title of the annotation explicitly, so of course you can retrive it, but to get the customdata you have to do this:
function doClick(evt){
alert("title: " + evt.title);
// Get the annotation, then get the custom data attached to it
alert("customdata: " + evt.annotation.customdata);
};

Related

Change the way the number of elements are shown on selecting a Point if multiple items exist at that point

Currently in ArcGIS Online if multiple items exist in a single point the template is shown like this
Will I be able to view the details with the number of elements as a part of the template like this
You can retrieve the number of selected features using Popup.featureCount.
The following CodePen uses this property to provide a dynamic PopupTemplate.title: https://codepen.io/arnofiva/pen/5b532f8577d097107cf8040da57e0b97
var template = layer.popupTemplate;
var defaultTitle = template.title;
// Compute popup title before it is shown
template.title = function() {
var total = view.popup.featureCount;
if (total > 1) {
return defaultTitle + " - Count: " + total + "";
} else {
return defaultTitle;
}
}
See the following ArcGIS API for JavaScript resources for more information on popups and widgets:
Popup Widget
PopupTemplate - use functions to set content
Popup with DOM node
Widget development - ViewModel pattern

react native arrow functions and geoQueries

I am still struggling a little bit with arrow functions. I have previously made these posts:
react native and globally accessible objects
react native arrow functions and if statements
But now I am having a new issue with how these can be used with geoQuery. I have tried the code shown below:
myFunction = () => {
var onKeyMovedRegistration = () => geoQuery.on("key_moved", function(key, location, distance) {
console.log('Test log');
if (key != this.props.userID) {
arraySearchResult = findKeyInArray(key, this.props.arrayOfKeys);
if (arraySearchResult != "keyNotFound") {
console.log(key + " moved within query to " + location + " (" + distance + " km from center)");
}
}
})
}
So myFunction is bound, and I am trying to bind the geoQuery as well, as otherwise this.props.userID and this.props.arrayOfKeys are not accessible if I use the original line:
var onKeyMovedRegistration = geoQuery.on("key_moved", function(key, location, distance) {
With the attempt above, nothing fires. I do not get "Test log" to the console. There is no crash or error, it's just clearly not how this is supposed to be done.
Anyone know how I can get past this one?
Since your geoFire listener function is not bound therefore you can't access class level props to it.
Therefore the simplest way would be to use the arrow function here as
geoQuery.on("key_moved", (key, location, distance) =>
After this, this will be bound to the class and you will be able to access the class level props.

Titanium - Label on Map Pin

I need to code for label on the map as product price in Titanium SDK.
Anybody have any idea how to achieve this ?
Waiting for your kind response.
What i get from your question is that when you click on a map marker ( product in your case ) , you what to show price of that item as an info window ( for that marker ).
If this is the case then set title of your annotation as the product price.
Something like ( example taken from titanium docs) :
var Map = require('ti.map'); //extend map global object
var win = Titanium.UI.createWindow();
var mountainView = Map.createAnnotation({
latitude:37.390749,
longitude:-122.081651,
title:"Appcelerator Headquarters", //<--------- YOUR PRODUCT PRICE HERE
subtitle:'Mountain View, CA',
pincolor:Map.ANNOTATION_RED,
myid:1 // Custom property to uniquely identify this annotation.
});
var mapview = Map.createView({
mapType: Map.NORMAL_TYPE,
region: {latitude:33.74511, longitude:-84.38993,
latitudeDelta:0.01, longitudeDelta:0.01},
animate:true,
regionFit:true,
userLocation:true,
annotations:[mountainView]
});
win.add(mapview);
// Handle click events on any annotations on this map.
mapview.addEventListener('click', function(evt) {
Ti.API.info("Annotation " + evt.title + " clicked, id: " + evt.annotation.myid);
});
win.open();

Determine Rules triggered by endeca

We have various endeca rules set up through Rules Manager in our application which are triggered while rendering the page.
Is it possible to determine which rule was triggered for a page through Java/JSP code?
The proper way to do this is with the Content Assembler API (endeca_content.jar). You need to create a content query and retrive the content object:
ContentItem content = results.getContent();
content.getName();
It is also possible to use the navigation API, using the SupplementList object from the navigation object: The title key will represent the name of the rule triggered. However, is you are using page builder in any meaningful way the proper approach is to use the Content Assemble API.
SupplementList sl = nav.getSupplements();
for (Object object : sl) {
Supplement s = (Supplement) object;
PropertyMap map = s.getProperties();
Set keys = map.keySet();
for (Object key : keys) {
logger.info("Sup prop: " + key + " \t" + map.get(key));
}
}

Which events are attached to an element?

How can I receive all events attached to an element with dojo?
dojo.query('#mydiv') // which events does #mydiv has?
To get all events on a DOM element:
// Get my div
myDiv = dojo.byId("myDiv");
// Obtain all event-related attributes
var events = dojo.filter(
myDiv.attributes,
function(item) {
return item.name.substr(0, 2) == 'on';
}
);
// Execute first found event, just for fun
eval(events[0].value);
If you get myDiv using dojo.query, remember that dojo.query returns an array, so your element would be in myDiv[0].
This solution does not work with events attached with dojo.connect. There probably is a way to extract this info from Dojo inner workings, but you would have to delve into the source code to understand how.
Another option is that you explicitly manage all dojo.connect events with a global registry. You could use dojox.collections to make this easier. For example, creating a global registry whose keys will be the dom nodes, and values will be the handles returned by dojo.connect (these handles contain the dom node, the type of event and the function to execute):
// On startup
dojo.require(dojox.collections.Dictionary);
eventRegistry = new dojox.collections.Dictionary();
...
// Registering an event for dom node with id=myDiv
var handle1 = dojo.connect(dojo.byId("myDiv"), "onclick", null, "clickHandler");
// Check if event container (e.g. an array) for this dom node is already created
var domNode = handle1[0];
if (!eventRegistry.containsKey(domNode))
eventRegistry.add(domNode, new Array());
eventRegistry.item(domNode).push(handle1);
...
// Add another event later to myDiv, assume container (array) is already created
var handle2 = dojo.connect(dojo.byId("myDiv"), "onmouseover", null, "mouseHandler");
eventRegistry.item(domNode).push(handle2);
...
// Later get all events attached to myDiv, and print event names
allEvents = eventRegistry.item(domNode);
dojo.forEach(
allEvents,
function(item) {
console.log(item[1]);
// Item is the handler returned by dojo.connect, item[1] is the name of the event!
}
);
You can hide the annoying check to see if event container is already created by creating a subclass of dojox.collections.Dictionary with this check already incorporated. Create a js file with this path fakenmc/EventRegistry.js, and put it beside dojo, dojox, etc:
dojo.provide('fakenmc.EventRegistry');
dojo.require('dojox.collections.Dictionary');
dojo.declare('fakenmc.EventRegistry', dojox.collections.Dictionary, {
addEventToNode : function(djConnHandle) {
domNode = djConnHandle[0];
if (!this.containsKey(domNode))
this.add(domNode, new Array());
this.item(domNode).push(djConnHandle);
}
});
Using the above class you would have to dojo.require('fakenmc.EventRegistry') instead of 'dojox.collections.Dictionary', and would simply directly add the dojo connect handle without other checks:
dojo.provide('fakenmc.EventRegistry');
eventRegistry = new fakenmc.EventRegistry();
var handle = dojo.connect(dojo.byId("myDiv"), "onclick", null, "clickHandler");
eventRegistry.addEventToNode(handle);
...
// Get all events attached to node
var allEvents = eventRegistry.item(dojo.byId("myDiv"));
...
This code is not tested, but I think you get the idea.
If its only for debugging purpose. You can try dijit.byId("myId").onClick.toString(); in your firebug console and you can see the entire onclick code this works even if the function is anonymous you can view the content of anonymous content.