nokia here maps geocoding and display map - geocoding

please, could someone explain me how can I manage, in Here Maps code, nokia.maps.map.Display listener and nokia.places.search.manager.geocode method?
I have markers to be geocoded, in geocode "oncomplete" it waits for the request to be completed, after that it listens when map display is ready, so as it happens asynchronously, it sometimes displays on browser a map not finished yet, this is because map.zoomTo(bbox, false) was not executed.
How can I manage these two events?
<script type="text/javascript">
function goPageOnLoad() {
container = new nokia.maps.map.Container();
map = new nokia.maps.map.Display(document.getElementById('gmapcanvas'),
{ components:[ infoBubbles, new nokia.maps.map.component.Behavior(), new
nokia.maps.map.component.ZoomBar(), new
nokia.maps.map.component.Overview(), new
nokia.maps.map.component.TypeSelector(), new
nokia.maps.map.component.ScaleBar() ] });
addMarkersGeoLoc(map,container);
}
function addMarkersGeoLoc(map,container) {
countMarkerGeoLoc=1; coordinate = new
nokia.maps.geo.Coordinate(0, 0); startGeoCode('Via Roma 2, 16038 Santa
Margherita Ligure GE ');
}
function startGeoCode(addressStringt) {
nokia.places.search.manager.geoCode({
searchTerm : addressString,
onComplete: function(data, requestStatus){
if(data != null){
coordinate =
new nokia.maps.geo.Coordinate(data.location.position.latitude,
data.location.position.longitude);
var marker = new
nokia.maps.map.StandardMarker(coordinate, {brush: {color: "#FF0000"}});
marker.addListener( CLICK, function (evt) {
infoBubbles.openBubble(content, marker.coordinate); } );
container.objects.add(marker);
managersFinished++;
}
else {
managersFinished++; alert('Address: '+addressString+', is not
localizable.');
}
if(managersFinished === countMarkerGeoLoc) {
map.objects.add(container);
map.set('zoomLevel', 14);
map.addListener("displayready", function () {
map.set('center',
[40.645304, 14.874063]);
bbox = container.getBoundingBox();
if(bbox !=null){
map.zoomTo(bbox, false);
}
});
}
}
});
}
</script>

The simplest method would be to wait for the displayready event before starting your geocoding.
function goPageOnLoad() {
container = new nokia.maps.map.Container();
map = new nokia.maps.map.Display
.. etc...
map.addListener('displayready', function () {
addMarkersGeoLoc(map,container);
}, false);
The other alternative would be to have a global bbox variable and use zoomTo() twice - either on displayready or on managersFinished === countMarkerGeoLoc i.e.
var bbox;
...
function goPageOnLoad() {
container = new nokia.maps.map.Container();
map = new nokia.maps.map.Display
.. etc...
map.addListener("displayready", function () {
if(bbox){map.zoomTo(bbox, false);}
});
...
if(managersFinished === countMarkerGeoLoc) {
map.objects.add(container);
bbox = container.getBoundingBox();
map.zoomTo(bbox, false);
Either the first or the second of the zoomTo() functions must fire to move the map.

Related

How tp send big Data set from loopback.js remote method

I am reading oracle ref Cursor and storing in p_ref out param and using the streams from resultset.toquerystream() method I am reading the data and pushing the data in array variable and once reached end of the stream I am sending the data.
its working fine for small data set of 1000 records but failing with error ERR_EMPTY_RESPONSE as you can see I am storing the data in array and returning the data once we reach end
but its failing with "ERR_EMPTY_RESPONSE"
oracledb.getConnection(
ds.settings,
function (err, connection) {
if (err) {
cb(err.message, []);
return;
}
let count = 0;
let params = {
p_ref: {type: oracledb.CURSOR, dir: oracledb.BIND_OUT}
};
let cursor = null;
let queryStream = null;
let data = [];
connection.execute(
sql,
params,
{outFormat: oracledb.OBJECT},
function (err, result) {
if (err) {
cb(err.message, []);
doRelease(connection);
return;
}
cursor = result.outBinds.p_ref;
queryStream = cursor.toQueryStream();
queryStream.on('data', function (row) {
count++;
data.push(row);
});
queryStream.on('error', function (err) {
if (!cbCalled) {
cbCalled = true;
cb(err.message);
doRelease(connection);
}
});
queryStream.on('end', function () {
console.log('Rows selected: ' + count);
cb('', data);
doRelease(connection);
});
queryStream.on('close', function () {
if (!cbCalled) {
console.log(count);
doRelease(connection);
}
});
}
);
}
);
Reference from here https://github.com/oracle/node-oracledb/blob/master/doc/api.md
var stream = connection.queryStream('SELECT employees_name FROM employees');
stream.on('error', function (error) { // handle any error... });
stream.on('data', function (data) { // handle data row... });
stream.on('end', function () { // release connection... });
stream.on('metadata', function (metadata) { // access metadata of query });
Try removing the call to doRelease() from the 'end' event.

Ember: Setting a component object value within a promise

I have component with a couple of properties, using a promise in the willRender hook to try and create a (pagination) object:
export default Ember.Component.extend({
pagination:null,
testing:null, // to check if this.set is ok within the promise!
willRender() {
let page = {};
let model = this.get('data');
model.get('products').then(relatedItems => {
let maxRecords = relatedItems.get('length');
relatedItems.forEach(function(item,index) {
if (item.get('slug') === itemModel.get('id')) {
if (index === 0) {
page.Prev = null;
page.Next = relatedItems.objectAt(index+1).get('slug');
}
else if (index+1 === maxRecords) {
page.Prev = relatedItems.objectAt(index-1).get('slug');
page.Next = null;
}
else {
page.Prev = relatedItems.objectAt(index-1).get('slug');
page.Next = relatedItems.objectAt(index+1).get('slug');
}
}
});
this.set('testing','hello world');
console.log(this.get('testing')); // hello world
this.set('pagination',page);
console.log(this.get('pagination')); // Object {Prev: "product-1", Next: "product-2"}
},reject => {
console.log('error '+reject);
});
}
})
In my template
{{testing}} // prints hello world
However, if I try and access {{pagination}} eg {{log pagination}}, the browser crashes with a loop printing out the object to the console.
I don't know where I'm going wrong here - any help much appreciated!
It's likely you are triggering the template to rerender causing willRender to fire over and over which causes an infinite loop in your code.
willRender is a non-standard place to do this code, init would be more standard since it only fires on initialization of the component. Even better would be to use
myInit: Ember.on('init', function(){
....
})`
instead of overriding willRender on the object.
try to check whether Object is present at specific position. i think its going undefined during iteration of for loop. try to ensure that ObjectAt is not returning undefined or null value during running of for loop.
relatedItems.forEach(function(item,index) {
if (item.get('slug') === itemModel.get('id')) {
if (index === 0) {
page.Prev = null;
if(relatedItems.objectAt(index+1) ! = undefined) {
page.Next = relatedItems.objectAt(index+1).get('slug');
}else{
page.Next == null;
}
}
else if (index+1 === maxRecords) {
if(relatedItems.objectAt(index-1) ! = undefined) {
page.Prev = relatedItems.objectAt(index-1).get('slug');
}else{
page.Prev = null;
}
page.Next = null;
}
else {
if(relatedItems.objectAt(index-1) ! = undefined) {
page.Prev = relatedItems.objectAt(index-1).get('slug');
}else{
page.Prev = null;
}
if(relatedItems.objectAt(index+1) ! = undefined) {
page.Next = relatedItems.objectAt(index+1).get('slug');
}else{
page.Next = null;
}
}
}
Please ensure that Object at is returning object.
There seems to be a few problems here, would be interested to know what your console errors are.
You don't seem to have defined itemModel so don't know how you're referencing that.
Also you can't access this from within a .then. You need to do something like this to set a component variable.
var _this = this;
promise().then(function(results) {
_this.set('testing', 'hello world');
});
you are not using , after testing:null
there should be , after testing property like that
pagination:null,
testing:null, // i use ',' after testing: null property
try to use your pagination code under init hook rather than willrender hook
init() {
//you code
},

how to differentiate user typed their own value or selected a suggestion from typeahead

I am using typeahead.js.
var getname = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('CompanyName'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: '/Profile/Getname?searchText=%QUERY',
});
getname.initialize();
var $emp = $('#employment');
$emp.typeahead(null, {
name: 'CompanyNames',
displayKey: 'CompanyName',
source: getname.ttAdapter(),
});
$emp.on("typeahead:selected", function (obj, user) {
$("#UserId").val(user.UserID);
}
is there a way to know when the user selects an option from the list or typed their own value?
I made it that way
var voivodeshipSelected = false;
$('input[name=voivodeshipSelect].typeahead').on('typeahead:select', function (ev, suggestion) {
$(this).validationEngine('hide');
voivodeshipSelected = true;
});
$('input[name=voivodeshipSelect].typeahead').on('typeahead:change', function (ev, data) {
if (!voivodeshipSelected) {
$(this).validationEngine('showPrompt', 'choose voivodeship', 'error', 'topRight', true);
}
else {
voivodeshipSelected = false;
}
});
I just add global variable which is set on select so than on change which is binded when select, check it, and showing prompt or not.

How to properly setup a store that acts as a single pointer across your web app

I have a home grown store that has a simple identityMap. When I return an array of models from this and bind it to a controllers "model" it reflects what you'd expect
the first time you hit a route it reflects this in the template as
you'd expect
But later if I get this same store instance (it's a singleton) and push an object into the identityMap it doesn't automatically update the previous template
The store itself is super basic (no relationships/ just push objects and get by id)
function buildRecord(type, data, store) {
var containerKey = 'model:' + type;
var factory = store.container.lookupFactory(containerKey);
var record = factory.create(data);
var id = data.id;
identityMapForType(type, store)[id] = record;
return record;
}
function identityMapForType(type, store) {
var typeIdentityMap = store.get('identityMap');
var idIdentityMap = typeIdentityMap[type] || {};
typeIdentityMap[type] = idIdentityMap;
return idIdentityMap;
}
var Store = Ember.Object.extend({
init: function() {
this.set('identityMap', {});
},
push: function(type, data) {
var record = this.getById(type, data.id);
if (record) {
record.setProperties(data);
} else {
record = buildRecord(type, data, this);
}
return record;
},
getById: function(type, id) {
var identityMap = identityMapForType(type, this);
return identityMap[id] || null;
}
getEverything: function(type) {
var identityMap = identityMapForType(type, this);
var keys = Object.keys(identityMap);
var values = [];
for (var i = 0; i < keys.length; i++)
{
var val = identityMap[keys[i]];
values.push(val);
}
return values;
}
});
Ember.onLoad('Ember.Application', function(Application) {
Application.initializer({
name: "store",
initialize: function(container, application) {
application.register('store:main', Store);
application.inject('controller', 'store', 'store:main');
application.inject('route', 'store', 'store:main');
}
});
});
In my model hook (in the find all route lets say) I simply query for each item and push them into the store
//inside my model find method lets say ...
find: function(store) {
var url = "/api/foo";
$.getJSON(url, function(response) {
response.forEach(function(data) {
var model = store.push("foo", data);
}
}
return store.getEverything("foo");
}
So I assumed my controllers' model was this bound array (using a single pointer in memory for this array of models)
Yet when I do this inside a controller submit action it won't re-render that prev view (to show the new item that was added to that store's array)
actions: {
submit: function() {
var foo = {}; // assume this is a real json response or js object
var store = this.get("store");
store.push("foo", foo);
}
}
Because of this today, I'm forced to get the parent controller and "set" / "push" this new object to it's content/model property :(
Anyone know what I'm doing wrong here?
I like homegrown solutions, they generally are easier to work with and meld around what you're working on.
So I'm actually surprised this part is working:
//inside my model find method lets say ...
find: function(store) {
var url = "/api/foo";
$.getJSON(url, function(response) {
response.forEach(function(data) {
var model = store.push("foo", data);
}
}
return store.getEverything("foo");
}
If I read through it I see you make an ajax call, and then return store.getEverything immediately after (without a guarantee that the ajax call has completed). Then inside of getEverything you create a new array called values then iterate the identity map linking up all of the currently available records and return that. At this point your store is unaware of this array going forward. So any changes to your store wouldn't get pushed out to the array, they might make it into the identity map, but it isn't feeding the getEverything array.
There are a couple of solutions, one would be to keep track of your everything array. That collection would be super cheap to build, more expensive to search, so keeping the identity map as well would be super beneficial. You could follow your same pattern, but one collection would be the map, whereas the other would be an array of everything.
Modified Build Record
function buildRecord(type, data, store) {
var containerKey = 'model:' + type;
var factory = store.container.lookupFactory(containerKey);
var record = factory.create(data);
var id = data.id;
identityMapForType(type, store)[id] = record;
everythingArrayForType(type, this).pushObject(record);
return record;
}
Copy paste, possibly could be refactored
function everythingArrayForType(type, store) {
var everythingArrays = store.get('everythingArrays');
var arr = everythingArrays[type] || [];
everythingArrays[type] = arr;
return arr;
}
Slightly modified Store
var Store = Ember.Object.extend({
init: function() {
this.set('identityMap', {});
this.set('everythingArrays', {});
},
push: function(type, data) {
var record = this.getById(type, data.id);
if (record) {
record.setProperties(data);
} else {
record = buildRecord(type, data, this);
}
return record;
},
getById: function(type, id) {
var identityMap = identityMapForType(type, this);
return identityMap[id] || null;
}
getEverything: function(type) {
return everythingArrayForType(type, this);
}
});

if control does not work using check box

I cannot manage to handle the 'check-box handler', a problem, that I have traced back to happen obviously within the if-control function.
If you try the following modified code, you see, that the Boolean-variable "e.parameter.myCheckBox" yields the correct result, the if-branching-off based on this variable, however, does not work. Does anyone see the mistake here?
Thank you very much
Martin
function ifTest(e) {
var app = UiApp.createApplication().setTitle('ifTest');
var panel = app.createVerticalPanel();
var grid = app.createGrid(3, 3);
var myCheckBox = app.createCheckBox().setName('myCheckBox').setId('myCheckBox');
var button = app.createButton('submit').setId("submit").setWidth("280").setHeight("35");
grid.setWidget(1, 0, app.createLabel('Check for True').setStyleAttribute("font-size", "110%"));
grid.setWidget(1, 1, myCheckBox);
grid.setWidget(2, 1, button);
var handler = app.createServerHandler('ifCheck');
var handler = app.createServerClickHandler('ifCheck');
handler.addCallbackElement(myCheckBox);
myCheckBox.setValue(false, false);
handler.addCallbackElement(grid);
button.addClickHandler(handler);
panel.add(grid);
app.add(panel);
ss.show(app);
return app;
}
function ifCheck(e) {
var bCBresult = e.parameter.myCheckBox;
var app = UiApp.getActiveApplication();
Browser.msgBox(bCBresult);
if (bCBresult) {
Browser.msgBox("bCBresult = true");
}
else {
Browser.msgBox("bCBresult = false");
};
return app.close();
}
the value returned by e.parameter.myCheckBox is a string, not a boolean. (that's actually the case for all e.parameter values..., they are always strings)
So your condition would be if (bCBresult=='true') {