我在传单地图中使用了meijer的geosearch。它工作正常,但我突然打破它,我不知道如何。地图仍会显示,但搜索框不会显示在地图中。打破应用程序的代码是(leaflet_map.js):
new L.Control.GeoSearch({
provider: new L.GeoSearch.Provider.OpenStreetMap(),
showMarker: false,
position: 'topright',
retainZoomLevel: false
}).addTo(map);
我不认为它可以找到geosearch js或css文件,即使我已经将它们清楚地包含在application.html.erb中:
<%= stylesheet_link_tag "leaflet.css" %>
<%= javascript_include_tag "leaflet.js" %>
<%= stylesheet_link_tag "l.geosearch.css" %>
<%= javascript_include_tag "l.control.geosearch.js" %>
<%= javascript_include_tag "l.geosearch.provider.openstreetmap.js" %>
我认为转折点可能是在命令行输入bundle exec rake assets:precompile
时(我也RAILS_ENV=production bundle exec rake assets:precompile
)。为什么会破坏geosearch?
我删除了我的公共/资源文件夹,但这没有任何区别。
此外,控制台不会显示有关geosearch.js文件损坏的任何投诉或未找到它们。像往常一样,我感到困惑。
js console:
Uncaught Error: Map container not found.
Uncaught TypeError: Cannot read property 'Provider' of undefined
Mixed Content: The page at 'xxxx' was loaded over HTTPS, but requested an insecure image 'http://a.tile.openstreetmap.org/13/7424/5131.png'. This content should also be served over HTTPS.
视图:
<div id="map-leaflet"></div>
<%= javascript_include_tag "easy-button" %>
<%= javascript_include_tag "leaflet_map" %>
leaflet_map.js
map = L.map('map-leaflet', {center: [10.0, 10.0], zoom: 16} );
map.options.maxZoom = 22;
L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 22
}).addTo(map);
// add location search box
new L.Control.GeoSearch({
provider: new L.GeoSearch.Provider.OpenStreetMap(),
showMarker: false,
position: 'topright',
retainZoomLevel: false
}).addTo(map);
演示网站here
答案 0 :(得分:1)
您的leaflet-map
初始化代码包含两次,一次在<script src="/assets/leaflet_map-8e1007491534b1245e2ccc867a845d14e60679a58ca180c5e9cbef68530aa571.js"></script>
内,一次来自application.js。删除地图div下方的struct data * readfile(int *j) {
struct data *input;
/* read the data */
return input;
}
int main(int argc, const char * argv[]) {
struct data *input;
input = readfile(&j);
printf("%f\n",input[0].percent_change);
}
资产参考,以开始解决这些问题。