- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如何获取使用绘图工具输入圆形、多边形和矩形作为图像设计的gmap 的url? 需要通过设计获取此自定义 map 并生成图像...为了找到 url,我创建了一个静态 map 并制作了图像,代码如下
this.showImage = function () {
var url = "http://maps.googleapis.com/maps/api/staticmap?center=" + map.center + "&zoom=" + map.zoom + "&size=800x600&sensor=false"
var div = document.getElementById('mapImg');
var img = document.createElement('img');
img.src = url;
div.appendChild(img);}
最佳答案
需要做的是将各种对象从 DrawingManager 转换为可以在 Static Map 上呈现的路径(或标记)。 .
下面是从 DrawingManager 到静态 map 工具的开始。它使用可以调整的圆(64 点)近似值。它是一个概念证明,而不是一个完整的应用程序。
注意:静态 map 有最大 URL 大小,如果添加的对象太多,它将失败。此代码不会尝试检查长度。
代码片段:
function createStaticMap() {
var fillC, strokeC, weight, path;
var staticMap = "https://maps.googleapis.com/maps/api/staticmap?size=512x512&maptype=roadmap";
for (var i = 0; i < overlays.length; i++) {
if (overlays[i].type == google.maps.drawing.OverlayType.POLYGON || overlays[i].type == google.maps.drawing.OverlayType.POLYLINE) {
path = encodeURIComponent(google.maps.geometry.encoding.encodePath(overlays[i].overlay.getPath()));
if (overlays[i].type == google.maps.drawing.OverlayType.POLYGON) {
fillC = overlays[i].overlay.get("fillColor");
strokeC = overlays[i].overlay.get("strokeColor");
weight = overlays[i].overlay.get("strokeWeight");
staticMap += "&path=";
if (typeof fillC != "undefined") staticMap += "fillcolor:" + fillC.replace(/#/, "0x");
if (typeof weight != "undefined") staticMap += "%7Cweight:" + weight;
else staticMap += "%7Cweight:0";
if (typeof strokeC != "undefined") staticMap += "%7Ccolor:" + strokeC.replace(/#/, "0x");
staticMap += "%7Cenc:" + path;
} else if (overlays[i].type == google.maps.drawing.OverlayType.POLYLINE) {
fillC = overlays[i].overlay.get("fillColor");
strokeC = overlays[i].overlay.get("strokeColor");
weight = overlays[i].overlay.get("strokeWeight");
staticMap += "&path=";
if (typeof weight != "undefined") staticMap += "weight:" + weight;
else staticMap += "weight:2";
if (typeof strokeC != "undefined") staticMap += "%7Ccolor:" + strokeC.replace(/#/, "0x");
staticMap += "%7Cenc:" + path;
}
} else if (overlays[i].type == google.maps.drawing.OverlayType.MARKER) {
staticMap += "&markers=color:blue|" + overlays[i].overlay.getPosition().toUrlValue(6);
} else if (overlays[i].type == google.maps.drawing.OverlayType.RECTANGLE) {
path = [];
var north = overlays[i].overlay.getBounds().getNorthEast().lat();
var east = overlays[i].overlay.getBounds().getNorthEast().lng();
var south = overlays[i].overlay.getBounds().getSouthWest().lat();
var west = overlays[i].overlay.getBounds().getSouthWest().lng();
path.push(new google.maps.LatLng(north, east));
path.push(new google.maps.LatLng(south, east));
path.push(new google.maps.LatLng(south, west));
path.push(new google.maps.LatLng(north, west));
path.push(new google.maps.LatLng(north, east));
path = encodeURIComponent(google.maps.geometry.encoding.encodePath(path));
fillC = overlays[i].overlay.get("fillColor");
strokeC = overlays[i].overlay.get("strokeColor");
weight = overlays[i].overlay.get("strokeWeight");
staticMap += "&path=";
if (typeof fillC != "undefined") staticMap += "fillcolor:" + fillC.replace(/#/, "0x");
else staticMap += "fillcolor:blue";
if (typeof weight != "undefined") staticMap += "%7Cweight:" + weight;
if (typeof strokeC != "undefined") staticMap += "%7Ccolor:" + strokeC.replace(/#/, "0x");
staticMap += "%7Cenc:" + path;
} else if (overlays[i].type == google.maps.drawing.OverlayType.CIRCLE) {
path = drawCircle(overlays[i].overlay.getCenter(),
overlays[i].overlay.getRadius(), 1);
path = encodeURIComponent(google.maps.geometry.encoding.encodePath(path));
fillC = overlays[i].overlay.get("fillColor");
strokeC = overlays[i].overlay.get("strokeColor");
weight = overlays[i].overlay.get("strokeWeight");
staticMap += "&path=";
if (typeof fillC != "undefined") staticMap += "fillcolor:" + fillC.replace(/#/, "0x");
else staticMap += "fillcolor:blue";
if (typeof weight != "undefined") staticMap += "%7Cweight:" + weight;
if (typeof strokeC != "undefined") staticMap += "%7Ccolor:" + strokeC.replace(/#/, "0x");
staticMap += "%7Cenc:" + path;
}
}
document.getElementById('staticMap').innerHTML = staticMap;
document.getElementById('imageholder').innerHTML = "<img src='" + staticMap + "' alt='static map' / > ";
document.getElementById('urllen').innerHTML = "URL length =" + staticMap.length + " characters";
}
var geocoder;
var map;
var overlays = [];
var drawingManager;
var selectedShape;
var colors = ['#1E90FF', '#FF1493', '#32CD32', '#FF8C00', '#4B0082'];
var selectedColor;
var colorButtons = {};
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
center: new google.maps.LatLng(-27.37777, -51.592762),
zoom: 16
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
google.maps.event.addListener(map, 'click', function(evt) {
document.getElementById('info').innerHTML = evt.latLng.toUrlValue(6);
});
var polyOptions = {
strokeWeight: 0,
fillOpacity: 0.45,
editable: true
};
drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.MARKER,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
google.maps.drawing.OverlayType.MARKER,
google.maps.drawing.OverlayType.CIRCLE,
google.maps.drawing.OverlayType.POLYGON,
google.maps.drawing.OverlayType.POLYLINE,
google.maps.drawing.OverlayType.RECTANGLE
]
},
markerOptions: {
icon: 'http://maps.google.com/mapfiles/ms/micons/blue.png',
draggable: true
},
polylineOptions: {
editable: true
},
rectangleOptions: polyOptions,
circleOptions: polyOptions,
polygonOptions: polyOptions
});
google.maps.event.addListener(drawingManager, 'overlaycomplete', function(ovrly) {
if (ovrly.type != google.maps.drawing.OverlayType.MARKER) {
// Switch back to non-drawing mode after drawing a shape.
drawingManager.setDrawingMode(null);
// Add an event listener that selects the newly-drawn shape when the user
// mouses down on it.
var newShape = ovrly.overlay;
newShape.type = ovrly.type;
google.maps.event.addListener(newShape, 'click', function() {
setSelection(newShape);
});
setSelection(newShape);
}
overlays.push(ovrly);
});
drawingManager.setMap(map);
// Clear the current selection when the drawing mode is changed, or when the
// map is clicked.
google.maps.event.addListener(drawingManager, 'drawingmode_changed', clearSelection);
google.maps.event.addListener(map, 'click', clearSelection);
google.maps.event.addDomListener(document.getElementById('delete-button'), 'click', deleteSelectedShape);
buildColorPalette();
}
google.maps.event.addDomListener(window, 'load', initialize);
function drawCircle(point, radius, dir) {
var d2r = Math.PI / 180; // degrees to radians
var r2d = 180 / Math.PI; // radians to degrees
var earthsradius = 6371.0 * 1000.0; // meters; 6371.0 is the radius of the earth in km
var points = 64;
var start, end;
// find the raidus in lat/lon
var rlat = (radius / earthsradius) * r2d;
var rlng = rlat / Math.cos(point.lat() * d2r);
var extp = [];
if (dir == 1) {
start = 0;
end = points + 1;
} // one extra here makes sure we connect the
else {
start = points + 1;
end = 0;
}
for (var i = start;
(dir == 1 ? i < end : i > end); i = i + dir) {
var theta = Math.PI * (i / (points / 2));
ey = point.lng() + (rlng * Math.cos(theta)); // center a + radius x * cos(theta)
ex = point.lat() + (rlat * Math.sin(theta)); // center b + radius y * sin(theta)
extp.push(new google.maps.LatLng(ex, ey));
}
// alert(extp.length);
return extp;
}
function clearSelection() {
if (selectedShape) {
selectedShape.setEditable(false);
selectedShape = null;
}
}
function setSelection(shape) {
clearSelection();
selectedShape = shape;
shape.setEditable(true);
selectColor(shape.get('fillColor') || shape.get('strokeColor'));
}
function deleteSelectedShape() {
if (selectedShape) {
selectedShape.setMap(null);
}
}
function selectColor(color) {
selectedColor = color;
for (var i = 0; i < colors.length; ++i) {
var currColor = colors[i];
colorButtons[currColor].style.border = currColor == color ? '2px solid #789' : '2px solid #fff';
}
// Retrieves the current options from the drawing manager and replaces the
// stroke or fill color as appropriate.
var polylineOptions = drawingManager.get('polylineOptions');
polylineOptions.strokeColor = color;
drawingManager.set('polylineOptions', polylineOptions);
var rectangleOptions = drawingManager.get('rectangleOptions');
rectangleOptions.fillColor = color;
drawingManager.set('rectangleOptions', rectangleOptions);
var circleOptions = drawingManager.get('circleOptions');
circleOptions.fillColor = color;
drawingManager.set('circleOptions', circleOptions);
var polygonOptions = drawingManager.get('polygonOptions');
polygonOptions.fillColor = color;
drawingManager.set('polygonOptions', polygonOptions);
}
function setSelectedShapeColor(color) {
if (selectedShape) {
if (selectedShape.type == google.maps.drawing.OverlayType.POLYLINE) {
selectedShape.set('strokeColor', color);
} else {
selectedShape.set('fillColor', color);
}
}
}
function makeColorButton(color) {
var button = document.createElement('span');
button.className = 'color-button';
button.style.backgroundColor = color;
google.maps.event.addDomListener(button, 'click', function() {
selectColor(color);
setSelectedShapeColor(color);
});
return button;
}
function buildColorPalette() {
var colorPalette = document.getElementById('color-palette');
for (var i = 0; i < colors.length; ++i) {
var currColor = colors[i];
var colorButton = makeColorButton(currColor);
colorPalette.appendChild(colorButton);
colorButtons[currColor] = colorButton;
}
selectColor(colors[0]);
}
html,
body,
#map-canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
#panel {
width: 200px;
font-family: Arial, sans-serif;
font-size: 13px;
float: right;
margin: 10px;
}
#color-palette {
clear: both;
}
.color-button {
width: 14px;
height: 14px;
font-size: 0;
margin: 2px;
float: left;
cursor: pointer;
}
#delete-button {
margin-top: 5px;
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=drawing&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<div id="imageholder"></div>
<div id="urllen"></div>
<div id="info"></div>
<div id="panel">
<div id="color-palette"></div>
<div>
<button id="delete-button">Delete Selected Shape</button>
</div>
</div>
<input type="button" value="create Static Map" onclick="createStaticMap()" />
<div id="map-canvas" style="border: 2px solid #3872ac;"></div>
<div id="staticMap"></div>
关于javascript - GMap 绘图工具,以图像 jpeg [静态 map URL],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31277220/
我正在尝试编写一个函数来制作绘图并将其自动保存到文件中。 我努力用它来动态地做的技巧[plotname=varname & filename=varname &], 并使其与从循环中调用它兼容。 #
有人可以帮助我如何在绘图条形图中添加“下拉”菜单。 我在以下链接 ( https://plot.ly/python/v3/dropdowns/ ) 上找到了一些信息,但我正在努力调整代码,因此下拉选项
我不确切知道如何表达这一点,但我本质上希望根据其他数据之前的列值将数据分组为 Excel 图的系列。例如: size weight apple 3 35 orange 4
我正在为出版物创建图表并希望它们具有相同的字体大小。 当我用多图创建图形时,字体大小会减小,即使我没有更改tiff() 分辨率或pointsize 参数。我根据最终适合的地 block 数量增加了图形
我用 glm::perspective(80.0f, 4.0f/3.0f, 1.0f, 120.0f);并乘以 glm::mat4 view = glm::lookAt( glm::vec3(
我在 Shiny UI 中有一个情节。如果我更改任何输入参数并且通过 react 性图将会改变。但是让我们考虑以下情况:- Shiny UI 中的绘图可以说股票的日内价格变动。为此,您查询一些实时数据
我对 R 有点陌生。我在以下两个线程中跟踪并实现了结果: http://tolstoy.newcastle.edu.au/R/e17/help/12/03/7984.html http://lukem
我想在 WPF 控件中使用 GDI+ 绘图。 最佳答案 有多种方法可以做到这一点,最简单的方法是锁定您使用 GDI 操作的位图,获取像素缓冲区(从锁定中获取的 BitmapData 中的 Scan0
如何在以下取自其网站的绘图示例中隐藏颜色条? df % layout(title = '2014 Global GDPSource:CIA World Factbook',
我有两列数据,X 和 Y,每个条目在两个向量的小数点后都有 4 位数据。 当我使用 plot(x,y) 绘制简单图时,轴上显示的数据精确到小数点后两位。如何在两个轴上将其更改为小数点后 4 位精度?
我目前正在使用 Canvas 处理 JavaFX-Drawing-Application。在 GraphicsContext 的帮助下,我使用 beginPath() 和 lineTo() 方法绘制线
如果这个问题已经得到解答,但我无法找到我需要的东西,我提前道歉。我想从名为 data1.dat、data2.dat 的文件中绘制一些结果......我设法通过循环导入数据,但我无法使用循环绘制结果。仅
我的 pandas 数据框中有一个功能,可以(可能)具有多个级别。我可以使用以下方法获得独特的级别: reasons = df["Reason"].unique() 我可以通过执行以下操作在单个图表上
我在 Ubuntu 14 和 Windows 7(均为 64 位)中用 Python 绘制结果时遇到问题。作为一个简单的比较,我做了: from tvb.simulator.lab import *
以下代码相当简单 - 它用随机选择的像素填充设计表面 - 没什么特别的(暂时忽略第二种方法中的 XXXXXXX)。 private void PaintBackground() { Rando
我正在尝试制作一个绘制函数图形的 swing 应用程序(现在很简单,例如 x+2)但我在根据屏幕坐标制作我的点的数学坐标时遇到问题。我希望它在我的图表中简单地画一条从 P1(0,1) 到 P2(1,2
编辑 4:问题的新格式 背景:我有一个扩展 JFrame 的类 Window,在 JFrame 中我有一个 Canvas 。我向 Canvas 添加自定义对象。这个对象的唯一目的(为了争论)是在 Ca
我需要为即将到来的锦标赛标记阶梯,但我找不到任何方法来语义标记它。到目前为止我看到的唯一方法是 mark it up as a table ,我想不惜一切代价避免这种情况。 有什么想法吗? 最佳答案
我目前正在为一个小型 uC 项目编写 UI。在计算垂直线的位置时遇到一些问题。这个想法是将红线沿 x 轴移动到矩形的末端。 使用无限旋转编码器递增的值,范围为 0 到 800,增量为 1。矩形的左侧是
我正在尝试绘制光分布图。我想准确地执行此问题的第一步所要求的:Statistical analysis on Bell shaped (Gaussian) curve . 现在我有一组值。我希望数组元
我是一名优秀的程序员,十分优秀!