+++ /dev/null
-$(document).ready(function () {
-
- var map = L.map("small_map", {
- attributionControl: false,
- zoomControl: false
- }).addLayer(new L.OSM.Mapnik());
-
- L.OSM.zoom()
- .addTo(map);
-
- var params = $("#small_map").data();
- var object, bbox;
- if (params.type == "changeset") {
- bbox = L.latLngBounds([params.minlat, params.minlon],
- [params.maxlat, params.maxlon]);
-
- map.fitBounds(bbox);
-
- L.rectangle(bbox, {
- weight: 2,
- color: '#e90',
- fillOpacity: 0
- }).addTo(map);
-
- $("#loading").hide();
-
- $("a[data-editor=remote]").click(function () {
- return remoteEditHandler(bbox);
- });
-
- updatelinks(map.getCenter(), 16, null, [[params.minlat, params.minlon],
- [params.maxlat, params.maxlon]]);
- } else if (params.type == "note") {
- object = {type: params.type, id: params.id};
-
- map.setView([params.lat, params.lon], 16);
-
- L.marker([params.lat, params.lon], { icon: getUserIcon() }).addTo(map);
-
- bbox = map.getBounds();
-
- $("#loading").hide();
-
- $("a[data-editor=remote]").click(function () {
- return remoteEditHandler(bbox);
- });
-
- updatelinks(params, 16, null, bbox, object);
- } else {
- $("#object_larger_map, #object_edit").hide();
-
- object = {type: params.type, id: params.id};
-
- if (!params.visible) {
- object.version = params.version - 1;
- }
-
- map.addObject(object, {
- zoom: true,
- callback: function(extent) {
- $("#loading").hide();
-
- if (extent && extent.isValid()) {
- $("#browse_map .secondary-actions").show();
-
- $("a.bbox[data-editor=remote]").click(function () {
- return remoteEditHandler(extent);
- });
-
- $("a.object[data-editor=remote]").click(function () {
- return remoteEditHandler(extent, params.type + params.id);
- });
-
- $("#object_larger_map").show();
- $("#object_edit").show();
-
- updatelinks(map.getCenter(), 16, null, extent, object);
- }
- }
- });
- }
-});
}
}
- if (params.box) {
- L.rectangle(params.box, {
- weight: 2,
- color: '#e90',
- fillOpacity: 0
- }).addTo(map);
- }
-
if (params.marker) {
marker.setLatLng([params.mlat, params.mlon]).addTo(map);
}
styles: {
node: options.style,
way: options.style,
- area: options.style
+ area: options.style,
+ changeset: {
+ weight: 2,
+ color: '#e90',
+ fillOpacity: 0
+ }
}
});
apiUrl: function (object) {
var url = "/api/" + OSM.API_VERSION + "/" + object.type + "/" + object.id;
- if (object.type != "node") {
+ if (object.type === "way" || object.type === "relation") {
url += "/full";
} else if (object.version) {
url += "/" + object.version;
},
mapParams: function (search) {
- var params = OSM.params(search), mapParams = {}, bounds, loc;
+ var params = OSM.params(search), mapParams = {}, bounds, loc, match;
if (params.mlon && params.mlat) {
mapParams.marker = true;
mapParams.mlat = parseFloat(params.mlat);
}
- if (params.node || params.way || params.relation) {
+ match = window.location.pathname.match(/\/browse\/(node|way|relation|changeset)\/(\d+)/);
+ if (match) {
+ mapParams.object_zoom = true;
+ mapParams.object = {type: match[1], id: parseInt(match[2])};
+ } else if (params.node || params.way || params.relation || params.note) {
mapParams.object_zoom = true;
if (params.node) {
}
}
+ match = window.location.pathname.match(/\/browse\/note\/(\d+)/);
+ if (match) {
+ mapParams.note = parseInt(match[1]);
+ } else if (params.note) {
+ mapParams.note = parseInt(params.note);
+ }
+
if (params.bbox) {
params.bbox = params.bbox.split(',');
bounds = L.latLngBounds(
parseFloat(params.maxlon)]);
}
- if (params.box === 'yes') {
- mapParams.box = bounds;
- }
-
var hash = OSM.parseHash(location.hash);
// Decide on a map starting position. Various ways of doing this.
mapParams.layers = hash.layers || (loc && loc[3]) || '';
- if (params.note) {
- mapParams.note = parseInt(params.note);
- }
-
var scale = parseFloat(params.scale);
if (scale > 0) {
mapParams.zoom = Math.log(360.0 / (scale * 512.0)) / Math.log(2.0);
+++ /dev/null
-<div id="browse_map" class='clearfix content_map'>
- <% if map.instance_of? Changeset or (map.instance_of? Node and map.version > 1) or map.visible? %>
-
- <% content_for :head do %>
- <%= javascript_include_tag "browse" %>
- <% end %>
-
- <%
- if map.instance_of? Changeset
- bbox = map.bbox.to_unscaled
- data = {
- :type => "changeset",
- :id => map.id,
- :minlon => bbox.min_lon,
- :minlat => bbox.min_lat,
- :maxlon => bbox.max_lon,
- :maxlat => bbox.max_lat
- }
- elsif map.instance_of? Note
- data = {
- :type => "note",
- :id => map.id,
- :lon => map.lon,
- :lat => map.lat
- }
- else
- data = {
- :type => map.class.name.downcase,
- :id => map.id,
- :version => map.version,
- :visible => map.visible
- }
- end
- %>
- <%= content_tag "div", "", :id => "small_map", :data => data %>
- <span id="loading"><%= t 'browse.map.loading' %></span>
-
- <ul class='secondary-actions clearfix'>
- <li>
- <% if map.instance_of? Note -%>
- <%= link_to t("browse.map.larger.area"),
- root_path(:notes => "yes"),
- :id => "area_larger_map",
- :class => "geolink bbox" %>
- <% else -%>
- <%= link_to t("browse.map.larger.area"),
- root_path(:box => "yes"),
- :id => "area_larger_map",
- :class => "geolink bbox" %>
- <% end -%>
- </li>
- <li>
- <%= render :partial => 'layouts/edit_menu',
- :locals => { :link_text => t("browse.map.edit.area"),
- :link_class => 'bbox' } %>
- </li>
- </ul>
-
- <% unless map.instance_of? Changeset %>
- <ul class='secondary-actions clearfix'>
- <li>
- <%= link_to t("browse.map.larger." + map.class.to_s.downcase),
- root_path,
- :id => "object_larger_map",
- :class => "geolink object" %>
- </li>
- <li>
- <%= render :partial => 'layouts/edit_menu',
- :locals => { :link_text => t("browse.map.edit." + map.class.to_s.downcase),
- :link_class => 'object' } %>
- </li>
- </ul>
- <% end %>
-
- <% else %>
- <%= t 'browse.map.deleted' %>
- <% end %>
-</div>
var params = {};
var mapParams = OSM.mapParams();
- if (mapParams.object) {
+ if (mapParams.object &&
+ mapParams.object.type !== 'note' &&
+ mapParams.object.type !== 'changeset') {
params.id = mapParams.object.type[0] + mapParams.object.id;
} else {
<% if @lat && @lon -%>
for (var i = 0; i < features.length; i++) {
var feature = features[i], layer;
- if (feature.type === "node") {
+ if (feature.type === "changeset") {
+ layer = L.rectangle(feature.latLngBounds, this.options.styles.changeset);
+ } else if (feature.type === "node") {
layer = L.circleMarker(feature.latLng, this.options.styles.node);
} else {
var latLngs = new Array(feature.nodes.length);
},
buildFeatures: function (xml) {
- var features = [],
+ var features = L.OSM.getChangesets(xml),
nodes = L.OSM.getNodes(xml),
ways = L.OSM.getWays(xml, nodes),
relations = L.OSM.getRelations(xml, nodes, ways);
});
L.Util.extend(L.OSM, {
+ getChangesets: function (xml) {
+ var result = [];
+
+ var nodes = xml.getElementsByTagName("changeset");
+ for (var i = 0; i < nodes.length; i++) {
+ var node = nodes[i], id = node.getAttribute("id");
+ result.push({
+ id: id,
+ type: "changeset",
+ latLngBounds: L.latLngBounds(
+ [node.getAttribute("min_lat"), node.getAttribute("min_lon")],
+ [node.getAttribute("max_lat"), node.getAttribute("max_lon")]),
+ tags: this.getTags(node)
+ });
+ }
+
+ return result;
+ },
+
getNodes: function (xml) {
var result = {};