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