Coder Social home page Coder Social logo

helpfulrobot / zarocknz-silverstripe-geodata-uploadfield Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zarocknz/silverstripe-geodata-uploadfield

0.0 2.0 0.0 118 KB

Image upload field for forms which gets the geolocation information when the file is selected

PHP 19.90% CSS 0.40% JavaScript 79.07% Scheme 0.63%

zarocknz-silverstripe-geodata-uploadfield's Introduction

SilverStripe Geodata Uploadfield

Build Status Latest Stable Version Latest Unstable Version Scrutinizer Code Quality Total Downloads License

File upload field for forms with a Google Map to allow the user to set the location of the uploaded media, for example photos.

Latitude, Longitude, and Zoom fields are saved in to the same DataObject as the Image the upload field is for when the form is submitted.

If the file has geolocation tags in it once the file is chosen the marker on the map will move to that location automatically (the user can adjust manually if desired).

Note this only works on front-end forms at this time.

Requirements

* Silverstripe 3.1.x+
* JQuery-1.7.1+

Usage example

Add the following fields to the DataObject your form submissions are saved in to...

'Latitude'  => 'Varchar(255)',
'Longitude' => 'Varchar(255)',
'Zoom'      => 'Int',

Also ensure your data object has an Image (or other object which allows file upload)...

private static $has_one = array(
    'Image' => 'Image',
);

Then create your form using the GeodataUploadField instead of a normal Silverstripe upload field...

public function getFrontEndFields($params = null)
{
   $fields = parent::getFrontEndFields($params);

   // Create GeoData Upload field.
   $upload = GeoDataUploadField::create('Image', 'Image');

   // Set options to prevent selection of existing or access to the filesystem as per Silverstripe docs.
   $upload->setCanAttachExisting(false);
   $upload->setCanPreviewFolder(false);

   $fields->replaceField('Image', $upload);

   return $fields;
}

Constructor options

There are a few other things you can pass to the constructor besides the field name and title. For the third parameter you can pass an array of options which will override the default options for the map in _config/geodata-uploadfield.yml.

If you have named the Latitude, Longitude, or Zoom fields differently in your DataObject you need to pass the names of them in to the constructor as the last 3 parameters otherwise nothing will be saved on form submission.

The following example shows creating a GeoDataUploadField passing some options and the differently named lat and lng fields...

$upload = GeoDataUploadField::create(
   'Image',                // Name.
   'Select an Image',      // Title
   array(                  // Options.
      'map' => array(
         'zoom' => 10
      )
   ),
   'theLatField',          // Latitude field name.
   'theLngField',          // Longitude field name.
   'theZomField'           // Zoom field name.
);

Remember, as long as you have named the fields on the dataobject Latitude, Longitude, and Zoom you don't need to pass their names in to the constructor.

Credits

This module is heavily based on the BetterBrief/silverstripe-googlemapfield by Will Morgan and others which has a BSD license.

This module also includes the Javascript EXIF Reader - jQuery plugin 0.1.3 by Jacob Seidelin which has a MPL License.

All I have really done is bought these two together and modified them to work in the way I needed for a project.

I would like to thank the creators and contributors of those repositories / libraries.

Maintainer

zarocknz - https://github.com/zarocknz

TODO

* Try to get this working CMS side.

zarocknz-silverstripe-geodata-uploadfield's People

Contributors

zarocknz avatar spekulatius avatar

Watchers

James Cloos avatar helpfulrobot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.