how can the layer parameter of control search retrieve the selected layers of control layer? - search

here I have
var baseLayers = {
"Fond de carte": osm,
};
var overlays = {
"Barrages en exploitation": markergroup3,
"Petits barrages": markergroup4,
"Wilayas": markergroup6,
"Regions": markergroup7,
};
var layerControl = new L.control.layers(baseLayers, overlays, { collapsed: true });
map.addControl(layerControl);
I want to pay for control search to recover the data after the selection of the layers of control layer
map.addControl(new L.Control.Search({
# layer: here I want to receive the selected layers
propertyName:'Nom',
initial:false,
zoom:12,
collapsed:true,
}));
I tried
var active = layerControl.getOverlays();
layer:function (text, active){
if (active=='markergroup4')
{
return markergroup4
}
else if (active=='markergroup3')
{
return markergroup4
}
},
but it doesn't work

Related

Admin mask with custom entity with ManyToManyAssociation

I have an shopware6 admin extension where some custom entity is stored and loaded. This custom entity has a ManyToManyAssociation to another custom entity. In my mask I use a entity multi select component for the selection.
const category = this.categoryRepository.create();
category.categoryId = this.newCategory;
category.weight = this.newWeight;
category.certificates = this.certificateCollection;
this.categoryRepository.save(category).then(() => {
this.isLoading = false;
this.isSaveSuccessful = true;
this.getList();
}).catch((exception) => {
this.isLoading = false;
this.createNotificationError({
message: this.$tc(
'global.notification.notificationSaveErrorMessageRequiredFieldsInvalid'
)
});
throw exception;
});
<sw-entity-multi-select
:label-property="labelPropertyCertificate"
:criteria="certificateCriteria"
entity-name="certificate"
:entity-collection="certificateCollection"
#change="changeCertificates"
/>
When sending the save request the content of my certificate selection is send with and js object with the property id. To create the correct entity I added some Entity creation process and build my own entity collection for the categoryCertificate collection.
Like this
const category = this.categoryRepository.create();
category.categoryId = this.newCategory;
category.weight = this.newWeight;
category.certificates = new EntityCollection(
this.categoryCertificateRepository.route,
this.categoryCertificateRepository.entityName,
Context.api,
);
this.certificates.forEach(function(item){
const categoryCertificate = me.categoryCertificateRepository.create();
categoryCertificate.categoryId = category.id;
categoryCertificate.certificateId = item.id;
category.certificates.add(categoryCertificate);
});
console.log(category);
this.categoryRepository.save(category).then(() => {
this.isLoading = false;
this.isSaveSuccessful = true;
this.getList();
}).catch((exception) => {
this.isLoading = false;
this.createNotificationError({
message: this.$tc(
'global.notification.notificationSaveErrorMessageRequiredFieldsInvalid'
)
});
throw exception;
});
The console.log shows this, which would be correct
categoryId: "77b959cf66de4c1590c7f9b7da3982f3"
certificates: r(1)
0: Proxy
[[Handler]]: Object
[[Target]]: Object
categoryId: "aa26daab83b04cc6af9a525e7ec1ce16"
certificateId: "8c32fb76000844bcb4d850831fe2f6c1"
extensions: {}
_isNew: true
[[Prototype]]: Object
[[IsRevoked]]: false
...
The request payload shows this, which is not correct.
{id: "b96c923dcee941c7a05c0cb4f98de4d9", categoryId: "251448b91bc742de85643f5fccd89051", weight: 0,…}
categoryId: "251448b91bc742de85643f5fccd89051"
certificates: [{id: "10fb19bccdb0419ca5f4b7abe6561db2"}]
id: "b96c923dcee941c7a05c0cb4f98de4d9"
weight: 0
where are my categoryId & certificateId properties gone? Does the categoryRepository strip them out?
Edit solution
Thx to dneustadt
this.certificates.forEach(function(item){
const categoryCertificate = me.careHintCategoryCertificateRepository.create();
categoryCertificate.id = item.id;
category.certificates.add(categoryCertificate);
});
this works!
By using a ManyToManyAssociationField the values for the columns of the mapping table are resolved dynamically. Since these columns belong to the mapping definition, not to your actual CategoryCertificate entity, they get stripped. You don't need to provide these IDs when you use the respective ManyToManyAssociationField property to assign data from either side.

Tensorflow js server side classification with mobilenet and blazeface

