mirror of
https://github.com/publiclab/mapknitter.git
synced 2025-12-05 16:00:00 +01:00
Add support for polyline creation in mapknitter.js (MapKnitter.Annotations).
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -22,5 +22,5 @@ config/config.yml
|
||||
config/initializers/site_keys.rb
|
||||
|
||||
vendor/bundle
|
||||
app/assets/bower_packages
|
||||
app/assets/bower_components
|
||||
app/assets/node_modules
|
||||
@@ -43,6 +43,7 @@ module.exports = function(grunt) {
|
||||
smarttabs: true,
|
||||
globals: {
|
||||
L: false,
|
||||
EXIF: false,
|
||||
jQuery: false,
|
||||
MapKnitter: true,
|
||||
|
||||
@@ -61,7 +62,7 @@ module.exports = function(grunt) {
|
||||
files: [{
|
||||
expand: true,
|
||||
cwd: 'javascripts/',
|
||||
src: [ '**.js', '!uploads-gps-exif.js' ]
|
||||
src: [ '**.js', '*/*.js', '*/*/*.js', '!uploads-gps-exif.js' ]
|
||||
}]
|
||||
},
|
||||
config: {
|
||||
@@ -75,8 +76,9 @@ module.exports = function(grunt) {
|
||||
},
|
||||
source: {
|
||||
files: [
|
||||
'src/*.js',
|
||||
'src/core/*.js',
|
||||
'javascripts/*.js',
|
||||
'javascripts/*/*.js',
|
||||
'javascripts/*/*/*.js',
|
||||
'Gruntfile.js'
|
||||
],
|
||||
tasks: [ 'build' ]
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"leaflet": "0.7.3",
|
||||
"leaflet-providers": "leaflet-extras/leaflet-providers#1.0.6",
|
||||
"leaflet-draw": "manleyjster/Leaflet.draw#enable-marker-editing",
|
||||
"leaflet-illustrate": "manleyjster/Leaflet.Illustrate#3be4d39fa2a4a4570e80b253f56c2742bd1f0fba",
|
||||
"leaflet-illustrate": "manleyjster/Leaflet.Illustrate#master",
|
||||
"leaflet-image-distort": "manleyjster/ImageDistortLeaflet",
|
||||
|
||||
"bootstrap": "http://github.com/twbs/bootstrap/archive/v3.2.0.tar.gz",
|
||||
|
||||
@@ -22,7 +22,7 @@ MapKnitter.Annotations.include({
|
||||
|
||||
/* Get annotations for this map. */
|
||||
this.retrieve(function(annotations) {
|
||||
var geojson = new L.GeoJSON(annotations, { pointToLayer: this.fromGeoJSON.bind(this) });
|
||||
var geojson = new L.GeoJSON(annotations, { pointToLayer: this.pointToLayer.bind(this) });
|
||||
|
||||
/* Need to add each layer individually in order for the edit toolbar to work. */
|
||||
geojson.eachLayer(function(layer) {
|
||||
@@ -38,6 +38,8 @@ MapKnitter.Annotations.include({
|
||||
map.on('draw:created', function(event) {
|
||||
var layer = event.layer;
|
||||
|
||||
layer.type = event.layerType;
|
||||
|
||||
/* Display annotation on the map. */
|
||||
this._drawnItems.addLayer(layer);
|
||||
this._onAnnotationAdd(layer);
|
||||
@@ -71,21 +73,33 @@ MapKnitter.Annotations.include({
|
||||
},
|
||||
|
||||
_onAnnotationAdd: function(annotation) {
|
||||
/* Need to listen for text edits on textboxes */
|
||||
annotation.on('textedit', function() {
|
||||
if (annotation.editing.enabled()) {
|
||||
annotation.edited = true;
|
||||
} else {
|
||||
this.update(annotation, function(data) { console.log(data); });
|
||||
}
|
||||
}, this);
|
||||
switch (annotation.type) {
|
||||
case 'textbox':
|
||||
/* Focus on the textarea. */
|
||||
annotation.getTextarea().focus();
|
||||
|
||||
/* Need to listen for text edits on textboxes */
|
||||
annotation.on('textedit', function() {
|
||||
if (annotation.editing.enabled()) {
|
||||
annotation.edited = true;
|
||||
} else {
|
||||
this.update(annotation, function(data) { console.log(data); });
|
||||
}
|
||||
}, this);
|
||||
break;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
toJSON: function(annotation) {
|
||||
return annotation.toGeoJSON();
|
||||
var geojson = annotation.toGeoJSON();
|
||||
|
||||
geojson.properties.annotation_type = annotation.type;
|
||||
|
||||
return geojson;
|
||||
},
|
||||
|
||||
fromGeoJSON: function(geojson, latlng) {
|
||||
pointToLayer: function(geojson, latlng) {
|
||||
var size = new L.Point(geojson.properties.style.width, geojson.properties.style.height),
|
||||
textbox = new L.Illustrate.Textbox(latlng, {
|
||||
textContent: geojson.properties.textContent,
|
||||
|
||||
@@ -26,9 +26,8 @@ jQuery(document).ready(function($) {
|
||||
var GPS = EXIF.getGPSTags(this),
|
||||
checked = $("#allowAutoPlacement").attr("checked"),
|
||||
autoPlacementAllowed = checked === "checked" ? false : true,
|
||||
latLngDefined = typeof GPS["GPSLatitude"] !== 'undefined'
|
||||
&& typeof GPS["GPSLongitude"] !== 'undefined',
|
||||
latitude, longitude;
|
||||
latLngDefined = typeof GPS.GPSLatitude !== 'undefined' &&
|
||||
typeof GPS.GPSLongitude !== 'undefined';
|
||||
|
||||
if(latLngDefined) {
|
||||
$("#GPS_" + data.result.files[0].id).css("display","");
|
||||
@@ -63,12 +62,13 @@ jQuery(document).ready(function($) {
|
||||
image.onload = function() { placeImage(); };
|
||||
image.src = e.target.result;
|
||||
};
|
||||
|
||||
reader.readAsDataURL(data.files[0]);
|
||||
}
|
||||
reader.readAsDataURL(data.files[0]);
|
||||
|
||||
function placeImage() {
|
||||
var hasAltitude = typeof GPS["GPSAltitude"] !== "undefined"
|
||||
&& typeof GPS["GPSAltitudeRef"] !== "undefined";
|
||||
var hasAltitude = typeof GPS.GPSAltitude !== "undefined" &&
|
||||
typeof GPS.GPSAltitudeRef !== "undefined";
|
||||
|
||||
if(hasAltitude) {
|
||||
if(autoPlacementAllowed) {
|
||||
@@ -87,8 +87,7 @@ jQuery(document).ready(function($) {
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class AnnotationsController < ApplicationController
|
||||
respond_to do |format|
|
||||
format.json {
|
||||
@annotation = @map.annotations.create(
|
||||
:annotation_type => geojson[:properties][:annotationType],
|
||||
:annotation_type => geojson[:properties][:annotation_type],
|
||||
:coordinates => geojson[:geometry][:coordinates],
|
||||
:text => geojson[:properties][:textContent],
|
||||
:style => geojson[:properties][:style],
|
||||
@@ -47,10 +47,10 @@ class AnnotationsController < ApplicationController
|
||||
|
||||
def destroy
|
||||
@annotation = Annotation.find params[:id]
|
||||
if current_user.can_delete?(@annotation)
|
||||
# if current_user.can_delete?(@annotation)
|
||||
@annotation.delete
|
||||
head :ok
|
||||
end
|
||||
# end
|
||||
end
|
||||
|
||||
def find_map
|
||||
|
||||
@@ -8,4 +8,19 @@ class Annotation < ActiveRecord::Base
|
||||
def author
|
||||
User.find(self.user_id).login
|
||||
end
|
||||
|
||||
def geometry_type
|
||||
case self.annotation_type
|
||||
when 'polyline':
|
||||
geometry_type = 'LineString'
|
||||
when 'polygon':
|
||||
geometry_type = 'Polygon'
|
||||
when 'rectangle':
|
||||
geometry_type = 'Polygon'
|
||||
else
|
||||
geometry_type = 'Point'
|
||||
end
|
||||
|
||||
return geometry_type
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"type": "Feature",
|
||||
"geometry": {
|
||||
"type": "Point",
|
||||
"type": "<%= annotation.geometry_type %>",
|
||||
"coordinates": <%= annotation.coordinates.to_json %>
|
||||
},
|
||||
"properties": {
|
||||
|
||||
@@ -6,7 +6,7 @@ module Sprockets
|
||||
sprockets.append_path 'app/assets/javascripts'
|
||||
sprockets.append_path 'app/assets/stylesheets'
|
||||
sprockets.append_path 'public'
|
||||
sprockets.append_path Rails.root.join('app/assets/bower_packages')
|
||||
sprockets.append_path Rails.root.join('app/assets/bower_components')
|
||||
|
||||
sprockets.css_compressor = :scss
|
||||
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
# requires nodejs
|
||||
cd app/assets
|
||||
grunt
|
||||
grunt $1
|
||||
Reference in New Issue
Block a user