Permalink
Browse files

Adding kothic example to async branch

  • Loading branch information...
1 parent 3939108 commit a46b3fa4e273879f49adcd89995ba7c7c3327589 @tmcw tmcw committed Jan 2, 2012
Showing with 2,329 additions and 21 deletions.
  1. +44 −0 examples/kothic/index.html
  2. +156 −0 examples/kothic/kothic.js
  3. +85 −0 examples/kothic/kothic.mm.js
  4. +2,005 −0 examples/kothic/osmosnimki.js
  5. +19 −10 modestmaps.js
  6. +1 −1 modestmaps.min.js
  7. +19 −10 src/layer.js
View
@@ -0,0 +1,44 @@
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" />
+<meta name="apple-mobile-web-app-status-bar-style" content="black" />
+<meta name="apple-mobile-web-app-capable" content="yes" />
+<title>Modest Maps JS - Callback Demo</title>
+<script type="text/javascript" src="kothic.js"></script>
+<script type="text/javascript" src="kothic.mm.js"></script>
+<script type="text/javascript" src="osmosnimki.js"></script>
+<script type="text/javascript" src="../../modestmaps.js"></script>
+<script type="text/javascript">
+
+var map;
+
+function initMap() {
+
+ var container = document.getElementById('container');
+
+ MapCSS.preloadSpriteImage("osmosnimki-maps", "http://osmosnimki.ru/leaf/icons/osmosnimki.png");
+
+ var template = 'http://{S}tile.openstreetmap.org/{Z}/{X}/{Y}.png';
+ var subdomains = [ '', 'a.', 'b.', 'c.' ];
+ var provider = new MM.TemplatedMapProvider(template, subdomains);
+
+ map = new MM.Map('map', new kothicProvider());
+
+ map.setCenterZoom(new MM.Location(53.9, 27.55), 10);
+
+}
+
+</script>
+<style type="text/css">
+div#map:focus {
+ outline: 0;
+}
+</style>
+</head>
+<body onload="initMap()" style="margin:0; padding:0; border:0">
+<div id="container" style="width:400px; height:400px;">
+ <div id="map" style="width:400px; height:400px;" tabindex="0">
+ </div>
+</div>
+</body>
+</html>
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,85 @@
+function kothicProvider() {
+ var k = {};
+
+ var canvases = {};
+ var scripts = {};
+ var callbacks = {};
+
+ var kothic = new Kothic({
+ buffered: false,
+ styles: MapCSS.availableStyles,
+ locales: ['be', 'ru', 'en']
+ });
+
+ function loadScript(url) {
+ var script = document.createElement('script');
+ script.src = url;
+ script.charset = 'utf-8';
+ document.getElementsByTagName('head')[0].appendChild(script);
+ return script;
+ }
+
+ function _invertYAxe (data) {
+ var type, coordinates, tileSize = data.granularity, i, j, k, l, feature;
+ for (i = 0; i < data.features.length; i++) {
+ feature = data.features[i];
+ coordinates = feature.coordinates;
+ type = data.features[i].type;
+ if (type === 'Point') {
+ coordinates[1] = tileSize - coordinates[1];
+ } else if (type === 'MultiPoint' || type === 'LineString') {
+ for (j = 0; j < coordinates.length; j++) {
+ coordinates[j][1] = tileSize - coordinates[j][1];
+ }
+ } else if (type === 'MultiLineString' || type === 'Polygon') {
+ for (k = 0; k < coordinates.length; k++) {
+ for (j = 0; j < coordinates[k].length; j++) {
+ coordinates[k][j][1] = tileSize - coordinates[k][j][1];
+ }
+ }
+ } else if (type === 'MultiPolygon') {
+ for (l = 0; l < coordinates.length; l++) {
+ for (k = 0; k < coordinates[l].length; k++) {
+ for (j = 0; j < coordinates[l][k].length; j++) {
+ coordinates[l][k][j][1] = tileSize - coordinates[l][k][j][1];
+ }
+ }
+ }
+ } else {
+ throw "Unexpected GeoJSON type: " + type;
+ }
+ if (feature.hasOwnProperty('reprpoint')) {
+ feature.reprpoint[1] = tileSize - feature.reprpoint[1];
+ }
+ }
+ }
+
+ function onKothicDataResponse(data, zoom, x, y) {
+ var key = [zoom, x, y].join('/'),
+ canvas = canvases[key];
+ _invertYAxe(data);
+ function onRenderComplete() {
+ callbacks[key](canvas);
+ document.getElementsByTagName('head')[0].removeChild(scripts[key]);
+ delete scripts[key];
+ // delete callbacks[key];
+ }
+ kothic.render(canvas, data, zoom, onRenderComplete);
+ }
+
+ window.onKothicDataResponse = onKothicDataResponse;
+
+ k.getTile = function(coord, callback) {
+ var zoomOffset = 0,
+ key = [(coord.zoom), coord.column, coord.row].join('/'),
+ url = 'http://osmosnimki.ru/vtile/' + key + '.js';
+ canvases[key] = document.createElement('canvas');
+ canvases[key].width = 256;
+ canvases[key].height = 256;
+ scripts[key] = loadScript(url);
+ callbacks[key] = callback;
+ };
+
+ k.releaseTile = function() { };
+ return k;
+}
Oops, something went wrong.

0 comments on commit a46b3fa

Please sign in to comment.