title: How can I make a custom SVG overlay on Leaflet without using D3?
body: <p>I have recently started a small project that involves drawing transport scheme on top of the Leaflet map. I've got a collection (array) of points denoting stops, each having an attribute <code>location</code> (LatLng). How can I place them on the map without using native markers but using SVG layer with paths &amp; circles instead and guaranteeing the correct geographical placement of elements on every dragging or zooming of the map?</p>
  
  <p>So far, I've thought of:</p>
  
  <ol>
  <li><p><em>Using the SVG overlay provided by Leaflet inside the overlay pane on the map.</em> The problem with this approach is that I have a feeling it was designed specifically for native elements like markers, polylines, etc, but not for custom SVG elements (I haven't found much info on that). And besides, every time I zoom the map in &amp; out, its elements' coordinates don't seem consistent &amp; different all the time.</p></li>
  <li><p><em>Appending an SVG overlay into the map container on top of the map panes.</em> That seems fine and you may be sure Leaflet doesn't 'corrupt' your overlay in any way, until you find out that the SVG is not draggable. Which seems to have 2 solutions:</p>
  
  <p>2.1. Assigning the map container's transform <code>traslate3d</code> value to the overlay. This seems to work &amp; does its job simultaneously displacing both map tile layer &amp; the overlay creating illusion as if they are bound together. Each point now has constant position on the SVG, as long as the map is not zoomed, which equals its projected position onto the container minus the difference between the container's &amp; the overlay's top-left corners. So assuming the overlay should fit all the points &amp; the user is shown the centre of the map, the SVG should start beyond the screen thus having negative values of <code>x</code> &amp; <code>y</code> attributes' or <code>left</code> &amp; <code>top</code> CSS properties. Actually, none of it seems to work correctly as the map is either zero size or the size that only fits the very few points in the top-left corner (which is outside the original viewport).</p>
  
  <p>2.2. <em>Creating a large SVG overlay which would cover the entire tile layer of the map.</em> It's almost the same as the previous solution, yet points can now be projected onto the tile layer directly which eliminates the need to compute the container's &amp; the overlay's positions difference all the time. Same problem with the negative values as above.</p>
  
  <p>2.3. <em>Using a static SVG overlay inside the map container &amp; recalculating the position of all of its elements on drag/zoom.</em>, which leads to the problem stated in the Leaflet's 'native' overlay approach &amp; seems pretty computationally expensive.</p></li>
  </ol>
  
  <p>So, are there any better ways to accomplish this (without D3 as I want a more 'native' solution) or maybe I'm just doing something fundamentally wrong which prevents me from achieving the goal?</p>
  
  <p>CSS &amp; element positioning have always been my weak points, so I'm not quite familiar with side effects of using negative values for SVG's <code>x</code> &amp; <code>y</code> properties, <code>left</code> &amp; <code>top</code> and <code>transform</code>'s <code>translate</code> in CSS &amp; combining them all together seems to confuse me a lot.</p>