Skip to content

Instantly share code, notes, and snippets.

@pgiraud
Last active August 29, 2015 13:58
Show Gist options
  • Select an option

  • Save pgiraud/9969840 to your computer and use it in GitHub Desktop.

Select an option

Save pgiraud/9969840 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers Basic OSM Example</title>
<script src="http://maps.google.com/maps/api/js?v=3&amp;sensor=false"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/theme/default/style.css" type="text/css">
<script src="//cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js"></script>
</head>
<body>
<h1 id="title">Basic OSM Example</h1>
<!--
<div id="tags">
-->
openstreetmap basic light
</div>
<div id="shortdesc">Show a Simple OSM Map</div>
<div id="map" class="smallmap" style="width:512px;height:256px;"></div>
<div id="docs">
<p>This example shows a very simple OSM layout with minimal controls.</p>
</div>
<script src="scales.js"></script>
</body>
</html>
var map, layer;
var resolutions = [2445.9849047851562, 1222.9924523925781, 611.4962261962891,
305.74811309814453, 152.87405654907226, 76.43702827453613,
38.218514137268066, 19.109257068634033, 9.554628534317017];
scalelinecontrol=new OpenLayers.Control.ScaleLine(
{geodesic: true}
);
var serverResolutions = [156543.03390625, 78271.516953125, 39135.7584765625,
19567.87923828125, 9783.939619140625,
4891.9698095703125, 2445.9849047851562,
1222.9924523925781, 611.4962261962891,
305.74811309814453, 152.87405654907226,
76.43702827453613, 38.218514137268066,
19.109257068634033, 9.554628534317017,
4.777314267158508, 2.388657133579254,
1.194328566789627, 0.5971642833948135];
resolutions=serverResolutions;
var options = {
controls: [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.TouchNavigation({
dragPanOptions: {
enableKinetic: true
}
}),
new OpenLayers.Control.Zoom(),
scalelinecontrol,
new OpenLayers.Control.LayerSwitcher()
],
projection: new OpenLayers.Projection('EPSG:900913'),
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
resolutions: resolutions,
layers: [new OpenLayers.Layer('fake', {
isBaseLayer: true,
displayInLayerSwitcher: false
})]
};
map = new OpenLayers.Map('map',options);
layer = new OpenLayers.Layer.OSM( "Simple OSM Map", null, {
isBaseLayer: false,
serverResolutions: serverResolutions
});
map.addLayer(layer);
var googlesatellite = new OpenLayers.Layer.Google(
"Google Satellite",
{
type: google.maps.MapTypeId.SATELLITE,
isBaseLayer: false,
visibility: false
}
);
map.addLayer(googlesatellite);
map.zoomToMaxExtent();
var center = map.getCenter();
// force chrome (33+) to correctly display the scaleline
map.setCenter(new OpenLayers.LonLat(center.lon, center.lat + 0.1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment