]> dev.renevier.net Git - syj.git/blob - public/js/syjraw.js
cf6be9c37eb8e964d3ea010be1581735d046a28c
[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 init() {
21     var map = new OpenLayers.Map('map', {
22                 controls: [ new OpenLayers.Control.Attribution() ],
23                 theme: null}),
24
25          baseLayer = new OpenLayers.Layer.OSM("OSM", null, { attribution: SyjStrings.osmAttribution }),
26
27          layerOptions = {format:     OpenLayers.Format.WKT,
28                         projection: WGS84,
29                         styleMap:   styleMap.view,
30                         attribution: SyjStrings.geomAttribution },
31
32         viewLayer = new OpenLayers.Layer.Vector("View Layer", layerOptions),
33         wkt = new OpenLayers.Format.WKT({ internalProjection: Mercator, externalProjection: WGS84 });
34
35     map.addLayers([baseLayer, viewLayer]);
36     viewLayer.addFeatures([wkt.read(gInitialGeom.data)]);
37     extent = viewLayer.getDataExtent();
38     map.updateSize();
39     map.zoomToExtent(extent);
40     resizeMap();
41 }
42
43 window.onresize = function() {
44     resizeMap();
45 };
46
47 if (window.addEventListener) {
48     window.addEventListener("load", init, false);
49 } else {
50     window.attachEvent("onload", init);
51 }