map._clusterLayer.getSource().forEachFeature(function(feature) {
//how to get index feature?
console.log(featureIndex);
}
There is a getId() function for features:
map._clusterLayer.getSource().forEachFeature(function(feature) {
// you may want to set the index depending on other attributes first:
// feature.setId(feature.get('yourPreferedKeyForIndex'));
// get feature index
var featureIndex = feature.getId();
console.log(featureIndex);
});
Related
I have created a select interaction for my ol3 map and attached a select event handler.
selectInteraction = new ol.interaction.Select({
...
});
selectInteraction.on('select', function (evt) {
???;
});
How do I interrogate 'evt' to determine:
Which feature was clicked to fire the event?
The ID and other attributes of this feature?
Whether the feature was selected or deselected?
The select event emitted by the ol.SelectInteraction is documented here.
As you can see, evt.selected will be an array of all features that were just selected. It will not contain already selected features which are kept selected when clicking a new feature while the addCondition is true. These are the clicked features that were not already selected and matched the filters to be included in the selection.
Likewise, evt.deselected will contain any features that were just deselected.
You can get the ID and properties of each feature with:
var featureID = feature.getId()
var properties = feature.getProperties()
var someSpecificProperty = feature.get("property-name")
See the docs for ol.Feature for more info on the feature and it's attributes.
Here are some items that should help you.. evt.selected gets you the features that are selected. This example is on a clustered layer and you can use the get function on features selected to retrieve properties from the object selected. If you don't know properties available to you then use console.dir(evt) to examine the object using the console.
selectInteraction.on('select', function(evt){
var coord = evt.mapBrowserEvent.coordinate;
var selItems = evt.selected;
var sellength = selItems.length;
var rptFrame = parent.window.frames["rptframe"];
for (var i = 0; i < sellength; i++) {
var label = selItems[i].get('l');
var url = selItems[i].get('url');
if (url) {
rptFrame.location.href = url;
} else {
var feaObj = selItems[i].get('features');
if (feaObj.length == 1) {
url = feaObj[0].get('url');
rptFrame.location.href = url;
} else {
writeMultiSelect(rptFrame,selItems);
}
}
}
});
Related to this topic and this other topic I'm experimenting a issue. This is the SdrivingMaquinForm.class.php code:
class SdrivingMaquinaForm extends BaseSdrivingMaquinaForm {
protected $current_user;
public function configure() {
$this->current_user = sfContext::getInstance()->getUser()->getGuardUser();
unset($this['updated_at'], $this['created_at']);
$this->widgetSchema['idempresa'] = new sfWidgetFormInputHidden();
$id_empresa = $this->current_user->getSfGuardUserProfile()->getIdempresa();
$this->setDefault('idempresa', $id_empresa);
$this->widgetSchema['no_emisor'] = new sfWidgetFormDoctrineChoice(array('model' => 'SdrivingEmisor', 'add_empty' => 'Seleccione un Emisor', 'table_method' => 'fillChoice'));
$this->validatorSchema['idempresa'] = new sfValidatorPass();
$this->validatorSchema['no_emisor'] = new sfValidatorPass();
}
protected function doUpdateObject($values) {
parent::doUpdateObject($values);
if (isset($this['no_emisor'])) {
if ($this->isNew()) {
$sdrivingMaquinaEmisor = new SdrivingMaquinaEmisor();
$this->getObject()->setSdrivingMaquinaEmisor($sdrivingMaquinaEmisor);
} else {
$sdrivingMaquinaEmisor = $this->getObject()->getSdrivingMaquinaEmisor();
}
$sdrivingMaquinaEmisor->setIdemisor($this->values['no_emisor']);
}
}
}
And it works perfectly, if I create a new maquina values are saved correctly, if I edit a existent record once again values are saved correctly and if I delete a record then the relation is deleted too. So the problem is not in actions or method. The problem I'm having is when user select to edit the existent record. Field idempresa and patente (see the schema.yml at first post metioned here) gets theirs values but no_emisor doesn't so every time I want to edit the record I got the select with values, yes, but the selected value isn't the right because I get the add_empty value. How I fix that? Meaning how I assign the default value for the select based on the one existent on the relation between maquina and emisor?
EDIT: working on a possible solution
I'm trying this code:
public function executeEdit(sfWebRequest $request) {
$this->forward404Unless($sdriving_maquina = Doctrine_Core::getTable('SdrivingMaquina')->find(array($request->getParameter('idmaquina'))), sprintf('Object sdriving_maquina does not exist (%s).', $request->getParameter('idmaquina')));
$this->forward404Unless($sdriving_maquina_emisor = Doctrine_Core::getTable('SdrivingMaquinaEmisor')->find(array($request->getParameter('idmaquina'))), sprintf('Object sdriving_maquina_emisor does not exist (%s).', $request->getParameter('idmaquina')));
$this->form = new SdrivingMaquinaForm($sdriving_maquina, $sdriving_maquina_emisor);
}
But then how in the form configure() method I can access to $sdriving_maquina_emisor in order to use form setDefault() method?
EDIT: doUpdateObject($values)
See this is how my doUpdateObject($values) function looks like:
protected function doUpdateObject($values) {
parent::doUpdateObject($values);
if (isset($this['no_emisor'])) {
if ($this->isNew()) {
$sdrivingMaquinaEmisor = new SdrivingMaquinaEmisor();
$this->getObject()->setSdrivingMaquinaEmisor($sdrivingMaquinaEmisor);
} else {
$sdrivingMaquinaEmisor = $this->getObject()->getSdrivingMaquinaEmisor();
}
$sdrivingMaquinaEmisor->setIdemisor($this->values['no_emisor']);
}
}
Where exactly feet the code you leave for doUpdateObject()?
In these situations you always have to do 2 things:
load the default value from the doctrine record object into the form widget
update the doctrine object with the posted value
And most of the times you should use updateDefaultsFromObject and doUpdateObject symmetrically.
To load back the saved values override updateDefaultsFromObject:
// maybe you have to declare it as public if the parent class requires that
protected function updateDefaultsFromObject()
{
parent::updateDefaultsFromObject();
if (isset($this['no_emisor'])
{
$this->setDefault('no_emisor', $this->getObject()->getSdrivingMaquinaEmisor()->getIdemisor());
}
}
// and you can simplify this a little bit as well
protected function doUpdateObject($values)
{
parent::doUpdateObject($values);
if (isset($this['no_emisor']))
{
$this->getObject()->getSdrivingMaquinaEmisor()->setIdemisor($this->values['no_emisor']);
}
}
I develop an application with asp.net mvc + breeze.
So far, I retrieve a specific record (based on id) like this:
var getTransportById = function (transportId, transportObservable) {
return manager.fetchEntityByKey('Transport', transportId, true)
.then(fetchSucceeded)
.fail(queryFailed);
}
function fetchSucceeded(data) {
var s = data.entity;
return ...
}
Now I need to retrieve the same record but need to 'expand' the property named sender which links to another entity (table). I did not find a way to 'expand' one property through fetchEntityByKey so I used a query like this:
var getTransportById = function (transportId, transportObservable) {
var query = EntityQuery.from('Transports')
.where('id', 'eq', transportId)
.expand('Sender')
.orderBy(orderBy.transport);
return manager.executeQuery(query)
.then(fetchSucceeded)
.fail(queryFailed);
}
function fetchSucceeded(data) {
var s = data.results[0];
return ...
}
My question: is it the good way to proceed? Is there another way of doing?
Thanks.
You can create a query from an EntityKey and then expand whichever properties you want. Something like this:
var entityKey = new EntityKey("Transport", transportId);
// expand whichever nav props you want here.
var query = EntityQuery.fromEntityKey(entityKey).expand("Sender").orderBy(...);
return entityManager.executeQuery(query).then( {
...
});
I am using Lib.Web.Mvc (version 6.1.0) to generate jqgrid in client.
Most attribute of JqGridColumnModel work fine but CellAttributes has not any effection here.
This is my Code:
configuration.Settings.ColumnsModels.AddRange(new JqGridColumnModel[]
{
new JqGridColumnModel("ProductID") { Index = "ProductID" },
new JqGridColumnModel("ProductName") { Index = "ProductName" },
new JqGridColumnModel("SupplierID") { Index = "SupplierID" },
new JqGridColumnModel("CategoryID") { Index = "CategoryID" },
new JqGridColumnModel("QuantityPerUnit") { Index = "QuantityPerUnit"},
new JqGridColumnModel("UnitPrice") { Index = "UnitPrice", CellAttributes*="value=1"}
});
I don't know if CellAttributes still not work in lastes version 6.1.0? Or I don't know how to use it.
Please give me idea to add more attributes to cell from server side (controller).
The JqGridColumnModel.CellAttributes is a proxy to cellattr property of colModel. This property takes a JavaScript function which should return string with attributes. Below you can find corresponding part from jqGrid documentation:
This function add attributes to the cell during the creation of the data - i.e dynamically. By example all valid attributes for the table cell can be used or a style attribute with different properties. The function should return string. ...
And from Lib.Web.Mvc documentation:
Gets or sets the function which can add attributes to the cell during the creation of the data (dynamically).
So in your case the code should look like this:
configuration.Settings.ColumnsModels.AddRange(new JqGridColumnModel[]
{
new JqGridColumnModel("ProductID") { Index = "ProductID" },
new JqGridColumnModel("ProductName") { Index = "ProductName" },
new JqGridColumnModel("SupplierID") { Index = "SupplierID" },
new JqGridColumnModel("CategoryID") { Index = "CategoryID" },
new JqGridColumnModel("QuantityPerUnit") { Index = "QuantityPerUnit" },
new JqGridColumnModel("UnitPrice") { Index = "UnitPrice", CellAttributes = "function() { return 'value=1'; }" }
});
UPDATE
There is one special case, the configuration import and export functionality. In this case all the settings for JavaScript functions, events and callbacks are ignored as those can't be serialized to JSON (this is by design).
I know I can get the current node with 'var top = Node.GetCurrent();' but I cant seem to find where I can get the related properties, specifically 'umbracoNaviHide'. I'd like to know how to access the same data that is accessible from XSLT in a user control
To get properties you need to use the GetProperty() method.
var top = Node.GetCurrent();
top.GetProperty("umbracoNaviHide").Value;
In Umbraco 8, you will have to do something like this:
private List<NavigationListItem> GetChildNavigationList(IPublishedContent page)
{
List<NavigationListItem> listItems = null;
var childPages = page.Children.Where(i => i.IsPublished());
if (childPages != null && childPages.Any() && childPages.Count() > 0)
{
listItems = new List<NavigationListItem>();
foreach (var childPage in childPages)
{
int myTrueFalseFieldValue = 1;
if (childPage.HasProperty("umbracoNaviHide"))
{
Int32.TryParse(childPage.GetProperty("umbracoNaviHide").GetValue().ToString(), out myTrueFalseFieldValue);
//myTrueFalseFieldValue = 0 // hide the page
//myTrueFalseFieldValue = 1 // don't hide the page
string name = childPage.Name;
int test = myTrueFalseFieldValue;
}
if (myTrueFalseFieldValue == 1)
{
NavigationListItem listItem = new NavigationListItem(new NavigationLink(childPage.Url, childPage.Name));
listItem.Items = GetChildNavigationList(childPage);
listItems.Add(listItem);
}
}
}
return listItems;
}
Above code will make sure that those pages which have set there umbrachoNaviHide checkbox property to true will not be included in the navigation list.
In order to see how to make custom property: umbracoNaviHide, please search youtube for "Day11: Hide Pages from Navigation in Umbraco"