PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/mobile-base.js

https://github.com/aabt/openlayers
JavaScript | 172 lines | 154 code | 12 blank | 6 comment | 0 complexity | 944a7ff240a3237cada2c348c2303b3a MD5 | raw file
  1. // API key for http://openlayers.org. Please get your own at
  2. // http://bingmapsportal.com/ and use that instead.
  3. var apiKey = "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf";
  4. // initialize map when page ready
  5. var map;
  6. var gg = new OpenLayers.Projection("EPSG:4326");
  7. var sm = new OpenLayers.Projection("EPSG:900913");
  8. var init = function (onSelectFeatureFunction) {
  9. var vector = new OpenLayers.Layer.Vector("Vector Layer", {});
  10. var sprintersLayer = new OpenLayers.Layer.Vector("Sprinters", {
  11. styleMap: new OpenLayers.StyleMap({
  12. externalGraphic: "img/mobile-loc.png",
  13. graphicOpacity: 1.0,
  14. graphicWith: 16,
  15. graphicHeight: 26,
  16. graphicYOffset: -26
  17. })
  18. });
  19. var sprinters = getFeatures();
  20. sprintersLayer.addFeatures(sprinters);
  21. var selectControl = new OpenLayers.Control.SelectFeature(sprintersLayer, {
  22. autoActivate:true,
  23. onSelect: onSelectFeatureFunction});
  24. var geolocate = new OpenLayers.Control.Geolocate({
  25. id: 'locate-control',
  26. geolocationOptions: {
  27. enableHighAccuracy: false,
  28. maximumAge: 0,
  29. timeout: 7000
  30. }
  31. });
  32. // create map
  33. map = new OpenLayers.Map({
  34. div: "map",
  35. theme: null,
  36. projection: sm,
  37. units: "m",
  38. numZoomLevels: 18,
  39. maxResolution: 156543.0339,
  40. maxExtent: new OpenLayers.Bounds(
  41. -20037508.34, -20037508.34, 20037508.34, 20037508.34
  42. ),
  43. controls: [
  44. new OpenLayers.Control.Attribution(),
  45. new OpenLayers.Control.TouchNavigation({
  46. dragPanOptions: {
  47. enableKinetic: true
  48. }
  49. }),
  50. geolocate,
  51. selectControl
  52. ],
  53. layers: [
  54. new OpenLayers.Layer.OSM("OpenStreetMap", null, {
  55. transitionEffect: 'resize'
  56. }),
  57. new OpenLayers.Layer.Bing({
  58. key: apiKey,
  59. type: "Road",
  60. // custom metadata parameter to request the new map style - only useful
  61. // before May 1st, 2011
  62. metadataParams: {
  63. mapVersion: "v1"
  64. },
  65. name: "Bing Road",
  66. transitionEffect: 'resize'
  67. }),
  68. new OpenLayers.Layer.Bing({
  69. key: apiKey,
  70. type: "Aerial",
  71. name: "Bing Aerial",
  72. transitionEffect: 'resize'
  73. }),
  74. new OpenLayers.Layer.Bing({
  75. key: apiKey,
  76. type: "AerialWithLabels",
  77. name: "Bing Aerial + Labels",
  78. transitionEffect: 'resize'
  79. }),
  80. vector,
  81. sprintersLayer
  82. ],
  83. center: new OpenLayers.LonLat(0, 0),
  84. zoom: 1
  85. });
  86. var style = {
  87. fillOpacity: 0.1,
  88. fillColor: '#000',
  89. strokeColor: '#f00',
  90. strokeOpacity: 0.6
  91. };
  92. geolocate.events.register("locationupdated", this, function(e) {
  93. vector.removeAllFeatures();
  94. vector.addFeatures([
  95. new OpenLayers.Feature.Vector(
  96. e.point,
  97. {},
  98. {
  99. graphicName: 'cross',
  100. strokeColor: '#f00',
  101. strokeWidth: 2,
  102. fillOpacity: 0,
  103. pointRadius: 10
  104. }
  105. ),
  106. new OpenLayers.Feature.Vector(
  107. OpenLayers.Geometry.Polygon.createRegularPolygon(
  108. new OpenLayers.Geometry.Point(e.point.x, e.point.y),
  109. e.position.coords.accuracy / 2,
  110. 50,
  111. 0
  112. ),
  113. {},
  114. style
  115. )
  116. ]);
  117. map.zoomToExtent(vector.getDataExtent());
  118. });
  119. function getFeatures() {
  120. var features = {
  121. "type": "FeatureCollection",
  122. "features": [
  123. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [1332700, 7906300]},
  124. "properties": {"Name": "Igor Tihonov", "Country":"Sweden", "City":"Gothenburg"}},
  125. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [790300, 6573900]},
  126. "properties": {"Name": "Marc Jansen", "Country":"Germany", "City":"Bonn"}},
  127. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [568600, 6817300]},
  128. "properties": {"Name": "Bart van den Eijnden", "Country":"Netherlands", "City":"Utrecht"}},
  129. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-7909900, 5215100]},
  130. "properties": {"Name": "Christopher Schmidt", "Country":"United States of America", "City":"Boston"}},
  131. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-937400, 5093200]},
  132. "properties": {"Name": "Jorge Gustavo Rocha", "Country":"Portugal", "City":"Braga"}},
  133. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-355300, 7547800]},
  134. "properties": {"Name": "Jennie Fletcher ", "Country":"Scotland", "City":"Edinburgh"}},
  135. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [657068.53608487, 5712321.2472725]},
  136. "properties": {"Name": "Bruno Binet ", "Country":"France", "City":"Chambéry"}},
  137. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [667250.8958124, 5668048.6072737]},
  138. "properties": {"Name": "Eric Lemoine", "Country":"France", "City":"Theys"}},
  139. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [653518.03606319, 5721118.5122914]},
  140. "properties": {"Name": "Antoine Abt", "Country":"France", "City":"La Motte Servolex"}},
  141. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [657985.78042416, 5711862.6251028]},
  142. "properties": {"Name": "Pierre Giraud", "Country":"France", "City":"Chambéry"}},
  143. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [742941.93818208, 5861818.9477535]},
  144. "properties": {"Name": "Stéphane Brunner", "Country":"Switzerland", "City":"Paudex"}},
  145. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [736082.61064069, 5908165.4649505]},
  146. "properties": {"Name": "Frédéric Junod", "Country":"Switzerland", "City":"Montagny-près-Yverdon"}},
  147. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [771595.97057525, 5912284.7041793]},
  148. "properties": {"Name": "Cédric Moullet", "Country":"Switzerland", "City":"Payerne"}},
  149. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [744205.23922364, 5861277.319748]},
  150. "properties": {"Name": "Benoit Quartier", "Country":"Switzerland", "City":"Lutry"}},
  151. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [1717430.147101, 5954568.7127565]},
  152. "properties": {"Name": "Andreas Hocevar", "Country":"Austria", "City":"Graz"}},
  153. { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-12362007.067301,5729082.2365672]},
  154. "properties": {"Name": "Tim Schaub", "Country":"United States of America", "City":"Bozeman"}}
  155. ]
  156. };
  157. var reader = new OpenLayers.Format.GeoJSON();
  158. return reader.read(features);
  159. }
  160. };