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