These are the available sources:
Created
July 8, 2013 05:54
-
-
Save milkbread/5946483 to your computer and use it in GitHub Desktop.
HTML: Tiled Vectors - a 1st Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Testmap for Vector Tiles</title> | |
<meta charset="utf-8" /> | |
<script src="http://cdn.leafletjs.com/leaflet-0.6.1/leaflet.js"></script> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://bl.ocks.org/NelsonMinar/raw/5851197/TileLayer.d3_topoJSON.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<style> | |
@import url(http://cdn.leafletjs.com/leaflet-0.6.1/leaflet.css); | |
.roads{ | |
fill:None; | |
stroke:#f00; | |
stroke-width:2px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map" style="width: 600px; height: 300px"></div> | |
<script> | |
var testing = []; | |
var map = L.map('map').setView([52.52,13.384], 13); | |
map._initPathRoot(); | |
var toolserver = L.tileLayer('http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png'); | |
var stamen = L.tileLayer('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png', {attribution: 'Add some attributes here!'}).addTo(map); | |
var baseLayers = {"stamen": stamen, "toolserver-mapnik":toolserver}; | |
map.on('viewreset',function(){console.log('test')}) | |
var topoJSON_tiles = new L.TileLayer.d3_topoJSON("http://tile.openstreetmap.us/vectiles-highroad/{z}/{x}/{y}.topojson", { | |
class: "roads", | |
layerName: "vectile" | |
}).addTo(map); | |
var overlays = {"tiled roads": topoJSON_tiles}; | |
var control = L.control.layers(baseLayers, overlays).addTo(map); | |
//console.log(stamen._tiles) | |
var storage = {'type':'FeatureCollection', 'features':[]}; | |
for (tile in stamen._tiles){ | |
var cache = tile.split(':') | |
var URL_ = "http://tile.openstreetmap.us/vectiles-highroad/"+map.getZoom()+"/"+cache[0]+"/"+cache[1]+".topojson"; | |
var loadedData = openVectorTile(URL_, storage); | |
console.log(loadedData) | |
} | |
console.log(storage) | |
function openVectorTile(URL, storage_){ | |
d3.json(URL, function(error, tileData) { | |
if (error) { | |
console.log(error); | |
} else { | |
//console.log(tileData) | |
var geoJson = topojson.feature(tileData, tileData.objects.vectile); | |
console.log(geoJson) | |
storage_.features = storage.features.concat(geoJson.features) | |
} | |
}); | |
} | |
function project(point) { | |
var latlng = new L.LatLng(point[1], point[0]); | |
var layerPoint = map.latLngToLayerPoint(latlng); | |
return [layerPoint.x, layerPoint.y]; | |
} | |
/* | |
http://tile.openstreetmap.us/vectiles-highroad/13/4401/2687.topojson | |
http://bl.ocks.org/NelsonMinar/raw/5851197/ | |
*/ | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment