]> dev.renevier.net Git - syj.git/blob - public/js/syjraw.js
add mapquest layer
[syj.git] / public / js / syjraw.js
1 var WGS84 = new OpenLayers.Projection("EPSG:4326");
2 var Mercator = new OpenLayers.Projection("EPSG:900913");
3
4 var styleMap = {
5     view: new OpenLayers.StyleMap({
6         "default": new OpenLayers.Style({
7             strokeColor: "blue",
8             strokeWidth: 5,
9             strokeOpacity: 0.7
10         })
11     })
12 };
13
14 function resizeMap() {
15     var map = document.getElementById('map');
16     map.style.width = map.offsetWidth.toString() + 'px';
17     map.style.height = map.offsetHeight.toString() + 'px';
18 }
19
20 function mapquestLayer() {
21       return new OpenLayers.Layer.OSM("Mapquest", [
22                 'http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png',
23                 'http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png',
24                 'http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png',
25                 'http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.png'],
26                     { attribution: SyjStrings.mapquestAttribution});
27 }
28
29 function osmLayer() {
30     return new OpenLayers.Layer.OSM("OSM", [
31                 'http://a.tile.openstreetmap.org/${z}/${x}/${y}.png',
32                 'http://b.tile.openstreetmap.org/${z}/${x}/${y}.png',
33                 'http://c.tile.openstreetmap.org/${z}/${x}/${y}.png'],
34                 { attribution: SyjStrings.osmAttribution});
35 }
36
37 function init() {
38     var map = new OpenLayers.Map('map', {
39                 controls: [ new OpenLayers.Control.Attribution() ],
40                 theme: null}),
41
42          parameters = OpenLayers.Util.getParameters(window.location.href),
43          baseLayer = null,
44
45          layerOptions = {format:     OpenLayers.Format.WKT,
46                         projection: WGS84,
47                         styleMap:   styleMap.view,
48                         attribution: SyjStrings.geomAttribution },
49
50         viewLayer = new OpenLayers.Layer.Vector("View Layer", layerOptions),
51         wkt = new OpenLayers.Format.WKT({ internalProjection: Mercator, externalProjection: WGS84 });
52
53     if (parameters.layer) {
54         switch (parameters.layer.toUpperCase()) {
55             case 'M':
56              baseLayer = mapquestLayer();
57             break;
58             case 'O':
59              baseLayer = osmLayer();
60             break;
61         }
62     }
63
64     if (!baseLayer) {
65         baseLayer = osmLayer();
66     }
67
68     map.addLayers([baseLayer, viewLayer]);
69     viewLayer.addFeatures([wkt.read(gInitialGeom.data)]);
70     extent = viewLayer.getDataExtent();
71     map.updateSize();
72     map.zoomToExtent(extent);
73     resizeMap();
74 }
75
76 window.onresize = function() {
77     resizeMap();
78 };
79
80 if (window.addEventListener) {
81     window.addEventListener("load", init, false);
82 } else {
83     window.attachEvent("onload", init);
84 }