- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道它已经在这里得到回答: google maps drag and drop objects into google maps from outside the Map ,但这并不完全是我所需要的。
我有一个带有购物卡的“Pokemon-Shop”网站。
当用户结账时, 我想让他们将项目拖到谷歌地图中,然后弹出放置位置。
我还有另一个问题:
每个掉落物都需要保存在对象中,并包含元素详细信息和掉落位置,并且 map 上的每个元素都应该有返 repo 物卡的选项。
可能吗?
最佳答案
这是一个好的开始。拖入和拖出 map 的效果非常好。
添加您的 API key
<style>
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
html, body, ul, li {
padding: 0;
margin: 0;
list-style: none;
}
#dropzone {
width: 10%;
height: 500px;
}
#map {
height: 500px;
width: 85%;
float: right;
}
#dropzone li {
height: 120px;
border: 1px solid #666666;
}
#dropzone li img {
height: 64px;
}
#dropzone .message {
color: #ff0000;
font: +1;
}
</style>
<div id="map" style=""></div>
<ul id="dropzone">
</ul>
<p>You can drag the icons inside the map, and you can drag the back out by dragging them to the left of the map</p>
<input id="dragged"><br>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?key=YOUR_KEY&libraries=geometry"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script>
<script>
var iconWidth = 64;
var iconHeight = 64;
var pokemonData = [
{
id: '001',
name: 'Bulbasaur',
icon: 'http://www.poke-amph.com/frlg/sprites/large/002.png',
},
{
id: '002',
name: 'Ivysaur',
icon: 'http://cdn.bulbagarden.net/upload/b/b0/Spr_3r_002.png',
},
{
id: '003',
name: 'Pikachu',
icon: 'http://pldh.net/media/pokemon/gen3/emerald/025.png',
},
{
id: '004',
name: 'Charmander',
icon: 'http://cdn.bulbagarden.net/upload/e/e9/Spr_3f_004.png',
}];
var map;
var overlay; // @see http://stackoverflow.com/questions/5510972/google-maps-drag-and-drop-objects-into-google-maps-from-outside-the-map
// when the draggable image is dragged into the map.
// this is where you want to handle transaction prices ...
function dragIn(e, icon, index) {
var x = e.pageX - $('#map').offset().left;
var y = e.pageY;
if(x > 0) {
// the image is inside the position of the map
// skip doubles
if(pokemonData[index].marker) { // if you allow multiple of the same icons, remove this
return true;
}
var point=new google.maps.Point(x, y);
var position = overlay.getProjection().fromContainerPixelToLatLng(point);
// add position to the object
pokemonData[index].mapPosition = [position.lat(), position.lng()];
generateMarkers([pokemonData[index]]);
// reset icon position. Feel free to hilight , or hide something ...
$(icon).attr('style', 'position: relative; left: 0; top: 0;');
$('#dropzone li').eq(index).find('.message').html('on map: ' + position.lat().toFixed(6) +','+ position.lng().toFixed(6));
// TODO: add extra stuff here
}
}
// when the draggable marker is dragged out of the map.
// this is where you want to handle transaction prices ...
function dragOut(e, marker, index) {
map.setOptions({draggable: true});
// remove the marker from the map
marker.setMap(null);
pokemonData[index].marker = null;
// extra display things
var content = '<img src="'+ pokemonData[index].icon +'"/><br/>' + pokemonData[index].name;
$('#dropzone li').eq(index).find('.message').html('marker taken off map');
// TODO: add extra stuff here
}
function updateMarkerPosition(e, marker) {
var index = pokemonData.itemIndex('marker', marker);
var position = e.latLng;
// update position
$('#dropzone li').eq(index).find('.message').html('on map: ' + position.lat().toFixed(6) +','+ position.lng().toFixed(6));
}
function generatePageMarkers(data) {
for (var i in data) {
if(data[i].id) {
var content = '<li><img data-id="'+ data[i].id +'" class="dragicon" src="'+ data[i].icon +'"/><br/><span class="name">' + data[i].name + '</span><div class="message"></div></li>';
$('#dropzone').append(content);
}
}
$('.dragicon').draggable({
stop: function(e, ui) {
var index = pokemonData.itemIndex('id', $(this).data('id'));
dragIn(e, this, index);
}
});
}
function generateMarkers(data) {
// generate the markers
for (var i in data) {
if(!data[i].id) {
break;
}
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data[i].mapPosition[0], data[i].mapPosition[1]),
map: map,
draggable: true,
//icon: data[i].icon,
icon: {
url: data[i].icon,
size: google.maps.Size(iconWidth, iconHeight),
target: google.maps.Point(iconWidth/2, iconHeight/2),
origin: google.maps.Point(iconWidth/2, iconHeight/2)
} ,
title: data[i].name
});
google.maps.event.addListener(marker, 'dragend', function(e) {
map.setOptions({draggable: true});
updateMarkerPosition(e, this);
})
google.maps.event.addListener(marker, 'drag', function(e) {
map.setOptions({draggable: false});
var pixelPosition = getPixelPosition(this);
//var index = markers.indexOf(this);
var index = pokemonData.itemIndex('marker', this);
//if (pixelPosition.right <= 60) {// Get the marker out of the map
if (pixelPosition.x <= 10) {// Get the marker out of the map
dragOut(e, this, index);
}
//document.getElementById("dragged").value = 'x: ' + pixelPosition.x +' - right:'+ pixelPosition.right;
})
// store the variable in the array
// markers.push(marker);
data[i].marker = marker;
}
}
Array.prototype.itemIndex = function(key, item) {
for (i = 0; i < this.length; i++) {
if(this[i][key] == item) {
return i;
}
}
return -1;
};
function initialize() {
map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(50.5, 4.5),
zoom: 7,
mapTypeId: 'roadmap'
});
overlay = new google.maps.OverlayView();
overlay.draw = function() {};
overlay.setMap(map);
//generateMarkers(pokemonData);
generatePageMarkers(pokemonData);
}
/**
* returns how many pixels the marker is from the map
* @see https://gist.github.com/keannan5390/3996774 (adapted by me)
*/
function getPixelPosition (marker) {
var scale = Math.pow(2, map.getZoom());
var nw = new google.maps.LatLng(
map.getBounds().getNorthEast().lat(),
map.getBounds().getSouthWest().lng()
);
var worldCoordinateNW = map.getProjection().fromLatLngToPoint(nw);
var worldCoordinate = map.getProjection().fromLatLngToPoint(marker.getPosition());
var pixelOffset = new google.maps.Point(
Math.floor((worldCoordinate.x - worldCoordinateNW.x) * scale),
Math.floor((worldCoordinate.y - worldCoordinateNW.y) * scale)
);
return {
x: pixelOffset.x,
y: pixelOffset.y,
right: document.getElementById("map").clientWidth - pixelOffset.x,
bottom: document.getElementById("map").clientHeight - pixelOffset.y
};
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
关于javascript - 将元素拖放到谷歌地图外部/内部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39758597/
我有一个带有 H264 身份验证的 RTSP 流的 URL - MPEG-4 第 10 部分编解码器。 Lik 看起来像这样:rtsp://login:pass@xxx.xxx.xxx.xxx:557
我正在开发移动应用程序。现在,我将访问 token 放在SharedPrefences上。我想问一下SharedPrefences上的存储访问 token 是否安全?如果没有,最好的做法是在哪里放置访
一个 UITableView,它有 20 行的 UITableViewCell,每一行都有一个按钮,单击按钮我想将 UITableViewCell 放到 UITableView 的底部。 是否有任何委
我有这样的代码。我删掉了所有的细节,但是这个文本区域会在按下按钮后发生变化,而它所做的只是改变了文本区域。没有添加滚动。我什至尝试将滚动策略设置为始终,但它返回错误。此面板将添加到另一个带有 Bord
我想在 NSString 中有 src="字符。 但我不能这样做,因为 "是 Objective C 的一部分。 我想这样做: NSString * name = [ [NSString alloc]
非常新手的问题,我是 html 的新手,特别是 highcharts 的东西。所以首先,我制作了这个 test.php 来显示图表。 Highcharts Exampl
如何将我的 fab 放在我的 fragment 上?请帮助我收到错误,例如。 android.view.InflateException: Binary XML file line #13: Erro
我已经完成了一个unity的迷你游戏,名为“penguins_test”。我导出了 2 个文件: penguins_test.html penguins_test.unity3d 现在,我想使用 Go
有谁知道如何将 uiviewcontroller(或只是 View )添加到 cocos2d 层上? 最佳答案 是这样的: [[CCDirector sharedDirector].view addS
我知道您可以采取一些技巧,将 HTML 元素放在 Silverlight 应用程序的顶部,但这无法全屏显示。有没有办法在 Silverlight 应用程序中显示 html 页面? 最佳答案 http:
从 Golang 教程中我不清楚如何将 Golang 代码放到 Github 以便以后能够从 Github 将该代码作为包导入。 这是来自 Golang 教程 http://golang.org/do
我围绕 Pygame 构建了我的整个游戏,并想把它放到 Steam 上。最后我了解到我需要 OpenGL 支持才能运行 Steam 的叠加层。初始化显示的代码: screen = pygame.dis
我需要将已编译的 apk 文件复制到作业 artifats,以便在成功时能够直接从作业页面下载它。 现在我已经在文件夹 build/apk/MyProject-release.apk 中编译了 apk
我愿意在本地和 Heroku 上处理不同的设置。所以我在 settings.py 的末尾使用了这个导入: try: from local_settings import * except Im
我是安卓新手。这个问题是我尝试使用 Android 应用程序和 Web 服务的步骤中的一个阶段。我之前问过一个问题,在这里:Fail to connect android to web service
我是 Git 新手。我刚刚在我的计算机上创建了一个 Git 存储库。现在我想将该存储库连接到网站 (GitHub) 并将我的代码推送到那里。 我该怎么做?我有点熟悉......我必须以某种方式将在线代
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: How to use an existing database with an Android applic
如何在浏览器选项卡上显示标签名称? :( 帮我我想将我的标签显示为选项卡,有什么技巧吗? 技巧 - ABC 技巧 - 最佳答案 是的,您可以使用 在浏览器选项卡中显示标签名称 示例标题代码:
我需要 Tomcat 上的 JAX-WS 运行时。 把“jax-ws/lib/*”放到“tomcat/lib”里可以吗? 如果将 jax-ws/lib 放入 tomcat/lib,是否需要 Tomca
我已经在Win10系统中安装了hadoop-2.5.2和eclipse neon.1a,但是我把“hadoop-eclipse-plugin-2.5.2.jar”放到/eclipse/plugins后
我是一名优秀的程序员,十分优秀!