I have been using Ammap Library and created Map.
https://www.amcharts.com/demos/custom-html-elements-map-markers/
I want to delete Map images object by using method(), Details are in below link.
Could any one let me know how to use this method()
https://docs.amcharts.com/3/javascriptmaps/MapImage#deleteObject
Method Name:"deleteObject()"
Thanks in Advance
deleteObject is a member method of the image/object itself, so you just call it from the object you want to delete, e.g.
image.deleteObject();
If your map is using custom HTML elements like in the demo, you also need to remove the div generated in your createCustomMarker method by calling removeChild in the DOM. You need to be able to access that div somehow, so I recommend modifying it to set the div's id to something you can look up later like the image's id:
// this function creates and returns a new marker element
function createCustomMarker(image) {
// create holder
var holder = document.createElement("div");
holder.className = "map-marker";
holder.title = image.title;
holder.id = image.id; //added to make div lookup easier
// ...
}
This modification assumes you set an id in your images, which is also recommended since you can use the getObjectById method to get the image object and call its deleteObject method.
Here's a sample function that deletes both the image and custom marker when an image ID is provided:
function deleteImage(imageId) {
var image = map.getObjectById(imageId);
var imageDiv;
if (image) {
image.deleteObject(); //delete the ammap image object
imageDiv = document.getElementById(imageId); //get the custom marker div
imageDiv.parentNode.removeChild(imageDiv); //remove it from the DOM
}
}
Demo - Click on the buttons to delete the corresponding marker.
Related
I'm having trouble passing in the name of an element into a Dyanamics CRM web Resource javacript.
This code works:
function OnFormLoad()
{
var subGrid = window.parent.document.getElementById("Claims")
// do work
}
This code doesn't:
function OnFormLoad(GridName)
{
var subGrid = window.parent.document.getElementById(GridName)
// do work
}
How do I pass in the name of the element I want to work with?
Please refrain from using document.getElementById in Dynamics as it is not supported.
I believe you are trying to get GridContext and get Data from that Grid.
For Example on Account entity we have Contacts as Grid and then you wish to get data from that Grid.
I replicated the same on Account Entity (OnLoad) and get tried to get data from Contacts Grid.
When adding OnLoad event I have passed Grid name as Parameter as below.
I have added below onLoad Js on Account entity and was able to retrieve data from grid.
Note: I have added timeout because directly firing onload was not able to load complete page and then grid Name was not available.
function onLoad(executionContext,gridName){
setTimeout(function(){ getGridDatat(executionContext,gridName); }, 3000);
}
function getGridDatat(executionContext,gridName){
debugger
var formContext = executionContext.getFormContext();
var gridContext = formContext.getControl("Contacts"); // get the grid context
var myRows = gridContext.getGrid().getRows();
/*var myRow = myRows.get(arg);
var gridRowData = myRow.getData();*/
var firstRow =myRows.get(0).getData();
var firstRowAllAttributes = firstrow.entity.attributes.getAll()
var firstRowfirstAttributeValue = firstrow.entity.attributes.get(0).getValue()
}
If you want to perform some operation on change of data formGird then there is one more way to achieve this. Make your grid as Editable and then you can find Events for that gird as below and could perform your operations.
I have a prefab which contains some buttons and I want to get the buttons and add specific onClick functions to them via script. I cant find the right way to get the buttons.
What I am trying is:
tempGo = Instantiate(prefabs[0]);
tempGo.transform.SetParent(transform, false);
tempGo.transform.localScale = Vector3.one;
tempGo.transform.localPosition = Vector3.zero;
Transform t = tempGo.GetComponentInChildren<Transform>().Find("AddGoals");
"AddGoals" Is my Buttons(Tag name)
So after this point how can I code it to add a specific function when the button gets clicked?
Any help would be appreciated thank you!
Get button component and add listener to it. Listener will call the function when that button is clicked. TaskOnClick is an example function that will be called when the button is clicked.
t.GetComponent<Button>().onClick.AddListener(TaskOnClick);
void TaskOnClick()
{
Debug.Log("You have clicked the button!");
}
Using .Find(""), you are looking for a gameobject with that name, not its tag. What you can do is after instantiating the object, use GameObject.FindGameObjectsWithTag("AddGoals"). This will return an array of all of the objects with that tag. Then with Linq you can do something like:
var items = GameObject.FindGameObjectsWithTag("AddGoals"); //This gives gameobject array
var itemTansforms = items.Select(x=>x.transfrom).ToList(); //gives you a list of the object tansforms
As for adding an event, you would need to grab the button component of the object and then add the onclick event.
items.ForEach(x=>x.GetComponent<Button>().AddListener(delegate {Debug.Log($"{x.name} has been clicked")}));
You would have to make sure it is actually a button, or the code will fail. This of course can be modified and is just an example. I hope this helps!
I am trying to get shadow Image of Text object without affecting the output of fabric.
Code
var clonedText = jQuery.extend({}, obj);
clonedText.fill = "rgba(50,50,50,0.5)";
imageURL = clonedText.toDataURL({format:'png'});
Result
Default:
AfterRun:
How can it be fixed?
I mean how can I copy object so that cant affect default image?
UPDATE:
I also tried this and this.
canvas._objects.forEach(function(obj, index){
var clonedText = fabric.util.object.clone(obj);
clonedText.fill = "rgba(50,50,50,0.5)";
imageURL = clonedText.toDataURL({format:'png'});
});
This has same result.
So you should not really clone instances like you would clone javascript objects.
Fabric objects can have references to canvas elements, image elements, deep structures, and every clone logic works on its own.
on fabricjs docs is specified that fabric.util.object.extende/clone does not clones fabricJS objects:
http://fabricjs.com/docs/fabric.util.object.html
Also in the docs is specified the clone method:
So you have to run
myText.clone(function(cloned) {
// do something with cloned....
});
If you are in need of a full syncronous process, and you are not using patterns or image sources for text you can also do:
var objectForm = myText.toObject();
var clonedText = new fabric.Text(objectForm.text, objectForm);
how can add new control from controller
// create a simple Input field
var oInput1 = new sap.m.Text('input1');
oInput1.setText("Some Text ");
oInput1.setTooltip("This is a tooltip ");
// attach it to some element in the page
oInput1.placeAt("sample1");
in view I add holder
try to add text from controller but it not display on screen.
var oLayout = this.getView().byId("idholder");
oLayout.addContent(oInput1);
is Run-time add new control is not possible. we have always render control in view and then update it is this good practice we have to follow ?
The placeAt() method is normally only used to place a View or App into the HTML.
If you want to add a UI5 control on your view, you can do it this way from the controller:
this.getView().addContent(oInput1);
But most likely you won't add controls directly to the view, but rather inside a layout or something inside your view. In that case, do it like this:
var oLayout = this.getView().byId("idOfYourSpecificLayoutFrame");
oLayout.addContent(oInput1);
I am dragging and dropping some element (with the help of Kendo UI) and generating the new element that are the clone element of draggable elements, my problem is that I want to provide new id to them? How can I do that?
Being droptargetOnDrop your drop event handler, you should do:
function droptargetOnDrop(e) {
var newEl = $(e.draggable.currentTarget).clone();
newEl.attr("id",kendo.guid());
e.dropTarget.append(newEl);
}
See your fiddle modified running here: http://jsfiddle.net/OnaBai/rTxaE/2/