Add text label to WPF Bing Maps - wpf-controls

Is it possible to add text to specified location (lat/long) in WPF bing maps?

Yes, c# code-behind I'll assume?
// I just created a Location object from the mouseclick but you can replace labelLocation with anything
Microsoft.Maps.MapControl.WPF.Location labelLocation = myMap.ViewportPointToLocation(mousePosition);
// Create a label
Label customLabel = new Label();
customLabel.Content = "Text here";
// With map layers we can add WPF children to lat long (WPF Location obj) on the map.
MapLayer labelLayer = new MapLayer();
labelLayer.AddChild(customLabel, labelLocation );
myMap.Children.Add(labelLayer);

Related

Unable to hide element category in a view in Revit file

I want to hide certain elements in the view.
I managed to hid (with view..HideCategoryTemporary) all the elements I wanted except the marked one in the picture attached.
3D_House_before_hide
Element snoop
This element is a building section of category OST_Viewers.
Manually hiding the element category via the view works, but fetching all OST_Viewers in the code and hiding them does not work.
The following code contain the building section elements in addition to the grids,
FilteredElementCollector viewers_sections = new FilteredElementCollector(doc, v_id).OfCategory(BuiltInCategory.OST_Viewers);
FilteredElementCollector grids = new FilteredElementCollector(doc, v_id).OfCategory(BuiltInCategory.OST_Grids);
FilteredElementCollector elements_to_be_hidden = new FilteredElementCollector(doc, v_id);
elements_to_be_hidden.UnionWith(viewers_sections).UnionWith(grids)
foreach (Element e in elements_to_be_hidden)
{
cur_view.HideCategoryTemporary(e.Category.Id);
}
I've checked that viewers_sections contains the mentioned building sections however it is not hidden from the view.
After hide
How do I hide these building sections?
Please use View#SetCategoryHidden instead to turn off the visibility of the category, the result of the View#HideCategoryTemporary will be reset after closing the file. Here is the working example:
var gridCate = this.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Grids);
var sectionsCate = this.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Sections);
using(var trans = new Transaction(this.Document))
{
trans.Start("Hide Grids & Secions");
this.ActiveView.SetCategoryHidden(gridCate.Id, true);
this.ActiveView.SetCategoryHidden(sectionsCate.Id, true);
trans.Commit();
}

Adding nested stackviews programmatically using xamarin.ios c#

I am creating a app for both android and ios using xamarin and mvvmcross.
In the ios app I want to add outer vertical stackview having nested horizontal stackviews. Basically I just want to create a basic person details screen where will be Label on left and textfield on right which will go in one horizontal stackview and like this there will many horizontal stackviews nested in outer vertical stackview.
I am looking for such example on internet but seems most of the examples are in swift but I was hardly able to find some in c#.
Can someone please help.
Thanks,
Santosh
UIStackView leverages the power of Auto Layout and Size Classes to manage a stack of subviews, either horizontally or vertically, which dynamically responds to the orientation and screen size of the iOS device. You can learn about it through this documentation.
In your case, we can construct a vertical stack to place several horizontal stack:
UIStackView verticalStack = new UIStackView();
View.AddSubview(verticalStack);
verticalStack.Axis = UILayoutConstraintAxis.Vertical;
verticalStack.TranslatesAutoresizingMaskIntoConstraints = false;
// Use auto layout to embed this super vertical stack in the View. Also there's no need to set the height constraint, vertical stack will automatically adjust that depending on its content
verticalStack.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor).Active = true;
verticalStack.TopAnchor.ConstraintEqualTo(TopLayoutGuide.GetBottomAnchor()).Active = true;
verticalStack.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor).Active = true;
for (int i=0; i<10; i++)
{
// Here try to put some horizontal stack with Label on left and textfield on right in the father stack.
UIStackView horizontalStack = new UIStackView();
horizontalStack.Distribution = UIStackViewDistribution.EqualSpacing;
horizontalStack.Axis = UILayoutConstraintAxis.Horizontal;
// UIStackView should use AddArrangedSubview() to add subviews.
verticalStack.AddArrangedSubview(horizontalStack);
UILabel textLabel = new UILabel();
textLabel.Text = "text";
UITextField textField = new UITextField();
textField.Placeholder = "enter text";
horizontalStack.AddArrangedSubview(textLabel);
horizontalStack.AddArrangedSubview(textField);
}
But if every horizontal stack's subViews are almost the same style and layouts. Why not try to use UITableView? You just need to set the single cell's contents and layouts, then use it in the tableView. Moreover this control is reused and scrollable.

How to add text below/above in the middle of the polyline in osmdroid

How to add text below/above in the middle of the polyline in osmdroid? setTitle() does not work neither is setSubDescription().
And also how to add button overlays.
There is a way to do it and it's an opt in feature of the Marker class. The easiest way to find an example is with the LatLonGridOverlay. I'll reduce the logic to something simple to understand below. The key is the order of code, see the title, then set the icon to null, then add to the map. You'll have to figure out where you want the Marker to be based on the coordinates of the polyline but it does work.
Polyline p = new Polyline();
List<GeoPoint> pts = new ArrayList<GeoPoint>();
//add your points here
p.setPoints(pts);
//add to map
Marker m = new Marker(mapView);
m.setTitle("Some text here");
//must set the icon last
m.setIcon(null);
m.setPosition(new GeoPoint(marker location here));
//add to map
source
Setting icon to null alone doesn't worked for me, I need to use setTextIcon:
distanceMarker = new Marker(mapView);
distanceMarker.setIcon(null);
distanceMarker.setTextIcon(distance);
GeoPoint p3 = new GeoPoint((loc.getLatitude()+poi.getLat())/2,(loc.getLongitude()+poi.getLon())/2);
distanceMarker.setPosition(p3);
mapView.getOverlayManager().add(distanceMarker);

How to assign a string id to UI elements.

I'm developing an app on android and I am generating UI elements in a loop. But I need these elements to have an id with letters and numbers, for example "rl1" or "rl2". I was trying to use the method RelativeLayout.setId() but, that method only accepts int. Is there a way I can set an ID as I want without being limited to numbers?
Thanks.
Here is the code I am trying to make work.
for (int i=1; i < 10; i++)
{
//gets the frameview where the elements will be created.
String LinearLayoutId = "frameview1";
int resID = getResources().getIdentifier(LinearLayoutId, "id", "com.myapp.ERS");
LinearLayout linearLayout = (LinearLayout)findViewById(resID);
//creates the RelativeLayout that will hold the ImageIcon and the TextView
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,40 );
rl.setLayoutParams(lp);
rl.setId("rl"); /// >>>> I would like here to set and ID of "rl1" for example.
rl.setBackgroundDrawable(getResources().getDrawable(R.drawable.bk36));
//creates the image icon within the layout at the left side
ImageView image = new ImageView(this);
lp = new RelativeLayout.LayoutParams(
40,RelativeLayout.LayoutParams.MATCH_PARENT );
image.setLayoutParams(lp);
String imageicon = "icon_"+i;
resID = getResources().getIdentifier(imageicon, "drawable", "com.myapp.ERS");
image.setImageDrawable(getResources().getDrawable(resID)); //sets the icon
rl.addView(image); //adds the ImageView to the relative layout
//creates the TextView within the layout with a 40 margin to the left
TextView tv = new TextView(this);
lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT );
lp.setMargins(40, 0, 0, 0);
tv.setLayoutParams(lp);
String textViewID = "tv"+i;
resID = getResources().getIdentifier(textViewID, "string", "com.myapp.ERS");
tv.setText(getResources().getString(resID));
tv.setTextColor(Color.BLACK);
tv.setTextSize(25);
rl.addView(tv);//adds the TextView to the relative layout
rl.setOnClickListener(mAddListener);
linearLayout.addView(rl);//adds the RelativeLayout to the LinearLayout
}
and then I have the OnCLickListener like this...
private OnClickListener mAddListener = new OnClickListener()
{
public void onClick(View v){
Intent intent;
Bundle bundle;
String id = getResources().getResourceEntryName(v.getId());
id = id.replaceAll("\\D+","");
int value = Integer.parseInt(id);
intent = new Intent(ERS.this, ShowInfo.class);
bundle = new Bundle();
bundle.putInt("key", value);
System.out.println(v.getId());
intent.putExtras(bundle);
startActivity(intent);
}
};
I have tried to set up numeric IDs, but then when I Look for them with:
String id = getResources().getResourceEntryName(v.getId());
It can't find them.
I had all of this in an xml file to begin with, but it was really long because there are about forty items in the list, and it was complicated for me to go and change a letter for example in all of them. I came up with this idea to generate them at runtime in a for loop. I am testing in the meantime with ten, but I can't get it to work.
If I am doing something incorrect, then pardon me, but I am new to this.
You may still find it easier to go back to XML layouts and use the R class to generate meaningful IDs. Although as you haven't included the original xml file you refer to at the end of the question, so I can only guess at the problem you had with it. It does seem to fit the bill though, and would allow you to create something along the lines of:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/hellotextview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hi there"/>
The android:id="#+id/hellotextview" generates an id that can be used elsewhere in your project. In your java code you could access that specific TextView with something similar to:
TextView helloText = (TextView) findViewById(R.id.hellotextview);
The R.id.hellotextview is a int automatically generated when the project is built (in gen/R.java), but as you get to pick the name you can assign them something relevant to you and your project. So instead of trying to use strings values such as "rl1" and "rl2" that you mentioned, you could use R.id.rl1 and R.id.rl2.
As well as individual UI elements, you can also use the same technique for strings (in res/values/strings.xml), and other resources stored under the project's res/ folder, such as icons, media files, etc. In the case of strings you would access them getString(R.string.some_name_given_by_you);
See Accessing Resources at the Android Developers site for more info.
Why dont you try using SharedPreferences as an alternative in case you want to access the elements which you give some ID elsewhere in some other activity.

Aspose.Words...calculating widt of text in pixels

I have an MVC3 C# .Net web app. I am using Aspose.Words to create an MS Word document. I have a requirement to not include tables in the document. However, on several lines of the document the alignment of the text is mis-aligned depending on the width of the text.
For example:
This looks good
Proposal Name: My Proposal Date:04/24/2012
This does not
Proposal Name: My Prop Date:04/24/2012
It should be
Proposal Name: My Prop Date:04/24/2012
Based on the width of the first bit of text, I need to calculate the width in pixels (I think) and insert a TAB if necessary.
Any ideas how to do this?
you can use Graphics.MeasureString function which gives you the width of your string in pixels based on your font. for more info go Here
Cheers,
Ehsan
The following code example returns the bounding rectangle of the current entity relative to the page top left corner.
Document doc = new Document(MyDir + "in.docx");
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
var renderObject = layoutCollector.GetEntity(para);
layoutEnumerator.Current = renderObject;
RectangleF location = layoutEnumerator.Rectangle;
Console.WriteLine(location);
}
src: https://www.aspose.com/community/forums/thread/541215/replace-run-text-with-string-of-spaces-of-same-pixel-length.aspx

Resources