style for OpenLayers modify feature (drag) - styles

When I use drag feature, then the circles on the polygon edge has the same style.
For example, this OpenLayers site. I need to change it, I mean they need to be a different color. What is their (cycrles) style attribute?

In fact OpenLayers has very unlogic documentation and sometimes no docs. Here are all style parameters: OpenLayers.Feature.Vector
fill {Boolean} Set to false if no fill is desired.
fillColor {String} Hex fill color. Default is “#ee9900”.
fillOpacity {Number} Fill opacity (0-1). Default is 0.4
stroke {Boolean} Set to false if no stroke is desired.
strokeColor {String} Hex stroke color. Default is “#ee9900”.
strokeOpacity {Number} Stroke opacity (0-1). Default is 1.
strokeWidth {Number} Pixel stroke width. Default is 1.
strokeLinecap {String} Stroke cap type. Default is “round”. [butt | round | square]
strokeDashstyle {String} Stroke dash style. Default is “solid”. [dot | dash | dashdot | longdash | longdashdot | solid]
graphic {Boolean} Set to false if no graphic is desired.
pointRadius {Number} Pixel point radius. Default is 6.
pointerEvents {String} Default is “visiblePainted”.
cursor {String} Default is “”.
externalGraphic {String} Url to an external graphic that will be used for rendering points.
graphicWidth {Number} Pixel width for sizing an external graphic.
graphicHeight {Number} Pixel height for sizing an external graphic.
graphicOpacity {Number} Opacity (0-1) for an external graphic.
graphicXOffset {Number} Pixel offset along the positive x axis for displacing an external graphic.
graphicYOffset {Number} Pixel offset along the positive y axis for displacing an external graphic.
rotation {Number} For point symbolizers, this is the rotation of a graphic in the clockwise direction about its center point (or any point off center as specified by graphicXOffset and graphicYOffset).
graphicZIndex {Number} The integer z-index value to use in rendering.
graphicName {String} Named graphic to use when rendering points. Supported values include “circle” (default), “square”, “star”, “x”, “cross”, “triangle”.
graphicTitle {String} Tooltip when hovering over a feature. deprecated, use title instead
title {String} Tooltip when hovering over a feature. Not supported by the canvas renderer.
backgroundGraphic {String} Url to a graphic to be used as the background under an externalGraphic.
backgroundGraphicZIndex {Number} The integer z-index value to use in rendering the background graphic.
backgroundXOffset {Number} The x offset (in pixels) for the background graphic.
backgroundYOffset {Number} The y offset (in pixels) for the background graphic.
backgroundHeight {Number} The height of the background graphic. If not provided, the graphicHeight will be used.
backgroundWidth {Number} The width of the background width. If not provided, the graphicWidth will be used.
label {String} The text for an optional label. For browsers that use the canvas renderer, this requires either fillText or mozDrawText to be available.
labelAlign {String} Label alignment. This specifies the insertion point relative to the text. It is a string composed of two characters. The first character is for the horizontal alignment, the second for the vertical alignment. Valid values for horizontal alignment: “l”=left, “c”=center, “r”=right. Valid values for vertical alignment: “t”=top, “m”=middle, “b”=bottom. Example values: “lt”, “cm”, “rb”. Default is “cm”.
labelXOffset {Number} Pixel offset along the positive x axis for displacing the label. Not supported by the canvas renderer.
labelYOffset {Number} Pixel offset along the positive y axis for displacing the label. Not supported by the canvas renderer.
labelSelect {Boolean} If set to true, labels will be selectable using SelectFeature or similar controls. Default is false.
labelOutlineColor {String} The color of the label outline. Default is ‘white’. Only supported by the canvas & SVG renderers.
labelOutlineWidth {Number} The width of the label outline. Default is 3, set to 0 or null to disable. Only supported by the canvas & SVG renderers.
fontColor {String} The font color for the label, to be provided like CSS.
fontOpacity {Number} Opacity (0-1) for the label
fontFamily {String} The font family for the label, to be provided like in CSS.
fontSize {String} The font size for the label, to be provided like in CSS.
fontStyle {String} The font style for the label, to be provided like in CSS.
fontWeight {String} The font weight for the label, to be provided like in CSS.
display {String} Symbolizers will have no effect if display is set to “none”. All other values have no effect.

This is how I've done it:
var layer_style = OpenLayers.Util.extend({},OpenLayers.Feature.Vector.style['default']);
layer_style.fillColor = "#333333";
layer_style.strokeColor = "#F62958";
layer_style.strokeOpacity = 0.75;
layer_style.fillOpacity = 0.5;
layer_style.strokeWidth = 5;
layer_style.pointRadius = 3;
layers_layer = osMap.getVectorLayer();
layers_layer.style = layer_style;
lines_layer could be a new layer too, just as long as it's where the item you want to modify is located.

Related

How to find bit length of text with specific font and font size

I'm developing NativeScript JavaScript code to create dynamic text marker for maps. I have the code working that creates a marker for a specific string. My next step is to take any given string, determine its height and width in bits, and create the marker sized to contain the text.
My problem is finding the size of the text, given the text string itself, the font size, and the font family.
It looks like getMeasuredWidth could work, except that the string must already be loaded on a page before that function will return a value. In my case, I simply need to compute the size; the text won't otherwise appear as such on a page (the text in the marker becomes an image).
Is there a way to do this?
var bmp = BitmapFactory.create(200);
bmp.dispose(function (b) {
try {
b.drawRect(
"100,34", // size
'0,0', // upper-left coordinate
KnownColors.Black, // border color
KnownColors.Cornsilk // fill color
);
b.writeText(
"Parking",
"2,25",
{ color: KnownColors.Black, size: 8, name: 'fontawesome-webfont', });
...
In the code above, the width of "100" of the bounding rectangle actually represents the bit width of "Parking" with a small amount of padding. What I want to does calculate the rectangle's height and width and not hard-code it.
Try this, finding label size without adding it to Page upon button click
export function onFindButtonTap(args: EventData) {
const button = <any>args.object;
const label = new Label();
label.text = "Hello, found my size?"
label.fontSize = 20;
(<any>label)._setupAsRootView(button._context);
label.onLoaded();
label.measure(0, 0);
console.log(`Width : ${label.getMeasuredWidth()} x Height : ${label.getMeasuredHeight()}`);
}
Playground Sample
Note: I didn't get a chance to test it with iOS yet, let me know if you hit any issues.

How can we get width and height of a cell in mxgraph after implying some scale and zoom on graph?

I'm trying to achieve an specific cell geometry width and height after implementing some scale and zoom on the graph(I want its new geometry attributes!).
var state = graph.view.getState(cell);
console.log(state.width, state.height);

filling available space inside a vertical layout

in my vaadin project i have a vertical layout (with the height 100%), with two other vertical layouts inside. the fist one has a fixed height, while the second one should fill the remaining space of the browser-window. it will have a bigger height than the remaining space and has an overflow-y: scroll css-attribute. i tried this with the method setExpandRatio but did not work (the height was often more than the remaining space). can i achieve this just with vaadin, or do i have to use javascript for this?
AbstractOrderedLayout root = new VerticalLayout();
root.setHeight(100, Unit.PERCENTAGE);
AbstractOrderedLayout child1 = new VerticalLayout();
AbstractOrderedLayout child2 = new VerticalLayout();
child1.setHeight(200, Unit.PIXELS);
root.addComponent(child1);
child2.setHeightUndefined();
root.addComponent(child2); // child2 will be filled with items. if its higher than the remaining space, it should be scrollable (overflow-y: auto)
// root.setExpandRatio(child2, 1F);
So if i've understood right you would like to have a first area with fixed height and a second area that could be bigger than remaining height so it needs to scroll.
If that's the case, here's the layout
VerticalLayout"Main" (sizeFull)
VerticalLayout"1" (width 100%, height fixed): fill this layout with your fixed height content
Panel (sizeFull + setExpandRation on VerticalLayoutMain to 1)
VerticalLayout"2" (width100%, heightUndefined): fill this layout with your other content
Regards

AndroidPlot - Labels and text

I am a non-developer product manager for an application built in both Android and iOS. We have a bar graph in iOS that provides text for the content of the graph. It displays Totals for each bar, and percentages for each segment of each bar.
In Android, using AndroidPlot (so I understand) we just display the bars with different color segments and no percent totals or totals. I am told by the developer that we can't show more.
I would display the images here, but stackoverflow tells me I don't have enough reputation points to do this. I have created a link to my dropbox with the images https://www.dropbox.com/sh/2uocm5bn79rerbe/AAB7s9QEEYIRIgXhKbUAaOyDa
Is it possible to use AndroidPlot to emulate this iOS chart or at least represent to same information to the end user?
Your developer is more or less correct but you have options. Androidplot's BarRenderer by default provides only an optional label at the top of each bar, which in your iOS images is occupied by the "available", "new", "used" and "rent" label. That label appears to be unused in your Android screenshot so one option would be to utilize those labels do display your totals.
As far as exactly matching the iOS implementation with Androidplot, the missing piece is the ability to add additional labels horizontally and vertically along the side of each bar. You can extend BarRenderer to do this by overriding it's onRender(...) method. Here's a link for your developer that shows where in the code he'll want to modify onRender(...).
I'd suggest these modifications to add the vertical labels:
Invoke Canvas.save(Canvas.ALL_SAVE_FLAG) to store the default orientation of the Canvas.
Use Canvas.translate(leftX, bottom) to center on the bottom left point of the bar
Rotate the Canvas 90 degrees using Canvas.rotate(90) to enable vertical text drawing
Draw whatever text is needed along the side of the plot; 0,0 now corresponds to the bottom left corner of the bar so start there when invoking canvas.drawText(x,y).
Invoke Canvas.restore() to restore the canvas' original orientation.
After implementing the above, adding horizontal "%" labels should be self evident but if you run into trouble feel free to ask more questions along the way.
UPDATE:
Here's a very basic implementation of the above. First the drawVerticalText method:
/**
*
* #param canvas
* #param paint paint used to draw the text
* #param text the text to be drawn
* #param x x-coord of where the text should be drawn
* #param y y-coord of where the text should be drawn
*/
protected void drawVerticalText(Canvas canvas, Paint paint, String text, float x, float y) {
// record the state of the canvas before the draw:
canvas.save(Canvas.ALL_SAVE_FLAG);
// center the canvas on our drawing coords:
canvas.translate(x, y);
// rotate into the desired "vertical" orientation:
canvas.rotate(-90);
// draw the text; note that we are drawing at 0, 0 and *not* x, y.
canvas.drawText(text, 0, 0, paint);
// restore the canvas state:
canvas.restore();
}
All that's left is to invoke this method where necessary. In your case it should be done once per BarGroup and should maintain a consistent position on the y axis. I added the following code to the STACKED case in BarRenderer.onRender(...), immediately above the break:
// needed some paint to draw with so I'll just create it here for now:
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(PixelUtils.spToPix(20));
drawVerticalText(
canvas,
paint,
"test",
barGroup.leftX,
basePositionY - PixelUtils.dpToPix(50)); // offset so the text doesnt intersect with the origin
Here's a screenshot of the result...sorry it's so huge:
Personally, I don't care for the fixed y-position of these vertical labels and would prefer them to float along the upper part of the bars. To accomplish this I modify my invocation of drawVerticalText(...) to look like this:
// needed some paint to draw with so I'll just create it here for now:
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(PixelUtils.spToPix(20));
// right-justify the text so it doesnt extend beyond the top of the bar
paint.setTextAlign(Paint.Align.RIGHT);
drawVerticalText(
canvas,
paint,
"test",
barGroup.leftX,
bottom);
Which produces this result:

How to add a vertial scrollbar in Canvas?

I am developing a Java ME application using Canvas. The details displayed on the Canvas are plentiful, so I need to scroll down the screen to view the further details.
But how can I add a vertical scrollbar on a Canvas?
I think that the scrollbar should be drawn inside the paint method. And you implement the keyReleased method when clicking the arrow of the scrollbar. To implement the scrolling I would prefer call repaint(); and I will manage the paint method with boolean or some other type of private variable.
Consider your canvas as the source and the scroll bar as destination use the following formula to find the scroll bar position
Target point X co-ordinate: tX = taX + ((tW * (sX - saX)) / sW)
Target point Y co-ordinate: tY = taY - ((tH * (saY - sY)) / sH)
saX : Source axis start X coordinate
saY : Source axis start Y coordinate
sW : Souce Width
sH : Source Height
taX : Target axis start X coordinate
taY : Target axis start Y coordinate
tW : Target Width
tH : Target Height
The target height would be the height of the canvas. You must draw the scroll bar as the topmost element.

Resources