I'm trying to use tensorflowjs with an already built model, at the beginning I had a problem with blazeface because it didn't find face on photo (that display just faces) and so I'm trying with mobilenet and same probleme the result are non sens. So pretty sur it came from the format of image I'm sending.
So this is my code:
module.exports = {
blazeface: require('#tensorflow-models/blazeface'),
mobilenet: require('#tensorflow-models/mobilenet'),
tf: require("#tensorflow/tfjs-node"),
fs: require("fs"),
sizeOf: require("image-size"),
async structureData(imageLink) {
let data = this.fs.readFileSync(imageLink);//return a buffer
const dimension = await this.sizeOf(imageLink);
const tensorflowImage = {
data: data,
width: dimension.width,
height: dimension.height
};
console.log(tensorflowImage)
return tensorflowImage;
},
async detectFace(imageLink) {
let image = await this.structureData(imageLink);
const model = await this./*blazeface*/mobilenet.load();
const returnTensors = false;
const predictions = await model.classify(image);
console.log(predictions);
}
}
So this code do not result of an error but the result are this =>
[
{
className: 'theater curtain, theatre curtain',
probability: 0.03815646469593048
},
{
className: 'web site, website, internet site, site',
probability: 0.0255243219435215
},
{ className: 'matchstick', probability: 0.02520526386797428 }
]
and with any photo (here it's a banana in white background).
So I'm pretty sur i need to rebuilt the structureData function but I don't know how ...
I also tried this with uint32array
async structureData(imageLink) {
let data = this.fs.readFileSync(imageLink);
data = new Uint32Array(data);
const dimension = await this.sizeOf(imageLink);
const tensorflowImage = {
data: data,
width: dimension.width,
height: dimension.height
};
console.log(tensorflowImage)
return tensorflowImage;
},
But I'm getting this error.
Error: pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, but was Object
remember that i'm using node and so I can't (or don't think I can) us HTMLimageelement
Thanks a lot :)
By using a tensor, a video or image element as parameter to the model, it will be able to do the classification.
let data = this.fs.readFileSync(imageLink);
tensor = tf.node.decodeImage(data, 3)
await model.classify(tensor)

Fabricjs custom serialization

I would like to create a canvas in which I would load images of some entity. the images of these entities could change from time to time.
FabricJs provides a built in serialization & de-serialization mechanism using following methods
fabric.Canvas#toJSON to serialize the canvas and
fabric.Canvas#loadFromJSON to de-serialize it but the problem with them is they serialize the image source as well which is enormous and useless in my case
(fabric.Canvas#toDatalessJSON & fabric.Canvas#loadFromDatalessJSON seems to work only for complex object but not images gitHub Ref)
whats is the approach to this?
should customize serialization by serializing all the required properties and recreate objects based on those info?
I have even try to create a subclass of Image removing src from toObject to avoid serializing it but it seems that does not work as well
here is what I have tried with subclass
fabric.MyImage = fabric.util.createClass(fabric.Image, {
type: 'MyImage',
initialize: function(options) {
options || (options = { })
this.callSuper('initialize', options)
this.set('artIndexes', options.artIndexes || '')
},
toObject: function() {
const TO = this.callSuper('toObject')
fabric.util.object.extend(TO, {
artIndexes: this.get('artIndexes')
})
delete TO.src
return TO
},
_render: function(ctx) {
this.callSuper('_render', ctx)
}// ,
// fromURL: function(a, b) {
// this.callSuper('fromURL', a, b)
// }
})
fabric.MyImage.fromObject = function (object, callback) {
fabric.util.enlivenObjects(object.objects, function (enlivenedObjects) {
delete object.objects
callback && callback(new fabric.MyImage(enlivenedObjects, object))
})
}
fabric.MyImage.async = true
and to add Image i would do somthing like this
let img = new fabric.MyImage({entetyReference: entetyRef})
img.setSrc(`${imageSource}`, image => {
this.canvas.add(img)
})
but during serialization and de-serializatiin using FabricJs provided method the object get lost from canvas
I am using latest version of fabricJs

YUI: get all data of row when click cell

I try to make example with datatable of YUI-2.8.2.
YAHOO.example.DynamicData = function() {
// Column definitions
myColumnDefs = [ // sortable:true enables sorting
{key:"id", label:"id", sortable:true},
{key:"date", label:"date", sortable:true},
{key:"price", label:"price", sortable:true},
{key:"number", label:"number", sortable:true}
];
// Custom parser
var stringToDate = function(sData) {
var array = sData.split("-");
return new Date(array[1] + " " + array[0] + ", " + array[2]);
};
var appendTestBtn = function(sData){
return "<input type=\"button\" value=\"Cancel\" onClick=\"javascript:onGetRowData();\">";
};
// DataSource instance
myDataSource = new YAHOO.util.DataSource("http://developer.yahoo.com/yui/examples/datatable/assets/php/json_proxy.php?");
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
myDataSource.responseSchema = {
resultsList: "records",
fields: [
{key:"id"},
{key:"date"},
{key:"price"},
{key:"number",parser:appendTestBtn}
],
metaFields: {
totalRecords: "totalRecords" // Access to value in the server response
}
};
// DataTable configuration
myConfigs = {
initialRequest: "sort=id&dir=asc&startIndex=0&results=25", // Initial request for first page of data
dynamicData: true, // Enables dynamic server-driven data
sortedBy : {key:"id", dir:YAHOO.widget.DataTable.CLASS_ASC}, // Sets UI initial sort arrow
paginator: new YAHOO.widget.Paginator({ rowsPerPage:5 }) // Enables pagination
};
// DataTable instance
myDataTable = new YAHOO.widget.DataTable("dynamicdata", myColumnDefs, myDataSource, myConfigs);
// Update totalRecords on the fly with value from server
myDataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
oPayload.totalRecords = oResponse.meta.totalRecords;
return oPayload;
}
return {
ds: myDataSource,
dt: myDataTable
};
}();
In source, i add a button at "number" column (using appendTestBtn method).
I want: when i click that button i can get all data of that row (Currently i only get data of that cell).
Please help me.
Thank you.
You can use a formatter instead:
var buttonFormatter = function (elCell, oRecord, oColumn, oData) {
return "<input type=\"button\" value=\"Cancel\" />"
};
in your column definition:
myColumnDefs = [ // sortable:true enables sorting
{key:"id", label:"id", sortable:true},
{key:"date", label:"date", sortable:true},
{key:"price", label:"price", sortable:true},
{key:"number", label:"number", formatter: buttonFormatter ,sortable:true}
];
and in your schema don't use parser:
fields: [
{key:"id"},
{key:"date"},
{key:"price"},
{key:"number"}
],
Now in your buttonFormatter method you have access to the row like this:
oRecord.getData("id")
oRecord.getData("date")
oRecord.getData("price")
Hope this helps

How to snap a polyline to a road with walking travelmode in Google Maps?

II want an user to draw a route with polylines on GoogleMaps. I've found a way to snap a polyline ( example in the link, code in below ). The code works with the directions service to draw a polyline on a road, the only problem is this only works with G_TRAVELMODE_DRIVING but I want to use G_TRAVELMODE_WALKING and when you use WALKING you have to supply the map and a div in the constructor of the directions object. When I do that it automatically removes the last line and only displays the current line. I've tried several things like supplying the map as null, or leaving out the map in the constructor.. I've also tried to give a second map in the constructor, get the polylines from the directions service and display them on the right map. But nothing works! I'd appreciate it if someone could help me!
http://econym.org.uk/gmap/example_snappath.htm
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(53.7877, -2.9832),13)
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
var dirn = new GDirections();
var firstpoint = true;
var gmarkers = [];
var gpolys = [];
var dist = 0;
GEvent.addListener(map, "click", function(overlay,point) {
// == When the user clicks on a the map, get directiobns from that point to itself ==
if (!overlay) {
if (firstpoint) {
dirn.loadFromWaypoints([point.toUrlValue(6),point.toUrlValue(6)],{getPolyline:true});
} else {
dirn.loadFromWaypoints([gmarkers[gmarkers.length-1].getPoint(),point.toUrlValue(6)],{getPolyline:true});
}
}
});
// == when the load event completes, plot the point on the street ==
GEvent.addListener(dirn,"load", function() {
// snap to last vertex in the polyline
var n = dirn.getPolyline().getVertexCount();
var p=dirn.getPolyline().getVertex(n-1);
var marker=new GMarker(p);
map.addOverlay(marker);
// store the details
gmarkers.push(marker);
if (!firstpoint) {
map.addOverlay(dirn.getPolyline());
gpolys.push(dirn.getPolyline());
dist += dirn.getPolyline().Distance();
document.getElementById("distance").innerHTML="Path length: "+(dist/1000).toFixed(2)+" km. "+(dist/1609.344).toFixed(2)+" miles.";
}
firstpoint = false;
});
GEvent.addListener(dirn,"error", function() {
GLog.write("Failed: "+dirn.getStatus().code);
});
}
else {
alert("Sorry, the Google Maps API is not compatible with this browser");
}
I know it's an old post, but since no answer came forward and I've recently been working on this sort of code (and got it working), try swapping the addListener with this.
GEvent.addListener(map, "click", function(overlay,point) {
// == When the user clicks on a the map, get directiobns from that point to itself ==
if (!overlay) {
if (firstpoint) {
dirn1.loadFromWaypoints([point.toUrlValue(6),point.toUrlValue(6)],{ getPolyline:true,travelMode:G_TRAVEL_MODE_WALKING});
} else {
dirn1.loadFromWaypoints([gmarkers[gmarkers.length-1].getPoint(),point.toUrlValue(6)],{ getPolyline:true,travelMode:G_TRAVEL_MODE_WALKING});
}
}
});

Resources