]> dev.renevier.net Git - syj.git/blobdiff - public/js/syjraw.js
add mapquest layer
[syj.git] / public / js / syjraw.js
index ec783f4d677685ddf82e1d4cb5fc5d267940e5eb..8a77bb0ee948faf92d9495aa8ea27e07e8d7733c 100644 (file)
@@ -11,12 +11,36 @@ var styleMap = {
     })
 };
 
+function resizeMap() {
+    var map = document.getElementById('map');
+    map.style.width = map.offsetWidth.toString() + 'px';
+    map.style.height = map.offsetHeight.toString() + 'px';
+}
+
+function mapquestLayer() {
+      return new OpenLayers.Layer.OSM("Mapquest", [
+                'http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png',
+                'http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png',
+                'http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png',
+                'http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png'],
+                    { attribution: SyjStrings.mapquestAttribution});
+}
+
+function osmLayer() {
+    return new OpenLayers.Layer.OSM("OSM", [
+                'http://a.tile.openstreetmap.org/${z}/${x}/${y}.png',
+                'http://b.tile.openstreetmap.org/${z}/${x}/${y}.png',
+                'http://c.tile.openstreetmap.org/${z}/${x}/${y}.png'],
+                { attribution: SyjStrings.osmAttribution});
+}
+
 function init() {
     var map = new OpenLayers.Map('map', {
                 controls: [ new OpenLayers.Control.Attribution() ],
                 theme: null}),
 
-         baseLayer = new OpenLayers.Layer.OSM("OSM", null, { attribution: SyjStrings.osmAttribution }),
+         parameters = OpenLayers.Util.getParameters(window.location.href),
+         baseLayer = null,
 
          layerOptions = {format:     OpenLayers.Format.WKT,
                         projection: WGS84,
@@ -26,14 +50,33 @@ function init() {
         viewLayer = new OpenLayers.Layer.Vector("View Layer", layerOptions),
         wkt = new OpenLayers.Format.WKT({ internalProjection: Mercator, externalProjection: WGS84 });
 
+    if (parameters.layer) {
+        switch (parameters.layer.toUpperCase()) {
+            case 'M':
+             baseLayer = mapquestLayer();
+            break;
+            case 'O':
+             baseLayer = osmLayer();
+            break;
+        }
+    }
+
+    if (!baseLayer) {
+        baseLayer = osmLayer();
+    }
+
     map.addLayers([baseLayer, viewLayer]);
     viewLayer.addFeatures([wkt.read(gInitialGeom.data)]);
     extent = viewLayer.getDataExtent();
     map.updateSize();
     map.zoomToExtent(extent);
-
+    resizeMap();
 }
 
+window.onresize = function() {
+    resizeMap();
+};
+
 if (window.addEventListener) {
     window.addEventListener("load", init, false);
 } else {