File: draw_on_map.js

package info (click to toggle)
cyclograph 1.7.1-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,136 kB
  • ctags: 705
  • sloc: python: 9,682; makefile: 5
file content (94 lines) | stat: -rw-r--r-- 3,240 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (C) 2011, 2012 Federico Brega
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 */

var map;
var featureLatLon;

function init() {
    map = new OpenLayers.Map('map', {displayProjection: new OpenLayers.Projection("EPSG:4326")});
    map.addControl(new OpenLayers.Control.LayerSwitcher());

    var osm = new OpenLayers.Layer.OSM();
    var cycle = new OpenLayers.Layer.OSM(
        "OpenCycleMap",
        ["http://a.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
            "http://b.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png",
            "http://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png"],
        { type: 'png', displayOutsideMaxExtent: true,
            transitionEffect: 'resize'}
    );
    var gphy = new OpenLayers.Layer.Google(
        "Google Physical",
        {type: google.maps.MapTypeId.TERRAIN}
    );
    var gmap = new OpenLayers.Layer.Google(
        "Google Streets",
        {numZoomLevels: 20}
    );
    var ghyb = new OpenLayers.Layer.Google(
        "Google Hybrid",
        {type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20}
    );
    var gsat = new OpenLayers.Layer.Google(
        "Google Satellite",
        {type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22}
    );
    var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
    renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;

    vectors = new OpenLayers.Layer.Vector(
        "Drawn",
        {renderers: renderer}
    );
    
    map.addLayers([cycle, osm, gphy, gmap, ghyb, gsat, vectors]);
    map.addControl(new OpenLayers.Control.LayerSwitcher());
    map.addControl(new OpenLayers.Control.MousePosition());

    convertCallback = function(feature) {
        featureLatLon = feature.clone();
        var geom = featureLatLon.geometry;
        geom.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
    };

    controls = {
        point: new OpenLayers.Control.DrawFeature(vectors,
                    OpenLayers.Handler.Point),
        line: new OpenLayers.Control.DrawFeature(vectors,
                    OpenLayers.Handler.Path, {'featureAdded': convertCallback}),
    };

    for(var key in controls) {
        map.addControl(controls[key]);
    }
    controls["line"].activate(); //TODO: activate through a proper function

    // Google.v3 uses EPSG:900913 
    map.setCenter(new OpenLayers.LonLat(10.2, 48.9).transform(
        new OpenLayers.Projection("EPSG:4326"),
        map.getProjectionObject()
    ), 5);
    
    for (var i = 0; i < map.layers.length; i++) {
        map.layers[i].animationEnabled = true;
    }
    
}

kmlFormat = new OpenLayers.Format.KML();
function createKml() {
    var kml = kmlFormat.write(featureLatLon);
    return kml
}