How to set up icon dimensions in Leaflet.IconMaterial? - leaflet

I'm using the Leaflet.IconMaterial plugin for my leaflet map, but I can't set the dimensions of my icon. How can that be done?

You can't. The dimensions of those icons are hardcoded, here for the size of the icon:
svg.setAttribute('width', '31');
svg.setAttribute('height', '42');
...and then here and here for the coordinates of the circle and the path that together form the "reverse drop" of the icon:
backgroundCircle.setAttribute('cx', '15.5');
backgroundCircle.setAttribute('cy', '15');
backgroundCircle.setAttribute('r', '11');
path.setAttributeNS(null, "d", "M15.6,1c-7.7,0-14,6.3-14,14c0,10.5,14,26,14,26s14-15.5,14-26C29.6,7.3,23.3,1,15.6,1z");
Note that the coordinates of the path points as well as the circle fall inside the width and height of the SVG.
Your best bet would be to make a copy of Leaflet.IconMaterial and change those hardcoded values yourself, and/or apply a scaling transform to the circle and the path inside the icon's SVG. Or better yet, make those values configurable via options (then, ideally, document those modifications and merge the code back with the original Leaflet.IconMaterial git repository).

Related

Is there a way to check for markers whos icons intersect / overlap visibly?

I am building a map and want to use the leaflet markercluster plugin to cluster any markers that intersect visibly (the icons overlap each other). I can't seem to figure out a way to check whether the markers icons intersect though.
I've examined the documentation and the Marker objects. The marker object has no "bounds" object and has no function to return the bounds of the icon.
Yes, it's possible.
This is implemented in some Leaflet plugins, like Leaflet.LayerGroup.Collision - the technique involves fetching the computed style of each icon's HTML element to get the actual size in CSS pixels, offset those numbers by the relative pixel position of the marker's LatLng, and using a rtree data structure to speed up the calculation of the overlaps. Do have a look at the complete source for LayerGroup.Collision plugin.
Note that this technique only takes into account the rectangular bounding boxes of the icons; while it would be possible to check for the individual transparent pixels, that would involve more complex data structures and a different technique to fetch the opacity of each pixel.

Resizing image generated by PaintCode app

I have imported a vector image to PaintCode app and then export its Swift to code. I want to use this vector image in a small View (30x30) but since I want it to work on different devices, I need it to be size-independent.
The original size of the vector image is 512x512. When I add its class to a UIView, only a very small part of the vector image can be seen:
I need to somehow resize the image that can be fit in any size of a frame. I read somewhere, that I have to draw a frame in PaintCode app around the image, I did it but nothing changed.
Start by selecting the "Frame" option from the toolbar
Apply the frame to you canvas...
nb: If you mess up the frame DELETE IT and start again, modifying the frame can change the underlying vector, which is annoying
Apply the desired resize options. This can be confusing the first time.
I group all the elements into a single group. Select the group and on the "box" next to the coordinates of the group, change all the lines to "wiggly" lines. This allows paint code the greatest amount of flexibility when resizing the image...
Finally, change the export options. I tend to use both "Drawing" and "Image" as it provides me the greatest amount of flexibility during development
You should also look at Resizing Constraints, Resizing Drawing Methods and PaintCode Power User: Frames for more details

Create label for conical surface

Is it possible to create labels for conical surfaces in MS-word.
I have a label ready, but it needs to adapt to that the printed label can be pasted on a conical surface (e.g. a coffee cup)
I doubt it. You could try using WordArt: these are predefined shapes, maybe one of those matches what you want to do.
I suspect you'd be better off using a program like Adobe Illustrator, which can convert text to vector images which you can distort any way you like.
The bigger problem is that the label won't fit properly on a shape that is curved in two dimensions: you'll always have folds somewhere.

How to flip x-y axis on click using d3

I am using d3 chart to plot some charts.
I am looking for something by which I can flip my axis on a click of a button. Having said that I mean, I am looking for the functionality which seamlessly works for all type of charts like bar, line, stack etc.
Has anyone done some awesome work like this? Please help
Here is the sample
http://jsfiddle.net/adityasethi2601/ae5BP/
If you arrange your chart carefully, you should be able to achieve the flip with SVG Transforms to rotate your image, translate it if necessary to new margins, and then reverse-rotate any text that you still want to be horizontal.
As a quick-and-dirty example, I've adapted your fiddle so that when the button is clicked, a class gets toggled on the SVG as a whole, which triggers a CSS rotate transform on the entire image.
Javascript:
d3.select("div#chart > svg") ///select the svg
.classed("rotate", function(){
return !d3.select(this).classed("rotate");
//check whether it is currently rotated
//and set it to the opposite
});
CSS:
svg.rotate{
/* rotate the entire image */
-webkit-transform: rotate(-90deg);
transform: rotate(-90deg);
}
http://jsfiddle.net/ae5BP/6/
However, note that CSS transforms (which apply to html objects, such as the entire SVG when embedded in a webpage) are not directly equivalent to SVG transforms, so I wasn't able to get the "reverse-rotate" on text elements working. To use SVG transforms, you'll need to wrap your entire chart in a <g> element to which you can apply the rotation. You'll also need to figure out the appropriate "center of rotation" coordinate, otherwise things will be rotated around your (0,0) origin point.
But this should give you an idea of where to start.
P.S. I also adapted the fiddle to make proper use of JSFiddle formatting and the external resources option for loading D3 -- use this format in the future.
You could also draw two versions of your chart (vertical & horizontal bar versions), and achieve a similar affect by having the "Flip Axis" button toggle visibility between the two.

Creating a stroke/outline of a .PNG with CALayer?

I would like to apply a "stroke" or outline to a png, identically to how Photoshop does it. I have a feeling this can be done with CALayer, but after some tinkering, it is not immediately obvious. setBorderWidth + setBorderColor is almost what I want, except that it only adds a border to the entire dimension of the image, rather than the outline of the png image itself.
Once the stroke is applied, I'd like to also knockout the fill of the png, leaving only an outlined border of the initial shape.
There is no automatic way to do what you're asking. You have to know the path of the shape within your png that you want to "knockout". Once you've defined that, you can create a CAShapeLayer, which accepts a CGPathRef, containing your points. You can stroke and fill the path layer with whatever color you choose and then add it to the layer hierarchy of the displaying view or use it to define a mask of one of the layers in your view.