Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
247 lines (218 sloc) 10.1 KB
<%-
map = item.maps.find(:first)
markers = map ? map.markers : []
default_position = item.default_map_position.split(/[ ]*,[ ]*/)
map_lat = (map && map.map_lat.present?) ? map.map_lat : default_position[0]
map_lng = (map && map.map_lng.present?) ? map.map_lng : default_position[1]
map_zoom = (map && map.map_zoom.present?) ? map.map_zoom : 14
in_size = safe(0){params[:item][:in_maps]['0'][:markers].size}
markers_size = [3, markers.size, in_size].max
google_api = request.ssl? ? "https://maps-api-ssl.google.com/maps/api/js?sensor=false&region=jp" : "http://maps.google.com/maps/api/js?sensor=false&region=jp"
-%>
<script type="text/javascript" src="<%= google_api %>"></script>
<script type="text/javascript" src="/_common/modules/cms/js/map.js"></script>
<script type="text/javascript">
//<![CDATA[
function addEvent(element, listener, func) {
try {
element.addEventListener(listener, func, false);
} catch (e) {
element.attachEvent('on' + listener, func);
}
}
function addMakerForm() {
var tr = document.createElement('tr');
//var mi = $('#markerForm').getElementsByTagName("tr").length;
var mi = $('#markerForm tr').size();
var e = document.createElement('th');
e.className = "name";
e.innerHTML = "名称";
tr.appendChild(e);
var e = document.createElement('td');
e.className = "name";
e.innerHTML = getMakerInputTag(mi, 'name');
tr.appendChild(e);
var e = document.createElement('th');
e.className = "point";
e.innerHTML = "座標";
tr.appendChild(e);
var e = document.createElement('td');
e.className = "point";
e.innerHTML = getMakerInputTag(mi, 'lat') + '.' + getMakerInputTag(mi, 'lng');
tr.appendChild(e);
var e = document.createElement('td');
e.className = "action";
e.innerHTML += '<a href="#" onclick="me.setMarker(\'item_in_maps_0_markers' + mi + '\'); return false;">≪クリックした座標を設定する</a>';
e.innerHTML += ' <a href="#" onclick="me.unsetMarker(\'item_in_maps_0_markers'+ mi + '\'); return false;">≪クリア</a>';
tr.appendChild(e);
$('#markerFormTbody').append(tr);
return false;
}
function getMakerInputTag(idx, name) {
var uname = name.substring(0, 1).toUpperCase() + name.substring(1)
var h = '<input type="text"';
h += ' id="item_in_maps_0_markers' + idx + uname + '"';
h += ' name="item[in_maps][0][markers][' + idx + '][' + name + ']"';
h += ' value="" />'
return h;
}
var me = null;
addEvent(window, 'load', function() {
// map
var mapOptions = {
center: new google.maps.LatLng(<%= map_lat.to_f %>, <%= map_lng.to_f %>),
zoom: <%= map_zoom %>,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: true,
scrollwheel: false
};
var map = new google.maps.Map(document.getElementById("map1"), mapOptions);
me = new MapEditor(map);
me.syncMap();
google.maps.event.addListener(map, 'dragend', function(){ me.syncMap(); } );
google.maps.event.addListener(map, 'zoom_changed', function(){ me.syncMap(); } );
google.maps.event.addListener(map, 'click', function(event){ me.syncClick(event); } );
<%- if @params_item_in_maps.kind_of?(Hash) &&
(params_markers = @params_item_in_maps['0'].try('[]', 'markers')).kind_of?(Hash) -%>
<%- params_markers.each do |key, value| next if value['lat'].blank? || value['lng'].blank? -%>
var marker<%= key %> = new google.maps.Marker({
// title: '<%= value['name'] %>'
position: new google.maps.LatLng(<%= value['lat'] %>, <%= value['lng'] %>),
map: map
});
var infowindow<%= key %> = new google.maps.InfoWindow({
content: '<%= h(value['name']).gsub(/\r\n|\r|\n/, '<br />').html_safe %>',
disableAutoPan: false
});
google.maps.event.addListener(marker<%= key %>, 'click', function() {
infowindow<%= key %>.open(map, marker<%= key %>);
});
me.markers['item_in_maps_0_markers<%= key %>'] = marker<%= key %>;
<%- end -%>
<%- else -%>
// markers
<% markers.each_with_index do |marker, idx| %>
var marker<%= idx %> = new google.maps.Marker({
//title: '<%= marker.name.gsub(/'/, "\\\\'") %>'
position: new google.maps.LatLng(<%= marker.lat %>, <%= marker.lng %>),
map: map
});
var infowindow<%= idx %> = new google.maps.InfoWindow({
content: '<%= marker.name.gsub(/'/, "\\\\'").gsub(/\r\n|\r|\n/, "<br />") %>',
disableAutoPan: false
});
google.maps.event.addListener(marker<%= idx %>, 'click', function() {
infowindow<%= idx %>.open(map, marker<%= idx %>);
});
// registers to a editor
me.markers['item_in_maps_0_markers<%= idx %>'] = marker<%= idx %>;
<% end %>
<%- end -%>
// hidden
google.maps.event.addListener(map, 'tilesloaded', function() {
google.maps.event.clearListeners(map, 'tilesloaded');
});
});
//]]>
</script>
<div id="mapForm" class="articleMapForm">
<div id="map1" class="mapCanvas"></div>
<input type="hidden" name="item[in_maps][0][name]" value="1" />
<table class="show mapInfo">
<caption>表示中のマップ情報</caption>
<tr>
<th style="width: 90px;">地名で検索</th>
<td>
<input id="searchAddr" name="searchAddr" type="text" value="" style="width: 150px"
onkeydown="me.search('searchAddr', event);" />
<button type="button" style="width: 60px" onclick="me.search('searchAddr'); return false;">検索</button>
</td>
</tr><tr>
<th style="width: 90px;">現在の座標</th>
<td class="point">
<input id="centerDispLat" name="centerDispLat" type="text" value="" readonly="readonly"
/>.<input id="centerDispLng" name="centerDispLng" type="text" value="" readonly="readonly" />
</td>
</tr><tr>
<th style="width: 90px;">現在の縮尺</th>
<td class="zoom"><input id="zoomDisp" name="zoomDisp" type="text" value="" readonly="readonly" /></td>
</tr><tr>
<th style="width: 90px;">クリック座標</th>
<td class="point">
<input id="clickDispLat" name="clickDispLat" type="text" value="" readonly="readonly"
/>.<input id="clickDispLng" name="clickDispLng" type="text" value="" readonly="readonly" />
</td>
</tr>
</table>
<table class="show mapForm">
<caption>マップの設定</caption>
<tr>
<th style="width: 90px;">マップ名</th>
<td class="name">
<%- if @params_item_in_maps.kind_of?(Hash) -%>
<%= text_field_tag 'item[in_maps][0][title]', @params_item_in_maps['0'].try('[]', 'title') %>
<%- else -%>
<%= f.array_text_field "in_maps[0][title]" %>
<%- end -%>
</td>
</tr><tr>
<th style="width: 90px;">座標</th>
<td class="point">
<%- if @params_item_in_maps.kind_of?(Hash) -%>
<%= text_field_tag 'item[in_maps][0][map_lat]', @params_item_in_maps['0'].try('[]', 'map_lat'), id: 'item_in_maps_0_mapLat' %><!--
-->.<%= text_field_tag 'item[in_maps][0][map_lng]', @params_item_in_maps['0'].try('[]', 'map_lng'), id: 'item_in_maps_0_mapLng' %>
<%- else -%>
<%= f.array_text_field "in_maps[0][map_lat]", :id => "item_in_maps_0_mapLat" %><!--
-->.<%= f.array_text_field "in_maps[0][map_lng]", :id => "item_in_maps_0_mapLng" %>
<%- end -%>
</td>
</tr><tr>
<th style="width: 90px;">縮尺</th>
<td class="zoom">
<%- if @params_item_in_maps.kind_of?(Hash) -%>
<%= text_field_tag 'item[in_maps][0][map_zoom]', @params_item_in_maps['0'].try('[]', 'map_zoom'), id: 'item_in_maps_0_mapZoom' %>
<%- else -%>
<%= f.array_text_field "in_maps[0][map_zoom]", :id => "item_in_maps_0_mapZoom" %>
<%- end -%>
<a href="#" onclick="me.setMapInfo('item_in_maps_0_map'); return false;">≪現在の座標と縮尺を設定する</a></td>
</tr>
</table>
<table id="markerForm" class="show markerForm">
<caption>マーカーの設定</caption>
<tbody id="markerFormTbody">
<% 0.upto(markers_size - 1) do |i| %>
<tr>
<th class="name">名称</th>
<td class="name">
<%- if @params_item_in_maps.kind_of?(Hash) -%>
<%= text_field_tag "item[in_maps][0][markers][#{i}][name]", @params_item_in_maps['0'].try('[]', 'markers')
.try('[]', i.to_s)
.try('[]', 'name'), id: "item_in_maps_0_markers#{i}Name" %>
<%- else -%>
<%= f.array_text_field "in_maps[0][markers][#{i}][name]", :id => "item_in_maps_0_markers#{i}Name" %></td>
<%- end -%>
<th class="point">座標</th>
<td class="point">
<%- if @params_item_in_maps.kind_of?(Hash) -%>
<%= text_field_tag "item[in_maps][0][markers][#{i}][lat]", @params_item_in_maps['0'].try('[]', 'markers')
.try('[]', i.to_s)
.try('[]', 'lat'), id: "item_in_maps_0_markers#{i}Lat" %><!--
-->.<%= text_field_tag "item[in_maps][0][markers][#{i}][lng]", @params_item_in_maps['0'].try('[]', 'markers')
.try('[]', i.to_s)
.try('[]', 'lng'), id: "item_in_maps_0_markers#{i}Lng" %>
<%- else -%>
<%= f.array_text_field "in_maps[0][markers][#{i}][lat]", :id => "item_in_maps_0_markers#{i}Lat" %><!--
-->.<%= f.array_text_field "in_maps[0][markers][#{i}][lng]", :id => "item_in_maps_0_markers#{i}Lng" %>
<%- end -%>
</td>
<td class="action">
<a href="#" onclick="me.setMarker('item_in_maps_0_markers<%= i %>'); return false;">≪クリックした座標を設定する</a>
<a href="#" onclick="me.unsetMarker('item_in_maps_0_markers<%= i %>'); return false;">≪クリア</a></td>
</tr>
<% end %>
</tbody>
</table>
<div class="addMarkerForm">
<a href="#" onclick="return addMakerForm();">入力フォームを追加する</a>
</div>
</div>
You can’t perform that action at this time.