Changeset 329
- Timestamp:
- 05/24/06 14:45:50 (3 years ago)
- Files:
-
- trunk/openlayers/examples/markerss.html (modified) (4 diffs)
- trunk/openlayers/lib/OpenLayers/Control/MouseDefaults.js (modified) (3 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/Markers.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Map.js (modified) (4 diffs)
- trunk/openlayers/tests/test_Map.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/examples/markerss.html
r325 r329 9 9 } 10 10 </style> 11 <script src=" lib/OpenLayers.js"></script>11 <script src="../lib/OpenLayers.js"></script> 12 12 <script type="text/javascript"> 13 13 <!-- … … 22 22 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'} ); 23 23 24 25 map.addLayer( 26 new OpenLayers.Layer.WMS("NASA Mosaic", 27 "http://wms.jpl.nasa.gov/wms.cgi", 28 {"EXCEPTIONS" : "application/vnd.ogc.se_inimage", 29 "format" : "image/jpeg", 30 layers:"modis,global_mosaic"} 31 )); 32 24 33 map.addLayer(layer); 25 34 … … 32 41 33 42 function changer() { 34 35 43 var lon = map.getLonLatFromLayerPx(new OpenLayers.Pixel(0,0)).lon; 44 var lat = map.getLonLatFromLayerPx(new OpenLayers.Pixel(0,0)).lat; 45 var slon = map.getLonLatFromScreenPx(new OpenLayers.Pixel(0,0)).lon; 46 var slat = map.getLonLatFromScreenPx(new OpenLayers.Pixel(0,0)).lat; 47 alert("lon=" + lon + " lat=" + lat 48 + "slon=" + slon + " slat=" + slat); 36 49 } 37 50 38 51 function add() { 39 52 var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.png',new OpenLayers.Size(10,17)); 40 marker = new OpenLayers.Marker(new OpenLayers.LonLat( 180,90), icon);53 marker = new OpenLayers.Marker(new OpenLayers.LonLat(0,00), icon); 41 54 markers.addMarker(marker); 42 55 … … 59 72 <div id="map"></div> 60 73 <div style="background-color:purple" onclick="add()"> click to add popup to map</div> 61 <div style="background-color:blue" onclick="changer()"> click to modify popup's attributes</div>74 <div style="background-color:blue" onclick="changer()"> click to get lon/lat for pixel point(0,0)</div> 62 75 <div style="background-color:red" onclick="destroy()"> click to destroy the popup</div> 63 76 <div style="background-color:green" onclick="remove()"> click to remove the popup from map</div> trunk/openlayers/lib/OpenLayers/Control/MouseDefaults.js
r326 r329 20 20 */ 21 21 defaultDblClick: function (evt) { 22 var newCenter = this.map.getLonLatFrom Pixel( evt.xy );22 var newCenter = this.map.getLonLatFromScreenPx( evt.xy ); 23 23 this.map.setCenter(newCenter, this.map.zoom + 1); 24 24 }, … … 69 69 var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX, 70 70 size.h / 2 + deltaY); 71 var newCenter = this.map.getLonLatFrom Pixel( newXY );71 var newCenter = this.map.getLonLatFromScreenPx( newXY ); 72 72 this.map.setCenter(newCenter); 73 73 this.mouseDragStart = evt.xy.copyOf(); … … 81 81 defaultMouseUp: function (evt) { 82 82 if (this.zoomBox) { 83 var start = this.map.getLonLatFrom Pixel( this.mouseDragStart );84 var end = this.map.getLonLatFrom Pixel( evt.xy );83 var start = this.map.getLonLatFromScreenPx( this.mouseDragStart ); 84 var end = this.map.getLonLatFromScreenPx( evt.xy ); 85 85 var top = Math.max(start.lat, end.lat); 86 86 var bottom = Math.min(start.lat, end.lat); trunk/openlayers/lib/OpenLayers/Layer/Markers.js
r326 r329 59 59 */ 60 60 drawMarker: function(marker) { 61 var px = this.map.get PixelFromLonLat(marker.lonlat);61 var px = this.map.getLayerPxFromLonLat(marker.lonlat); 62 62 var markerImg = marker.draw(px); 63 63 if (!marker.drawn) { trunk/openlayers/lib/OpenLayers/Map.js
r328 r329 172 172 addPopup: function(popup) { 173 173 this.popups.push(popup); 174 var px = this.get PixelFromLonLat(popup.lonlat)174 var px = this.getLayerPxFromLonLat(popup.lonlat) 175 175 var popupDiv = popup.draw(px); 176 176 if (popupDiv) { … … 275 275 276 276 /** 277 * @param {OpenLayers.Pixel} point 277 * @param {OpenLayers.Pixel} layerPx 278 * 279 * @returns px translated into screen pixel coordinates 280 * @type OpenLayers.Pixel 281 */ 282 getScreenPxFromLayerPx:function(layerPx) { 283 var screenPx = layerPx.copyOf(); 284 285 screenPx.x += parseInt(this.layerContainerDiv.style.left); 286 screenPx.y += parseInt(this.layerContainerDiv.style.top); 287 288 return screenPx; 289 }, 290 291 /** 292 * @param {OpenLayers.Pixel} screenPx 293 * 294 * @returns px translated into screen pixel coordinates 295 * @type OpenLayers.Pixel 296 */ 297 getLayerPxFromScreenPx:function(screenPx) { 298 var layerPx = screenPx.copyOf(); 299 300 layerPx.x -= parseInt(this.layerContainerDiv.style.left); 301 layerPx.y -= parseInt(this.layerContainerDiv.style.top); 302 303 return layerPx; 304 }, 305 306 307 /** 308 * @param {OpenLayers.Pixel} px 278 309 * 279 310 * @return {OpenLayers.LonLat} 280 311 */ 281 getLonLatFromPixel: function (point) { 312 getLonLatFromLayerPx: function (px) { 313 //adjust for displacement of layerContainerDiv 314 px = this.getScreenPxFromLayerPx(px); 315 return this.getLonLatFromScreenPx(px); 316 }, 317 318 /** 319 * @param {OpenLayers.Pixel} screenPx 320 * 321 * @returns An OpenLayers.LonLat which is the passed-in screen 322 * OpenLayers.Pixel, translated into lon/lat given the 323 * current extent and resolution 324 * @type OpenLayers.LonLat 325 */ 326 getLonLatFromScreenPx: function (screenPx) { 282 327 var center = this.getCenter(); //map center lon/lat 283 328 var res = this.getResolution(); 284 329 var size = this.getSize(); 285 330 286 var delta_x = point.x - (size.w / 2);287 var delta_y = point.y - (size.h / 2);331 var delta_x = screenPx.x - (size.w / 2); 332 var delta_y = screenPx.y - (size.h / 2); 288 333 289 334 return new OpenLayers.LonLat(center.lon + delta_x * res , 290 335 center.lat - delta_y * res); 336 }, 337 338 /** 339 * @param {OpenLayers.LonLat} lonlat 340 * 341 * @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat, 342 * translated into layer pixels given the current extent 343 * and resolution 344 * @type OpenLayers.Pixel 345 */ 346 getLayerPxFromLonLat: function (lonlat) { 347 //adjust for displacement of layerContainerDiv 348 var px = this.getScreenPxFromLonLat(lonlat); 349 return this.getLayerPxFromScreenPx(px); 291 350 }, 292 351 … … 299 358 * @type OpenLayers.Pixel 300 359 */ 301 get PixelFromLonLat: function (lonlat) {360 getScreenPxFromLonLat: function (lonlat) { 302 361 var resolution = this.getResolution(); 303 362 var extent = this.getExtent(); … … 337 396 for (var i = 0; i < this.popups.length; i++) { 338 397 var popup = this.popups[i]; 339 var px = this.get PixelFromLonLat(popup.lonlat);398 var px = this.getLayerPxFromLonLat(popup.lonlat); 340 399 popup.moveTo(px); 341 400 } trunk/openlayers/tests/test_Map.html
r315 r329 126 126 127 127 var pixel = new OpenLayers.Pixel(50,150); 128 var lonlat = map.getLonLatFrom Pixel(pixel);129 t.ok( lonlat instanceof OpenLayers.LonLat, "getLonLatFrom Pixelreturns valid OpenLayers.LonLat" );128 var lonlat = map.getLonLatFromScreenPx(pixel); 129 t.ok( lonlat instanceof OpenLayers.LonLat, "getLonLatFromScreenPx returns valid OpenLayers.LonLat" ); 130 130 131 var newPixel = map.get PixelFromLonLat(lonlat);132 t.ok( newPixel instanceof OpenLayers.Pixel, "get PixelFromLonLat returns valid OpenLayers.Pixel" );131 var newPixel = map.getScreenPxFromLonLat(lonlat); 132 t.ok( newPixel instanceof OpenLayers.Pixel, "getScreenPxFromLonLat returns valid OpenLayers.Pixel" ); 133 133 134 134 // WARNING!!! I'm faily sure that the following test's validity
