{"id":3517,"date":"2014-05-14T13:39:25","date_gmt":"2014-05-14T04:39:25","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=3517"},"modified":"2019-11-01T17:22:44","modified_gmt":"2019-11-01T08:22:44","slug":"post-3517","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/leaflet-js\/3517","title":{"rendered":"\u3010D3.js\u3011 Leaflet\u306bSVG\u3092\u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u3059\u308b\u3002"},"content":{"rendered":"<p><a href=\"http:\/\/leafletjs.com\/\">Leaflet<\/a>\u306f\u3001\u30e2\u30d0\u30a4\u30eb\u30d5\u30ec\u30f3\u30c9\u30ea\u30fc\u3067\u30a4\u30f3\u30bf\u30e9\u30af\u30c6\u30a3\u30d6\u306a\u5730\u56f3\u3092Web\u4e0a\u306b\u8868\u793a\u3059\u308bJavaScript\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u6700\u8fd1\u3001\u6d77\u5916\u3067\u306e\u5b58\u5728\u611f\u304c\u9ad8\u307e\u3063\u3066\u3044\u308b\u3088\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3001D3\u3067\u4f5c\u6210\u3057\u305fsvg\u8981\u7d20\u3092Leaflet\u4e0a\u306b\u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n(\u307e\u3060\u3001\u30bd\u30fc\u30b9\u306e\u30b3\u30e1\u30f3\u30c8\u306b\u66f8\u3044\u305f\u3053\u3068\u4ee5\u4e0a\u306e\u77e5\u8b58\u304c\u306a\u3044\u306e\u3067\u3001\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306e\u307f\u3067\u8a73\u3057\u3044\u89e3\u8aac\u306f\u3042\u308a\u307e\u305b\u3093)<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>D3.js\u3068\u3068\u3082\u306bLeaflet.js\u3068leaflet.css\u3092\u8aad\u307f\u8fbc\u3093\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"lang:xhtml decode:true \" >&lt;!-- leaflet\u306ecss\u3092\u8aad\u307f\u8fbc\u3080 --&gt;\n&lt;link rel=\"stylesheet\" href=\"https:\/\/unpkg.com\/leaflet@1.5.1\/dist\/leaflet.css\"\n    integrity=\"sha512-xwE\/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==\"\n    crossorigin=\"\" \/&gt;\n&lt;!-- leaflet\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u8aad\u307f\u8fbc\u3080--&gt;\n&lt;script src=\"https:\/\/unpkg.com\/leaflet@1.5.1\/dist\/leaflet.js\"\n    integrity=\"sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8\/oTtHPx9\/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og==\"\n    crossorigin=\"\"&gt;&lt;\/script&gt; \n\n&lt;!-- D3.js ver.5 \u3092\u8aad\u307f\u8fbc\u3080--&gt;\n&lt;script src='\/\/unpkg.com\/d3@5.0.0\/dist\/d3.min.js'&gt;&lt;\/script&gt;<\/pre>\n<h3>\u30dd\u30a4\u30f3\u30c8\u60c5\u5831\u3092\u8868\u793a\u3059\u308b<\/h3>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/2e54b3b17ae68a0befe60f6f3b6531a7\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/thumbnail.png\" alt=\"\" width=\"972\" height=\"509\" class=\"alignnone size-full wp-image-6581\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/thumbnail.png 972w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/thumbnail-286x150.png 286w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/thumbnail-768x402.png 768w\" sizes=\"auto, (max-width: 972px) 100vw, 972px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/2e54b3b17ae68a0befe60f6f3b6531a7\">example<\/a><\/p>\n<pre class=\"lang:js decode:true \" >\/\/Leaflet\u521d\u671f\u8a2d\u5b9a\nvar map = L.map('map').setView([ 36.3219088, 139.0032936 ], 12);\nvar mapLink = '<a target=\"_blank\" href=\"http:\/\/portal.cyberjapan.jp\/help\/termsofuse.html\" rel=\"noopener noreferrer\">\u56fd\u571f\u5730\u7406\u9662 \u5730\u7406\u9662\u5730\u56f3 \u6a19\u6e96\u5730\u56f3<\/a>';\n\n\/\/Leaflet\u306bsvg\u30ec\u30a4\u30e4\u30fc\u3092\u8ffd\u52a0\nL.svg().addTo(map);\n\n\/\/Tile Map Service\u306e\u6307\u5b9a\nL.tileLayer('http:\/\/cyberjapandata.gsi.go.jp\/xyz\/std\/{z}\/{x}\/{y}.png', {\n    attribution: '&copy; ' + mapLink + ' Contributors',\n    maxZoom: 18\n}).addTo(map);\n\n\/\/ svg\u8981\u7d20\u3092\u9078\u629e\nvar svg = d3.select('#map').select('svg');\n\n\/\/\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3080\nd3.json('landprice.geojson').then(function(point) {\n    \/\/\u5143\u30c7\u30fc\u30bf\u306bLeaflet\u306eLatLngobj\u3092\u8ffd\u52a0\n    point.features.forEach(function(d) {\n        d.LatLngObj = new L.LatLng(d.geometry.coordinates[1], d.geometry.coordinates[0]);\n    });\n\n    \/\/\u30b5\u30fc\u30af\u30eb\u8981\u7d20\u3092\u8ffd\u52a0\n    var circle = svg\n        .selectAll('circle')\n        .data(point.features)\n        .enter()\n        .append('circle')\n        .attr('stroke', 'black')\n        .attr('stroke-width', 2)\n        .attr('fill', 'red')\n        .attr('fill-opacity', 0.7)\n        .attr('r', 10);\n\n    var update = function() {\n        \/\/\u30b5\u30fc\u30af\u30eb\u8981\u7d20\u306e\u4f4d\u7f6e\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b\n        console.log('update');\n        circle.attr('transform', function(d) {\n            return (\n                'translate(' + map.latLngToLayerPoint(d.LatLngObj).x + ',' + map.latLngToLayerPoint(d.LatLngObj).y + ')'\n            );\n        });\n    };\n\n    map.on('moveend', update);\n    update();\n});\n<\/pre>\n<h3>\u30dd\u30ea\u30f3\u30b4\u30f3\u3092\u8868\u793a\u3059\u308b<\/h3>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/2e54b3b17ae68a0befe60f6f3b6531a7\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/thumbnail-1.png\" alt=\"\" width=\"964\" height=\"512\" class=\"alignnone size-full wp-image-6582\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/thumbnail-1.png 964w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/thumbnail-1-282x150.png 282w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/thumbnail-1-768x408.png 768w\" sizes=\"auto, (max-width: 964px) 100vw, 964px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/2e54b3b17ae68a0befe60f6f3b6531a7\">example<\/a><\/p>\n<pre class=\"lang:js decode:true \" >\/\/Leaflet\u521d\u671f\u8a2d\u5b9a\nvar map = L.map('map').setView([ 39.702053, 141.15448379999998 ], 5);\nvar mapLink = '<a target=\"_blank\" href=\"http:\/\/portal.cyberjapan.jp\/help\/termsofuse.html\" rel=\"noopener noreferrer\">\u56fd\u571f\u5730\u7406\u9662 \u5730\u7406\u9662\u5730\u56f3 \u6a19\u6e96\u5730\u56f3<\/a>';\n\n\/\/Leaflet\u306bsvg\u30ec\u30a4\u30e4\u30fc\u3092\u8ffd\u52a0\nL.svg().addTo(map);\n\n\/\/Tile Map Service\u306e\u6307\u5b9a\nL.tileLayer('http:\/\/cyberjapandata.gsi.go.jp\/xyz\/std\/{z}\/{x}\/{y}.png', {\n    attribution: '&copy; ' + mapLink + ' Contributors',\n    maxZoom: 18\n}).addTo(map);\n\nd3.json('pref.geojson').then(drawMap);\n\nfunction drawMap(geojson) {\n    \/\/ svg\u8981\u7d20\u3092\u9078\u629e\n    var svg = d3.select('#map').select('svg');\n    var g = svg.append('g');\n\n    \/\/\u7def\u5ea6\u7d4c\u5ea6->\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\u95a2\u6570\u4f5c\u6210\n    \/\/\u4f4d\u7f6e\u2192\u5ea7\u6a19\u5909\u63db\n    var projectPoint = function(x, y) {\n        var point = map.latLngToLayerPoint(new L.LatLng(y, x));\n        this.stream.point(point.x, point.y);\n    };\n    var transform = d3.geoTransform({ point: projectPoint });\n    var path = d3.geoPath().projection(transform);\n\n    featureElement = g\n        .selectAll('path')\n        .data(geojson.features)\n        .enter()\n        .append('path')\n        .attr('stroke', 'red')\n        .attr('fill', 'green')\n        .attr('fill-opacity', 0.4);\n\n    \/\/path\u306ed\u5c5e\u6027\u3092\u66f4\u65b0\n    var update = function() {\n        featureElement.attr('d', path);\n    };\n\n    map.on('moveend', update);\n    update();\n}\n <\/pre>\n<h2>\u53c2\u8003<\/h2>\n<p><a href=\"http:\/\/bost.ocks.org\/mike\/leaflet\/\">D3 + Leaflet<\/a> Mike Bostock\u6c0f\u306b\u3088\u308b\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/p>\n<p>\u53c2\u8003\u66f8<br \/>\n<a href=\"https:\/\/leanpub.com\/leaflet-tips-and-tricks\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/LtANDt.png\" alt=\"Leaflet Tips and Tricks\" width=\"192\" height=\"270\" class=\"alignnone size-full wp-image-3518\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/LtANDt.png 192w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/LtANDt-107x150.png 107w\" sizes=\"auto, (max-width: 192px) 100vw, 192px\" \/><\/a><\/p>\n<h2>\u95a2\u9023\u8a18\u4e8b<\/h2>\n<p><span class=\"removed_link\" title=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2379\">\u3010D3.js\u3011Google Map\u306bSVG\u3092\u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u3059\u308b(SHAPE\u30c7\u30fc\u30bf\u8efd\u91cf\u5316)<\/span><br \/>\n<a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2831\">\u3010D3.js\u3011OpenLayers\u4e0a\u306bD3.js\u3067\u4f5c\u6210\u3057\u305fSVG\u3092\u30aa\u30fc\u30d0\u30fc\u30ec\u30a4<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Leaflet\u306f\u3001\u30e2\u30d0\u30a4\u30eb\u30d5\u30ec\u30f3\u30c9\u30ea\u30fc\u3067\u30a4\u30f3\u30bf\u30e9\u30af&hellip;<\/p>\n","protected":false},"author":1,"featured_media":3519,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,55],"tags":[],"class_list":["post-3517","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3v4","category-leaflet-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=3517"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3517\/revisions"}],"predecessor-version":[{"id":3520,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3517\/revisions\/3520"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/3519"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=3517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=3517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=3517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}