Is there a way to read the KML /Document/name to set a layer title within an OpenLayers 3 map?
I have some dynamic KML layers, and I would like to read the titles from the KML layers themselves.
I am currently using code like this to load my KML layers.
layer = new ol.layer.Vector({
source: new ol.source.Vector({
url: kmlurl,
format: new ol.format.KML({
extractStyles: true
})
})
});
map.addLayer(layer);
Currently using OL 3.6.0.
Are there any events I can hook into to get at the raw KML so I can parse it manually?
thanks!
It's possible to do it with jQuery. Use this following code.
The code take the first element with the tag 'Folder' and give the content of the first tag called 'name'.
var url = 'data/my_kml_file.kml'; // your kml file
var elemTagName = 'Folder'; // the element you want the name
// jQuery
$.get( url , function( kmlDatas ) {
var myElem = kmlDatas.getElementsByTagName( elemTagName )[0];
var myElemName = myElem.getElementsByTagName( "name" )[0].innerHTML;
console.info( "KML " + elemTagName + " name: " + myElemName );
});
'elemTagName' got the value 'Folder' because i don't see a 'name' tag in 'Document' of my KML files. Instead there is a 'Folder' > 'name'.
If you really want to use 'Document' > 'name' , just replace the elemTagName by 'Document'.
Related
I am trying to adapt Zack Akil's script to generate a Google Form from a Google Sheet using App Script, but one thing that I am struggling with is to make the sheet's input parsed as HTML. I generate a form based on my sheet, all the text on cells is placed in Forms as plain text, the HTML is not parsed (see figure below).
I pasted the script from Zack and I kindly ask you to point out where should I modify in order to have this parsed on the form.
function getSpreadsheetData(sheetName) {
// Return an list of objects (one for each row) containing the sheets data.
var arrayOfArrays = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName || 'Sheet1').getDataRange().getValues();
var headers = arrayOfArrays.shift();
return arrayOfArrays.map(function (row) {
return row.reduce(function (memo, value, index) {
if (value) {
memo[headers[index]] = value;
}
return memo;
}, {});
});
}
function create_ranges_for_data(form, data, data_section_name){
// loop throughh each row
data.forEach(function (row) {
// create a new question page
form.addPageBreakItem()
// add page title
form.addSectionHeaderItem()
.setTitle(data_section_name);
// create number range input with the title being the document to be labeled
form.addScaleItem()
.setTitle(row[data_section_name])
.setBounds(1, 10)
.setRequired(true);
});
}
function make_form_using_column(column_name) {
// create a new Google Form document
var form = FormApp.create('Data labelling - ' + column_name)
desc = "Thank you for taking the time to label this data!";
form.setDescription(desc);
form.setProgressBar(true);
form.setShowLinkToRespondAgain(false)
var data = getSpreadsheetData();
create_ranges_for_data(form, data, column_name);
}
function gen_form(){
var COLUMN_TO_USE = 'Input text'
make_form_using_column(COLUMN_TO_USE);
}
You can't use HTML text formatting. most sites block it because it poses a security risk. You might need to install an add-on or, like fullfine said, use bold text.
I have a View in my SAPUI5 application where I am creating a OData Model.
In the next step I want to use his metadata to bind a Property.
My error message is
abap.js:64 Assertion failed: COLUMN/#sap:label is not a valid property path
I think here is another mistake because before i tried this, I had always a OData Model which i defined in the manifest file and it worked fine - but now when creating a Model in the same view it doesn't work.
I also thougt about to set the Model to the View, but I think its not neccessery because in the Path I am saying, please look at "oModel" OData Model for your data. {oModel</....
Did I forgot something?
// creating model
var oModel = new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/sap/xxxx/", "oModel");
var oLabel = new sap.ui.comp.smartfield.SmartLabel({
text: "{oModel>/#showcase/" + column + "/#sap:label}" // {ODataModel>/#showcase/" + column + "/#sap:label}" //
});
the "oModel" inside the line
text: "{oModel>/#showcase/" + column + "/#sap:label}"
refers to a name, under which you can assign the model to any Control that is inherited from sap.ui.base.ManagedObject. it has no relationship to the variable name "oModel" that you use to create the model in JS.
the following should work (note, I replaced one occurrence of oModel with bla, the other with blubber to point out the difference
var bla = new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/sap/xxxx/");
var oLabel = new sap.ui.comp.smartfield.SmartLabel({
text: "{blubber>/#showcase/" + column + "/#sap:label}"
});
oLabel.setModel(bla, "blubber")
or, alternatively:
var oLabel = new sap.ui.comp.smartfield.SmartLabel({
models: {
"blubber": new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/sap/xxxx/")
},
text: "{blubber>/#showcase/" + column + "/#sap:label}"
});
I need to insert at the beginning of the list a new option in the select2 control.
I tried with
var data = {
id: -1,
text: 'SISTEMA'
};
var newOption = new Option(data.text, data.id, false, false);
$('#UsuarioId').append(newOption).trigger('change');
But that does not work when data comes from Ajax. In that case, the combobox appears with that option selected and when list is expanded, that option is not there.
Regards
Jaime
Create a variable and initially define that variable as the option you want to include - eg:
var trHTML;
trHTML = '<option value=""></option>'
Then loop through your result set adding each item back to that variable
$.each(x, function (i, item) {
trHTML += '<option value=' + value_name +'>'+ display_name +'</option>';
});
Then append the entire list to the select, and initiate Select2
$('#dropdown_name').append(trHTML);
$('#dropdown_name').select2({
placeholder: "foobar",
allowClear: true
});
This documentation from select2 already explains
https://select2.org/data-sources/ajax
I have the requirement to send filter values via OData-service, to fill a table with relevant entries.
So basically there are input fields, where you can select e.g. "AA" (american airlines) for Carrier-ID.
So the filter values need to be created dynamically, regarding to the user input.
I tried following:
var aFilters = [
new sap.ui.model.Filter({
path: "Carrid",
operator: sap.ui.model.FilterOperator.EQ,
value1: "{selection>/Carrid}"
})
];
oModel.read("/SFLIGHTSSet",{
method: "GET",
filters: aFilters,
success: function(oData2, oResponse) {
var oJSONModel = new sap.ui.model.json.JSONModel();
oJSONModel.setData({
modelData: oData2.results
});
oTable.setModel(oJSONModel);
oTable.bindRows("/modelData");
},
error: function(oError) {
console.log("Error!");
}
});
But that doesn't work.
I receive in back-end following request:
"( Carrid eq '{selection>/Carrid}' )"
So the binding doesn't work in the filter-creation...
The binding is correct because I can use it the same way in a Label:
new sap.m.Label({
text: "{selection>/Carrid}"
});
I researched a lot and know that people have problems with it in XML views.. but couldn't find any solution for JS-Views.
I guess your problem is in the line
"{selection>/Carrid}"
Get the value of the User-Input from the Control somehow like this
var sCarrid= this.byId("MySelection").getBindingContext("selection").getProperty("Carrid");
and modify your Filter
var oFilters = [ new sap.ui.model.Filter("Carrid",
sap.ui.model.FilterOperator.EQ,
sCarrid) ];
This question already has an answer here:
OData Model Not Working
(1 answer)
Closed 20 days ago.
I have created a webservice and trying to bind data using oData protocol in SAPUI5.
I have created a table:
createContent : function(oController) {
jQuery.sap.require("sap.ui.table.Table");
//Create table control with properties
var oTable = new sap.ui.table.Table({
width : "100%",
rowHeight : 50,
title : "Lst of Items",
selectionMode : sap.ui.table.SelectionMode.None
});
oTable.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "PO Number"
}),
template : new sap.ui.commons.TextView({
text : "{PoNumber}"
}),
}
));
oTable.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Item"
}),
template : new sap.ui.commons.TextView({
text : "{PoItem}"
}),
}
));
//Filter values for a certain PO
var aFilter = [];
aFilter.push( new sap.ui.model.Filter("PoNumber", sap.ui.model.FilterOperator.EQ, "4500000043") );
oTable.bindRows({
path: "/PurchaseOrderItemCollection",
filters: aFilter
});
return oTable;
}
The output should be as follows:
PONumber POItem
4500000043 0010
4500000043 0020
But what I get is:
PONumber POItem
4500000043 0020
4500000043 0020
So it shows the last item twice and doesn't show the first item. If I put a break point in my web service code then it is populated correctly.
The data model is created in the following way:
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, false, "user", "passw");
sap.ui.getCore().setModel(oModel);
I have encountered this. Problem is with your data model. Ensure that for the entity both PO number and PO item are marked as keys. Refresh any metadata cache, ensure that both properties appear as keys and try again. It should work.
Thanks
Krishna
My understanding is every entity/entry in the collection should have a unique id <entry><id>...</id></entry>.
And in my case, the returned collection had no ids set for the entities. So the bound ui element finds multiple objects with same id (in this case empty id) and ends up displaying value which it finds the last.
The same should apply even if the id is same across all entities.
Hope it helps, if you have not already found what the problem is.
Thanks,