I am using vs2010 in windows 7 OS.
I installed Tomcat-7.0.27 then i copied geoserver war file into it.
here Tomcat and geoserver is running fine(1.Tomcat: http://localhost:8085
2.Geoserver: http://localhost:8085/geoserver/index.html)
Then i created one wms layer in geoserver. its working fine.
I am calling the this wms layer in my web application.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="Maps_Google.WebForm5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="http://openlayers.org/api/theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css" type="text/css" />
<script type="text/javascript" src="http://openlayers.org/dev/OpenLayers.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
function init() {
var options = {
maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
maxResolution: "auto",
projection: new OpenLayers.Projection("EPSG:900913"),
controls: [],
units: 'm'
};
map = new OpenLayers.Map('map', options);
map.addControl(new OpenLayers.Control.LayerSwitcher());
var gsat = new OpenLayers.Layer.Google(
"Google Physical",
{ type: google.maps.MapTypeId.TERRAIN, numZoomLevels: 22 }
);
var NE_image = new OpenLayers.Layer.WMS(
"cite:vietnam_IZ_V4 - Untiled", "http://10.81.5.31:8085/geoserver/cite/wms?", { LAYERS: 'cite:vietnam_IZ_V4', transparent: true }, { isBaseLayer: false }
);
map.addLayers([gsat, NE_image]);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
var bounds = new OpenLayers.Bounds(
103.98606273474692, 8.775560097336232,
109.40715417511227, 22.48734509850342
);
map.addControl(new OpenLayers.Control.PanZoomBar({
position: new OpenLayers.Pixel(2, 15)
}));
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.Scale($('scale')));
map.addControl(new OpenLayers.Control.MousePosition({ element: $('location') }));
format = 'image/png';
map.events.register('click', map, function (e) {
document.getElementById('nodelist').innerHTML = "Loading... please wait...";
var params = {
REQUEST: "GetFeatureInfo",
EXCEPTIONS: "application/vnd.ogc.se_xml",
BBOX: map.getExtent().toBBOX(),
SERVICE: "WMS",
INFO_FORMAT: 'text/html',
QUERY_LAYERS: map.layers[1].params.LAYERS,
FEATURE_COUNT: 50,
"Layers": 'cite:vietnam_IZ_V4',
WIDTH: map.size.w,
HEIGHT: map.size.h,
format: format,
styles: map.layers[1].params.STYLES,
srs: map.layers[1].params.SRS
};
if (map.layers[1].params.VERSION == "1.3.0") {
params.version = "1.3.0";
params.j = parseInt(e.xy.x);
params.i = parseInt(e.xy.y);
} else {
params.version = "1.1.1";
params.x = parseInt(e.xy.x);
params.y = parseInt(e.xy.y);
}
if (map.layers[1].params.CQL_FILTER != null) {
params.cql_filter = map.layers[1].params.CQL_FILTER;
}
if (map.layers[1].params.FILTER != null) {
params.filter = map.layers[1].params.FILTER;
}
if (map.layers[1].params.FEATUREID) {
params.featureid = map.layers[1].params.FEATUREID;
}
OpenLayers.loadURL("http://10.81.5.31:8085/geoserver/cite/wms", params, this, setHTML, setHTML);
OpenLayers.Event.stop(e);
});
}
function setHTML(response) {
document.getElementById('nodelist').innerHTML = response.responseText;
};
</script>
</head>
<body onload="init()">
<h1 id="title">OpenLayers: Google Layer Example</h1>
<div id="map" class="smallmap" style="width: 100%; height: 500px;"></div>
<div id="nodelist">
Click on the map to get feature info
</div>
</body>
</html>
When i click on the map marker points in chrome I am getting the below Error
Error:
"XMLHttpRequest cannot load http://10.81.5.31:8085/geoserver/cite/wms?REQUEST=GetFeatureInfo&EXCEPTIONS…00&format=image%2Fpng&styles=&srs=EPSG%3A900913&version=1.1.1&x=1226&y=116. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access."
This error coming only in the chrome.
Its works fine in IE, and Its displaying the map marker information when I click on the marker.
Later searching in google I fixed it but adding in the shortcut of google chrome : --disable-web-security.
But this is not a feasible solution.
I tried adding web.config file
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
</customHeaders>
</httpProtocol>
This is also not successful.
Please give me your suggestions how do I can overcome this problem.