]> dev.renevier.net Git - syj.git/blobdiff - public/js/syjraw.js
add mapquest layer back
[syj.git] / public / js / syjraw.js
index cf6be9c37eb8e964d3ea010be1581735d046a28c..59b3f5c4a876eee75c5ef794ac3862827758e6f7 100644 (file)
@@ -1,3 +1,8 @@
+/*  This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
+    and is published under the AGPL license. */
+
+"use strict";
+
 var WGS84 = new OpenLayers.Projection("EPSG:4326");
 var Mercator = new OpenLayers.Projection("EPSG:900913");
 
@@ -17,12 +22,33 @@ function resizeMap() {
     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 mapnikLayer() {
+    return new OpenLayers.Layer.OSM("Mapnik", [
+                '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() ],
+                controls: [
+                    new OpenLayers.Control.Navigation(),
+                    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,
@@ -32,9 +58,24 @@ 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 'Q':
+             baseLayer = mapquestLayer();
+            break;
+            case 'M':
+             baseLayer = mapnikLayer();
+            break;
+        }
+    }
+
+    if (!baseLayer) {
+        baseLayer = mapnikLayer();
+    }
+
     map.addLayers([baseLayer, viewLayer]);
     viewLayer.addFeatures([wkt.read(gInitialGeom.data)]);
-    extent = viewLayer.getDataExtent();
+    var extent = viewLayer.getDataExtent();
     map.updateSize();
     map.zoomToExtent(extent);
     resizeMap();