`

Marker(mousedown)

阅读更多

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

    

    <title>My JSP 'marker_mousedown.jsp' starting page</title>

    

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">    

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

<link rel="stylesheet" href="<%=basePath%>/Script/theme/default/style.css" type="text/css">

    <link rel="stylesheet" href="<%=basePath%>/Style/style.css" type="text/css">

     <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>

<script src="<%=basePath%>/Script/lib/OpenLayers.js"></script>

<script type="text/javascript">

var map = null;

var wms_url = "http://vmap0.tiles.osgeo.org/wms/vmap0";

var wms_version = "1.3.0";

var layer_name = 'country';

 

var wms_layer = null;

var marker_layer = null;

 

var marker = null;

 

function init()

{

//创建map对象,

map = new OpenLayers.Map("map");

 var gphy = new OpenLayers.Layer.Google("Google Physical",{

 type: G_PHYSICAL_MAP

 });

wms_layer = new OpenLayers.Layer.WMS("OpenLayers WMS",

 wms_url,

 {layers: layer_name},

 {singleTile: true});

 

marker_layer = new OpenLayers.Layer.Markers("markers");

 

// 添加图层

map.addLayers([gphy,wms_layer, marker_layer]);        

map.addControl( new OpenLayers.Control.LayerSwitcher() );

map.addControl( new OpenLayers.Control.MousePosition());

//---------------------------------------------------------------//

//注册鼠标事件

// map.events.register('mousedown', map, onMakerMouseDown);

 

// 放大到全屏

map.zoomToMaxExtent();

}

 

function addMarker(x, y, opacity) 

{

 

marker = new OpenLayers.Marker(new OpenLayers.LonLat(x, y));

//透明度

marker.setOpacity(opacity);

//注册鼠标事件

marker.events.register('mousedown', marker, onMakerMouseDown);

marker_layer.addMarker(marker);

}

 

/*

 * 鼠标点击Marker的响应函数

 */

function onMakerMouseDown(evt)

{

//alert(evt.x);

alert(marker.CLASS_NAME);

OpenLayers.Event.stop(evt);

}

 

function onAddMarker()

{

var x = document.getElementById("X").value;

var y = document.getElementById("Y").value;

var opacity = document.getElementById("opacity").value;

 

addMarker(x, y, opacity);

}

</script>

  </head>

<BODY onload="init()">

    <div>

      <div>X<input type="text" id="X" value="0">

           Y<input type="text" id="Y" value="0">

           透明度<input type="text" id="opacity" value="255">

           <input type="button" value="Add Marker" onClick="onAddMarker();"></div>

      <div id="map" class="smallmap"></div>

    </div>

 </BODY>

</html>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics