dayjournal memo

Total 974 articles!!

Leaflet #015 - ダウンロードデータのリンクを利用

Yasunori Kirimoto's avatar

LeafletでCDNを利用しないでダウンロードデータのリンクで利用するためには下記のように記述します。

index.html


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>sample</title>

    <script src="http://maps.google.com/maps/api/js?v=3.2&amp;sensor=false"></script>

    <script src="./plugin/leaflet-0.7.3/leaflet.js"></script>
    <script src="./plugin/leaflet-plugins-master/layer/tile/Google.js"></script>
    <script src="./plugin/leaflet-plugins-master/layer/tile/Bing.js"></script>

    <script src="./gj/sample.geojson"></script>

    <link href="./plugin/leaflet-0.7.3/leaflet.css" rel="stylesheet" />
    <link href="./css/stylesheet.css" rel="stylesheet" />

</head>

<body>

    <div id="map"></div>

    <script src="./js/script.js"></script>

</body>

</html>

stylesheet.css


        html, body {
            height: 100%;
            padding: 0;
            margin: 0;
        }

        #map {
            z-index: 0;
            height: 100%;
        }

        .leaflet-google-layer {
            z-index: 1;
        }

        .leaflet-map-pane {
            z-index: 2;
        }

sample.geojson


var pointdata = {
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },

"features": [
{ "type": "Feature", "properties": { "id": 5 }, "geometry": { "type": "Point", "coordinates": [ 139.73025667682498, 35.684728657838271 ] } },
{ "type": "Feature", "properties": { "id": 4 }, "geometry": { "type": "Point", "coordinates": [ 139.7404818862039, 35.630246376589362 ] } },
{ "type": "Feature", "properties": { "id": 3 }, "geometry": { "type": "Point", "coordinates": [ 139.77705667359774, 35.713791961149241 ] } },
{ "type": "Feature", "properties": { "id": 2 }, "geometry": { "type": "Point", "coordinates": [ 139.76722474150262, 35.68153424228494 ] } },
{ "type": "Feature", "properties": { "id": 1 }, "geometry": { "type": "Point", "coordinates": [ 139.7001709646139, 35.690318577295173 ] } }
]
};

script.js


var t_std = new L.tileLayer('http://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png', {
    attribution: "<a href='http://www.gsi.go.jp/kikakuchousei/kikakuchousei40182.html' target='_blank'>国土地理院</a>"
});

var t_pale = new L.tileLayer('http://cyberjapandata.gsi.go.jp/xyz/pale/{z}/{x}/{y}.png', {
    attribution: "<a href='http://www.gsi.go.jp/kikakuchousei/kikakuchousei40182.html' target='_blank'>国土地理院</a>"
});

var t_ort = new L.tileLayer('http://cyberjapandata.gsi.go.jp/xyz/ort/{z}/{x}/{y}.jpg', {
    attribution: "<a href='http://www.gsi.go.jp/kikakuchousei/kikakuchousei40182.html' target='_blank'>国土地理院</a>"
});

var o_std = new L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: '&amp;copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
});

var g_roadmap = new L.Google('ROADMAP');

var g_satellite = new L.Google('SATELLITE');

var g_hybrid = new L.Google('HYBRID');

var map = L.map('map', {
    center: [35.6831925, 139.7511307],
    zoom: 13,
    zoomControl: false,
    layers: [t_pale]
});

var geoJson_sample = L.geoJson(pointdata).addTo(map);

var Map_b = {
    "地理院地図 標準": t_std,
    "地理院地図 淡色": t_pale,
    "地理院地図 オルソ": t_ort,
    "OpenStreetMap 標準": o_std,
    "GoogleMap 標準": g_roadmap,
    "GoogleMap オルソ": g_satellite,
    "GoogleMap ハイブリッド": g_hybrid,
};

var Map_o = {
    "sample": geoJson_sample,
};

L.control.scale({ maxWidth: 250, imperial: false }).addTo(map);

L.control.layers(Map_b, Map_o, { collapsed: false }).addTo(map);

index.htmlを実行すると下記のようにブラウザで表示されます。 ※「この地図は、国土地理院長の承認を得て、同院発行の電子地形図(タイル)を複製したものである。 (承認番号 平27情複、 第224号)」

Leaflet_015_01


※GeoJSONのオブジェクトはWebサーバーにアップロードしないと表示されないようです。



book

Q&A