{"id":4647,"date":"2015-10-28T13:05:44","date_gmt":"2015-10-28T04:05:44","guid":{"rendered":"https:\/\/y2tech.net\/blog\/?p=4647"},"modified":"2025-12-02T16:56:31","modified_gmt":"2025-12-02T07:56:31","slug":"trying-openlayers-3","status":"publish","type":"post","link":"https:\/\/y2tech.net\/blog\/computer\/webmap\/trying-openlayers-3-4647\/","title":{"rendered":"\u3061\u3087\u3063\u3068\u3060\u3051OpenLayers 3 \u3067\u904a\u3093\u3067\u307f\u305f"},"content":{"rendered":"<h3>OpenLayers 3 \u304c\u9762\u767d\u305d\u3046<\/h3>\r\n<br \/>\r\n<p>Web\u30de\u30c3\u30d7\u30b7\u30b9\u30c6\u30e0\u306e\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u3057\u3066\u6700\u3082\u30dd\u30d4\u30e5\u30e9\u30fc\u306a\u306e\u306f\u3001\u8a00\u308f\u305a\u3068\u77e5\u308c\u305f Google Maps \u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308b\u304b\u3068\u601d\u3046\u304c\u3001\u30aa\u30fc\u30d7\u30f3\u306a\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3068\u3057\u3066\u306f OpenLayers \u304c\u77e5\u3089\u308c\u3066\u3044\u308b\uff0eOpenLayers\u3000\u306b\u3064\u3044\u3066\u306f\u3053\u308c\u307e\u3067\u4f55\u5ea6\u304b\u53d6\u308a\u4e0a\u3052\u3066\u304d\u305f\u304c\u3001OpenLayers\u304cV3\u306b\u306a\u308a\u5927\u5206\u5b89\u5b9a\u3057\u3066\u304d\u305f\u3088\u3046\u306a\u306e\u3067\u3001\u305d\u308d\u305d\u308d<a href=\"http:\/\/openlayers.org\" target=\"_blank\" rel=\"noopener\">OpenLayers 3<\/a>\u306b\u53d6\u308a\u7d44\u3093\u3067\u307f\u3088\u3046\u3068\u601d\u3046\uff0e<\/p>\r\n<br>\r\n<p>OpenLayers3\u306e\u30b5\u30a4\u30c8\u306b GPX, KML \u306a\u3069\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5730\u56f3\u4e0a\u306b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3059\u308b\u3060\u3051\u3067\u5730\u56f3\u4e0a\u306b\u91cd\u306d\u3066\u8868\u793a\u3059\u308bOL3 \u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30e9\u30c3\u30b0\u30b5\u30f3\u30d7\u30eb\u304c\u8f09\u3063\u3066\u3044\u305f\u306e\u3067\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3092\u3061\u3087\u3063\u3068\u3060\u3051\u5f04\u3063\u3066\u30d9\u30fc\u30b9\u30de\u30c3\u30d7\u3092\u56fd\u571f\u5730\u7406\u9662\u306e\u5730\u56f3\u306b\u7f6e\u304d\u63db\u3048\u305f\u30b5\u30f3\u30d7\u30eb\u3092\u7f6e\u3044\u3066\u307f\u305f\uff0e<\/p>\r\n<br \/>\r\n<p>\u3053\u308c\u307e\u3067\u3001\u30b5\u30fc\u30d0\u30b5\u30a4\u30c9\u3067PHP\u306a\u3069\u3067XML\u306e\u30d1\u30fc\u30b7\u30f3\u30b0\u3092\u884c\u3063\u3066\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u306eJavascript\u3078\u30c7\u30fc\u30bf\u3092\u6e21\u3057\u3066\u3044\u305f\u304c\u3001OpenLayers 3 \u3067\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u3067 XML\u30c7\u30fc\u30bf\u3092\u76f4\u63a5\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3057\u305f\u65b9\u304c\u7c21\u5358\u304b\u3064\u5197\u9577\u306aJavascript\u30b3\u30fc\u30c9\u3092\u6e21\u3055\u306a\u304f\u3066\u6e08\u3080\u306e\u3067Wordpress\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u306a\u3069\u306e\u5236\u4f5c\u304c\u5927\u5206\u697d\u306b\u306a\u308a\u305d\u3046\u3060\uff0e<\/p>\r\n<br>\r\n<p>OpenLayers 3 \u306e\u6a5f\u80fd\u304c\u5927\u5206\u5145\u5b9f\u3057\u3066\u304d\u305f\u3088\u3046\u306a\u306e\u3067\u3001Google\u3001Yahoo! Japan, Bing Maps \u306a\u3069\u306e\u30d7\u30ed\u30d7\u30e9\u30a4\u30a8\u30bf\u30ea\u306a\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u304b\u3089\u305d\u308d\u305d\u308d\u8131\u5374\u3067\u304d\u308b\u304b\u3082\u3057\u308c\u306a\u3044\uff0eOpenLayers 3 \u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u76f8\u5909\u308f\u3089\u305a\u8aac\u660e\u4e0d\u8db3\u306a\u306e\u3067\u3001\u4f7f\u3044\u3053\u306a\u3059\u306b\u306f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u30ec\u30d9\u30eb\u307e\u3067\u8fbf\u3063\u3066\u3001\u5185\u5bb9\u3092\u628a\u63e1\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u306e\u304c\u3064\u3089\u3044\u3068\u3053\u308d\u3060\uff0e<\/p>\r\n<br>\r\n<hr \/>\r\n<br>\r\n<h4>\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/h4>\r\n<br>\r\n<br>\r\n<pre><code class=\"language-Markup\">\r\nvar defaultStyle = {\r\n  'Point': [new ol.style.Style({\r\n    image: new ol.style.Circle({\r\n      fill: new ol.style.Fill({\r\n        color: 'rgba(255,255,0,0.5)'\r\n      }),\r\n      radius: 5,\r\n      stroke: new ol.style.Stroke({\r\n        color: '#ff0',\r\n        width: 1\r\n      })\r\n    })\r\n  })],\r\n  'LineString': [new ol.style.Style({\r\n    stroke: new ol.style.Stroke({\r\n      color: '#f00',\r\n      width: 3\r\n    })\r\n  })],\r\n  'Polygon': [new ol.style.Style({\r\n    fill: new ol.style.Fill({\r\n      color: 'rgba(0,255,255,0.5)'\r\n    }),\r\n    stroke: new ol.style.Stroke({\r\n      color: '#0ff',\r\n      width: 1\r\n    })\r\n  })],\r\n  'MultiPoint': [new ol.style.Style({\r\n    image: new ol.style.Circle({\r\n      fill: new ol.style.Fill({\r\n        color: 'rgba(255,0,255,0.5)'\r\n      }),\r\n      radius: 5,\r\n      stroke: new ol.style.Stroke({\r\n        color: '#f0f',\r\n        width: 1\r\n      })\r\n    })\r\n  })],\r\n  'MultiLineString': [new ol.style.Style({\r\n    stroke: new ol.style.Stroke({\r\n      color: '#0f0',\r\n      width: 3\r\n    })\r\n  })],\r\n  'MultiPolygon': [new ol.style.Style({\r\n    fill: new ol.style.Fill({\r\n      color: 'rgba(0,0,255,0.5)'\r\n    }),\r\n    stroke: new ol.style.Stroke({\r\n      color: '#00f',\r\n      width: 1\r\n    })\r\n  })]\r\n};\r\n\r\nvar styleFunction = function(feature, resolution) {\r\n  var featureStyleFunction = feature.getStyleFunction();\r\n  if (featureStyleFunction) {\r\n    return featureStyleFunction.call(feature, resolution);\r\n  } else {\r\n    return defaultStyle[feature.getGeometry().getType()];\r\n  }\r\n};\r\n\r\nvar dragAndDropInteraction = new ol.interaction.DragAndDrop({\r\n  formatConstructors: [\r\n    ol.format.GPX,\r\n    ol.format.GeoJSON,\r\n    ol.format.IGC,\r\n    ol.format.KML,\r\n    ol.format.TopoJSON\r\n  ]\r\n});\r\n\r\n\/\/================================= GSI Map ==========================================\r\nvar map = new ol.Map( {\r\n\ttarget: \"map\",\r\n\trenderer: ['canvas', 'dom'],\r\n\tlayers: [\r\n\t\tnew ol.layer.Tile( {\r\n\t\t\tsource: new ol.source.XYZ( {\r\n\t\t\t\tattributions: [\r\n\t\t\t\t\tnew ol.Attribution( {\r\n\t\t\t\t\t\thtml: \"<a href='http:\/\/maps.gsi.go.jp\/development\/ichiran.html' target='_blank' rel=\"noopener\">\u5730\u7406\u9662\u30bf\u30a4\u30eb<\/a>\"\r\n\t\t\t\t\t} )\r\n\t\t\t\t],\r\n\t\t\t\turl: \"http:\/\/cyberjapandata.gsi.go.jp\/xyz\/std\/{z}\/{x}\/{y}.png\",\r\n\t\t\t\tprojection: \"EPSG:3857\"\r\n\t\t\t} )\r\n\t\t} )\r\n\t],\r\n\tcontrols: ol.control.defaults( {\r\n\t\tattributionOptions: ( {\r\n\t\t\tcollapsible: false\r\n\t\t} )\r\n\t} ),\r\n\tview: new ol.View( {\r\n\t\tprojection: \"EPSG:3857\",\r\n\t\tcenter: ol.proj.transform( [138.7313889, 35.3622222], \"EPSG:4326\", \"EPSG:3857\" ),\r\n\t\tmaxZoom: 18,\r\n\t\tzoom: 12\r\n\t} ),\r\n\tinteractions: ol.interaction.defaults().extend( [dragAndDropInteraction] )\r\n});\r\n\/\/======================================================================================\r\n\r\ndragAndDropInteraction.on( 'addfeatures', function( event ) {\r\n\r\n\tvar vectorSource = new ol.source.Vector( {\r\n\t\tfeatures: event.features\r\n\t});\r\n\tmap.addLayer( new ol.layer.Vector( {\r\n\t\tsource: vectorSource,\r\n\t\tstyle: styleFunction\r\n\t}));\r\n\tmap.getView().fit( \r\n\t\tvectorSource.getExtent(), \/** @type {ol.Size} *\/ ( map.getSize() ) );\r\n});\r\n\r\nvar displayFeatureInfo = function( pixel ) {\r\n\tvar features = [];\r\n\tmap.forEachFeatureAtPixel( pixel, function( feature, layer ) {\r\n\t\tfeatures.push(feature);\r\n\t});\r\n\tif ( features.length > 0 ) {\r\n\t\tvar info = [];\r\n\t\tvar i, ii;\r\n\t\tfor ( i = 0, ii = features.length; i < ii; ++i)  {\r\n\t\t\tinfo.push(features[i].get('name'));\r\n\t\t}\r\n\t\tdocument.getElementById('info').innerHTML = info.join(', ') || '&#038;nbsp';\r\n\t} else {\r\n\t\tdocument.getElementById('info').innerHTML = '&nbsp;';\r\n\t}\r\n};\r\n\r\nmap.on( 'pointermove', function( evt ) {\r\n\tif ( evt.dragging ) {\r\n\t\treturn;\r\n\t}\r\n\tvar pixel = map.getEventPixel( evt.originalEvent );\r\n\tdisplayFeatureInfo( pixel );\r\n});\r\n\r\nmap.on( 'click', function( evt ) {\r\n\tdisplayFeatureInfo( evt.pixel );\r\n});\r\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"OpenLayers3\u306e\u30b5\u30a4\u30c8\u306b GPX, KML \u306a\u3069\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5730\u56f3\u4e0a\u306b\u30c9\u30e9\u30c3\u30b0\uff06\u30c9\u30ed\u30c3\u30d7\u3059\u308b\u3060\u3051\u3067\u5730\u56f3\u4e0a\u306b\u91cd\u306d\u3066\u8868\u793a\u3059\u308b\u304c\u8f09\u3063\u3066\u3044\u305f\u306e\u3067\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3092\u3061\u3087\u3063\u3068\u3060\u3051\u5f04\u3063\u3066\u30d9\u30fc\u30b9\u30de\u30c3\u30d7\u3092\u56fd\u571f\u5730\u7406\u9662\u306e\u5730\u56f3\u306b\u7f6e\u304d\u63db\u3048\u305f\u30b5\u30f3\u30d7\u30eb\u3092\u7f6e\u3044\u3066\u307f\u305f\uff0e","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[561],"tags":[697,696],"class_list":["post-4647","post","type-post","status-publish","format-standard","hentry","category-webmap","tag-drag-drop","tag-openlayers-3"],"_links":{"self":[{"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/posts\/4647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/comments?post=4647"}],"version-history":[{"count":2,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/posts\/4647\/revisions"}],"predecessor-version":[{"id":10892,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/posts\/4647\/revisions\/10892"}],"wp:attachment":[{"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/media?parent=4647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/categories?post=4647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/y2tech.net\/blog\/wp-json\/wp\/v2\/tags?post=4647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}