{"id":2819,"date":"2013-05-07T08:59:04","date_gmt":"2013-05-06T23:59:04","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=2819"},"modified":"2018-03-07T17:45:36","modified_gmt":"2018-03-07T08:45:36","slug":"post-2819","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/google-map-api\/2819","title":{"rendered":"\u3010D3.js\u3011Google Map\u4e0a\u306b\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u63cf\u304f"},"content":{"rendered":"<p><a href=\"http:\/\/bl.ocks.org\/shimizu\/1f8c1f44e29f93a34a2be3be1db5829d\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/05\/gmapVoronoi.jpg\" alt=\"D3.js GoogleMap Voronoi Diagram\" width=\"590\" height=\"390\" class=\"alignnone size-full wp-image-2821\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/05\/gmapVoronoi.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/05\/gmapVoronoi-227x150.jpg 227w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2817\">\u524d\u306e\u8a18\u4e8b<\/a>\u3067\u306f\u3001\u30ac\u30bd\u30ea\u30f3\u30b9\u30bf\u30f3\u30c9\u306e\u4f4d\u7f6e\u60c5\u5831\u3092\u7528\u3044\u3066\u9ad8\u5d0e\u5e02\u306e\u5730\u56f3\u4e0a\u306b\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u8868\u793a\u3057\u307e\u3057\u305f\u3002<br \/>\n\u4eca\u56de\u306f\u3001\u540c\u3058\u30c7\u30fc\u30bf\u3092\u4f7f\u3063\u3066Google Map\u4e0a\u306b\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u63cf\u304d\u3001\u30d1\u30f3\uff0f\u30ba\u30fc\u30e0\u306b\u3082\u5bfe\u5fdc\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/bl.ocks.org\/shimizu\/1f8c1f44e29f93a34a2be3be1db5829d\">example<\/a><\/p>\n<p>D3.js\u3092\u4f7f\u3048\u3070\u5730\u56f3\u4e0a\u306b\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u66f8\u304f\u306e\u3082\u6bd4\u8f03\u7684\u7c21\u5358\u306b\u884c\u3048\u307e\u3059\u3002<br \/>\n\u533b\u7642\u6a5f\u95a2\u30c7\u30fc\u30bf\u306a\u3069\u3092\u4f7f\u3063\u3066\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u63cf\u3044\u3066\u307f\u3066\u3082\u9762\u767d\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/h2>\n<pre class=\"lang:js decode:true \" >d3.json('gasStation.geojson', main);\n\nfunction main(pointjson) {\n        \n    \/\/Google Map \u521d\u671f\u5316\n    const map = new google.maps.Map(document.getElementById('map'), {\n        zoom: 11,\n        mapTypeId: google.maps.MapTypeId.ROADMAP,\n        center: new google.maps.LatLng(36.322356, 139.013057),       \n    });\n\n        \n    const overlay = new google.maps.OverlayView(); \/\/OverLay\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u4f5c\u6210\n\n    \/\/\u30aa\u30fc\u30d0\u30ec\u30a4\u8ffd\u52a0\n    overlay.onAdd = function () {\n\n        const layer = d3.select(this.getPanes().overlayLayer).append(\"div\").attr(\"class\", \"SvgOverlay\");\n        const svg = layer.append(\"svg\");\n        const svgOverlay = svg.append(\"g\").attr(\"class\", \"AdminDivisions\");\n        const pointLayer = svgOverlay.append(\"g\");\n        const voronoiLayer = svgOverlay.append(\"g\");\n        const markerOverlay = this;\n        const overlayProjection = markerOverlay.getProjection();\n\n        \/\/Google Map\u306e\u6295\u5f71\u6cd5\u8a2d\u5b9a\n        const googleMapProjection =  coordinates =>  {\n            const googleCoordinates = new google.maps.LatLng(coordinates[1], coordinates[0]);\n            const pixelCoordinates = overlayProjection.fromLatLngToDivPixel(googleCoordinates);\n            return [pixelCoordinates.x + 4000, pixelCoordinates.y + 4000];\n        }\n        \n            \n            \n        \/\/\u518d\u63cf\u753b\u6642\u306b\u547c\u3070\u308c\u308b\u30b3\u30fc\u30eb\u30d0\u30c3\u30af    \n        overlay.draw = function () {\n            const width = svg.node().clientWidth;\n            const height = svg.node().clientHeight;\n\n            \/\/\u6bcd\u70b9\u4f4d\u7f6e\u60c5\u5831\n            const pointdata = pointjson.features;           \n            \/\/\u30d4\u30af\u30bb\u30eb\u30dd\u30b8\u30b7\u30e7\u30f3\u60c5\u5831\n            const positions = [];\n\n            pointdata.forEach(d => {        \n                positions.push(googleMapProjection(d.geometry.coordinates)); \/\/\u4f4d\u7f6e\u60c5\u5831\u2192\u30d4\u30af\u30bb\u30eb\n            });\n    \n    \n            \/\/\u6bcd\u70b9\u8868\u793a\n            const updatePoint = pointLayer.selectAll(\".point\").data(positions)              \n            const enterPoint = updatePoint.enter()\n                .append(\"circle\")\n                .attr(\"class\", \"point\")\n                .attr(\"r\", 2);\n                \n            const point = updatePoint.merge(enterPoint)\n                .attr(\"transform\", d =>  `translate(${d[0]}, ${d[1]})` )\n            \n        \n            \/\/\u30dc\u30ed\u30ce\u30a4\u5909\u63db\u95a2\u6570\n            const voronoi = d3.voronoi()\n                .extent([[-1, -1],[width+1, height+1]]);\n        \n            \/\/\u30dc\u30ed\u30ce\u30a4\u5883\u754c\u30dd\u30ea\u30b4\u30f3\u30c7\u30fc\u30bf\u3092\u751f\u6210\u3059\u308b\n            const polygons = voronoi(positions).polygons();         \n                    \n            \/\/\u5883\u754c\u8868\u793a\n            voronoiLayer.selectAll(\".cell\").remove(); \/\/\u4e00\u65e6\u5168\u6d88\u3057\u3057\u3066\u969bappend\u3059\u308b\u65b9\u304c\u30b9\u30e0\u30fc\u30ba\u306b\u5730\u56f3\u304c\u52d5\u3044\u305f\u3002\n            voronoiLayer.selectAll(\".cell\").data(polygons)\n                .enter()\n                .append(\"path\")\n                .attr(\"class\", \"cell\")\n                .attr(\"fill\", \"none\")\n                .attr(\"stroke\", \"black\")\n        .attr(\"d\", d => {\n            if(!d) return null\n            return \"M\" + d.filter( df => df != null ).join(\"L\") + \"Z\"\n        })\n        };\n\n    };\n\n    \/\/\u4f5c\u6210\u3057\u305fSVG\u3092\u5730\u56f3\u306b\u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u3059\u308b\n    overlay.setMap(map);\n    \n        \n};<\/pre>\n<h2>\u53c2\u8003<\/h2>\n<p><a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3609\">\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u4f7f\u3063\u3066\u30e9\u30d9\u30eb\u306e\u91cd\u306a\u308a\u5408\u3044\u3092\u89e3\u6d88\u3059\u308b<\/a><br \/>\n<a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3645\">\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u4f7f\u3063\u3066\u3001\u5730\u56f3\u4e0a\u306e\u7279\u5b9a\u306e\u4f4d\u7f6e\u304b\u3089\u6700\u3082\u8fd1\u3044\u65bd\u8a2d\u3092\u898b\u3064\u3051\u51fa\u3059\u3002<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u306e\u8a18\u4e8b\u3067\u306f\u3001\u30ac\u30bd\u30ea\u30f3\u30b9\u30bf\u30f3\u30c9\u306e\u4f4d\u7f6e\u60c5\u5831\u3092\u7528\u3044\u3066\u9ad8&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2821,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,37],"tags":[],"class_list":["post-2819","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3v4","category-google-map-api","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2819","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=2819"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2819\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/2821"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=2819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=2819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=2819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}