我对这张openlayers地图完全感到困惑.即使有很多例子和wiki,我也找不到如何重用它.我的意思是我想通过管理员显示我的城市地图,管理员可以添加点和位置,它应该显示在前端.请帮我怎么做?
我正在尝试向OpenLayers地图添加一个按钮,该按钮应该在单击时调用JS函数.我设法让它看起来像我想要的,但触发功能不起作用.
如果我有Control.Navigation存在,单击按钮似乎开始拖动事件,我可以通过单击该按钮来拖动地图.但即使我删除所有其他控件,按钮的触发器处理程序也不会被调用.
我也尝试添加"autoActivate"参数(由于某些原因,它不会使控件自动激活),我已经尝试在添加它之后为按钮调用activate()函数,这似乎切换了控件的"活动"属性,但它仍然不响应点击.
有人可以指出我正确的方向,或者发布一个有效的例子吗?我的非工作示例如下.
谢谢,贾尼斯
<html>
<head>
<title>OpenLayers.Control.Button</title>
<style text="text/css">
.olControlButton {
position: absolute;
top: 0;
right: 0;
background: red;
width: 22px;
height: 22px;
}
</style>
<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map;
var panel;
function buttonClicked()
{
alert ('Button clicked.');
}
function init()
{
map = new OpenLayers.Map ('map', {controls: [/*new OpenLayers.Control.Navigation()*/]});
map.addLayer (new OpenLayers.Layer.WMS ("OpenLayers WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'}));
map.zoomToMaxExtent();
panel = new OpenLayers.Control.Panel();
map.addControl (panel);
panel.addControls ([new OpenLayers.Control.Button ({autoActivate: true, displayClass: 'olControlButton', trigger: buttonClicked, title: 'Button is …Run Code Online (Sandbox Code Playgroud) 我在PHP中接收POST请求时遇到问题.我正在使用JavaScript将数据发送到带有POST请求的PHP页面.JavaScript来自OpenLayers.js,发送请求的部分如下所示:
var postrequest = OpenLayers.Request.POST({
url: "http://localhost/index.php",
data: "success",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
Run Code Online (Sandbox Code Playgroud)
在PHP中,我正在使用此代码来查看,我得到了什么:
<?php
print_r($_POST);
?>
Run Code Online (Sandbox Code Playgroud)
这是发生的事情:
所以发送和接收数据,但我的PHP代码不知道它,或者我没有使用正确的PHP函数.
任何建议,在哪里寻找,以及尝试什么?
我在我的项目中使用GWT-OpenLayers,我在转换坐标方面遇到了问题.我知道如何为单点做到这一点,transform(from,to)但我可以在不申请每一点的情况下这样做吗?现在我正在解析KLM数据以获取功能列表,我将它们添加到新的矢量中
我试图从已发布的ArcGIS地图服务中显示WMS图层,而我得到的只是粉红色图块.任何人都可以帮我纠正我的代码有什么问题吗?当我平移到美国时,我得到的只是"破碎的图像粉红色瓷砖"......没有任何WMS图层出现.
<html>
<head>
<title>Karta</title>
<link rel="stylesheet" href="openlayers/theme/default/style.css" type="text/css">
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
function inicializacija(){
var options = {
projection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
numZoomLevels: 18,
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
};
var map = new OpenLayers.Map("map-id", options);
//var osm = new OpenLayers.Layer.OSM("Open Street Map");
//var wms = new OpenLayers.Layer.MapServer( "World Map", "http://localhost/cgi-bin/mapserv.exe", {layers: 'countries',map: '/ms4w/Apache/htdocs/MapFile06_wms.map', srs: 'EPSG:4326'} );
//map.addLayers([osm,wms]);
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer?request=GetCapabilities&service=WMS", {layers: "States"} );
map.addLayer(layer);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
map.zoomToExtent(new OpenLayers.Bounds(1490000, 5600000,1850000, 5900000));
}
</script> …Run Code Online (Sandbox Code Playgroud) 我有一个地图,当前捕获了双击事件并触发了一些代码以在地图上设置航路点,因此效果很好。
我真正想做的是检测平板电脑/移动设备用户的长按,因为我认为双击方法(在ipad上可以正常工作)不如使用鼠标指针精确。我认为我必须以某种方式绑定到onmousedown / onmouseup并设置一个计时器/阈值,但是我正在努力使这种工作正常进行。
我希望我的开放图层地图适合整个屏幕.我希望用户能够在里面导航,缩放和拖动它.
这是一个小提琴:http://jsfiddle.net/mhicauber/t8K4p/1/
我的问题是我不明白我在制作地图时给出的一些价值观:
mapLayer = new OpenLayers.Layer.Image(
'My map',
'http://tchanca.com/private/Masse1080.jpg',
OpenLayers.Bounds.fromString("-160,-90.0,160,90.0"), new OpenLayers.Size(screenSize.width, screenSize.height), {
maxExtent: OpenLayers.Bounds.fromString("-160,-90.0,160,90.0")
});
Run Code Online (Sandbox Code Playgroud)
使用这些值,用户可以将地图的一部分拖出屏幕.如果我将maxExtent值更改为0,0,0,0,那么,map将包含在屏幕中,并且不能拖到外面但是只要我放大,我就无法拖动地图.
有什么-160,-90.0,160,90.0价值可以参考?我应该用什么代码:
非常感谢你.请原谅我对制图学缺乏了解,我对这个问题很不错...
"OpenLayers库提供了一个JavaScript API,可以很容易地将各种来源的地图合并到您的网页或应用程序中." 但是,通过扫描文档,各种来源似乎只包括基于网络的地球地图提供者.
是否可以使用OpenLayers在本地存储的底图上显示功能,例如海图(例如http://www.charts.noaa.gov/InteractiveCatalog/nrnc.shtml?rnc=12280)或任意(非地球)光栅图像与人工笛卡尔坐标?
- 编辑 -
以下页面显示了本地存储的图像,与文档说明图像必须可通过Web访问相反.但是,有没有办法使用多个图像文件作为瓷砖?而不是单个文件?
<html>
<head>
<title>OpenLayers Example</title>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
</head>
<body>
<div style="width:640px; height:480px; border:3px solid" id="map"></div>
<script defer="defer" type="text/javascript">
var options = {
maxResolution: 10,
units: 'm',
resolutions: [10, 5, 2, 1, .5],
};
var map = new OpenLayers.Map('map', options);
var extent = new OpenLayers.Bounds(-4824, -3294, 4824, 3294);
var size = new OpenLayers.Size(4824, 3294);
var img = new OpenLayers.Layer.Image( "Basemap",
"maps/map0.jpg", extent, size, {layers: 'basic'} );
map.addLayer(img);
map.zoomToMaxExtent();
</script>
</body> …Run Code Online (Sandbox Code Playgroud) 我试图解决下一个错误,但没有成功.
我有以下jQuery和HTML5代码:
<script language="javascript" type="text/javascript">
function doExportMap() {
map.once('postcompose', function(event) {
var canvas = event.context.canvas;
var exportBMPElement = document.createElement('a');
exportBMPElement.download = 'Mapa.bmp';
exportBMPElement.href = canvas.toDataURL('image/bmp');
document.body.appendChild(exportBMPElement);
exportBMPElement.click();
document.body.removeChild(exportBMPElement);
});
map.renderSync();
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但现在,我收到以下错误:
SecurityError: The operation is insecure.
exportBMPElement.href = canvas.toDataURL('image/bmp');
Run Code Online (Sandbox Code Playgroud)
怎么了?有任何想法吗?
有趣的是,我没有从外部源加载图像.该图像来自localhost
在Openlayers中,可以根据缩放级别打开或关闭某些功能.尽管查看了文档,我还没有在OpenLayers 3中找到相同的功能.有谁知道如何做到这一点?这是我放在地图上的功能ol.style.Text,只有在用户放大到特定缩放级别后才能显示.
var geoJsonObj = {
'type': 'Feature',
'geometry': JSON.parse(response.FieldList[key].Shape)
}
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geoJsonObj)
});
Fields[Field.FieldID] = new ol.layer.Vector({
projection: 'EPSG:4269',
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'yellow',
width: 1
}),
fill: new ol.style.Fill({
color: rcisWebMapUtilities.convertHex(response.FieldList[key].Shade, '0.5')
}),
text: new ol.style.Text({
textAlign: 'Center',
text: response.FieldList[key].Acres,
scale: 1
})
})
});
Run Code Online (Sandbox Code Playgroud) openlayers ×10
javascript ×5
jquery ×2
openlayers-3 ×2
arcgis ×1
button ×1
click ×1
gwt ×1
html5 ×1
php ×1
post ×1
triggers ×1
wms ×1