My project is geographic maps application.
This is my protocol:
var myprotocol = new OpenLayers.Protocol.HTTP({
url: url,
format: new OpenLayers.Format.GeoJSON({
extractStyles: true,
extractAttributes: true
})
});
This is my layer function:
var layer = new OpenLayers.Layer.Vector("layerName", {
projection: epsg4326,
strategies: strategies,
protocol: myprotocol,
displayInLayerSwitcher: true
});
layer.events.register('loadend', layer, function (evt) {
console.log("onloadend was called");
});
layer.events.register('loadstart', layer, function (evt) {
console.log("onloadstart was called");
}
This is my other function:
myprotocol.read({
// maxFeatures: 100,
callback: function (resp) {
console.log("read _CallBack was called");
console.log(resp);
}
});
myprotocol.handleResponse = function (resp, opt) {
console.log("handleResponse was called");
};
These are my attributes:
var data = new Object();
data.iconUrl = katman.iconUrl;
data.fillColor = katman.fillColor;
data.fillOpacity = katman.fillOpacity;
data.graphicHeight = katman.graphicHeight;
data.graphicOpacity = katman.graphicOpacity;
data.graphicWidth = katman.graphicWidth;
data.graphicXOffset = katman.graphicXOffset;
data.graphicYOffset = katman.graphicYOffset;
data.pointRadius = katman.pointRadius;
data.pointerEvents = katman.pointerEvents;
data.rotation = katman.rotation;
data.strokeColor = katman.strokeColor;
data.strokeDashstyle = katman.strokeDashstyle;
data.strokeLinecap = katman.strokeLinecap;
data.strokeOpacity = katman.strokeOpacity;
data.strokeWidth = katman.strokeWidth;
data.layerId = feature.data.layerId;
data.shapeId = feature.data.shapeId;
I want to add this attributes for each feature that I received featurecollection object from web service.
I've solved this problem with the following code.thank you for help me..
myprotocol.handleResponse = function (resp, opt) {
console.log("handleResponse was called");
var features = geojson.read(resp.priv.responseText);
for (var i in features) {
var feature = features[i];
feature.attributes.iconUrl = katman.iconUrl;
feature.attributes.fillColor = katman.fillColor;
feature.attributes.fillOpacity = katman.fillOpacity;
feature.attributes.graphicHeight = katman.graphicHeight;
feature.attributes.graphicOpacity = katman.graphicOpacity;
feature.attributes.graphicWidth = katman.graphicWidth;
feature.attributes.graphicXOffset = katman.graphicXOffset;
feature.attributes.graphicYOffset = katman.graphicYOffset;
feature.attributes.pointRadius = katman.pointRadius;
feature.attributes.pointerEvents = katman.pointerEvents;
feature.attributes.rotation = katman.rotation;
feature.attributes.strokeColor = katman.strokeColor;
feature.attributes.strokeDashstyle = katman.strokeDashstyle;
feature.attributes.strokeLinecap = katman.strokeLinecap;
feature.attributes.strokeOpacity = katman.strokeOpacity;
feature.attributes.strokeWidth = katman.strokeWidth;
}
layer.addFeatures(features);
};
Related
Here is my code I want to return getConn.result and use it in my js page. Could you help me?
function readObjectStore(storeName) {
// Open (or create) the database
var open = indexedDB.open("Publisher", 1);
open.onupgradeneeded = function () {}
open.onsuccess = function () {
var db = open.result;
var tx = db.transaction(storeName, "readwrite");
var store = tx.objectStore(storeName);
if (storeName == "connectionStrings") {
var getConn = store.getAll();
getConn.onsuccess = function () {
return getConn.result;
}
}
}
}
How can i Execute the Client.prototype.disconnect on another page of javascript code?
Maybe i just have to inherit it?
If yes, then how do i inherit it?
Thanks.
function(Komanda, _, Helpers, Channels, Channel, ChannelView, ChannelsView, Message, Notice, NamesView, Popup, moment, uuid) {
var Client = function(session) {
var self = this;
self.irc = window.requireNode("irc");
self.options = session.attributes;
self.options.stripColors = false;
self.nick = session.attributes.nick;
self.socket = null;
self.session = session;
self.retryCount = 300;
self.retryCountCurrent = 0;
self.retryFunction = null;
self.attemptingReconnect = false;
self.allowReconnect = true;
self.topics = {};
self.binded = false;
self.channels = new Channels();
self.channel = new Channel();
self.channelsView = new ChannelsView({
collection: self.channels,
model: self.channel
});
self.views = [];
$(".channel-item[data-name=\"Status\"]").removeClass("selected");
$(".channel").hide();
var c = new Channel({
channel: "Status",
topic: false,
names: {},
name: "Server Status",
server: self.options.uuid,
status: true,
pm: false
});
self.channels.add(c);
var view = new ChannelView({
model: c
});
Komanda.current = {
server: self.options.uuid,
channel: "Status"
};
$(".channel-holder").append(view.render().el);
var selector = $("#sidebar div.session[data-id=\"" + self.options.uuid + "\"]");
if (selector.find(".channel-list").length > 0) {
selector.find(".channel-list").replaceWith(self.channelsView.render().el);
} else {
selector.append(self.channelsView.render().el);
}
self._whois = {};
return this;
};
Client.prototype.disconnect = function(callback) {
var self = this;
self.attemptingReconnect = false;
self.socket.disconnect("quit message", function() {
self.session.set("connectionOpen", false);
self.clearViews();
self.socket.conn.end();
if (_.isFunction(callback)) {
callback(self);
}
});
};
Alright, here's what the plan is. Go through each file, add the file into the array. Once all files are added, then combine them using the JSZipUtility and Docxtemplater:
'click .merge-icon': (e) => {
var programId = Router.current().url.split('/').pop();
var programObj = Programs.findOne(programId);
var insertedDocuments = [];
var i = 0;
var count = programObj.activityIds.count;
var fileDownloadPromise = new Promise((resolve, reject) => {
programObj.activityIds.forEach(function(activityId) {
var activityObj = Activities.findOne(activityId);
var documentObj = ActivityFiles.findOne(activityObj.documents.pop()._id);
JSZipUtils.getBinaryContent(documentObj.url(), callback);
function callback(error, content) {
var zip = new JSZip(content);
var doc = new Docxtemplater().loadZip(zip);
var xml = zip.files[doc.fileTypeConfig.textPath].asText();
xml = xml.substring(xml.indexOf("<w:body>") + 8);
xml = xml.substring(0, xml.indexOf("</w:body>"));
xml = xml.substring(0, xml.indexOf("<w:sectPr"));
insertedDocuments.push(xml);
i++;
if (i == count - 1) {
resolve();
}
}
});
});
fileDownloadPromise.then(() => {
JSZipUtils.getBinaryContent('/assets/template.docx', callback);
function callback(error, content) {
console.log(content);
var zip = new JSZip(content);
var doc = new Docxtemplater().loadZip(zip);
setData(doc);
}
function setData(doc) {
doc.setData({
body: insertedDocuments.join('<w:br/><w:br/>')
});
doc.render();
useResult(doc);
}
function useResult(doc) {
var out = doc.getZip().generate({
type: 'blob',
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
});
saveAs(out, programObj.name + '.docx');
}
});
}
Turns out nothing's happening. What's wrong with the execution of this Promise here ?
I'm only calling resolve when every file has been loaded in the array.
i have this class (product).
var Product = function () {
this.products = [];
this.priceFrom = null;
this.priceTo = null;
this.countDone = 0;
};
Product.prototype = {
constructor: Product,
getProductsByPriceRange: function (priceFrom, priceTo) {
var xhrUrl = "<?= base_url('market/products/xhr_product_price_range') ?>";
var xhrData = {price_from: priceFrom, price_to: priceTo};
var xhrType = "json";
var UtilsClass = new Utils();
UtilsClass.xhrConnection(xhrUrl, xhrData, xhrType, function (data) {
/* MY DATA IS HERE */
});
},
buildList:function (products) {
for (var i = 0; i < products.length; i++) {
var product = products[i];
console.log("product");
}
},
buildOne: function (product) {
}
};
/*....more classes */
And another piece of code (out of product class):
var fromPrice = data.from;
var toPrice = data.to;
var ProductClass = new Product();
var lastCountDone = ProductClass.countDone;
ProductClass.priceFrom = fromPrice;
ProductClass.priceTo = toPrice;
var myProducts = ProductClass.getProductsByPriceRange(ProductClass.priceFrom, ProductClass.priceTo);
My question is... can i wait callback of UtilsClass.xhrConnection (in first piece) and use generated data of callback in second piece of code (out of first piece).
Any ideas would be very valuable to me. Thank you!
var Product = function () {
this.products = [];
this.priceFrom = null;
this.priceTo = null;
this.countDone = 0;
};
Product.prototype = {
constructor: Product,
getProductsByPriceRange: function (priceFrom, priceTo) {
var xhrUrl = "<?= base_url('market/products/xhr_product_price_range') ?>";
var xhrData = {price_from: priceFrom, price_to: priceTo};
var xhrType = "json";
var UtilsClass = new Utils();
return new Promise(function(resolve, reject){
UtilsClass.xhrConnection(xhrUrl, xhrData, xhrType, function (data) {
/* MY DATA IS HERE */
resolve(data)
});
});
},
buildList:function (products) {
for (var i = 0; i < products.length; i++) {
var product = products[i];
console.log("product");
}
},
buildOne: function (product) {
}
};
While calling,
var fromPrice = data.from;
var toPrice = data.to;
var ProductClass = new Product();
var lastCountDone = ProductClass.countDone;
ProductClass.priceFrom = fromPrice;
ProductClass.priceTo = toPrice;
var myProducts = ProductClass.getProductsByPriceRange(ProductClass.priceFrom, ProductClass.priceTo).then(function(data){%your data will be available here%});
I tried to use following code to test the performance of IndexedDB.
The code is modified from http://www.html5rocks.com/en/tutorials/indexeddb/todo/ ,
It works well in chrome, but fails in Firefox 10, saying "db.setVersion is not a function".
I want to know how can I modify the code to make it work in firefox?
var count=0;
var MAX=10;
var times=3;
var allTime;
var stime;
var etime;
var html5rocks = {};
var indexedDB = window.indexedDB || window.webkitIndexedDB ||
window.mozIndexedDB;
if ('webkitIndexedDB' in window) {
window.IDBTransaction = window.webkitIDBTransaction;
window.IDBKeyRange = window.webkitIDBKeyRange;
}
html5rocks.indexedDB = {};
html5rocks.indexedDB.db = null;
html5rocks.indexedDB.onerror = function(e) {
//console.log(e);
alert("Why didn't you allow my web app to use IndexedDB?!");
};
html5rocks.indexedDB.open = function(type) {
var request = indexedDB.open("todos");
request.onsuccess = function(e) {
var v = "1.20";
html5rocks.indexedDB.db = e.target.result;
var db = html5rocks.indexedDB.db;
// We can only create Object stores in a setVersion transaction;
if (v!= db.version) {
var setVrequest = db.setVersion(v);
// onsuccess is the only place we can create Object Stores
setVrequest.onerror = html5rocks.indexedDB.onerror;
setVrequest.onsuccess = function(e) {
if(db.objectStoreNames.contains("todo")) {
db.deleteObjectStore("todo");
}
var store = db.createObjectStore("todo",
{keyPath: "number"});
addTest();
};
}
else addTest();
};
request.onerror = html5rocks.indexedDB.onerror;
}
html5rocks.indexedDB.addTodo = function(todoText,num) {
var db = html5rocks.indexedDB.db;
var trans = db.transaction(["todo"], IDBTransaction.READ_WRITE);
var store = trans.objectStore("todo");
var data = {
"text": todoText,
"number": num
};
var request = store.put(data);
request.onsuccess = function(e) {
count++;
if(count>=times*MAX)
{
etime=new Date;
var t=document.getElementById('result').innerHTML;
document.getElementById('result').innerHTML=t+((etime.valueOf()-stime.valueOf())/times)+"<br/>";
allTime=0;stime=new Date;count=0;
getTest();
}
};
request.onerror = function(e) {
console.log("Error Adding: ", e);
};
};
html5rocks.indexedDB.getTodo = function(id) {
var db = html5rocks.indexedDB.db;
var trans = db.transaction(["todo"], IDBTransaction.READ_WRITE);
var store = trans.objectStore("todo");
var request = store.get(id);
request.onsuccess = function(e) {
count++;
if(count>=times*MAX)
{
etime=new Date;
var t=document.getElementById('result').innerHTML;
document.getElementById('result').innerHTML=t+((etime.valueOf()-stime.valueOf())/times)+"<br/>";
allTime=0;stime=new Date;count=0;
delTest();
}
};
request.onerror = function(e) {
console.log("Error getting: ", e);
};
};
html5rocks.indexedDB.deleteTodo = function(id) {
var db = html5rocks.indexedDB.db;
var trans = db.transaction(["todo"], IDBTransaction.READ_WRITE);
var store = trans.objectStore("todo");
var request = store.delete(id);
request.onsuccess = function(e) {
count++;
if(count>=times*MAX)
{
etime=new Date;
var t=document.getElementById('result').innerHTML;
document.getElementById('result').innerHTML=t+((etime.valueOf()-stime.valueOf())/times)+"<br/>";
allTime=0;stime=new Date;count=0;
dataTest();
}
};
request.onerror = function(e) {
console.log("Error Adding: ", e);
};
};
html5rocks.indexedDB.addData = function(d) {
var db = html5rocks.indexedDB.db;
var trans = db.transaction(["todo"], IDBTransaction.READ_WRITE);
var store = trans.objectStore("todo");
var data={
"text":d,
"number":1
};
var request = store.put(data);
request.onsuccess = function(e) {
etime=new Date;
var t=document.getElementById('result').innerHTML;
document.getElementById('result').innerHTML=t+((etime.valueOf()-stime.valueOf()))+"<br/>";
};
request.onerror = function(e) {
console.log("Error Adding: ", e);
};
};
function addTest() {
for(i=1;i<=times*MAX;i++)
html5rocks.indexedDB.addTodo(' ',i);
}
function getTest() {
for(i=1;i<=times*MAX;i++)
html5rocks.indexedDB.getTodo(Math.round(Math.random()*(MAX*times-1)+1));
}
function delTest() {
for(i=1;i<=times*MAX;i++)
html5rocks.indexedDB.deleteTodo(i);
}
function dataTest() {
data=' ';
for(i=1;i<=21;i++)
data=data+data;
stime=new Date
html5rocks.indexedDB.addData(data);
}
function init() {
stime=new Date;
allTime=0;
html5rocks.indexedDB.open();
}
The spec is not finalized. This is currently shipped as the property mozIndexedDB in Gecko and webkitIndexedDB in Chrome until the standard is finalized. So you have to write for moz also. Now this code is only for webkit.
https://developer.mozilla.org/en/IndexedDB
setVersion() is Deprecated
The new way is to define the version in the IDBDatabase.open() method
firefox from version 10.0 implements open() with the new specification in which an indexeddb database IDBDatabase version is set as the second parameter of the open() method
example
var v = "1.20";
var request = indexedDB.open("todos", v);
html5 indexeddb javascript
The problem here is not the one chosen as the correct answer.
The problem is that the IndexedDB examples on HTML5Rocks were written to the pre-January IndexeDB spec. The working group has since published a breaking change going from the setVersion API to the new onupgradedneeded style.
Here, Firefox is technically correct to fail. Star this issue if you want to see Chrome do the same.