gpt4 book ai didi

ruby-on-rails - RoR gem Gmaps4rails,自定义信息窗口

转载 作者:行者123 更新时间:2023-12-04 03:36:52 25 4
gpt4 key购买 nike

我在 RoR 中有一个网站。

我使用 gmaps4rails gem 调用 Google map 。

我想去除信息窗口的背景div,但我不知道该怎么做。

enter image description here

@编辑1

我的 index.html.erb 中有这段代码

<body>

<%# Mapa para mostrar todos os pontos guardados na base de dados %>
<div id="map_show" class="" style=""></div>

<script type="text/javascript">

var InfoBoxBuilder, handler,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;

InfoBoxBuilder = (function(superClass) {
extend(InfoBoxBuilder, superClass);

function InfoBoxBuilder() {
return InfoBoxBuilder.__super__.constructor.apply(this, arguments);
}

InfoBoxBuilder.prototype.create_infowindow = function() {
var boxText;
if (!_.isString(this.args.infowindow)) {
return null;
}
boxText = document.createElement("div");
boxText.setAttribute('class', 'yourClass'); // This is where you add a class style it in your css and see what happens
boxText.innerHTML = this.args.infowindow;
return this.infowindow = new InfoBox(this.infobox(boxText));
};

InfoBoxBuilder.prototype.infobox = function(boxText) {
return {
content: boxText,
pixelOffset: new google.maps.Size(-140, 0),
boxStyle: {
width: "280px"
}
};
};

return InfoBoxBuilder;

})(Gmaps.Google.Builders.Marker);

handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map_show'}}, function() {
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();


});
</script>
</body>

但是输出是这样的:

enter image description here

我做错了什么?

@EDIT2

在我的部分 _infowindow.html.erb 中,我有这段代码可以为我提供纪念碑的信息,并且该信息将用于标记。

    <div class="card" style="">
<%= image_tag poi.image, :class => "card-img-top cover" %>
<div class="card-block">
<h4 class="card-title"><%= poi.name %></h4>
<p class="card-text"><%= simple_format(poi.description.first(400)) %></p>
</div>
</div>

我可以把它放在哪里?我不知道把代码放在哪里。

@EDIT3

我使用此代码在 Controller 中呈现局部:

marker.infowindow render_to_string(:partial => "/home/infowindow", :locals => { :poi => poi})

但信息窗口仍然像第一张图片

最佳答案

我仍在学习,但基本上您需要能够定位信息窗口 div。当您使用 gmaps4rails 创建一个信息窗口时,它会在主 div 中创建一个 div,因此您只需要自定义内部 div。您需要多一点代码来定位主 div。我曾经使用以下代码来完成此操作:

var InfoBoxBuilder, handler,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;

InfoBoxBuilder = (function(superClass) {
extend(InfoBoxBuilder, superClass);

function InfoBoxBuilder() {
return InfoBoxBuilder.__super__.constructor.apply(this, arguments);
}

InfoBoxBuilder.prototype.create_infowindow = function() {
var boxText;
if (!_.isString(this.args.infowindow)) {
return null;
}
boxText = document.createElement("Div");
boxText.setAttribute('class', 'yourClass');
boxText.innerHTML = this.args.infowindow;
return this.infowindow = new InfoBox(this.infobox(boxText));
};

InfoBoxBuilder.prototype.infobox = function(boxText) {
return {
content: boxText,
pixelOffset: new google.maps.Size(-140, 0),
boxStyle: {
width: "280px"
}
};
};

return InfoBoxBuilder;

})(Gmaps.Google.Builders.Marker);

这将允许您定位主 div 来改变窗口的整体外观。让我知道这是否适合您,或者您是否需要更多指导也可以发布您的代码。

这是我告诉您的更新后的代码部分。

        <!-- Custom info markers -->

<div id="map_show" class="" style=""></div>

<script type="text/javascript">

var InfoBoxBuilder, handler,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;

InfoBoxBuilder = (function(superClass) {
extend(InfoBoxBuilder, superClass);

function InfoBoxBuilder() {
return InfoBoxBuilder.__super__.constructor.apply(this, arguments);
}

InfoBoxBuilder.prototype.create_infowindow = function() {
var boxText;
if (!_.isString(this.args.infowindow)) {
return null;
}
boxText = document.createElement("div");
boxText.setAttribute('class', 'yourClass'); // This is where you add a class style it in your css and see what happens
boxText.innerHTML = this.args.infowindow;
return this.infowindow = new InfoBox(this.infobox(boxText));
};

InfoBoxBuilder.prototype.infobox = function(boxText) {
return {
content: boxText,
pixelOffset: new google.maps.Size(-140, 0),
boxStyle: {
width: "280px"
}
};
};

return InfoBoxBuilder;

})(Gmaps.Google.Builders.Marker);

handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map_show'}}, function() {
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();


});
</script>

我更新了我的答案以适合您的答案。您需要创建一个类,它在本节中显示您的类,并根据您的喜好设置样式。

 boxText = document.createElement("div");
boxText.setAttribute('class', 'yourClass'); // This is where you add a class style it in your css and see what happens

关于ruby-on-rails - RoR gem Gmaps4rails,自定义信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44998241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com