khtml.js is a map library for web browsers and openstreetmap tiles. Target of this project is, to build a map library that is faster than google, bing, openlayers... librarys.
It's optimized for speed and uses browser features like 3D CSS (webkit).
It's a low level library that allows you to make librarys with more features or web application on top of it. A central feature is multitouch support for iphone.
At the moment the lib has 40kByte and is one file.

|
|
Initialize with setCenter... <script type="text/javascript" src="khtml.js"> </script> <script type="text/javascript"> function init(){ map1=new kmap(document.getElementById("map1")); var center=new kPoint(48.2,15.633); map1.setCenter(center,9); } </script> </head> <body onload="init()"> <div id="map1" style="widht:100px;height:100px"> </div> ... |
|
|
Initialize with setBounds
...
<script type="text/javascript" src="khtml.js"> </script>
<script type="text/javascript">
function init(){
map2=new kmap(document.getElementById("map2"));
var sw=new kPoint(48.2,16.4);
var ne=new kPoint(48.4,16.8);
var b=new kBounds(sw,ne);
map2.setBounds(b);
}
</script>
</head>
<body onload="init()">
<div id="map1" style="widht:100px;height:100px"> </div>
...
|
|
|
Markers
...
map3=new kmap(document.getElementById("map3"));
var center=new kPoint(48.2,15.633);
map3.setCenter(center,9);
var flagcenter1=new kPoint(48.197231,15.645451);
var img=document.createElement("img");
img.setAttribute("src","images/dot_green.png");
img.style.position="absolute";
img.style.top="-3px"; //<--- flag
img.style.left="-4px"; //<--- flag
img.style.width="8px"; //<--- flag
img.style.height="8px";
img2=img.cloneNode(true);
var m=new kMarker(flagcenter1,img);
map3.addOverlay(m);
var flagcenter1=new kPoint(48.290231,15.605451);
var m=new kMarker(flagcenter1,img2);
map3.addOverlay(m);
...
Status
|
|
|
Path
var lat=centerLat -0.2;
var lng=centerLon -0.2;
var points=new Array();
for(var i=0; i < 20; i++){
lat=lat+Math.random()/10 -0.02;
lng=lng+Math.random()/10 -0.02;
var point=new kPoint(lat,lng);
points.push(point);
}
var style=new kStyle();
style.addStyle("stroke","red");
style.addStyle("stroke-dasharray","8,4,3,4");
style.addStyle("stroke-width",4);
var line=new kPolyline(points,style);
map4.addOverlay(line);
|
|
|
Area
...
var points=new Array();
points.push(new kPoint(48.290231,15.605451));
points.push(new kPoint(48.490231,15.605451));
points.push(new kPoint(48.490231,15.305451));
points.push(new kPoint(48.290231,15.305451));
points.push(new kPoint(48.290231,15.605451));
var style=new kStyle();
style.addStyle("stroke","black");
style.addStyle("fill","yellow");
style.addStyle("fill-opacity","0.4");
style.addStyle("stroke-width",2);
var line=new kPolyline(points,style);
map5.addOverlay(line);
...
StatusJSON style parameters for style would be maybe nice. |
More methodesmap.renderOverlays(); //for refreshing overlays if your app needs map.setCenter(point,zoom); var point=map.getCenter(); map.setBounds(point1,point2); var bounds=map.getBouns(); var zoom=map.getZoom(); var lat=point.getLat(); var lng=point.getLng(); var pointNW=bounds.getNW(); var pointSE=bounds.getSE(); var centerPoint=bounds.getCenter(); var bounds=kBounds(pointNW,pointSE); var distance=bounds.getDistance(); //distance from NW to SE in Meter |
|
| Webkit (chrome, safari) | Very fast zoom if images are in cache. Image loading not optimizable (webkit bug details) |
| Firefox | 3D CSS missing, "zoom" function for div buggy and slow: not usable, normal image zoom in use |
| iPhone | see Webkit, excellent Moultitouch!! |
| Internet Explorer | Should work for IE 6-8, VML not very well tested |
| Opera | 3D CSS missing -> slow |
| Konqueror | 3D CSS missing -> slow |
| Android | Tested on Legend, there is a bug somewhere and it stops function after a while |
Handling millions of images and place it highspeed on the browser window is not an easy task. Browsers do things in a diffent way and Browsers have bugs. Webkit has excellent image zoom but a bad image loading bug.
I tried to implement this library 5 times and started every time completly new.
Many parts of the code are not easy readable.
Some parts of the code like marker handling should be readable by skilled javascript programers.
The xy2latlng ,latlng2xy methods are a bit tricky and maybe buggy.
If you want to do the hardcore things and optimize speed, than welcome in hell.
Documentation for programers
| name: | |
| text: | |