I want to use text instead of StandardMarker in Nokia HERE map.
I tried using TextMarker but didn't work. May be I used incorrectly. Can you suggest me that how to do this?
TextMarker is not a built-in class of the API, rather the example in the API playground (http://developer.here.com/apiexplorer/examples/public/api-for-js/markers/extending-marker-to-text-marker.html) introduces this class by extending the Marker class. Take a look at the source code of the API explorer example.
The general idea is that you will need to produce a graphics (or graphics image) for the marker icon to use. There are multiple ways to do this but creating an SVG markup string with text is probably the easiest way to do it (as shown in the example code).
What the code in the example does it takes some variables and replaces parts of the SVG template string with the values.
var iconSVG = '<svg width="__WIDTH__" height="__HEIGHT__" xmlns="http://www.w3.org/2000/svg">' +
'<rect x="__X__" y="__Y__" rx="5" ry="5" width="__RECT_WIDTH__" height="__RECT_HEIGHT__" ' +
'style="fill:__BRUSH__;stroke:__STROKE__;stroke-width:__STROKEWIDTH__;"/>' +
'<text x="__OFFSETX__" y="__OFFSETY__" fill="__TEXT_PEN__" style="font-weight:normal; ' +
'font-family:__FONTFAMILY__; font-size:__FONTSIZE__;" textContent="__TEXT__">__TEXT__</text>' +
'</svg>',
From the SVG markup string you can produce a graphics image:
icon = new nokia.maps.gfx.GraphicsImage(that.svgParser.parseSvg(iconSVG));
And this graphics image can be used as a marker icon.
marker.set("icon", icon)
The most important thing to note is that you need to figure out the size of your text (width and height) manually.
Related
I'm attempting to add a vector map to a webpage using HERE Maps API for JavaScript. I've been using the style code below to render a super minimal style akin to the 4th picture from the top at this link (the one with only road and water area layers).
sources:
omv:
type: OMV
max_zoom: 17
min_display_zoom: 1
# global description of the map, in this example
# the map background color is white
scene:
background:
color: [1.000, 1.000, 1.000, 1.00]
# section contains the style information for the layers
# that are present on the map
layers:
# user defined name of the rendering layer
water_areas:
# the section defines where the rendering layer takes
# its data from source: omv is mandatory for the Vector Tile API
# layer: water specifies what vector layer is taken
# for the rendering see REST API documentation for the
# list of available layers.
data: {source: omv, layer: water}
# section defines how to render the layer
draw:
polygons:
order: 1 # z-order of the layer
color: [0.055, 0.604, 0.914, 1.00]
road:
data: {source: omv, layer: roads}
draw:
lines:
order: 2
color: [0.561, 0.561, 0.561, 1.00]
width: 15
It wasn't difficult to figure out how to add things like geoshape overlays and UI controls and panning, but the one thing I haven't been able to add successfully is road labels. (Which seems like it'd be quite easy.)
I've attempted to grab code for road label layers from other documentation examples, but it always breaks the map (leaving only my geoshapes on a white background). This may be because there's always global variable attached to the label's language or fill color, but when I attempt to bring in all the global variable settings and references, the map is still broken.
So my question is, does anyone know of a simple/foolproof way to add road labels to a HERE map with such a minimal style? I suppose I'm looking for the minimum attributes necessary to make that layer visible. Thanks!
To better way to rework (delete section/add yours) vector styles to utilize the online editor Map Style editor (it allows you see changes immediately) and after that load reworked style yaml file in your web app like:
function setStyle(map) {
// get the vector provider from the base layer
var provider = map.getBaseLayer().getProvider();
// Create the style object from the YAML configuration.
// First argument is the style path and the second is the base URL to use for
// resolving relative URLs in the style like textures, fonts.
// all referenced resources relative to the base path https://js.api.here.com/v3/3.1/styles/omv.
var style = new H.map.Style('URL/to/your.yaml',
'https://js.api.here.com/v3/3.1/styles/omv/');
// set the style on the existing layer
provider.setStyle(style);
}
See please the example on https://jsfiddle.net/qw64zL85/
There is using this yaml example file with road_labels: there only yaml text
So when trying to add a HoverTool to a plot, the MultiLine Hover works.
But the problem I am having is, that I have another highlighting Single Line, that I do not want the Hover to act on.
So I wanted to input just the multiline to the renderers keyword
p.add_tools(HoverTool(tooltips = [('Name: ', '#Name'),
('Value', '#Value')],
renderers = [multiline]
)
and I am getting the following error:
ValueError: expected an element of either Auto or List(Instance(Renderer)), got [MultiLine(id='4982e76f-7dda-4d78-b729-240c9a29bdef', ...)]
What am I missing?
Glyphs (such as MultiLine) are more like a description of what to draw. There is a seperate GlyphRenderer that takes glyphs and uses them to draw (it can actually have several versions of a glyph to use in different cases, e.g. for selecting and highlighting and decimating). The renderers arg of the hover tool expects the GlyphRenderer, not the glyph.
If you are using bokeh.plotting, then the glyph renderer is returned by the method on the figure:
r = plot.multi_line(...) # r is what to configure on the hover tool
If you are using the low level bokeh.models API then you must already be configuring a GlyphRenderer manually for your MultiLine. Pass that to the hover tool instead.
Why does my OBJ model have has no material and display as black?
I have an OBJ:
<a-obj-model id="gorilla" src="#gorilla-obj" mtl="#gorilla-mtl"></a-obj-model>
I can see the geometry, but the material shows up as black.
If you check your MTL, you might notice it is trying to use TGA or some other sort of textures that aren't plain images. In this case, you need to include additional three.js loaders.
You could try including all the necessary loaders like including https://github.com/mrdoob/three.js/blob/dev/examples/js/loaders/TGALoader.js and THREE.Loader.Handlers.add( /\.tga$/i, new THREE.TGALoader() );
However, it might be simplest to just batch convert all the TGAs to just use images like PNGs using a converter, and replace all instances of 'tga' with 'png'.
My aim is to create a text image and put it on top of other images. This is the command I use to create the text image:
String[] cp_img_arguments = {"convert",
"-size", width_size + "x",
"-background", background_colour,
"-pointsize", pointsize.toString(),
"-font", font_path,
"-fill",text_colour,
"caption:" + text,
destination};
In order to calculate the size of the image I need, I make use of FontsMetrics like this:
Font font = new Font(fontName, Font.PLAIN, pointsize);
Canvas canvas = new Canvas();
fontMetrics = canvas.getFontMetrics(font);
width_size = fontMetrics.stringWidth(toString());
Although I often generate images with the text truncated or multi-line, which means the width I calculate is not actually enough for the text.
The font comes from a .ttf file. I believe this miss-calculation happens because of the density/DPI parameter in GraphicsMagick. I am not currently using it (default is 55 I believe), but I wonder how that affects the actual font size, compared to what FontMetrics calculate.
Does anyone have experience generating images with text using gm? Any ideas how I can make the image dimension calculation more accurate?
I am creating a PDF using iTextSharp.
Part of the process adds straightforward text to the PDF and another part creates an outline of the same text.
For the straighforward text aspect I am using the ShowTextAligned method in iTextSharp; which requires a Basefont and has no way of setting the style.
For the outline I am creating a GDI GraphicsPath to get points, which are then translated into PDF curves/lines etc. The AddString method requires a Drawing.FontStyle
Now my issue is that I need to set the style of AddString to the same one being used by the BaseFont. I.E if the Basefont is rendering Regular, i need to set the AddString fontstyle to regular
How do I determine what style is being used by the BaseFont in ShowTextAligned?
Further info:
I have also tried using ColumnText; which allows you to set an iTextSharp Font, along with it's style. Though using this method results in a font that is rendered with the approximate style; I.E a font usually in regular and set to bold gives a slightly malformed bold font.
EDIT
When I say i need to pass in the BaseFont to ShowTextAligned, What I mean to say is that in order to use this method you have to set the font and size first using SetFontAndSize of the PdfContentByte - it is this method that requires the BaseFont.
I know I must be missing something obvious.. I just can't see the wood for the trees :)
You can try defining your base font beforehand and use it throughout your PDF doc.
See iTextSharp - Working with Fonts
Sample code:
BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
Font times = new Font(bfTimes, 12, Font.ITALIC, Color.RED);
The above lines create a BaseFont object and uses the built-in constant values to set the font family and encoding. It also specifies false for embedding the font within the PDF document. A new Font object is created using the BaseFont object, and further setting the font size in points, the style and the color - again, using iTextSharp's constants for these values.
For more info on BaseFont, see its class definition.
You can use SetColorFill method. Like this
content.BeginText();
BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252,BaseFont.NOT_EMBEDDED);
content.SetFontAndSizebaseFont, 12);
BaseColor baseColor = new BaseColor(255, 0, 0);
content.SetColorFill(baseColor);
//or use predefined colors
content.SetColorFill(BaseColor.RED);
// use ShowTextAligned method
content.EndText();