在svg地图中包装小图像

时间:2016-02-29 06:54:19

标签: jquery html css html5 svg

我正面临一个奇怪的挑战。我的挑战是在svg地图路径中安装700多个小图像。我尝试了许多不同的想法,但每次都失败了。

我的目标:

enter image description here

我在做什么:

.big-map {
    background: url(img/map.svg) no-repeat;
    height: 360px;
    width: 100%;
    position: relative;
  }
  .map-flex {
    background: rgba(200, 20, 20, 0.5);
    height: 149px;
    width: 333px;
    transform: rotateZ(23deg);
    position: absolute;
    top: 32px;
    left: 64px;
    transform-origin: left top;
    display: flex;
    justify-content: center;
    align-content: center;
    align-items: center;
    flex-wrap: wrap;
  }
  .big-map img {
    width: 16px;
  }
<div class="big-map">
  <div class="map-flex">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
    <img src="img/a.jpg">
  </div>
</div>

我的map.svg包含:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 viewBox="-191 305.6 389.5 182.4" style="enable-background:new -191 305.6 389.5 182.4;" xml:space="preserve">
<style type="text/css">
	.st0{fill:#FFFFFF;stroke:#231F20;stroke-miterlimit:10;}
</style>
<g class="group">
<path class="st0" d="M196.6,473.1c-0.3,0-0.6,0.1-0.8,0.1c0.2,5.1-0.2,8-3,11.2c-0.3,0.1-0.5,0.2-0.8,0.3c-1.6-1-2.9-2.2-4.8-3.1
	c0-0.7-0.5-1.7-1.3-2.4c-0.1,0.1-0.2,0.2-0.3,0.4c-1.2,0.7-0.7,1.6-2.2,2.1c-0.8-0.6-1-1.1-2.2-1.3c-0.2,1.1-0.4,1.9-0.7,3
	c-1.9,0-2.2-0.6-4.2-0.7c0,1.8-2.1,2.8-4.1,3c-3-3.4-9.7-2.8-10.4,2.5c-2,0.2-2.4-0.4-4.3-0.4c-0.2-1.2-0.5-1.5-1.1-2.1
	c-0.1,0-0.1,0-0.2,0c-1.3,0.5-2.9,1-4.7,0.8c-2.9-1.6-4-4.5-4.5-8.9c-1.4,0.5-1.1,2.4-2.2,3.3c-1.2,0.4-2.4,0.7-3.6,1.1
	c0,0.4,0,0.8,0,1.2c-0.4,0-0.9,0.1-1.3,0.1c0,0.8-0.1,1.3-0.5,1.8c-1.8,1.2-3.2,1.4-5.4,0.8c-0.4,1.2-0.6,1.8-2.3,2
	c-0.9-1.8-5-2.2-6.9-2.8c-0.6-0.7-1.3-1.4-1.9-2.2c-0.7,0-1.4-0.1-2.1-0.1c-2.5-0.7-5.4-2.1-7.6-3.1c-1.3,0.2-2.6,0.4-3.8,0.6
	c-0.3,0.9-0.4,1.2-1.7,1.4c-0.5-0.2-0.8-0.9-1.1-1.1c-0.8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1-0.7,2.1-0.9
	c1.3,1,3.7,3.4,5.5,3.5c0.9-0.2,1.9-0.3,2.8-0.5c1.2,0.3,5.2,3.4,6.4,4.2c-0.2,0.6-0.4,1.2-0.7,1.8c1.6-0.1,3.2-0.1,4.7-0.2
	c0.7-0.4,0.7-1.5,2.2-1.4c1,0.1,2,0.2,2.9,0.4c1.2-0.4,1.9-1.7,3.8-1.4c0.1,0.8,0,0.9,0.3,1.2c2.5,0.7,4.6-2.4,6.8-2.9
	c0.1,0.1,0.1,0.1,0.2,0.1c0.1,1.3,0.2,2.3,1,2.8c1.2-0.9,4.6-3.8,5.3-0.9c0.4-0.4,0.8-0.8,1.2-1.2c0.7,0.4,1.1,0.8,2.1,1
	c0.1-0.8,0.2-1,0.7-1.4c1.3,0.2,2.1,0.1,2.7,1.2c0.8-0.3,1.6-0.5,2.5-0.8c0.6-2.2,1.4-4,3-5.4c2.8-0.2,2.8,1.1,4.5,1.9
	c1.1,0.2,1.6-0.1,2.1-0.7c1.1,0.5,2.1,0.9,3.2,1.4c0,0.3,0.1,0.6,0.1,0.8c-0.3,0.3-0.6,0.6-0.9,0.9c0.3,0.6,0.6,1.3,0.9,1.9
	c-0.9,0.7-4.7,14-5.4,15.9c0.8,1,1.4,1.6,1.6,3.4c-1.1,0.6-0.9,1.4-1.1,2.7c0.6,0.5,0.9,0.7,1.2,1.7c-1.6,3.5-1.7,8-2.1,11.8
	c1.4,0.9,0.9,1.7,2,3c0.7,0.9,1.9,0.1,2.8,0.7c1.1,0.7,1,1.6,2.4,2.1c-0.1,2.6,1.1,3.7,2.6,5.5c0.2,0.3,1.2,4.1,1.4,4.8
	C199.4,466.2,196.3,469.3,196.6,473.1z"></path></g>
</svg>

非常感谢任何帮助。

更新

正如Paul LeBeau在答案中提到的,我尝试了以下内容:

var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.strokeStyle = '#000';
ctx.lineWidth = 1;
ctx.fillStyle = '#000';
ctx.scale(1.8453456, 2.0702263);
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.8 1.4,0.9 0.9,1.7 2,3 0.7,0.9 1.9,0.1 2.8,0.7 1.1,0.7 1,1.6 2.4,2.1 -0.1,2.6 1.1,3.7 2.6,5.5 0.2,0.3 1.2,4.1 1.4,4.8 2,4.2 -1.1,7.3 -0.8,11.1 z");
ctx.stroke(p);
ctx.fill(p);
ctx.fillStyle = '#FFF';
var getPt = function() {
  var x = Math.random() * 730,
    y = Math.random() * 390;
  if (!ctx.isPointInPath(p, x, y)) {
    return getPt();
  } else {
    return {
      "x": x,
      "y": y
    };
  }
};
for (j = 0; j < 700; j++) {
  var pt = getPt();
  ctx.fillRect(pt.x, pt.y, 1, 1);
};
body {
  background: rebeccapurple;
}
<canvas id='canvas' height='390px' width='730px'></canvas>

尽管如此,我们还是可以看到路径之外的许多点。请检查。

注意:每个浏览器仍未完全支持Path2D,如果浏览器中断,请使用最新的Chrome进行测试。对于部署,您可以使用Canvas5 Polyfill

1 个答案:

答案 0 :(得分:1)

Canvas具有isPointInPath()功能。一种可能的方法:

  1. 创建画布
  2. 在画布上定义地图路径
  3. 使用以下内容放置图像。

    for each image to place:
       while (not foundpointinpath)
          x = random value between 0 & width
          y = random value between 0 & height)
          foundpointinpath = canvas.isPointInPath(path, x, y)
       draw image with random rotation at (x,y)